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 
10 //=============================================================================
11 // Vector-valued Intefaces
12 //=============================================================================
13 
15 template <typename ConfiguratorType, typename Imp>
17 
18 protected:
23 
24 public:
25  UnitTriangleFENonlinOpIntegratorShellFE( const ConfiguratorType & Conf ) : _config( Conf){ }
26 
28 
29  void assembleAdd ( VectorType &Dest ) const {
30  RealType *nl_cache = new RealType[ _config.maxNumQuadPoints() ];
31 
32  for ( int elementIdx = 0; elementIdx < _config.getInitializer().getNumTriangs(); ++elementIdx){
33  const ElementType& El ( _config.getInitializer().getTriang( elementIdx ) );
34  const int numLocalDofs = _config.getNumLocalDofs ( El );
35 
36  const typename ConfiguratorType::BaseFuncSetType &bfs = _config.getBaseFunctionSet ( El );
37  const int numQuadPoints = bfs.numQuadPoints( );
38 
39  for ( int q = 0; q < numQuadPoints; ++q )
40  nl_cache[q] = this->asImp().getNonlinearity ( El, q );
41 
42  RealType aux;
43 
44  for ( int dof = 0; dof < numLocalDofs; ++dof ) {
45  aux = 0.;
46 
47  for ( int q = 0; q < numQuadPoints; ++q )
48  aux += nl_cache[q] * bfs.evaluate ( dof, q ) * bfs.getWeight ( q );
49 
50  Dest[ _config.localToGlobal ( El, dof ) ] += 0.5 * aux;
51  }
52  }
53  delete[] nl_cache;
54  }
55 
57  RealType getNonlinearity ( const typename ConfiguratorType::ElementType & El, int QuadPoint ) const {
58  throw std::invalid_argument( aol::strprintf ( "Called the interface function. In File %s at line %d.", __FILE__, __LINE__ ).c_str() );
59  return this->asImp().getNonlinearity ( El, QuadPoint );
60  }
61 
62 protected:
63  // barton-nackman
64  inline Imp& asImp() { return static_cast<Imp&> ( *this ); }
65  inline const Imp& asImp() const { return static_cast<const Imp&> ( *this ); }
66 
67 };
68 
69 //=============================================================================
70 // Matrix-valued Intefaces
71 //=============================================================================
72 
73 
75 template < typename ConfiguratorType, typename Imp >
77 public:
83 
84  explicit MatrixValuedIntegratorBase ( const ConfiguratorType &conf ) : _config ( conf ) {}
85 
86 protected:
87  void assembleTripletList ( std::vector<TripletType> & tripletList, const RealType Factor ) const {
88  tripletList.reserve(_config.getInitializer().getNumTriangs() * aol::Sqr( _config.getNumLocalDofs() ) );
89  LocalMatrixType localMatrix;
90  int globalDofs[ ConfiguratorType::maxNumLocalDofs ];
91  for ( int elementIdx = 0; elementIdx < _config.getInitializer().getNumTriangs(); ++elementIdx){
92  const ElementType& El ( _config.getInitializer().getTriang( elementIdx ) );
93  this->asImp().prepareLocalMatrix ( El, localMatrix );
94  const int numLocalDofs = _config.getNumLocalDofs ( El );
95 
96  // Part of exercise 1
97  }
98  }
99 
100 public:
101 
102  template <typename SparseMatrixType>
103  void assemble ( SparseMatrixType &Dest, const RealType Factor = 1.0 ) const {
104  std::vector<TripletType> tripletList;
105  assembleTripletList ( tripletList, Factor );
106  Dest.setFromTriplets( tripletList.cbegin(), tripletList.cend() );
107  }
108 
109  template <typename SparseMatrixType>
110  void assembleDirichlet ( SparseMatrixType &Dest, const MaskType& boundaryMask, const RealType Factor = 1.0 ) const {
111 
112  std::vector<TripletType> tripletList;
113  assembleTripletList ( tripletList, Factor );
114 
115  std::vector<TripletType> tripletListMasked;
116  tripletListMasked.reserve(_config.getInitializer().getNumTriangs() * aol::Sqr( _config.getNumLocalDofs() ) );
117 
118  for( unsigned iter=0; iter < tripletList.size(); ++iter ){
119  if( (boundaryMask[tripletList[iter].row()]) || (boundaryMask[tripletList[iter].col()]) ){
120  //Boundary node!
121  } else {
122  tripletListMasked.push_back( tripletList[iter] );
123  }
124  }
125 
126  for ( int i = 0; i < _config.getNumGlobalDofs(); ++i ){
127  if ( boundaryMask[i] )
128  tripletListMasked.push_back( TripletType( i, i, 1.0 ) );
129  }
130 
131  Dest.setFromTriplets( tripletListMasked.begin(), tripletListMasked.end() );
132  }
133 
134 protected:
135  // barton-nackman
136  inline Imp& asImp() { return static_cast<Imp&> ( *this ); }
137  inline const Imp& asImp() const { return static_cast<const Imp&> ( *this ); }
138 
140 };
141 
142 
143 
144 
149 template <typename ConfiguratorType, typename Imp >
151  public MatrixValuedIntegratorBase< ConfiguratorType, UnitTriangleFELinWeightedStiffIntegrator<ConfiguratorType, Imp> > {
152 protected:
158 
159 public:
162  _config ( Config ) {}
163 
164 
166  inline void getCoeffMatrix ( const typename ConfiguratorType::ElementType &El, int QuadPoint,
167  Matrix22 &Matrix ) const {
168  this->asImp().getCoeffMatrix ( El, QuadPoint, Matrix );
169  }
170 
172  inline void prepareLocalMatrix ( const typename ConfiguratorType::ElementType &El,
173  LocalMatrixType &LocalMatrix ) const {
174  const int numDofs = _config.getNumLocalDofs ( El );
175 
176  for ( int i = 0; i < numDofs; ++i )
177  for ( int j = 0; j < numDofs; ++j )
178  LocalMatrix(i,j) = 0.;
179 
180  Matrix22 mat;
181  DomVecType matgrad1;
182 
183  const typename ConfiguratorType::BaseFuncSetType &bfs = _config.getBaseFunctionSet ( El );
184  const int numQuadPoints = bfs.numQuadPoints( );
185 
186  // Part of exercise 1
187  }
188 
189 protected:
190  inline Imp &asImp() { return static_cast<Imp&> ( *this ); }
191  inline const Imp &asImp() const { return static_cast<const Imp&> ( *this ); }
192 
193 };
194 
195 } // end namespace
196 
197 #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 assembleDirichlet(SparseMatrixType &Dest, const MaskType &boundaryMask, const RealType Factor=1.0) 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.
T Sqr(const T a)
Definition: aol.h:134
int getNumTriangs() const
Definition: triangMesh.h:46
DataTypeContainer::Matrix22 Matrix22
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.
void assemble(SparseMatrixType &Dest, const RealType Factor=1.0) const
General interface for matrix valued integrators.
MatrixValuedIntegratorBase(const ConfiguratorType &conf)
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.
int getNumGlobalDofs() const
Returns the number of global degrees of freedom.
ConfiguratorType::LocalMatrixType LocalMatrixType
ConfiguratorType::SparseMatrixType SparseMatrixType
Definition: ex2.cpp:27
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.
Triangle which has a tangent space at each node.
const BaseFuncSetType & getBaseFunctionSet(const ElementType &) const
Returns the base funcitons set for an element.
DataTypeContainer::TripletType TripletType