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