Programming tasks to Scientific Computing I
discreteFunctionShellFE.h
Go to the documentation of this file.
1 #ifndef __DISCRETEFUNCTIONSHELLFE_H
2 #define __DISCRETEFUNCTIONSHELLFE_H
3 
4 #include <EigenDataContainer.h>
5 #include <initializer_list>
6 
7 namespace shellFE {
8 
9 template <typename ConfiguratorType, typename VectorType, typename NLTYPE >
11 
12  void getLocalDof ( const ConfiguratorType & conf, const VectorType &dofs, const typename ConfiguratorType::ElementType &El,
13  const int bfNum, const NLTYPE &bfValue, NLTYPE &aux ) {
14  aux = bfValue;
15  aux *= dofs[ conf.localToGlobal ( El, bfNum ) ];
16  }
17 
18 };
19 
21 template <typename ConfiguratorType, typename VectorType = typename ConfiguratorType::VectorType >
23 public:
30 
32  const VectorType & _dofs;
33 
35  : _conf ( config ),
36  _dofs ( Dofs ) { }
37 
38  RealType evaluate ( const ElementType &El, const DomVecType& RefCoord ) const {
39  const BaseFuncSetType &bfs = _conf.getBaseFunctionSet ( El );
40  RealType w = 0.;
41  RealType v, aux;
42  for ( int b = 0; b < static_cast<int> ( _conf.getNumLocalDofs ( El ) ); ++b ) {
43  v = bfs.evaluate ( b, RefCoord );
45  w += aux;
46  }
47  return w;
48  }
49 
50  RealType evaluateAtQuadPoint ( const ElementType &El, int QuadPoint ) const {
51  const BaseFuncSetType &bfs = _conf.getBaseFunctionSet ( El );
52  RealType w = 0.;
53  RealType v, aux;
54  for ( int b = 0; b < static_cast<int> ( _conf.getNumLocalDofs ( El ) ); ++b ) {
55  v = bfs.evaluate ( b, QuadPoint );
57  w += aux;
58  }
59  return w;
60  }
61 
62  void evaluateGradient ( const ElementType &El, const DomVecType& RefCoord, DomVecType& Grad ) const {
63  const BaseFuncSetType &bfs = _conf.getBaseFunctionSet ( El );
64  DomVecType v, aux;
65  Grad.setZero();
66  for ( int b = 0; b < static_cast<int> ( _conf.getNumLocalDofs ( El ) ); ++b ) {
67  bfs.evaluateGradient ( b, RefCoord, v );
69  Grad += aux;
70  }
71  }
72 
73  void evaluateGradientAtQuadPoint ( const ElementType &El, int QuadPoint, DomVecType& Grad ) const {
74  const BaseFuncSetType &bfs = _conf.getBaseFunctionSet ( El );
75  DomVecType v, aux;
76  Grad.setZero();
77  for ( int b = 0; b < static_cast<int> ( _conf.getNumLocalDofs ( El ) ); ++b ) {
78  v = bfs.evaluateGradient ( b, QuadPoint );
80  Grad += aux;
81  }
82  }
83 
84  const VectorType& getDofs ( ) const {return _dofs;}
85 
86 };
87 
89 template <typename ConfiguratorType>
91 public:
99 
102 
103  const int _numComponents;
104  mutable std::vector<Eigen::Ref<const VectorType> > _refs;
105  mutable std::vector<DiscFuncType> _discrFuncs;
106 
107 public:
108 
109  DiscreteVectorFunctionDefaultShellFE ( const ConfiguratorType &Configurator, const VectorType &Dofs, const int numComponents ) :
110  _numComponents ( numComponents )
111  {
112  const int numGlobalDofs = Configurator.getNumGlobalDofs();
113  _refs.reserve( _numComponents );
114  _discrFuncs.reserve( _numComponents );
115 
116  _refs.push_back ( Dofs.segment( 0, numGlobalDofs) );
117  _refs.push_back ( Dofs.segment( numGlobalDofs, numGlobalDofs) );
118  _refs.push_back ( Dofs.segment( 2 * numGlobalDofs, numGlobalDofs) );
119 
120  _discrFuncs.push_back ( DiscFuncType ( Configurator, _refs[0] ) );
121  _discrFuncs.push_back ( DiscFuncType ( Configurator, _refs[1] ) );
122  _discrFuncs.push_back ( DiscFuncType ( Configurator, _refs[2] ) );
123  }
124 
125  void evaluate( const ElementType &El, const DomVecType& RefCoord, TangentVecType &Value ) const {
126  for ( int c = 0; c < 3; ++c )
127  Value[c] = _discrFuncs[c].evaluate ( El, RefCoord );
128  }
129 
130  void evaluateAtQuadPoint ( const ElementType &El, int QuadPoint, TangentVecType &Value ) const {
131  for ( int c = 0; c < 3; ++c )
132  Value[c] = _discrFuncs[c].evaluateAtQuadPoint ( El, QuadPoint );
133  }
134 
135  void evaluateGradient ( const ElementType &El, const DomVecType& RefCoord, Matrix32 &Dx ) const {
136  DomVecType v;
137  for ( int c = 0; c < 3; c++ ) {
138  _discrFuncs[c].evaluateGradient ( El, RefCoord, v );
139  Dx( c, 0 ) = v[0];
140  Dx( c, 1 ) = v[1];
141  }
142  }
143 
144  void evaluateGradientAtQuadPoint ( const ElementType &El, int QuadPoint, Matrix32 &Dx ) const {
145  DomVecType v;
146  for ( int c = 0; c < 3; ++c ) {
147  _discrFuncs[c].evaluateGradientAtQuadPoint ( El, QuadPoint, v );
148  Dx( c, 0 ) = v[0];
149  Dx( c, 1 ) = v[1];
150  }
151  }
152 
153  void evaluateFirstFundamentalForm ( const ElementType &El, const DomVecType& RefCoord, Matrix22 &g ) const {
154  Matrix32 Dx;
155  evaluateGradient( El, RefCoord, Dx );
156  g = Dx.transpose() * Dx;
157  }
158 
159 
160  void evaluateFirstFundamentalFormAtQuadPoint ( const ElementType &El, int QuadPoint, Matrix22 &g ) const {
161  Matrix32 Dx;
162  evaluateGradientAtQuadPoint( El, QuadPoint, Dx );
163  g = Dx.transpose() * Dx;
164  }
165 
166  void evaluateFirstFundamentalForm ( const Matrix32 &Dx, Matrix22 &g ) const {
167  g = Dx.transpose() * Dx;
168  }
169 
170  // given chart X -> compute n \circ X = d_1 X \cross d_2 X / |.|
171  void evaluateNormalAtQuadPointOnShell ( const ElementType &El, int QuadPoint, TangentVecType &normal ) const {
172  Matrix32 Dx;
173  evaluateGradientAtQuadPoint ( El, QuadPoint, Dx );
174  TangentVecType unNormalizedNormal ( (Dx.col(0)).cross(Dx.col(1)) );
175  normal = unNormalizedNormal.normalized();
176  }
177 
178  void evaluateNormal ( const Matrix32 &Dx, TangentVecType &normal ) const {
179  TangentVecType unNormalizedNormal ( (Dx.col(0)).cross(Dx.col(1)) );
180  normal = unNormalizedNormal.normalized();
181  }
182 
183 
184  const DiscFuncType& operator[] ( int i ) const { return _discrFuncs[i];}
185  DiscFuncType& operator[] ( int i ) { return _discrFuncs[i];}
186 
187 };
188 
189 } // end namespace
190 
191 #endif
Helper class to evaluate a discrete nodal function on a given mesh.
DataTypeContainer::VectorType VectorType
void evaluateAtQuadPoint(const ElementType &El, int QuadPoint, TangentVecType &Value) const
ConfiguratorType::TangentVecType TangentVecType
RealType evaluate(int BaseFuncNum, const DomVecType &RefCoord) const
Evaluates a base function at.
DiscreteFunctionDefaultShellFE(const ConfiguratorType &config, const VectorType &Dofs)
void evaluate(const ElementType &El, const DomVecType &RefCoord, TangentVecType &Value) const
DiscreteVectorFunctionDefaultShellFE(const ConfiguratorType &Configurator, const VectorType &Dofs, const int numComponents)
DataTypeContainer::Matrix32 Matrix32
DataTypeContainer::DomVecType DomVecType
DataTypeContainer::RealType RealType
RealType evaluateAtQuadPoint(const ElementType &El, int QuadPoint) const
void evaluateGradient(int BaseFuncNum, const DomVecType &, DomVecType &Gradient) const
Evaluates the gradient of a base function at RefCoord.
DataTypeContainer::Matrix22 Matrix22
void evaluateGradient(const ElementType &El, const DomVecType &RefCoord, DomVecType &Grad) const
void evaluateGradientAtQuadPoint(const ElementType &El, int QuadPoint, DomVecType &Grad) const
RealType evaluate(const ElementType &El, const DomVecType &RefCoord) const
int getNumLocalDofs(const ElementType &) const
Get The number of local degrees of freedom on an element.
void evaluateGradientAtQuadPoint(const ElementType &El, int QuadPoint, Matrix32 &Dx) const
Helper class to evaluate a discrete vector-valued nodal function on a given mesh. ...
void evaluateFirstFundamentalForm(const ElementType &El, const DomVecType &RefCoord, Matrix22 &g) const
DataTypeContainer::TangentVecType TangentVecType
void evaluateNormal(const Matrix32 &Dx, TangentVecType &normal) const
void evaluateFirstFundamentalFormAtQuadPoint(const ElementType &El, int QuadPoint, Matrix22 &g) const
int localToGlobal(const ElementType &T, int localIndex) const
Returns global index of the dof with number localIndex.
ConfiguratorType::BaseFuncSetType BaseFuncSetType
int getNumGlobalDofs() const
Returns the number of global degrees of freedom.
ConfiguratorType::VectorType VectorType
Definition: ex2.cpp:26
void evaluateNormalAtQuadPointOnShell(const ElementType &El, int QuadPoint, TangentVecType &normal) const
std::vector< Eigen::Ref< const VectorType > > _refs
void evaluateFirstFundamentalForm(const Matrix32 &Dx, Matrix22 &g) const
void evaluateGradient(const ElementType &El, const DomVecType &RefCoord, Matrix32 &Dx) const
DataTypeContainer::Matrix33 Matrix33
Eigen typedefs for use with the TriangleMesh.
DiscreteFunctionDefaultShellFE< ConfiguratorType, Eigen::Ref< const VectorType > > DiscFuncType
Configurator for Finite Elements.
void getLocalDof(const ConfiguratorType &conf, const VectorType &dofs, const typename ConfiguratorType::ElementType &El, const int bfNum, const NLTYPE &bfValue, NLTYPE &aux)
Triangle which has a tangent space at each node.
const BaseFuncSetType & getBaseFunctionSet(const ElementType &) const
Returns the base funcitons set for an element.