FEMFunction< MeshType, FiniteElementTraits > Class Template Reference

#include <FEMFunction.hpp>

Inheritance diagram for FEMFunction< MeshType, FiniteElementTraits >:

Inheritance graph
[legend]
Collaboration diagram for FEMFunction< MeshType, FiniteElementTraits >:

Collaboration graph
[legend]

List of all members.

Public Types

enum  Type {
  cfunction, constant, convection, dgfunction,
  femfunction, linearBasis, spectral, unaryMinus,
  modulo, sum, difference, product,
  division, power, min, max,
  gt, ge, lt, le,
  ne, eq, and_, or_,
  xor_, not_, derivate, integrate,
  normal, domainCharacteristic, meshCharacteristic, objectCharacteristic,
  composed, references, FEM0, undefined
}

Public Member Functions

real_t operator() (const TinyVector< 3, real_t > &x) const
void operator= (const ScalarFunctionBase &f)
TinyVector< 3, real_t > gradient (const TinyVector< 3, real_t > &x) const
real_t dx (const TinyVector< 3 > &x) const
real_t dy (const TinyVector< 3 > &x) const
real_t dz (const TinyVector< 3 > &x) const
 FEMFunction (ConstReferenceCounting< MeshType > mesh)
 FEMFunction (ConstReferenceCounting< MeshType > mesh, const ScalarFunctionBase &f)
 FEMFunction (ConstReferenceCounting< MeshType > mesh, const real_t &d)
 FEMFunction (ConstReferenceCounting< MeshType > mesh, const Vector< real_t > &values)
 ~FEMFunction ()
void setOutsideValue (const real_t &value)
const real_t & outsideValue () const
bool canBeSimplified () const
bool hasSameType (const FEMFunctionBase &f) const
ConstReferenceCounting< MeshbaseMesh () const
const
ScalarDiscretizationTypeBase::Type
discretizationType () const
const Vector< real_t > & values () const
real_t & operator[] (const size_t &i)
const real_t & operator[] (const size_t &i) const
void setName (const std::string &name)
const std::string & name () const
const Typetype () const
real_t operator() (const real_t &x, const real_t &y, const real_t &z) const
virtual real_t dx (const TinyVector< 3, real_t > &x) const
virtual real_t dy (const TinyVector< 3, real_t > &x) const
virtual real_t dz (const TinyVector< 3, real_t > &x) const

Protected Member Functions

std::ostream & __put (std::ostream &os) const

Protected Attributes

ConstReferenceCounting< Mesh__baseMesh
ConstReferenceCounting
< ScalarDegreeOfFreedomPositionsSet
__dofPositionsSet
Vector< real_t > __values
const ScalarDiscretizationTypeFEM __discretizationType
real_t __outsideValue
const Type __type
std::string __name

Private Member Functions

 FEMFunction (const FEMFunction< MeshType, FiniteElementTraits > &f)

Private Attributes

ConstReferenceCounting< MeshType > __mesh

Friends

std::ostream & operator<< (std::ostream &os, const ScalarFunctionBase &scalarFunction)


Detailed Description

template<typename MeshType, typename FiniteElementTraits>
class FEMFunction< MeshType, FiniteElementTraits >

Definition at line 37 of file FEMFunction.hpp.


Member Enumeration Documentation

enum ScalarFunctionBase::Type [inherited]

Enumerator:
cfunction 
constant 
convection 
dgfunction 
femfunction 
linearBasis 
spectral 
unaryMinus 
modulo 
sum 
difference 
product 
division 
power 
min 
max 
gt 
ge 
lt 
le 
ne 
eq 
and_ 
or_ 
xor_ 
not_ 
derivate 
integrate 
normal 
domainCharacteristic 
meshCharacteristic 
objectCharacteristic 
composed 
references 
FEM0 
undefined 

Definition at line 40 of file ScalarFunctionBase.hpp.

