Skip to content

Commit

Permalink
observables: make observables immutable.
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSzuttor committed Apr 8, 2021
1 parent e700b1b commit 90293aa
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 290 deletions.
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
2 changes: 1 addition & 1 deletion src/core/observables/PidObservable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ using ParticleReferenceRange =
*/
class PidObservable : virtual public Observable {
/** Identifiers of particles measured by this observable */
std::vector<int> m_ids;
const std::vector<int> m_ids;

virtual std::vector<double>
evaluate(ParticleReferenceRange particles,
Expand Down
15 changes: 10 additions & 5 deletions src/core/observables/ProfileObservable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ 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;
/** Number of bins for each coordinate. */
const std::array<size_t, 3> n_bins;

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,
Expand All @@ -42,17 +48,16 @@ class ProfileObservable : virtual public Observable {
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;

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 Down
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
101 changes: 25 additions & 76 deletions src/script_interface/observables/LBProfileObservable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,94 +50,43 @@ class LBProfileObservable
using Base::Base;
LBProfileObservable() {
this->add_parameters(
{{"n_x_bins",
[this](const Variant &v) {
profile_observable()->n_bins[0] =
static_cast<size_t>(get_value<int>(v));
},
{{"n_x_bins", AutoParameter::read_only,
[this]() {
return static_cast<int>(profile_observable()->n_bins[0]);
return static_cast<int>(profile_observable()->get_n_bins()[0]);
}},
{"n_y_bins",
[this](const Variant &v) {
profile_observable()->n_bins[1] =
static_cast<size_t>(get_value<int>(v));
},
{"n_y_bins", AutoParameter::read_only,
[this]() {
return static_cast<int>(profile_observable()->n_bins[1]);
return static_cast<int>(profile_observable()->get_n_bins()[1]);
}},
{"n_z_bins",
[this](const Variant &v) {
profile_observable()->n_bins[2] =
static_cast<size_t>(get_value<int>(v));
},
{"n_z_bins", AutoParameter::read_only,
[this]() {
return static_cast<int>(profile_observable()->n_bins[2]);
return static_cast<int>(profile_observable()->get_n_bins()[2]);
}},
{"min_x",
[this](const Variant &v) {
profile_observable()->limits[0].first = get_value<double>(v);
},
[this]() { return profile_observable()->limits[0].first; }},
{"min_y",
[this](const Variant &v) {
profile_observable()->limits[1].first = get_value<double>(v);
},
[this]() { return profile_observable()->limits[1].first; }},
{"min_z",
[this](const Variant &v) {
profile_observable()->limits[2].first = get_value<double>(v);
},
[this]() { return profile_observable()->limits[2].first; }},
{"max_x",
[this](const Variant &v) {
profile_observable()->limits[0].second = get_value<double>(v);
},
[this]() { return profile_observable()->limits[0].second; }},
{"max_y",
[this](const Variant &v) {
profile_observable()->limits[1].second = get_value<double>(v);
},
[this]() { return profile_observable()->limits[1].second; }},
{"max_z",
[this](const Variant &v) {
profile_observable()->limits[2].second = get_value<double>(v);
},
[this]() { return profile_observable()->limits[2].second; }},
{"sampling_delta_x",
[this](const Variant &v) {
profile_observable()->sampling_delta[0] = get_value<double>(v);
},
{"min_x", AutoParameter::read_only,
[this]() { return profile_observable()->get_limits()[0].first; }},
{"min_y", AutoParameter::read_only,
[this]() { return profile_observable()->get_limits()[1].first; }},
{"min_z", AutoParameter::read_only,
[this]() { return profile_observable()->get_limits()[2].first; }},
{"max_x", AutoParameter::read_only,
[this]() { return profile_observable()->get_limits()[0].second; }},
{"max_y", AutoParameter::read_only,
[this]() { return profile_observable()->get_limits()[1].second; }},
{"max_z", AutoParameter::read_only,
[this]() { return profile_observable()->get_limits()[2].second; }},
{"sampling_delta_x", AutoParameter::read_only,
[this]() { return profile_observable()->sampling_delta[0]; }},
{"sampling_delta_y",
[this](const Variant &v) {
profile_observable()->sampling_delta[1] = get_value<double>(v);
},
{"sampling_delta_y", AutoParameter::read_only,
[this]() { return profile_observable()->sampling_delta[1]; }},
{"sampling_delta_z",
[this](const Variant &v) {
profile_observable()->sampling_delta[2] = get_value<double>(v);
},
{"sampling_delta_z", AutoParameter::read_only,
[this]() { return profile_observable()->sampling_delta[2]; }},
{"sampling_offset_x",
[this](const Variant &v) {
profile_observable()->sampling_offset[0] = get_value<double>(v);
},
{"sampling_offset_x", AutoParameter::read_only,
[this]() { return profile_observable()->sampling_offset[0]; }},
{"sampling_offset_y",
[this](const Variant &v) {
profile_observable()->sampling_offset[1] = get_value<double>(v);
},
{"sampling_offset_y", AutoParameter::read_only,
[this]() { return profile_observable()->sampling_offset[1]; }},
{"sampling_offset_z",
[this](const Variant &v) {
profile_observable()->sampling_offset[2] = get_value<double>(v);
},
{"sampling_offset_z", AutoParameter::read_only,
[this]() { return profile_observable()->sampling_offset[2]; }},
{"allow_empty_bins",
[this](const Variant &v) {
profile_observable()->allow_empty_bins = get_value<bool>(v);
},
{"allow_empty_bins", AutoParameter::read_only,
[this]() { return profile_observable()->allow_empty_bins; }}});
}

Expand Down
Loading

0 comments on commit 90293aa

Please sign in to comment.