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.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
23
24#include <stdexcept>
25#include <vector>
26
27TabulatedPotential::TabulatedPotential(double minval, double maxval,
28 std::vector<double> const &force,
29 std::vector<double> const &energy)
30 : minval{minval}, maxval{maxval} {
31
32 if (minval > maxval) {
33 throw std::domain_error("TabulatedPotential parameter 'max' must be "
34 "larger than or equal to parameter 'min'");
35 }
36 if (minval != -1.) {
37 if (minval == maxval and force.size() != 1) {
38 throw std::domain_error(
39 "TabulatedPotential parameter 'force' must contain 1 element");
40 }
41 if (force.empty()) {
42 throw std::domain_error("TabulatedPotential parameter 'force' must "
43 "contain at least 1 element");
44 }
45 if (force.size() != energy.size()) {
46 throw std::invalid_argument("TabulatedPotential parameter 'force' must "
47 "have the same size as parameter 'energy'");
48 }
49 invstepsize = static_cast<double>(force.size() - 1) / (maxval - minval);
50 } else {
51 invstepsize = 0.;
52 }
55}
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