00040             {
00041     cfunction,
00042     constant,
00043     convection,
00044     dgfunction,
00045     femfunction,
00046     linearBasis,
00047     spectral,
00048     unaryMinus,
00049 
00050     modulo,
00051     sum,
00052     difference,
00053     product,
00054     division,
00055     power,
00056 
00057     min,
00058     max,
00059 
00060     gt,
00061     ge,
00062     lt,
00063     le,
00064     ne,
00065     eq,
00066     and_,
00067     or_,
00068     xor_,
00069 
00070     not_,
00071 
00072     derivate,
00073     integrate,
00074 
00075     normal,
00076 
00077     domainCharacteristic,
00078     meshCharacteristic,
00079     objectCharacteristic,
00080 
00081     composed,
00082     references,
00083 
00084     FEM0,
00085 
00086     undefined
00087   };


Constructor & Destructor Documentation

template<typename MeshType, typename FiniteElementTraits>
FEMFunction< MeshType, FiniteElementTraits >::FEMFunction ( const FEMFunction< MeshType, FiniteElementTraits > &  f  )  [private]

Copy constructor

Parameters:
f given function
Note:
forbidden to avoid wild copies

template<typename MeshType, typename FiniteElementTraits>
FEMFunction< MeshType, FiniteElementTraits >::FEMFunction ( ConstReferenceCounting< MeshType >  mesh  )  [inline]

Constructor

Parameters:
mesh mesh supporting the function

Definition at line 218 of file FEMFunction.hpp.

00219     : FEMFunctionBase(mesh,
00220                       ScalarDiscretizationTypeBase::Type(FiniteElementTraits::ScalarDiscretizationTypeBase)),
00221       __mesh(mesh)
00222   {
00223     ;
00224   }

template<typename MeshType, typename FiniteElementTraits>
FEMFunction< MeshType, FiniteElementTraits >::FEMFunction ( ConstReferenceCounting< MeshType >  mesh,
const ScalarFunctionBase f 
) [inline]

Constructor

Parameters:
mesh mesh supporting the function
f function of initialization

Definition at line 232 of file FEMFunction.hpp.

00234     : FEMFunctionBase(mesh,
00235                       ScalarDiscretizationTypeBase::Type(FiniteElementTraits::ScalarDiscretizationTypeBase)),
00236       __mesh(mesh)
00237   {
00238     (*this) = f;
00239   }

template<typename MeshType, typename FiniteElementTraits>
FEMFunction< MeshType, FiniteElementTraits >::FEMFunction ( ConstReferenceCounting< MeshType >  mesh,
const real_t &  d 
) [inline]

Constructor

Parameters:
mesh mesh supporting the function
d value of initialization

Definition at line 247 of file FEMFunction.hpp.

References FEMFunctionBase::__values.

00249     : FEMFunctionBase(mesh, ScalarDiscretizationTypeBase::Type(FiniteElementTraits::ScalarDiscretizationTypeBase)),
00250       __mesh(mesh)
00251   {
00252     __values = d;
00253   }

template<typename MeshType, typename FiniteElementTraits>
FEMFunction< MeshType, FiniteElementTraits >::FEMFunction ( ConstReferenceCounting< MeshType >  mesh,
const Vector< real_t > &  values 
) [inline]

Constructor

Parameters:
mesh given mesh
values given values

Definition at line 261 of file FEMFunction.hpp.

References FEMFunctionBase::__values, ASSERT, and Vector< T >::size().

00263     : FEMFunctionBase(mesh, ScalarDiscretizationTypeBase::Type(FiniteElementTraits::ScalarDiscretizationTypeBase)),
00264       __mesh(mesh)
00265   {
00266     ASSERT(__values.size() == values.size());
00267     __values = values;
00268   }

Here is the call graph for this function:

template<typename MeshType, typename FiniteElementTraits>
FEMFunction< MeshType, FiniteElementTraits >::~FEMFunction (  )  [inline]

Destructor

Definition at line 274 of file FEMFunction.hpp.

00275   {
00276     ;
00277   }


Member Function Documentation

template<typename MeshType, typename FiniteElementTraits>
real_t FEMFunction< MeshType, FiniteElementTraits >::operator() ( const TinyVector< 3, real_t > &  x  )  const [inline, virtual]

