FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
dynamic_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/factory_wrapper.hpp>
10#include <kernel/cubature/auto_alias.hpp>
12
13namespace FEAT
14{
15 namespace Cubature
16 {
18 public Exception
19 {
20 public:
21 explicit UnknownRule(const String & rule, const String& shape) :
22 Exception(String("Unknown cubature rule '") + rule + "' for shape " + shape)
23 {
24 }
25 virtual ~UnknownRule() noexcept
26 {
27 }
28 };
29
31 {
32 private:
33 String _name;
34
35 public:
37 {
38 }
39
40 explicit DynamicFactory(String name_) :
41 _name(name_)
42 {
43 }
44
45 DynamicFactory(const DynamicFactory& other) :
46 _name(other._name)
47 {
48 }
49
50 DynamicFactory& operator=(const DynamicFactory& other)
51 {
52 _name = other._name;
53 return *this;
54 }
55
56 const String& name() const
57 {
58 return _name;
59 }
60
61 template<typename Shape_, typename Weight_, typename Coord_, typename Point_>
62 void create_throw(Rule<Shape_, Weight_, Coord_, Point_>& rule) const
63 {
64 if(!create(rule, _name))
65 throw UnknownRule(_name, Shape_::name());
66 }
67
68 template<typename Shape_, typename Weight_, typename Coord_, typename Point_>
69 bool create(Rule<Shape_, Weight_, Coord_, Point_>& rule) const
70 {
71 return create(rule, _name);
72 }
73
74 template<typename Shape_, typename Weight_, typename Coord_, typename Point_>
75 static bool create(Rule<Shape_, Weight_, Coord_, Point_>& rule, const String& name)
76 {
77 // map auto-aliases
78 String mapped_name(AutoAlias<Shape_>::map(name));
79 CreateFunctor<Rule<Shape_, Weight_, Coord_, Point_> > functor(rule, mapped_name);
81 return functor.okay();
82 }
83
85 private:
86 template<typename Rule_>
87 class CreateFunctor
88 {
89 private:
90 Rule_& _rule;
91 const String& _name;
92 bool _okay;
93
94 public:
95 CreateFunctor(Rule_& rule, const String& name) :
96 _rule(rule),
97 _name(name),
98 _okay(false)
99 {
100 }
101
102 template<typename Factory_>
103 void factory()
104 {
105 if(!_okay)
106 {
107 _okay = Factory_::create(_rule, _name);
108 }
109 }
110
111 bool okay() const
112 {
113 return _okay;
114 }
115 };
117 }; // class DynamicFactory<...>
118
119#ifdef FEAT_EICKT
120 extern template bool DynamicFactory::create<Shape::Simplex<2>, Real, Real, Tiny::Vector<Real, 2, 2>>
122 extern template bool DynamicFactory::create<Shape::Simplex<3>, Real, Real, Tiny::Vector<Real, 3, 3>>
124 extern template bool DynamicFactory::create<Shape::Hypercube<2>, Real, Real, Tiny::Vector<Real, 2, 2>>
126 extern template bool DynamicFactory::create<Shape::Hypercube<3>, Real, Real, Tiny::Vector<Real, 3, 3>>
128#endif // FEAT_EICKT
129 } // namespace Cubature
130} // namespace FEAT
Generic Cubature Factory Wrapper class template.
Cubature Rule class template.
Definition: rule.hpp:38
Base exception class.
Definition: exception.hpp:27
String class implementation.
Definition: string.hpp:46
Tiny Vector class template.
FEAT namespace.
Definition: adjactor.hpp:12
double Real
Real data type.