34 namespace interpolation {
39 NDGrid::NDGrid(std::vector<int> size, std::vector<const double *> gridCoordinates)
40 : coord_m(), maps_m(), constantSpacing_m(false) {
41 for (
unsigned int i=0; i<size.size(); i++) {
44 "ND Grid must be at least 1x1x...x1 grid"));
46 coord_m.push_back(std::vector<double>(gridCoordinates[i],
47 gridCoordinates[i] + size[i]));
53 : coord_m(nDimensions), maps_m(), constantSpacing_m(true) {
54 for (
int i=0; i<nDimensions; i++) {
57 "ND Grid must be at least 1x1x...x1 grid"));
59 coord_m[i] = std::vector<double>(size[i]);
60 for (
unsigned int j=0; j<
coord_m[i].size(); j++) {
61 coord_m[i][j] = min[i] + j*spacing[i];
67 : coord_m(gridCoordinates), maps_m(), constantSpacing_m(false) {
68 for (
unsigned int i=0; i<gridCoordinates.size(); i++) {
69 if (gridCoordinates[i].
size() < 1) {
71 "ND Grid must be at least 1x1x...x1 grid"));
79 double * array =
new double[
coord_m[dimension].size() ];
80 for (
unsigned int i=0; i<coord_m[dimension].size(); i++) {
81 array[i] = coord_m[dimension][i];
92 std::vector<int> index(
coord_m.size(),0);
93 std::vector<int> content(
coord_m.size(),1);
94 for (
int i =
int(index.size()-2); i >= 0; i--) {
95 content[i] = content[i+1]*
coord_m[i+1].size();
97 for (
int i = 0; i < int(index.size()); i++) {
98 index[i] = difference/content[i];
99 difference -= index[i] * content[i];
101 for (
unsigned int i=0; i<index.size(); i++) {
104 for (
int i =
int(index.size())-1; i > 0; i--) {
115 if (difference < 0) {
118 std::vector<int> index(
coord_m.size(),0);
119 std::vector<int> content(
coord_m.size(),1);
120 for (
int i =
int(index.size()-2); i >= 0; i--) {
121 content[i] = content[i+1]*
coord_m[i+1].size();
123 for (
int i = 0; i < int(index.size()); i++) {
124 index[i] = difference/content[i];
125 difference -= index[i] * content[i];
127 for (
unsigned int i = 0; i < index.size(); i++) {
130 for (
int i=
int(index.size())-1; i>0; i--) {
160 while (lhs[i] == 0 && i>0) {
170 for (
unsigned int i = 0; i <
coord_m.size(); i++) {
171 for (
unsigned int j = 0; j <
coord_m[i].size()-1; j++) {
172 double coord_j1 =
coord_m[i][j+1];
173 double coord_j0 =
coord_m[i][j];
174 double coord_1 =
coord_m[i][1];
175 double coord_0 =
coord_m[i][0];
176 if (
fabs(1-(coord_j1-coord_j0)/(coord_1-coord_0)) > tolerance_m) {
190 return (lhs[i] > rhs[i]);
195 std::vector<int> index (
coord_m.size(),0);
196 std::vector<int> content(
coord_m.size(),1);
197 for (
int i =
int(index.size()-2); i >= 0; i--) {
198 content[i] = content[i+1]*
coord_m[i+1].size();
200 for (
int i = 0; i < int(index.size()); i++) {
201 difference += (lhs.
state_m[i]-1) * (content[i]);
207 std::vector<int> index(
coord_m.size());
208 std::vector<double> pos(position, position+
coord_m.size());
210 for (
unsigned int i = 0; i <
coord_m.size(); i++)
212 if (index[i] <
int(
coord_m[i].
size()-1) && index[i] >= 0) {
213 index[i] += (2*(position[i] -
coord_m[i][index[i]]) >
coord_m[i][index[i]+1]-
coord_m[i][index[i]] ? 2 : 1);
229 std::vector<std::vector<double> >
coord(
coord_m.size());
230 for (
size_t i = 0; i <
coord.size(); ++i) {
233 "ND Grid must be at least 2x2x...x2 grid"));
236 for (
size_t j = 0; j <
coord[i].size(); ++j) {
virtual Mesh::Iterator & subEquals(Mesh::Iterator &lhs, int difference) const
virtual Mesh::Iterator & addOne(Mesh::Iterator &lhs) const
std::vector< int > state_m
PETE_TUTree< FnFabs, typename T::PETE_Expr_t > fabs(const PETE_Expr< T > &l)
The base class for all OPAL exceptions.
double & coord(const int &index, const int &dimension)
virtual Mesh::Iterator & addEquals(Mesh::Iterator &lhs, int difference) const
virtual Mesh::Iterator & subOne(Mesh::Iterator &lhs) const
void setConstantSpacing(bool spacing)
double * newCoordArray(const int &dimension) const
void lowerBound(const std::vector< double > &pos, std::vector< int > &xIndex) const
int size(const int &dimension) const
virtual bool isGreater(const Mesh::Iterator &lhs, const Mesh::Iterator &rhs) const
Base class for meshing routines.
NDGrid()
////// NDGrid ///////
int toInteger(const Mesh::Iterator &lhs) const
std::vector< std::vector< double > > coord_m
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Mesh::Iterator getNearest(const double *position) const