Class documentation of Concepts

Loading...
Searching...
No Matches
elementFormula.hh
Go to the documentation of this file.
1
7#ifndef elementFormVector_hh
8#define elementFormVector_hh
9
10#include "toolbox/hashMap.hh"
11#include "formula/exceptions.hh"
12#include "geometry/cell.hh"
13#include "space/element.hh"
14#include "space/formula.hh"
15#include "function/vector.hh"
16
17#include "basics/debug.hh"
18
19#define ElmFormVectorBaseConstr_D 0
20
21
22namespace concepts {
23
24 template<typename F, typename G>
25 class ElementFunction; // declared in space/function.hh
26
27 // **************************************************** ElementFormulaBase **
28
39 template<typename F, class G, class H, class I>
41 public:
48 const ElementFunction<I,G>& f);
50 protected:
51 const Space<G>& spc_;
52 const Vector<F> v_;
54 std::unique_ptr<const ElementFunction<I,G> > f_;
55
56 mutable const Element<G> *lastElm_, *lastElmOur_;
57
58 mutable Array<F> coeff_;
59
61 template<typename J, typename P>
62 void compute_(const Element<G>& elm, Array<J>& val, const P& p,
63 const Real t = 0.0) const;
64 private:
66 std::unordered_map<uint, const Element<G>*> elementPointer_;
67
69 uint getKey_(const Element<G>& elm) const;
71 void getElement_(const Element<G>& elm, const Element<G>*& elmOur) const;
72 };
73
74 template<class F, class G, class H, class I>
76 (const Space<G>& spc, const Vector<F>& v, const ElementFunction<I,G>& f)
77 : spc_(spc), v_(v), f_(f.clone()), lastElm_(0), lastElmOur_(0), coeff_(0)
78 {
79 DEBUGL(ElmFormVectorBaseConstr_D, "start");
80 Scan<Element<G> >* sc = spc_.scan();
81 while (!sc->eos()) {
82 const Element<G>& elm = (*sc)++;
83 uint key = getKey_(elm);
84 elementPointer_.insert
85 (std::pair<uint, const Element<G>*>(key, &elm));
86 DEBUGL(ElmFormVectorBaseConstr_D,
87 "Inserted key = " << key << " -> elm = " << elm);
88 }
89 DEBUGL(ElmFormVectorBaseConstr_D, "done.");
90 }
91
92 template<class F, class G, class H, class I>
95 dynamic_cast<const ElementWithCell<G>*>(&elm);
97 const Cell& cell = elmC->cell();
98 uint key = cell.connector().key().key();
99 return key;
100 }
101
102 template<class F, class G, class H, class I>
103 void ElementFormulaVectorBase<F,G,H,I>::getElement_
104 (const Element<G>& elm, const Element<G>*& elmOur) const {
105 uint key = getKey_(elm);
106 typename std::unordered_map<uint, const Element<G>*>::const_iterator i =
107 elementPointer_.find(key);
108 if (i == elementPointer_.end())
109 throw(ElementNotInDomainOfFormula(elm)); // this
110
111 lastElmOur_ = elmOur = i->second;
112 lastElm_ = &elm;
113 }
114
115 template<class F, class G, class H, class I>
116 template<typename J, typename P>
118 (const Element<G>& elm, Array<J>& val, const P& p, const Real t) const {
119 const Element<G>* elmOur = 0;
120 getElement_(elm, elmOur);
122 DEBUGL(0, "elmOur = " << *elmOur);
123 DEBUGL(0, "v_ = " << v_);
124 elmOur->T().extract(v_, coeff_);
125 DEBUGL(0, "coeff_ = " << coeff_);
126 (*f_)(*elmOur, coeff_, val, p, t);
127 DEBUGL(0, "val = " << val);
128 }
129
130 // ********************************************* ElementFormulaVector<dim> **
131
142 template<uint dim, class F = Real, class G = F,
143 class H = typename Realtype<F>::type>
145 public ElementFormulaVectorBase<F,H,Point<G,dim>,G> {
146 public:
152 const ElementFunction<G,H>& f);
153 virtual Point<G,dim> operator() (const ElementWithCell<H>& elm,
154 const Real p, const Real t = 0.0) const;
155 virtual Point<G,dim> operator() (const ElementWithCell<H>& elm,
156 const Real2d& p, const Real t = 0.0) const;
157 virtual Point<G,dim> operator() (const ElementWithCell<H>& elm,
158 const Real3d& p, const Real t = 0.0) const;
159
161 return new ElementFormulaVector(this->spc_, this->v_, *this->f_);
162 }
163 protected:
164 virtual std::ostream& info(std::ostream& os) const;
165 };
166
167 template<uint dim, class F, class G, class H>
169 (const Space<H>& spc, const Vector<F>& v, const ElementFunction<G,H>& f) :
170 ElementFormulaVectorBase<F,H,Point<G,dim>,G>(spc, v, f)
171 {
172 conceptsAssert3(this->f_->n() == dim, Assertion(),
173 "not matching number of vector components of element function");
174 }
175
176 template<uint dim, class F, class G, class H>
178 (const ElementWithCell<H>& elm, const Real p, const Real t) const {
179 // get's function value
180 Array<G> val;
181 this->compute_(elm, val, p, t);
182 conceptsAssert(val.size() == dim, Assertion());
183 // copy it to a point
185 memorycpy((G*)res, (const G*)val, dim);
186 return res;
187 }
188
189 template<uint dim, class F, class G, class H>
190 Point<G,dim> ElementFormulaVector<dim,F,G,H>::operator()
191 (const ElementWithCell<H>& elm, const Real2d& p, const Real t) const {
192 // get's function value
193 Array<G> val;
194 this->compute_(elm, val, p, t);
195 conceptsAssert(val.size() == dim, Assertion());
196 // copy it to a point
198 memorycpy((G*)res, (const G*)val, dim);
199 return res;
200 }
201
202
203 template<uint dim, class F, class G, class H>
204 Point<G,dim> ElementFormulaVector<dim,F,G,H>::operator()
205 (const ElementWithCell<H>& elm, const Real3d& p, const Real t) const {
206 // get's function value
207 Array<G> val;
208 this->compute_(elm, val, p, t);
209 conceptsAssert(val.size() == dim, Assertion());
210 // copy it to a point
212 memorycpy((G*)res, (const G*)val, dim);
213 return res;
214 }
215
216 template<uint dim, class F, class G, class H>
217 std::ostream& ElementFormulaVector<dim,F,G,H>::info(std::ostream& os) const {
218 return os << concepts::typeOf(*this) << "(" << *this->f_ << ", "
219 << this->v_ << ")";
220 }
221
222 // *********************************************** ElementFormulaVector<1> **
223
229 template<class F, class G, class H>
230 class ElementFormulaVector<1,F,G,H> :
231 public ElementFormulaVectorBase<F,H,G,G> {
232 public:
238 ElementFormulaVector(const Space<H>& spc, const Vector<F>& v,
239 const ElementFunction<G,H>& f);
240 virtual G operator() (const ElementWithCell<H>& elm, const Real p,
241 const Real t = 0.0) const;
242 virtual G operator() (const ElementWithCell<H>& elm, const Real2d& p,
243 const Real t = 0.0) const;
244 virtual G operator() (const ElementWithCell<H>& elm, const Real3d& p,
245 const Real t = 0.0) const;
246
248 return new ElementFormulaVector(this->spc_, this->v_, *this->f_);
249 }
250 protected:
251 virtual std::ostream& info(std::ostream& os) const;
252 };
253
254 template<class F, class G, class H>
256 (const Space<H>& spc, const Vector<F>& v, const ElementFunction<G,H>& f) :
257 ElementFormulaVectorBase<F,H,G,G>(spc, v, f) {
258 conceptsAssert3(this->f_->n() == 1, Assertion(),
259 "only scalar element functions");
260 }
261
262 template<class F, class G, class H>
264 (const ElementWithCell<H>& elm, const Real p, const Real t) const {
266 this->compute_(elm, res, p, t);
267 return res[0];
268 }
269
270 template<class F, class G, class H>
271 G ElementFormulaVector<1,F,G,H>::operator()
272 (const ElementWithCell<H>& elm, const Real2d& p, const Real t) const {
273 Array<G> res;
274 this->compute_(elm, res, p, t);
275 return res[0];
276 }
277
278
279 template<class F, class G, class H>
280 G ElementFormulaVector<1,F,G,H>::operator()
281 (const ElementWithCell<H>& elm, const Real3d& p, const Real t) const {
282 Array<G> res;
283 this->compute_(elm, res, p, t);
284 return res[0];
285 }
286
287 template<class F, class G, class H>
288 std::ostream& ElementFormulaVector<1,F,G,H>::info(std::ostream& os) const {
289
290 return os << "ElementFormulaVector<1>(" << *this->f_ << ", " << this->v_
291 << ")";
292 }
293
294} // namespace concepts
295
296#endif // elementFormVector_hh
uint size() const
Returns the requested size of the array.
Definition array.hh:259
virtual Connector & connector() const =0
Returns the connector.
const Key & key() const
Returns the key of the connector.
Definition connector.hh:105
void compute_(const Element< G > &elm, Array< J > &val, const P &p, const Real t=0.0) const
Performs the computations.
std::unique_ptr< const ElementFunction< I, G > > f_
Element function.
ElementFormulaVectorBase(const Space< G > &spc, const Vector< F > &v, const ElementFunction< I, G > &f)
virtual ElementFormulaVectorBase< F, G, H, I > * clone() const =0
Virtual copy constructor.
virtual ElementFormulaVector< 1, F, G, H > * clone() const
Virtual copy constructor.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
ElementFormulaVector(const Space< H > &spc, const Vector< F > &v, const ElementFunction< G, H > &f)
virtual ElementFormulaVector< dim, F, G, H > * clone() const
Virtual copy constructor.
uint key() const
Returns the key.
Definition connector.hh:66
virtual Scanner * scan() const =0
Returns a scanner to iterate over the elements of the space.
#define conceptsAssert(cond, exc)
#define DEBUGL(doit, msg)
Definition debug.hh:40
#define conceptsAssert3(cond, exc, msg)
std::string typeOf(const T &t)
Definition output.hh:43
double Real
Definition typedefs.hh:39
void memorycpy(F *dest, const G *src, size_t n)
Copies n entries from src to dest (faster than std::memcpy)
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320