00001
00002
00003 #ifndef DUNE_LAGRANGESHAPEFUNCTIONS_HH
00004 #define DUNE_LAGRANGESHAPEFUNCTIONS_HH
00005
00006 #include<iostream>
00007 #include<dune/common/fvector.hh>
00008 #include<dune/common/exceptions.hh>
00009 #include<dune/common/misc.hh>
00010 #include<dune/common/geometrytype.hh>
00011
00012 #include"shapefunctions.hh"
00013 #include"lagrange/cubeshapefunctions.hh"
00014 #include"lagrange/prismshapefunctions.hh"
00015 #include"lagrange/pyramidshapefunctions.hh"
00016 #include"lagrange/simplexshapefunctions.hh"
00017
00023 namespace Dune
00024 {
00030
00031
00032
00033
00034
00035
00041 template<typename C, typename T, int d>
00042 class LagrangeShapeFunction : public ShapeFunction<C,T,d,1>
00043 {
00044 public:
00045
00046 enum { dim=d };
00047 enum { comps=1 };
00048 typedef C CoordType;
00049 typedef T ResultType;
00050
00052 virtual const FieldVector<CoordType,dim>& position () const = 0;
00053 };
00054
00055
00056
00062 template<typename C, typename T, int d>
00063 class LagrangeShapeFunctionSet : public ShapeFunctionSet<C,T,d,1>
00064 {
00065 public:
00066
00067 enum { dim=d };
00068 enum { comps=1 };
00069
00070
00071 typedef C CoordType;
00072 typedef T ResultType;
00073 typedef LagrangeShapeFunction<CoordType,ResultType,dim> value_type;
00074
00076 virtual const value_type& operator[] (int i) const = 0;
00077 };
00078
00079
00080
00081
00082
00083
00084
00089 template<typename Imp>
00090 class LagrangeShapeFunctionWrapper :
00091 public LagrangeShapeFunction<typename Imp::CoordType,typename Imp::ResultType,Imp::dim>,
00092 private Imp
00093 {
00094 public:
00095
00096
00097 enum { dim=Imp::dim };
00098 enum { comps=1 };
00099
00100
00101 typedef typename Imp::CoordType CoordType;
00102 typedef typename Imp::ResultType ResultType;
00103 typedef Imp ImplementationType;
00104
00106 LagrangeShapeFunctionWrapper& operator= (const Imp& imp)
00107 {
00108 Imp::operator=(imp);
00109 return *this;
00110 }
00111
00113 virtual ResultType evaluateFunction (int comp, const FieldVector<CoordType,dim>& x) const
00114 {
00115 return Imp::evaluateFunction(comp,x);
00116 }
00117
00119 virtual ResultType evaluateDerivative (int comp, int dir, const FieldVector<CoordType,dim>& x) const
00120 {
00121 return Imp::evaluateDerivative(comp,dir,x);
00122 }
00123
00125 virtual int localindex (int comp) const
00126 {
00127 return Imp::localindex(comp);
00128 }
00129
00131 virtual int codim () const
00132 {
00133 return Imp::codim();
00134 }
00135
00137 virtual int entity () const
00138 {
00139 return Imp::entity();
00140 }
00141
00143 virtual int entityindex () const
00144 {
00145 return Imp::entityindex();
00146 }
00147
00149 virtual const FieldVector<CoordType,dim>& position () const
00150 {
00151 return Imp::position();
00152 }
00153 };
00154
00155
00156
00157
00162 template<typename Imp>
00163 class LagrangeShapeFunctionSetWrapper :
00164 public LagrangeShapeFunctionSet<typename Imp::CoordType,typename Imp::ResultType,Imp::dim>,
00165 private Imp
00166 {
00167 public:
00168
00169
00170 enum { dim=Imp::dim };
00171 enum { comps=1 };
00172
00173
00174 typedef typename Imp::CoordType CoordType;
00175 typedef typename Imp::ResultType ResultType;
00176 typedef Imp ImplementationType;
00177 typedef LagrangeShapeFunction<CoordType,ResultType,dim> value_type;
00178
00179
00181 virtual int size () const
00182 {
00183 return Imp::size();
00184 }
00185
00187 virtual int size (int entity, int codim) const
00188 {
00189 return Imp::size(entity,codim);
00190 }
00191
00193 virtual const value_type& operator[] (int i) const
00194 {
00195 return Imp::operator[](i);
00196 }
00197
00199 virtual int order () const
00200 {
00201 return Imp::order();
00202 }
00203
00205 virtual GeometryType type () const
00206 {
00207 return Imp::type();
00208 }
00209 };
00210
00211
00212
00213
00214
00215
00216
00217
00218
00224 template<typename C, typename T, int d>
00225 class LagrangeShapeFunctionSetContainer : public ShapeFunctionSetContainer<C,T,d,1,Power_m_p<3,d>::power >
00226 {
00227 public:
00228
00229 enum { dim=d };
00230 enum { comps=1 };
00231 enum { maxsize=Power_m_p<3,dim>::power };
00232
00233
00234 typedef C CoordType;
00235 typedef T ResultType;
00236
00238 typedef LagrangeShapeFunctionSet<C,T,d> value_type;
00239
00240 const value_type& operator() (GeometryType type, int order) const
00241 {
00242 if ( type.isCube() )
00243 {
00244 if (order==0) return wrappedp0cube;
00245 if (order==1) return wrappedp1cube;
00246 if (order==2) return wrappedp2cube;
00247 DUNE_THROW(RangeError, "order not available for cubes");
00248 }
00249
00250 if ( type.isSimplex() )
00251 {
00252 if (order==0) return wrappedp0simplex;
00253 if (order==1) return wrappedp1simplex;
00254 if (order==2) return wrappedp2simplex;
00255 DUNE_THROW(RangeError, "order not available for simplex");
00256 }
00257
00258 if ( type.isPyramid() )
00259 {
00260 DUNE_THROW(RangeError, "No pyramid for this dimension");
00261 }
00262
00263 if ( type.isPrism() )
00264 {
00265 DUNE_THROW(RangeError, "No prism for this dimension ");
00266 }
00267
00268 DUNE_THROW(RangeError, "type or order not available");
00269 }
00270
00271 private:
00272
00273 typedef LagrangeShapeFunctionWrapper<P0CubeShapeFunction<C,T,d> > WrappedP0CubeShapeFunction;
00274 typedef P0CubeShapeFunctionSet<C,T,d,WrappedP0CubeShapeFunction> P0CubeWrappedShapeFunctionSet;
00275 typedef LagrangeShapeFunctionSetWrapper<P0CubeWrappedShapeFunctionSet> WrappedP0CubeShapeFunctionSet;
00276 WrappedP0CubeShapeFunctionSet wrappedp0cube;
00277
00278 typedef LagrangeShapeFunctionWrapper<P1CubeShapeFunction<C,T,d> > WrappedP1CubeShapeFunction;
00279 typedef P1CubeShapeFunctionSet<C,T,d,WrappedP1CubeShapeFunction> P1CubeWrappedShapeFunctionSet;
00280 typedef LagrangeShapeFunctionSetWrapper<P1CubeWrappedShapeFunctionSet> WrappedP1CubeShapeFunctionSet;
00281 WrappedP1CubeShapeFunctionSet wrappedp1cube;
00282
00283 typedef LagrangeShapeFunctionWrapper<P2CubeShapeFunction<C,T,d> > WrappedP2CubeShapeFunction;
00284 typedef P2CubeShapeFunctionSet<C,T,d,WrappedP2CubeShapeFunction> P2CubeWrappedShapeFunctionSet;
00285 typedef LagrangeShapeFunctionSetWrapper<P2CubeWrappedShapeFunctionSet> WrappedP2CubeShapeFunctionSet;
00286 WrappedP2CubeShapeFunctionSet wrappedp2cube;
00287
00288
00289 typedef LagrangeShapeFunctionWrapper<P0SimplexShapeFunction<C,T,d> > WrappedP0SimplexShapeFunction;
00290 typedef P0SimplexShapeFunctionSet<C,T,d,WrappedP0SimplexShapeFunction> P0SimplexWrappedShapeFunctionSet;
00291 typedef LagrangeShapeFunctionSetWrapper<P0SimplexWrappedShapeFunctionSet> WrappedP0SimplexShapeFunctionSet;
00292 WrappedP0SimplexShapeFunctionSet wrappedp0simplex;
00293
00294 typedef LagrangeShapeFunctionWrapper<P1SimplexShapeFunction<C,T,d> > WrappedP1SimplexShapeFunction;
00295 typedef P1SimplexShapeFunctionSet<C,T,d,WrappedP1SimplexShapeFunction> P1SimplexWrappedShapeFunctionSet;
00296 typedef LagrangeShapeFunctionSetWrapper<P1SimplexWrappedShapeFunctionSet> WrappedP1SimplexShapeFunctionSet;
00297 WrappedP1SimplexShapeFunctionSet wrappedp1simplex;
00298
00299 typedef LagrangeShapeFunctionWrapper<P2SimplexShapeFunction<C,T,d> > WrappedP2SimplexShapeFunction;
00300 typedef P2SimplexShapeFunctionSet<C,T,d,WrappedP2SimplexShapeFunction> P2SimplexWrappedShapeFunctionSet;
00301 typedef LagrangeShapeFunctionSetWrapper<P2SimplexWrappedShapeFunctionSet> WrappedP2SimplexShapeFunctionSet;
00302 WrappedP2SimplexShapeFunctionSet wrappedp2simplex;
00303 };
00304
00306 template<typename C, typename T>
00307 class LagrangeShapeFunctionSetContainer<C,T,3> : public ShapeFunctionSetContainer<C,T,3,1,Power_m_p<3,3>::power >
00308 {
00309 public:
00310
00311 enum { dim=3 };
00312 enum { comps=1 };
00313 enum { maxsize=Power_m_p<3,dim>::power };
00314
00315
00316 typedef C CoordType;
00317 typedef T ResultType;
00318
00320 typedef LagrangeShapeFunctionSet<C,T,3> value_type;
00321
00322 const value_type& operator() (GeometryType type, int order) const
00323 {
00324 if ( type.isCube() )
00325 {
00326 if (order==0) return wrappedp0cube;
00327 if (order==1) return wrappedp1cube;
00328 if (order==2) return wrappedp2cube;
00329 DUNE_THROW(RangeError, "order not available for cubes");
00330 }
00331
00332 if ( type.isSimplex() )
00333 {
00334 if (order==0) return wrappedp0simplex;
00335 if (order==1) return wrappedp1simplex;
00336 if (order==2) return wrappedp2simplex;
00337 DUNE_THROW(RangeError, "order not available for simplex");
00338 }
00339
00340 if (type.isPyramid() )
00341 {
00342 if (order==0) return wrappedp0pyramid;
00343 if (order==1) return wrappedp1pyramid;
00344 DUNE_THROW(RangeError, "order not available for pyramid");
00345 }
00346
00347 if (type.isPrism())
00348 {
00349 if (order==0) return wrappedp0prism;
00350 if (order==1) return wrappedp1prism;
00351 if (order==2) return wrappedp2prism;
00352 else
00353 DUNE_THROW(RangeError, "order not available for prism");
00354 }
00355
00356 DUNE_THROW(RangeError, "type or order not available");
00357 }
00358
00359 private:
00360
00361 typedef LagrangeShapeFunctionWrapper<P0CubeShapeFunction<C,T,dim> > WrappedP0CubeShapeFunction;
00362 typedef P0CubeShapeFunctionSet<C,T,dim,WrappedP0CubeShapeFunction> P0CubeWrappedShapeFunctionSet;
00363 typedef LagrangeShapeFunctionSetWrapper<P0CubeWrappedShapeFunctionSet> WrappedP0CubeShapeFunctionSet;
00364 WrappedP0CubeShapeFunctionSet wrappedp0cube;
00365
00366 typedef LagrangeShapeFunctionWrapper<P1CubeShapeFunction<C,T,dim> > WrappedP1CubeShapeFunction;
00367 typedef P1CubeShapeFunctionSet<C,T,dim,WrappedP1CubeShapeFunction> P1CubeWrappedShapeFunctionSet;
00368 typedef LagrangeShapeFunctionSetWrapper<P1CubeWrappedShapeFunctionSet> WrappedP1CubeShapeFunctionSet;
00369 WrappedP1CubeShapeFunctionSet wrappedp1cube;
00370
00371 typedef LagrangeShapeFunctionWrapper<P2CubeShapeFunction<C,T,dim> > WrappedP2CubeShapeFunction;
00372 typedef P2CubeShapeFunctionSet<C,T,dim,WrappedP2CubeShapeFunction> P2CubeWrappedShapeFunctionSet;
00373 typedef LagrangeShapeFunctionSetWrapper<P2CubeWrappedShapeFunctionSet> WrappedP2CubeShapeFunctionSet;
00374 WrappedP2CubeShapeFunctionSet wrappedp2cube;
00375
00376
00377 typedef LagrangeShapeFunctionWrapper<P0SimplexShapeFunction<C,T,dim> > WrappedP0SimplexShapeFunction;
00378 typedef P0SimplexShapeFunctionSet<C,T,dim,WrappedP0SimplexShapeFunction> P0SimplexWrappedShapeFunctionSet;
00379 typedef LagrangeShapeFunctionSetWrapper<P0SimplexWrappedShapeFunctionSet> WrappedP0SimplexShapeFunctionSet;
00380 WrappedP0SimplexShapeFunctionSet wrappedp0simplex;
00381
00382 typedef LagrangeShapeFunctionWrapper<P1SimplexShapeFunction<C,T,dim> > WrappedP1SimplexShapeFunction;
00383 typedef P1SimplexShapeFunctionSet<C,T,dim,WrappedP1SimplexShapeFunction> P1SimplexWrappedShapeFunctionSet;
00384 typedef LagrangeShapeFunctionSetWrapper<P1SimplexWrappedShapeFunctionSet> WrappedP1SimplexShapeFunctionSet;
00385 WrappedP1SimplexShapeFunctionSet wrappedp1simplex;
00386
00387 typedef LagrangeShapeFunctionWrapper<P2SimplexShapeFunction<C,T,dim> > WrappedP2SimplexShapeFunction;
00388 typedef P2SimplexShapeFunctionSet<C,T,dim,WrappedP2SimplexShapeFunction> P2SimplexWrappedShapeFunctionSet;
00389 typedef LagrangeShapeFunctionSetWrapper<P2SimplexWrappedShapeFunctionSet> WrappedP2SimplexShapeFunctionSet;
00390 WrappedP2SimplexShapeFunctionSet wrappedp2simplex;
00391
00392
00393 typedef LagrangeShapeFunctionWrapper<P0PyramidShapeFunction<C,T> > WrappedP0PyramidShapeFunction;
00394 typedef P0PyramidShapeFunctionSet<C,T,WrappedP0PyramidShapeFunction> P0PyramidWrappedShapeFunctionSet;
00395 typedef LagrangeShapeFunctionSetWrapper<P0PyramidWrappedShapeFunctionSet> WrappedP0PyramidShapeFunctionSet;
00396 WrappedP0PyramidShapeFunctionSet wrappedp0pyramid;
00397
00398 typedef LagrangeShapeFunctionWrapper<P1PyramidShapeFunction<C,T> > WrappedP1PyramidShapeFunction;
00399 typedef P1PyramidShapeFunctionSet<C,T,WrappedP1PyramidShapeFunction> P1PyramidWrappedShapeFunctionSet;
00400 typedef LagrangeShapeFunctionSetWrapper<P1PyramidWrappedShapeFunctionSet> WrappedP1PyramidShapeFunctionSet;
00401 WrappedP1PyramidShapeFunctionSet wrappedp1pyramid;
00402
00403
00404 typedef LagrangeShapeFunctionWrapper<P0PrismShapeFunction<C,T> > WrappedP0PrismShapeFunction;
00405 typedef P0PrismShapeFunctionSet<C,T,WrappedP0PrismShapeFunction> P0PrismWrappedShapeFunctionSet;
00406 typedef LagrangeShapeFunctionSetWrapper<P0PrismWrappedShapeFunctionSet> WrappedP0PrismShapeFunctionSet;
00407 WrappedP0PrismShapeFunctionSet wrappedp0prism;
00408
00409 typedef LagrangeShapeFunctionWrapper<P1PrismShapeFunction<C,T> > WrappedP1PrismShapeFunction;
00410 typedef P1PrismShapeFunctionSet<C,T,WrappedP1PrismShapeFunction> P1PrismWrappedShapeFunctionSet;
00411 typedef LagrangeShapeFunctionSetWrapper<P1PrismWrappedShapeFunctionSet> WrappedP1PrismShapeFunctionSet;
00412 WrappedP1PrismShapeFunctionSet wrappedp1prism;
00413
00414 typedef LagrangeShapeFunctionWrapper<P2PrismShapeFunction<C,T> > WrappedP2PrismShapeFunction;
00415 typedef P2PrismShapeFunctionSet<C,T,WrappedP2PrismShapeFunction> P2PrismWrappedShapeFunctionSet;
00416 typedef LagrangeShapeFunctionSetWrapper<P2PrismWrappedShapeFunctionSet> WrappedP2PrismShapeFunctionSet;
00417 WrappedP2PrismShapeFunctionSet wrappedp2prism;
00418 };
00419
00420
00421
00422 template<typename C, typename T, int d>
00423 struct LagrangeShapeFunctions {
00424 static P0CubeShapeFunctionSetContainer<C,T,d> p0cube;
00425 static P1CubeShapeFunctionSetContainer<C,T,d> p1cube;
00426 static P2CubeShapeFunctionSetContainer<C,T,d> p2cube;
00427 static P0SimplexShapeFunctionSetContainer<C,T,d> p0simplex;
00428 static P1SimplexShapeFunctionSetContainer<C,T,d> p1simplex;
00429 static P2SimplexShapeFunctionSetContainer<C,T,d> p2simplex;
00430 static LagrangeShapeFunctionSetContainer<C,T,d> general;
00431 };
00432
00434 }
00435 #endif