ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
dipoles.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-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_DIPOLES
23
25
26#include "actor/traits.hpp"
28#include "actor/visitors.hpp"
29#include "communication.hpp"
30#include "errorhandling.hpp"
32
33#include <utils/demangle.hpp>
34
35#include <cassert>
36#include <optional>
37#include <stdexcept>
38
39namespace Dipoles {
40
42 impl = std::make_unique<Implementation>();
44}
45
47 if (impl->solver) {
48 std::visit([](auto &ptr) { ptr->sanity_checks(); }, *impl->solver);
49 }
50}
51
54 if (impl->solver) {
55 visit_try_catch([](auto &ptr) { ptr->init(); }, *impl->solver);
56 }
57}
58
60 if (impl->solver) {
61 visit_try_catch([](auto &ptr) { ptr->on_boxl_change(); }, *impl->solver);
62 }
63}
64
66 if (impl->solver) {
67 std::visit([](auto &ptr) { ptr->on_node_grid_change(); }, *impl->solver);
68 }
69}
70
72 if (impl->solver) {
73 visit_try_catch([](auto &ptr) { ptr->on_periodicity_change(); },
74 *impl->solver);
75 }
76}
77
79 if (impl->solver) {
80 visit_try_catch([](auto &ptr) { ptr->on_cell_structure_change(); },
81 *impl->solver);
82 }
83}
84
85double Solver::cutoff() const {
86#ifdef ESPRESSO_DP3M
87 if (impl->solver) {
88 if (auto dp3m = get_actor_by_type<DipolarP3M>(impl->solver)) {
89 return dp3m->dp3m_params.r_cut;
90 }
91 }
92#endif
93 return inactive_cutoff;
94}
95
98#ifdef ESPRESSO_DP3M
99 if (impl->solver) {
100 if (auto dp3m = get_actor_by_type<DipolarP3M>(impl->solver)) {
101 dp3m->count_magnetic_particles();
102 }
103 }
104#endif
106 }
107}
108
110 template <class Solver>
111 void operator()(std::shared_ptr<Solver> const &actor) const {
112 actor->add_long_range_forces();
113 }
114};
115
117 template <class Solver>
118 double operator()(std::shared_ptr<Solver> const &actor) const {
119 return actor->long_range_energy();
120 }
121};
122
124 if (impl->solver) {
125 runtimeWarningMsg() << "pressure calculated, but pressure not implemented.";
126 }
127}
128
130 if (impl->solver) {
131 std::visit(LongRangeForce{}, *impl->solver);
132 }
133}
134
136 if (impl->solver) {
137 return std::visit(LongRangeEnergy{}, *impl->solver);
138 }
139 return 0.;
140}
141
142} // namespace Dipoles
143#endif // ESPRESSO_DIPOLES
constexpr double inactive_cutoff
Special cutoff value for an inactive interaction.
Definition config.hpp:53
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
#define runtimeWarningMsg()
double operator()(std::shared_ptr< Solver > const &actor) const
Definition dipoles.cpp:118
void operator()(std::shared_ptr< Solver > const &actor) const
Definition dipoles.cpp:111
void sanity_checks() const
Definition dipoles.cpp:46
double cutoff() const
Definition dipoles.cpp:85
void on_cell_structure_change()
Definition dipoles.cpp:78
std::unique_ptr< Implementation > impl
Pointer-to-implementation.
void on_boxl_change()
Definition dipoles.cpp:59
void on_periodicity_change()
Definition dipoles.cpp:71
void calc_pressure_long_range() const
Definition dipoles.cpp:123
bool reinit_on_observable_calc
Whether to reinitialize the solver on observable calculation.
void on_observable_calc()
Definition dipoles.cpp:96
void calc_long_range_force() const
Definition dipoles.cpp:129
void on_dipoles_change()
Definition dipoles.cpp:52
void on_node_grid_change()
Definition dipoles.cpp:65
double calc_energy_long_range() const
Definition dipoles.cpp:135
void visit_try_catch(Visitor &&visitor, Variant &actor)
Run a kernel on a variant and queue errors.