Loading [MathJax]/extensions/TeX/AMSmath.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
Coulomb.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/Coulomb.hpp"
21
22#include "utils.hpp"
23
24#include <fcs.h>
25
26#include <stdexcept>
27#include <string>
28#include <utility>
29#include <vector>
30
31namespace Scafacos {
32
33Coulomb::Coulomb(MPI_Comm comm, std::string method, std::string parameters)
34 : Scafacos{comm, std::move(method), std::move(parameters)} {
35 fcs_int near_field_delegation;
36 fcs_get_near_field_delegation(m_handle, &near_field_delegation);
37 m_method_can_delegate_near_field = static_cast<bool>(near_field_delegation);
38 m_delegate_near_field = m_method_can_delegate_near_field;
39}
40
41void Coulomb::set_runtime_parameters(double const *const box_l,
42 int const *const periodicity,
43 int const total_particles) {
44 auto const near_field_flag = get_near_field_flag();
45 Scafacos::set_runtime_parameters(box_l, periodicity, total_particles,
46 near_field_flag);
47}
48
50 if (delegate != m_delegate_near_field) {
51 if (delegate and not m_method_can_delegate_near_field) {
52 throw std::runtime_error("Method '" + get_method() +
53 "' cannot delegate short-range calculation");
54 }
55 m_delegate_near_field = delegate;
56 auto const near_field_flag = get_near_field_flag();
57 handle_error(fcs_set_near_field_flag(m_handle, near_field_flag));
58 }
59}
60
61double Coulomb::r_cut() const {
62 if (m_delegate_near_field) {
63 fcs_float r_cut;
64 fcs_get_r_cut(m_handle, &r_cut);
65 return r_cut;
66 }
67 return 0.0;
68}
69
70void Coulomb::set_r_cut(double r_cut) {
71 if (m_delegate_near_field) {
72 fcs_set_r_cut(m_handle, r_cut);
73 }
74}
75
76void Coulomb::run(std::vector<double> &charges, std::vector<double> &positions,
77 std::vector<double> &fields,
78 std::vector<double> &potentials) {
79
80 auto const n_part = charges.size();
81 fields.resize(3ul * n_part);
82 potentials.resize(n_part);
83
84 tune(charges, positions);
85 auto const size = static_cast<int>(n_part);
86 handle_error(fcs_run(m_handle, size, positions.data(), charges.data(),
87 fields.data(), potentials.data()));
88}
89
90void Coulomb::tune(std::vector<double> &charges,
91 std::vector<double> &positions) {
92 auto const n_part = charges.size();
93 auto const size = static_cast<int>(n_part);
94 handle_error(fcs_tune(m_handle, size, positions.data(), charges.data()));
95}
96
97} // namespace Scafacos
#define handle_error(stmt)
void run(std::vector< double > &charges, std::vector< double > &positions, std::vector< double > &fields, std::vector< double > &potentials)
Calculate the fields and potentials for charges.
Definition Coulomb.cpp:76
void set_near_field_delegation(bool delegate)
Delegate the short-range calculation.
Definition Coulomb.cpp:49
void tune(std::vector< double > &charges, std::vector< double > &positions)
Tune parameters.
Definition Coulomb.cpp:90
void set_r_cut(double r_cut)
Set short-range cutoff.
Definition Coulomb.cpp:70
Coulomb(MPI_Comm comm, std::string method, std::string parameters)
Definition Coulomb.cpp:33
double r_cut() const
Get short-range cutoff (0.0 if not supported by the method).
Definition Coulomb.cpp:61
void set_runtime_parameters(double const *box_l, int const *periodicity, int total_particles)
Set box geometry and number of particles.
Definition Coulomb.cpp:41
void set_runtime_parameters(double const *box_l, int const *periodicity, int total_particles, int near_field_flag)
Set box geometry, number of particles and calculation type.
Definition Scafacos.cpp:85
std::string get_method() const
Get active method name.
Definition Scafacos.hpp:40
FCS m_handle
Handle from the library.
Definition Scafacos.hpp:51