OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
LegendreGauss1d.hpp
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the following paper when you publish your work:
33 *
34 * [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35 *
36 * Good starting points for code and simulation methodology are:
37 *
38 * [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39 * [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40 * [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43 * [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45 * [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46 */
47
48#ifndef MATH_INTEGRATION_LEGENDREGAUSS1D_HPP
49#define MATH_INTEGRATION_LEGENDREGAUSS1D_HPP
50
51namespace OpenMD {
52
53 template<class returnType, class argumentType>
54 class LegendreGauss1d {
55 public:
56 LegendreGauss1d(size_t points);
57 virtual ~LegendreGauss1d();
58 virtual returnType integrand(const argumentType& r) const = 0;
59 virtual returnType integral(const argumentType& rmin,
60 const argumentType& rmax,
61 RealType length) const;
62
63 std::vector<RealType> xi;
64 std::vector<RealType> w;
65 size_t points;
66
67 protected:
68 };
69
70 struct LegendreGauss1dParams : public LegendreGauss1d<RealType, RealType> {
71 public:
72 LegendreGauss1dParams(size_t points) :
73 LegendreGauss1dParams<RealType, RealType>(points) {};
74
75 virtual RealType integrand(const RealType& r) const { return 0; };
76
77 private:
78 };
79
80 template<class returnType, class argumentType>
81 LegendreGauss1d<returnType, argumentType>::LegendreGauss1d(size_t p) :
82 points(p) {
83 xi.resize(points);
84 w.resize(points);
85 switch (points) {
86 case 1:
87 xi[0] = 0.0;
88 w[0] = 2.0;
89 break;
90 case 2:
91 xi[0] = 1.0 / sqrt(3.);
92 xi[1] = -xi[0];
93 w[0] = 1.0;
94 w[1] = w[0];
95 break;
96 case 3:
97 xi[0] = 0.0;
98 xi[1] = sqrt(0.6);
99 xi[2] = -xi[1];
100 w[0] = 8.0 / 9.0;
101 w[1] = 5.0 / 9.0;
102 w[2] = w[1];
103 break;
104 case 4:
105 xi[0] = 0.861136;
106 xi[1] = -xi[0];
107 xi[2] = 0.339981;
108 xi[3] = -xi[2];
109 w[0] = 0.347855;
110 w[1] = w[0];
111 w[2] = 0.652145;
112 w[3] = w[2];
113 break;
114 case 5:
115 xi[0] = 0;
116 xi[1] = 0.906180;
117 xi[2] = -xi[1];
118 xi[3] = 0.538469;
119 xi[4] = -xi[3];
120 w[0] = 0.568889;
121 w[1] = 0.236927;
122 w[2] = w[1];
123 w[3] = 0.478629;
124 w[4] = w[3];
125 break;
126 case 6:
127 xi[0] = 0.932470;
128 xi[1] = -xi[0];
129 xi[2] = 0.661209;
130 xi[3] = -xi[2];
131 xi[4] = 0.238619;
132 xi[5] = -xi[4];
133 w[0] = 0.171324;
134 w[1] = w[0];
135 w[2] = 0.360702;
136 w[3] = w[2];
137 w[4] = 0.467914;
138 w[5] = w[4];
139 break;
140 default:
141 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
142 "LegendreGauss1d does not implement a %d point algorithm\n",
143 points);
144 painCave.isFatal = 1;
145 ;
146 simError();
147 }
148 }
149
150 template<class returnType, class argumentType>
151 LegendreGauss1d<returnType, argumentType>::~LegendreGauss1d() {
152 xi.clear();
153 xi.shrink_to_fit();
154 w.clear();
155 w.shrink_to_fit();
156 }
157
158 template<class returnType, class argumentType>
159 returnType LegendreGauss1d<returnType, argumentType>::integral(
160 const argumentType& rmin, const argumentType& rmax,
161 RealType length) const {
162 returnType s(0);
163 for (size_t i = 0; i < points; i++) {
164 argumentType r = 0.5 * ((xi[i] + 1.0) * rmax + (1.0 - xi[i]) * rmin);
165 s + = integrand(r) * w[i];
166 }
167 return 0.5 * length * s;
168 }
169} // namespace OpenMD
170#endif // MATH_INTEGRATION_LEGENDREGAUSS1D_HPP
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.