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
TabulatedPotential.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#ifndef CORE_TABULATED_POTENTIAL_HPP
20#define CORE_TABULATED_POTENTIAL_HPP
21
23
24#include <boost/serialization/access.hpp>
25#include <boost/serialization/vector.hpp>
26
27#include <algorithm>
28#include <vector>
29
30/** Evaluate forces and energies using a custom potential profile.
31 *
32 * Forces and energies are evaluated by linear interpolation. The curves
33 * @ref force_tab and @ref energy_tab must be sampled uniformly between
34 * @ref minval and @ref maxval.
35 */
37 /** Position on the x-axis of the first tabulated value. */
38 double minval = -1.0;
39 /** Position on the x-axis of the last tabulated value. */
40 double maxval = -1.0;
41 /** Inverse distance on the x-axis between tabulated values. */
42 double invstepsize = 0.0;
43 /** Tabulated forces. */
44 std::vector<double> force_tab;
45 /** Tabulated energies. */
46 std::vector<double> energy_tab;
47
48 TabulatedPotential() = default;
49 TabulatedPotential(double minval, double maxval,
50 std::vector<double> const &force,
51 std::vector<double> const &energy);
52
53 /** Evaluate the force at position @p x.
54 * @param x Bond length/angle
55 * @return Interpolated force.
56 */
57 double force(double x) const {
59 std::clamp(x, minval, maxval));
60 }
61
62 /** Evaluate the energy at position @p x.
63 * @param x Bond length/angle
64 * @return Interpolated energy.
65 */
66 double energy(double x) const {
68 std::clamp(x, minval, maxval));
69 }
70
71 double cutoff() const { return maxval; }
72};
73
74#endif
T linear_interpolation(Container const &table, T hi, T offset, T x)
Linear interpolation between two data points.
Evaluate forces and energies using a custom potential profile.
std::vector< double > force_tab
Tabulated forces.
double force(double x) const
Evaluate the force at position x.
double invstepsize
Inverse distance on the x-axis between tabulated values.
double maxval
Position on the x-axis of the last tabulated value.
double energy(double x) const
Evaluate the energy at position x.
std::vector< double > energy_tab
Tabulated energies.
double minval
Position on the x-axis of the first tabulated value.
TabulatedPotential()=default