Class documentation of Concepts

Loading...
Searching...
No Matches
formula.hh
Go to the documentation of this file.
1
6#ifndef funFormula_hh
7#define funFormula_hh
8
9#include <map>
10#include "basics/debug.hh"
12#include "space/formula.hh"
13#include "space/function.hh"
14#include "function/vector.hh"
15
16#define PWFormVecBaseConstr_D 0
17
18namespace concepts {
19
20 // *************************************************** PiecewiseVectorBase **
21
32 template<class F, class G, class H, class I>
34 public:
39 protected:
41 const Space<G>& spc_;
47 std::map<uint, const ElementWithCell<G>*> elm_;
52 const ElementWithCell<G>* element_(const Connector& cell) const;
53 };
54
55 template<class F, class G, class H, class I>
57 (const Space<G>& spc, const Vector<F>& coeff,
59 : spc_(spc), coeff_(spc_->dim()), fun_(&fun)
60 {
61 memorycpy((F*)coeff_, (const F*)coeff, spc_->dim());
62 DEBUGL(PWFormVecBaseConstr_D, "Space = " << *spc_);
63 // scanner over the elements
65 while(*sc) {
66 const Element<G>& e = (*sc)++;
67 DEBUGL(PWFormVecBaseConstr_D, "Element = " << e);
68 const ElementWithCell<G>* elm =
69 dynamic_cast<const ElementWithCell<G>*>(&e);
71 elm_[elm->cell().connector().key()] = elm;
72 }
73 DEBUGL(PWFormVecBaseConstr_D, "Mapping Cell -> Element = " <<
74 (OutputMatlab<std::map<uint, const ElementWithCell<G>*> >(elm_)));
75 }
76
77 template<class F, class G, class H, class I>
78 const ElementWithCell<G>*
80 // look for element to which the cell belongs to
81 typename std::map<uint, const ElementWithCell<G>*>::
82 const_iterator i = elm_.find(cell.key());
83 // if such a cell exists return the element
84 if (i != elm_.end()) return i->second;
85 // look at the children cell and call the method recursivly
86 const Connector* child = 0;
87 for(uint j = 0; ( child = cell.child(j) ) ; ++j) {
88 const ElementWithCell<G>* elm = element_(*child);
89 // if a children cell belongs to a element return the element
90 if (elm) return elm;
91 }
92 // no element found
93 return 0;
94 }
95
96 // ************************************************** PiecewiseVector<dim> **
97
98 template<uint dim, class F, class G, class H>
100 public PiecewiseFormulaVectorBase<F,G,Point<H,dim>,H> {
101 public:
102 PiecewiseFormulaVector(const Space<G>& spc, const Vector<F>& coeff,
105 Array<F> c((const F*)this->coeff_, this->spc_.dim());
106 const Vector<F> coeff(*this->spc_, (F*)c);
107 return new PiecewiseFormulaVector<dim,F,G,H>(coeff, *this->fun_);
108 }
109 virtual Point<H,dim> operator()(const Connector& cell, const Real p,
110 const Real t = 0.0) const;
111 virtual Point<H,dim> operator()(const Connector& cell, const Real2d& p,
112 const Real t = 0.0) const;
113 virtual Point<H,dim> operator()(const Connector& cell, const Real3d& p,
114 const Real t = 0.0) const;
115 };
116
117 template<uint dim, class F, class G, class H>
118 PiecewiseFormulaVector<dim,F,G,H>::PiecewiseFormulaVector
119 (const Space<G>& spc, const Vector<F>& coeff,
120 const ElementFunction<H,G>& fun) :
121 PiecewiseFormulaVectorBase<F,G,Point<H,dim>,H>(spc, coeff, fun) {}
122
123 template<uint dim, class F, class G, class H>
125 (const Connector& cell, const Real p, const Real t) const
126 {
127 const ElementWithCell<G>* elm = this->element_(cell);
129 if (elm) {
130 // get's function value
131 Array<H> val;
132 (*this->fun_)(*elm, this->coeff_, val, p, t);
133 conceptsAssert(val.size() == dim, Assertion());
134 // copy it to a point
135 memorycpy((H*)res, (const H*)val, dim);
136 }
137 return res;
138 }
139
140 template<uint dim, class F, class G, class H>
142 (const Connector& cell, const Real2d& p, const Real t) const
143 {
144 const ElementWithCell<G>* elm = this->element_(cell);
146 if (elm) {
147 // get's function value
148 Array<H> val;
149 (*this->fun_)(*elm, this->coeff_, val, p, t);
150 conceptsAssert(val.size() == dim, Assertion());
151 // copy it to a point
152 memorycpy((H*)res, (const H*)val, dim);
153 }
154 return res;
155 }
156
157 template<uint dim, class F, class G, class H>
158 Point<H,dim> PiecewiseFormulaVector<dim,F,G,H>::operator()
159 (const Connector& cell, const Real3d& p, const Real t) const
160 {
161 const ElementWithCell<G>* elm = this->element_(cell);
162 Point<H,dim> res;
163 if (elm) {
164 // get's function value
165 Array<H> val;
166 (*this->fun_)(*elm, this->coeff_, val, p, t);
167 conceptsAssert(val.size() == dim, Assertion());
168 // copy it to a point
169 memorycpy((H*)res, (const H*)val, dim);
170 }
171 return res;
172 }
173
174 // ********************************************* PiecewiseFormulaVector<1> **
175
176 template<class F, class G, class H>
177 class PiecewiseFormulaVector<1,F,G,H> :
178 public PiecewiseFormulaVectorBase<F,G,H,H> {
179 public:
180 PiecewiseFormulaVector(const Space<G>& spc, const Vector<F>& coeff,
183 Array<F> c((const F*)this->coeff_, this->spc_.dim());
184 const Vector<F> coeff(*this->spc_, (F*)c);
185 return new PiecewiseFormulaVector<1,F,G,H>(coeff, *this->fun_);
186 }
187 virtual H operator()(const Connector& cell, const Real p,
188 const Real t = 0.0) const;
189 virtual H operator()(const Connector& cell, const Real2d& p,
190 const Real t = 0.0) const;
191 virtual H operator()(const Connector& cell, const Real3d& p,
192 const Real t = 0.0) const;
193 };
194
195 template<class F, class G, class H>
196 PiecewiseFormulaVector<1,F,G,H>::PiecewiseFormulaVector
197 (const Space<G>& spc, const Vector<F>& coeff,
198 const ElementFunction<H,G>& fun) :
199 PiecewiseFormulaVectorBase<F,G,H,H>(spc, coeff, fun) {}
200
201 template<class F, class G, class H>
203 (const Connector& cell, const Real p, const Real t) const
204 {
205 const ElementWithCell<G>* elm = this->element_(cell);
206 if (elm) {
207 // get's function value
208 Array<H> val;
209 (*this->fun_)(*elm, this->coeff_, val, p, t);
210 conceptsAssert(val.size() == 1, Assertion());
211 return val[0];
212 }
213 return H(0);
214 }
215
216 template<class F, class G, class H>
218 (const Connector& cell, const Real2d& p, const Real t) const
219 {
220 const ElementWithCell<G>* elm = this->element_(cell);
221 DEBUGL(0, "Cell = " << cell);
222 if (elm) {
223 DEBUGL(0, "Element = " << *elm);
224 // get's function value
225 Array<H> val;
226 (*this->fun_)(*elm, this->coeff_, val, p, t);
227 conceptsAssert(val.size() == 1, Assertion());
228 DEBUGL(0, "p = " << p << ", Value = " << val[0]);
229 return val[0];
230 }
231 return H(0);
232 }
233
234 template<class F, class G, class H>
235 H PiecewiseFormulaVector<1,F,G,H>::operator()
236 (const Connector& cell, const Real3d& p, const Real t) const
237 {
238 DEBUGL(0, "Cell = " << cell);
239 const ElementWithCell<G>* elm = this->element_(cell);
240 if (elm) {
241 DEBUGL(0, "Element = " << *elm);
242 // get's function value
243 Array<H> val;
244 (*this->fun_)(*elm, this->coeff_, val, p, t);
245 conceptsAssert(val.size() == 1, Assertion());
246 DEBUGL(0, "p = " << p << ", Value = " << val[0]);
247 return val[0];
248 }
249 return H(0);
250 }
251
252} // namespace concepts
253
254#endif // funFormula_hh
255
256
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
virtual Connector * child(uint i, bool mode=0)=0
virtual const Cell & cell() const =0
Returns the cell on which the element is built.
const ElementWithCell< G > * element_(const Connector &cell) const
Definition formula.hh:79
Array< F > coeff_
Solution vector.
Definition formula.hh:43
PiecewiseFormulaVectorBase(const Space< G > &spc, const Vector< F > &coeff, const ElementFunction< I, G > &fun)
Definition formula.hh:57
const ElementFunction< I, G > * fun_
Function of the FE function.
Definition formula.hh:45
std::map< uint, const ElementWithCell< G > * > elm_
Mapping from cell key to the element.
Definition formula.hh:47
const Space< G > & spc_
Space.
Definition formula.hh:41
virtual PiecewiseFormulaVector< 1, F, G, H > * clone() const
Virtual copy constructor.
Definition formula.hh:182
virtual PiecewiseFormulaVector< dim, F, G, H > * clone() const
Virtual copy constructor.
Definition formula.hh:104
virtual Point< H, dim > operator()(const Connector &cell, const Real p, const Real t=0.0) const
Definition formula.hh:125
virtual uint dim() const =0
Returns the dimension of the space.
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
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