Class documentation of Concepts

Loading...
Searching...
No Matches
formulafrmEformula.hh
Go to the documentation of this file.
1
8#ifndef formulatfrmEformula_hh
9#define formulatfrmEformula_hh
10
11#include "geometry.hh"
12#include "formula.hh"
14
15#include <algorithm>
16
17#if __GNUC__ == 2
18# include <float.h>
19# define EPS DBL_EPSILON
20#else
21# include <limits>
22# define EPS std::numeric_limits<double>::epsilon()
23#endif
24
25namespace concepts{
26
27 // ************************************************************* JacobianCell *
28
35 template<uint dimC> class JacobianCell;
36
37 template<> class JacobianCell<1>{
38 public:
39 typedef concepts::Edge1d cell;
40 };
41
42 template<> class JacobianCell<2>{
43 public:
44 typedef concepts::Quad2d cell;
45 };
46
47 template<> class JacobianCell<3>{
48 public:
50 };
51
52
53 // ********************************************************** TensorVertexMap *
54
61 template<uint dimC> class TensorVertexMap;
62
63 template<> class TensorVertexMap<1>{
64 public:
66 };
67
68 template<> class TensorVertexMap<2>{
69 public:
71 };
72
73 template<> class TensorVertexMap<3>{
74 public:
76 };
77
78
79
85 template<uint dimC>
87
89 : cell(cell), key(cell.connector().key()){};
90
91 virtual bool operator<(const CellStripeElement<dimC>& sb) const{
92 return this->key < sb.key;
93 }
94
95 virtual bool operator==(const CellStripeElement<dimC>& sb) const{
96 return key == sb.key;
97 }
98
99 const typename JacobianCell<dimC>::cell& cell;
100 const uint key;
101
102
103 protected:
104 virtual std::ostream& info(std::ostream& os) const{
105 return os<< concepts::typeOf(*this)<<"[ "<< key << " ] ";
106 }
107 };
108
109
110
125 template<uint dimC>
126 class CellBox : public OutputOperator{
127 public:
128 CellBox(const typename JacobianCell<dimC>::cell& cell):
129 cell(cell), isDummy(false), key(cell.connector().key().key()){
130
131 for(uint j = 0; j < dimC; ++j)
132 minX[j] = maxX[j] = cell.vertex(0)[j];
133
134 for(uint i = 1; i < pow(2,dimC); ++i){
135
136 for(uint j = 0; j < dimC; ++j){
137 maxX[j] = std::max(maxX[j], cell.vertex(i)[j] );
138 minX[j] = std::min(minX[j], cell.vertex(i)[j] );
139 }
140 }//for i
141 }
142
143
144 // //dummy constructor
145 CellBox(const typename JacobianCell<dimC>::cell& cell, Real xMax):
146 cell(cell), isDummy(true), key(cell.connector().key().key()){
147
148 minX[0] = - std::numeric_limits<double>::max();
149 maxX[0] = xMax;
150
151 for(uint i = 1 ; i < dimC; ++i){
152 minX[i] = maxX[i] = - std::numeric_limits<double>::max();
153 }
154
155 }
156
163 virtual bool operator<(const CellBox<dimC>& box) const;
164
165
166 virtual bool operator==(const CellBox<dimC>& box) const{
167 //safety hold ask for isDummy
168 return this->key == box.key && isDummy == box.isDummy;
169 }
170
171 Real minX[dimC];
172 Real maxX[dimC];
173
174 const typename JacobianCell<dimC>::cell& cell;
175 bool isDummy;
176 uint key;
177
178 protected:
179 virtual std::ostream& info(std::ostream& os) const{
180 os<< concepts::typeOf(*this)<<"[key = "<< key<<"] << box frame = ";
181 for(uint i = 0 ; i < dimC-1; ++i)
182 os << "["<<minX[i] << " , "<< maxX[i] << "] x ";
183 os << "["<<minX[dimC-1] << " , "<< maxX[dimC-1] << "]";
184 return os;
185 }
186 };
187
188
195 template<uint dimC>
196 struct CCell_F : public OutputOperator{
197
198 CCell_F(const typename JacobianCell<dimC>::cell& cell, const uint cardF=2):
199 cell(cell), key(cell.connector().key()), cardF(cardF){
201 computeF();
202 }
203
204
205 bool operator==(CCell_F cCF) const{
206 return this->key == cCF.key;
207 }
208
209 bool operator<(CCell_F cCF) const{
210 return this->key < cCF.key;
211 }
212
213
214 const typename JacobianCell<dimC>::cell& cell;
215 const uint key;
216 const uint cardF;
217
218 //Finite set of physical points
220
221 protected:
222 virtual std::ostream& info(std::ostream& os) const{
223 return os << concepts::typeOf(*this)<<"[ Cellkey = "<< key << " ], F = " << F;
224 }
225 void computeF();
226 };
227
228
234 template<uint dimC>
236 CCell_F_dist(const CCell_F<dimC>& ccF, const Point<Real,dimC>& P):
237 ccF(ccF), dist_2((ccF.F[0]-P).l2_2()) {
238
239 for(uint i = 1; i < ccF.F.size(); ++i){
240 dist_2 = std::min(dist_2, (ccF.F[i]-P).l2_2());
241 }
242 }
243 bool operator==(CCell_F_dist ccF_d) const{
244 return this->ccF.key == ccF_d.ccF.key;
245 }
246
247 bool operator<(CCell_F_dist ccF_d) const{
248 return this->dist_2 < ccF_d.dist_2;
249 }
250 const CCell_F<dimC>& ccF;
251 //squared distance of P and F
252 Real dist_2;
253
254 protected:
255 virtual std::ostream& info(std::ostream& os) const{
256 return os << concepts::typeOf(*this)<<"[] ";
257 }
258 };
259
260
261
265 template<uint dimC,class G> class MultiVector;
266
267
268 // ********************************* specific MultiVector classes **
269
270 template<> class MultiVector<0,const ElementWithCell<Real>* >{
271 public:
272 typedef const ElementWithCell<Real>* map;
273 };
274 template<> class MultiVector<0,const ElementWithCell<Cmplx>* >{
275 public:
276 typedef const ElementWithCell<Cmplx>* map;
277 };
278
279
280
281 template<> class MultiVector<0,concepts::Set<CellBox<1>>>{
282 public:
283 typedef std::pair<concepts::Set<CellBox<1>>, Real> map;
284 };
285 template<> class MultiVector<0,concepts::Set<CellBox<2>>>{
286 public:
287 typedef std::pair<concepts::Set<CellBox<2>>, Real> map;
288 };
289 template<> class MultiVector<0,concepts::Set<CellBox<3>>>{
290 public:
291 typedef std::pair<concepts::Set<CellBox<3>>, Real> map;
292 };
293
294
296 template<uint dimC,class G> class MultiVector{
297 public:
298 typedef std::vector<typename MultiVector<dimC-1,G>::map > map;
299 };
300
301
302 // **************************************************** CellMap **
303
311 template<uint dimC, class H>
312 struct CellMap: public OutputOperator{
313
314 CellMap();
315
316 CellMap(const CellMap<dimC,H>& map);
317
318 void resize(const uint (&maxlevel)[dimC]);
319
320 //add information at given index
321 void add(const ElementWithCell<H>* elm, const uint (&idx)[dimC]);
322
323 //@ pre idx is accessable
324 const ElementWithCell<H>* get(const uint (&idx)[dimC]);
325
326 uint sizes[dimC];
327
328 //a better range safe multiarray, since 2^64 cannot be holded in a ulonglong!
330
331 protected:
332 virtual std::ostream& info(std::ostream& os) const{
333 return os << concepts::typeOf(*this)<<"["<<dimC<<"]";
334 }
335 };
336
337
338
339
340 // **************************************************** FFEF_Error **
341
345 class FFEF_Error: public ExceptionBase {
346 public:
350 FFEF_Error(const std::string& file, const unsigned int line,
351 const std::string& function, const std::string& errorMessage) throw ();
352
353
354 virtual const char* what() const throw();
355
356 virtual ~FFEF_Error() throw () {};
357 protected:
358 virtual std::ostream& info(std::ostream& os) const throw ();
359 private:
360 std::string errorMessage_;
361 mutable std::string outputMessage_ ;
362 };
363
364
365
366 // ************************************************* FormulaFromElementFormula *
367
519
520 private:
521 //this is the maximal refinement level allowed here, maximal practical level should be around < 32.
522 static uint max_lvl;
523
524 public:
525
531 enum PNF {Exc = 0, NaN, Zero};
532
533
553 //template<class F, class H>
556 const Set<uint>* s_attrb = 0,
557 const Set<uint>* d_attrb = 0,
558 const Point<Real, dim> scale = Point<Real, dim>(1),
559 const Point<Real, dim> shift = Point<Real, dim>(0),
560 const uint N = 10,
561 const uint cardF_2 = 2,
562 const Real tol = EPS,
563 const Real interior = 0.00000001,
564 const uint maxDoI = 3
565 );
566
567 virtual ~FormulaFromElementFormula(){};
568
569
570 virtual F operator() (const Real p, const Real t = 0.0) const;
571 virtual F operator() (const Real2d& p, const Real t = 0.0) const;
572 virtual F operator() (const Real3d& p, const Real t = 0.0) const;
573
574 virtual F operator() (const Connector& cntr,
575 const Real p,
576 const Real t = 0.0) const;
577
578 virtual F operator() (const Connector& cntr,
579 const Real2d& p,
580 const Real t = 0.0) const;
581
582 virtual F operator() (const Connector& cntr,
583 const Real3d& p,
584 const Real t = 0.0) const;
585
586
607
608
617 inline void setPNF(PNF pnf) {pnf_ = pnf;}
618
619
621
622 protected:
623 virtual std::ostream& info(std::ostream& os) const {
624 return os << "u_ = " << this->u_ << ", pnf_ = " << this->pnf_ ;
625 }
626
627
628 private:
629
632
637
639 const Point<Real, dim> scale_;
641 const Point<Real, dim> shift_;
642
644 const Real tol_;
646 const uint N_;
648 const uint cardF_2_;
650 const Real interior_;
651
652 //heuristic approach due to integration or graphical application
653 //often next local coordinate is in the same element as the last one
654 mutable const ElementWithCell<G>* lastElm_;
655
657 mutable const typename JacobianCell<dim>::cell* lastCell_;
658
660 mutable const typename JacobianCell<dim>::cell* lastCoarseCell_;
661
663 mutable bool wasCurved_;
664
666 mutable bool wasCurved_c_;
667
668
674 mutable Z2 cCellType_;
675
678 bool allowPer_;
679
684
688 const uint maxDoI_;
689
690 //Flag for Point not found behaviour of underlying search routine.
691 PNF pnf_;
692
693
694
697
701
702
703
704
705 //maps I in IN^dim to the coressponding child cells key
706 //it holds 0<= I_i maxLevel_i
707 // where maxLevel is the highest number of levels in diretion x_i
708
709 //example :
710 //
711 // coarsest cell href4
712 // 1_________ ________ _________
713 // | | | | | maxlevel_0 = 1 | | | maxlevel_0 = 2
714 // | | |___|___| maxlevel_1 = 1 |___|___| maxlevel_1 = 1
715 // | | | | | | | | |
716 // |_______| |___|___| |_|_|___|
717 // 0 1
718
719 // We devide the coarsest cell into sectors along coord i
720 // 0 <= l_i / (2^maxLevel_i) <= 1 , l_i = 0,..., 2^maxLevel_i
721 //
722 // Then map(l_0, l_1, l_2) maps into a sector surjectiv.
723 //
724 // Example :
725 // _____________
726 // 1 | e | d |
727 // |_____|_____|
728 // 0 | a| b| c |
729 // |__|__|_____|
730 // 0 1 2 3
731 //
732 // then for example map(0,0) = a, map(2,0) = map(3,0) = c
733
734 //the map is from coarse elms to its finest children
735 mutable concepts::HashMap<CellMap<dim,G> > mapToFinestElm_;
736
737
742
743
746
750 Set<uint> mapCCells_;
751
752
763 void build_directMap_(const typename JacobianCell<dim>::cell* cell,
765
766
767 template<uint dim1 = dim,
768 typename std::enable_if<dim1 == 1u, uint>::type = 0>
769 void setLocalMap_(const typename JacobianCell<dim>::cell* coarseCell,
770 const HashMap<const ElementWithCell<G>* >& mapToElm,
771 CellMap<dim, G>& map,
772 const std::array<uint,dim> idxL,
773 const std::array<uint,dim> idxR) const;
774
775 template<uint dim2 = dim,
776 typename std::enable_if<dim2 == 2u, uint>::type = 0>
777 void setLocalMap_(const typename JacobianCell<dim>::cell* coarseCell,
778 const HashMap<const ElementWithCell<G>* >& mapToElm,
779 CellMap<dim, G>& map,
780 const std::array<uint,dim> idxL,
781 const std::array<uint,dim> idxR) const ;
782
783 template<uint dim3 = dim,
784 typename std::enable_if<dim3 == 3u, uint>::type = 0>
785 void setLocalMap_(const typename JacobianCell<dim>::cell* coarseCell,
786 const HashMap<const ElementWithCell<G>* >& mapToElm,
787 CellMap<dim, G>& map,
788 const std::array<uint,dim> idxL,
789 const std::array<uint,dim> idxR) const;
790
791
792
796 const Point<Real, dim> scale,
797 const Point<Real, dim> shift,
798 const uint N,
799 const uint cardF_2 ,
800 const Real tol,
801 const Real interior,
804 const bool allowPer,
805 const Point<Real, dim> O,
806 const Point<Real, dim> eL,
807 const Set<uint> mapCCells,
808 const Set<const typename JacobianCell<dim>::cell* > coarsestCell,
809 const Set<const typename JacobianCell<dim>::cell* > irrCCells,
811 const uint maxDoI,
812 const PNF pnf,
814
830 F compute_(const Point<Real,dim>& p, const Real t) const;
831
840 void buildBoxCandidates_(const Point<Real, dim> P, concepts::Set<CellStripeElement<dim> >& box) const;
841
854 bool getOrigPoint_(//const concepts::ElementWithCell<G>& elm,
855 const typename JacobianCell<dim>::cell& cell,
856 const Point<Real, dim> P, Point<Real, dim>& eta, const uint N,
857 const Real interior,
858 const Point<Real, dim>& x0 = Real3d(0.49,0.51,0.49)) const;
859
860
861 //
862 // then applies original shift/scale to p to build P
863
870 void shift_DBox_(const Point<Real,dim>& p, Point<Real,dim>& P) const;
871
872
873
874 //a cell is called coarse iff its level of refinement is zero in each direction
875 bool isCoarse_(const typename JacobianCell<dim>::cell& cell);
876
877
885 void addElements_(const uint cKey,
886 const typename JacobianCell<dim>::cell& cell,
889
890
891 //@pre arrays are initialized with zero entries
892 //template<uint dim>
893 void getExtremalLevel(const typename JacobianCell<dim>::cell* cell,
894 uint (&maxL)[dim], uint (&minL)[dim]);
895
896
902 bool compute0_(const typename JacobianCell<dim>::cell& cCell, const Point<Real, dim>& P,
903 const Point<Real, dim>& cEta,const Real t, F& val) const;
904
905
911 bool compute1_(const typename JacobianCell<dim>::cell& cCell, const Point<Real, dim>& P,
912 const Point<Real, dim>& cEta,const Real t, F& val) const;
913
918 bool checkCCells_(const std::set<typename CellType<dim>::cell *>& allCell,
919 typename std::set<typename CellType<dim>::cell *>::const_iterator iter);
920
921
922 F handlePNF_() const;
923
924
925
926
927
928 };
929
930#ifdef __clang__
932 const std::array<Real,std::size_t(1u)> x0,
933 const std::array<Real,std::size_t(1u)> xN,
934 const concepts::Edge1d*& cld);
936 const std::array<Real,std::size_t(2u)> x0,
937 const std::array<Real,std::size_t(2u)> xN,
938 const concepts::Quad2d*& cld);
940 const std::array<Real,std::size_t(3u)> x0,
941 const std::array<Real,std::size_t(3u)> xN,
943
944#else
952 template<uint dimC>
954 const std::array<Real,std::size_t(dimC)> x0,
955 const std::array<Real,std::size_t(dimC)> xN,
956 const typename JacobianCell<dimC>::cell*& cld);
957#endif
958
959
960
961
962} //namespace concepts
963
964#endif // formulatfrmEformula.hh
virtual bool operator<(const CellBox< dimC > &box) const
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
FFEF_Error(const std::string &file, const unsigned int line, const std::string &function, const std::string &errorMessage)
virtual FormulaFromElementFormula< dim, F, G > * clone() const
Virtual copy constructor.
void allowPeriodicity(const Point< Real, dim > &O, const Point< Real, dim > &eL)
FormulaFromElementFormula(const concepts::ElementFormulaContainer< F, G > frm, const concepts::SpaceOnCoarseCells< dim, G > &sSpc, const Set< uint > *s_attrb=0, const Set< uint > *d_attrb=0, const Point< Real, dim > scale=Point< Real, dim >(1), const Point< Real, dim > shift=Point< Real, dim >(0), const uint N=10, const uint cardF_2=2, const Real tol=EPS, const Real interior=0.00000001, const uint maxDoI=3)
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual F operator()(const Real p, const Real t=0.0) const
recursive definition of the multivector
#define conceptsAssert(cond, exc)
std::string typeOf(const T &t)
Definition output.hh:43
double Real
Definition typedefs.hh:39
void getChild(const typename JacobianCell< dimC >::cell &cCell, const Point< Real, dimC > &eta, const std::array< Real, std::size_t(dimC)> x0, const std::array< Real, std::size_t(dimC)> xN, const typename JacobianCell< dimC >::cell *&cld)
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320
std::complex< Real > Cmplx
Type for a complex number. It also depends on the setting of Real.
Definition typedefs.hh:42
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.