ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/observables/ProfileObservable.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 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#pragma once
23
26
29
30#include <algorithm>
31#include <cstddef>
32#include <iterator>
33#include <memory>
34#include <string>
35#include <vector>
36
37namespace ScriptInterface {
38namespace Observables {
39
40template <typename CoreObs>
42 : public AutoParameters<ProfileObservable<CoreObs>, Observable> {
44
45public:
46 using Base::Base;
48 this->add_parameters(
49 {{"n_x_bins",
50 [this](const Variant &v) {
51 profile_observable()->n_bins[0] =
52 static_cast<std::size_t>(get_value<int>(v));
53 },
54 [this]() {
55 return static_cast<int>(profile_observable()->n_bins[0]);
56 }},
57 {"n_y_bins",
58 [this](const Variant &v) {
59 profile_observable()->n_bins[1] =
60 static_cast<std::size_t>(get_value<int>(v));
61 },
62 [this]() {
63 return static_cast<int>(profile_observable()->n_bins[1]);
64 }},
65 {"n_z_bins",
66 [this](const Variant &v) {
67 profile_observable()->n_bins[2] =
68 static_cast<std::size_t>(get_value<int>(v));
69 },
70 [this]() {
71 return static_cast<int>(profile_observable()->n_bins[2]);
72 }},
73 {"min_x",
74 [this](const Variant &v) {
75 profile_observable()->limits[0].first = get_value<double>(v);
76 },
77 [this]() { return profile_observable()->limits[0].first; }},
78 {"min_y",
79 [this](const Variant &v) {
80 profile_observable()->limits[1].first = get_value<double>(v);
81 },
82 [this]() { return profile_observable()->limits[1].first; }},
83 {"min_z",
84 [this](const Variant &v) {
85 profile_observable()->limits[2].first = get_value<double>(v);
86 },
87 [this]() { return profile_observable()->limits[2].first; }},
88 {"max_x",
89 [this](const Variant &v) {
90 profile_observable()->limits[0].second = get_value<double>(v);
91 },
92 [this]() { return profile_observable()->limits[0].second; }},
93 {"max_y",
94 [this](const Variant &v) {
95 profile_observable()->limits[1].second = get_value<double>(v);
96 },
97 [this]() { return profile_observable()->limits[1].second; }},
98 {"max_z",
99 [this](const Variant &v) {
100 profile_observable()->limits[2].second = get_value<double>(v);
101 },
102 [this]() { return profile_observable()->limits[2].second; }}});
103 }
104
105 void construct(VariantMap const &) override {}
106
107 Variant call_method(std::string const &method,
108 VariantMap const &parameters) override {
109 if (method == "edges") {
110 std::vector<Variant> variant_edges;
111 std::ranges::copy(profile_observable()->edges(),
112 std::back_inserter(variant_edges));
113 return variant_edges;
114 }
115 return Base::call_method(method, parameters);
116 }
117
118 std::shared_ptr<::Observables::ProfileObservable> profile_observable() const {
119 return m_observable;
120 }
121
122 std::shared_ptr<::Observables::Observable> observable() const override {
123 return m_observable;
124 }
125
126private:
127 std::shared_ptr<CoreObs> m_observable;
128};
129
130} /* namespace Observables */
131} /* namespace ScriptInterface */
Bind parameters in the script interface.
Base class for script interfaces to core observables classes.
std::shared_ptr<::Observables::Observable > observable() const override
Variant call_method(std::string const &method, VariantMap const &parameters) override
std::shared_ptr<::Observables::ProfileObservable > profile_observable() const
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
Recursive variant implementation.
Definition Variant.hpp:84