ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/observables/LBProfileObservable.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2026 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef SCRIPT_INTERFACE_OBSERVABLES_LBPROFILEOBSERVABLE_HPP
23#define SCRIPT_INTERFACE_OBSERVABLES_LBPROFILEOBSERVABLE_HPP
24
26
27#include "Observable.hpp"
30
31#include <algorithm>
32#include <cstddef>
33#include <iterator>
34#include <memory>
35#include <string>
36#include <type_traits>
37#include <vector>
38
39namespace ScriptInterface {
40namespace Observables {
41
42template <typename CoreLBObs>
44 : public AutoParameters<LBProfileObservable<CoreLBObs>, Observable> {
46
47public:
48 static_assert(
49 std::is_base_of_v<::Observables::LBProfileObservable, CoreLBObs>);
50 using Base::Base;
52 this->add_parameters(
53 {{"n_x_bins", AutoParameter::read_only,
54 [this]() {
55 return static_cast<int>(profile_observable()->n_bins()[0]);
56 }},
57 {"n_y_bins", AutoParameter::read_only,
58 [this]() {
59 return static_cast<int>(profile_observable()->n_bins()[1]);
60 }},
61 {"n_z_bins", AutoParameter::read_only,
62 [this]() {
63 return static_cast<int>(profile_observable()->n_bins()[2]);
64 }},
66 [this]() { return profile_observable()->limits()[0].first; }},
68 [this]() { return profile_observable()->limits()[1].first; }},
70 [this]() { return profile_observable()->limits()[2].first; }},
72 [this]() { return profile_observable()->limits()[0].second; }},
74 [this]() { return profile_observable()->limits()[1].second; }},
76 [this]() { return profile_observable()->limits()[2].second; }},
77 {"sampling_delta_x", AutoParameter::read_only,
78 [this]() { return profile_observable()->sampling_delta[0]; }},
79 {"sampling_delta_y", AutoParameter::read_only,
80 [this]() { return profile_observable()->sampling_delta[1]; }},
81 {"sampling_delta_z", AutoParameter::read_only,
82 [this]() { return profile_observable()->sampling_delta[2]; }},
83 {"sampling_offset_x", AutoParameter::read_only,
84 [this]() { return profile_observable()->sampling_offset[0]; }},
85 {"sampling_offset_y", AutoParameter::read_only,
86 [this]() { return profile_observable()->sampling_offset[1]; }},
87 {"sampling_offset_z", AutoParameter::read_only,
88 [this]() { return profile_observable()->sampling_offset[2]; }},
89 {"allow_empty_bins", AutoParameter::read_only,
90 [this]() { return profile_observable()->allow_empty_bins; }}});
91 }
92
93 void do_construct(VariantMap const &params) override {
95 m_observable = std::make_shared<CoreLBObs>(
96 get_value_or<double>(params, "sampling_delta_x", 1.),
97 get_value_or<double>(params, "sampling_delta_y", 1.),
98 get_value_or<double>(params, "sampling_delta_z", 1.),
99 get_value_or<double>(params, "sampling_offset_x", 0.),
100 get_value_or<double>(params, "sampling_offset_y", 0.),
101 get_value_or<double>(params, "sampling_offset_z", 0.),
102 get_value<int>(params, "n_x_bins"),
103 get_value<int>(params, "n_y_bins"),
104 get_value<int>(params, "n_z_bins"),
105 get_value<double>(params, "min_x"),
106 get_value<double>(params, "max_x"),
107 get_value<double>(params, "min_y"),
108 get_value<double>(params, "max_y"),
109 get_value<double>(params, "min_z"),
110 get_value<double>(params, "max_z"),
111 get_value_or<bool>(params, "allow_empty_bins", false));
112 });
113 }
114
115 Variant do_call_method(std::string const &method,
116 VariantMap const &parameters) override {
117 if (method == "edges") {
118 std::vector<Variant> variant_edges;
119 std::ranges::copy(profile_observable()->edges(),
120 std::back_inserter(variant_edges));
121 return variant_edges;
122 }
123 return Base::do_call_method(method, parameters);
124 }
125
126 std::shared_ptr<::Observables::Observable> observable() const override {
127 return m_observable;
128 }
129
130 virtual std::shared_ptr<::Observables::LBProfileObservable>
132 return m_observable;
133 }
134
135private:
136 std::shared_ptr<CoreLBObs> m_observable;
137};
138
139} /* namespace Observables */
140} /* namespace ScriptInterface */
141
142#endif
Bind parameters in the script interface.
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
Context * context() const
Responsible context.
virtual std::shared_ptr<::Observables::LBProfileObservable > profile_observable() const
Variant do_call_method(std::string const &method, VariantMap const &parameters) override
std::shared_ptr<::Observables::Observable > observable() const override
Base class for script interfaces to core observables classes.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:133
static constexpr const ReadOnly read_only
Recursive variant implementation.
Definition Variant.hpp:84