ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
StokesianDynamics.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022-2025 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <config/config.hpp>
21
22#ifdef ESPRESSO_STOKESIAN_DYNAMICS
23
24#include "StokesianDynamics.hpp"
25
27
28#include "core/BoxGeometry.hpp"
32
33#include <memory>
34#include <stdexcept>
35#include <string>
36
37namespace ScriptInterface {
38namespace Integrators {
39
42 {"viscosity", AutoParameter::read_only,
43 [this]() { return get_instance().viscosity; }},
45 [this]() {
47 }},
48 {"lubrication", AutoParameter::read_only,
49 [this]() {
50 return static_cast<bool>(get_instance().flags &
51 static_cast<int>(sd_flags::LUBRICATION));
52 }},
53 {"self_mobility", AutoParameter::read_only,
54 [this]() {
55 return static_cast<bool>(get_instance().flags &
56 static_cast<int>(sd_flags::SELF_MOBILITY));
57 }},
58 {"pair_mobility", AutoParameter::read_only,
59 [this]() {
60 return static_cast<bool>(get_instance().flags &
61 static_cast<int>(sd_flags::PAIR_MOBILITY));
62 }},
63 {"approximation_method", AutoParameter::read_only,
64 [this]() {
65 return std::string(
66 (get_instance().flags & static_cast<int>(sd_flags::FTS)) ? "fts"
67 : "ft");
68 }},
69 });
70}
71
73 context()->parallel_try_catch([&]() {
74 int bitfield = 0;
75 if (get_value_or<bool>(params, "self_mobility", true)) {
76 bitfield |= static_cast<int>(sd_flags::SELF_MOBILITY);
77 }
78 if (get_value_or<bool>(params, "pair_mobility", true)) {
79 bitfield |= static_cast<int>(sd_flags::PAIR_MOBILITY);
80 }
81 auto const approx =
82 get_value_or<std::string>(params, "approximation_method", "fts");
83 if (approx == "fts") {
84 bitfield |= static_cast<int>(sd_flags::FTS);
85 } else if (approx != "ft") {
86 throw std::invalid_argument("Unknown approximation '" + approx + "'");
87 }
88 m_instance = std::make_shared<::StokesianDynamics>(
89 get_value<double>(params, "viscosity"),
90 get_value<std::unordered_map<int, double>>(params, "radii"), bitfield);
91 });
92}
93
95 context()->parallel_try_catch([&]() {
96 auto &system = get_system();
97 auto const &box_geo = *system.box_geo;
98 if (box_geo.periodic(0) or box_geo.periodic(1) or box_geo.periodic(2)) {
99 throw std::runtime_error(
100 "Stokesian Dynamics requires periodicity (False, False, False)");
101 }
102 system.stokesian_dynamics = m_instance;
103 system.propagation->set_integ_switch(INTEG_METHOD_SD);
104 });
105}
106
107} // namespace Integrators
108} // namespace ScriptInterface
109
110#endif // ESPRESSO_STOKESIAN_DYNAMICS
@ INTEG_METHOD_SD
void add_parameters(std::vector< AutoParameter > &&params)
::StokesianDynamics const & get_instance() const
void do_construct(VariantMap const &params) override
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
auto make_unordered_map_of_variants(std::unordered_map< K, V > const &v)
Definition Variant.hpp:144
See for the Stokesian dynamics method used here.
static constexpr const ReadOnly read_only