00001
00002
00003
00004
00005 #ifndef elementMaps_hh
00006 #define elementMaps_hh
00007
00008 #include "basics/outputOperator.hh"
00009 #include "basics/typedefs.hh"
00010 #include "basics/vectorsMatrices.hh"
00011 #include "basics/cloneable.hh"
00012 #include "toolbox/sequence.hh"
00013 #include "toolbox/arrayOp.hh"
00014
00015 namespace concepts {
00016
00017
00018
00022 class Map1d : public OutputOperator {
00023 public:
00024 std::ostream& info(std::ostream& os) const {return os << "Map1d()";};
00025 };
00026
00027
00028
00032 class Map2d : public OutputOperator {
00033 public:
00034 std::ostream& info(std::ostream& os) const {return os << "Map2d()";};
00035 virtual bool straight() const {return false;};
00036 };
00037
00038
00039
00045 class MapEdge1d : public Map1d {
00046 public:
00051 inline MapEdge1d(const Real vtx0, const Real vtx1) :
00052 vtx0_(vtx0), vtx1_(vtx1) {}
00053
00057 inline Real operator()(const Real x) const {
00058 return vtx0_*(1.0-x) + vtx1_*x; }
00059
00061 inline Real jacobian(const Real) const { return vtx1_-vtx0_; }
00062
00064 inline MapEdge1d* clone() const {return new MapEdge1d(vtx0_, vtx1_);};
00065 protected:
00066 virtual std::ostream& info(std::ostream& os) const;
00067 private:
00069 Real vtx0_, vtx1_;
00070 };
00071
00072
00073
00082 class MappingEdge2d : public Cloneable, public Map1d {
00083 public:
00088 MappingEdge2d(const Real2d vtx0, const Real2d vtx1);
00090 MappingEdge2d(const MappingEdge2d &edgemap);
00092 virtual MappingEdge2d* clone() const = 0;
00094 virtual MappingEdge2d* inverse() const;
00098 virtual Real2d operator()(const Real t) const = 0;
00100 virtual Real2d derivative(const Real t, const uint n = 1) const = 0;
00101
00103 virtual Real2d normal(const Real t) const;
00105 inline Real2d n0(const Real t) const {
00106 return UnitNd<2>(normal(t));
00107 }
00114 virtual Real curvature(const Real t, uint n = 0) const;
00115
00119 virtual MappingEdge2d* part(const Real t0, const Real t1) const;
00120
00122 inline const Real2d& vtx(uint i) const {return vtx_[i];}
00123 protected:
00124 virtual std::ostream& info(std::ostream& os) const;
00126 Real2d vtx_[2];
00127 };
00128
00129
00130
00135 class PartMappingEdge2d : public MappingEdge2d {
00136 public:
00142 PartMappingEdge2d(const MappingEdge2d& edgemap,
00143 const Real t0, const Real t1);
00145 PartMappingEdge2d(const PartMappingEdge2d &edgemap);
00147 virtual PartMappingEdge2d* clone() const;
00149 virtual PartMappingEdge2d* inverse() const;
00153 virtual Real2d operator()(const Real t) const;
00155 virtual Real2d derivative(const Real t, const uint n = 1) const;
00156 protected:
00157 virtual std::ostream& info(std::ostream& os) const;
00158 private:
00160 std::auto_ptr<const MappingEdge2d> edgemap_;
00162 const Real t0_, t1_;
00163
00165 inline const Real t_(const Real t) const {
00166 return t0_*(1. - t) + t1_*t;
00167 }
00168 };
00169
00170
00171
00177 class InverseMappingEdge2d : public MappingEdge2d {
00178 public:
00183 InverseMappingEdge2d(const MappingEdge2d& edgemap);
00184
00185 virtual InverseMappingEdge2d* clone() const;
00186 virtual MappingEdge2d* inverse() const {
00187 return edgemap_->clone();
00188 }
00192 virtual Real2d operator()(const Real t) const;
00194 virtual Real2d derivative(const Real t, const uint n = 1) const;
00201 virtual Real curvature(const Real t, uint n = 0) const;
00202 PartMappingEdge2d* part(const Real t0, const Real t1) const;
00203 protected:
00204 virtual std::ostream& info(std::ostream& os) const;
00206 const MappingEdge2d* edgemap_;
00207 };
00208
00209
00210
00216 class MappingStraightEdge2d : public MappingEdge2d {
00217 public:
00222 MappingStraightEdge2d(const Real2d vtx0, const Real2d vtx1);
00224 MappingStraightEdge2d(const MappingStraightEdge2d &edgemap);
00226 virtual MappingStraightEdge2d* clone() const;
00227 virtual MappingStraightEdge2d* inverse() const {
00228 return new MappingStraightEdge2d(vtx(1), vtx(0));
00229 }
00233 virtual Real2d operator()(const Real t) const;
00235 virtual Real2d derivative(const Real t, const uint n = 1) const;
00236 virtual Real curvature(const Real t, uint n = 0) const;
00237 MappingStraightEdge2d* part(const Real t0, const Real t1) const;
00238 protected:
00239 virtual std::ostream& info(std::ostream& os) const;
00241 Real2d delta_;
00242 };
00243
00244
00245
00257 class CircleMappingEdge2d : public MappingEdge2d {
00258 public:
00274 CircleMappingEdge2d(const Real r, const Real2d vtx0, const Real2d vtx1);
00282 CircleMappingEdge2d(const Real2d center, const Real r,
00283 const Real angle0, const Real angle1);
00295 CircleMappingEdge2d(const Real2d vtx0, const Real2d vtxm, const Real2d vtx1);
00297 CircleMappingEdge2d(const CircleMappingEdge2d &edgemap);
00299 virtual CircleMappingEdge2d* clone() const;
00300 virtual MappingEdge2d* inverse() const;
00301
00302 virtual Real2d operator()(const Real t) const;
00303 virtual Real2d derivative(const Real t, const uint n = 1) const;
00304 virtual Real curvature(const Real t, const uint n = 0) const;
00305 MappingEdge2d* part(const Real t0, const Real t1) const;
00306 protected:
00307 virtual std::ostream& info(std::ostream& os) const;
00308 private:
00310 Real r_;
00312 Real2d m_;
00314 Real angle0_, angle1_;
00315
00316 inline Real phi_(const Real t) const {
00317 return angle0_ * (1.-t) + angle1_ * t;
00318 }
00319 };
00320
00321
00322
00333 class EllipseMappingEdge2d : public MappingEdge2d {
00334 public:
00341 EllipseMappingEdge2d(const Real2d center, const Real a, const Real b,
00342 const Real2d vtx0, const Real2d vtx1);
00344 EllipseMappingEdge2d(const EllipseMappingEdge2d &edgemap);
00346 virtual EllipseMappingEdge2d* clone() const;
00347 virtual EllipseMappingEdge2d* inverse() const;
00348
00349 virtual Real2d operator()(const Real t) const;
00350 virtual Real2d derivative(const Real t, const uint n = 1) const;
00351 EllipseMappingEdge2d* part(const Real t0, const Real t1) const;
00352 protected:
00353 virtual std::ostream& info(std::ostream& os) const;
00354 private:
00356 Real2d m_;
00358 Real a_, b_;
00360 Real angle0_, angle1_;
00361
00362 EllipseMappingEdge2d(const Real2d center, const Real a, const Real b,
00363 const Real angle0, const Real angle1);
00364 };
00365
00366
00367
00375 class ParabelMappingEdge2d : public MappingEdge2d {
00376 public:
00383 ParabelMappingEdge2d(const Real2d vtx0, const Real2d vtx1,
00384 const Real2d cusp, const Real2d ap);
00386 ParabelMappingEdge2d(const ParabelMappingEdge2d &edgemap);
00388 virtual ParabelMappingEdge2d* clone() const;
00389
00390 virtual Real2d operator()(const Real t) const;
00391 virtual Real2d derivative(const Real t, const uint n = 1) const;
00392 ParabelMappingEdge2d* part(const Real t0, const Real t1) const;
00393 protected:
00394 virtual std::ostream& info(std::ostream& os) const;
00395 private:
00397 const UnitNd<2> v_, vrot_;
00399 const Real2d cusp_;
00401 const Real s0_, deltas_;
00403 Real p_;
00405 const Real s_(const Real t) const;
00406 };
00407
00408
00409
00416 class MappingParallelEdge2d : public MappingEdge2d {
00417 public:
00427 MappingParallelEdge2d(const MappingEdge2d &edgemap, const Real d);
00429 MappingParallelEdge2d(const MappingParallelEdge2d &edgemap);
00431 virtual MappingParallelEdge2d* clone() const;
00432
00433 virtual Real2d operator()(const Real t) const;
00434 virtual Real2d derivative(const Real t, const uint n = 1) const;
00435 virtual Real curvature(const Real t, const uint n = 0) const;
00436 virtual Real2d n0(const Real t) const;
00437
00439 inline const MappingEdge2d& map() const { return *edgemap_; }
00441 inline const Real d() const { return d_; }
00442 MappingParallelEdge2d* part(const Real t0, const Real t1) const;
00443 protected:
00444 virtual std::ostream& info(std::ostream& os) const;
00445 private:
00447 std::auto_ptr<const MappingEdge2d> edgemap_;
00449 Real d_;
00450 };
00451
00452 class MappingQuad2d;
00453
00454
00455
00460 class MappingQuadEdge2d : public MappingEdge2d {
00461 public:
00471 MappingQuadEdge2d(const MappingQuad2d& map, const uint edge);
00478 MappingQuadEdge2d(const MappingQuad2d& map,
00479 const Real2d xi0, const Real2d xi1);
00481 MappingQuadEdge2d(const MappingQuadEdge2d &edgemap);
00483 virtual MappingQuadEdge2d* clone() const;
00484
00485 virtual Real2d operator()(const Real t) const;
00486 virtual Real2d derivative(const Real t, const uint n = 1) const;
00487 virtual MappingQuadEdge2d* inverse() const {
00488 return new MappingQuadEdge2d(*map_, xi_ + xidiff_, xi_);
00489 }
00490 protected:
00491 virtual std::ostream& info(std::ostream& os) const;
00492 private:
00494 std::auto_ptr<MappingQuad2d> map_;
00496 Real2d xi_, xidiff_;
00497
00498
00499 inline const Real2d lcoord_(const Real t) const {
00500 return xi_ + xidiff_*t;
00501 }
00502
00503 inline const Real2d lderiv_(const Real t) const {
00504 return xidiff_;
00505 }
00506 };
00507
00508
00509
00515 class MappingTriangle2d : public Map2d {
00516 public:
00521 virtual Real2d operator()(const Real x, const Real y) const = 0;
00522
00526 virtual MappingTriangle2d* clone() const = 0;
00527
00533
00534
00536 virtual Real jacobianDeterminant(const Real x, const Real y) const;
00537
00539 virtual MapReal2d jacobian(const Real x, const Real y) const = 0;
00540
00542 virtual MapReal2d jacobianInverse(const Real x, const Real y) const;
00543 };
00544
00545
00546
00552 class VertexTriangle2d : public MappingTriangle2d {
00553 public:
00560 VertexTriangle2d(Real2d vtx0, Real2d vtx1, Real2d vtx2);
00561
00563 VertexTriangle2d(const VertexTriangle2d &map);
00564
00565 virtual ~VertexTriangle2d();
00566 virtual VertexTriangle2d* clone() const;
00567
00568
00573 virtual bool straight() const {return true;};
00574
00575 virtual MapReal2d jacobian(const Real x, const Real y) const {
00576 return jacobian_;
00577 }
00578
00579 Real2d operator()(const Real x, const Real y) const {
00580 conceptsAssert(0.0 <= y, Assertion());
00581 conceptsAssert(0.0 <= x, Assertion());
00582 conceptsAssert(y <= x, Assertion());
00583 conceptsAssert(x <= 1.0, Assertion());
00584
00585 Real2d res(vtx1_); res -= vtx0_; res *= x;
00586 Real2d res2(vtx2_); res2 -= vtx1_; res2 *= y;
00587 res += res2;
00588
00589 res += vtx0_;
00590 return res;
00591 }
00592 protected:
00593 virtual std::ostream& info(std::ostream& os) const;
00594 private:
00596 Real2d vtx0_, vtx1_, vtx2_;
00598 MapReal2d jacobian_;
00599 };
00600
00601
00602
00610 class MapTriangle2d : public MappingTriangle2d {
00611 public:
00622 MapTriangle2d(char* map, const Real scX, const Real scY);
00623
00625 MapTriangle2d(const MapTriangle2d &map);
00626
00627 virtual ~MapTriangle2d();
00628 virtual MapTriangle2d* clone() const;
00629
00630 virtual MapReal2d jacobian(const Real x, const Real y) const;
00631
00632 Real2d operator()(const Real x, const Real y) const {
00633 conceptsAssert(0.0 <= y, Assertion());
00634 conceptsAssert(0.0 <= x, Assertion());
00635 conceptsAssert(y <= x, Assertion());
00636 conceptsAssert(x <= 1.0, Assertion());
00637 return Real2d(map_, scx_ * x, scy_ * (x == 0 ? 0 : y/x));
00638 }
00639 protected:
00640 virtual std::ostream& info(std::ostream& os) const;
00641 private:
00643 uchar* map_;
00644
00646 uint sz_;
00647
00649 const Real scx_;
00650
00652 const Real scy_;
00653 };
00654
00655
00656
00657
00662 class MappingQuad2d : public Map2d {
00663 public:
00668 virtual Real2d operator()(Real x, Real y) const = 0;
00669
00671 virtual Real jacobianDeterminant(const Real x, const Real y) const;
00672
00674 virtual MapReal2d jacobian(const Real x, const Real y) const = 0;
00675
00677 virtual MapReal2d jacobianInverse(const Real x, const Real y) const;
00678
00683 virtual MapReal2d hessian(uint i, const Real x, const Real y) const = 0;
00684
00702 virtual Real lineElement(const Real x, const uint edge) const;
00703
00711 virtual MappingEdge2d* edge(const uint edge) const {
00712 return new MappingQuadEdge2d(*this, edge);
00713 }
00714
00718 virtual MappingQuad2d* part(const Real2d x0, const Real2d y0) const;
00719
00721 virtual MappingQuad2d* clone() const = 0;
00722 protected:
00723 virtual std::ostream& info(std::ostream& os) const;
00724 };
00725
00726
00727
00736 class MapQuad2d : public MappingQuad2d {
00737 public:
00750 MapQuad2d(const char* map, Real scX, Real scY,
00751 Real2d org = Real2d(0.0, 0.0), Real stretch = 1.0);
00752 MapQuad2d(const char* map, Real scX, Real scY, Real2d org,
00753 Real2d scaling);
00754
00756 MapQuad2d(const MapQuad2d &map);
00757 virtual ~MapQuad2d();
00758
00759 virtual Real2d operator()(Real x, Real y) const {
00760 Real2d v(map_, scx_ * x, scy_ * y);
00761 return Real2d(v[0]*scaling_[0] + org_[0], v[1]*scaling_[1] + org_[0]);
00762 }
00763
00764 virtual MapReal2d jacobian(const Real x, const Real y) const;
00765
00766 virtual MapReal2d hessian(uint i, const Real x, const Real y) const;
00767
00768 virtual MapQuad2d* clone() const { return new MapQuad2d(*this); }
00769 protected:
00770 virtual std::ostream& info(std::ostream& os) const;
00771 private:
00773 uchar* map_;
00774
00776 uint sz_;
00777
00779 Real scx_;
00780
00782 Real scy_;
00783
00784 Real2d org_;
00785 Real2d scaling_;
00786
00788 void operator=(const MapQuad2d &);
00789 };
00790
00791
00792
00798 class VertexQuad2d : public MappingQuad2d {
00799 public:
00802 VertexQuad2d(Real2d vtx0, Real2d vtx1, Real2d vtx2, Real2d vtx3);
00804 VertexQuad2d(const VertexQuad2d& v);
00805 virtual ~VertexQuad2d();
00806 virtual Real2d operator()(Real x, Real y) const;
00807
00812 virtual MapReal2d jacobian(const Real x, const Real y) const;
00813
00814 virtual MapReal2d hessian(uint i, const Real x, const Real y) const;
00815
00820 virtual Real lineElement(const Real x, const uint edge);
00821
00822 virtual MappingStraightEdge2d* edge(const uint edge) const;
00823
00824 virtual VertexQuad2d* part(const Real2d x0, const Real2d y0) const;
00825
00826 virtual VertexQuad2d* clone() const;
00827
00828 virtual bool straight() const {return true;};
00829 protected:
00830 virtual std::ostream& info(std::ostream& os) const;
00831 private:
00833 Real2d vtx_[4];
00835 Real len_[4];
00837 bool hasLength_;
00838 };
00839
00840
00841
00852 class BlendingQuad2d : public MappingQuad2d {
00853 public:
00883 BlendingQuad2d(const MappingEdge2d* edgemap0,
00884 const MappingEdge2d* edgemap1,
00885 const MappingEdge2d* edgemap2,
00886 const MappingEdge2d* edgemap3 = 0,
00887 const Real2d* vtx0 = 0, const Real2d* vtx1 = 0,
00888 const Real2d* vtx2 = 0, const Real2d* vtx3 = 0);
00890 BlendingQuad2d(const BlendingQuad2d& v);
00891 ~BlendingQuad2d();
00892 virtual Real2d operator()(Real x, Real y) const;
00893 virtual MapReal2d jacobian(const Real x, const Real y) const;
00894 virtual MapReal2d hessian(uint i, const Real x, const Real y) const;
00895 virtual Real lineElement(const Real x, const uint edge) const;
00896 virtual MappingEdge2d* edge(const uint edge) const {
00897 conceptsAssert(edge < 4, Assertion());
00898 return edgemap_[edge]->clone();
00899 }
00900 virtual BlendingQuad2d* clone() const { return new BlendingQuad2d(*this); }
00901 protected:
00902 virtual std::ostream& info(std::ostream& os) const;
00903 private:
00905 Real2d vtx_[4];
00907 const MappingEdge2d* edgemap_[4];
00909 void testJacobian_() const;
00910 };
00911
00912
00913
00918 class PartMappingQuad2d : public MappingQuad2d {
00919 public:
00926 PartMappingQuad2d(const MappingQuad2d& map,
00927 const Real2d xi0, const Real2d xi1);
00929 PartMappingQuad2d(const PartMappingQuad2d &map);
00931 virtual PartMappingQuad2d* clone() const;
00935 virtual Real2d operator()(Real x, Real y) const;
00936 virtual MapReal2d jacobian(const Real x, const Real y) const;
00937 virtual MapReal2d hessian(uint i, const Real x, const Real y) const;
00938 virtual MappingEdge2d* edge(const uint edge) const;
00939 protected:
00940 virtual std::ostream& info(std::ostream& os) const;
00941 private:
00943 std::auto_ptr<const MappingQuad2d> map_;
00947 const Real2d x0_;
00951 const Real2d d_;
00952
00954 inline const Real2d xi_(const Real x, const Real y) const {
00955 return x0_ + Real2d(x * d_[0], y * d_[1]);
00956 }
00957 };
00958
00959
00960
00967 class InverseVertexQuadSector2d : public Map2d {
00968 public:
00971 InverseVertexQuadSector2d(const Real2d vtx0, const Real2d vtx1,
00972 const Real2d vtx2, const Real2d vtx3);
00976 InverseVertexQuadSector2d(const Sequence<Real2d> x);
00977
00978 InverseVertexQuadSector2d(const InverseVertexQuadSector2d& v);
00979 virtual ~InverseVertexQuadSector2d();
00980 virtual Real2d operator()(const Real2d x) const;
00981 virtual MapReal2d jacobian(const Real2d x) const;
00982 virtual bool is_inregion(const Real2d x) const;
00983 virtual bool is_inpatch(const Real2d x) const;
00984 virtual InverseVertexQuadSector2d* clone() const;
00985
00986 protected:
00987 virtual std::ostream& info(std::ostream& os) const;
00988
00989 private:
00991 void construct_(const Real2d vtx0, const Real2d vtx1,
00992 const Real2d vtx2, const Real2d vtx3);
00994 Real2d sector_p_[4];
00996 Real2d vtx_[4];
00997 };
00998
00999
01000
01003 class MapTriangle3d : public Map2d {
01004 public:
01015 MapTriangle3d(const char* map, Real scX, Real scY);
01016
01023 MapTriangle3d(Real3d vtx0, Real3d vtx1, Real3d vtx2);
01024
01026 MapTriangle3d(const MapTriangle3d &map);
01027 ~MapTriangle3d() { delete[] map_; };
01028
01036 Real3d operator()(Real x, Real y) const {
01037 if (map_)
01038 return Real3d(map_, scx_ * x, scy_ * y);
01039 else {
01040 Real3d res;
01041 res.lincomb(B1_, B2_, x, x*y);
01042 res += b_;
01043 return res;
01044 }
01045 }
01046
01048 inline MapTriangle3d* clone() const {return new MapTriangle3d(*this);};
01049 private:
01051 uchar* map_;
01052
01054 uint sz_;
01055
01057 Real scx_;
01058
01060 Real scy_;
01061
01063 Real3d B1_, B2_, b_;
01064
01066 void operator=(const MapTriangle3d &);
01067 };
01068
01069 }
01070
01071 #endif // elementMaps_hh