LifeV
VenantKirchhoffMaterialLinear.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  * @file
29  * @brief This file contains the definition for the St. Venant Kirchhoff linear material
30  *
31  * @version 1.0
32  * @date 01-01-2010
33  * @author Paolo Tricerri
34  *
35  * @maintainer Paolo Tricerri <paolo.tricerri@epfl.ch>
36  */
37 
38 #ifndef _LINVENANTKIRCHHOFFMATERIAL_H_
39 #define _LINVENANTKIRCHHOFFMATERIAL_H_
40 
41 #include <lifev/structure/solver/isotropic/StructuralIsotropicConstitutiveLaw.hpp>
42 
43 
44 namespace LifeV
45 {
46 template <typename MeshType>
47 class VenantKirchhoffMaterialLinear :
48  public StructuralIsotropicConstitutiveLaw<MeshType>
49 {
50  //!@name Type definitions
51  //@{
52 
53 public:
54  typedef StructuralIsotropicConstitutiveLaw<MeshType> super;
55 
56  typedef typename super::data_Type data_Type;
57 
58  typedef typename super::vector_Type vector_Type;
59  typedef typename super::matrix_Type matrix_Type;
60 
61  typedef typename super::matrixPtr_Type matrixPtr_Type;
62  typedef typename super::dataPtr_Type dataPtr_Type;
63  typedef typename super::displayerPtr_Type displayerPtr_Type;
64  typedef typename super::vectorPtr_Type vectorPtr_Type;
65 
66  typedef typename super::mapMarkerVolumesPtr_Type mapMarkerVolumesPtr_Type;
67  typedef typename super::mapMarkerVolumes_Type mapMarkerVolumes_Type;
68  typedef typename mapMarkerVolumes_Type::const_iterator mapIterator_Type;
69 
70  typedef typename super::vectorVolumes_Type vectorVolumes_Type;
71  typedef std::shared_ptr<vectorVolumes_Type> vectorVolumesPtr_Type;
72 
73  typedef std::vector<UInt> vectorIndexes_Type;
74  typedef std::shared_ptr<vectorIndexes_Type> vectorIndexesPtr_Type;
75  typedef std::map< UInt, vectorIndexes_Type> mapMarkerIndexes_Type;
76  typedef std::shared_ptr<mapMarkerIndexes_Type> mapMarkerIndexesPtr_Type;
77  typedef typename mapMarkerIndexes_Type::const_iterator mapIteratorIndex_Type;
78 
79  typedef typename super::FESpacePtr_Type FESpacePtr_Type;
80  typedef typename super::ETFESpacePtr_Type ETFESpacePtr_Type;
81 
82  //Vector for vector parameters
83  typedef typename super::vectorsParameters_Type vectorsParameters_Type;
84  typedef typename super::vectorsParametersPtr_Type vectorsParametersPtr_Type;
85 
86  typedef MatrixSmall<3, 3> matrixSmall_Type;
87 
88  typedef typename super::tensorF_Type tensorF_Type;
89 
90  //@}
91 
92  //! @name Constructor & Destructor
93  //@{
94 
95  VenantKirchhoffMaterialLinear();
96 
97  virtual ~VenantKirchhoffMaterialLinear();
98 
99  //@}
100 
101  //!@name Methods
102  //@{
103 
104  //! Setup the created object of the class StructuralIsotropicConstitutiveLaw
105  /*!
106  \param dFespace: the FiniteElement Space
107  \param monolithicMap: the MapEpetra
108  \param offset: the offset parameter used assembling the matrices
109  */
110  void setup (const FESpacePtr_Type& dFESpace,
111  const ETFESpacePtr_Type& ETFESpace,
112  const std::shared_ptr<const MapEpetra>& monolithicMap,
113  const UInt offset,const dataPtr_Type& dataMaterial);
114 
115  //! Compute the Stiffness matrix in StructuralSolver::buildSystem()
116  /*!
117  \param dataMaterial the class with Material properties data
118  */
119  void computeLinearStiff ( dataPtr_Type& /*dataMaterial*/,
120  const mapMarkerVolumesPtr_Type /*mapsMarkerVolumes*/,
121  const mapMarkerIndexesPtr_Type /*mapsMarkerIndexes*/ );
122 
123  //! Updates the Jacobian matrix in StructualSolver::updateJacobian
124  /*!
125  \param disp: solution at the k-th iteration of NonLinearRichardson Method
126  \param dataMaterial: a pointer to the dataType member in StructuralSolver class to get
127  the material coefficients (e.g. Young modulus, Poisson ratio..)
128  \param displayer: a pointer to the Dysplaier member in the StructuralSolver class
129  */
130  void updateJacobianMatrix ( const vector_Type& disp,
131  const dataPtr_Type& dataMaterial,
132  const mapMarkerVolumesPtr_Type mapsMarkerVolumes,
133  const mapMarkerIndexesPtr_Type mapsMarkerIndexes,
134  const displayerPtr_Type& displayer);
135 
136  //! Updates the nonlinear terms in the Jacobian matrix in StructualSolver::updateJacobian
137  /*!
138  \param stiff: stiffness matrix provided from outside
139  \param disp: solution at the k-th iteration of NonLinearRichardson Method
140  \param dataMaterial: a pointer to the dataType member in StructuralSolver class to get
141  the material coefficients (e.g. Young modulus, Poisson ratio..)
142  \param displayer: a pointer to the Dysplaier member in the StructuralSolver class
143  */
144  void updateNonLinearJacobianTerms ( matrixPtr_Type& jacobian,
145  const vector_Type& /*disp*/,
146  const dataPtr_Type& /*dataMaterial*/,
147  const mapMarkerVolumesPtr_Type /*mapsMarkerVolumes*/,
148  const mapMarkerIndexesPtr_Type /*mapsMarkerIndexes*/,
149  const displayerPtr_Type& /*displayer*/);
150 
151  //! Interface method to compute the new Stiffness matrix in StructuralSolver::evalResidual and in
152  //! StructuralSolver::updateSystem since the matrix is the expression of the matrix is the same.
153  /*!
154  \param sol: the solution vector
155  \param factor: scaling factor used in FSI
156  \param dataMaterial: a pointer to the dataType member in StructuralSolver class to get the
157  material coefficients (e.g. Young modulus, Poisson ratio..)
158  \param displayer: a pointer to the Dysplaier member in the StructuralSolver class
159  */
160 
161  void computeStiffness ( const vector_Type& sol, Real factor, const dataPtr_Type& dataMaterial,
162  const mapMarkerVolumesPtr_Type mapsMarkerVolumes,
163  const mapMarkerIndexesPtr_Type mapsMarkerIndexes,
164  const displayerPtr_Type& displayer );
165 
166  void computeKinematicsVariables ( const VectorElemental& /*dk_loc*/ ) {}
167 
168  //! ShowMe method of the class (saved on a file the two matrices)
169  void showMe ( std::string const& fileNameStiff,
170  std::string const& fileNameJacobian);
171 
172  //! Compute the First Piola Kirchhoff Tensor
173  /*!
174  \param firstPiola Epetra_SerialDenseMatrix that has to be filled
175  \param tensorF Epetra_SerialDenseMatrix the deformation gradient
176  \param cofactorF Epetra_SerialDenseMatrix cofactor of F
177  \param invariants std::vector with the invariants of C and the detF
178  \param material UInt number to get the material parameteres form the VenantElasticData class
179  */
180  void computeLocalFirstPiolaKirchhoffTensor ( Epetra_SerialDenseMatrix& firstPiola,
181  const Epetra_SerialDenseMatrix& tensorF,
182  const Epetra_SerialDenseMatrix& cofactorF,
183  const std::vector<Real>& invariants,
184  const UInt marker);
185  //! Compute the First Piola Kirchhoff Tensor
186  /*!
187  \param disp the displacement field from which we compute the fisrt piola-Kirchhoff tensor
188  \param sigma_1 the first column of the Cauchy stress tensor
189  \param sigma_2 the second column of the Cauchy stress tensor
190  \param sigma_3 the third column of the Cauchy stress tensor
191  */
192  void computeCauchyStressTensor ( const vectorPtr_Type disp,
193  const QuadratureRule& evalQuad,
194  vectorPtr_Type sigma_1,
195  vectorPtr_Type sigma_2,
196  vectorPtr_Type sigma_3);
197 
198  //@}
199 
200  //! @name Get Methods
201  //@{
202 
203  //! Get the linear part of the matrix
204  matrixPtr_Type const linearStiff() const
205  {
206  return M_linearStiff;
207  }
208 
209  //! Get the Stiffness matrix
210  matrixPtr_Type const stiffMatrix() const
211  {
212  return M_stiff;
213  }
214 
215  //! Get the Stiffness vector
216  vectorPtr_Type const stiffVector() const
217  {
218  vectorPtr_Type zero ( new vector_Type() );
219  return zero;
220  }
221 
222  void apply ( const vector_Type& sol, vector_Type& res,
223  const mapMarkerVolumesPtr_Type /*mapsMarkerVolumes*/,
224  const mapMarkerIndexesPtr_Type /*mapsMarkerIndexes*/,
225  const displayerPtr_Type /*displayer*/)
226  {
227  res += *M_stiff * sol;
228  }
229 
230  //@}
231 
232 protected:
233 
234  //! construct the vectors for the parameters
235  /*!
236  \param VOID
237  \return VOID
238  */
239  void setupVectorsParameters ( void);
240 
241  //! Protected members
242 
243  //! Matrix Kl: stiffness linear
244  matrixPtr_Type M_linearStiff;
245 
246  //! Matrix Kl: stiffness linear
247  matrixPtr_Type M_stiff;
248 
249 };
250 
251 template <typename MeshType>
252 VenantKirchhoffMaterialLinear<MeshType>::VenantKirchhoffMaterialLinear() :
253  super ( ),
254  M_linearStiff ( ),
255  M_stiff ( )
256 {
257 }
258 
259 template <typename MeshType>
260 VenantKirchhoffMaterialLinear<MeshType>::~VenantKirchhoffMaterialLinear()
261 {}
262 
263 
264 template <typename MeshType>
265 void
266 VenantKirchhoffMaterialLinear<MeshType>::setup (const FESpacePtr_Type& dFESpace,
267  const ETFESpacePtr_Type& dETFESpace,
268  const std::shared_ptr<const MapEpetra>& monolithicMap,
269  const UInt offset,const dataPtr_Type& dataMaterial)
270 {
271  this->M_dataMaterial = dataMaterial;
272  this->M_dispFESpace = dFESpace;
273  this->M_dispETFESpace = dETFESpace;
274  this->M_localMap = monolithicMap;
275  this->M_linearStiff.reset (new matrix_Type (*this->M_localMap) );
276  this->M_offset = offset;
277 
278  // The 2 is because the law uses two parameters.
279  // another way would be to set up the number of constitutive parameters of the law
280  // in the data file to get the right size. Note the comment below.
281  this->M_vectorsParameters.reset ( new vectorsParameters_Type ( 2 ) );
282 
283  this->setupVectorsParameters( );
284 
285 }
286 
287 
288 template <typename MeshType>
289 void
290 VenantKirchhoffMaterialLinear<MeshType>::setupVectorsParameters ( void )
291 {
292  // Paolo Tricerri: February, 20th
293  // In each class, the name of the parameters has to inserted in the law
294  // TODO: move the saving of the material parameters to more abstract objects
295  // such that in the class of the material we do not need to call explicitly
296  // the name of the parameter.
297 
298  // Number of volume on the local part of the mesh
299  UInt nbElements = this->M_dispFESpace->mesh()->numVolumes();
300 
301  // Parameter lambda
302  // 1. resize the vector in the first element of the vector.
303  (* (this->M_vectorsParameters) ) [0].resize ( nbElements );
304 
305  // Parameter mu
306  (* (this->M_vectorsParameters) ) [1].resize ( nbElements );
307 
308  for (UInt i (0); i < nbElements; i++ )
309  {
310  // Extracting the marker
311  UInt markerID = this->M_dispFESpace->mesh()->element ( i ).markerID();
312 
313  Real lambda = this->M_dataMaterial->lambda ( markerID );
314  Real mu = this->M_dataMaterial->mu ( markerID );
315 
316  ( (* (this->M_vectorsParameters) ) [0]) [ i ] = lambda;
317  ( (* (this->M_vectorsParameters) ) [1]) [ i ] = mu;
318  }
319 }
320 
321 
322 template <typename MeshType>
323 void VenantKirchhoffMaterialLinear<MeshType>::computeLinearStiff (dataPtr_Type& /*dataMaterial*/,
324  const mapMarkerVolumesPtr_Type /*mapsMarkerVolumes*/,
325  const mapMarkerIndexesPtr_Type /*mapsMarkerIndexes*/)
326 {
327  using namespace ExpressionAssembly;
328 
329  * (this->M_linearStiff) *= 0.0;
330 
331  //Compute the linear part of the Stiffness Matrix.
332  //In the case of Linear Material it is the Stiffness Matrix.
333  //In the case of NonLinear Materials it must be added of the non linear part.
334 
335  integrate ( elements ( this->M_dispETFESpace->mesh() ),
336  this->M_dispFESpace->qr(),
337  this->M_dispETFESpace,
338  this->M_dispETFESpace,
339  parameter ( (* (this->M_vectorsParameters) ) [0]) * div ( phi_i ) * div ( phi_j )
340  ) >> M_linearStiff;
341 
342  integrate ( elements ( this->M_dispETFESpace->mesh() ),
343  this->M_dispFESpace->qr(),
344  this->M_dispETFESpace,
345  this->M_dispETFESpace,
346  value ( 2.0 ) * parameter ( (* (this->M_vectorsParameters) ) [1]) * dot ( sym (grad (phi_j) ) , grad (phi_i) )
347  ) >> M_linearStiff;
348 
349  this->M_linearStiff->globalAssemble();
350 
351  //Initialization of the pointer M_stiff to what is pointed by M_linearStiff
352  this->M_stiff = this->M_linearStiff;
353  this->M_jacobian = this->M_linearStiff;
354 }
355 
356 
357 template <typename MeshType>
358 void VenantKirchhoffMaterialLinear<MeshType>::updateJacobianMatrix (const vector_Type& disp,
359  const dataPtr_Type& dataMaterial,
360  const mapMarkerVolumesPtr_Type mapsMarkerVolumes,
361  const mapMarkerIndexesPtr_Type mapsMarkerIndexes,
362  const displayerPtr_Type& displayer)
363 {
364  //displayer->leaderPrint(" \n*********************************\n ");
365  displayer->leaderPrint (" S- Updating the Jacobian Matrix (constant, Linear Elastic)\n");
366  //displayer->leaderPrint(" \n*********************************\n ");
367 
368  //displayer->leaderPrint(" \n*********************************\n ");
369  updateNonLinearJacobianTerms (this->M_jacobian, disp, this->M_dataMaterial, mapsMarkerVolumes, mapsMarkerIndexes, displayer);
370  //displayer->leaderPrint(" \n*********************************\n ");
371 
372 }
373 
374 template <typename MeshType>
375 void VenantKirchhoffMaterialLinear<MeshType>::updateNonLinearJacobianTerms ( matrixPtr_Type& /*jacobian*/,
376  const vector_Type& /*disp*/,
377  const dataPtr_Type& /*dataMaterial*/,
378  const mapMarkerVolumesPtr_Type /*mapsMarkerVolumes*/,
379  const mapMarkerIndexesPtr_Type /*mapsMarkerIndexes*/,
380  const displayerPtr_Type& /*displayer*/ )
381 {
382  // this->M_stiff->globalAssemble();
383  // displayer->leaderPrint(" S- Doing nothing - Updating non linear terms in Jacobian Matrix (constant, Linear Elastic)\n");
384 }
385 
386 template <typename MeshType>
387 void VenantKirchhoffMaterialLinear<MeshType>::computeStiffness ( const vector_Type& /*disp*/,
388  Real /*factor*/,
389  const dataPtr_Type& /*dataMaterial*/,
390  const mapMarkerVolumesPtr_Type /*mapsMarkerVolumes*/,
391  const mapMarkerIndexesPtr_Type /*mapsMarkerIndexes*/,
392  const displayerPtr_Type& displayer )
393 
394 {
395  displayer->leaderPrint (" \n*********************************\n ");
396  displayer->leaderPrint (" S- Using the the Stiffness Matrix (constant, Linear Elastic)");
397  displayer->leaderPrint (" \n*********************************\n ");
398 }
399 
400 
401 template <typename MeshType>
402 void
403 VenantKirchhoffMaterialLinear<MeshType>::showMe ( std::string const& fileNameStiff,
404  std::string const& fileNameJacobian
405  )
406 {
407  //This string is to save the linear part
409  fileNamelinearStiff += "linear";
410 
412  this->M_stiff->spy (fileNameStiff);
414 }
415 
416 template <typename MeshType>
417 void
418 VenantKirchhoffMaterialLinear<MeshType>::computeLocalFirstPiolaKirchhoffTensor ( Epetra_SerialDenseMatrix& firstPiola,
419  const Epetra_SerialDenseMatrix& tensorF,
420  const Epetra_SerialDenseMatrix& cofactorF,
421  const std::vector<Real>& invariants,
422  const UInt marker)
423 {
424 
425  //Get the material parameters
426  Real lambda = this->M_dataMaterial->lambda (marker);
427  Real mu = this->M_dataMaterial->mu (marker);
428 
429  Epetra_SerialDenseMatrix copyF (tensorF);
430  Epetra_SerialDenseMatrix identity (nDimensions, nDimensions);
431 
432  copyF (0,0) += -1.0;
433  copyF (1,1) += -1.0;
434  copyF (2,2) += -1.0;
435 
436  identity (0,0) = 1.0;
437  identity (1,1) = 1.0;
438  identity (2,2) = 1.0;
439 
440  Real divergenceU ( copyF (0, 0) + copyF (1, 1) + copyF (2, 2) ); //DivU = tr(copyF)
441  Real coefIdentity (0.0);
442  coefIdentity = divergenceU * lambda;
443  identity.Scale ( coefIdentity );
444 
445  Epetra_SerialDenseMatrix transposed (copyF);
446  transposed.SetUseTranspose (true);
447 
448  Epetra_SerialDenseMatrix secondTerm (nDimensions, nDimensions);
449 
450  secondTerm = copyF;
451  secondTerm += transposed;
452  secondTerm.Scale (mu);
453 
454  firstPiola = identity;
455  firstPiola += secondTerm;
456 
457  // Here we multiply the Piola tensor for J and F^-T because in the WallTensionEstimator class
458  // the transformation from the Piola to the Cauchy stress tensor is always done while for this model
459  // the two tensors coincide
460  firstPiola.Scale( invariants[3] );
461 
462  Epetra_SerialDenseMatrix tensorP (nDimensions, nDimensions);
463 
464  tensorP.Multiply ('N', 'N', 1.0, firstPiola, cofactorF, 0.0); //see Epetra_SerialDenseMatrix
465 
466  firstPiola.Scale(0.0);
467  firstPiola += tensorP;
468 }
469 
470 template <typename MeshType>
471 void VenantKirchhoffMaterialLinear<MeshType>::computeCauchyStressTensor ( const vectorPtr_Type disp,
472  const QuadratureRule& evalQuad,
473  vectorPtr_Type sigma_1,
474  vectorPtr_Type sigma_2,
475  vectorPtr_Type sigma_3)
476 
477 {
478 
479  using namespace ExpressionAssembly;
480 
481  MatrixSmall<3, 3> identity;
482 
483  // Defining the div of u
484  identity (0, 0) = 1.0; identity (0, 1) = 0.0; identity (0, 2) = 0.0;
485  identity (1, 0) = 0.0; identity (1, 1) = 1.0; identity (1, 2) = 0.0;
486  identity (2, 0) = 0.0; identity (2, 1) = 0.0; identity (2, 2) = 1.0;
487 
488  ExpressionTrace<ExpressionInterpolateGradient<MeshType, MapEpetra, 3, 3> > Div( grad( this->M_dispETFESpace, *disp, this->M_offset ) );
489 
490  evaluateNode( elements ( this->M_dispETFESpace->mesh() ),
491  evalQuad,
492  this->M_dispETFESpace,
493  meas_K * dot ( vectorFromMatrix( parameter ( (* (this->M_vectorsParameters) ) [0]) * Div * identity +
494  parameter ( (* (this->M_vectorsParameters) ) [1]) *
495  ( grad ( this->M_dispETFESpace, *disp, this->M_offset ) +
496  transpose ( grad ( this->M_dispETFESpace, *disp, this->M_offset ) )
497  )
498  , 0 ), phi_i)
499  ) >> sigma_1;
500  sigma_1->globalAssemble();
501 
502 
503 
504  evaluateNode( elements ( this->M_dispETFESpace->mesh() ),
505  evalQuad,
506  this->M_dispETFESpace,
507  meas_K * dot ( vectorFromMatrix( parameter ( (* (this->M_vectorsParameters) ) [0]) * Div * identity +
508  parameter ( (* (this->M_vectorsParameters) ) [1]) *
509  ( grad ( this->M_dispETFESpace, *disp, this->M_offset ) +
510  transpose ( grad ( this->M_dispETFESpace, *disp, this->M_offset ) )
511  )
512  , 1 ), phi_i)
513  ) >> sigma_2;
514  sigma_2->globalAssemble();
515 
516  evaluateNode( elements ( this->M_dispETFESpace->mesh() ),
517  evalQuad,
518  this->M_dispETFESpace,
519  meas_K * dot ( vectorFromMatrix( parameter ( (* (this->M_vectorsParameters) ) [0]) * Div * identity +
520  parameter ( (* (this->M_vectorsParameters) ) [1]) *
521  ( grad ( this->M_dispETFESpace, *disp, this->M_offset ) +
522  transpose ( grad ( this->M_dispETFESpace, *disp, this->M_offset ) )
523  )
524  , 2 ), phi_i)
525  ) >> sigma_3;
526  sigma_3->globalAssemble();
527 
528 }
529 
530 
531 template <typename MeshType>
532 inline StructuralIsotropicConstitutiveLaw<MeshType>* createVenantKirchhoffLinear()
533 {
534  return new VenantKirchhoffMaterialLinear<MeshType >();
535 }
536 namespace
537 {
539 }
540 
541 } //Namespace LifeV
542 
543 #endif /* __LINVENANTKIRCHHOFF_H */
void assignFunction(bcBase_Type &base)
Assign the function to the base of the BCHandler.
class ExpressionInterpolateGradient Class representing an interpolation in an expression.
class ExpressionEmult Class for representing the transpose operation of an expression ...
ExpressionDivJ div(const ExpressionPhiJ &)
Simple function to be used in the construction of an expression.
const ExpressionPhiJ phi_j
Simple function to be used in the construction of an expression.
double Real
Generic real data.
Definition: LifeV.hpp:175
ExpressionDivI div(const ExpressionPhiI &)
Simple function to be used in the construction of an expression.
QuadratureRule - The basis class for storing and accessing quadrature rules.
const ExpressionPhiI phi_i
Simple function to be used in the construction of an expression.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191