Evaluates the FEMFunction at point x.

Parameters:
x the position of evaluation
Returns:
$ f(x) $

Implements ScalarFunctionBase.

Definition at line 73 of file FEMFunction.hpp.

References FEMFunction< MeshType, FiniteElementTraits >::__mesh, FEMFunctionBase::__outsideValue, and FEMFunctionBase::__values.

00074   {
00075     typename MeshType::const_iterator icell = __mesh->find(x);
00076     if (icell.end()) {
00077       return __outsideValue;
00078     }
00079 
00080     const CellType& K = *icell;
00081     Transformation T(K);
00082 
00083     TinyVector<3, real_t> xhat;
00084     T.invertT(x, xhat);
00085 
00086     real_t value = 0;
00087     for (size_t l=0; l<FiniteElementType::numberOfDegreesOfFreedom; ++l) {
00088       value += __values[(*__dofPositionsSet)(icell.number(),l)]*FiniteElementType::instance().W(l,xhat);
00089     }
00090 
00091     return value;
00092   }

template<typename MeshType, typename FiniteElementTraits>
void FEMFunction< MeshType, FiniteElementTraits >::operator= ( const ScalarFunctionBase f  )  [inline, virtual]

Affects a function to a FEMFunction

Parameters:
f original function

Implements FEMFunctionBase.

Definition at line 99 of file FEMFunction.hpp.

References FEMFunctionBase::__dofPositionsSet, FEMFunctionBase::__outsideValue, FEMFunctionBase::__values, FEMFunctionBase::baseMesh(), FEMFunctionBase::discretizationType(), Vector< T >::size(), and ScalarFunctionBase::type().

00100   {
00101     // during an affectation, outside values are set to 0 (the fem
00102     // function is "pure")
00103     __outsideValue = 0;
00104 
00105     if (f.type() == this->type()) {
00106       const FEMFunctionBase& femBase = dynamic_cast<const FEMFunctionBase&>(f);
00107       if ((femBase.discretizationType() == this->discretizationType()) and
00108           (femBase.baseMesh() == this->baseMesh())) {
00109         // if the function is of the same kind: just copy values
00110         const FEMFunction<MeshType,FiniteElementTraits>& fem
00111           = dynamic_cast<const FEMFunction<MeshType,FiniteElementTraits>&>(femBase);
00112         __values = fem.__values;
00113         return;
00114       }
00115     }
00116     for (size_t i=0; i<__values.size(); i++) {
00117       const TinyVector<3>& x = __dofPositionsSet->vertex(i);
00118       __values[i] = f(x);
00119     }
00120   }

Here is the call graph for this function:

template<typename MeshType, typename FiniteElementTraits>
TinyVector<3,real_t> FEMFunction< MeshType, FiniteElementTraits >::gradient ( const TinyVector< 3, real_t > &  x  )  const [inline, virtual]

Evaluates the function's gradient at position x

Parameters:
x position of evaluation
Returns:
$ \nabla f (x) \nabla $

Implements FEMFunctionBase.

Definition at line 130 of file FEMFunction.hpp.

References FEMFunction< MeshType, FiniteElementTraits >::__mesh, and FEMFunctionBase::__values.

Referenced by FEMFunction< MeshType, FiniteElementTraits >::dx(), FEMFunction< MeshType, FiniteElementTraits >::dy(), and FEMFunction< MeshType, FiniteElementTraits >::dz().

