Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

observables: make observables immutable. #4211

Merged
merged 2 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ doc/dg/background_errors.unsorted
.ycm_extra_conf.py
.ipynb_checkpoints

build*/
/*build*/
2 changes: 1 addition & 1 deletion src/core/accumulators/MeanVarianceCalculator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MeanVarianceCalculator : public AccumulatorBase {
public:
// The accumulator struct has to be initialized with the correct vector size,
// therefore the order of init is important.
MeanVarianceCalculator(std::shared_ptr<Observables::Observable> const &obs,
MeanVarianceCalculator(std::shared_ptr<Observables::Observable> obs,
int delta_N)
: AccumulatorBase(delta_N), m_obs(obs), m_acc(obs->n_values()) {}

Expand Down
26 changes: 19 additions & 7 deletions src/core/observables/ProfileObservable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,37 @@ namespace Observables {

/** Cartesian profile observable */
class ProfileObservable : virtual public Observable {
protected:
/** Range of the profile edges. */
const std::array<std::pair<double, double>, 3> limits;
jngrad marked this conversation as resolved.
Show resolved Hide resolved
/** Number of bins for each coordinate. */
const std::array<size_t, 3> n_bins;
jngrad marked this conversation as resolved.
Show resolved Hide resolved

public:
ProfileObservable(int n_x_bins, int n_y_bins, int n_z_bins, double min_x,
double max_x, double min_y, double max_y, double min_z,
double max_z)
: limits{{std::make_pair(min_x, max_x), std::make_pair(min_y, max_y),
std::make_pair(min_z, max_z)}},
n_bins{{static_cast<size_t>(n_x_bins), static_cast<size_t>(n_y_bins),
static_cast<size_t>(n_z_bins)}} {}
/** Range of the profile edges. */
std::array<std::pair<double, double>, 3> limits;
/** Number of bins for each coordinate. */
std::array<size_t, 3> n_bins;
static_cast<size_t>(n_z_bins)}} {
if (max_x <= min_x)
throw std::runtime_error("max_x has to be > min_x");
if (max_y <= min_y)
throw std::runtime_error("max_y has to be > min_y");
if (max_z <= min_z)
throw std::runtime_error("max_z has to be > min_z");
}

std::vector<size_t> shape() const override {
return {n_bins[0], n_bins[1], n_bins[2]};
}

auto get_n_bins() const { return n_bins; }

auto get_limits() const { return limits; }
/** Calculate the bin edges for each dimension */
std::array<std::vector<double>, 3> edges() {
std::array<std::vector<double>, 3> edges() const {
std::array<std::vector<double>, 3> profile_edges = {
{std::vector<double>(n_bins[0] + 1), std::vector<double>(n_bins[1] + 1),
std::vector<double>(n_bins[2] + 1)}};
Expand All @@ -67,7 +79,7 @@ class ProfileObservable : virtual public Observable {
profile_edges[2].begin());
return profile_edges;
}
};
}; // namespace Observables

} // Namespace Observables
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CylindricalTransformationParameters
[this]() { return m_transform_params->orientation(); }}});
}
std::shared_ptr<::Utils::CylindricalTransformationParameters>
cyl_transform_params() {
cyl_transform_params() const {
return m_transform_params;
}
void do_construct(VariantMap const &params) override {
Expand Down
81 changes: 22 additions & 59 deletions src/script_interface/observables/CylindricalLBProfileObservable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,83 +56,46 @@ class CylindricalLBProfileObservable
CylindricalLBProfileObservable() {
this->add_parameters({
{"transform_params", m_transform_params},
{"n_r_bins",
[this](const Variant &v) {
cylindrical_profile_observable()->n_bins[0] =
static_cast<size_t>(get_value<int>(v));
},
{"n_r_bins", AutoParameter::read_only,
[this]() {
return static_cast<int>(cylindrical_profile_observable()->n_bins[0]);
return static_cast<int>(
cylindrical_profile_observable()->get_n_bins()[0]);
}},
{"n_phi_bins",
[this](const Variant &v) {
cylindrical_profile_observable()->n_bins[1] =
static_cast<size_t>(get_value<int>(v));
},
{"n_phi_bins", AutoParameter::read_only,
[this]() {
return static_cast<int>(cylindrical_profile_observable()->n_bins[1]);
return static_cast<int>(
cylindrical_profile_observable()->get_n_bins()[1]);
}},
{"n_z_bins",
[this](const Variant &v) {
cylindrical_profile_observable()->n_bins[2] =
static_cast<size_t>(get_value<int>(v));
},
{"n_z_bins", AutoParameter::read_only,
[this]() {
return static_cast<int>(cylindrical_profile_observable()->n_bins[2]);
return static_cast<int>(
cylindrical_profile_observable()->get_n_bins()[2]);
}},
{"min_r",
[this](const Variant &v) {
cylindrical_profile_observable()->limits[0].first =
get_value<double>(v);
},
{"min_r", AutoParameter::read_only,
[this]() {
return cylindrical_profile_observable()->limits[0].first;
return cylindrical_profile_observable()->get_limits()[0].first;
}},
{"min_phi",
[this](const Variant &v) {
cylindrical_profile_observable()->limits[1].first =
get_value<double>(v);
},
{"min_phi", AutoParameter::read_only,
[this]() {
return cylindrical_profile_observable()->limits[1].first;
return cylindrical_profile_observable()->get_limits()[1].first;
}},
{"min_z",
[this](const Variant &v) {
cylindrical_profile_observable()->limits[2].first =
get_value<double>(v);
},
{"min_z", AutoParameter::read_only,
[this]() {
return cylindrical_profile_observable()->limits[2].first;
return cylindrical_profile_observable()->get_limits()[2].first;
}},
{"max_r",
[this](const Variant &v) {
cylindrical_profile_observable()->limits[0].second =
get_value<double>(v);
},
{"max_r", AutoParameter::read_only,
[this]() {
return cylindrical_profile_observable()->limits[0].second;
return cylindrical_profile_observable()->get_limits()[0].second;
}},
{"max_phi",
[this](const Variant &v) {
cylindrical_profile_observable()->limits[1].second =
get_value<double>(v);
},
{"max_phi", AutoParameter::read_only,
[this]() {
return cylindrical_profile_observable()->limits[1].second;
return cylindrical_profile_observable()->get_limits()[1].second;
}},
{"max_z",
[this](const Variant &v) {
cylindrical_profile_observable()->limits[2].second =
get_value<double>(v);
},
{"max_z", AutoParameter::read_only,
[this]() {
return cylindrical_profile_observable()->limits[2].second;
return cylindrical_profile_observable()->get_limits()[2].second;
}},
{"sampling_density",
[this](const Variant &v) {
cylindrical_profile_observable()->sampling_density =
get_value<double>(v);
},
{"sampling_density", AutoParameter::read_only,
[this]() {
return cylindrical_profile_observable()->sampling_density;
}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,80 +58,44 @@ class CylindricalPidProfileObservable
{"ids", AutoParameter::read_only,
[this]() { return cylindrical_pid_profile_observable()->ids(); }},
{"transform_params", m_transform_params},
{"n_r_bins",
[this](const Variant &v) {
cylindrical_pid_profile_observable()->n_bins[0] =
static_cast<size_t>(get_value<int>(v));
},
{"n_r_bins", AutoParameter::read_only,
[this]() {
return static_cast<int>(
cylindrical_pid_profile_observable()->n_bins[0]);
cylindrical_pid_profile_observable()->get_n_bins()[0]);
}},
{"n_phi_bins",
[this](const Variant &v) {
cylindrical_pid_profile_observable()->n_bins[1] =
static_cast<size_t>(get_value<int>(v));
},
{"n_phi_bins", AutoParameter::read_only,
[this]() {
return static_cast<int>(
cylindrical_pid_profile_observable()->n_bins[1]);
cylindrical_pid_profile_observable()->get_n_bins()[1]);
}},
{"n_z_bins",
[this](const Variant &v) {
cylindrical_pid_profile_observable()->n_bins[2] =
static_cast<size_t>(get_value<int>(v));
},
{"n_z_bins", AutoParameter::read_only,
[this]() {
return static_cast<int>(
cylindrical_pid_profile_observable()->n_bins[2]);
cylindrical_pid_profile_observable()->get_n_bins()[2]);
}},
{"min_r",
[this](const Variant &v) {
cylindrical_pid_profile_observable()->limits[0].first =
get_value<double>(v);
},
{"min_r", AutoParameter::read_only,
[this]() {
return cylindrical_pid_profile_observable()->limits[0].first;
return cylindrical_pid_profile_observable()->get_limits()[0].first;
}},
{"min_phi",
[this](const Variant &v) {
cylindrical_pid_profile_observable()->limits[1].first =
get_value<double>(v);
},
{"min_phi", AutoParameter::read_only,
[this]() {
return cylindrical_pid_profile_observable()->limits[1].first;
return cylindrical_pid_profile_observable()->get_limits()[1].first;
}},
{"min_z",
[this](const Variant &v) {
cylindrical_pid_profile_observable()->limits[2].first =
get_value<double>(v);
},
{"min_z", AutoParameter::read_only,
[this]() {
return cylindrical_pid_profile_observable()->limits[2].first;
return cylindrical_pid_profile_observable()->get_limits()[2].first;
}},
{"max_r",
[this](const Variant &v) {
cylindrical_pid_profile_observable()->limits[0].second =
get_value<double>(v);
},
{"max_r", AutoParameter::read_only,
[this]() {
return cylindrical_pid_profile_observable()->limits[0].second;
return cylindrical_pid_profile_observable()->get_limits()[0].second;
}},
{"max_phi",
[this](const Variant &v) {
cylindrical_pid_profile_observable()->limits[1].second =
get_value<double>(v);
},
{"max_phi", AutoParameter::read_only,
[this]() {
return cylindrical_pid_profile_observable()->limits[1].second;
return cylindrical_pid_profile_observable()->get_limits()[1].second;
}},
{"max_z",
[this](const Variant &v) {
cylindrical_pid_profile_observable()->limits[2].second =
get_value<double>(v);
},
{"max_z", AutoParameter::read_only,
[this]() {
return cylindrical_pid_profile_observable()->limits[2].second;
return cylindrical_pid_profile_observable()->get_limits()[2].second;
}},
});
};
Expand Down
Loading