FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
rule.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
9#include <kernel/shape.hpp>
10#include <kernel/util/tiny_algebra.hpp>
11
12// includes, system
13#include <vector>
14
15namespace FEAT
16{
20 namespace Cubature
21 {
22 enum CtorFactory
23 {
24 ctor_factory
25 };
26
32 template<
33 typename Shape_,
34 typename Weight_ = Real,
35 typename Coord_ = Real,
36 typename Point_ = Tiny::Vector<Coord_, Shape_::dimension>>
37 class Rule
38 {
39 public:
40 typedef Shape_ ShapeType;
41 typedef Weight_ WeightType;
42 typedef Coord_ CoordType;
43 typedef Point_ PointType;
44 static constexpr int dimension = ShapeType::dimension;
45
46 protected:
47 String _name;
48 int _num_points;
49 std::vector<WeightType> _weights;
50 std::vector<PointType> _points;
51
52 public:
53 Rule() :
54 _name(),
55 _num_points(0)
56 {
57 }
58
59 explicit Rule(int num_points, const String& name) :
60 _name(name),
61 _num_points(num_points)
62 {
63 if(num_points > 0)
64 {
65 _weights.resize(std::size_t(num_points));
66 _points.resize(std::size_t(num_points));
67 }
68 }
69
70 template<typename Factory_>
71 Rule(CtorFactory, const Factory_& factory) :
72 _name(),
73 _num_points(0)
74 {
75 factory.create_throw(*this);
76 }
77
79 Rule(Rule&& other) :
80 _name(other._name),
81 _num_points(other._num_points),
82 _weights(std::forward<std::vector<WeightType>>(other._weights)),
83 _points(std::forward<std::vector<PointType>>(other._points))
84 {
85 other._name.clear();
86 other._num_points = 0;
87 }
88
91 {
92 // avoid self-move
93 if(this == &other)
94 return *this;
95
96 _name = other._name;
97 _num_points = other._num_points;
98 _weights = std::forward<std::vector<WeightType>>(other._weights);
99 _points = std::forward<std::vector<PointType>>(other._points);
100
101 other._name.clear();
102 other._num_points = 0;
103
104 return *this;
105 }
106
107 virtual ~Rule()
108 {
109 }
110
111 Rule clone() const
112 {
113 Rule rule(_num_points, _name);
114 rule._weights = this->_weights;
115 rule._points = this->_points;
116 return rule;
117 }
118
119 const String& get_name() const
120 {
121 return _name;
122 }
123
124 int get_num_points() const
125 {
126 return _num_points;
127 }
128
129 WeightType& get_weight(int i)
130 {
131 ASSERT(i < _num_points);
132 return _weights[std::size_t(i)];
133 }
134
135 WeightType* get_weights()
136 {
137 return _weights.data();
138 }
139
140 const WeightType& get_weight(int i) const
141 {
142 ASSERT(i < _num_points);
143 return _weights[std::size_t(i)];
144 }
145
146 const WeightType* get_weights() const
147 {
148 return _weights.data();
149 }
150
151 PointType& get_point(int i)
152 {
153 ASSERT(i < _num_points);
154 return _points[std::size_t(i)];
155 }
156
157 PointType* get_points()
158 {
159 return _points.data();
160 }
161
162 const PointType& get_point(int i) const
163 {
164 ASSERT(i < _num_points);
165 return _points[std::size_t(i)];
166 }
167
168 const PointType* get_points() const
169 {
170 return _points;
171 }
172
173 CoordType& get_coord(int i, int j)
174 {
175 ASSERTM((i >= 0) && (i < _num_points), "point index i out-of-range");
176 ASSERTM((j >= 0) && (j < dimension), "coord index j out-of-range");
177 return _points[std::size_t(i)][j];
178 }
179
180 const CoordType& get_coord(int i, int j) const
181 {
182 ASSERTM((i >= 0) && (i < _num_points), "point index i out-of-range");
183 ASSERTM((j >= 0) && (j < dimension), "coord index j out-of-range");
184 return _points[std::size_t(i)][j];
185 }
186 }; // class Rule<...>
187 } // namespace Cubature
188} // namespace FEAT
#define ASSERT(expr)
Debug-Assertion macro definition.
Definition: assertion.hpp:229
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
Definition: assertion.hpp:230
Cubature Rule class template.
Definition: rule.hpp:38
Rule(Rule &&other)
move ctor
Definition: rule.hpp:79
Rule & operator=(Rule &&other)
move-assign operator
Definition: rule.hpp:90
String class implementation.
Definition: string.hpp:46
FEAT namespace.
Definition: adjactor.hpp:12
double Real
Real data type.