00131   {
00132     typename MeshType::const_iterator icell = __mesh->find(x);
00133     if (icell.end()) {
00134       return 0;
00135     }
00136 
00137     const CellType& K = *icell;
00138     Transformation T(K);
00139 
00140     TinyVector<3, real_t> xhat;
00141     T.invertT(x, xhat);
00142 
00143     TinyVector<3, real_t> referenceGradient = 0;
00144     for (size_t l=0; l<FiniteElementType::numberOfDegreesOfFreedom; ++l) {
00145       const real_t value = __values[(*__dofPositionsSet)(icell.number(),l)];
00146       referenceGradient[0] += value*FiniteElementType::instance().dxW(l,xhat);
00147       referenceGradient[1] += value*FiniteElementType::instance().dyW(l,xhat);
00148       referenceGradient[2] += value*FiniteElementType::instance().dzW(l,xhat);
00149     }
00150 
00151     TinyMatrix<3,3, real_t> J;
00152     {
00153       TinyVector<3, real_t> temp;
00154 
00155       T.dx(x,temp);
00156       for(size_t i=0; i<3; ++i) {
00157         J(0,i) = temp[i];
00158       }
00159 
00160       T.dy(x,temp);
00161       for(size_t i=0; i<3; ++i) {
00162         J(1,i) = temp[i];
00163       }
00164 
00165       T.dz(x,temp);
00166       for(size_t i=0; i<3; ++i) {
00167         J(2,i) = temp[i];
00168       }
00169     }
00170     // now we use 
00171     TinyVector<3, real_t> result;
00172 
00173     gaussPivot(J, referenceGradient, result);
00174     return result;
00175   }

template<typename MeshType, typename FiniteElementTraits>
real_t FEMFunction< MeshType, FiniteElementTraits >::dx ( const TinyVector< 3 > &  x  )  const [inline]

Evaluates first derivative of the function

Parameters:
x position of evaluation
Returns:
$ \partial_x f at position x $

Definition at line 184 of file FEMFunction.hpp.

References FEMFunction< MeshType, FiniteElementTraits >::gradient().

00185   {
00186     return gradient(x)[0];
00187   }

Here is the call graph for this function:

template<typename MeshType, typename FiniteElementTraits>
real_t FEMFunction< MeshType, FiniteElementTraits >::dy ( const TinyVector< 3 > &  x  )  const [inline]

Evaluates second derivative of the function

Parameters:
x position of evaluation
Returns:
$ \partial_y f at position x $

Definition at line 196 of file FEMFunction.hpp.

References FEMFunction< MeshType, FiniteElementTraits >::gradient().

00197   {
00198     return gradient(x)[1];
00199   }

Here is the call graph for this function:

template<typename MeshType, typename FiniteElementTraits>
real_t FEMFunction< MeshType, FiniteElementTraits >::dz ( const TinyVector< 3 > &  x  )  const [inline]

Evaluates third derivative of the function

Parameters:
x position of evaluation
Returns:
$ \partial_z f at position x $

Definition at line 208 of file FEMFunction.hpp.

References FEMFunction< MeshType, FiniteElementTraits >::gradient().

00209   {
00210     return gradient(x)[2];
00211   }

Here is the call graph for this function:

std::ostream& FEMFunctionBase::__put ( std::ostream &  os  )  const [inline, protected, virtual, inherited]

output of the FEMFunction

Parameters:
os output stream
Returns:
os

Implements ScalarFunctionBase.

Definition at line 64 of file FEMFunctionBase.hpp.

References FEMFunctionBase::__discretizationType, and ScalarDiscretizationTypeBase::name().

00065   {
00066     os << "{fem-" << ScalarDiscretizationTypeBase::name(__discretizationType) << '}';
00067     return os;
00068   }

Here is the call graph for this function:

void FEMFunctionBase::setOutsideValue ( const real_t &  value  )  [inline, inherited]

set outside value

Parameters:
value outside value

Definition at line 87 of file FEMFunctionBase.hpp.

References FEMFunctionBase::__outsideValue.

Referenced by FEMFunctionBuilder::build().

00088   {
00089     __outsideValue = value;
00090   }

const real_t& FEMFunctionBase::outsideValue (  )  const [inline, inherited]

Access to the outside value

Returns:
__outsidValue

Definition at line 97 of file FEMFunctionBase.hpp.

References FEMFunctionBase::__outsideValue.

Referenced by ScalarFunctionBuilder::Simplifier::__getOperatorF1F2SimplifiedFunction(), and ScalarFunctionBuilder::setUnaryMinus().

00098   {
00099     return __outsideValue;
00100   }

bool FEMFunctionBase::canBeSimplified (  )  const [inline, virtual, inherited]

