ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
dlc.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 "config/config.hpp"
25
26#ifdef DIPOLES
27
28#include "actor/traits.hpp"
29
33
34#include <ParticleRange.hpp>
35
36#include <memory>
37#include <variant>
38
40
41namespace traits {
42template <>
43struct is_layer_correction<DipolarLayerCorrection> : std::true_type {};
44} // namespace traits
45
46/** @brief Parameters for the DLC method */
47struct dlc_data {
48 dlc_data(double maxPWerror, double gap_size, double far_cut);
49
50 /** maximal pairwise error of the potential and force */
51 double maxPWerror;
52
53 /** Size of the empty gap. Note that MDLC relies on the user to make sure
54 * that this condition is fulfilled.
55 */
56 double gap_size;
57
58 /** Up to where particles can be found */
59 double box_h;
60
61 /** Cutoff of the exponential sum. Since in all other MMM methods this is
62 * the far formula, we call it here the same, although in the ELC context
63 * it does not make much sense.
64 */
65 double far_cut;
66
67 /** Flag whether #far_cut was set by the user, or calculated by ESPResSo.
68 * In the latter case, the cutoff will be adapted if important parameters,
69 * such as the box dimensions, change.
70 */
72};
73
74/**
75 * @brief Adapt a magnetostatics solver to remove contributions from the
76 * z-direction. For details see @cite brodka04a.
77 */
78struct DipolarLayerCorrection : public Dipoles::Actor<DipolarLayerCorrection> {
79 using BaseSolver = std::variant<
80#ifdef DP3M
81 std::shared_ptr<DipolarP3M>,
82#endif
83 std::shared_ptr<DipolarDirectSum>>;
84
85 /** @name Variables from the adapted solver. */
86 /**@{*/
87 double prefactor;
88 double epsilon;
90 /**@}*/
92
93 /** Magnetostatics solver that is adapted. */
95
96 DipolarLayerCorrection(dlc_data &&parameters, BaseSolver &&solver);
97
99 visit_base_solver(
100 [this](auto &solver) { solver->bind_system(m_system.lock()); });
101 sanity_checks_node_grid();
102 /* None of the DLC parameters depend on the DP3M parameters,
103 * but the DP3M parameters depend on the DLC parameters during tuning,
104 * therefore DLC needs to be tuned before DP3M. */
105 recalc_box_h();
107 visit_base_solver([](auto &solver) { solver->on_activation(); });
108 }
109 /** @brief Recalculate all box-length-dependent parameters. */
111 recalc_box_h();
113 visit_base_solver([](auto &actor) { actor->on_boxl_change(); });
114 }
115 void on_node_grid_change() const {
116 sanity_checks_node_grid();
117 visit_base_solver([](auto &solver) { solver->on_node_grid_change(); });
118 }
120 visit_base_solver([](auto &solver) { solver->on_periodicity_change(); });
121 }
123 visit_base_solver([](auto &solver) { solver->on_cell_structure_change(); });
124 }
125 void init() {
126 recalc_box_h();
128 visit_base_solver([](auto &solver) { solver->init(); });
129 }
130
131 void sanity_checks() const {
132 sanity_checks_node_grid();
133 visit_base_solver([](auto &actor) { actor->sanity_checks(); });
134 }
135
136 void recalc_box_h();
138 if (dlc.far_calculated) {
139 dlc.far_cut = tune_far_cut();
140 }
141 }
142
143 /** @brief Calculate the dipolar energy correction. */
144 double energy_correction(ParticleRange const &particles) const;
145 /** @brief Add the dipolar force and torque corrections. */
146 void add_force_corrections(ParticleRange const &particles) const;
147
148 void adapt_solver();
149
151 prefactor = -1.;
152 epsilon = -1.;
154 }
155
156private:
157 /** Check if a magnetic particle is in the gap region. */
158 void check_gap(Particle const &p) const;
159 double tune_far_cut() const;
160
161 void sanity_checks_node_grid() const;
162
163 template <class Visitor> void visit_base_solver(Visitor &&visitor) const {
164 std::visit(visitor, base_solver);
165 }
166};
167
168#endif // DIPOLES
A range of particles.
std::weak_ptr< System > m_system
This file contains the defaults for ESPResSo.
P3M algorithm for long-range magnetic dipole-dipole interaction.
Adapt a magnetostatics solver to remove contributions from the z-direction.
Definition dlc.hpp:78
double epsilon_correction
Definition dlc.hpp:89
double energy_correction(ParticleRange const &particles) const
Calculate the dipolar energy correction.
Definition dlc.cpp:356
void sanity_checks() const
Definition dlc.hpp:131
BaseSolver base_solver
Magnetostatics solver that is adapted.
Definition dlc.hpp:94
void on_node_grid_change() const
Definition dlc.hpp:115
void on_periodicity_change() const
Definition dlc.hpp:119
void add_force_corrections(ParticleRange const &particles) const
Add the dipolar force and torque corrections.
Definition dlc.cpp:304
std::variant< std::shared_ptr< DipolarP3M >, std::shared_ptr< DipolarDirectSum > > BaseSolver
Definition dlc.hpp:83
void on_cell_structure_change() const
Definition dlc.hpp:122
void on_boxl_change()
Recalculate all box-length-dependent parameters.
Definition dlc.hpp:110
Struct holding all information for one particle.
Definition Particle.hpp:395
Parameters for the DLC method.
Definition dlc.hpp:47
bool far_calculated
Flag whether far_cut was set by the user, or calculated by ESPResSo.
Definition dlc.hpp:71
double maxPWerror
maximal pairwise error of the potential and force
Definition dlc.hpp:51
double far_cut
Cutoff of the exponential sum.
Definition dlc.hpp:65
double gap_size
Size of the empty gap.
Definition dlc.hpp:56
double box_h
Up to where particles can be found.
Definition dlc.hpp:59
Whether an actor is a layer correction method.
Definition traits.hpp:26