ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ek/Solver.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 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#include "ek/Implementation.hpp"
23#include "ek/Solver.hpp"
24#include "ek/utils.hpp"
25
26#include "ek/EKNone.hpp"
27#include "ek/EKWalberla.hpp"
28
29#include "system/System.hpp"
30
31#include <utils/Vector.hpp>
32
33#include <cassert>
34#include <cmath>
35#include <limits>
36#include <memory>
37#include <optional>
38#include <stdexcept>
39#include <string>
40#include <tuple>
41#include <variant>
42#include <vector>
43
44namespace EK {
45
46Solver::Solver() { impl = std::make_unique<Implementation>(); }
47
48static auto is_solver_set(std::unique_ptr<Solver::Implementation> const &ptr) {
49 return ptr != nullptr and ptr->solver.has_value();
50}
51
52static void check_solver(std::unique_ptr<Solver::Implementation> const &ptr) {
53 if (not is_solver_set(ptr)) {
54 throw NoEKActive{};
55 }
56}
57
58bool Solver::is_solver_set() const { return EK::is_solver_set(impl); }
59
60void Solver::reset() { System::get_system().ek.impl->solver = std::nullopt; }
61
63 return is_solver_set() and
64 std::visit([](auto &ptr) { return ptr->is_ready_for_propagation(); },
65 *impl->solver);
66}
67
69 check_solver(impl);
70 std::visit([](auto &ptr) { ptr->propagate(); }, *impl->solver);
71}
72
74 if (impl->solver) {
75 auto const &system = get_system();
76 std::visit([&](auto &ptr) { ptr->sanity_checks(system); }, *impl->solver);
77 }
78}
79
80void Solver::veto_time_step(double time_step) const {
81 if (impl->solver) {
82 std::visit([=](auto &ptr) { ptr->veto_time_step(time_step); },
83 *impl->solver);
84 }
85}
86
87void Solver::veto_kT(double kT) const {
88 if (impl->solver) {
89 std::visit([=](auto &ptr) { ptr->veto_kT(kT); }, *impl->solver);
90 }
91}
92
94 if (impl->solver) {
95 std::visit([](auto const &ptr) { ptr->veto_boxl_change(); }, *impl->solver);
96 }
97}
98
100 if (impl->solver) {
101 auto &solver = *impl->solver;
102 std::visit([](auto &ptr) { ptr->on_cell_structure_change(); }, solver);
103 }
104}
105
107 if (impl->solver) {
108 std::visit([](auto &ptr) { ptr->on_boxl_change(); }, *impl->solver);
109 }
110}
111
113 if (impl->solver) {
114 std::visit([](auto &ptr) { ptr->on_node_grid_change(); }, *impl->solver);
115 }
116}
117
119 if (impl->solver) {
120 std::visit([](auto &ptr) { ptr->on_timestep_change(); }, *impl->solver);
121 }
122}
123
125 if (impl->solver) {
126 std::visit([](auto &ptr) { ptr->on_temperature_change(); }, *impl->solver);
127 }
128}
129
130double Solver::get_tau() const {
131 check_solver(impl);
132 return std::visit([](auto &ptr) { return ptr->get_tau(); }, *impl->solver);
133}
134
135template <> void Solver::set<EKNone>(std::shared_ptr<EKNone> ek_instance) {
136 assert(impl);
137 assert(not impl->solver.has_value());
138 impl->solver = ek_instance;
139}
140
141#ifdef WALBERLA
142template <>
143void Solver::set<EKWalberla>(std::shared_ptr<EKWalberla> ek_instance) {
144 assert(impl);
145 assert(not impl->solver.has_value());
146 auto const &system = get_system();
147 ek_instance->sanity_checks(system);
148 impl->solver = ek_instance;
149}
150#endif // WALBERLA
151
152} // namespace EK
Vector implementation and trait types for boost qvm interoperability.
This file contains the defaults for ESPResSo.
static auto is_solver_set(std::unique_ptr< Solver::Implementation > const &ptr)
Definition ek/Solver.cpp:48
static void check_solver(std::unique_ptr< Solver::Implementation > const &ptr)
Definition ek/Solver.cpp:52
System & get_system()
void veto_time_step(double time_step) const
Check if a MD time step is compatible with the EK tau.
Definition ek/Solver.cpp:80
void on_boxl_change()
void on_node_grid_change()
void propagate()
Propagate the EK species.
Definition ek/Solver.cpp:68
void sanity_checks() const
Perform EK parameter checks.
Definition ek/Solver.cpp:73
void on_cell_structure_change()
Definition ek/Solver.cpp:99
void veto_boxl_change() const
Definition ek/Solver.cpp:93
bool is_ready_for_propagation() const
Return true if an EK solver can be propagated.
Definition ek/Solver.cpp:62
double get_tau() const
Get the EK time step.
void on_timestep_change()
void on_temperature_change()
void veto_kT(double kT) const
Check if a thermostat is compatible with the EK temperature.
Definition ek/Solver.cpp:87
void reset()
Remove the EK solver.
Definition ek/Solver.cpp:60
bool is_solver_set() const
Return true if an EK solver is active.
Definition ek/Solver.cpp:58