ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/constraints/ShapeBasedConstraint.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 "Constraint.hpp"
25
26#include "core/BoxGeometry.hpp"
31
33
34#include <memory>
35#include <string>
36
37namespace ScriptInterface {
38namespace Constraints {
39
41 std::unique_ptr<VariantMap> m_params;
42 std::weak_ptr<::System::System const> m_system;
43
44public:
46 : m_constraint(std::make_shared<::Constraints::ShapeBasedConstraint>()),
47 m_shape(nullptr) {
48 auto system = ::System::get_system().shared_from_this();
49 m_constraint->bind_system(system);
50 m_system = system;
51 add_parameters({{"only_positive", m_constraint->only_positive()},
52 {"penetrable", m_constraint->penetrable()},
53 {"particle_type",
54 [this](Variant const &value) {
55 m_constraint->set_type(get_value<int>(value));
56 },
57 [this]() { return m_constraint->type(); }},
58 {"shape",
59 [this](Variant const &value) {
60 m_shape =
62 if (m_shape) {
63 m_constraint->set_shape(m_shape->shape());
64 }
65 },
66 [this]() { return m_shape; }},
67 {"particle_velocity", m_constraint->velocity()}});
68 }
69
70 Variant do_call_method(std::string const &name, VariantMap const &) override {
71 if (name == "total_force") {
72 return shape_based_constraint()->total_force();
73 }
74 if (name == "min_dist") {
75 auto const system = m_system.lock();
77 return shape_based_constraint()->min_dist(
78 *system->box_geo, system->cell_structure->local_particles());
79 }
80 if (name == "total_normal_force") {
81 return shape_based_constraint()->total_normal_force();
82 }
83
84 return none;
85 }
86
87 std::shared_ptr<::Constraints::Constraint> constraint() override {
88 return std::static_pointer_cast<::Constraints::Constraint>(m_constraint);
89 }
90 std::shared_ptr<const ::Constraints::Constraint> constraint() const override {
91 return std::static_pointer_cast<::Constraints::Constraint>(m_constraint);
92 }
93 std::shared_ptr<::Constraints::ShapeBasedConstraint>
95 return m_constraint;
96 }
97
98 void do_construct(VariantMap const &params) override {
99 m_params = std::make_unique<VariantMap>(params);
100 for (auto const &kv : *m_params) {
101 do_set_parameter(kv.first, kv.second);
102 }
103 }
104
105 void
106 bind_system(std::shared_ptr<::System::System const> const &system) override {
107 assert(m_params);
108 assert(system);
109 m_system = system;
110 shape_based_constraint()->bind_system(system);
111 for (auto const &kv : *m_params) {
112 do_set_parameter(kv.first, kv.second);
113 }
114 m_params.reset();
115 }
116
117private:
118 /* The actual constraint */
119 std::shared_ptr<::Constraints::ShapeBasedConstraint> m_constraint;
120
121 /* Keep a reference to the shape */
122 std::shared_ptr<Shapes::Shape> m_shape;
123};
124
125} // namespace Constraints
126} // namespace ScriptInterface
void do_set_parameter(const std::string &name, const Variant &value) final
void add_parameters(std::vector< AutoParameter > &&params)
std::shared_ptr< const ::Constraints::Constraint > constraint() const override
std::shared_ptr<::Constraints::ShapeBasedConstraint > shape_based_constraint() const
void bind_system(std::shared_ptr<::System::System const > const &system) override
Variant do_call_method(std::string const &name, VariantMap const &) override
boost::string_ref name() 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: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
System & get_system()
static SteepestDescentParameters params
Currently active steepest descent instance.