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
10#include <kernel/util/string.hpp>
11
12// includes, system
13#include <vector>
14
15namespace FEAT
16{
17 namespace Cubature
18 {
22 namespace Scalar
23 {
35 template<
36 typename Weight_ = Real,
37 typename Coord_ = Real>
38 class Rule
39 {
40 public:
42 typedef Weight_ WeightType;
44 typedef Coord_ CoordType;
45
46 protected:
52 std::vector<WeightType> _weights;
54 std::vector<CoordType> _coords;
55
56 public:
58 Rule() :
59 _name(),
61 {
62 }
63
75 explicit Rule(int num_points, String name) :
76 _name(name),
77 _num_points(num_points)
78 {
79 if(num_points > 0)
80 {
81 _weights.resize(std::size_t(num_points));
82 _coords.resize(std::size_t(num_points));
83 }
84 }
85
87 Rule(Rule&& other) :
88 _name(other._name),
90 _weights(std::forward<std::vector<WeightType>>(other._weights)),
91 _coords(std::forward<std::vector<CoordType>>(other._coords))
92 {
93 other._name.clear();
94 other._num_points = 0;
95 }
96
99 {
100 // avoid self-move
101 if(this == &other)
102 return *this;
103
104 _name = other._name;
105 _num_points = other._num_points;
106 _weights = std::forward<std::vector<WeightType>>(other._weights);
107 _coords = std::forward<std::vector<CoordType>>(other._coords);
108
109 other._name.clear();
110 other._num_points = 0;
111
112 return *this;
113 }
114
116 virtual ~Rule()
117 {
118 }
119
120 Rule clone() const
121 {
122 Rule rule(_num_points, _name);
123 rule._weights = this->_weights;
124 rule._coords = this->_coords;
125 return rule;
126 }
127
128 const String& get_name() const
129 {
130 return _name;
131 }
132
133 int get_num_points() const
134 {
135 return _num_points;
136 }
137
138 WeightType& get_weight(int i)
139 {
140 ASSERTM(i < _num_points, "weight index out-of-range");
141 return _weights[std::size_t(i)];
142 }
143
144 const WeightType& get_weight(int i) const
145 {
146 ASSERTM(i < _num_points, "weight index out-of-range");
147 return _weights[std::size_t(i)];
148 }
149
150 CoordType& get_coord(int i)
151 {
152 ASSERTM(i < _num_points, "point index out-of-range");
153 return _coords[std::size_t(i)];
154 }
155
156 const CoordType& get_coord(int i) const
157 {
158 ASSERTM(i < _num_points, "point index out-of-range");
159 return _coords[std::size_t(i)];
160 }
161 }; // class Rule<...>
162 } // namespace Scalar
163 } // namespace Cubature
164} // namespace FEAT
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
Definition: assertion.hpp:230
Scalar Cubature Rule class template.
Definition: rule.hpp:39
int _num_points
The total number of points in the cubature rule.
Definition: rule.hpp:50
String _name
The name of the cubature rule.
Definition: rule.hpp:48
virtual ~Rule()
virtual destructor
Definition: rule.hpp:116
Rule(int num_points, String name)
Constructor.
Definition: rule.hpp:75
std::vector< CoordType > _coords
Cubature point coordinates array.
Definition: rule.hpp:54
Rule & operator=(Rule &&other)
move-assign operator
Definition: rule.hpp:98
Coord_ CoordType
Coord typedef.
Definition: rule.hpp:44
Rule()
default constructor
Definition: rule.hpp:58
Weight_ WeightType
Weight typedef.
Definition: rule.hpp:42
Rule(Rule &&other)
move ctor
Definition: rule.hpp:87
std::vector< WeightType > _weights
Cubature weights array.
Definition: rule.hpp:52
String class implementation.
Definition: string.hpp:46
FEAT namespace.
Definition: adjactor.hpp:12
double Real
Real data type.