LifeV
VenantKirchhoffElasticHandler.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 an abstract class for Elastic Structures.
30  *
31  * @version 1.0
32  * @date 01-06-2003
33  * @author Miguel Angel Fernandez
34  *
35  * @contributor Paolo Tricerri <paolo.tricerri@epfl.ch>
36  * @maintainer Paolo Tricerri <paolo.tricerri@epfl.ch>
37  */
38 
39 #ifndef _ELASTICSTRUCTUREHANDLER_H_
40 #define _ELASTICSTRUCTUREHANDLER_H_
41 
42 #include <cmath>
43 #include <sstream>
44 #include <cstdlib>
45 
46 #include <life/lifesolver/dataElasticStructure.hpp>
47 #include <lifev/core/fem/ReferenceFE.hpp>
48 #include <lifev/core/fem/DOF.hpp>
49 #include <lifev/core/LifeV.hpp>
50 #include <life/lifefilters/medit_wrtrs.hpp>
51 #include <lifev/core/fem/BCHandler.hpp>
52 
53 namespace LifeV
54 {
55 /*!
56  \class VenantKirchhoffElasticHandler
57 */
58 
59 template <typename Mesh>
62 {
63 
64 public:
65  //! @name Type definitions
66  //@{
67 
68  typedef Real ( *Function ) ( const Real&, const Real&, const Real&, const Real&, const ID& );
69  typedef std::function<Real ( Real const&, Real const&, Real const&, Real const&, ID const& ) > source_Type;
72 
73  //@}
74 
75  //! @name Constructors & Destructor
76  //@{
77 
79 
80  /*!
81  \param data_file GetPot data file
82  \param refFE reference FE for the displacement
83  \param Qr volumic quadrature rule
84  \param bdQr surface quadrature
85  \param BCh boundary conditions for the displacement
86  */
88  const RefernceFE& refFE,
89  const QuadratureRule& Qr,
90  const QuadratureRule& bdQr,
91  BCHandler& BCh );
92 
93  /*!
94  \param data_file GetPot data file
95  \param refFE reference FE for the displacement
96  \param Qr volumic quadrature rule
97  \param bdQr surface quadrature
98  */
100  const ReferenceFE& refFE,
101  const QuadratureRule& Qr,
102  const QuadratureRule& bdQr);
103 
104  //! Destructor
106  {}
107 
108  //@}
109 
110  //! @name Methods
111  //@{
112 
113  //! Update the right hand side for time advancing
114  /*!
115  \param source volumic force
116  \param time present time
117  */
118  virtual void timeAdvance ( source_Type const& , const Real& time ) = 0;
119 
120  //! Solve the non-linear problem
121  virtual void iterate() = 0;
122 
123  //! Postprocessing
124  void postProcess();
125 
126  //! Sets initial condition for the displacment en velocity
127  /*!
128  \param d0 space function defining the initial displacement
129  \param w0 space function defining the initial velocity
130  */
131  void initialize ( const Function& d0, const Function& w0 );
132 
133  /*!
134  \param depName file containing the initial displacement vector
135  \param velName file containing the initial velocity vector
136  \param starT starting time when the displacement and the velocity vectors
137  are set
138  */
139  void initialize ( const std::string& depName,
140  const std::string& velName,
141  Real startT = 0.);
142 
143  //@}
144 
145  //! @name Set methods
146  //@{
147 
148  //! checking if BC are set
149  const bool setSolidBC() const
150  {
151  return M_setBC;
152  }
153 
154  //! set the fluid BCs
155  /*!
156  \param BCh_solid BCHandler object containing the boundary conditions
157  */
158  void setSolidBC (BCHandler& BCh_solid)
159  {
160  M_BCh_solid = &BCh_solid;
161  M_setBC = true;
162  }
163 
164  //@}
165 
166  //! @name Get methods
167  //@{
168 
169  //! Returns the displacement vector
171 
172  //! Returns the velocity vector
174 
175  //! Returns the number of unknowns
176  const UInt getDimension() const
177  {
178  return M_dim;
179  }
180 
181  //! Returns the reference FE object
182  const ReferenceFE& getRefFE() const
183  {
184  return M_refFE;
185  }
186 
187  //! Returns the current FE object
189  {
190  return M_fe;
191  }
192  //! Returns the current FE object
193  const CurrentFE& getFe() const
194  {
195  return M_fe;
196  }
197  //! Returns the current boundary FE object
199  {
200  return M_feBd;
201  }
202  //! Returns the DOF object
203  const DOF& getdDof() const
204  {
205  return M_dof;
206  }
207 
208  //! Returns the BCHandler object
210  {
211  return *M_BCh_solid;
212  }
213  //@}
214 
215 private:
216 
217  //! @name Provate Methods
218  /*!@{
219 
220  //!private copy constructor:this class should not be copied
221  /*!
222  if you need a copy you should implement it, so that it copies the shared pointer one by one, without copying the content.
223  */
225  {}
226 
227  /*!
228  \param name string containing the name of the file
229  \param unknown vector that must be initialized to the vector contained in the file
230  */
231  void readUnknown ( const std::string& name,
233 
234  //! Reference FE
235  const ReferenceFE& M_refFE;
236 
237  //! The DOF object
239 
240  //! The number of total displacement dofs
242 
243  //! Quadrature rule for volumic elementary computations
245 
246  //! Quadrature rule for elementary computations
248 
249  //! Current FE
251 
252  //! Current boundary FE
254 
255  //! The displacement
258 
259  //! The velocity
261 
262  //! The current time
264 
265  //! Aux. var. for PostProc
267 
268  //! The BC handler
270 
271  bool M_setBC;
272 
273 };
274 
275 
276 //=========================================
277 // Constructor
278 //=========================================
279 
280 template <typename Mesh>
284  M_refFE ( ),
285  M_dof ( ),
286  M_dim ( ),
287  M_Qr ( ),
288  M_bdQr ( ),
289  M_fe ( ),
290  M_feBd ( ),
291  M_d ( ),
292  M_dRhs ( ),
293  M_w ( ),
294  M_time ( ),
295  M_count ( ),
296  M_BCh_solid ( )
297 {}
298 
299 template <typename Mesh>
302  const ReferenceFE& refFE,
303  const QuadratureRule& Qr,
304  const QuadratureRule& bdQr,
305  BCHandler& BCh )
306 {
308  M_refFE = refFE;
309  M_dof ( this->mesh(), M_refFE ),
310  M_dim = M_dof.numTotalDof();
311  M_Qr = Qr;
312  M_bdQr = bdQr;
313  M_fe ( M_refFE, getGeometricMap ( this->mesh() ), M_Qr )
315  M_d = M_dim;
316  M_dRhs = M_dim;
317  M_w = M_dim;
318  M_time = 0;
319  M_count = 0;
320  M_BCh_solid = &BCh;
321 }
322 
323 template <typename Mesh>
326  const ReferenceFE& refFE,
327  const QuadratureRule& Qr,
328  const QuadratureRule& bdQr)
329 {
330  VenantKirchhoffElasticData<Mesh> = data;
331  M_refFE = refFE;
332  M_dof ( this->mesh(), M_refFE ),
333  M_dim = M_dof.numTotalDof();
334  M_Qr = Qr;
335  M_bdQr = bdQr;
336  M_fe ( M_refFE, getGeometricMap ( this->mesh() ), M_Qr );
337  M_feBd ( M_refFE.boundaryFE(), getGeometricMap ( this->mesh() ).boundaryMap(), M_bdQr );
338  M_d = M_dim;
339  M_dRhs = M_dim;
340  M_w = M_dim ;
341  // _BCh( new BCHandler(0)),
342  M_time = 0;
343  M_count = 0;
344  M_BCh_solid = 0;
345 }
346 
347 // Returns the displacement vector
348 template <typename Mesh>
349 PhysVectUnknown<Vector>&
350 VenantKirchhoffElasticHandler<Mesh>::disp()
351 {
352  return M_d;
353 }
354 
355 
356 // Returns the velocity vector
357 template <typename Mesh>
358 PhysVectUnknown<Vector>&
360 {
361  return M_w;
362 }
363 
364 // Postprocessing
365 template <typename Mesh>
366 void
368 {
369  std::ostringstream index;
370  std::string name, namedef;
371 
372  ++M_count;
373 
374  if ( fmod ( float ( M_count ), float ( this->_verbose ) ) == 0.0 )
375  {
376  std::cout << " S- Post-processing \n";
377  index << ( M_count / this->_verbose );
378 
379  switch ( index.str().size() )
380  {
381  case 1:
382  name = "00" + index.str();
383  break;
384  case 2:
385  name = "0" + index.str();
386  break;
387  case 3:
388  name = index.str();
389  break;
390  }
391 
392  namedef = "defor." + name + ".mesh";
393  wr_medit_ascii_scalar ( "dep_x." + name + ".bb", M_d.giveVec(), this->mesh().numVertices() );
394  wr_medit_ascii_scalar ( "dep_y." + name + ".bb", M_d.giveVec() + M_dim, this->mesh().numVertices() );
395  wr_medit_ascii_scalar ( "dep_z." + name + ".bb", M_d.giveVec() + 2 * M_dim, this->mesh().numVertices() );
396  wr_medit_ascii2 ( namedef, this->mesh(), M_d, this->_factor );
397 
398  // wr_medit_ascii_vector("veloc."+name+".bb",_u.giveVec(),this->mesh().numVertices(),_dim_u);
399 
400  system ( ( "ln -sf " + namedef + " dep_x." + name + ".mesh" ).data() );
401  system ( ( "ln -sf " + namedef + " dep_y." + name + ".mesh" ).data() );
402  system ( ( "ln -sf " + namedef + " dep_z." + name + ".mesh" ).data() );
403 
404  // system(("ln -s "+this->mesh()_file+" veloc."+name+".mesh").data());
405 
406  wr_medit_ascii_scalar ( "veld_x." + name + ".bb", M_w.giveVec(), this->mesh().numVertices() );
407  wr_medit_ascii_scalar ( "veld_y." + name + ".bb", M_w.giveVec() + M_dim, this->mesh().numVertices() );
408  wr_medit_ascii_scalar ( "veld_z." + name + ".bb", M_w.giveVec() + 2 * M_dim, this->mesh().numVertices() );
409 
410  // wr_medit_ascii_vector("veloc."+name+".bb",_u.giveVec(),this->mesh().numVertices(),_dim_u);
411 
412  system ( ( "ln -sf " + namedef + " veld_x." + name + ".mesh" ).data() );
413  system ( ( "ln -sf " + namedef + " veld_y." + name + ".mesh" ).data() );
414  system ( ( "ln -sf " + namedef + " veld_z." + name + ".mesh" ).data() );
415 
416  // system(("ln -s "+this->mesh()_file+" veloc."+name+".mesh").data());
417  }
418 }
419 
420 // Sets the initial condition
421 template <typename Mesh>
422 void
423 VenantKirchhoffElasticHandler<Mesh>::initialize ( const Function& d0, const Function& w0 )
424 {
425 
426  // Initialize velocity
427 
428  typedef typename Mesh::VolumeShape GeoShape; // Element shape
429 
430  UInt nDofpV = M_refFE.nbDofPerVertex; // number of DOF per vertex
431  UInt nDofpE = M_refFE.nbDofPerEdge; // number of DOF per edge
432  UInt nDofpF = M_refFE.nbDofPerFace; // number of DOF per face
433  UInt nDofpEl = M_refFE.nbDofPerVolume; // number of DOF per Volume
434 
435  UInt nElemV = GeoShape::S_numVertices; // Number of element's vertices
436  UInt nElemE = GeoShape::S_numEdges; // Number of element's edges
437  UInt nElemF = GeoShape::S_numFaces; // Number of element's faces
438 
439  UInt nDofElemV = nElemV * nDofpV; // number of vertex's DOF on a Element
440  UInt nDofElemE = nElemE * nDofpE; // number of edge's DOF on a Element
441  UInt nDofElemF = nElemF * nDofpF; // number of face's DOF on a Element
442 
443  ID nbComp = M_d.nbcomp(); // Number of components of the mesh velocity
444 
445  Real x, y, z;
446 
447  ID lDof;
448 
449  // Loop on elements of the mesh
450  for ( ID iElem = 0; iElem < this->mesh().numVolumes(); ++iElem )
451  {
452 
453  M_fe.updateJac ( this->mesh().volume ( iElem ) );
454 
455  // Vertex based Dof
456  if ( nDofpV )
457  {
458 
459  // loop on element vertices
460  for ( ID iVe = 0; iVe < nElemV; ++iVe )
461  {
462 
463  // Loop number of DOF per vertex
464  for ( ID l = 0; l < nDofpV; ++l )
465  {
466  lDof = iVe * nDofpV + l; // Local dof in this element
467 
468  // Nodal coordinates
469  M_fe.coorMap ( x, y, z, M_fe.refFE.xi ( lDof ), M_fe.refFE.eta ( lDof ), M_fe.refFE.zeta ( lDof ) );
470 
471  // Loop on data vector components
472  for ( UInt icmp = 0; icmp < nbComp; ++icmp )
473  {
474  M_d ( icmp * M_dim + M_dof.localToGlobalMap ( iElem, lDof ) ) = d0 ( 0.0, x, y, z, icmp + 1 );
475  M_w ( icmp * M_dim + M_dof.localToGlobalMap ( iElem, lDof ) ) = w0 ( 0.0, x, y, z, icmp + 1 );
476  }
477  }
478  }
479  }
480 
481  // Edge based Dof
482  if ( nDofpE )
483  {
484 
485  // loop on element edges
486  for ( ID iEd = 0; iEd < nElemE; ++iEd )
487  {
488 
489  // Loop number of DOF per edge
490  for ( ID l = 0; l < nDofpE; ++l )
491  {
492  lDof = nDofElemV + iEd * nDofpE + l; // Local dof in the adjacent Element
493 
494  // Nodal coordinates
495  M_fe.coorMap ( x, y, z, M_fe.refFE.xi ( lDof ), M_fe.refFE.eta ( lDof ), M_fe.refFE.zeta ( lDof ) );
496 
497  // Loop on data vector components
498  for ( UInt icmp = 0; icmp < nbComp; ++icmp )
499  {
500  M_d ( icmp * M_dim + M_dof.localToGlobalMap ( iElem, lDof ) ) = d0 ( 0.0, x, y, z, icmp + 1 );
501  M_w ( icmp * M_dim + M_dof.localToGlobalMap ( iElem, lDof ) ) = w0 ( 0.0, x, y, z, icmp + 1 );
502  }
503  }
504  }
505  }
506 
507  // Face based Dof
508  if ( nDofpF )
509  {
510 
511  // loop on element faces
512  for ( ID iFa = 0; iFa < nElemF; ++iFa )
513  {
514 
515  // Loop on number of DOF per face
516  for ( ID l = 0; l < nDofpF; ++l )
517  {
518 
519  lDof = nDofElemE + nDofElemV + iFa * nDofpF + l; // Local dof in the adjacent Element
520 
521  // Nodal coordinates
522  M_fe.coorMap ( x, y, z, M_fe.refFE.xi ( lDof ), M_fe.refFE.eta ( lDof ), M_fe.refFE.zeta ( lDof ) );
523 
524  // Loop on data vector components
525  for ( UInt icmp = 0; icmp < nbComp; ++icmp )
526  {
527  M_d ( icmp * M_dim + M_dof.localToGlobalMap ( iElem, lDof ) ) = d0 ( 0.0, x, y, z, icmp + 1 );
528  M_w ( icmp * M_dim + M_dof.localToGlobalMap ( iElem, lDof ) ) = w0 ( 0.0, x, y, z, icmp + 1 );
529  }
530  }
531  }
532  }
533  // Element based Dof
534  // Loop on number of DOF per Element
535  for ( ID l = 0; l < nDofpEl; ++l )
536  {
537  lDof = nDofElemF + nDofElemE + nDofElemV + l; // Local dof in the Element
538 
539  // Nodal coordinates
540  M_fe.coorMap ( x, y, z, M_fe.refFE.xi ( lDof ), M_fe.refFE.eta ( lDof ), M_fe.refFE.zeta ( lDof ) );
541 
542  // Loop on data vector components
543  for ( UInt icmp = 0; icmp < nbComp; ++icmp )
544  {
545  M_d ( icmp * M_dim + M_dof.localToGlobalMap ( iElem, lDof ) ) = d0 ( 0.0, x, y, z, icmp + 1 );
546  M_w ( icmp * M_dim + M_dof.localToGlobalMap ( iElem, lDof ) ) = w0 ( 0.0, x, y, z, icmp + 1 );
547  }
548  }
549  }
550 }
551 
552 
553 // Sets the initial condition
554 template <typename Mesh>
555 void
556 VenantKirchhoffElasticHandler<Mesh>::initialize ( const std::string& depName,
557  const std::string& velName,
558  Real startT)
559 {
560  std::cout << " S- restarting at time = " << startT << std::endl;
561 
562  M_count = (Int) (startT / this->timestep() - 0.5);
563 
564  // Loop on elements of the mesh
565  for ( ID iElem = 0; iElem < this->mesh().numVolumes(); ++iElem )
566  {
567  M_fe.updateJac ( this->mesh().volume ( iElem ) );
568  }
569  readUnknown (depName, M_d);
570  readUnknown (velName, M_w);
571 }
572 
573 
574 template <typename Mesh>
575 void
576 VenantKirchhoffElasticHandler<Mesh>::readUnknown ( const std::string& name,
577  PhysVectUnknown<Vector>& unknown)
578 {
579  std::string sdummy;
580  std::string ext;
581  UInt nsx, nsy, nsz;
582  Int ndim;
583 
584  Int nDof = M_dim;
585 
586  std::string filenamex = name;
587  ext = "_x.bb";
588  filenamex.insert (filenamex.end(), ext.begin(), ext.end() );
589 
590  std::ifstream filex (filenamex.c_str(), std::ios::in);
591 
592  if (!filex)
593  {
594  std::cout << "Reading file " << filenamex
595  << " impossible" << std::endl;
596  exit (1);
597  }
598 
599  filex >> ndim;
600  filex >> sdummy;
601  filex >> nsx;
602 
603  if (nsx != M_dim)
604  {
605  std::cout << "restart: nonmatching dimension in file " << filenamex << std::endl;
606  exit (1);
607  }
608 
609  filex >> sdummy;
610 
611  for (UInt ix = 0; ix < nsx; ++ix)
612  {
613  filex >> unknown[ix + 0 * nDof];
614  // unknown[ix + 0*nDof] /= factor;
615  }
616 
617  filex.close();
618 
619  std::string filenamey = name;
620  ext = "_y.bb";
621  filenamey.insert (filenamey.end(), ext.begin(), ext.end() );
622 
623  std::ifstream filey (filenamey.c_str(), std::ios::in);
624 
625  if (!filey)
626  {
627  std::cout << "Reading file " << filenamey
628  << " impossible" << std::endl;
629  exit (1);
630  }
631 
632  filey >> ndim;
633  filey >> sdummy;
634  filey >> nsy;
635 
636  if (nsy != M_dim)
637  {
638  std::cout << "restart: nonmatching dimension in file " << filenamex << std::endl;
639  exit (1);
640  }
641 
642  filey >> sdummy;
643 
644  for (UInt iy = 0; iy < nsy; ++iy)
645  {
646  filey >> unknown[iy + 1 * nDof];
647  // unknown[iy + 1*nDof] /= factor;
648  }
649 
650  filey.close();
651 
652  std::string filenamez = name;
653  ext = "_z.bb";
654  filenamez.insert (filenamez.end(), ext.begin(), ext.end() );
655 
656  // std::cout << "Reading INRIA solid file (" << filenamez << ")"
657  // << ":" << std::endl;
658 
659  std::ifstream filez (filenamez.c_str(), std::ios::in);
660 
661  if (!filez)
662  {
663  std::cout << "Reading mesh file " << filenamez
664  << " impossible" << std::endl;
665  exit (1);
666  }
667 
668  filez >> ndim;
669  filez >> sdummy;
670  filez >> nsz;
671 
672  if (nsz != M_dim)
673  {
674  std::cout << "restart: nonmatching dimension in file " << filenamex << std::endl;
675  exit (1);
676  }
677 
678  filez >> sdummy;
679 
680  for (UInt iz = 0; iz < nsz; ++iz)
681  {
682  filez >> unknown[iz + 2 * nDof];
683  // unknown[iz + 2*nDof] /= factor;
684  }
685 
686  filez.close();
687 }
688 
689 
690 }
691 
692 #endif
VenantKirchhoffElasticHandler(VenantKirchhoffElasticHandler &T)
virtual void iterate()=0
Solve the non-linear problem.
CurrentFEManifold M_feBd
Current boundary FE.
const UInt getDimension() const
Returns the number of unknowns.
void initialize(const std::string &depName, const std::string &velName, Real startT=0.)
A class for a finite element on a manifold.
BCHandler - class for handling boundary conditions.
Definition: BCHandler.hpp:100
PhysVectUnknown< Vector > M_w
The velocity.
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
PhysVectUnknown< Vector > & getVelocity()
Returns the velocity vector.
void updateInverseJacobian(const UInt &iQuadPt)
const QuadratureRule & M_bdQr
Quadrature rule for elementary computations.
const QuadratureRule & M_Qr
Quadrature rule for volumic elementary computations.
virtual void timeAdvance(source_Type const &, const Real &time)=0
Update the right hand side for time advancing.
PhysVectUnknown< Vector > M_d
The displacement.
uint32_type ID
IDs.
Definition: LifeV.hpp:194
BCHandler & getBCh_solid()
Returns the BCHandler object.
setUp(const VenantKirchhoffElasticData< Mesh > &data, const ReferenceFE &refFE, const QuadratureRule &Qr, const QuadratureRule &bdQr)
void initialize(const Function &d0, const Function &w0)
Sets initial condition for the displacment en velocity.
const bool setSolidBC() const
checking if BC are set
double Real
Generic real data.
Definition: LifeV.hpp:175
CurrentFE - A primordial class for the assembly of the local matrices/vectors retaining the values on...
Definition: CurrentFE.hpp:243
The class for a reference Lagrangian finite element.
setUp(const VenantKirchhoffElasticData< Mesh > &data, const RefernceFE &refFE, const QuadratureRule &Qr, const QuadratureRule &bdQr, BCHandler &BCh)
const CurrentFE & getFe() const
Returns the current FE object.
const ReferenceFE & getRefFE() const
Returns the reference FE object.
std::function< Real(Real const &, Real const &, Real const &, Real const &, ID const &) > source_Type
UInt M_dim
The number of total displacement dofs.
QuadratureRule - The basis class for storing and accessing quadrature rules.
CurrentFEManifold & getFeBd()
Returns the current boundary FE object.
void setSolidBC(BCHandler &BCh_solid)
set the fluid BCs
std::shared_ptr< bchandlerRaw_type > bchandler_Type
PhysVectUnknown< Vector > & getDisplacement()
Returns the displacement vector.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
CurrentFE & getFe()
Returns the current FE object.
const DOF & getdDof() const
Returns the DOF object.