Simpatico  v1.10
OrthoRegion.cpp
1 /*
2 * Util Package - C++ Utilities for Scientific Computation
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "OrthoRegion.h"
9 #include <util/space/Dimension.h>
10 #include <util/math/feq.h>
11 #include <util/global.h>
12 
13 #include <sstream>
14 
15 namespace Simp
16 {
17 
18  using namespace Util;
19 
20  /*
21  * Constructor.
22  */
24  {
25  for (int i = 0; i < Dimension; ++i) {
26  minima_[i] = 0.0;
27  maxima_[i] = 1.0;
28  lengths_[i] = 1.0;
29  halfLengths_[i] = 0.5;
30  };
31  volume_ = 1.0;
32  }
33 
34  /*
35  * Set lengths_, halfLengths_, and volume_ to consistent values.
36  */
38  {
39  for (int i = 0; i < Dimension; ++i) {
40  assert(maxima_[i] > minima_[i]);
41  lengths_[i] = maxima_[i] - minima_[i];
42  halfLengths_[i] = 0.5*lengths_[i];
43  };
44  volume_ = lengths_[0] * lengths_[1] * lengths_[2];
45  }
46 
47  /*
48  * Check consistency of data.
49  */
51  {
52  for (int i = 0; i < Dimension; ++i) {
53  if (maxima_[i] <= minima_[i]) {
54  UTIL_THROW("maxima_[i] <= minima_[i]");
55  }
56  if (!feq(lengths_[i], maxima_[i] - minima_[i])) {
57  UTIL_THROW("lengths_[i] != maxima_[i] - minima_[i]");
58  }
59  if (!feq(halfLengths_[i], 0.5*lengths_[i])) {
60  UTIL_THROW("halfLengths_[i] != 0.5*lengths_[i]");
61  }
62  }
63  double product = lengths_[0]*lengths_[1]*lengths_[2];
64  double diff = volume_ - product;
65  if (!feq(volume_, product)) {
66  std::stringstream buf;
67  buf.precision(12);
68  buf << "volume_ != product of lengths_" << std::endl;
69  buf << "volume_ = " << volume_ << std::endl;
70  buf << "lengths_[0] = " << lengths_[0] << std::endl;
71  buf << "lengths_[1] = " << lengths_[1] << std::endl;
72  buf << "lengths_[2] = " << lengths_[2] << std::endl;
73  buf << "product = " << product;
74  buf << "diff = " << diff;
75  UTIL_THROW(buf.str().c_str());
76  }
77  return true;
78  }
79 
80 }
bool isValid()
Return true if valid, or throw Exception.
Definition: OrthoRegion.cpp:50
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
void resetRegion()
Set lengths and volume to values consistent with minima and maxima.
Definition: OrthoRegion.cpp:37
float product(float a, float b)
Product for float Data.
Definition: product.h:22
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
Vector minima_
Minimum coordinates: Require r[i] >= minima_[i].
Definition: OrthoRegion.h:33
Vector lengths_
OrthoRegion lengths: lengths_[i] = maxima_[i] - minima_[i].
Definition: OrthoRegion.h:39
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
OrthoRegion()
Constructor.
Definition: OrthoRegion.cpp:23
Utility classes for scientific computation.
Definition: accumulators.mod:1
Vector maxima_
Maximum coordinates: Require r[i] < maxima_[i].
Definition: OrthoRegion.h:36
double volume_
Volume: V = lengths_[0]*lengths_[1]*lengths_[2].
Definition: OrthoRegion.h:45
bool feq(double x, double y, double eps=1.0E-10)
Are two floating point numbers equal to within round-off error?
Definition: feq.h:27
Vector halfLengths_
Half region lengths: halfLengths_[i] = 0.5*lengths_[i].
Definition: OrthoRegion.h:42