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-2022 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 "scafacos/Dipoles.hpp"
21
22#include "utils.hpp"
23
24#include <fcs.h>
25
26#include <cassert>
27#include <string>
28#include <utility>
29#include <vector>
30
31#ifdef FCS_ENABLE_DIPOLES
32
33namespace Scafacos {
34
35Dipoles::Dipoles(MPI_Comm comm, std::string method, std::string parameters)
36 : Scafacos{comm, std::move(method), std::move(parameters)} {}
37
38void Dipoles::set_runtime_parameters(double const *const box_l,
39 int const *const periodicity,
40 int const total_particles) {
41 // magnetostatics: ScaFaCoS calculates near field
42 auto const near_field_flag = fcs_int{1};
43 Scafacos::set_runtime_parameters(box_l, periodicity, total_particles,
44 near_field_flag);
45 handle_error(fcs_set_total_dipole_particles(m_handle, total_particles));
46}
47
48void Dipoles::run(std::vector<double> &dipoles, std::vector<double> &positions,
49 std::vector<double> &fields,
50 std::vector<double> &potentials) {
51
52 assert(dipoles.size() % 3ul == 0ul);
53
54 fields.resize(2ul * dipoles.size());
55 potentials.resize(dipoles.size());
56
57 auto const n_part = static_cast<int>(dipoles.size() / 3ul);
58 handle_error(fcs_set_dipole_particles(m_handle, n_part, positions.data(),
59 dipoles.data(), fields.data(),
60 potentials.data()));
61 handle_error(fcs_run(m_handle, 0, nullptr, nullptr, nullptr, nullptr));
62}
63
64} // namespace Scafacos
65
66#endif // FCS_ENABLE_DIPOLES
#define handle_error(stmt)