51 std::pair< std::vector<double>,std::vector<double> >
edges_;
57 std::vector<int>
wrapIndices(
const std::vector<int> &indices)
const
59 std::vector<int> newIndices(indices);
65 int index = indices.at(i);
68 newIndices.at(i) = index;
83 virtual size_t mapTo1d(
const std::vector<int> &indices)
const = 0;
98 std::vector<double> lower,
99 std::vector<double> upper,
100 std::vector<bool> isPeriodic)
103 edges_(std::pair< std::vector<double>, std::vector<double> >(lower, upper)),
109 throw std::invalid_argument(
"Size of vector containing upper or "
110 "lower edges, does not match size of vector containing "
111 "number of grid points.");
117 throw std::invalid_argument(
"Size of vector isPeriodic does not "
118 "match size of vector containing number of grid points.");
153 std::cerr <<
"Warning! Grid size requested for a dimension larger "
154 "than the grid dimensionality!\n";
180 std::cerr <<
"Warning! Lower edge requested for a dimension larger "
181 "than the grid dimensionality!\n";
207 std::cerr <<
"Warning! Upper edge requested for a dimension larger "
208 "than the grid dimensionality!\n";
235 std::cerr <<
"Warning! Periodicity requested for a dimension larger "
236 "than the grid dimensionality!\n";
296 std::vector<int>
GetIndices(
const std::vector<double> &x)
const
300 throw std::invalid_argument(
"Specified point has a larger "
301 "dimensionality than the grid.");
306 double xpos = x.at(i);
319 indices.at(i) = std::floor( (xpos -
GetLower(i)) / spacing);
335 double interpvalue = 0;
337 for (
size_t i = 0 ; i < pow(2,
dimension_) ; ++i)
340 std::vector<double> shiftedvector = x;
343 double accumulatedweight = 1;
347 shiftedvector[j] += ((tempindex%2)-0.5)*spacing;
348 tempindex = tempindex/2;
351 std::vector<int> shiftedindices =
GetIndices(shiftedvector);
352 std::vector<double> shiftedcenters =
GetCoordinates(shiftedindices);
358 if(shiftedindices[j] == -1)
361 shiftedvector[j] += spacing/2;
366 shiftedvector[j] -= spacing/2;
371 if(std::abs(x[j]-shiftedcenters[j]) > spacing)
372 accumulatedweight *= (1-(std::abs(std::abs(x[j]-shiftedcenters[j]) - (
GetUpper(j) -
GetLower(j)))/spacing));
374 accumulatedweight *= (1-(std::abs(x[j]-shiftedcenters[j])/spacing));
377 interpvalue += accumulatedweight*
at(shiftedvector);
394 throw std::invalid_argument(
"1d Grid index can only be accessed for "
395 "1d-Grids can be accessed with a.");
412 throw std::invalid_argument(
413 "Grid indices specified for GetCoordinates() do not have "
414 "the same dimensionality as the grid.");
421 v.at(i) =
GetLower(i) + (indices[i] + 0.5)*spacing;
452 const T&
at(
const std::vector<int> &indices)
const
456 throw std::invalid_argument(
"Dimension of indices does not match "
457 "dimension of the grid.");
468 T&
at(
const std::vector<int> &indices)
470 return const_cast<T&
>(
static_cast<const GridBase<T>*
>(
this)->
at(indices));
485 const T&
at(std::initializer_list<R>&& x)
const
487 return at(
static_cast<std::vector<R>
>(x));
502 T&
at(std::initializer_list<R>&& x)
504 return at(
static_cast<std::vector<R>
>(x));
514 const T&
at(
int index)
const
517 throw std::invalid_argument(
"Only 1d-Grids can be accessed with a "
518 "single integer as the index.");
532 return const_cast<T&
>(
static_cast<const GridBase<T>*
>(
this)->
at(index));
543 const T&
at(
const std::vector<double> &x)
const
556 T&
at(
const std::vector<double> &x)
569 const T&
at(
double x)
const
572 throw std::invalid_argument(
"Only 1d-Grids can be accessed with a "
573 "single float as the specified point.");
587 return const_cast<T&
>(
static_cast<const GridBase<T>*
>(
this)->
at(x));
624 return at(
static_cast<std::vector<R>
>(x));
641 return at(
static_cast<std::vector<R>
>(x));
const T & operator[](int index) const
Access 1d-Grid per [] operator, read-only.
std::vector< double > GetCoordinates(const std::vector< int > &indices)
Return coordinates of the grid center points.
T & operator[](const std::vector< double > &x)
Access Grid element pertaining to a specific point per [] read-write.
const T & at(double x) const
Access 1d-Grid by point - read-only.
T & at(int index)
Access 1d Grid by index, read-write.
std::pair< std::vector< double >, std::vector< double > > edges_
Edges of the Grid in each dimension.
T & operator[](const std::vector< int > &indices)
Access Grid element per [] read-write.
T & at(std::initializer_list< R > &&x)
Access Grid element via initializer list.
const T & operator[](std::initializer_list< R > &&x) const
Const access of Grid element via initializer list.
T & at(const std::vector< int > &indices)
Access Grid element read/write.
std::vector< int > GetIndices(const std::vector< double > &x) const
Return the Grid indices for a given point.
size_t size() const
Get the size of the internal storage vector.
double GetInterpolated(const std::vector< double > &x)
Return linear interpolation on a coordinate.
bool GetPeriodic(size_t dim) const
Get the periodicity in a specific dimension.
int GetNumPoints(size_t dim) const
Get the number of points for a specific dimension.
std::vector< T > data_
Internal storage of the data.
T const * data() const
Get pointer to const of the internal data storage vector.
const std::vector< bool > & GetPeriodic() const
Return the periodicity of the Grid.
std::vector< int > wrapIndices(const std::vector< int > &indices) const
Wrap the index around periodic boundaries.
const T & operator[](const std::vector< int > &indices) const
Access Grid element per [] read-only.
const std::vector< double > & GetLower() const
Return the lower edges of the Grid.
std::vector< int > numPoints_
Number of points in each dimension.
T & at(const std::vector< double > &x)
Access Grid element pertaining to a specific point – read/write.
const std::vector< double > & GetUpper() const
Return the upper edges of the Grid.
int GetIndex(double x) const
Return the Grid index for a one-dimensional grid.
size_t dimension_
Dimension of the grid.
const T & at(const std::vector< double > &x) const
Access Grid element pertaining to a specific point – read-only.
virtual size_t mapTo1d(const std::vector< int > &indices) const =0
This function needs to be implemented by child classes.
double GetUpper(size_t dim) const
Get the upper edge for a specific dimension.
double GetCoordinate(int index)
Return center point of 1d-grid.
const std::vector< int > & GetNumPoints() const
Get the number of points for all dimensions.
T & operator[](int index)
Access 1d-Grid per [] operator, read-write.
T & operator[](double x)
Access 1d-Grid via specific point, read-write.
const T & operator[](const std::vector< double > &x) const
Access Grid element pertaining to a specific point per [] read-only.
size_t GetDimension() const
Get the dimension.
T & at(double x)
Access 1d-Grid by point - read-write.
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
const T & at(std::initializer_list< R > &&x) const
Const access of Grid element via initializer list.
T * data()
Get pointer to the internal data storage vector.
double GetLower(size_t dim) const
Get the lower edge for a specific dimension.
const T & at(int index) const
Access 1d Grid by index, read-only.
GridBase(std::vector< int > numPoints, std::vector< double > lower, std::vector< double > upper, std::vector< bool > isPeriodic)
Constructor.
T & operator[](std::initializer_list< R > &&x)
Access Grid element via initializer list.
std::vector< bool > isPeriodic_
Periodicity of the Grid.
const T & operator[](double x) const
Access 1d-Grid via specific point, read-only.