OpenMD 3.1
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 appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
45#ifndef MATH_INTEGRATION_LEGENDREGAUSS1D_HPP
46#define MATH_INTEGRATION_LEGENDREGAUSS1D_HPP
47
48namespace OpenMD {
49
50 template<class returnType, class argumentType>
52 public:
53 LegendreGauss1d(size_t points);
54 virtual ~LegendreGauss1d();
55 virtual returnType integrand(const argumentType& r) const = 0;
56 virtual returnType integral(const argumentType& rmin,
57 const argumentType& rmax,
58 RealType length) const;
59
60 std::vector<RealType> xi;
61 std::vector<RealType> w;
62 size_t points;
63
64 protected:
65 };
66
67 struct LegendreGauss1dParams : public LegendreGauss1d<RealType, RealType> {
68 public:
69 LegendreGauss1dParams(size_t points) :
71
72 virtual RealType integrand(const RealType& r) const { return 0; };
73
74 private:
75 };
76
77 template<class returnType, class argumentType>
79 points(p) {
80 xi.resize(points);
81 w.resize(points);
82 switch (points) {
83 case 1:
84 xi[0] = 0.0;
85 w[0] = 2.0;
86 break;
87 case 2:
88 xi[0] = 1.0 / sqrt(3.);
89 xi[1] = -xi[0];
90 w[0] = 1.0;
91 w[1] = w[0];
92 break;
93 case 3:
94 xi[0] = 0.0;
95 xi[1] = sqrt(0.6);
96 xi[2] = -xi[1];
97 w[0] = 8.0 / 9.0;
98 w[1] = 5.0 / 9.0;
99 w[2] = w[1];
100 break;
101 case 4:
102 xi[0] = 0.861136;
103 xi[1] = -xi[0];
104 xi[2] = 0.339981;
105 xi[3] = -xi[2];
106 w[0] = 0.347855;
107 w[1] = w[0];
108 w[2] = 0.652145;
109 w[3] = w[2];
110 break;
111 case 5:
112 xi[0] = 0;
113 xi[1] = 0.906180;
114 xi[2] = -xi[1];
115 xi[3] = 0.538469;
116 xi[4] = -xi[3];
117 w[0] = 0.568889;
118 w[1] = 0.236927;
119 w[2] = w[1];
120 w[3] = 0.478629;
121 w[4] = w[3];
122 break;
123 case 6:
124 xi[0] = 0.932470;
125 xi[1] = -xi[0];
126 xi[2] = 0.661209;
127 xi[3] = -xi[2];
128 xi[4] = 0.238619;
129 xi[5] = -xi[4];
130 w[0] = 0.171324;
131 w[1] = w[0];
132 w[2] = 0.360702;
133 w[3] = w[2];
134 w[4] = 0.467914;
135 w[5] = w[4];
136 break;
137 default:
138 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
139 "LegendreGauss1d does not implement a %d point algorithm\n",
140 points);
141 painCave.isFatal = 1;
142 ;
143 simError();
144 }
145 }
146
147 template<class returnType, class argumentType>
148 LegendreGauss1d<returnType, argumentType>::~LegendreGauss1d() {
149 xi.clear();
150 xi.shrink_to_fit();
151 w.clear();
152 w.shrink_to_fit();
153 }
154
155 template<class returnType, class argumentType>
156 returnType LegendreGauss1d<returnType, argumentType>::integral(
157 const argumentType& rmin, const argumentType& rmax,
158 RealType length) const {
159 returnType s(0);
160 for (size_t i = 0; i < points; i++) {
161 argumentType r = 0.5 * ((xi[i] + 1.0) * rmax + (1.0 - xi[i]) * rmin);
162 s + = integrand(r) * w[i];
163 }
164 return 0.5 * length * s;
165 }
166} // namespace OpenMD
167#endif // MATH_INTEGRATION_LEGENDREGAUSS1D_HPP
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.