OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
GaussianTriangleQuadrature.hpp
1// Note that this code is mostly from the Drake project: https://drake.mit.edu/
2// and is governed by their BSD 3-Clause license:
3// https://github.com/RobotLocomotion/drake/blob/master/LICENSE.TXT
4// Only minor modifications have been made to make it work in OpenMD.
5
6#ifndef MATH_INTEGRATION_GAUSSIANTRIANGLEQUADRATURERULE_HPP
7#define MATH_INTEGRATION_GAUSSIANTRIANGLEQUADRATURERULE_HPP
8
9#include <stdexcept>
10#include <vector>
11
12#include "math/integration/TriangleQuadratureRule.hpp"
13
14namespace OpenMD {
15
17 public:
18 /// Constructs the Gaussian quadrature rule of the specified order, which
19 /// must be between 1 and 5.
20 explicit GaussianTriangleQuadratureRule(int order) : order_(order) {
21 assert(order >= 1);
22 if (order > 5) {
23 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
24 "GaussianTriangleQuadrature does not implement a %d point "
25 "algorithm\n",
26 order);
27 painCave.isFatal = 1;
28 ;
29 simError();
30 }
31 SetWeightsAndQuadraturePoints();
32 }
33
34 private:
35 // Sets the weights and quadrature points depending on the order of the
36 // quadrature rule. Weights and quadrature points for the rational numbers
37 // were taken from pp. 8-9 of:
38 // http://math2.uncc.edu/~shaodeng/TEACHING/math5172/Lectures/Lect_15.PDF
39 // Weights and quadrature points for decimal numbers were taken from p. 1140
40 // of:
41 // D. A. Dunavant. High degree efficient symmetrical Gaussian quadrature
42 // rules for the triangle. Intl. J. Num. Meth. Eng. pp. 1129-1148, 1985.
43 void SetWeightsAndQuadraturePoints() {
44 switch (order_) {
45 case 1:
46 weights_.resize(1);
47 quadrature_points_.resize(1);
48 weights_[0] = 1.0;
49 quadrature_points_[0] = Vector2d(1.0 / 3.0, 1.0 / 3.0);
50 break;
51
52 case 2:
53 weights_.resize(3);
54 quadrature_points_.resize(3);
55 weights_[0] = weights_[1] = weights_[2] = 1.0 / 3.0;
56 quadrature_points_[0] = Vector2d(1.0 / 6.0, 1.0 / 6.0);
57 quadrature_points_[1] = Vector2d(1.0 / 6.0, 2.0 / 3.0);
58 quadrature_points_[2] = Vector2d(2.0 / 3.0, 1.0 / 6.0);
59 break;
60
61 case 3:
62 weights_.resize(4);
63 quadrature_points_.resize(4);
64 weights_[0] = -27.0 / 48.0;
65 weights_[1] = weights_[2] = weights_[3] = 25.0 / 48.0;
66 quadrature_points_[0] = Vector2d(1.0 / 3.0, 1.0 / 3.0);
67 quadrature_points_[1] = Vector2d(1.0 / 5.0, 1.0 / 5.0);
68 quadrature_points_[2] = Vector2d(1.0 / 5.0, 3.0 / 5.0);
69 quadrature_points_[3] = Vector2d(3.0 / 5.0, 1.0 / 5.0);
70 break;
71
72 case 4:
73 weights_.resize(6);
74 quadrature_points_.resize(6);
75 weights_[0] = weights_[1] = weights_[2] = 0.223381589678011;
76 weights_[3] = weights_[4] = weights_[5] = 0.109951743655322;
77 quadrature_points_[0] = Vector2d(0.445948490915965, 0.445948490915965);
78 quadrature_points_[1] = Vector2d(0.445948490915965, 0.108103018168070);
79 quadrature_points_[2] = Vector2d(0.108103018168070, 0.445948490915965);
80 quadrature_points_[3] = Vector2d(0.091576213509771, 0.091576213509771);
81 quadrature_points_[4] = Vector2d(0.091576213509771, 0.816847572980459);
82 quadrature_points_[5] = Vector2d(0.816847572980459, 0.091576213509771);
83 break;
84
85 case 5:
86 weights_.resize(7);
87 quadrature_points_.resize(7);
88 weights_[0] = 0.225;
89 weights_[1] = weights_[2] = weights_[3] = 0.132394152788506;
90 weights_[4] = weights_[5] = weights_[6] = 0.125939180544827;
91 quadrature_points_[0] = Vector2d(1.0 / 3.0, 1.0 / 3.0);
92 quadrature_points_[1] = Vector2d(0.470142064105115, 0.470142064105115);
93 quadrature_points_[2] = Vector2d(0.470142064105115, 0.059715871789770);
94 quadrature_points_[3] = Vector2d(0.059715871789770, 0.470142064105115);
95 quadrature_points_[4] = Vector2d(0.101286507323456, 0.101286507323456);
96 quadrature_points_[5] = Vector2d(0.101286507323456, 0.797426985353087);
97 quadrature_points_[6] = Vector2d(0.797426985353087, 0.101286507323456);
98 break;
99
100 default:
101 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
102 "GaussianTriangleQuadrature does not implement a %d point "
103 "algorithm\n",
104 order_);
105 painCave.isFatal = 1;
106 ;
107 simError();
108 }
109 }
110
111 int do_order() const final { return order_; }
112
113 const std::vector<RealType>& do_weights() const final { return weights_; }
114
115 const std::vector<Vector2d>& do_quadrature_points() const final {
116 return quadrature_points_;
117 }
118
119 const int order_ {-1};
120 std::vector<RealType> weights_;
121 std::vector<Vector2d> quadrature_points_;
122 };
123
124} // namespace OpenMD
125#endif
GaussianTriangleQuadratureRule(int order)
Constructs the Gaussian quadrature rule of the specified order, which must be between 1 and 5.
A "rule" (weights and quadrature points) for computing quadrature over triangular domains.
int order() const
Returns the order of this rule.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.