51 std::pair< std::vector<double>,std::vector<double> >
edges_;
62 std::vector<int>
wrapIndices(
const std::vector<int> &indices)
const
64 std::vector<int> newIndices(indices);
70 int index = indices.at(i);
75 newIndices.at(i) = index;
90 virtual size_t mapTo1d(
const std::vector<int> &indices)
const = 0;
105 std::vector<double> lower,
106 std::vector<double> upper,
107 std::vector<bool> isPeriodic)
110 edges_(std::pair< std::vector<double>, std::vector<double> >(lower, upper)),
116 throw std::invalid_argument(
"Size of vector containing upper or "
117 "lower edges, does not match size of vector containing "
118 "number of grid points.");
124 throw std::invalid_argument(
"Size of vector isPeriodic does not "
125 "match size of vector containing number of grid points.");
133 throw std::invalid_argument(
"A periodic grid is incompatible with a grid size of 1.");
136 edges_.first[i] -= spacing/2;
137 edges_.second[i] += spacing/2;
152 std::vector<int> navigate(dim);
155 for(
size_t i = 0 ; i < dim ; i++)
163 for(
size_t j = 0 ; j < dim ; j++)
170 for(
size_t j = 0 ; j < surfsize ; j++)
172 int runningcount = j;
173 for(
size_t k = 0 ; k < dim ; k++)
183 auto temp = this->
at(navigate);
185 this->
at(navigate) = temp;
220 std::cerr <<
"Warning! Grid size requested for a dimension larger "
221 "than the grid dimensionality!\n";
236 else {lower[i] =
edges_.first[i];}
250 std::cerr <<
"Warning! Lower edge requested for a dimension larger "
251 "than the grid dimensionality!\n";
255 else{
return edges_.first[dim];}
267 else {upper[i] =
edges_.second[i];}
282 std::cerr <<
"Warning! Upper edge requested for a dimension larger "
283 "than the grid dimensionality!\n";
287 else{
return edges_.second[dim];}
311 std::cerr <<
"Warning! Periodicity requested for a dimension larger "
312 "than the grid dimensionality!\n";
372 std::vector<int>
GetIndices(
const std::vector<double> &x)
const
376 throw std::invalid_argument(
"Specified point has a larger "
377 "dimensionality than the grid.");
383 double xpos = x.at(i);
386 if (xpos <
edges_.first[i])
391 else if (xpos >
edges_.second[i])
401 indices.at(i) = std::floor( (xpos -
edges_.first[i]) / spacing);
475 throw std::invalid_argument(
"1d Grid index can only be accessed for "
476 "1d-Grids can be accessed with a.");
506 throw std::invalid_argument(
507 "Grid indices specified for GetCoordinates() do not have "
508 "the same dimensionality as the grid.");
515 v.at(i) =
edges_.first[i] + (indices[i] + 0.5)*spacing;
546 const T&
at(
const std::vector<int> &indices)
const
550 throw std::invalid_argument(
"Dimension of indices does not match "
551 "dimension of the grid.");
562 T&
at(
const std::vector<int> &indices)
564 return const_cast<T&
>(
static_cast<const GridBase<T>*
>(
this)->
at(indices));
579 const T&
at(std::initializer_list<R>&& x)
const
581 return at(
static_cast<std::vector<R>
>(x));
596 T&
at(std::initializer_list<R>&& x)
598 return at(
static_cast<std::vector<R>
>(x));
608 const T&
at(
int index)
const
611 throw std::invalid_argument(
"Only 1d-Grids can be accessed with a "
612 "single integer as the index.");
626 return const_cast<T&
>(
static_cast<const GridBase<T>*
>(
this)->
at(index));
637 const T&
at(
const std::vector<double> &x)
const
650 T&
at(
const std::vector<double> &x)
663 const T&
at(
double x)
const
666 throw std::invalid_argument(
"Only 1d-Grids can be accessed with a "
667 "single float as the specified point.");
681 return const_cast<T&
>(
static_cast<const GridBase<T>*
>(
this)->
at(x));
718 return at(
static_cast<std::vector<R>
>(x));
735 return at(
static_cast<std::vector<R>
>(x));
int GetNumPoints(size_t dim) const
Get the number of points for a specific dimension.
T & at(const std::vector< double > &x)
Access Grid element pertaining to a specific point – read/write.
const T & at(double x) const
Access 1d-Grid by point - read-only.
std::vector< bool > isPeriodic_
Periodicity of the Grid.
const T & operator[](const std::vector< double > &x) const
Access Grid element pertaining to a specific point per [] read-only.
T & operator[](int index)
Access 1d-Grid per [] operator, read-write.
T & operator[](const std::vector< int > &indices)
Access Grid element per [] read-write.
virtual size_t mapTo1d(const std::vector< int > &indices) const =0
This function needs to be implemented by child classes.
const std::vector< double > GetLower() const
Return the lower edges of the Grid.
std::pair< std::vector< double >, std::vector< double > > edges_
Edges of the Grid in each dimension.
T & operator[](const std::vector< double > &x)
Access Grid element pertaining to a specific point per [] read-write.
const T & at(int index) const
Access 1d Grid by index, read-only.
const T & at(const std::vector< double > &x) const
Access Grid element pertaining to a specific point – read-only.
double GetCoordinate(int index)
Return center point of 1d-grid.
const T & at(std::initializer_list< R > &&x) const
Const access of Grid element via initializer list.
const T & operator[](int index) const
Access 1d-Grid per [] operator, read-only.
T & at(double x)
Access 1d-Grid by point - read-write.
virtual ~GridBase()
Destructor.
size_t size() const
Get the size of the internal storage vector.
std::vector< int > GetIndices(const std::vector< double > &x) const
Return the Grid indices for a given point.
T * data()
Get pointer to the internal data storage vector.
bool GetPeriodic(size_t dim) const
Get the periodicity in a specific dimension.
std::vector< double > GetCoordinates(const std::vector< int > &indices)
! Return the distance to adjacent grid center points from given coordinates
std::vector< int > numPoints_
Number of points in each dimension.
size_t dimension_
Dimension of the grid.
const T & operator[](double x) const
Access 1d-Grid via specific point, read-only.
size_t GetDimension() const
Get the dimension.
T & at(int index)
Access 1d Grid by index, read-write.
int GetIndex(double x) const
Return linear interpolation on a coordinate.
const T & at(const std::vector< int > &indices) const
Access Grid element read-only.
const std::vector< double > GetUpper() const
Return the upper edges of the Grid.
T & operator[](std::initializer_list< R > &&x)
Access Grid element via initializer list.
GridBase(std::vector< int > numPoints, std::vector< double > lower, std::vector< double > upper, std::vector< bool > isPeriodic)
Constructor.
std::vector< T > data_
Internal storage of the data.
const std::vector< bool > & GetPeriodic() const
Return the periodicity of the Grid.
void syncGrid()
Sync the grid.
const T & operator[](std::initializer_list< R > &&x) const
Const access of Grid element via initializer list.
const std::vector< int > GetNumPoints() const
Get the number of points for all dimensions.
const T & operator[](const std::vector< int > &indices) const
Access Grid element per [] read-only.
double GetLower(size_t dim) const
Get the lower edge for a specific dimension.
T & at(const std::vector< int > &indices)
Access Grid element read/write.
T & operator[](double x)
Access 1d-Grid via specific point, read-write.
T const * data() const
Get pointer to const of the internal data storage vector.
std::vector< int > wrapIndices(const std::vector< int > &indices) const
Wrap the index around periodic boundaries.
double GetUpper(size_t dim) const
Get the upper edge for a specific dimension.
T & at(std::initializer_list< R > &&x)
Access Grid element via initializer list.