Checks if the function can be simplified

Returns:
true

Implements ScalarFunctionBase.

Definition at line 107 of file FEMFunctionBase.hpp.

00108   {
00109     return true;
00110   }

bool FEMFunctionBase::hasSameType ( const FEMFunctionBase f  )  const [inline, inherited]

Check if a finite element function is of the same type

Parameters:
f given function
Returns:
true if discretization type and mesh are the same

Definition at line 119 of file FEMFunctionBase.hpp.

References FEMFunctionBase::__baseMesh, FEMFunctionBase::__discretizationType, and ScalarDiscretizationTypeBase::type().

Referenced by ScalarFunctionBuilder::Simplifier::__getOperatorSimplifiedFunction().

00120   {
00121     return ((__discretizationType.type() == f.__discretizationType.type())
00122             and (__baseMesh == f.__baseMesh));
00123   }

Here is the call graph for this function:

ConstReferenceCounting<Mesh> FEMFunctionBase::baseMesh (  )  const [inline, inherited]

const ScalarDiscretizationTypeBase::Type& FEMFunctionBase::discretizationType (  )  const [inline, inherited]

const Vector<real_t>& FEMFunctionBase::values (  )  const [inline, inherited]

real_t& FEMFunctionBase::operator[] ( const size_t &  i  )  [inline, inherited]

access to the value at the ith degree of freedom

Parameters:
i number of the degree of freedom
Returns:
__values[i]

Definition at line 162 of file FEMFunctionBase.hpp.

References FEMFunctionBase::__values.

00163   {
00164     return __values[i];
00165   }

const real_t& FEMFunctionBase::operator[] ( const size_t &  i  )  const [inline, inherited]

Read only Access to the value at the ith degree of freedom

Parameters:
i number of the degree of freedom
Returns:
__values[i]

Definition at line 174 of file FEMFunctionBase.hpp.

References FEMFunctionBase::__values.

00175   {
00176     return __values[i];
00177   }

void ScalarFunctionBase::setName ( const std::string &  name  )  [inline, inherited]

Sets the name of the function

Parameters:
name name to give to this function

Definition at line 109 of file ScalarFunctionBase.hpp.

References ScalarFunctionBase::__name.

Referenced by FunctionExpressionVariable::execute().

00110   {
00111     __name = name;
00112   }

const std::string& ScalarFunctionBase::name (  )  const [inline, inherited]

Gets the name of the function

Returns:
__name

Definition at line 119 of file ScalarFunctionBase.hpp.

References ScalarFunctionBase::__name.

00120   {
00121     return __name;
00122   }

const Type& ScalarFunctionBase::type (  )  const [inline, inherited]

real_t ScalarFunctionBase::operator() ( const real_t &  x,
const real_t &  y,
const real_t &  z 
) const [inline, inherited]

Evaluates the function at point $ (x,y,z) $

Parameters:
x $ x $
y $ y $
z $ z $
Returns:
$ f(x,y,z) $

Definition at line 162 of file ScalarFunctionBase.hpp.

00165   {
00166     return this->operator()(TinyVector<3, real_t>(x,y,z));    
00167   }

virtual real_t ScalarFunctionBase::dx ( const TinyVector< 3, real_t > &  x  )  const [inline, virtual, inherited]

Evaluates first derivative of the function

Parameters:
x position of evaluation
Returns:
$ \partial_x f $ at position $ x $

Definition at line 185 of file ScalarFunctionBase.hpp.

References ErrorHandler::normal.

00186   {
00187     std::stringstream errorMsg;
00188 
00189     errorMsg << "cannot compute derivative of non discrete functions :-(\n";
00190     errorMsg << "the function " << (*this) << " is not of that kind"
00191              << std::ends;
00192 
00193     throw ErrorHandler(__FILE__,__LINE__,
00194                        errorMsg.str(),
00195                        ErrorHandler::normal);
00196     return 0;
00197   }

virtual real_t ScalarFunctionBase::dy ( const TinyVector< 3, real_t > &  x  )  const [inline, virtual, inherited]

