00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef DG_FUNCTION_HPP
00021 #define DG_FUNCTION_HPP
00022
00023 #include <FiniteElementTraits.hpp>
00024 #include <DGFunctionBase.hpp>
00025
00034 template <typename MeshType,
00035 typename FiniteElementTraits>
00036 class DGFunction
00037 : public DGFunctionBase
00038 {
00039 private:
00040 typedef typename MeshType::CellType
00041 CellType;
00043 typedef
00044 typename FiniteElementTraits::Transformation
00045 Transformation;
00048 typedef
00049 typename FiniteElementTraits::Type
00050 FiniteElementType;
00053 ConstReferenceCounting<MeshType>
00054 __mesh;
00063 DGFunction(const DGFunction<MeshType,FiniteElementTraits>& f);
00064 public:
00072 real_t operator()(const TinyVector<3,real_t>& x) const
00073 {
00074 typename MeshType::const_iterator icell = __mesh->find(x);
00075 if (icell.end()) {
00076 return __outsideValue;
00077 }
00078
00079 const CellType& K = *icell;
00080 Transformation T(K);
00081
00082 TinyVector<3, real_t> xhat;
00083 T.invertT(x, xhat);
00084
00085 real_t value = 0;
00086 for (size_t l=0; l<FiniteElementType::numberOfDegreesOfFreedom; ++l) {
00087 value += __values[(*__dofPositionsSet)(icell.number(),l)]*FiniteElementType::instance().W(l,xhat);
00088 }
00089
00090 return value;
00091 }
00092
00098 void operator=(const ScalarFunctionBase& f)
00099 {
00100
00101
00102 __outsideValue = 0;
00103
00104 if (f.type() == this->type()) {
00105 const DGFunctionBase& dgBase = dynamic_cast<const DGFunctionBase&>(f);
00106 if ((dgBase.discretizationType() == this->discretizationType()) and
00107 (dgBase.baseMesh() == this->baseMesh())) {
00108
00109 const DGFunction<MeshType,FiniteElementTraits>& dg
00110 = dynamic_cast<const DGFunction<MeshType,FiniteElementTraits>&>(dgBase);
00111 __values = dg.__values;
00112 return;
00113 }
00114 }
00115 for (size_t i=0; i<__values.size(); i++) {
00116 const TinyVector<3>& x = __dofPositionsSet->vertex(i);
00117 __values[i] = f(x);
00118 }
00119 }
00120
00128 TinyVector<3,real_t>
00129 gradient(const TinyVector<3,real_t>& x) const
00130 {
00131 typename MeshType::const_iterator icell = __mesh->find(x);
00132 if (icell.end()) {
00133 return 0;
00134 }
00135
00136 const CellType& K = *icell;
00137 Transformation T(K);
00138
00139 TinyVector<3, real_t> xhat;
00140 T.invertT(x, xhat);
00141
00142 TinyVector<3, real_t> referenceGradient = 0;
00143 for (size_t l=0; l<FiniteElementType::numberOfDegreesOfFreedom; ++l) {
00144 const real_t value = __values[(*__dofPositionsSet)(icell.number(),l)];
00145 referenceGradient[0] += value*FiniteElementType::instance().dxW(l,xhat);
00146 referenceGradient[1] += value*FiniteElementType::instance().dyW(l,xhat);
00147 referenceGradient[2] += value*FiniteElementType::instance().dzW(l,xhat);
00148 }
00149
00150 TinyMatrix<3,3, real_t> J;
00151 {
00152 TinyVector<3, real_t> temp;
00153
00154 T.dx(x,temp);
00155 for(size_t i=0; i<3; ++i) {
00156 J(0,i) = temp[i];
00157 }
00158
00159 T.dy(x,temp);
00160 for(size_t i=0; i<3; ++i) {
00161 J(1,i) = temp[i];
00162 }
00163
00164 T.dz(x,temp);
00165 for(size_t i=0; i<3; ++i) {
00166 J(2,i) = temp[i];
00167 }
00168 }
00169
00170 TinyVector<3, real_t> result;
00171
00172 gaussPivot(J, referenceGradient, result);
00173 return result;
00174 }
00175
00183 real_t dx(const TinyVector<3>& x) const
00184 {
00185 return gradient(x)[0];
00186 }
00187
00195 real_t dy(const TinyVector<3>& x) const
00196 {
00197 return gradient(x)[1];
00198 }
00199
00207 real_t dz(const TinyVector<3>& x) const
00208 {
00209 return gradient(x)[2];
00210 }
00211
00217 DGFunction(ConstReferenceCounting<MeshType> mesh)
00218 : DGFunctionBase(mesh,
00219 ScalarDiscretizationTypeBase::Type(FiniteElementTraits::ScalarDiscretizationTypeBase)),
00220 __mesh(mesh)
00221 {
00222 ;
00223 }
00224
00231 DGFunction(ConstReferenceCounting<MeshType> mesh,
00232 const ScalarFunctionBase& f)
00233 : DGFunctionBase(mesh,
00234 ScalarDiscretizationTypeBase::Type(FiniteElementTraits::ScalarDiscretizationTypeBase)),
00235 __mesh(mesh)
00236 {
00237 (*this) = f;
00238 }
00239
00246 DGFunction(ConstReferenceCounting<MeshType> mesh,
00247 const real_t& d)
00248 : DGFunctionBase(mesh, ScalarDiscretizationTypeBase::Type(FiniteElementTraits::ScalarDiscretizationTypeBase)),
00249 __mesh(mesh)
00250 {
00251 __values = d;
00252 }
00253
00260 DGFunction(ConstReferenceCounting<MeshType> mesh,
00261 const Vector<real_t>& values)
00262 : DGFunctionBase(mesh, ScalarDiscretizationTypeBase::Type(FiniteElementTraits::ScalarDiscretizationTypeBase)),
00263 __mesh(mesh)
00264 {
00265 ASSERT(__values.size() == values.size());
00266 __values = values;
00267 }
00268
00273 ~DGFunction()
00274 {
00275 ;
00276 }
00277 };
00278
00279 #endif // DG_FUNCTION_HPP