ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
magnetostatics/scafacos_impl.cpp
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#include "config/config.hpp"
23
24#ifdef SCAFACOS_DIPOLES
25
28
29#include "BoxGeometry.hpp"
31#include "communication.hpp"
32#include "system/System.hpp"
33
34#include <utils/Span.hpp>
35#include <utils/Vector.hpp>
36#include <utils/matrix.hpp>
37
38#include <cassert>
39#include <memory>
40#include <string>
41
42std::shared_ptr<DipolarScafacos>
43make_dipolar_scafacos(std::string const &method,
44 std::string const &parameters) {
45 return std::make_shared<DipolarScafacosImpl>(comm_cart, method, parameters);
46}
47
49 auto const &system = get_system();
50 auto const &box_geo = *system.box_geo;
51 auto const &cell_structure = *system.cell_structure;
52
53 positions.clear();
54 dipoles.clear();
55
56 for (auto const &p : cell_structure.local_particles()) {
57 auto const pos = box_geo.folded_position(p.pos());
58 positions.push_back(pos[0]);
59 positions.push_back(pos[1]);
60 positions.push_back(pos[2]);
61 auto const dip = p.calc_dip();
62 dipoles.push_back(dip[0]);
63 dipoles.push_back(dip[1]);
64 dipoles.push_back(dip[2]);
65 }
66}
67
69 if (positions.empty())
70 return;
71
72 auto const &cell_structure = *get_system().cell_structure;
73
74 auto it_potentials = potentials.begin();
75 auto it_f = std::size_t{0ul};
76 for (auto &p : cell_structure.local_particles()) {
77 // The scafacos term "potential" here in fact refers to the magnetic
78 // field. So, the torques are given by m \times B
79 auto const dip = p.calc_dip();
80 auto const t = vector_product(
81 dip, Utils::Vector3d(Utils::Span<const double>(&*it_potentials, 3)));
82 // The force is given by G m, where G is a matrix
83 // which comes from the "fields" output of scafacos like this
84 // 0 1 2
85 // 1 3 4
86 // 2 4 5
87 // where the numbers refer to indices in the "field" output from scafacos
88 auto const G = Utils::Matrix<double, 3, 3>{
89 {fields[it_f + 0ul], fields[it_f + 1ul], fields[it_f + 2ul]},
90 {fields[it_f + 1ul], fields[it_f + 3ul], fields[it_f + 4ul]},
91 {fields[it_f + 2ul], fields[it_f + 4ul], fields[it_f + 5ul]}};
92 auto const f = G * dip;
93
94 // Add to particles
95 p.force() += prefactor * f;
96 p.torque() += prefactor * t;
97 it_f += 6ul;
98 it_potentials += 3;
99 }
100
101 /* Check that the particle number did not change */
102 assert(it_potentials == potentials.end());
103}
104
105#endif // SCAFACOS_DIPOLES
Vector implementation and trait types for boost qvm interoperability.
float f[3]
__shared__ int pos[MAXDEPTH *THREADS5/WARPSIZE]
double prefactor
Magnetostatics prefactor.
A stripped-down version of std::span from C++17.
Definition Span.hpp:38
boost::mpi::communicator comm_cart
The communicator.
This file contains the defaults for ESPResSo.
__device__ void vector_product(float const *a, float const *b, float *out)
std::shared_ptr< DipolarScafacos > make_dipolar_scafacos(std::string const &method, std::string const &parameters)
Matrix implementation and trait types for boost qvm interoperability.
void update_particle_forces() const override
Matrix representation with static size.
Definition matrix.hpp:65