ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
Coulomb.hpp
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#ifndef ESPRESSO_SRC_SCAFACOS_COULOMB_HPP
21#define ESPRESSO_SRC_SCAFACOS_COULOMB_HPP
22
23#include "scafacos/Scafacos.hpp"
24
25#include <fcs.h>
26
27#include <mpi.h>
28
29#include <string>
30#include <vector>
31
32namespace Scafacos {
33
34/** @brief Abstraction of a Coulomb method from the ScaFaCoS library. */
35struct Coulomb : public Scafacos {
36 Coulomb(MPI_Comm comm, std::string method, std::string parameters);
37
38 /** @brief Set box geometry and number of particles. */
39 void set_runtime_parameters(double const *box_l, int const *periodicity,
40 int total_particles);
41
42 /** @brief Calculate the fields and potentials for charges. */
43 void run(std::vector<double> &charges, std::vector<double> &positions,
44 std::vector<double> &fields, std::vector<double> &potentials);
45
46 /**
47 * @brief Delegate the short-range calculation.
48 * By default, ESPResSo calculates the short-range forces and energies
49 * if the chosen ScaFaCoS method support delegation. This decision can
50 * be overriden to obtain the result from a full ScaFaCos calculation.
51 * @param delegate Delegate short-range calculation to ESPResSo if true,
52 * or to ScaFaCoS if false.
53 */
54 void set_near_field_delegation(bool delegate);
55
56 bool get_near_field_delegation() const { return m_delegate_near_field; }
57
58 /** @brief Calculate short-range pair force. */
59 double pair_force(double dist) const {
60 if (m_delegate_near_field) {
61 fcs_float field;
62 fcs_compute_near_field(m_handle, dist, &field);
63 return field;
64 }
65
66 return 0.0;
67 }
68
69 /** @brief Calculate short-range pair energy. */
70 double pair_energy(double dist) const {
71 if (m_delegate_near_field) {
72 fcs_float potential;
73 fcs_compute_near_potential(m_handle, dist, &potential);
74 return potential;
75 }
76
77 return 0.0;
78 }
79
80 /** @brief Tune parameters */
81 void tune(std::vector<double> &charges, std::vector<double> &positions);
82 /** @brief Get short-range cutoff (0.0 if not supported by the method). */
83 double r_cut() const;
84 /** @brief Set short-range cutoff */
85 void set_r_cut(double r_cut);
86
87private:
88 auto get_near_field_flag() const {
89 return static_cast<fcs_int>((m_delegate_near_field) ? 0 : 1);
90 }
91
92 /** Whether the method supports delegating the short-range calculation. */
93 bool m_method_can_delegate_near_field;
94 /** Whether to delegate short-range calculation to ESPResSo. */
95 bool m_delegate_near_field;
96};
97
98} // namespace Scafacos
99#endif
double pair_force(double dist) const
Calculate short-range pair force.
Definition Coulomb.hpp:59
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
bool get_near_field_delegation() const
Definition Coulomb.hpp:56
void set_r_cut(double r_cut)
Set short-range cutoff.
Definition Coulomb.cpp:70
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
double pair_energy(double dist) const
Calculate short-range pair energy.
Definition Coulomb.hpp:70
FCS m_handle
Handle from the library.
Definition Scafacos.hpp:51