24 #include "Drivers/DriverException.h"
27 #include "Validator/ObjectRequirement.h"
76 size_t mapTo1d(
const std::vector<int> &indices)
const override
79 for (
size_t i=0; i < GridBase<T>::GetDimension(); ++i) {
80 int index = indices.at(i);
83 if ( (periodic && (index < 0 || index >= numpoints)) ||
84 (periodic && (index < -1 || index > numpoints)) )
86 throw std::out_of_range(
"Bin index out of range.");
92 for (
size_t i=0; i < GridBase<T>::GetDimension(); ++i) {
94 idx += indices.at(i) * fac;
97 idx += (indices.at(i) + 1) * fac;
117 std::vector<double> lower,
118 std::vector<double> upper,
119 std::vector<bool> isPeriodic)
120 :
GridBase<T>(numPoints, lower, upper, isPeriodic)
122 size_t data_size = 1;
123 for (
size_t d = 0; d < GridBase<T>::GetDimension(); ++d) {
126 data_size *= storage_size;
162 reader.parse(JsonSchema::grid, schema);
163 validator.
Parse(schema, path);
172 std::vector<double> lower;
173 for (
auto &lv : json[
"lower"]) {
174 lower.push_back(lv.asDouble());
177 size_t dimension = lower.size();
180 std::vector<double> upper;
181 for (
auto &uv : json[
"upper"]) {
182 upper.push_back(uv.asDouble());
185 if (upper.size() != dimension) {
187 "number of lower values!"});
191 std::vector<int> number_points;
192 for (
auto &np : json[
"number_points"]) {
193 number_points.push_back(np.asInt());
196 if (number_points.size() != dimension) {
197 throw BuildException({
"Arrays \"lower\" and \"number_points\" do "
198 "not have the same size!"});
202 std::vector<bool> isPeriodic;
203 for (
auto &periodic : json[
"periodic"]) {
204 isPeriodic.push_back(periodic.asBool());
207 if (isPeriodic.size() == 0) {
208 isPeriodic = std::vector<bool>(dimension,
false);
209 }
else if (isPeriodic.size() != dimension) {
211 "have the same size!"});
318 for (
size_t i = 0; i <
hist_->GetDimension() - 1; ++i) {
319 if (
hist_->GetPeriodic(i) &&
324 }
else if (!
hist_->GetPeriodic(i) &&
363 if (shift.size() !=
hist_->GetDimension()) {
364 throw std::invalid_argument(
"Vector to shift iterator does not "
365 "match histogram dimension.");
368 for (
size_t i = 0; i <
hist_->GetDimension(); ++i) {
397 for (
size_t i = 0; i <
hist_->GetDimension() - 1; ++i) {
428 if (shift.size() !=
hist_->GetDimension()) {
429 throw std::invalid_argument(
"Vector to shift iterator does not "
430 "match histogram dimension.");
433 for (
size_t i = 0; i <
hist_->GetDimension(); ++i) {
469 return !( (*this) == rhs );
501 for (
size_t i = 0; i <
indices_.size(); ++i) {
552 for (
size_t i = 0; i < indices.size(); ++i) {
574 for (
size_t i = 0; i < indices.size(); ++i) {
593 typename std::vector<T>::const_iterator
begin()
const
596 for (
size_t i = 0; i < indices.size(); ++i) {
615 typename std::vector<T>::const_iterator
end()
const
618 for (
size_t i = 0; i < indices.size(); ++i) {
R value_type
Either T or const T for iterator and const_iterator, respectively.
HistIterator self_type
Type name of the iterator.
bool HasErrors()
Check if errors have occured.
self_type & operator-=(std::vector< int > shift)
Subtraction assignment operator.
self_type operator++(int)
Post-increment operator.
int & index(size_t d)
Access a specific index.
Histogram< T > * hist_
Pointer to histogram to iterate over.
self_type & operator++()
Pre-increment operator.
HistIterator(const HistIterator &other)
Copy constructor.
size_t mapTo1d(const std::vector< int > &indices) const override
Map d-dimensional indices to 1-d data vector.
std::vector< T >::const_iterator end() const
Return const iterator after last valid bin.
HistIterator< T > iterator
Custom iterator over a histogram.
HistIterator()=default
Use default constructor.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value to generate Requirement(s).
R & reference
Either T& or T const& for iterator and const_iterator, respectively.
Exception to be thrown when building the Driver fails.
int difference_type
Difference type is an int.
self_type & operator--()
Pre-decrement operator.
std::vector< int > indices_
Indices of current bin.
std::vector< std::string > GetErrors()
Get list of error messages.
const std::vector< bool > & GetPeriodic() const
Return the periodicity of the Grid.
HistIterator(const std::vector< int > &indices, Histogram< T > *hist)
Constructor.
bool operator==(const self_type &rhs) const
Equality operator.
iterator end()
Return iterator after last valid bin.
const self_type operator+(std::vector< int > shift)
Addition operator.
Requirements on an object.
self_type & operator+=(std::vector< int > shift)
Addition assignment operator.
bool isUnderOverflowBin() const
Check if current iterator position is under- or overflow bin.
double coordinate(size_t d) const
Access specific coordinate dimension.
self_type operator--(int)
Post-decrement operator.
const std::vector< int > & GetNumPoints() const
Get the number of points for all dimensions.
R * pointer
Either T* or T const* for iterator and const_iterator, respectively.
HistIterator< const T > const_iterator
Custom constant iterator over a histogram.
iterator begin()
Return iterator at first bin of histogram.
static Histogram< T > * BuildHistogram(const Json::Value &json, const std::string &path)
Set up the histogram.
reference operator*()
Dereference operator.
Histogram(std::vector< int > numPoints, std::vector< double > lower, std::vector< double > upper, std::vector< bool > isPeriodic)
Constructor.
const self_type operator-(std::vector< int > shift)
Subtraction iterator.
std::vector< double > coordinates() const
Access coordinates.
static Histogram< T > * BuildHistogram(const Json::Value &json)
Set up the histogram.
std::bidirectional_iterator_tag iterator_category
HistIterator is a bidirectional iterator.
std::vector< T >::const_iterator begin() const
Return const iterator at first bin of histogram.
bool operator!=(const self_type &rhs) const
Non-equality operator.
virtual void Validate(const Value &json, const std::string &path) override
Validate JSON value.
std::vector< int > & indices()
Access indices.