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
30
#include "
magnetostatics/actor.hpp
"
31
#include "
magnetostatics/dipolar_direct_sum.hpp
"
32
#include "
magnetostatics/dp3m.hpp
"
33
34
#include <
ParticleRange.hpp
>
35
36
#include <memory>
37
#include <variant>
38
39
struct
DipolarLayerCorrection
;
40
41
namespace
traits
{
42
template
<>
43
struct
is_layer_correction
<
DipolarLayerCorrection
> : std::true_type {};
44
}
// namespace traits
45
46
/** @brief Parameters for the DLC method */
47
struct
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
*/
71
bool
far_calculated
;
72
};
73
74
/**
75
* @brief Adapt a magnetostatics solver to remove contributions from the
76
* z-direction. For details see @cite brodka04a.
77
*/
78
struct
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
;
89
double
epsilon_correction
;
90
/**@}*/
91
dlc_data
dlc
;
92
93
/** Magnetostatics solver that is adapted. */
94
BaseSolver
base_solver
;
95
96
DipolarLayerCorrection
(
dlc_data
&¶meters,
BaseSolver
&&solver);
97
98
void
on_activation
() {
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
();
106
recalc_far_cut
();
107
visit_base_solver([](
auto
&solver) { solver->on_activation(); });
108
}
109
/** @brief Recalculate all box-length-dependent parameters. */
110
void
on_boxl_change
() {
111
recalc_box_h
();
112
recalc_far_cut
();
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
}
119
void
on_periodicity_change
()
const
{
120
visit_base_solver([](
auto
&solver) { solver->on_periodicity_change(); });
121
}
122
void
on_cell_structure_change
()
const
{
123
visit_base_solver([](
auto
&solver) { solver->on_cell_structure_change(); });
124
}
125
void
init
() {
126
recalc_box_h
();
127
recalc_far_cut
();
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
();
137
void
recalc_far_cut
() {
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
150
void
release_solver
() {
151
prefactor
= -1.;
152
epsilon
= -1.;
153
epsilon_correction
= 0.;
154
}
155
156
private
:
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
ParticleRange.hpp
Dipoles::Actor
Definition
magnetostatics/actor.hpp:32
ParticleRange
A range of particles.
Definition
ParticleRange.hpp:38
System::Leaf::m_system
std::weak_ptr< System > m_system
Definition
core/system/Leaf.hpp:36
config.hpp
This file contains the defaults for ESPResSo.
dipolar_direct_sum.hpp
dp3m.hpp
P3M algorithm for long-range magnetic dipole-dipole interaction.
actor.hpp
traits
Definition
traits.hpp:24
DipolarLayerCorrection
Adapt a magnetostatics solver to remove contributions from the z-direction.
Definition
dlc.hpp:78
DipolarLayerCorrection::dlc
dlc_data dlc
Definition
dlc.hpp:91
DipolarLayerCorrection::release_solver
void release_solver()
Definition
dlc.hpp:150
DipolarLayerCorrection::epsilon
double epsilon
Definition
dlc.hpp:88
DipolarLayerCorrection::epsilon_correction
double epsilon_correction
Definition
dlc.hpp:89
DipolarLayerCorrection::energy_correction
double energy_correction(ParticleRange const &particles) const
Calculate the dipolar energy correction.
Definition
dlc.cpp:356
DipolarLayerCorrection::recalc_far_cut
void recalc_far_cut()
Definition
dlc.hpp:137
DipolarLayerCorrection::on_activation
void on_activation()
Definition
dlc.hpp:98
DipolarLayerCorrection::sanity_checks
void sanity_checks() const
Definition
dlc.hpp:131
DipolarLayerCorrection::base_solver
BaseSolver base_solver
Magnetostatics solver that is adapted.
Definition
dlc.hpp:94
DipolarLayerCorrection::on_node_grid_change
void on_node_grid_change() const
Definition
dlc.hpp:115
DipolarLayerCorrection::on_periodicity_change
void on_periodicity_change() const
Definition
dlc.hpp:119
DipolarLayerCorrection::add_force_corrections
void add_force_corrections(ParticleRange const &particles) const
Add the dipolar force and torque corrections.
Definition
dlc.cpp:304
DipolarLayerCorrection::adapt_solver
void adapt_solver()
Definition
dlc.cpp:476
DipolarLayerCorrection::init
void init()
Definition
dlc.hpp:125
DipolarLayerCorrection::prefactor
double prefactor
Definition
dlc.hpp:87
DipolarLayerCorrection::recalc_box_h
void recalc_box_h()
Definition
dlc.cpp:504
DipolarLayerCorrection::BaseSolver
std::variant< std::shared_ptr< DipolarP3M >, std::shared_ptr< DipolarDirectSum > > BaseSolver
Definition
dlc.hpp:83
DipolarLayerCorrection::on_cell_structure_change
void on_cell_structure_change() const
Definition
dlc.hpp:122
DipolarLayerCorrection::on_boxl_change
void on_boxl_change()
Recalculate all box-length-dependent parameters.
Definition
dlc.hpp:110
Particle
Struct holding all information for one particle.
Definition
Particle.hpp:395
dlc_data
Parameters for the DLC method.
Definition
dlc.hpp:47
dlc_data::far_calculated
bool far_calculated
Flag whether far_cut was set by the user, or calculated by ESPResSo.
Definition
dlc.hpp:71
dlc_data::maxPWerror
double maxPWerror
maximal pairwise error of the potential and force
Definition
dlc.hpp:51
dlc_data::far_cut
double far_cut
Cutoff of the exponential sum.
Definition
dlc.hpp:65
dlc_data::gap_size
double gap_size
Size of the empty gap.
Definition
dlc.hpp:56
dlc_data::box_h
double box_h
Up to where particles can be found.
Definition
dlc.hpp:59
traits::is_layer_correction
Whether an actor is a layer correction method.
Definition
traits.hpp:26
traits.hpp
src
core
magnetostatics
dlc.hpp
Generated on Fri Nov 22 2024 02:13:54 for ESPResSo by
1.9.8