ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/constraints/ExternalPotential.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
27#include "couplings.hpp"
28#include "fields.hpp"
29
32
33#include <utils/Vector.hpp>
34
35#include <memory>
36#include <string>
37
38namespace ScriptInterface {
39namespace Constraints {
40template <typename Coupling, typename Field>
43
44public:
46 add_parameters(detail::coupling_parameters<Coupling>(
47 [this]() { return m_constraint->coupling(); }));
48 add_parameters(detail::field_parameters<Field>(
49 [this]() { return m_constraint->field(); }));
50 }
51
52 void do_construct(VariantMap const &args) override {
53 m_constraint = std::make_shared<CoreField>(
54 detail::make_coupling<Coupling>(args), detail::make_field<Field>(args));
55 }
56
57 Variant do_call_method(const std::string &name,
58 VariantMap const &args) override {
59 if (name == "_eval_field") {
60 return m_constraint->field()(get_value<Utils::Vector3d>(args, "x"),
61 get_value_or<double>(args, "t", 0.));
62 }
63 if (name == "_eval_jacobian") {
64 return m_constraint->field().jacobian(
65 get_value<Utils::Vector3d>(args, "x"));
66 }
67
68 return none;
69 }
70
71 std::shared_ptr<::Constraints::Constraint> constraint() override {
72 return std::static_pointer_cast<::Constraints::Constraint>(m_constraint);
73 }
74
75 std::shared_ptr<const ::Constraints::Constraint> constraint() const override {
76 return std::static_pointer_cast<::Constraints::Constraint>(m_constraint);
77 }
78
79private:
80 /* The actual constraint */
81 std::shared_ptr<CoreField> m_constraint;
82};
83} // namespace Constraints
84} // namespace ScriptInterface
Vector implementation and trait types for boost qvm interoperability.
Constraint interface for ExternalField::PotentialField.
void add_parameters(std::vector< AutoParameter > &&params)
std::shared_ptr< const ::Constraints::Constraint > constraint() const override
Variant do_call_method(const std::string &name, VariantMap const &args) override
std::shared_ptr<::Constraints::Constraint > constraint() override
boost::string_ref name() const
ScriptInterface implementations for the various couplings provided.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:82
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
Definition Variant.hpp:80
constexpr const None none
None-"literal".
Definition Variant.hpp:63