Programming tasks to Scientific Computing I
unityTriangleIntegratorShellFE.h
Go to the documentation of this file.
1 
5 #ifndef __UNITTRIANGLEINTEGRATORSHELLFE_H
6 #define __UNITTRIANGLEINTEGRATORSHELLFE_H
7 
8 namespace shellFE {
9 
11 template <typename ConfiguratorType, typename Imp>
13 public:
16 protected:
18 public:
19 
21 
23 
24  void assembleAdd ( RealType &Dest ) const {
25 
26  RealType res = 0.;
27 
28  for ( int elementIdx = 0; elementIdx < _config.getInitializer().getNumTriangs(); ++elementIdx){
29  const ElementType& El ( _config.getInitializer().getTriang( elementIdx ) );
30  const typename ConfiguratorType::BaseFuncSetType &bfs = _config.getBaseFunctionSet ( El );
31  const int numQuadPoints = bfs.numQuadPoints( );
32 
33  RealType a = 0.;
34  for ( int q = 0; q < numQuadPoints; ++q ) {
35  a += this->asImp().evaluateIntegrand ( El, q ) * bfs.getWeight ( q );
36  }
37  res += a;
38  }
39  Dest += 0.5 * res;
40  }
41 
43  RealType evaluateIntegrand ( const typename ConfiguratorType::ElementType &El, int QuadPoint ) const {
44  throw std::invalid_argument( aol::strprintf ( "Called the interface function. In File %s at line %d.", __FILE__, __LINE__ ).c_str() );
45  return this->asImp().evaluateIntegrand ( El, QuadPoint );
46  }
47 
48 protected:
49  // barton-nackman
50  inline Imp& asImp() { return static_cast<Imp&> ( *this ); }
51  inline const Imp& asImp() const { return static_cast<const Imp&> ( *this ); }
52 
53 };
54 
55 //=============================================================================
56 // Vector-valued Intefaces
57 //=============================================================================
58 
60 template <typename ConfiguratorType, typename Imp>
62 
63 protected:
68 
69 public:
70  UnitTriangleFENonlinOpIntegratorShellFE( const ConfiguratorType & Conf ) : _config( Conf){ }
71 
73 
74  void assembleAdd ( VectorType &Dest ) const {
75  RealType *nl_cache = new RealType[ _config.maxNumQuadPoints() ];
76 
77  for ( int elementIdx = 0; elementIdx < _config.getInitializer().getNumTriangs(); ++elementIdx){
78  const ElementType& El ( _config.getInitializer().getTriang( elementIdx ) );
79  const int numLocalDofs = _config.getNumLocalDofs ( El );
80 
81  const typename ConfiguratorType::BaseFuncSetType &bfs = _config.getBaseFunctionSet ( El );
82  const int numQuadPoints = bfs.numQuadPoints( );
83 
84  for ( int q = 0; q < numQuadPoints; ++q )
85  nl_cache[q] = this->asImp().getNonlinearity ( El, q );
86 
87  RealType aux;
88 
89  for ( int dof = 0; dof < numLocalDofs; ++dof ) {
90  aux = 0.;
91 
92  for ( int q = 0; q < numQuadPoints; ++q )
93  aux += nl_cache[q] * bfs.evaluate ( dof, q ) * bfs.getWeight ( q );
94 
95  Dest[ _config.localToGlobal ( El, dof ) ] += 0.5 * aux;
96  }
97  }
98  delete[] nl_cache;
99  }
100 
102  RealType getNonlinearity ( const typename ConfiguratorType::ElementType & El, int QuadPoint ) const {
103  throw std::invalid_argument( aol::strprintf ( "Called the interface function. In File %s at line %d.", __FILE__, __LINE__ ).c_str() );
104  return this->asImp().getNonlinearity ( El, QuadPoint );
105  }
106 
107 protected:
108  // barton-nackman
109  inline Imp& asImp() { return static_cast<Imp&> ( *this ); }
110  inline const Imp& asImp() const { return static_cast<const Imp&> ( *this ); }
111 
112 };
113 
114 //=============================================================================
115 // Matrix-valued Intefaces
116 //=============================================================================
117 
118 
120 template < typename ConfiguratorType, typename Imp >
122 public:
128 
129  explicit MatrixValuedIntegratorBase(const ConfiguratorType &conf, const RealType factor = 1.0)
130  : _config ( conf ), _factor(factor), _tripletListAssembled(false)
131  {}
132 
133 protected:
134  void assembleTripletList ( std::vector<TripletType> & tripletList, const RealType Factor ) const {
135  tripletList.reserve(_config.getInitializer().getNumTriangs() * aol::Sqr( _config.getNumLocalDofs() ) );
136  LocalMatrixType localMatrix;
137  int globalDofs[ ConfiguratorType::maxNumLocalDofs ];
138  for ( int elementIdx = 0; elementIdx < _config.getInitializer().getNumTriangs(); ++elementIdx){
139  const ElementType& El ( _config.getInitializer().getTriang( elementIdx ) );
140  this->asImp().prepareLocalMatrix ( El, localMatrix );
141  const int numLocalDofs = _config.getNumLocalDofs ( El );
142 
143  for ( int i = 0; i < numLocalDofs; ++i )
144  globalDofs[ i ] = _config.localToGlobal ( El, i );
145 
146  for ( int i = 0; i < numLocalDofs; ++i ) {
147  int glob_i = globalDofs[ i ];
148  for ( int j = 0; j < numLocalDofs; ++j ) {
149  int glob_j = globalDofs[ j ];
150  tripletList.push_back( TripletType( glob_i, glob_j, Factor * localMatrix(i,j) ) );
151  }
152  }
153  }
154  }
155 
156 public:
158  if(!_tripletListAssembled) {
159  assembleTripletList(_tripletList, _factor);
160  _tripletListAssembled = true;
161  }
162  }
163 
164  template <typename SparseMatrixType>
165  void assemble ( SparseMatrixType &Dest ) const {
166  assembleTripletListCached();
167  Dest.setFromTriplets( _tripletList.cbegin(), _tripletList.cend() );
168  }
169 
170  template <typename SparseMatrixType>
171  void assembleDirichlet ( SparseMatrixType &Dest, const MaskType& boundaryMask ) const {
172  assembleTripletListCached();
173 
174  std::vector<TripletType> tripletListMasked;
175  tripletListMasked.reserve(_config.getInitializer().getNumTriangs() * aol::Sqr( _config.getNumLocalDofs() ) );
176 
177  for( unsigned iter=0; iter < _tripletList.size(); ++iter ){
178  if( (boundaryMask[_tripletList[iter].row()]) || (boundaryMask[_tripletList[iter].col()]) ){
179  //Boundary node!
180  } else {
181  tripletListMasked.push_back( _tripletList[iter] );
182  }
183  }
184 
185  for ( int i = 0; i < _config.getNumGlobalDofs(); ++i ){
186  if ( boundaryMask[i] )
187  tripletListMasked.push_back( TripletType( i, i, 1.0 ) );
188  }
189 
190  Dest.setFromTriplets( tripletListMasked.begin(), tripletListMasked.end() );
191  }
192 
193 protected:
194  // barton-nackman
195  inline Imp& asImp() { return static_cast<Imp&> ( *this ); }
196  inline const Imp& asImp() const { return static_cast<const Imp&> ( *this ); }
197 
199  mutable std::vector<TripletType> _tripletList;
200  RealType _factor;
201  mutable bool _tripletListAssembled;
202 };
203 
204 
205 
206 
211 template <typename ConfiguratorType, typename Imp >
213  public MatrixValuedIntegratorBase< ConfiguratorType, UnitTriangleFELinWeightedStiffIntegrator<ConfiguratorType, Imp> > {
214 protected:
220 
221 public:
224  _config ( Config ) {}
225 
226 
228  inline void getCoeffMatrix ( const typename ConfiguratorType::ElementType &El, int QuadPoint,
229  Matrix22 &Matrix ) const {
230  this->asImp().getCoeffMatrix ( El, QuadPoint, Matrix );
231  }
232 
234  inline void prepareLocalMatrix ( const typename ConfiguratorType::ElementType &El,
235  LocalMatrixType &LocalMatrix ) const {
236 
237 
238  const int numDofs = _config.getNumLocalDofs ( El );
239 
240  for ( int i = 0; i < numDofs; ++i )
241  for ( int j = 0; j < numDofs; ++j )
242  LocalMatrix(i,j) = 0.;
243 
244  Matrix22 mat;
245  DomVecType matgrad1;
246 
247  const typename ConfiguratorType::BaseFuncSetType &bfs = _config.getBaseFunctionSet ( El );
248  const int numQuadPoints = bfs.numQuadPoints( );
249 
250  for ( int q = 0; q < numQuadPoints; ++q ) {
251  getCoeffMatrix ( El, q, mat );
252  for ( int i = 0; i < numDofs; ++i ) {
253  DomVecType grad_i = bfs.evaluateGradient( i, q );
254  matgrad1 = mat * grad_i;
255  for ( int j = 0; j < numDofs; ++j ) {
256  DomVecType grad_j = bfs.evaluateGradient( j, q );
257  LocalMatrix(j,i) += matgrad1.dot( grad_j ) * bfs.getWeight ( q );
258  }
259  }
260  }
261  for ( int i = 0; i < numDofs; ++i )
262  for ( int j = 0; j < numDofs; ++j )
263  LocalMatrix(i,j) *= 0.5; // 0.5 is the volume of the unit triangle
264  }
265 
266 protected:
267  inline Imp &asImp() { return static_cast<Imp&> ( *this ); }
268  inline const Imp &asImp() const { return static_cast<const Imp&> ( *this ); }
269 
270 };
271 
272 } // end namespace
273 
274 #endif
DataTypeContainer::MaskType MaskType
Provides an easy interface to Finite Element operators of the form , where is an ASYMMETRIC coeffici...
DataTypeContainer::VectorType VectorType
void prepareLocalMatrix(const typename ConfiguratorType::ElementType &El, LocalMatrixType &LocalMatrix) const
Computes the numerical quadrature of the bilinear form and saves the values locally.
const TriangleType & getTriang(const int num) const
Definition: triangMesh.h:87
void assemble(SparseMatrixType &Dest) const
Integrator for , of some scalar valued function .
RealType evaluate(int BaseFuncNum, const DomVecType &RefCoord) const
Evaluates a base function at.
int numQuadPoints() const
Returns the number of quadrature points.
Eigen::Matrix< RealType, maxNumLocalDofs, maxNumLocalDofs > LocalMatrixType
int maxNumQuadPoints() const
Returns the maximum number of quadrature points per element.
DataTypeContainer::DomVecType DomVecType
DataTypeContainer::RealType RealType
RealType getWeight(int QuadPoint) const
Returns the quadrature weight at QuadPointa quadrature point.
void evaluateGradient(int BaseFuncNum, const DomVecType &, DomVecType &Gradient) const
Evaluates the gradient of a base function at RefCoord.
T Sqr(const T a)
Definition: aol.h:134
int getNumTriangs() const
Definition: triangMesh.h:46
DataTypeContainer::Matrix22 Matrix22
void assembleDirichlet(SparseMatrixType &Dest, const MaskType &boundaryMask) const
void assembleTripletList(std::vector< TripletType > &tripletList, const RealType Factor) const
RealType getNonlinearity(const typename ConfiguratorType::ElementType &El, int QuadPoint) const
interface function, has to be provided in derived classes.
int getNumLocalDofs(const ElementType &) const
Get The number of local degrees of freedom on an element.
General interface for matrix valued integrators.
string strprintf(const char *format,...)
Give back formatted string, analogously to sprintf, but save the long way &#39;round with char arrays...
Definition: aol.cpp:5
int localToGlobal(const ElementType &T, int localIndex) const
Returns global index of the dof with number localIndex.
const InitType & getInitializer() const
Returns the mesh.
Definition: rhs.h:14
ConfiguratorType::SparseMatrixType SparseMatrixType
Definition: ex1.cpp:28
int getNumGlobalDofs() const
Returns the number of global degrees of freedom.
ConfiguratorType::LocalMatrixType LocalMatrixType
void getCoeffMatrix(const typename ConfiguratorType::ElementType &El, int QuadPoint, Matrix22 &Matrix) const
This function has to be provided in the implementation (derived class) of the interface.
Configurator for Finite Elements.
Integrator to compute , where is the argument of the operator.
Triangle which has a tangent space at each node.
RealType evaluateIntegrand(const typename ConfiguratorType::ElementType &El, int QuadPoint) const
interface function, has to be provided in derived classes.
const BaseFuncSetType & getBaseFunctionSet(const ElementType &) const
Returns the base funcitons set for an element.
DataTypeContainer::TripletType TripletType
MatrixValuedIntegratorBase(const ConfiguratorType &conf, const RealType factor=1.0)