1 #include <lifev/navier_stokes_blocks/solver/NavierStokesSolverBlocks.hpp> 24 SignFunction(
const std::shared_ptr<Epetra_Comm>& communicator ) {
k = 0;
z = 0; comm = communicator; }
29 int interrogate_k () {
int k_global; comm->MaxAll(&k,&k_global,1);
return k_global; }
30 int interrogate_z () {
int z_global; comm->MaxAll(&z,&z_global,1);
return z_global; }
35 NavierStokesSolverBlocks::NavierStokesSolverBlocks(
const dataFile_Type dataFile,
const commPtr_Type& communicator):
38 M_displayer(communicator),
39 M_graphIsBuilt(
false),
40 M_oper(
new Operators::NavierStokesOperator),
41 M_operLoads(
new Operators::NavierStokesOperator),
43 M_fullyImplicit(
false),
44 M_graphPCDisBuilt(
false),
45 M_steady ( dataFile(
"fluid/miscellaneous/steady",
false) ),
46 M_density ( dataFile(
"fluid/physics/density", 1.0 ) ),
47 M_viscosity ( dataFile(
"fluid/physics/viscosity", 0.035 ) ),
48 M_useStabilization ( dataFile(
"fluid/stabilization/use",
false) ),
49 M_stabilizationType ( dataFile(
"fluid/stabilization/type",
"none") ),
50 M_nonconforming ( dataFile(
"fluid/nonconforming",
false) ),
51 M_imposeWeakBC ( dataFile(
"fluid/weak_bc/use",
false) ),
52 M_flagWeakBC ( dataFile(
"fluid/weak_bc/flag", 31) ),
53 M_meshSizeWeakBC ( dataFile(
"fluid/weak_bc/mesh_size", 0.0) ),
54 M_computeAerodynamicLoads ( dataFile(
"fluid/forces/compute",
false) ),
55 M_flagBody ( dataFile(
"fluid/forces/flag", 31 ) ),
56 M_solve_blocks ( dataFile(
"fluid/solve_blocks",
true ) ),
57 M_useFastAssembly ( dataFile(
"fluid/use_fast_assembly",
false ) ),
58 M_orderBDF ( dataFile(
"fluid/time_discretization/BDF_order", 2 ) ),
59 M_orderVel ( dataFile(
"fluid/stabilization/vel_order", 2 ) )
61 M_prec.reset ( Operators::NSPreconditionerFactory::instance().createObject (dataFile(
"fluid/preconditionerType",
"SIMPLE")));
64 NavierStokesSolverBlocks::~NavierStokesSolverBlocks()
68 void NavierStokesSolverBlocks::setParameters( )
70 std::string optionsPrec = M_dataFile(
"fluid/options_preconditioner",
"solverOptionsFast");
71 optionsPrec +=
".xml";
72 Teuchos::RCP<Teuchos::ParameterList> solversOptions = Teuchos::getParametersFromXmlFile (optionsPrec);
73 M_prec->setOptions(*solversOptions);
74 setSolversOptions(*solversOptions);
77 void NavierStokesSolverBlocks::setup(
const meshPtr_Type& mesh,
const int& id_domain)
82 if ( !M_nonconforming )
84 uOrder = M_dataFile(
"fluid/space_discretization/vel_order",
"P1");
85 pOrder = M_dataFile(
"fluid/space_discretization/pres_order",
"P1");
86 M_stiffStrain = M_dataFile(
"fluid/space_discretization/stiff_strain",
false );
93 uOrder = M_dataFile(
"fluid/master_space_discretization/vel_order",
"P1");
94 pOrder = M_dataFile(
"fluid/master_space_discretization/pres_order",
"P1");
95 M_stiffStrain = M_dataFile(
"fluid/master_space_discretization/stiff_strain",
false );
98 else if ( id_domain == 1 )
100 uOrder = M_dataFile(
"fluid/slave_space_discretization/vel_order",
"P1");
101 pOrder = M_dataFile(
"fluid/slave_space_discretization/pres_order",
"P1");
102 M_stiffStrain = M_dataFile(
"fluid/slave_space_discretization/stiff_strain",
false );
107 M_penalizeReverseFlow = M_dataFile(
"fluid/penalize_reverse_flow",
false);
108 M_flagPenalizeReverseFlow = M_dataFile(
"fluid/flag_outflow", 2);
113 M_useGraph = M_dataFile(
"fluid/use_graph",
false);
115 M_velocityFESpace.reset (
new FESpace<mesh_Type, map_Type> (mesh, uOrder, 3, M_comm) );
116 M_pressureFESpace.reset (
new FESpace<mesh_Type, map_Type> (mesh, pOrder, 1, M_comm) );
117 M_velocityFESpaceScalar.reset (
new FESpace<mesh_Type, map_Type> (mesh, uOrder, 1, M_comm) );
119 M_fespaceUETA.reset(
new ETFESpace_velocity(M_velocityFESpace->mesh(), &(M_velocityFESpace->refFE()), M_comm));
120 M_fespaceUETA_scalar.reset(
new ETFESpace_pressure(M_velocityFESpaceScalar->mesh(), &(M_velocityFESpaceScalar->refFE()), M_comm));
121 M_fespacePETA.reset(
new ETFESpace_pressure(M_pressureFESpace->mesh(), &(M_pressureFESpace->refFE()), M_comm));
123 M_uExtrapolated.reset(
new vector_Type ( M_velocityFESpace->map(), Repeated ) );
124 M_uExtrapolated->zero();
126 M_velocity.reset(
new vector_Type(M_velocityFESpace->map()) );
127 M_pressure.reset(
new vector_Type(M_pressureFESpace->map()) );
129 M_block00.reset(
new matrix_Type(M_velocityFESpace->map() ) );
130 M_block01.reset(
new matrix_Type(M_velocityFESpace->map() ) );
131 M_block10.reset(
new matrix_Type(M_pressureFESpace->map() ) );
132 M_block11.reset(
new matrix_Type(M_pressureFESpace->map() ) );
139 M_fullyImplicit = M_dataFile (
"newton/convectiveImplicit",
false);
141 M_monolithicMap.reset(
new map_Type ( M_velocityFESpace->map() ) );
142 *M_monolithicMap += M_pressureFESpace->map();
144 if ( M_useFastAssembly )
146 M_fastAssembler.reset(
new FastAssemblerNS ( M_velocityFESpace->mesh(), M_comm,
147 &(M_velocityFESpace->refFE()), &(M_pressureFESpace->refFE()),
148 M_velocityFESpace, M_pressureFESpace,
149 &(M_velocityFESpace->qr()) ) );
150 M_fastAssembler->allocateSpace ( &(M_velocityFESpace->fe()),
true );
154 if ( M_fullyImplicit )
156 M_displayer.leaderPrint (
" F - solving nonlinear Navier-Stokes\n");
157 M_relativeTolerance = M_dataFile (
"newton/abstol", 1.e-4);
158 M_absoluteTolerance = M_dataFile (
"newton/reltol", 1.e-4);
159 M_etaMax = M_dataFile (
"newton/etamax", 1e-4);
160 M_maxiterNonlinear = M_dataFile (
"newton/maxiter", 10);
162 M_nonLinearLineSearch = M_dataFile (
"newton/NonLinearLineSearch", 0);
164 if (M_comm->MyPID() == 0)
165 M_out_res.open (
"residualsNewton");
167 M_solution.reset(
new vector_Type ( *M_monolithicMap ) );
171 if ( M_useStabilization )
173 if ( id_domain == 0 )
175 M_stabilization.reset ( StabilizationFactory::instance().createObject (
"SUPG_SEMI_IMPLICIT_ALE" ) );
179 M_stabilization.reset ( StabilizationFactory::instance().createObject ( M_dataFile(
"fluid/stabilization/type",
"none") ) );
183 if (M_comm->MyPID() == 0)
184 std::cout <<
"\nUsing the " << M_stabilization->label() <<
" stabilization\n\n";
186 M_stabilization->setVelocitySpace(M_velocityFESpace);
187 M_stabilization->setPressureSpace(M_pressureFESpace);
188 M_stabilization->setDensity(M_density);
189 M_stabilization->setViscosity(M_viscosity);
190 int vel_order = M_dataFile (
"fluid/stabilization/vel_order", 1 );
191 M_stabilization->setConstant( vel_order );
192 M_stabilization->setBDForder ( M_dataFile (
"fluid/time_discretization/BDF_order", 1 ) );
193 M_stabilization->setCommunicator ( M_velocityFESpace->map().commPtr() );
194 M_stabilization->setTimeStep ( M_dataFile (
"fluid/time_discretization/timestep", 0.001 ) );
195 M_stabilization->setETvelocitySpace ( M_fespaceUETA );
196 M_stabilization->setETpressureSpace ( M_fespacePETA );
197 M_stabilization->setUseGraph( M_useGraph );
198 M_stabilization->setUseODEfineScale( M_dataFile(
"fluid/stabilization/ode_fine_scale",
false ) );
201 M_displayer.leaderPrintMax (
" Number of DOFs for the velocity = ", M_velocityFESpace->dof().numTotalDof()*3 ) ;
202 M_displayer.leaderPrintMax (
" Number of DOFs for the pressure = ", M_pressureFESpace->dof().numTotalDof() ) ;
206 void NavierStokesSolverBlocks::setExportFineScaleVelocity( ExporterHDF5<mesh_Type>& exporter,
const int& numElementsTotal)
208 M_stabilization->setExportFineScaleVelocity ( exporter, numElementsTotal );
211 void NavierStokesSolverBlocks::setSolversOptions(
const Teuchos::ParameterList& solversOptions)
213 std::shared_ptr<Teuchos::ParameterList> monolithicOptions;
214 monolithicOptions.reset(
new Teuchos::ParameterList(solversOptions.sublist(
"MonolithicOperator")) );
215 M_pListLinSolver = monolithicOptions;
218 void NavierStokesSolverBlocks::buildGraphs()
220 M_displayer.leaderPrint (
" F - Pre-building the graphs... ");
225 using namespace ExpressionAssembly;
230 M_Mu_graph.reset (
new Epetra_FECrsGraph (Copy, * (M_velocityFESpace->map().map (Unique) ), 0) );
231 buildGraph ( elements (M_fespaceUETA->mesh() ),
235 M_density * dot ( phi_i, phi_j )
237 M_Mu_graph->GlobalAssemble();
238 M_Mu_graph->OptimizeStorage();
242 M_Btranspose_graph.reset (
new Epetra_FECrsGraph (Copy, * (M_velocityFESpace->map().map (Unique) ), 0) );
243 buildGraph ( elements (M_fespaceUETA->mesh() ),
247 value(-1.0) * phi_j * div(phi_i)
248 ) >> M_Btranspose_graph;
249 M_Btranspose_graph->GlobalAssemble( *(M_pressureFESpace->map().map (Unique)), *(M_velocityFESpace->map().map (Unique)) );
250 M_Btranspose_graph->OptimizeStorage();
253 M_B_graph.reset (
new Epetra_FECrsGraph (Copy, *(M_pressureFESpace->map().map (Unique)), 0) );
254 buildGraph ( elements (M_fespaceUETA->mesh() ),
260 M_B_graph->GlobalAssemble( *(M_velocityFESpace->map().map (Unique)), *(M_pressureFESpace->map().map (Unique)) );
261 M_B_graph->OptimizeStorage();
264 M_C_graph.reset (
new Epetra_FECrsGraph (Copy, * (M_velocityFESpace->map().map (Unique) ), 0) );
265 buildGraph ( elements (M_fespaceUETA->mesh() ),
269 dot( M_density*value(M_fespaceUETA, *M_uExtrapolated)*grad(phi_j), phi_i)
271 M_C_graph->GlobalAssemble();
272 M_C_graph->OptimizeStorage();
275 M_A_graph.reset (
new Epetra_FECrsGraph (Copy, * (M_velocityFESpace->map().map (Unique) ), 0) );
277 buildGraph ( elements (M_fespaceUETA->mesh() ),
281 value( 0.5 * M_viscosity ) * dot( grad(phi_i) , grad(phi_j) + transpose(grad(phi_j)) )
283 M_A_graph->GlobalAssemble();
284 M_A_graph->OptimizeStorage();
287 M_F_graph.reset (
new Epetra_FECrsGraph (Copy, * (M_velocityFESpace->map().map (Unique) ), 0) );
290 buildGraph ( elements (M_fespaceUETA->mesh() ),
294 dot ( phi_i, phi_j ) +
295 dot( M_density*value(M_fespaceUETA, *M_uExtrapolated)*grad(phi_j), phi_i) +
296 value( 0.5 * M_viscosity ) * dot( grad(phi_i) + transpose(grad(phi_i)) , grad(phi_j) + transpose(grad(phi_j)) )
300 M_Jacobian_graph.reset (
new Epetra_FECrsGraph (Copy, * (M_velocityFESpace->map().map (Unique) ), 0) );
301 buildGraph ( elements (M_fespaceUETA->mesh() ),
305 dot ( phi_i, phi_j ) +
306 dot( M_density*value(M_fespaceUETA, *M_uExtrapolated)*grad(phi_j), phi_i) +
307 dot( M_density * phi_j * grad(M_fespaceUETA, *M_uExtrapolated), phi_i ) +
308 value( 0.5 * M_viscosity ) * dot( grad(phi_i) + transpose(grad(phi_i)) , grad(phi_j) + transpose(grad(phi_j)) )
309 ) >> M_Jacobian_graph;
310 M_Jacobian_graph->GlobalAssemble();
311 M_Jacobian_graph->OptimizeStorage();
316 buildGraph ( elements (M_fespaceUETA->mesh() ),
320 dot ( phi_i, phi_j ) +
321 dot( M_density*value(M_fespaceUETA, *M_uExtrapolated)*grad(phi_j), phi_i) +
322 M_viscosity * dot( grad(phi_i) , grad(phi_j) + transpose(grad(phi_j)) )
326 M_Jacobian_graph.reset (
new Epetra_FECrsGraph (Copy, * (M_velocityFESpace->map().map (Unique) ), 0) );
327 buildGraph ( elements (M_fespaceUETA->mesh() ),
331 dot ( phi_i, phi_j ) +
332 dot( M_density*value(M_fespaceUETA, *M_uExtrapolated)*grad(phi_j), phi_i) +
333 dot( M_density * phi_j * grad(M_fespaceUETA, *M_uExtrapolated), phi_i ) +
334 M_viscosity * dot( grad(phi_i) , grad(phi_j) + transpose(grad(phi_j)) )
335 ) >> M_Jacobian_graph;
336 M_Jacobian_graph->GlobalAssemble();
337 M_Jacobian_graph->OptimizeStorage();
340 M_F_graph->GlobalAssemble();
341 M_F_graph->OptimizeStorage();
343 if ( M_useStabilization )
345 M_stabilization->buildGraphs();
350 M_graphIsBuilt =
true;
353 M_displayer.leaderPrintMax (
" done in ", chrono.diff() ) ;
356 void NavierStokesSolverBlocks::buildSystem()
358 if ( M_useFastAssembly )
360 M_displayer.leaderPrint (
" F - Using fast assembly\n");
362 if ( M_orderVel == 1 )
364 M_fastAssembler->setConstants_NavierStokes(M_density, M_viscosity, M_timeStep, M_orderBDF, 30.0, M_alpha );
366 else if ( M_orderVel == 2 )
368 M_fastAssembler->setConstants_NavierStokes(M_density, M_viscosity, M_timeStep, M_orderBDF, 60.0, M_alpha );
371 M_fastAssembler->updateGeoQuantities ( &(M_velocityFESpace->fe()) );
374 if ( M_useGraph && !M_graphIsBuilt )
377 M_displayer.leaderPrint (
" F - Assembling constant terms... ");
383 M_Mu.reset (
new matrix_Type ( M_velocityFESpace->map(), *M_Mu_graph ) );
386 M_Btranspose.reset (
new matrix_Type ( M_velocityFESpace->map(), *M_Btranspose_graph ) );
387 M_Btranspose->zero();
389 M_B.reset (
new matrix_Type ( M_pressureFESpace->map(), *M_B_graph ) );
392 M_A.reset (
new matrix_Type ( M_velocityFESpace->map(), *M_A_graph ) );
395 M_C.reset (
new matrix_Type ( M_velocityFESpace->map(), *M_C_graph ) );
398 M_F.reset (
new matrix_Type ( M_velocityFESpace->map(), *M_F_graph ) );
401 M_Jacobian.reset (
new matrix_Type ( M_velocityFESpace->map(), *M_Jacobian_graph ) );
406 M_Mu.reset (
new matrix_Type ( M_velocityFESpace->map() ) );
409 M_Btranspose.reset (
new matrix_Type ( M_velocityFESpace->map() ) );
410 M_Btranspose->zero();
412 M_B.reset (
new matrix_Type ( M_pressureFESpace->map() ) );
415 M_A.reset (
new matrix_Type ( M_velocityFESpace->map() ) );
418 M_C.reset (
new matrix_Type ( M_velocityFESpace->map() ) );
421 M_F.reset (
new matrix_Type ( M_velocityFESpace->map() ) );
424 M_Jacobian.reset (
new matrix_Type ( M_velocityFESpace->map() ) );
428 if ( M_useFastAssembly )
430 M_fastAssembler->assemble_constant_terms( M_Mu, M_A, M_Btranspose, M_B );
431 M_Mu->globalAssemble();
432 M_Btranspose->globalAssemble( M_pressureFESpace->mapPtr(), M_velocityFESpace->mapPtr() );
433 M_B->globalAssemble( M_velocityFESpace->mapPtr(), M_pressureFESpace->mapPtr());
434 M_A->globalAssemble();
438 using namespace ExpressionAssembly;
443 integrate ( elements (M_fespaceUETA->mesh() ),
444 M_velocityFESpace->qr(),
447 value(M_density) * dot ( phi_i, phi_j )
449 M_Mu->globalAssemble();
452 integrate( elements(M_fespaceUETA->mesh()),
453 M_velocityFESpace->qr(),
456 value(-1.0) * phi_j * div(phi_i)
459 M_Btranspose->globalAssemble( M_pressureFESpace->mapPtr(), M_velocityFESpace->mapPtr() );
461 integrate( elements(M_fespaceUETA->mesh()),
462 M_pressureFESpace->qr(),
468 M_B->globalAssemble( M_velocityFESpace->mapPtr(), M_pressureFESpace->mapPtr());
470 integrate( elements(M_fespaceUETA->mesh()),
471 M_velocityFESpace->qr(),
474 value( M_viscosity ) * dot( grad(phi_i), grad(phi_j) + transpose(grad(phi_j)) )
477 M_A->globalAssemble();
482 *M_block01 += *M_Btranspose;
485 if ( !M_useStabilization )
487 M_block01->globalAssemble( M_pressureFESpace->mapPtr(), M_velocityFESpace->mapPtr() );
488 M_block10->globalAssemble( M_velocityFESpace->mapPtr(), M_pressureFESpace->mapPtr());
492 M_displayer.leaderPrintMax (
" done in ", chrono.diff() ) ;
495 void NavierStokesSolverBlocks::updateSystem(
const vectorPtr_Type& u_star,
const vectorPtr_Type& rhs_velocity )
498 M_velocityExtrapolated.reset(
new vector_Type ( *u_star, Unique ) );
499 M_uExtrapolated.reset(
new vector_Type ( *u_star, Repeated ) );
504 if ( M_useFastAssembly )
506 M_fastAssembler->assembleConvective( M_C, *M_uExtrapolated );
510 using namespace ExpressionAssembly;
511 integrate( elements(M_fespaceUETA->mesh()),
512 M_velocityFESpace->qr(),
515 dot( M_density * value(M_fespaceUETA, *M_uExtrapolated)*grad(phi_j), phi_i)
519 if ( M_imposeWeakBC )
523 using namespace ExpressionAssembly;
524 QuadratureBoundary myBDQR (buildTetraBDQR (quadRuleTria7pt) );
526 M_block00_weakBC.reset (
new matrix_Type ( M_velocityFESpace->map() ) );
527 M_block00_weakBC->zero();
529 integrate( boundary(M_fespaceUETA->mesh(), M_flagWeakBC),
533 value(-1.0)*value(M_viscosity)*dot( phi_i, ( grad(phi_j) + transpose( grad(phi_j) ) ) * Nface )
534 -value(M_viscosity)*dot( ( grad(phi_i) + transpose( grad(phi_i) ) ) * Nface, phi_j )
535 -value(M_density)*dot( phi_i, dot( value(M_fespaceUETA, *M_uExtrapolated), Nface ) * phi_j )
536 +value(4.0)*value(M_viscosity)/value(M_meshSizeWeakBC)*dot( phi_i - dot( phi_i, Nface)*Nface, phi_j - dot( phi_j, Nface)*Nface )
537 +value(4.0)*value(M_viscosity)/value(M_meshSizeWeakBC)*( dot( phi_i, Nface)*dot( phi_j, Nface) )
540 M_block00_weakBC->globalAssemble();
541 *M_C += *M_block00_weakBC;
544 if ( M_penalizeReverseFlow )
546 this->setupPostProc();
547 std::shared_ptr<SignFunction> signEvaluation(
new SignFunction(M_comm));
549 using namespace ExpressionAssembly;
552 QuadratureBoundary myBDQR (buildTetraBDQR (quadRuleTria7pt) );
554 boundary (M_fespaceUETA->mesh(), M_flagPenalizeReverseFlow),
558 value(-1.0*M_density)*eval( signEvaluation, dot(value(M_fespaceUETA, *M_uExtrapolated),Nface))*dot(phi_i, phi_j)
563 M_C->globalAssemble();
568 *M_block00 *= M_alpha/M_timeStep;
571 if ( !M_useStabilization )
572 M_block00->globalAssemble();
575 M_rhs.reset(
new vector_Type ( M_velocityFESpace->map(), Unique ) );
579 *M_rhs = *M_Mu* (*rhs_velocity);
582 *M_block01 += *M_Btranspose;
587 if ( !M_fullyImplicit && M_useStabilization )
589 M_displayer.leaderPrint (
"\tF - Assembling semi-implicit stabilization terms... ");
593 if ( M_useStabilization )
595 if ( M_stabilizationType.compare(
"VMSLES_SEMI_IMPLICIT")==0 )
596 M_stabilization->apply_matrix( *u_star, *M_pressure_extrapolated, *rhs_velocity);
599 if ( M_useFastAssembly )
601 M_stabilization->setFastAssembler( M_fastAssembler );
602 M_fastAssembler->setAlpha(M_alpha);
603 M_fastAssembler->setTimeStep(M_timeStep);
606 M_stabilization->apply_matrix( *u_star );
610 *M_block00 += *M_stabilization->block_00();
612 *M_block01 += *M_stabilization->block_01();
614 *M_block10 += *M_stabilization->block_10();
617 *M_block11 += *M_stabilization->block_11();
618 M_block11->globalAssemble();
620 M_rhs_pressure.reset(
new vector_Type ( M_pressureFESpace->map(), Unique ) );
621 M_rhs_pressure->zero();
623 M_stabilization->apply_vector( M_rhs, M_rhs_pressure, *u_star, *rhs_velocity);
625 M_rhs_pressure->globalAssemble();
628 M_displayer.leaderPrintMax (
" done in ", chrono.diff() ) ;
631 if ( M_imposeWeakBC )
635 using namespace ExpressionAssembly;
637 QuadratureBoundary myBDQR (buildTetraBDQR (quadRuleTria7pt) );
639 M_block01_weakBC.reset(
new matrix_Type(M_velocityFESpace->map() ) );
641 integrate( boundary(M_fespaceUETA->mesh(), M_flagWeakBC),
645 dot( phi_i, phi_j * Nface)
648 M_block01_weakBC->globalAssemble( M_pressureFESpace->mapPtr(), M_velocityFESpace->mapPtr() );
649 *M_block01 += *M_block01_weakBC;
651 integrate( boundary(M_fespaceUETA->mesh(), M_flagWeakBC),
655 value(-1.0)*dot(phi_i*Nface, phi_j)
660 M_rhs->globalAssemble();
661 M_block00->globalAssemble();
662 M_block01->globalAssemble( M_pressureFESpace->mapPtr(), M_velocityFESpace->mapPtr() );
663 M_block10->globalAssemble(M_velocityFESpace->mapPtr(), M_pressureFESpace->mapPtr());
667 void NavierStokesSolverBlocks::applyBoundaryConditions ( bcPtr_Type & bc,
const Real& time )
669 if ( M_computeAerodynamicLoads )
671 M_displayer.leaderPrint(
"\tNS operator - Compute Loads: TRUE");
673 M_block00_noBC.reset(
new matrix_Type(M_velocityFESpace->map() ) );
674 M_block01_noBC.reset(
new matrix_Type(M_velocityFESpace->map() ) );
676 M_block00_noBC->zero();
677 M_block01_noBC->zero();
679 *M_block00_noBC += *M_block00;
680 *M_block01_noBC += *M_block01;
682 if ( M_imposeWeakBC )
684 *M_block00_noBC -= *M_block00_weakBC;
685 *M_block01_noBC -= *M_block01_weakBC;
688 M_block00_noBC->globalAssemble();
689 M_block01_noBC->globalAssemble( M_pressureFESpace->mapPtr(), M_velocityFESpace->mapPtr() );
692 M_rhs_noBC.reset(
new vector_Type ( M_velocityFESpace->map(), Unique ) );
694 *M_rhs_noBC += *M_rhs;
698 bcManage ( *M_block00, *M_rhs, *M_velocityFESpace->mesh(), M_velocityFESpace->dof(), *bc, M_velocityFESpace->feBd(), 1.0, time );
699 bcManageMatrix( *M_block01, *M_velocityFESpace->mesh(), M_velocityFESpace->dof(), *bc, M_velocityFESpace->feBd(), 0.0, 0.0);
702 void NavierStokesSolverBlocks::applyBoundaryConditions ( bcPtr_Type & bc,
const Real& time,
const vectorPtr_Type& velocities )
707 bcManage ( *M_block00, *M_rhs, *M_velocityFESpace->mesh(), M_velocityFESpace->dof(), *bc, M_velocityFESpace->feBd(), 1.0, time );
708 bcManageMatrix( *M_block01, *M_velocityFESpace->mesh(), M_velocityFESpace->dof(), *bc, M_velocityFESpace->feBd(), 0.0, 0.0);
710 *M_rhs += *velocities;
713 void NavierStokesSolverBlocks::iterate( bcPtr_Type & bc,
const Real& time,
const vectorPtr_Type& velocities )
715 applyBoundaryConditions ( bc, time, velocities);
717 if ( M_dataFile(
"fluid/stabilization/ode_fine_scale",
false ) )
719 if ( M_stabilizationType.compare(
"SUPG_SEMI_IMPLICIT")==0 )
720 M_stabilization->updateODEfineScale ( M_velocity, M_pressure );
721 else if ( M_stabilizationType.compare(
"VMSLES_NEW")==0 )
722 M_stabilization->updateODEfineScale ( M_velocity, M_pressure, M_velocityExtrapolated );
726 void NavierStokesSolverBlocks::iterate( bcPtr_Type & bc,
const Real& time )
728 applyBoundaryConditions ( bc, time );
730 if (M_useStabilization)
731 if ( M_dataFile(
"fluid/stabilization/ode_fine_scale",
false ) )
733 if ( M_stabilizationType.compare(
"SUPG_SEMI_IMPLICIT")==0 )
734 M_stabilization->updateODEfineScale ( M_velocity, M_pressure );
735 else if ( M_stabilizationType.compare(
"VMSLES_NEW")==0 )
736 M_stabilization->updateODEfineScale ( M_velocity, M_pressure, M_velocityExtrapolated );
740 void NavierStokesSolverBlocks::solveTimeStep( )
743 M_displayer.leaderPrint(
"\tNS operator - set up the block operator...");
747 Operators::NavierStokesOperator::operatorPtrContainer_Type operData(2,2);
748 operData(0,0) = M_block00->matrixPtr();
749 operData(0,1) = M_block01->matrixPtr();
750 operData(1,0) = M_block10->matrixPtr();
751 if ( M_useStabilization )
752 operData(1,1) = M_block11->matrixPtr();
754 M_oper->setUp(operData, M_displayer.comm());
756 M_displayer.leaderPrintMax(
" done in " , chrono.diff() );
760 M_displayer.leaderPrint(
"\tPreconditioner operator - set up the block operator...");
764 if ( std::strcmp(M_prec->Label(),
"aSIMPLEOperator")==0 )
766 if (M_useStabilization)
768 M_prec->setUp(M_block00, M_block10, M_block01, M_block11);
772 M_prec->setUp(M_block00, M_block10, M_block01);
775 M_prec->setDomainMap(M_oper->OperatorDomainBlockMapPtr());
776 M_prec->setRangeMap(M_oper->OperatorRangeBlockMapPtr());
777 M_prec->updateApproximatedMomentumOperator();
778 M_prec->updateApproximatedSchurComplementOperator();
782 M_displayer.leaderPrintMax(
" done in " , chrono.diff() );
785 M_displayer.leaderPrint(
"\tset up the Trilinos solver...");
787 std::string solverType(M_pListLinSolver->get<std::string>(
"Linear Solver Type"));
788 M_invOper.reset(Operators::InvertibleOperatorFactory::instance().createObject(solverType));
790 M_invOper->setParameterList(M_pListLinSolver->sublist(solverType));
791 M_invOper->setOperator(M_oper);
792 M_invOper->setPreconditioner(M_prec);
795 M_displayer.leaderPrintMax(
" done in " , chrono.diff() );
798 BlockEpetra_Map upMap;
799 upMap.setUp ( M_velocityFESpace->map().map(Unique), M_pressureFESpace->map().map(Unique));
801 if ( M_useStabilization )
803 vector_Type rhs ( *M_monolithicMap, Unique );
804 vector_Type sol ( *M_monolithicMap, Unique );
809 rhs.subset ( *M_rhs, M_velocityFESpace->map(), 0, 0 );
810 rhs.subset ( *M_rhs_pressure, M_pressureFESpace->map(), 0, M_velocityFESpace->map().mapSize() );
812 M_invOper->ApplyInverse(rhs.epetraVector(), sol.epetraVector());
814 M_velocity->subset ( sol, M_velocityFESpace->map(), 0, 0 );
815 M_pressure->subset ( sol, M_pressureFESpace->map(), M_velocityFESpace->map().mapSize(), 0 );
819 BlockEpetra_MultiVector up(upMap, 1), rhs(upMap, 1);
820 rhs.block(0).Update(1.0, M_rhs->epetraVector(), 0.);
823 M_invOper->ApplyInverse(rhs,up);
825 M_velocity->epetraVector().Update(1.0,up.block(0),0.0);
826 M_pressure->epetraVector().Update(1.0,up.block(1),0.0);
830 if ( M_computeAerodynamicLoads )
833 M_forces.reset (
new vector_Type ( M_velocityFESpace->map(), Unique ) );
837 *M_forces += *M_rhs_noBC;
839 *M_forces -= *M_block00_noBC * ( *M_velocity );
841 *M_forces -= *M_block01_noBC * ( *M_pressure );
845 VectorSmall<2> NavierStokesSolverBlocks::computeForces( BCHandler& bcHDrag,
848 bcHDrag.bcUpdate ( *M_velocityFESpace->mesh(), M_velocityFESpace->feBd(), M_velocityFESpace->dof() );
849 bcHLift.bcUpdate ( *M_velocityFESpace->mesh(), M_velocityFESpace->feBd(), M_velocityFESpace->dof() );
851 vector_Type onesOnBodyDrag(M_velocityFESpace->map(), Unique);
852 onesOnBodyDrag.zero();
854 vector_Type onesOnBodyLift(M_velocityFESpace->map(), Unique);
855 onesOnBodyLift.zero();
857 bcManageRhs ( onesOnBodyDrag, *M_velocityFESpace->mesh(), M_velocityFESpace->dof(), bcHDrag, M_velocityFESpace->feBd(), 1., 0.);
858 bcManageRhs ( onesOnBodyLift, *M_velocityFESpace->mesh(), M_velocityFESpace->dof(), bcHLift, M_velocityFESpace->feBd(), 1., 0.);
863 drag = M_forces->dot(onesOnBodyDrag);
864 lift = M_forces->dot(onesOnBodyLift);
866 VectorSmall<2> Forces;
873 void NavierStokesSolverBlocks::iterate_nonlinear(
const Real& time )
875 applyBoundaryConditionsSolution ( time );
880 UInt status = NonLinearRichardson ( *M_solution, *
this, M_absoluteTolerance, M_relativeTolerance, M_maxiterNonlinear, M_etaMax,
881 M_nonLinearLineSearch, 0, 2, M_out_res, 0.0);
883 if ( M_computeAerodynamicLoads )
885 M_forces.reset (
new vector_Type ( *M_monolithicMap, Unique ) );
887 computeForcesNonLinear(M_forces, M_solution);
890 if (status == EXIT_FAILURE)
892 M_displayer.leaderPrint(
" WARNING: Newton failed " );
895 M_velocity->subset ( *M_solution, M_velocityFESpace->map(), 0, 0 );
896 M_pressure->subset ( *M_solution, M_pressureFESpace->map(), M_velocityFESpace->map().mapSize(), 0 );
899 void NavierStokesSolverBlocks::iterate_steady( )
904 applyBoundaryConditionsSolution ( 0.0 );
908 status = NonLinearRichardson ( *M_solution, *
this, M_absoluteTolerance, M_relativeTolerance, M_maxiterNonlinear, M_etaMax,
909 M_nonLinearLineSearch, 0, 2, M_out_res, 0.0);
911 M_velocity->subset ( *M_solution, M_velocityFESpace->map(), 0, 0 );
912 M_pressure->subset ( *M_solution, M_pressureFESpace->map(), M_velocityFESpace->map().mapSize(), 0 );
915 void NavierStokesSolverBlocks::applyBoundaryConditionsSolution (
const Real& time )
917 updateBCHandler(M_bc_sol);
918 bcManageRhs ( *M_solution, *M_velocityFESpace->mesh(), M_velocityFESpace->dof(), *M_bc_sol, M_velocityFESpace->feBd(), 1.0, time );
921 void NavierStokesSolverBlocks::updateBCHandler( bcPtr_Type & bc )
923 bc->bcUpdate ( *M_velocityFESpace->mesh(), M_velocityFESpace->feBd(), M_velocityFESpace->dof() );
926 void NavierStokesSolverBlocks::evaluateResidual(
const vectorPtr_Type& convective_velocity,
927 const vectorPtr_Type& velocity_km1,
928 const vectorPtr_Type& pressure_km1,
929 const vectorPtr_Type& rhs_velocity,
930 vectorPtr_Type& residualVelocity,
931 vectorPtr_Type& residualPressure)
933 residualVelocity->zero();
934 residualPressure->zero();
937 vectorPtr_Type res_velocity (
new vector_Type ( M_velocityFESpace->map(), Repeated ) );
938 vectorPtr_Type res_pressure (
new vector_Type ( M_pressureFESpace->map(), Repeated ) );
939 res_velocity->zero();
940 res_pressure->zero();
943 vectorPtr_Type convective_velocity_repeated (
new vector_Type (*convective_velocity, Repeated) );
944 vectorPtr_Type u_km1_repeated (
new vector_Type (*velocity_km1, Repeated) );
945 vectorPtr_Type p_km1_repeated (
new vector_Type (*pressure_km1, Repeated) );
946 vectorPtr_Type rhs_velocity_repeated (
new vector_Type (*rhs_velocity, Repeated) );
949 using namespace ExpressionAssembly;
953 integrate ( elements ( M_fespaceUETA->mesh() ),
954 M_velocityFESpace->qr(),
956 value(M_density) * value ( M_alpha / M_timeStep ) * dot ( value ( M_fespaceUETA, *u_km1_repeated ), phi_i ) -
957 value(M_density) * dot ( value ( M_fespaceUETA, *rhs_velocity_repeated ), phi_i ) +
958 value(M_viscosity) * dot ( grad ( phi_i ) + transpose ( grad ( phi_i ) ), grad ( M_fespaceUETA, *u_km1_repeated ) + transpose ( grad ( M_fespaceUETA, *u_km1_repeated ) ) ) +
959 value(M_density) * dot ( value ( M_fespaceUETA, *convective_velocity_repeated ) * grad ( M_fespaceUETA, *u_km1_repeated ), phi_i ) +
960 value ( -1.0 ) * value ( M_fespacePETA, *p_km1_repeated ) * div ( phi_i )
965 integrate ( elements ( M_fespaceUETA->mesh() ),
966 M_velocityFESpace->qr(),
968 value(M_density) * value ( M_alpha / M_timeStep ) * dot ( value ( M_fespaceUETA, *u_km1_repeated ), phi_i ) -
969 value(M_density) * dot ( value ( M_fespaceUETA, *rhs_velocity_repeated ), phi_i ) +
970 value(M_viscosity) * dot ( grad ( phi_i ), grad ( M_fespaceUETA, *u_km1_repeated ) + transpose ( grad ( M_fespaceUETA, *u_km1_repeated ) ) ) +
971 value(M_density) * dot ( value ( M_fespaceUETA, *convective_velocity_repeated ) * grad ( M_fespaceUETA, *u_km1_repeated ), phi_i ) +
972 value ( -1.0 ) * value ( M_fespacePETA, *p_km1_repeated ) * div ( phi_i )
976 integrate ( elements ( M_fespaceUETA->mesh() ),
977 M_pressureFESpace->qr(),
979 trace ( grad ( M_fespaceUETA, *u_km1_repeated ) ) * phi_i
983 if ( M_useStabilization )
985 M_displayer.leaderPrint (
"[F] - Assembly residual of the stabilization \n" ) ;
986 M_stabilization->apply_vector(res_velocity, res_pressure, *convective_velocity, *velocity_km1, *pressure_km1, *rhs_velocity);
989 res_velocity->globalAssemble();
990 res_pressure->globalAssemble();
992 vector_Type res_velocity_unique ( *res_velocity, Unique );
993 vector_Type res_pressure_unique ( *res_pressure, Unique );
995 *residualVelocity = res_velocity_unique;
996 *residualPressure = res_pressure_unique;
999 void NavierStokesSolverBlocks::evaluateResidual(
const vectorPtr_Type& convective_velocity,
1000 const vectorPtr_Type& velocity_km1,
1001 const vectorPtr_Type& pressure_km1,
1002 const vectorPtr_Type& rhs_velocity,
1003 vectorPtr_Type& residual)
1009 vectorPtr_Type res_velocity (
new vector_Type ( M_velocityFESpace->map(), Repeated ) );
1010 vectorPtr_Type res_pressure (
new vector_Type ( M_pressureFESpace->map(), Repeated ) );
1011 res_velocity->zero();
1012 res_pressure->zero();
1015 vectorPtr_Type convective_velocity_repeated (
new vector_Type (*convective_velocity, Repeated) );
1016 vectorPtr_Type u_km1_repeated (
new vector_Type (*velocity_km1, Repeated) );
1017 vectorPtr_Type p_km1_repeated (
new vector_Type (*pressure_km1, Repeated) );
1018 vectorPtr_Type rhs_velocity_repeated (
new vector_Type (*rhs_velocity, Repeated) );
1021 using namespace ExpressionAssembly;
1023 if ( M_stiffStrain )
1025 integrate ( elements ( M_fespaceUETA->mesh() ),
1026 M_velocityFESpace->qr(),
1028 M_density * value ( M_alpha / M_timeStep ) * dot ( value ( M_fespaceUETA, *u_km1_repeated ), phi_i ) -
1029 M_density * dot ( value ( M_fespaceUETA, *rhs_velocity_repeated ), phi_i ) +
1030 M_viscosity * dot ( grad ( phi_i ) + transpose ( grad ( phi_i ) ), grad ( M_fespaceUETA, *u_km1_repeated ) + transpose ( grad ( M_fespaceUETA, *u_km1_repeated ) ) ) +
1031 M_density * dot ( value ( M_fespaceUETA, *convective_velocity_repeated ) * grad ( M_fespaceUETA, *u_km1_repeated ), phi_i ) +
1032 value ( -1.0 ) * value ( M_fespacePETA, *p_km1_repeated ) * div ( phi_i )
1037 integrate ( elements ( M_fespaceUETA->mesh() ),
1038 M_velocityFESpace->qr(),
1040 M_density * value ( M_alpha / M_timeStep ) * dot ( value ( M_fespaceUETA, *u_km1_repeated ), phi_i ) -
1041 M_density * dot ( value ( M_fespaceUETA, *rhs_velocity_repeated ), phi_i ) +
1042 M_viscosity * dot ( grad ( phi_i ), grad ( M_fespaceUETA, *u_km1_repeated ) + transpose ( grad ( M_fespaceUETA, *u_km1_repeated ) ) ) +
1043 M_density * dot ( value ( M_fespaceUETA, *convective_velocity_repeated ) * grad ( M_fespaceUETA, *u_km1_repeated ), phi_i ) +
1044 value ( -1.0 ) * value ( M_fespacePETA, *p_km1_repeated ) * div ( phi_i )
1048 integrate ( elements ( M_fespaceUETA->mesh() ),
1049 M_pressureFESpace->qr(),
1051 trace ( grad ( M_fespaceUETA, *u_km1_repeated ) ) * phi_i
1055 if ( M_useStabilization )
1057 M_displayer.leaderPrint (
"[F] - Assembly residual of the stabilization \n" ) ;
1058 M_stabilization->apply_vector(res_velocity, res_pressure, *convective_velocity, *velocity_km1, *pressure_km1, *rhs_velocity);
1061 res_velocity->globalAssemble();
1062 res_pressure->globalAssemble();
1064 vector_Type res_velocity_unique ( *res_velocity, Unique );
1065 vector_Type res_pressure_unique ( *res_pressure, Unique );
1067 residual->subset ( res_velocity_unique, M_velocityFESpace->map(), 0, 0 );
1068 residual->subset ( res_pressure_unique, M_pressureFESpace->map(), 0, M_velocityFESpace->map().mapSize() );
1072 void NavierStokesSolverBlocks::assembleInterfaceMass( matrixPtr_Type& mass_interface,
const mapPtr_Type& interface_map,
1073 markerID_Type interfaceFlag,
const vectorPtr_Type& numerationInterface,
1077 matrixPtr_Type fluid_interfaceMass(
new matrix_Type ( M_velocityFESpace->map(), 50 ) );
1078 fluid_interfaceMass->zero();
1081 QuadratureBoundary myBDQR (buildTetraBDQR (quadRuleTria7pt) );
1083 using namespace ExpressionAssembly;
1084 integrate ( boundary (M_fespaceUETA->mesh(), interfaceFlag ),
1091 >> fluid_interfaceMass;
1093 fluid_interfaceMass->globalAssemble();
1096 mass_interface.reset(
new matrix_Type ( *interface_map, 50 ) );
1097 fluid_interfaceMass->restrict ( interface_map, numerationInterface, offset, mass_interface );
1100 void NavierStokesSolverBlocks::computeForcesNonLinear(vectorPtr_Type& force,
const vectorPtr_Type& solution)
1106 vectorPtr_Type u_km1 (
new vector_Type ( M_velocityFESpace->map(), Repeated ) );
1107 vectorPtr_Type p_km1 (
new vector_Type ( M_pressureFESpace->map(), Repeated ) );
1110 u_km1->subset ( *solution, M_velocityFESpace->map(), 0, 0 );
1111 p_km1->subset ( *solution, M_pressureFESpace->map(), M_velocityFESpace->map().mapSize(), 0 );
1114 vectorPtr_Type res_velocity (
new vector_Type ( M_velocityFESpace->map(), Unique ) );
1115 vectorPtr_Type res_pressure (
new vector_Type ( M_pressureFESpace->map(), Unique ) );
1116 res_velocity->zero();
1117 res_pressure->zero();
1119 vectorPtr_Type rhs_velocity_repeated;
1120 rhs_velocity_repeated.reset(
new vector_Type ( *M_velocityRhs, Repeated ) );
1122 using namespace ExpressionAssembly;
1124 if ( M_stiffStrain )
1126 integrate ( elements ( M_fespaceUETA->mesh() ),
1127 M_velocityFESpace->qr(),
1129 M_density * value ( M_alpha / M_timeStep ) * dot ( value ( M_fespaceUETA, *u_km1 ), phi_i ) -
1130 M_density * dot ( value ( M_fespaceUETA, *rhs_velocity_repeated ), phi_i ) +
1131 value ( 0.5 ) * M_viscosity * dot ( grad ( phi_i ) + transpose ( grad ( phi_i ) ), grad ( M_fespaceUETA, *u_km1 ) +
1132 transpose ( grad ( M_fespaceUETA, *u_km1 ) ) ) +
1133 M_density * dot ( value ( M_fespaceUETA, *u_km1 ) * grad ( M_fespaceUETA, *u_km1 ), phi_i ) +
1134 value ( -1.0 ) * value ( M_fespacePETA, *p_km1 ) * div ( phi_i )
1139 integrate ( elements ( M_fespaceUETA->mesh() ),
1140 M_velocityFESpace->qr(),
1142 M_density * value ( M_alpha / M_timeStep ) * dot ( value ( M_fespaceUETA, *u_km1 ), phi_i ) -
1143 M_density * dot ( value ( M_fespaceUETA, *rhs_velocity_repeated ), phi_i ) +
1144 M_viscosity * dot ( grad ( phi_i ), grad ( M_fespaceUETA, *u_km1 ) + transpose ( grad ( M_fespaceUETA, *u_km1 ) ) ) +
1145 M_density * dot ( value ( M_fespaceUETA, *u_km1 ) * grad ( M_fespaceUETA, *u_km1 ), phi_i ) +
1146 value ( -1.0 ) * value ( M_fespacePETA, *p_km1 ) * div ( phi_i )
1150 integrate ( elements ( M_fespaceUETA->mesh() ),
1151 M_pressureFESpace->qr(),
1153 trace ( grad ( M_fespaceUETA, *u_km1 ) ) * phi_i
1156 if ( M_useStabilization )
1158 M_stabilization->apply_vector(res_velocity, res_pressure, *u_km1, *p_km1, *rhs_velocity_repeated);
1161 res_velocity->globalAssemble();
1162 res_pressure->globalAssemble();
1164 force->subset ( *res_velocity, M_velocityFESpace->map(), 0, 0 );
1165 force->subset ( *res_pressure, M_pressureFESpace->map(), 0, M_velocityFESpace->map().mapSize() );
1168 void NavierStokesSolverBlocks::evalResidual(vector_Type& residual,
const vector_Type& solution,
const UInt )
1174 vectorPtr_Type u_km1_subs (
new vector_Type ( M_velocityFESpace->map(), Unique ) );
1175 vectorPtr_Type p_km1_subs (
new vector_Type ( M_pressureFESpace->map(), Unique ) );
1178 u_km1_subs->subset ( solution, M_velocityFESpace->map(), 0, 0 );
1179 p_km1_subs->subset ( solution, M_pressureFESpace->map(), M_velocityFESpace->map().mapSize(), 0 );
1182 vectorPtr_Type u_km1 (
new vector_Type ( *u_km1_subs, Repeated ) );
1183 vectorPtr_Type p_km1 (
new vector_Type ( *p_km1_subs, Repeated ) );
1186 vectorPtr_Type res_velocity (
new vector_Type ( M_velocityFESpace->map(), Repeated ) );
1187 vectorPtr_Type res_pressure (
new vector_Type ( M_pressureFESpace->map(), Repeated ) );
1188 res_velocity->zero();
1189 res_pressure->zero();
1191 vectorPtr_Type rhs_velocity_repeated;
1195 rhs_velocity_repeated.reset(
new vector_Type ( *M_velocityRhs, Repeated ) );
1201 using namespace ExpressionAssembly;
1203 if ( M_stiffStrain )
1205 integrate ( elements ( M_fespaceUETA->mesh() ),
1206 M_velocityFESpace->qr(),
1208 value ( 0.5 ) * M_viscosity * dot ( grad ( phi_i ) + transpose ( grad ( phi_i ) ), grad ( M_fespaceUETA, *u_km1 ) + transpose ( grad ( M_fespaceUETA, *u_km1 ) ) ) +
1209 M_density * dot ( value ( M_fespaceUETA, *u_km1 ) * grad ( M_fespaceUETA, *u_km1 ), phi_i ) +
1210 value ( -1.0 ) * value ( M_fespacePETA, *p_km1 ) * div ( phi_i )
1216 integrate ( elements ( M_fespaceUETA->mesh() ),
1217 M_velocityFESpace->qr(),
1219 M_viscosity * dot ( grad ( phi_i ), grad ( M_fespaceUETA, *u_km1 ) + transpose ( grad ( M_fespaceUETA, *u_km1 ) ) ) +
1220 M_density * dot ( value ( M_fespaceUETA, *u_km1 ) * grad ( M_fespaceUETA, *u_km1 ), phi_i ) +
1221 value ( -1.0 ) * value ( M_fespacePETA, *p_km1 ) * div ( phi_i )
1225 integrate ( elements ( M_fespaceUETA->mesh() ),
1226 M_pressureFESpace->qr(),
1228 trace ( grad ( M_fespaceUETA, *u_km1 ) ) * phi_i
1233 using namespace ExpressionAssembly;
1235 if ( M_stiffStrain )
1237 integrate ( elements ( M_fespaceUETA->mesh() ),
1238 M_velocityFESpace->qr(),
1240 M_density * value ( M_alpha / M_timeStep ) * dot ( value ( M_fespaceUETA, *u_km1 ), phi_i ) -
1241 M_density * dot ( value ( M_fespaceUETA, *rhs_velocity_repeated ), phi_i ) +
1242 M_viscosity * dot ( grad ( phi_i ) + transpose ( grad ( phi_i ) ), grad ( M_fespaceUETA, *u_km1 ) + transpose ( grad ( M_fespaceUETA, *u_km1 ) ) ) +
1243 M_density * dot ( value ( M_fespaceUETA, *u_km1 ) * grad ( M_fespaceUETA, *u_km1 ), phi_i ) +
1244 value ( -1.0 ) * value ( M_fespacePETA, *p_km1 ) * div ( phi_i )
1249 integrate ( elements ( M_fespaceUETA->mesh() ),
1250 M_velocityFESpace->qr(),
1252 M_density * value ( M_alpha / M_timeStep ) * dot ( value ( M_fespaceUETA, *u_km1 ), phi_i ) -
1253 M_density * dot ( value ( M_fespaceUETA, *rhs_velocity_repeated ), phi_i ) +
1254 M_viscosity * dot ( grad ( phi_i ), grad ( M_fespaceUETA, *u_km1 ) + transpose ( grad ( M_fespaceUETA, *u_km1 ) ) ) +
1255 M_density * dot ( value ( M_fespaceUETA, *u_km1 ) * grad ( M_fespaceUETA, *u_km1 ), phi_i ) +
1256 value ( -1.0 ) * value ( M_fespacePETA, *p_km1 ) * div ( phi_i )
1260 integrate ( elements ( M_fespaceUETA->mesh() ),
1261 M_pressureFESpace->qr(),
1263 trace ( grad ( M_fespaceUETA, *u_km1 ) ) * phi_i
1267 if ( M_useStabilization )
1269 M_displayer.leaderPrint (
"[F] - Assembly residual of the stabilization \n" ) ;
1270 M_stabilization->apply_vector(res_velocity, res_pressure, *u_km1, *p_km1, *rhs_velocity_repeated);
1273 res_velocity->globalAssemble();
1274 res_pressure->globalAssemble();
1277 vector_Type res_velocity_unique ( *res_velocity, Unique );
1278 vector_Type res_pressure_unique ( *res_pressure, Unique );
1282 applyBoundaryConditionsResidual(res_velocity_unique);
1286 applyBoundaryConditionsResidual(res_velocity_unique, M_time );
1289 residual.subset ( res_velocity_unique, M_velocityFESpace->map(), 0, 0 );
1290 residual.subset ( res_pressure_unique, M_pressureFESpace->map(), 0, M_velocityFESpace->map().mapSize() );
1294 updateConvectiveTerm(u_km1);
1295 updateJacobian(*u_km1);
1297 if ( M_useStabilization )
1299 M_stabilization->apply_matrix(*u_km1, *p_km1, *M_velocityRhs);
1301 *M_block00 += *M_stabilization->block_00();
1302 M_block00->globalAssemble();
1305 *M_block01 += *M_Btranspose;
1306 *M_block01 += *M_stabilization->block_01();
1307 M_block01->globalAssemble( M_pressureFESpace->mapPtr(), M_velocityFESpace->mapPtr() );
1311 *M_block10 += *M_stabilization->block_10();
1312 M_block10->globalAssemble(M_velocityFESpace->mapPtr(), M_pressureFESpace->mapPtr());
1315 *M_block11 += *M_stabilization->block_11();
1316 M_block11->globalAssemble();
1321 void NavierStokesSolverBlocks::applyBoundaryConditionsResidual ( vector_Type& r_u,
const Real& time )
1324 VectorEpetra ru_copy(r_u, Unique);
1327 if ( !M_bc_res_essential->bcUpdateDone() )
1328 M_bc_res_essential->bcUpdate ( *M_velocityFESpace->mesh(),
1329 M_velocityFESpace->feBd(),
1330 M_velocityFESpace->dof() );
1332 if ( !M_bc_res_natural->bcUpdateDone() )
1333 M_bc_res_natural->bcUpdate ( *M_velocityFESpace->mesh(),
1334 M_velocityFESpace->feBd(),
1335 M_velocityFESpace->dof() );
1337 bcManageRhs ( ru_copy,
1338 *M_velocityFESpace->mesh(),
1339 M_velocityFESpace->dof(),
1341 M_velocityFESpace->feBd(),
1345 bcManageRhs ( ru_copy,
1346 *M_velocityFESpace->mesh(),
1347 M_velocityFESpace->dof(),
1348 *M_bc_res_essential,
1349 M_velocityFESpace->feBd(),
1357 void NavierStokesSolverBlocks::updateConvectiveTerm (
const vectorPtr_Type& velocity)
1360 vectorPtr_Type velocity_repeated;
1361 velocity_repeated.reset (
new vector_Type ( *velocity, Repeated ) );
1366 if ( M_useFastAssembly )
1368 M_fastAssembler->assembleConvective( M_C, *velocity_repeated );
1372 using namespace ExpressionAssembly;
1373 integrate ( elements (M_fespaceUETA->mesh() ),
1374 M_velocityFESpace->qr(),
1377 dot ( M_density * value (M_fespaceUETA, *velocity_repeated) *grad (phi_j), phi_i)
1382 M_C->globalAssemble();
1387 *M_block00 += *M_Mu;
1388 *M_block00 *= M_alpha / M_timeStep;
1392 if ( !M_fullyImplicit )
1393 M_block00->globalAssemble( );
1396 void NavierStokesSolverBlocks::updateJacobian(
const vector_Type& u_k )
1398 vector_Type uk_rep ( u_k, Repeated );
1401 M_displayer.leaderPrint (
"[F] - Update Jacobian convective term\n" ) ;
1403 if ( M_fullyImplicit )
1405 if ( M_useFastAssembly )
1407 M_fastAssembler->jacobianNS( M_Jacobian, uk_rep );
1411 using namespace ExpressionAssembly;
1412 integrate( elements(M_fespaceUETA->mesh()),
1413 M_velocityFESpace->qr(),
1416 dot( M_density * phi_j * grad(M_fespaceUETA, uk_rep), phi_i )
1421 M_Jacobian->globalAssemble();
1423 *M_block00 += *M_Jacobian;
1424 if ( !M_useStabilization )
1425 M_block00->globalAssemble( );
1428 void NavierStokesSolverBlocks::updateStabilization(
const vector_Type& convective_velocity_previous_newton_step,
1429 const vector_Type& velocity_previous_newton_step,
1430 const vector_Type& pressure_previous_newton_step,
1431 const vector_Type& velocity_rhs )
1433 M_displayer.leaderPrint (
"[F] - Update Jacobian stabilization terms\n" ) ;
1435 if ( M_useFastAssembly )
1437 vector_Type beta_km1( convective_velocity_previous_newton_step, Repeated);
1438 vector_Type u_km1( velocity_previous_newton_step, Repeated);
1439 vector_Type p_km1( pressure_previous_newton_step, Repeated);
1440 vector_Type u_bdf( velocity_rhs, Repeated);
1446 matrixPtr_Type systemMatrix_fast_block_00 (
new matrix_Type ( M_velocityFESpace->map() ) );
1447 matrixPtr_Type systemMatrix_fast_block_01 (
new matrix_Type ( M_velocityFESpace->map() ) );
1448 matrixPtr_Type systemMatrix_fast_block_10 (
new matrix_Type ( M_pressureFESpace->map() ) );
1449 matrixPtr_Type systemMatrix_fast_block_11 (
new matrix_Type ( M_pressureFESpace->map() ) );
1450 systemMatrix_fast_block_00->zero();
1451 systemMatrix_fast_block_01->zero();
1452 systemMatrix_fast_block_10->zero();
1453 systemMatrix_fast_block_11->zero();
1455 M_fastAssembler->supg_FI_FSI_terms( systemMatrix_fast_block_00, systemMatrix_fast_block_01, systemMatrix_fast_block_10, systemMatrix_fast_block_11,
1456 beta_km1, u_km1, p_km1, u_bdf);
1458 systemMatrix_fast_block_00->globalAssemble();
1459 systemMatrix_fast_block_01->globalAssemble( M_pressureFESpace->mapPtr(), M_velocityFESpace->mapPtr() );
1460 systemMatrix_fast_block_10->globalAssemble( M_velocityFESpace->mapPtr(), M_pressureFESpace->mapPtr() );
1461 systemMatrix_fast_block_11->globalAssemble();
1463 *M_block00 += *systemMatrix_fast_block_00;
1464 M_block00->globalAssemble();
1467 *M_block01 += *M_Btranspose;
1468 *M_block01 += *systemMatrix_fast_block_01;
1469 M_block01->globalAssemble( M_pressureFESpace->mapPtr(), M_velocityFESpace->mapPtr() );
1473 *M_block10 += *systemMatrix_fast_block_10;
1474 M_block10->globalAssemble(M_velocityFESpace->mapPtr(), M_pressureFESpace->mapPtr());
1477 *M_block11 += *systemMatrix_fast_block_11;
1478 M_block11->globalAssemble();
1482 M_stabilization->apply_matrix(convective_velocity_previous_newton_step,
1483 velocity_previous_newton_step,
1484 pressure_previous_newton_step,
1487 *M_block00 += *M_stabilization->block_00();
1488 M_block00->globalAssemble();
1491 *M_block01 += *M_Btranspose;
1492 *M_block01 += *M_stabilization->block_01();
1493 M_block01->globalAssemble( M_pressureFESpace->mapPtr(), M_velocityFESpace->mapPtr() );
1497 *M_block10 += *M_stabilization->block_10();
1498 M_block10->globalAssemble(M_velocityFESpace->mapPtr(), M_pressureFESpace->mapPtr());
1501 *M_block11 += *M_stabilization->block_11();
1502 M_block11->globalAssemble();
1508 void NavierStokesSolverBlocks::solveJac( vector_Type& increment,
const vector_Type& residual,
const Real )
1511 applyBoundaryConditionsJacobian ( M_bc_sol );
1514 M_displayer.leaderPrint(
"\tNS operator - set up the block operator...");
1518 Operators::NavierStokesOperator::operatorPtrContainer_Type operDataJacobian ( 2, 2 );
1519 operDataJacobian ( 0, 0 ) = M_block00->matrixPtr();
1520 operDataJacobian ( 0, 1 ) = M_block01->matrixPtr();
1521 operDataJacobian ( 1, 0 ) = M_block10->matrixPtr();
1522 if ( M_useStabilization )
1523 operDataJacobian ( 1, 1 ) = M_block11->matrixPtr();
1525 M_oper->setUp(operDataJacobian, M_displayer.comm());
1527 M_displayer.leaderPrintMax(
" done in " , chrono.diff() );
1529 M_displayer.leaderPrint(
"\tPreconditioner operator - set up the block operator...");
1534 if ( std::strcmp(M_prec->Label(),
"aSIMPLEOperator")==0 )
1536 if (M_useStabilization)
1538 M_prec->setUp(M_block00, M_block10, M_block01, M_block11);
1542 M_prec->setUp(M_block00, M_block10, M_block01);
1545 M_prec->setDomainMap(M_oper->OperatorDomainBlockMapPtr());
1546 M_prec->setRangeMap(M_oper->OperatorRangeBlockMapPtr());
1547 M_prec->updateApproximatedMomentumOperator();
1548 M_prec->updateApproximatedSchurComplementOperator();
1552 M_displayer.leaderPrintMax(
" done in " , chrono.diff() );
1556 M_displayer.leaderPrint(
"\tset up the Trilinos solver...");
1558 std::string solverType(M_pListLinSolver->get<std::string>(
"Linear Solver Type"));
1559 M_invOper.reset(Operators::InvertibleOperatorFactory::instance().createObject(solverType));
1560 M_invOper->setParameterList(M_pListLinSolver->sublist(solverType));
1563 M_displayer.leaderPrintMax(
" done in " , chrono.diff() );
1565 M_invOper->setOperator(M_oper);
1566 M_invOper->setPreconditioner(M_prec);
1571 M_invOper->ApplyInverse(residual.epetraVector(), increment.epetraVector());
1573 vector_Type increment_velocity ( M_velocityFESpace->map(), Unique ) ;
1574 vector_Type increment_pressure ( M_pressureFESpace->map(), Unique ) ;
1576 increment_velocity.zero();
1577 increment_pressure.zero();
1579 increment_velocity.subset(increment);
1580 increment_pressure.subset(increment, M_velocityFESpace->dof().numTotalDof() * 3);
1584 void NavierStokesSolverBlocks::applyBoundaryConditionsJacobian ( bcPtr_Type & bc )
1586 bcManageMatrix( *M_block00, *M_velocityFESpace->mesh(), M_velocityFESpace->dof(), *bc, M_velocityFESpace->feBd(), 1.0, 0.0);
1587 bcManageMatrix( *M_block01, *M_velocityFESpace->mesh(), M_velocityFESpace->dof(), *bc, M_velocityFESpace->feBd(), 0.0, 0.0);
1588 M_block01->globalAssemble(M_pressureFESpace->mapPtr(), M_velocityFESpace->mapPtr());
1591 void NavierStokesSolverBlocks::preprocessBoundary(
const Real& nx,
const Real& ny,
const Real& nz, BCHandler& bc, Real& Q_hat,
const vectorPtr_Type& Phi_h,
const UInt flag,
1592 vectorPtr_Type& Phi_h_flag, vectorPtr_Type& V_hat_x, vectorPtr_Type& V_hat_y, vectorPtr_Type& V_hat_z)
1594 Phi_h_flag.reset (
new vector_Type ( M_velocityFESpaceScalar->map() ) );
1597 bcManageRhs ( *Phi_h_flag, *M_velocityFESpaceScalar->mesh(), M_velocityFESpaceScalar->dof(), bc, M_velocityFESpaceScalar->feBd(), 1., 0.);
1599 *Phi_h_flag *= *Phi_h;
1605 vectorPtr_Type Phi_h_flag_rep;
1606 Phi_h_flag_rep.reset (
new vector_Type ( *Phi_h_flag, Repeated ) );
1608 vectorPtr_Type Q_hat_vec;
1609 Q_hat_vec.reset (
new vector_Type ( M_velocityFESpaceScalar->map() ) );
1612 vectorPtr_Type ones_vec;
1613 ones_vec.reset (
new vector_Type ( M_velocityFESpaceScalar->map() ) );
1618 using namespace ExpressionAssembly;
1619 QuadratureBoundary myBDQR (buildTetraBDQR (quadRuleTria6pt) );
1621 boundary (M_fespaceUETA_scalar->mesh(), flag),
1623 M_fespaceUETA_scalar,
1624 value(M_fespaceUETA_scalar, *Phi_h_flag_rep)*phi_i
1629 Q_hat = Q_hat_vec->dot(*ones_vec);
1631 V_hat_x.reset (
new vector_Type ( *Phi_h_flag ) );
1632 V_hat_y.reset (
new vector_Type ( *Phi_h_flag ) );
1633 V_hat_z.reset (
new vector_Type ( *Phi_h_flag ) );
1640 void NavierStokesSolverBlocks::solveLaplacian(
const UInt& , bcPtr_Type& bc_laplacian, vectorPtr_Type& laplacianSolution)
1643 bc_laplacian->bcUpdate ( *M_velocityFESpaceScalar->mesh(), M_velocityFESpaceScalar->feBd(), M_velocityFESpaceScalar->dof() );
1645 vectorPtr_Type Phi_h;
1646 Phi_h.reset (
new vector_Type ( M_velocityFESpaceScalar->map() ) );
1649 vectorPtr_Type rhs_laplacian_repeated(
new vector_Type (M_velocityFESpaceScalar->map(), Repeated ) );
1650 rhs_laplacian_repeated->zero();
1652 std::shared_ptr< MatrixEpetra<Real> > Laplacian;
1653 Laplacian.reset (
new MatrixEpetra<Real> ( M_velocityFESpaceScalar->map() ) );
1657 using namespace ExpressionAssembly;
1660 elements(M_fespaceUETA_scalar->mesh()),
1661 M_velocityFESpaceScalar->qr(),
1662 M_fespaceUETA_scalar,
1663 M_fespaceUETA_scalar,
1664 dot( grad(phi_i) , grad(phi_j) )
1669 using namespace ExpressionAssembly;
1672 elements(M_fespaceUETA_scalar->mesh()),
1673 M_velocityFESpaceScalar->qr(),
1674 M_fespaceUETA_scalar,
1676 ) >> rhs_laplacian_repeated;
1680 rhs_laplacian_repeated->globalAssemble();
1682 vectorPtr_Type rhs_laplacian(
new vector_Type (*rhs_laplacian_repeated, Unique ) );
1684 bcManage ( *Laplacian, *rhs_laplacian, *M_velocityFESpaceScalar->mesh(), M_velocityFESpaceScalar->dof(), *bc_laplacian, M_velocityFESpaceScalar->feBd(), 1.0, 0.0 );
1685 Laplacian->globalAssemble();
1687 Teuchos::RCP< Teuchos::ParameterList > belosList = Teuchos::rcp (
new Teuchos::ParameterList );
1688 belosList = Teuchos::getParametersFromXmlFile (
"SolverParamListLaplacian.xml" );
1691 prec_Type* precRawPtr;
1692 basePrecPtr_Type precPtr;
1693 precRawPtr =
new prec_Type;
1694 precRawPtr->setDataFromGetPot ( M_dataFile,
"prec" );
1695 precPtr.reset ( precRawPtr );
1698 LinearSolver solver;
1699 solver.setCommunicator ( M_comm );
1700 solver.setParameters ( *belosList );
1701 solver.setPreconditioner ( precPtr );
1704 solver.setOperator ( Laplacian );
1705 solver.setRightHandSide ( rhs_laplacian );
1706 solver.solve ( Phi_h );
1708 *laplacianSolution = *Phi_h;
1712 NavierStokesSolverBlocks::setupPostProc( )
1714 M_postProcessing.reset (
new PostProcessingBoundary<mesh_Type> ( M_velocityFESpace->mesh(),
1715 &M_velocityFESpace->feBd(),
1716 &M_velocityFESpace->dof(),
1717 &M_pressureFESpace->feBd(),
1718 &M_pressureFESpace->dof(),
1719 *M_monolithicMap ) );
1724 NavierStokesSolverBlocks::flux (
const markerID_Type& flag,
const vector_Type& velocity )
1726 vector_Type velocity_rep ( velocity, Repeated );
1727 return M_postProcessing->flux ( velocity_rep, flag );
1731 NavierStokesSolverBlocks::area (
const markerID_Type& flag )
1733 return M_postProcessing->measure ( flag );
1737 NavierStokesSolverBlocks::geometricCenter (
const markerID_Type& flag )
1739 return M_postProcessing->geometricCenter ( flag );
1743 NavierStokesSolverBlocks::normal (
const markerID_Type& flag )
1745 return M_postProcessing->normal ( flag );
1749 NavierStokesSolverBlocks::pres (
const markerID_Type& flag,
const vector_Type& pressure )
1751 vector_Type pressure_rep ( pressure, Repeated );
1752 return M_postProcessing->average ( pressure_rep, flag, 1 ) [0];
1756 NavierStokesSolverBlocks::setBoundaryConditions (
const bcPtr_Type& bc )
1758 M_bc_sol.reset (
new BCHandler ( ) );
1759 M_bc_res_essential.reset (
new BCHandler ( ) );
1760 M_bc_res_natural.reset (
new BCHandler ( ) );
1762 for ( std::vector<BCBase>::iterator it = bc->begin(); it != bc->end(); it++ )
1764 if ( it->type() > 3 )
1766 M_bc_sol->addBC( *it );
1767 M_bc_res_essential->addBC( *it );
1769 else if ( it->type() == 0 )
1771 M_bc_res_natural->addBC( *it );
SignFunction(const SignFunction &)
std::shared_ptr< Epetra_Comm > comm
return_Type operator()(const Real &a)
SignFunction(const std::shared_ptr< Epetra_Comm > &communicator)
double Real
Generic real data.