Evaluates second derivative of the function

Parameters:
x position of evaluation
Returns:
$ \partial_y f $ at position $ x $

Definition at line 206 of file ScalarFunctionBase.hpp.

References ErrorHandler::normal.

00207   {
00208     std::stringstream errorMsg;
00209 
00210     errorMsg << "cannot compute derivative of non discrete functions :-(\n";
00211     errorMsg << "the function " << (*this) << " is not of that kind"
00212              << std::ends;
00213 
00214     throw ErrorHandler(__FILE__,__LINE__,
00215                        errorMsg.str(),
00216                        ErrorHandler::normal);
00217     return 0;
00218   }

virtual real_t ScalarFunctionBase::dz ( const TinyVector< 3, real_t > &  x  )  const [inline, virtual, inherited]

Evaluates third derivative of the function

Parameters:
x position of evaluation
Returns:
$ \partial_z f $ at position $ x $

Definition at line 227 of file ScalarFunctionBase.hpp.

References ErrorHandler::normal.

00228   {
00229     std::stringstream errorMsg;
00230 
00231     errorMsg << "cannot compute derivative of non discrete functions :-(\n";
00232     errorMsg << "the function " << (*this) << " is not of that kind"
00233              << std::ends;
00234 
00235     throw ErrorHandler(__FILE__,__LINE__,
00236                        errorMsg.str(),
00237                        ErrorHandler::normal);
00238     return 0;
00239   }


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const ScalarFunctionBase scalarFunction 
) [friend, inherited]

Writes the function scalarFunction to the stream os

Parameters:
os the output stream
scalarFunction the function to write
Returns:
os

Definition at line 142 of file ScalarFunctionBase.hpp.

00144   {
00145     if (scalarFunction.__name.size()>0) {
00146       os << scalarFunction.__name;
00147       return os;
00148     } else {
00149       return scalarFunction.__put(os);
00150     }
00151   }


Member Data Documentation

template<typename MeshType, typename FiniteElementTraits>
ConstReferenceCounting<MeshType> FEMFunction< MeshType, FiniteElementTraits >::__mesh [private]

reference to the mesh through the Mesh (basis) class

Definition at line 46 of file FEMFunctionBase.hpp.

Referenced by FEMFunctionBase::baseMesh(), and FEMFunctionBase::hasSameType().

degree of freedom position set

Definition at line 50 of file FEMFunctionBase.hpp.

Referenced by FEMFunction< MeshType, FiniteElementTraits >::operator=(), and FEMFunctionBase::~FEMFunctionBase().

Vector<real_t> FEMFunctionBase::__values [protected, inherited]

type of discretization

Definition at line 55 of file FEMFunctionBase.hpp.

Referenced by FEMFunctionBase::__put(), FEMFunctionBase::discretizationType(), and FEMFunctionBase::hasSameType().

real_t FEMFunctionBase::__outsideValue [protected, inherited]

this value is returned when function is evaluated outside the mesh.

Note:
It is required to allow expression like $ f+a $ (where $ f $ is a fem-function and $ a $ a constant) to be simplifed (FEM functions are considered to be 0 outside the mesh by convention).

Definition at line 79 of file FEMFunctionBase.hpp.

Referenced by FEMFunction< MeshType, FiniteElementTraits >::operator()(), FEMFunction< MeshType, FiniteElementTraits >::operator=(), FEMFunctionBase::outsideValue(), and FEMFunctionBase::setOutsideValue().

const Type ScalarFunctionBase::__type [protected, inherited]

type of the function

Definition at line 90 of file ScalarFunctionBase.hpp.

Referenced by ScalarFunctionBase::type().

std::string ScalarFunctionBase::__name [protected, inherited]

name of the function

Definition at line 92 of file ScalarFunctionBase.hpp.

Referenced by ScalarFunctionBase::name(), and ScalarFunctionBase::setName().


The documentation for this class was generated from the following file:

Generated on Wed Nov 19 00:06:27 2008 for FreeFEM3D (aka ff3d) by  doxygen 1.5.6