LifeV
VenantKirchhoffViscoelasticSolver.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 ************************************************************************
4 
5  This file is part of the LifeV Applications.
6  Copyright (C) 2001-2010 EPFL, Politecnico di Milano
7 
8  This library is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as
10  published by the Free Software Foundation; either version 2.1 of the
11  License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  USA
22 
23 ************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  * @file
29  * @brief VenantKirchhoffViscoelasticSolver - Class to solve second order problem as linear visco-elastic
30  * problem and waves problem.
31  *
32  * @author Matteo Pozzoli <matteo1.pozzoli@mail.polimi.it>
33  *
34  * @contributor Matteo Pozzoli <matteo1.pozzoli@mail.polimi.it>
35  *
36  * @maintainer Matteo Pozzoli <matteo1.pozzoli@mail.polimi.it>
37  */
38 
39 
40 #ifndef VENANTKIRCHHOFFVISCOELASTICSOLVER_H_
41 #define VENANTKIRCHHOFFVISCOELASTICSOLVER_H_ 1
42 
43 
44 #include <Epetra_Vector.h>
45 #include <EpetraExt_MatrixMatrix.h>
46 
47 #include<boost/scoped_ptr.hpp>
48 
49 
50 #include <lifev/core/array/MatrixElemental.hpp>
51 #include <lifev/core/array/VectorElemental.hpp>
52 #include <lifev/core/array/MatrixEpetra.hpp>
53 #include <lifev/core/array/VectorEpetra.hpp>
54 
55 #include <lifev/core/fem/AssemblyElemental.hpp>
56 #include <lifev/core/fem/Assembly.hpp>
57 #include <lifev/core/fem/BCManage.hpp>
58 #include <lifev/core/fem/FESpace.hpp>
59 
60 #include <lifev/core/util/LifeChrono.hpp>
61 
62 #include <lifev/core/algorithm/SolverAztecOO.hpp>
63 
64 #include <lifev/structure/solver/VenantKirchhoffViscoelasticData.hpp>
65 #include <lifev/core/util/Displayer.hpp>
66 
67 
68 namespace LifeV
69 {
70 //! SecondOrderProblem this class solver second order problem, waves equation and linear viscoelastic problem
71 /*!
72  \class VenantKirchhoffViscoelasticSolver
73  \brief
74  This class solves the following waves equation:
75 
76  \f[M \frac{d^2 u}{d t^2} + D(u,\frac{d u}{d t} ) \frac{d u}{d t} + A(u, \frac{d u}{dt}) = f\f]
77 
78 where \f$M\f$ is mass matrix, \f$A\f$ stiffness matrix and \f$D\f$ is damping matrix given by \f$ \beta M + \gamma A\f$.
79 
80  If \f$A\f$ and \f$D\f$ depend on \f$u\f$ and \f$dot{u}\f$ we linearize the problem using suitable extrapolations.
81  we use the time advancing scheme defined in TimeAdvanceBase class for details see TimeAdvanceBase.pdf notes.
82 */
83 
84 template < typename Mesh,
85  typename SolverType = LifeV::SolverAztecOO >
86 
88 {
89 public:
90 
91  //! @name Public Types
92  //@{
93 
94  typedef Real ( *Function ) ( const Real&, const Real&, const Real&, const Real&, const ID& );
95  typedef std::function<Real ( Real const&, Real const&, Real const&, Real const&, ID const& ) > source_type;
96 
97  typedef BCHandler bchandler_raw_type;
99 
100  typedef SolverType solver_type;
101 
106 
107  typedef typename SolverType::prec_raw_type prec_raw_type;
108  typedef typename SolverType::prec_type prec_type;
109 
110  typedef VenantKirchhoffViscoelasticData data_type;
111 
112  //@}
113 
114  //! @name Constructors & Destructor
115  //@{
116 
117  //! Constructor
119 
120  //! virtual Destructor
122 
123  //@}
124 
125  //! @name Methods
126  //@{
127 
128  //! class setup
129  /*!
130  @param data file
131  @param feSpace finite element space
132  @param comm communicator
133  */
134  void setup ( std::shared_ptr<data_type> data,
135  const std::shared_ptr< FESpace<Mesh, MapEpetra> >& feSpace,
136  std::shared_ptr<Epetra_Comm>& comm
137  );
138 
139  //! class setup
140  /*!
141  @param data file
142  @param feSpace finite element space
143  @param BCh boundary condition
144  @param comm communicator
145  */
146  void setup ( std::shared_ptr<data_type> data,
147  const std::shared_ptr< FESpace<Mesh, MapEpetra> >& feSpace,
148  bchandler_type& BCh,
149  std::shared_ptr<Epetra_Comm>& comm
150  );
151 
152 
153  //! class setup
154  /*!
155  @param data file
156  @param feSpace finite element space
157  @param comm communicator
158  @param epetraMap epetra vector
159  @param offset
160  */
161  virtual void setup ( std::shared_ptr<data_type> data,
162  const std::shared_ptr< FESpace<Mesh, MapEpetra> >& feSpace,
163  std::shared_ptr<Epetra_Comm>& comm,
164  const std::shared_ptr<const MapEpetra>& epetraMap,
165  UInt offset = 0 );
166 
167 
168  //! buildSystem
169  /*!
170  @param xi is the coefficient of mass term defined as \f$\xi^0/dt^2\f$;
171  @param alpha is the coefficient of damping term defined as \f$\alpha^0/dt\f$;
172  @note by default \f$xi\f$ is equal to 1 and \f$alpha\f$ is equal to 0;
173  */
174  void buildSystem (const Real& xi = 1, const Real& alpha = 0);
175 
176  //! buildSystem
177  /*!
178  @param matrix is the Mass \f$ + \f$ Damping \f$+\f$ Stiffness
179  @param xi is the coefficient of mass term defined as \f$\xi^0/dt^2\f$;
180  */
181  void buildSystem (matrix_ptrtype matrix, const Real& xi);
182 
183  //! build Damping matrix
184  /*!
185  building damping matrix defined as \f$\gamma A + \beta M\f$
186  @param damping matrix
187  @param alpha is the coefficient of time advancing
188  scheme defined as \f$\alpha^0/dt\f$
189  @notes alpha can be 1 and we can introduce
190  the time advancing coefficient in the updateSystem
191  */
192  void buildDamping (matrix_ptrtype damping, const Real& alpha);
193 
194  //!updateSystem with coefficients of time advance methods
195  /*
196  @param xi parameter of mass matrix \f$(\xi^0/dt^2)\f$;
197  @param alpha parameter of damping matrix \f$(\alpha^0/dt)\f$;
198  @param rhs vector
199  @note: this method must be used when we call buildSystem(1,1);
200  in this case we must set the coefficients of time advancing scheme;
201  */
202  void updateSystem (const vector_type& rhs,
203  const Real& xi = 0,
204  const Real& alpha = 0 );
205 
206  //! compute the start solution
207  /*! we consider the system \f$M w + D v + A u = f\f$;
208  in general we knowns the \f$u^0\f$, \f$v^0\f$ but not \f$w^0\f$.
209  This method computes \f$w^0\f$ starting by \f$F = f^0 - D v^0 -A u^0\f$
210  and boundary conditions associated to \f$w\f$;
211  @param solution is the vector where save the solution;
212  @param bch the boundary condition respect to \f$w\f$;
213  @param rhs is \f$f^0 - D v^0 -A u^0\f$
214  */
215  void computeStartValue ( vector_type& solution, const bchandler_raw_type& bch, const vector_type& rhs );
216 
217  //! Solve the system
218  /*!
219  solve the system
220  @param bch is boundary condition;
221  */
222  void iterate ( bchandler_raw_type& bch );
223 
224  //! update source term
225  /*!
226  @param source is the vector where we evaluate the source term;
227  */
228  void updateSourceTerm (const vector_type& source);
229 
230  //! updateRHS
231  /*!
232  @param rhs is the right and side;
233  */
234  inline void updateRHS (const vector_type& rhs)
235  {
236  M_displayer->leaderPrint (" P- Updating right hand side... ");
237 
238  LifeChrono chrono;
239  chrono.start();
240 
241  *M_rhsNoBC = rhs;
242  M_rhsNoBC->globalAssemble();
243 
244  chrono.stop();
245  M_displayer->leaderPrintMax ("done in ", chrono.diff() );
246  }
247 
248  //! reset the Prec
249  void resetPrec()
250  {
251  M_resetPrec = true;
252  }
253 
254  //@}
255 
256  //@name Set Methods
257  //@{
258 
259  //! Sets source term
260  /*!
261  @param source is function
262  */
263  void setSourceTerm ( source_type const& source )
264  {
265  M_source = source;
266  }
267 
268  //! Set parameters
269  /*!
270  @param dataFile is the file contains the parameters of problem
271  this method must be removed
272  */
273  void setDataFromGetPot ( const GetPot& dataFile );
274 
275  //@}
276 
277  //@name Get Methods
278  //@{
279 
280  //! Return the map
281  /*!
282  @returns epetraMap
283  */
284  MapEpetra const& map() const
285  {
286  return M_localMap;
287  }
288 
289  //! Return the map
290  /*!
291  @returns displayer
292  */
293  Displayer const& displayer() const
294  {
295  return M_displayer;
296  }
297 
298  //!Return the mass matrix
299  /*!
300  @returns the mass matrix (it doesn't divided by \f$\xi/dt^2\f$)
301  */
302  matrix_type const matrMass() const
303  {
304  return *M_matrMass;
305  }
306 
307  //!Return the damping matrix
308  /*!
309  @returns the damping matrix (it doesn't divided by \f$\alpha/dt\f$)
310  */
312  {
313  return M_matrDamping;
314  }
315 
316  //!Return the damping matrix
317  /*!
318  @returns the system matrix given by Stiffness + Damping \f$\alpha/dt\f$ + Mass \f$\xi/dt^2\f$
319  */
321  {
322  return M_matrSystem;
323  }
324 
325  //!Return the Stiffness matrix
326  /*!
327  @returns the stiffness matrix
328  */
330  {
331  return M_matrLinearStiffness;
332  }
333 
334  //! Return FESpace
336  {
337  return M_FESpace;
338  }
339 
340  //! BCHandler getter and setter
341  /*!
342  @returns the boundary conditions
343  */
344  BCHandler const& BChandler() const
345  {
346  return M_BCh;
347  }
348 
349  //! Return the solution
350  /*!
351  @returns the solution
352  */
354  {
355  return M_solution;
356  }
357 
358  //! Return residual
359  /*
360  @returns the residual
361  */
363  {
364  return M_residual;
365  }
366 
367  //!Return right hand side without boundary conditions
368  /*
369  @returns the right hand side without boundary conditions;
370  */
372  {
373  return M_rhsNoBC;
374  }
375 
376  //!return the communicator
377  /*!
378  @returns the communicator
379  */
380  std::shared_ptr<Epetra_Comm> const& comm() const
381  {
382  return M_displayer->comm();
383  }
384 
385  //! Return offset;
386  /*
387  @returns offset;
388  */
389  const UInt& offset() const
390  {
391  return M_offset;
392  }
393 
394  //!thickness
395  /*!
396  @returns the thickness
397  */
398  inline const Real& thickness() const
399  {
400  return M_data->thickness();
401  }
402  //!density
403  /*!
404  @returns the density
405  */
406  inline const Real& density() const
407  {
408  return M_data->rho();
409  }
410 
411  //!young
412  /*!
413  @returns the young
414  */
415  inline const Real& young() const
416  {
417  return M_data->young();
418  }
419  //!poisson
420  /*!
421  @returns the poisson
422  */
423  inline const Real& poisson() const
424  {
425  return M_data->poisson();
426  }
427 
428  //@}
429 
430 private:
431  //@ Private Methods
432 
433  //! apply boundary condition
434  /*!
435  @param matrix of system;
436  @param rhs right hand side without boundaryCondition;
437  @param BCh boundary condition;
438  @param offset
439  */
441  vector_type& rhs,
443  UInt offset = 0);
444 
445  //@name Attributes
446 
447 protected :
448 
449  //! data of problem
451 
452  //! feSpace
454 
455  //! displayer
457 
458  //! current rank
460 
461  //! boundary condition
463 
464  //! Epetra map need to define the VectorEpetra;
466 
467  //! Matrix mass
469 
470  //! Matrix stiffness linear
472 
473  //! Matrix System
475 
476  //! Matrix Damping \f$\gamma A + \beta M\f$
478 
479  //!@name Elementary matrices and vectors:
480  //@{
481  //! linear stiffness
483 
484  //! mass
486  //!mass+ linear stiffness
488 
489  //!damping
491  //@}
492 
493  //! unknowns vector
495 
496  //! right hand side
498 
499  //! right hand side without boundary condition
501 
502  //! residual
504 
505  //! source term
507 
508  //! data for solving tangent problem with aztec
510 
511  //! true if reuse the preconditonar
513 
514  //! max number of iteration before to update preconditonator
516 
517  //! reset preconditionator
519 
520  //! maximum number of iteration for solver method
522 
523  //! offset
525 
526 };
527 
528 // ==============================================================
529 // Constructors & Destructors
530 // ==============================================================
531 
532 //! Empty Constructor
533 
534 template <typename Mesh, typename SolverType>
535 VenantKirchhoffViscoelasticSolver<Mesh, SolverType>::
537  M_data ( ),
538  M_FESpace ( ),
539  M_displayer ( ),
540  M_me ( 0 ),
541  M_BCh ( ),
542  M_localMap ( ),
543  M_matrMass ( ),
545  M_matrSystem ( ),
546  M_matrDamping ( ),
547  M_elmatK ( ),
548  M_elmatM ( ),
549  M_elmatC ( ),
550  M_elmatD ( ),
551  M_solution ( ),
552  M_rhs ( ),
553  M_rhsNoBC ( ),
554  M_residual ( ),
555  M_source ( ),
556  M_linearSolver ( ),
557  M_reusePrec ( ),
558  M_maxIterForReuse ( ),
559  M_resetPrec ( ),
560  M_maxIterSolver ( ),
561  M_offset ( )
562 
563 {
564 }
565 
566 // ==============================================================
567 // Methods
568 // ==============================================================
569 
570 template <typename Mesh, typename SolverType>
571 void
572 VenantKirchhoffViscoelasticSolver<Mesh, SolverType>::setup (
573  std::shared_ptr<data_type> data,
574  const std::shared_ptr< FESpace<Mesh, MapEpetra> >& feSpace,
575  std::shared_ptr<Epetra_Comm>& comm,
576  const std::shared_ptr<const MapEpetra>& epetraMap,
577  UInt offset
578 )
579 {
580  M_data = data;
581  M_FESpace = feSpace;
582  M_displayer.reset (new Displayer (comm) );
583  M_me = comm->MyPID();
584  M_elmatK.reset ( new MatrixElemental ( M_FESpace->fe().nbFEDof(), nDimensions, nDimensions ) );
585  M_elmatM.reset ( new MatrixElemental ( M_FESpace->fe().nbFEDof(), nDimensions, nDimensions ) );
586  M_elmatC.reset ( new MatrixElemental ( M_FESpace->fe().nbFEDof(), nDimensions, nDimensions ) );
587  M_elmatD.reset ( new MatrixElemental ( M_FESpace->fe().nbFEDof(), nDimensions, nDimensions ) );
588  M_localMap = epetraMap;
589  M_solution.reset (new vector_type (*M_localMap) );
590  M_rhsNoBC.reset ( new vector_type (*M_localMap) );
591  M_matrMass.reset (new matrix_type (*M_localMap) );
592  M_matrLinearStiffness.reset (new matrix_type (*M_localMap) );
593  M_matrDamping.reset (new matrix_type (*M_localMap) );
594  M_matrSystem.reset (new matrix_type (*M_localMap) );
595  M_offset = offset;
596 }
597 
598 template <typename Mesh, typename SolverType>
599 void
600 VenantKirchhoffViscoelasticSolver<Mesh, SolverType>::setup (
601  std::shared_ptr<data_type> data,
602  const std::shared_ptr< FESpace<Mesh, MapEpetra> >& feSpace,
603  std::shared_ptr<Epetra_Comm>& comm
604 )
605 {
606  setup ( data, feSpace, comm, feSpace->mapPtr(), (UInt) 0 );
607  M_rhs.reset ( new vector_type (*M_localMap) );
608  M_residual.reset ( new vector_type (*M_localMap) );
609  M_linearSolver.reset ( new SolverType ( comm ) );
610 
611 }
612 
613 template <typename Mesh, typename SolverType>
614 void
615 VenantKirchhoffViscoelasticSolver<Mesh, SolverType>::setup (
616  std::shared_ptr<data_type> data,
617  const std::shared_ptr< FESpace<Mesh, MapEpetra> >& feSpace,
618  bchandler_type& BCh,
619  std::shared_ptr<Epetra_Comm>& comm
620 )
621 {
622  setup (data, feSpace, comm);
623  M_BCh = BCh;
624 }
625 
626 template <typename Mesh, typename SolverType>
627 void
628 VenantKirchhoffViscoelasticSolver<Mesh, SolverType>::setDataFromGetPot ( const GetPot& dataFile )
629 {
630  M_linearSolver->setDataFromGetPot ( dataFile, "problem/solver" );
631  M_linearSolver->setupPreconditioner (dataFile, "problem/prec");
632 }
633 
634 template <typename Mesh, typename SolverType>
635 void
636 VenantKirchhoffViscoelasticSolver<Mesh, SolverType>::
637 buildSystem (const Real& xi, const Real& alpha)
638 {
639  M_displayer->leaderPrint (" P- Computing constant matrices ... ");
640  LifeChrono chrono;
641  chrono.start();
642 
643  // these lines must be removed next week
644  this->buildSystem (M_matrSystem, xi);
645 
646  if (M_data->damping() )
647  {
648  M_matrDamping.reset (new matrix_type (*M_localMap) );
649  this->buildDamping (M_matrSystem, alpha);
650  }
651  M_matrSystem->globalAssemble();
652 
653  chrono.stop();
654  M_displayer->leaderPrintMax ( "done in ", chrono.diff() );
655 }
656 
657 template <typename Mesh, typename SolverType>
658 void
659 VenantKirchhoffViscoelasticSolver<Mesh, SolverType>::
660 buildSystem (matrix_ptrtype matrSystem, const Real& xi)
661 {
662  M_displayer->leaderPrint ( "P- Building the system ... ");
663 
664  LifeChrono chrono;
665  chrono.start();
666 
667  // Elementary computation and matrix assembling
668  // Loop on elements
669 
670  for ( UInt iVol = 0; iVol < this->M_FESpace->mesh()->numVolumes(); ++iVol )
671  {
672  this->M_FESpace->fe().updateFirstDeriv ( this->M_FESpace->mesh()->element ( iVol ) );
673 
674  Int marker = this->M_FESpace->mesh()->volumeList ( iVol ).markerID();
675 
676  this->M_elmatK->zero();
677  this->M_elmatM->zero();
678 
679  // building stiffness matrix
680  AssemblyElemental::stiff_strain ( 2 * M_data->mu (marker), *this->M_elmatK, this->M_FESpace->fe() );
681  AssemblyElemental::stiff_div ( M_data->lambda (marker), *this->M_elmatK, M_FESpace->fe() );
682 
683  this->M_elmatC->mat() = this->M_elmatK->mat();
684 
685  // mass*xi to compute mass+stiff
686 
687  AssemblyElemental::mass ( xi * M_data->rho(), *this->M_elmatM, this->M_FESpace->fe(), 0, 0, nDimensions );
688 
689  this->M_elmatC->mat() += this->M_elmatM->mat();
690 
691  //mass
692  this->M_elmatM->zero();
693  AssemblyElemental::mass (M_data->rho(), *this->M_elmatM, this->M_FESpace->fe(), 0, 0, nDimensions );
694 
695  assembleMatrix ( *M_matrLinearStiffness,
696  *this->M_elmatC,
697  this->M_FESpace->fe(),
698  this->M_FESpace->fe(),
699  this->M_FESpace->dof(),
700  this->M_FESpace->dof(),
701  0, 0, 0, 0);
702 
703  assembleMatrix ( *matrSystem,
704  *this->M_elmatC,
705  this->M_FESpace->fe(),
706  this->M_FESpace->fe(),
707  this->M_FESpace->dof(),
708  this->M_FESpace->dof(),
709  0, 0, 0, 0);
710 
711  assembleMatrix ( *this->M_matrMass,
712  *this->M_elmatM,
713  this->M_FESpace->fe(),
714  this->M_FESpace->fe(),
715  this->M_FESpace->dof(),
716  this->M_FESpace->dof(),
717  0, 0, 0, 0);
718  }
719 
720  M_matrMass->globalAssemble();
721  M_matrLinearStiffness->globalAssemble();
722  chrono.stop();
723  M_displayer->leaderPrintMax ("done in ", chrono.diff() );
724 
725 }
726 
727 template <typename Mesh, typename SolverType>
728 void VenantKirchhoffViscoelasticSolver<Mesh, SolverType>::
729 buildDamping (matrix_ptrtype damping, const Real& alpha)
730 {
731  LifeChrono chrono;
732  chrono.start();
733 
734  M_displayer->leaderPrint ( "P- Building the system Damping matrix ... ");
735 
736  // Elementary computation and matrix assembling
737  // Loop on elements
738  for ( UInt iVol = 0; iVol < this->M_FESpace->mesh()->numVolumes(); ++iVol )
739  {
740  this->M_FESpace->fe().updateFirstDeriv ( this->M_FESpace->mesh()->element ( iVol ) );
741 
742  Int marker = this->M_FESpace->mesh()->volumeList ( iVol ).markerID();
743 
744  Real gamma = M_data->gamma (marker);
745  Real beta = M_data->beta (marker);
746 
747  //building damping matrix
748 
749  this->M_elmatD->zero();
750 
751  AssemblyElemental::stiff_strain ( 2.0 * M_data->mu (marker) * gamma , *this->M_elmatD, this->M_FESpace->fe() );
752  AssemblyElemental::stiff_div ( M_data->lambda (marker) * gamma, *this->M_elmatD, this->M_FESpace->fe() );
753  AssemblyElemental::mass ( beta * M_data->rho(), *this->M_elmatD, this->M_FESpace->fe(), 0, 0);
754 
755  assembleMatrix ( *damping,
756  *this->M_elmatD,
757  this->M_FESpace->fe(),
758  this->M_FESpace->fe(),
759  this->M_FESpace->dof(),
760  this->M_FESpace->dof(),
761  0, 0, 0, 0);
762  }
763 
764  *M_matrSystem += *damping * alpha;
765  *M_matrDamping = *damping;
766 
767  M_matrDamping->globalAssemble();
768  M_displayer->leaderPrintMax ( " done in ", chrono.diff() );
769 }
770 
771 template <typename Mesh, typename SolverType>
772 void VenantKirchhoffViscoelasticSolver<Mesh, SolverType>::
774  const Real& xi,
775  const Real& alpha)
776 {
777 
778  LifeChrono chrono;
779 
780  updateRHS (rhs);
781 
782  if (xi == 0 & alpha == 0 )
783  {
784  M_displayer->leaderPrint ("P - use the same System matrix ... \n ");
785  }
786  else
787  {
788  M_displayer->leaderPrint ("P - updating the System matrix .... ");
789  chrono.start();
791 
792  if (xi != 0. )
793  {
794  *M_matrSystem += *M_matrMass * xi;
795  }
796 
797  if (alpha != 0)
798  {
799  *M_matrSystem += *M_matrDamping * alpha;
800  }
801 
802  M_matrSystem->GlobalAssemble();
803 
804  chrono.stop();
805  M_displayer->leaderPrintMax ("done in ", chrono.diff() );
806  }
807 
808 }
809 
810 template <typename Mesh, typename SolverType>
811 void VenantKirchhoffViscoelasticSolver<Mesh, SolverType>::
812 computeStartValue ( vector_type& solution, const bchandler_raw_type& bch, const vector_type& rhs )
813 {
814  vector_type rhsFull (rhs);
815 
816  prec_type prec;
817 
818  std::string precType = "Ifpack" ;
819 
820  prec.reset ( PRECFactory::instance().createObject (precType) );
821 
822  prec->buildPreconditioner (M_matrMass);
823 
824  Real condest = prec->Condest();
825 
826  M_linearSolver->setPreconditioner (prec);
827 
828  M_linearSolver->setMatrix (*M_matrMass);
829 
830  Int numIter = M_linearSolver->solve (solution, rhs);
831 }
832 
833 template <typename Mesh, typename SolverType>
834 void VenantKirchhoffViscoelasticSolver<Mesh, SolverType>::
836 {
837  M_displayer->leaderPrint ("P - updating the Source Term.... ");
838  LifeChrono chrono;
839  chrono.start();
840 
841  for ( UInt iVol = 0; iVol < this->M_FESpace->mesh()->numVolumes(); ++iVol )
842  {
843  // M_elvecSource.zero();
844  Real f, x, y, z;
845 
846  UInt i, inod, ig, ic;
847  UInt eleID = this->M_FESpace->fe().currentLocalId();
848  Real u_ig;
849  for ( UInt iComp = 0; iComp < nDimensions; ++iComp )
850  {
851  for ( ig = 0; ig < this->M_FESpace->fe().nbQuadPt(); ++ig )
852  {
853  this->M_FESpace->fe().coorQuadPt ( x, y, z, ig );
854  f = M_source (M_data->dataTime()->time(), x, y, z, iComp + 1 );
855  u_ig = 0.;
856 
857  for ( i = 0; i < M_FESpace->fe().nbFEDof(); ++i )
858  {
859  inod = this->M_FESpace->dof().localToGlobalMap ( eleID, i ) + iComp * this->M_FESpace->dof().numTotalDof();
860  u_ig = f * this->M_FESpace->fe().phi ( i, ig );
861  source.sumIntoGlobalValues (inod, u_ig * this->M_FESpace->fe().weightDet ( ig ) );
862  }
863  }
864  }
865  }
866  source.GlobalAssemble();
867 
868  chrono.stop();
869  M_displayer->leaderPrintMax ("done on ", chrono.diff() );
870 }
871 
872 template <typename Mesh, typename SolverType>
873 void VenantKirchhoffViscoelasticSolver<Mesh, SolverType>::
875 {
876  LifeChrono chrono;
877 
878  // matrix and vector assembling communication
879  M_displayer->leaderPrint (" P- Solving the system ... \n");
880 
881  chrono.start();
882 
883  matrix_ptrtype matrFull ( new matrix_type (*M_localMap, M_matrSystem->meanNumEntries() ) );
884  *matrFull += *M_matrSystem;
885 
886  M_rhsNoBC->globalAssemble();
887 
888  vector_type rhsFull (*M_rhsNoBC);
889 
890  // boundary conditions update
891  M_displayer->leaderPrint (" P- Applying boundary conditions ... ");
892 
893  chrono.start();
894  this->applyBoundaryConditions (*matrFull, rhsFull, bch);
895 
896  chrono.stop();
897 
898  M_displayer->leaderPrintMax ("done in " , chrono.diff() );
899 
900  M_linearSolver->resetPreconditioner();
901  M_resetPrec = false;
902 
903  // solving the system
904  M_linearSolver->setMatrix (*matrFull);
905  Real numIter = M_linearSolver->solveSystem ( rhsFull, *M_solution, matrFull);
906 
907  numIter = std::abs (numIter);
908 
909  if (numIter >= M_maxIterForReuse || numIter >= M_maxIterSolver)
910  {
911  resetPrec();
912  }
913 
914  *M_residual = *M_matrSystem * ( *M_solution);
915  *M_residual -= *M_rhsNoBC;
916 
917 } // iterate()
918 
919 //=========================================================
920 // Private Methods
921 //=========================================================
922 
923 template<typename Mesh, typename SolverType>
924 void VenantKirchhoffViscoelasticSolver<Mesh, SolverType>::
925 applyBoundaryConditions (matrix_type& matrix,
926  vector_type& rhs,
927  bchandler_raw_type& BCh,
928  UInt offset)
929 {
930  if (offset)
931  {
932  BCh.setOffset (offset);
933  }
934 
935  if ( !BCh.bcUpdateDone() )
936  {
937  BCh.bcUpdate ( *this->M_FESpace->mesh(), this->M_FESpace->feBd(), this->M_FESpace->dof() );
938  }
939 
940  vector_type rhsFull (rhs, Unique); // bcManages now manages the also repeated parts
941 
942  bcManage ( matrix, rhsFull, *this->M_FESpace->mesh(), this->M_FESpace->dof(), BCh, this->M_FESpace->feBd(), 1., M_data->dataTime()->time() );
943 
944  // matrix should be GlobalAssembled by bcManage
945 
946  rhs = rhsFull;
947 
948 } // applyBoundaryCondition
949 
950 } // namespace
951 #endif /* VENANTKIRCHHOFFVISCOELASTICSOLVER */
std::shared_ptr< MatrixElemental > M_elmatK
linear stiffness
std::shared_ptr< const MapEpetra > M_localMap
Epetra map need to define the VectorEpetra;.
std::function< Real(Real const &, Real const &, Real const &, Real const &, ID const &) > source_type
matrix_ptrtype const matrSystem() const
Return the damping matrix.
std::shared_ptr< solver_type > M_linearSolver
data for solving tangent problem with aztec
Displayer const & displayer() const
Return the map.
matrix_type const matrMass() const
Return the mass matrix.
FESpace - Short description here please!
Definition: FESpace.hpp:78
UInt M_maxIterSolver
maximum number of iteration for solver method
std::shared_ptr< MatrixElemental > M_elmatD
damping
matrix_ptrtype M_matrLinearStiffness
Matrix stiffness linear.
virtual void setup(std::shared_ptr< data_type > data, const std::shared_ptr< FESpace< Mesh, MapEpetra > > &feSpace, std::shared_ptr< Epetra_Comm > &comm, const std::shared_ptr< const MapEpetra > &epetraMap, UInt offset=0)
class setup
void setSourceTerm(source_type const &source)
Sets source term.
std::shared_ptr< data_type > M_data
data of problem
void setup(std::shared_ptr< data_type > data, const std::shared_ptr< FESpace< Mesh, MapEpetra > > &feSpace, bchandler_type &BCh, std::shared_ptr< Epetra_Comm > &comm)
class setup
void buildDamping(matrix_ptrtype damping, const Real &alpha)
build Damping matrix
matrix_ptrtype const matrLinearStiff() const
Return the Stiffness matrix.
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
void setDataFromGetPot(const GetPot &dataFile)
Set parameters.
UInt M_maxIterForReuse
max number of iteration before to update preconditonator
void setup(std::shared_ptr< data_type > data, const std::shared_ptr< FESpace< Mesh, MapEpetra > > &feSpace, std::shared_ptr< Epetra_Comm > &comm)
class setup
Epetra_Import const & importer()
Getter for the Epetra_Import.
Definition: MapEpetra.cpp:394
std::shared_ptr< MatrixElemental > M_elmatC
mass+ linear stiffness
uint32_type ID
IDs.
Definition: LifeV.hpp:194
std::shared_ptr< vector_type > M_residual
residual
void computeStartValue(vector_type &solution, const bchandler_raw_type &bch, const vector_type &rhs)
compute the start solution
FESpace< Mesh, MapEpetra > & feSpace()
Return FESpace.
vector_ptrtype M_rhsNoBC
right hand side without boundary condition
void buildSystem(matrix_ptrtype matrix, const Real &xi)
buildSystem
void buildSystem(const Real &xi=1, const Real &alpha=0)
buildSystem
std::shared_ptr< FESpace< Mesh, MapEpetra > > M_FESpace
feSpace
double Real
Generic real data.
Definition: LifeV.hpp:175
std::shared_ptr< bchandler_raw_type > bchandler_type
void updateSystem(const vector_type &rhs, const Real &xi=0, const Real &alpha=0)
updateSystem with coefficients of time advance methods
vector_ptrtype & rhsContributionSecondDerivativeithoutBC()
Return right hand side without boundary conditions.
const UInt nDimensions(NDIM)
BCHandler const & BChandler() const
BCHandler getter and setter.
void updateSourceTerm(const vector_type &source)
update source term
void applyBoundaryConditions(matrix_type &matrix, vector_type &rhs, bchandler_raw_type &BCh, UInt offset=0)
apply boundary condition
void iterate(bchandler_raw_type &bch)
Solve the system.
matrix_ptrtype const matrDamping() const
Return the damping matrix.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191