2 #include <lifev/fsi_blocks/solver/ALESolver.hpp> 12 ALESolver::ALESolver ( FESpace<mesh_Type, MapEpetra>& mmFESpace,
13 std::shared_ptr<Epetra_Comm> comm ) :
14 M_FESpace ( mmFESpace ),
15 M_localMap ( M_FESpace.map() ),
16 M_matrHE (
new matrix_Type (M_localMap ) ),
18 M_me ( comm->MyPID() ),
19 M_verbose ( M_me == 0 ),
20 M_elmat ( M_FESpace.fe().nbFEDof(), nDimensions, nDimensions ),
25 M_linearElasticity (
false),
31 ALESolver::ALESolver ( FESpace<mesh_Type, MapEpetra>& mmFESpace,
32 std::shared_ptr<Epetra_Comm> comm ,
35 M_FESpace ( mmFESpace ),
36 M_localMap ( localMap),
37 M_matrHE (
new matrix_Type (M_localMap ) ),
39 M_me ( comm->MyPID() ),
40 M_verbose ( M_me == 0 ),
41 M_elmat ( M_FESpace.fe().nbFEDof(), nDimensions, nDimensions ),
45 M_linearElasticity (
false),
56 void ALESolver::setUp (
const GetPot& dataFile )
58 M_linearElasticity = dataFile (
"ale/useLinearElasticity",
false);
60 M_diffusion = dataFile (
"ale/diffusion", 1.0);
62 M_young = dataFile (
"solid/model/young", 0.0);
64 M_poisson = dataFile (
"solid/model/poisson", 0.0);
68 M_secondRHS.reset (
new vector_Type (M_FESpace.map() ) );
69 M_disp.reset (
new vector_Type (M_FESpace.map() ) );
72 void ALESolver::iterate ( BCHandler& BCh )
77 M_displayer.leaderPrint (
" ALE- Applying boundary conditions ... ");
81 applyBoundaryConditions (*M_secondRHS, BCh);
84 M_displayer.leaderPrintMax (
"done in " , chrono.diff() );
87 void ALESolver::applyBoundaryConditions (vector_Type& rhs, BCHandler& BCh)
92 if ( ! BCh.bcUpdateDone() )
95 BCh.bcUpdate ( *M_FESpace.mesh(), M_FESpace.feBd(), M_FESpace.dof() );
100 BCh.setOffset (M_offset);
104 bcManageRhs (rhs, *M_FESpace.mesh(), M_FESpace.dof(), BCh, M_FESpace.feBd(), 1., 0.0);
107 bcManageMatrix ( *M_matrHE, *M_FESpace.mesh(), M_FESpace.dof(), BCh, M_FESpace.feBd(), 1.0, 0. );
110 void ALESolver::applyBoundaryConditions (BCHandler& BCh)
113 if ( ! BCh.bcUpdateDone() )
115 BCh.bcUpdate ( *M_FESpace.mesh(), M_FESpace.feBd(), M_FESpace.dof() );
118 bcManageMatrix ( *M_matrHE_BC, *M_FESpace.mesh(), M_FESpace.dof(), BCh, M_FESpace.feBd(), 1.0, 0. );
121 void ALESolver::computeMatrix( )
125 M_displayer.leaderPrint (
" ALE- Computing constant matrices ... ");
127 M_matrHE.reset (
new matrix_Type (M_localMap ) );
129 if ( M_linearElasticity )
131 using namespace ExpressionAssembly;
132 M_aleFESpace_ETA.reset(
new ETFESpaceAle_Type ( M_FESpace.mesh(), &(M_FESpace.refFE()), M_FESpace.map().commPtr() ) );
134 Real lambda = ( M_young * M_poisson ) / ( ( 1.0 + M_poisson ) * ( 1.0 - 2.0 * M_poisson ) );
135 Real mu = M_young / ( 2.0 * ( 1.0 + M_poisson ) );
137 integrate ( elements (M_aleFESpace_ETA->mesh() ),
141 pow( value(0.0228)/detJ, 0.8) * (
142 value( mu ) * dot ( grad(phi_i) , grad(phi_j) + transpose( grad(phi_j) ) ) +
143 value( lambda ) * div(phi_i) * div(phi_j)
149 UInt totalDof = M_FESpace.dof().numTotalDof();
151 for ( UInt i = 0; i < M_FESpace.mesh()->numVolumes(); ++i )
154 M_FESpace.fe().updateFirstDerivQuadPt ( M_FESpace.mesh()->volumeList ( i ) );
156 AssemblyElemental::stiff ( M_diffusion, M_elmat, M_FESpace.fe(), 0, 0, 3 );
158 for ( UInt j = 0; j < M_FESpace.fieldDim(); ++j )
160 assembleMatrix ( *M_matrHE, M_elmat, M_FESpace.fe(), M_FESpace.dof(), j, j, j * totalDof + M_offset, j * totalDof + M_offset );
165 M_matrHE->globalAssemble();
167 M_matrHE_BC.reset (
new matrix_Type (M_localMap ) );
169 *M_matrHE_BC += *M_matrHE;
172 M_displayer.leaderPrintMax (
"done in " , chrono.diff() );
176 void ALESolver::updateShapeDerivatives ( Real& alpha,
178 const Real& viscosity,
179 const vector_Type& un,
180 const vector_Type& uk,
182 const vector_Type& w,
183 FESpace<mesh_Type, MapEpetra>& velocityFESpace,
184 FESpace<mesh_Type, MapEpetra>& pressureFESpace,
186 bool convectiveTermDerivative,
192 M_displayer.leaderPrint (
" ALE- Computing shapeDerivatives ... ");
194 UInt numVelocityComponent = nDimensions;
197 M_matrShapeDerVel.reset (
new matrix_Type ( velocityFESpace.map() ) );
198 M_matrShapeDerPressure.reset (
new matrix_Type ( pressureFESpace.map() ) );
200 VectorElemental elementConvectionVelocity( velocityFESpace.fe().nbFEDof(), nDimensions );
201 VectorElemental elementMeshVelocity ( velocityFESpace.fe().nbFEDof(), nDimensions );
202 VectorElemental u_loc ( velocityFESpace.fe().nbFEDof(), nDimensions );
203 VectorElemental elementPressure ( pressureFESpace.fe().nbFEDof(), 1 );
204 VectorElemental elementVelocity ( velocityFESpace.fe().nbFEDof(), nDimensions );
207 vector_Type unRepeated ( un , Repeated );
208 vector_Type ukRepeated ( uk , Repeated );
210 vector_Type wRepeated ( w , Repeated );
214 for ( UInt i = 0; i <
this->M_FESpace.mesh()->numVolumes(); i++ )
217 pressureFESpace.fe().update ( pressureFESpace.mesh()->volumeList ( i ) );
218 velocityFESpace.fe().updateFirstDerivQuadPt ( velocityFESpace.mesh()->volumeList ( i ) );
219 pressureFESpace.fe().updateFirstDerivQuadPt ( velocityFESpace.mesh()->volumeList ( i ) );
225 M_FESpace.fe().updateFirstDerivQuadPt ( M_FESpace.mesh()->volumeList ( i ) );
228 std::shared_ptr<MatrixElemental> elementMatrixPressure (
new MatrixElemental ( pressureFESpace.fe().nbFEDof(),
231 M_FESpace.fe().nbFEDof(),
234 std::shared_ptr<MatrixElemental> elementMatrixVelocity (
new MatrixElemental ( velocityFESpace.fe().nbFEDof(),
237 velocityFESpace.fe().nbFEDof(),
240 std::shared_ptr<MatrixElemental> elementMatrixConvective;
242 if ( convectiveTermDerivative )
244 elementMatrixConvective.reset (
new MatrixElemental ( velocityFESpace.fe().nbFEDof(),
247 velocityFESpace.fe().nbFEDof(),
250 elementMatrixConvective->zero();
253 elementMatrixPressure->zero();
254 elementMatrixVelocity->zero();
256 for ( UInt iNode = 0 ; iNode < velocityFESpace.fe().nbFEDof() ; iNode++ )
258 UInt iLocal = velocityFESpace.fe().patternFirst ( iNode );
260 for ( UInt iComponent = 0; iComponent < numVelocityComponent; ++iComponent )
262 UInt iGlobal = velocityFESpace.dof().localToGlobalMap ( i, iLocal ) + iComponent * velocityFESpace.dim();
266 elementConvectionVelocity.vec() [ iLocal + iComponent * velocityFESpace.fe().nbFEDof() ] = unRepeated (iGlobal)
267 - wRepeated ( iGlobal );
273 elementMeshVelocity.vec( ) [ iLocal + iComponent * velocityFESpace.fe().nbFEDof() ] = wRepeated ( iGlobal );
275 elementVelocity.vec( ) [ iLocal + iComponent * velocityFESpace.fe().nbFEDof() ] = ukRepeated ( iGlobal );
281 u_loc.vec() [ iLocal + iComponent * velocityFESpace.fe().nbFEDof() ] = unRepeated ( iGlobal );
292 for ( UInt iNode = 0 ; iNode < pressureFESpace.fe().nbFEDof() ; iNode++ )
295 UInt iLocal = pressureFESpace.fe().patternFirst ( iNode );
296 UInt iGlobal = pressureFESpace.dof().localToGlobalMap ( i, iLocal ) + numVelocityComponent * velocityFESpace.dim();
298 elementPressure[ iLocal ] = ukRepeated[ iGlobal ];
301 AssemblyElemental::shape_terms (
307 elementConvectionVelocity,
309 *elementMatrixVelocity,
311 pressureFESpace.fe(),
312 (ID) M_FESpace.fe().nbFEDof(),
313 *elementMatrixPressure,
330 AssemblyElemental::source_press ( 1.0,
332 *elementMatrixPressure,
334 pressureFESpace.fe(),
335 (ID) M_FESpace.fe().nbFEDof() );
338 if ( convectiveTermDerivative )
339 AssemblyElemental::mass_gradu ( density,
341 *elementMatrixConvective,
342 velocityFESpace.fe() );
356 UInt
const velocityTotalDof ( velocityFESpace.dof().numTotalDof() );
357 UInt
const meshTotalDof ( M_FESpace.dof().numTotalDof() );
358 for ( UInt iComponent = 0; iComponent < numVelocityComponent; ++iComponent )
360 for ( UInt jComponent = 0; jComponent < numVelocityComponent; ++jComponent )
362 assembleMatrix ( *M_matrShapeDerVel,
363 *elementMatrixVelocity,
364 velocityFESpace.fe(),
366 velocityFESpace.dof(),
370 iComponent * velocityTotalDof,
371 jComponent * meshTotalDof);
374 if ( convectiveTermDerivative )
375 assembleMatrix ( *M_matrShapeDerVel,
376 *elementMatrixConvective,
377 velocityFESpace.fe(),
378 velocityFESpace.fe(),
379 velocityFESpace.dof(),
380 velocityFESpace.dof(),
383 iComponent * velocityTotalDof,
384 jComponent * velocityTotalDof );
387 assembleMatrix ( *M_matrShapeDerPressure,
388 *elementMatrixPressure,
389 pressureFESpace.fe(),
391 pressureFESpace.dof(),
396 iComponent * meshTotalDof );
400 if ( ! BCh.bcUpdateDone() )
403 BCh.bcUpdate ( *velocityFESpace.mesh(), velocityFESpace.feBd(), velocityFESpace.dof() );
406 bcManageMatrix ( *M_matrShapeDerVel, *velocityFESpace.mesh(), velocityFESpace.dof(), BCh, velocityFESpace.feBd(), 0.0, 0.0 );
408 M_matrShapeDerVel->globalAssemble(M_FESpace.mapPtr(), velocityFESpace.mapPtr());
409 M_matrShapeDerPressure->globalAssemble(M_FESpace.mapPtr(), pressureFESpace.mapPtr());
413 M_displayer.leaderPrintMax (
"done in ", chrono.diff() );