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/rule.hpp>
10
11namespace FEAT
12{
13 namespace Cubature
14 {
16 namespace Intern
17 {
18 template<
19 typename Driver_,
20 bool variadic_ = Driver_::variadic>
21 class DriverFactoryAliasMapper;
22 } // namespace Intern
24
43 template<
44 template<typename> class Driver_,
45 typename Shape_,
46 bool variadic_ = Driver_<Shape_>::variadic>
47 class DriverFactory DOXY({});
48
54 template<
55 template<typename> class Driver_,
56 typename Shape_>
57 class DriverFactory<Driver_, Shape_, false>
58 {
59 public:
60 typedef Driver_<Shape_> DriverType;
61 typedef Shape_ ShapeType;
62 static constexpr bool variadic = false;
63 static constexpr int num_points = DriverType::num_points;
64
65 public:
67 {
68 }
69
79 template<typename Weight_, typename Coord_, typename Point_>
81 {
82 rule = Rule<Shape_, Weight_, Coord_, Point_>(DriverType::num_points, DriverType::name());
83 DriverType::fill(rule);
84 return true;
85 }
86
103 template<typename Weight_, typename Coord_, typename Point_>
105 {
106 // map alias names
107 Intern::DriverFactoryAliasMapper<DriverType> mapper(name);
108 DriverType::alias(mapper);
109 String mapped_name(mapper.name());
110
111 // check mapped name
112 if(mapped_name.trim().compare_no_case(DriverType::name()) != 0)
113 return false;
114
115 // create the rule
116 return create(rule);
117 }
118
122 static String name()
123 {
124 return DriverType::name();
125 }
126
130 template<typename Functor_>
131 static void alias(Functor_& functor)
132 {
133 DriverType::alias(functor);
134 }
135 }; // class DriverFactory<...,false>
136
142 template<
143 template<typename> class Driver_,
144 typename Shape_>
145 class DriverFactory<Driver_, Shape_, true>
146 {
147 public:
148 typedef Driver_<Shape_> DriverType;
149 typedef Shape_ ShapeType;
150 static constexpr bool variadic = true;
151 static constexpr int min_points = DriverType::min_points;
152 static constexpr int max_points = DriverType::max_points;
153
154 protected:
155 int _num_points;
156
157 public:
158 explicit DriverFactory(int num_points) :
159 _num_points(num_points)
160 {
161 XASSERT(num_points >= DriverType::min_points);
162 XASSERT(num_points <= DriverType::max_points);
163 }
164
171 template<typename Weight_, typename Coord_, typename Point_>
173 {
174 return create(rule, _num_points);
175 }
176
186 template<typename Weight_, typename Coord_, typename Point_>
187 static bool create(Rule<Shape_, Weight_, Coord_, Point_>& rule, int num_points)
188 {
189 if((num_points < DriverType::min_points) || (num_points > DriverType::max_points))
190 return false;
191
192 rule = Rule<Shape_, Weight_, Coord_, Point_>(DriverType::count(num_points),
193 (DriverType::name() + ":" + stringify(num_points)));
194 DriverType::fill(rule, num_points);
195 return true;
196 }
197
214 template<typename Weight_, typename Coord_, typename Point_>
216 {
217 // map alias names
218 Intern::DriverFactoryAliasMapper<DriverType> mapper(name);
219 DriverType::alias(mapper);
220 String mapped_name(mapper.name());
221
222 // try to find a colon within the string
223 String::size_type k = mapped_name.find_first_of(':');
224 if(k == mapped_name.npos)
225 return false;
226
227 // extract substrings until the colon
228 String head(mapped_name.substr(0, k));
229 String tail(mapped_name.substr(k + 1));
230
231 // check head - this is the name of the formula
232 if(head.trim().compare_no_case(DriverType::name()) != 0)
233 return false;
234
235 // check substring
236 int num_points(0);
237 if(!tail.trim().parse(num_points))
238 return false;
239
240 // try to create the rule
241 return create(rule, num_points);
242 }
243
247 static String name()
248 {
249 return DriverType::name();
250 }
251
255 template<typename Functor_>
256 static void alias(Functor_& functor)
257 {
258 DriverType::alias(functor);
259 }
260 }; // class DriverFactory<...,true>
261
263 namespace Intern
264 {
265 template<typename Driver_>
266 class DriverFactoryAliasMapper<Driver_, false>
267 {
268 private:
269 String _name;
270 bool _mapped;
271
272 public:
273 explicit DriverFactoryAliasMapper(const String& name_in) :
274 _name(name_in),
275 _mapped(false)
276 {
277 }
278
279 void alias(const String& alias_name)
280 {
281 if(!_mapped)
282 {
283 if(_name.compare_no_case(alias_name) == 0)
284 {
285 _name = Driver_::name();
286 _mapped = true;
287 }
288 }
289 }
290
291 String name()
292 {
293 return _name;
294 }
295 };
296
297 template<typename Driver_>
298 class DriverFactoryAliasMapper<Driver_, true>
299 {
300 private:
301 String _name;
302 bool _mapped;
303
304 public:
305 explicit DriverFactoryAliasMapper(const String& name_in) :
306 _name(name_in),
307 _mapped(false)
308 {
309 }
310
311 void alias(const String& alias_name, int num_points)
312 {
313 if(!_mapped)
314 {
315 if(_name.compare_no_case(alias_name) == 0)
316 {
317 _name = Driver_::name() + ":" + stringify(num_points);
318 _mapped = true;
319 }
320 }
321 }
322
323 String name()
324 {
325 return _name;
326 }
327 };
328 } // namespace Intern
330 } // namespace Cubature
331} // namespace FEAT
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
static bool create(Rule< Shape_, Weight_, Coord_, Point_ > &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.
static bool create(Rule< Shape_, Weight_, Coord_, Point_ > &rule)
Creates the cubature rule.
static String name()
Returns the name of the cubature rule.
static bool create(Rule< Shape_, Weight_, Coord_, Point_ > &rule, const String &name)
Creates the cubature rule from a string.
static bool create(Rule< Shape_, Weight_, Coord_, Point_ > &rule, int num_points)
Creates the cubature rule.
bool create(Rule< Shape_, Weight_, Coord_, Point_ > &rule)
Creates the cubature rule.
static void alias(Functor_ &functor)
Calls the driver's alias function.
Scalar Cubature Driver-Factory class template.
Cubature Rule class template.
Definition: rule.hpp:38
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