FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
driver_factory.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/cubature/scalar/rule.hpp>
10
11namespace FEAT
12{
13 namespace Cubature
14 {
15 namespace Scalar
16 {
18 namespace Intern
19 {
20 template<
21 typename Driver_,
22 bool variadic_ = Driver_::variadic>
23 class DriverFactoryAliasMapper;
24 } // namespace Intern
26
42 template<
43 typename Driver_,
44 bool variadic_ = Driver_::variadic>
45 class DriverFactory DOXY({});
46
52 template<typename Driver_>
53 class DriverFactory<Driver_, false>
54 {
55 public:
56 typedef Driver_ DriverType;
57
58 static constexpr bool variadic = false;
59 static constexpr bool tensorize = DriverType::tensorize;
60 static constexpr int num_points = DriverType::num_points;
61
62 public:
64 {
65 }
66
76 template<typename Weight_, typename Coord_>
77 static bool create(Rule<Weight_, Coord_>& rule)
78 {
79 // create the rule
80 rule = Rule<Weight_, Coord_>(DriverType::num_points, DriverType::name());
81 DriverType::fill(rule);
82 return true;
83 }
84
101 template<typename Weight_, typename Coord_>
102 static bool create(Rule<Weight_, Coord_>& rule, const String& name)
103 {
104 // map alias names
105 Intern::DriverFactoryAliasMapper<DriverType> mapper(name);
106 DriverType::alias(mapper);
107 String mapped_name(mapper.name());
108
109 // check mapped name
110 if(mapped_name.trim().compare_no_case(DriverType::name()) != 0)
111 return false;
112
113 // create the rule
114 return create(rule);
115 }
116
120 static String name()
121 {
122 return DriverType::name();
123 }
124
128 template<typename Functor_>
129 static void alias(Functor_& functor)
130 {
131 DriverType::alias(functor);
132 }
133 }; // class DriverFactory<...>
134
140 template<typename Driver_>
141 class DriverFactory<Driver_, true>
142 {
143 public:
144 typedef Driver_ DriverType;
145
146 static constexpr bool variadic = true;
147 static constexpr bool tensorize = DriverType::tensorize;
148 static constexpr int min_points = DriverType::min_points;
149 static constexpr int max_points = DriverType::max_points;
150
151 protected:
152 int _num_points;
153
154 public:
155 explicit DriverFactory(int num_points) :
156 _num_points(num_points)
157 {
158 XASSERT(num_points >= DriverType::min_points);
159 XASSERT(num_points <= DriverType::max_points);
160 }
161
168 template<typename Weight_, typename Coord_>
170 {
171 return create(rule, _num_points);
172 }
173
183 template<typename Weight_, typename Coord_>
184 static bool create(Rule<Weight_, Coord_>& rule, int num_points)
185 {
186 if((num_points < DriverType::min_points) || (num_points > DriverType::max_points))
187 return false;
188
189 rule = Rule<Weight_, Coord_>(num_points, (DriverType::name() + ":" + stringify(num_points)));
190 DriverType::fill(rule, num_points);
191 return true;
192 }
193
210 template<typename Weight_, typename Coord_>
211 static bool create(Rule<Weight_, Coord_>& rule, const String& name_in)
212 {
213 // map alias names
214 Intern::DriverFactoryAliasMapper<DriverType> mapper(name_in);
215 DriverType::alias(mapper);
216 String mapped_name(mapper.name());
217
218 // try to find a colon within the string
219 String::size_type k = mapped_name.find_first_of(':');
220 if(k == mapped_name.npos)
221 return false;
222
223 // extract substrings until the colon
224 String head(mapped_name.substr(0, k));
225 String tail(mapped_name.substr(k + 1));
226
227 // check head - this is the name of the formula
228 if(head.trim().compare_no_case(DriverType::name()) != 0)
229 return false;
230
231 // check substring
232 int num_points = 0;
233 if(!tail.trim().parse(num_points))
234 return false;
235
236 // try to create the rule
237 return create(rule, num_points);
238 }
239
243 static String name()
244 {
245 return DriverType::name();
246 }
247
251 template<typename Functor_>
252 static void alias(Functor_& functor)
253 {
254 DriverType::alias(functor);
255 }
256 }; // class DriverFactory<...>
257
259 namespace Intern
260 {
261 template<typename Driver_>
262 class DriverFactoryAliasMapper<Driver_, false>
263 {
264 private:
265 String _name;
266 bool _mapped;
267
268 public:
269 explicit DriverFactoryAliasMapper(const String& name_in) :
270 _name(name_in),
271 _mapped(false)
272 {
273 }
274
275 void alias(const String& alias_name)
276 {
277 if(!_mapped)
278 {
279 if(_name.compare_no_case(alias_name) == 0)
280 {
281 _name = Driver_::name();
282 _mapped = true;
283 }
284 }
285 }
286
287 String name()
288 {
289 return _name;
290 }
291 };
292
293 template<typename Driver_>
294 class DriverFactoryAliasMapper<Driver_, true>
295 {
296 private:
297 String _name;
298 bool _mapped;
299
300 public:
301 explicit DriverFactoryAliasMapper(const String& name_in) :
302 _name(name_in),
303 _mapped(false)
304 {
305 }
306
307 void alias(const String& alias_name, int num_points)
308 {
309 if(!_mapped)
310 {
311 if(_name.compare_no_case(alias_name) == 0)
312 {
313 _name = Driver_::name() + ":" + stringify(num_points);
314 _mapped = true;
315 }
316 }
317 }
318
319 String name()
320 {
321 return _name;
322 }
323 };
324 } // namespace Intern
326 } // namespace Scalar
327 } // namespace Cubature
328} // namespace FEAT
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
static bool create(Rule< Weight_, Coord_ > &rule)
Creates the cubature rule.
static bool create(Rule< Weight_, Coord_ > &rule, const String &name)
Creates the cubature rule from a string.
static void alias(Functor_ &functor)
Calls the driver's alias function.
static String name()
Returns the name of the cubature rule.
bool create(Rule< Weight_, Coord_ > &rule)
Creates the cubature rule.
static bool create(Rule< Weight_, Coord_ > &rule, int num_points)
Creates the cubature rule.
static void alias(Functor_ &functor)
Calls the driver's alias function.
static bool create(Rule< Weight_, Coord_ > &rule, const String &name_in)
Creates the cubature rule from a string.
static String name()
Returns the name of the cubature rule.
Scalar Cubature Driver-Factory class template.
Scalar Cubature Rule class template.
Definition: rule.hpp:39
String class implementation.
Definition: string.hpp:46
bool parse(T_ &t) const
Parses the string and stores its value in the provided variable.
Definition: string.hpp:837
int compare_no_case(const String &other) const
Compares two strings without regard to case.
Definition: string.hpp:679
String trim(const String &charset) const
Trims the string.
Definition: string.hpp:327
FEAT namespace.
Definition: adjactor.hpp:12
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:944