41 constantSpacing_m(false) {
47 int xSize,
const double* x,
int ySize,
const double* y,
int zSize,
const double* z)
55 constantSpacing_m(false) {
59 "ThreeDGrid::ThreeDGrid(...)",
"3D Grid must be at least 2x2x2 grid"));
70 constantSpacing_m(false) {
74 "ThreeDGrid::ThreeDGrid(...)",
"3D Grid must be at least 2x2x2 grid"));
78 double dX,
double dY,
double dZ,
double minX,
double minY,
double minZ,
79 int numberOfXCoords,
int numberOfYCoords,
int numberOfZCoords)
80 : x_m(numberOfXCoords),
83 xSize_m(numberOfXCoords),
84 ySize_m(numberOfYCoords),
85 zSize_m(numberOfZCoords),
87 constantSpacing_m(true) {
88 for (
int i = 0; i < numberOfXCoords; i++)
90 for (
int j = 0; j < numberOfYCoords; j++)
92 for (
int k = 0; k < numberOfZCoords; k++)
106 std::vector<int>
end(3, 1);
118 std::vector<double> new_x(
x_m.size() - 1);
119 std::vector<double> new_y(
y_m.size() - 1);
120 std::vector<double> new_z(
z_m.size() - 1);
121 for (
size_t i = 0; i <
x_m.size() - 1; ++i) {
122 new_x[i] = (
x_m[i] +
x_m[i + 1]) / 2.;
124 for (
size_t i = 0; i <
y_m.size() - 1; ++i) {
125 new_y[i] = (
y_m[i] +
y_m[i + 1]) / 2.;
127 for (
size_t i = 0; i <
z_m.size() - 1; ++i) {
128 new_z[i] = (
z_m[i] +
z_m[i + 1]) / 2.;
134 if (difference < 0)
return subEquals(lhs, -difference);
154 if (difference < 0)
return addEquals(lhs, -difference);
178 if (
x >= vec.back()) {
179 index = vec.size() - 1;
183 size_t xUpper = vec.size() - 1;
184 while (xUpper - xLower > 1) {
185 index = (xUpper + xLower) / 2;
186 if (
x >= vec[index]) {
221 }
else if (lhs.
state_m[2] == 1) {
245 std::vector<VectorMap*>::iterator it = std::find(
maps_m.begin(),
maps_m.end(), map);
256 std::vector<VectorMap*>::iterator it = std::find(
maps_m.begin(),
maps_m.end(), map);
264 for (
unsigned int i = 0; i <
x_m.size() - 1; i++)
265 if (std::abs(1 - (
x_m[i + 1] -
x_m[i]) / (
x_m[1] -
x_m[0])) > 1e-9) {
269 for (
unsigned int i = 0; i <
y_m.size() - 1; i++)
270 if (std::abs(1 - (
y_m[i + 1] -
y_m[i]) / (
y_m[1] -
y_m[0])) > 1e-9) {
274 for (
unsigned int i = 0; i <
z_m.size() - 1; i++)
275 if (std::abs(1 - (
z_m[i + 1] -
z_m[i]) / (
z_m[1] -
z_m[0])) > 1e-9) {
282 std::vector<int> index(3);
283 lowerBound(position[0], index[0], position[1], index[1], position[2], index[2]);
284 if (index[0] <
xSize_m - 1 && index[0] >= 0)
286 (2 * (position[0] -
x_m[index[0]]) >
x_m[index[0] + 1] -
x_m[index[0]] ? 2 : 1);
289 if (index[1] <
ySize_m - 1 && index[1] >= 0)
291 (2 * (position[1] -
y_m[index[1]]) >
y_m[index[1] + 1] -
y_m[index[1]] ? 2 : 1);
294 if (index[2] <
zSize_m - 1 && index[2] >= 0)
296 (2 * (position[2] -
z_m[index[2]]) >
z_m[index[2] + 1] -
z_m[index[2]] ? 2 : 1);
299 if (index[0] < 1) index[0] = 1;
300 if (index[1] < 1) index[1] = 1;
301 if (index[2] < 1) index[2] = 1;
std::vector< int > state_m
Base class for meshing routines.
Mesh::Iterator begin() const
void setConstantSpacing()
std::vector< double > y_m
virtual void getPosition(const Mesh::Iterator &it, double *position) const
static void vectorLowerBound(std::vector< double > vec, double x, int &index)
Mesh::Iterator end() const
std::vector< double > x_m
virtual Mesh::Iterator & subEquals(Mesh::Iterator &lhs, int difference) const
void remove(VectorMap *map)
std::vector< double > z_m
virtual Mesh::Iterator & subOne(Mesh::Iterator &lhs) const
virtual bool isGreater(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs) const
virtual Mesh::Iterator & addOne(Mesh::Iterator &lhs) const
virtual Mesh::Iterator & addEquals(Mesh::Iterator &lhs, int difference) const
void lowerBound(const double &x, int &xIndex, const double &y, int &yIndex, const double &z, int &zIndex) const
std::vector< VectorMap * > maps_m
Mesh::Iterator getNearest(const double *position) const