ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
couplings.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 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#pragma once
21
22/**
23 * @file
24 * @brief ScriptInterface implementations for the
25 * various couplings provided.
26 *
27 * These are separated from the Constraints because
28 * they can be reused together with the couplings themselves.
29 */
30
36
38
39#include <unordered_map>
40#include <vector>
41
42namespace ScriptInterface {
43namespace Constraints {
44namespace detail {
45using namespace ::FieldCoupling::Coupling;
46
47/**
48 * Default version for parameterless couplings.
49 */
50template <typename Coupling> struct coupling_parameters_impl {
51 static Coupling make(const VariantMap &) { return Coupling{}; }
52 template <typename This>
53 static std::vector<AutoParameter> params(const This &) {
54 return {};
55 }
56};
57
58template <> struct coupling_parameters_impl<Viscous> {
59 template <typename This>
60 static std::vector<AutoParameter> params(const This &this_) {
61 return {{
62 "gamma",
64 [this_]() { return this_().gamma(); },
65 }};
66 }
67};
68
69template <> struct coupling_parameters_impl<Scaled> {
70 template <typename This>
71 static std::vector<AutoParameter> params(const This &this_) {
72 return {{
73 "default_scale",
75 [this_]() { return this_().default_scale(); },
76 },
77 {"particle_scales", AutoParameter::read_only, [this_]() {
78 return make_unordered_map_of_variants(this_().particle_scales());
79 }}};
80 }
81};
82
83template <typename Coupling, typename This>
84static std::vector<AutoParameter> coupling_parameters(const This &this_) {
85 return coupling_parameters_impl<Coupling>::params(this_);
86}
87
88template <typename T> T make_coupling(const VariantMap &) { return T{}; }
89template <> inline Viscous make_coupling<Viscous>(const VariantMap &params) {
90 return Viscous{get_value<double>(params, "gamma")};
91}
92
93template <> inline Scaled make_coupling<Scaled>(const VariantMap &params) {
94 return Scaled{get_value_or<std::unordered_map<int, double>>(
95 params, "particle_scales", {}),
96 get_value<double>(params, "default_scale")};
97}
98} // namespace detail
99} // namespace Constraints
100} // namespace ScriptInterface
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:69
auto make_unordered_map_of_variants(std::unordered_map< K, V > const &v)
Definition Variant.hpp:80
static SteepestDescentParameters params
Currently active steepest descent instance.
static constexpr const ReadOnly read_only