39 #include <lifev/core/algorithm/PreconditionerIfpack.hpp> 40 #include <lifev/core/algorithm/PreconditionerML.hpp> 42 #include <lifev/core/util/LifeChrono.hpp> 43 #include <lifev/core/array/MatrixEpetraStructured.hpp> 44 #include <lifev/core/array/MatrixEpetraStructuredView.hpp> 45 #include <lifev/core/array/MatrixEpetraStructuredUtility.hpp> 51 PreconditionerComposition ( comm ),
55 M_SIMPLEType (
"SIMPLE" )
68 const std::string& section,
69 const std::string& subsection )
71 const bool verbose ( M_comm->MyPID() == 0 );
73 bool displayList = dataFile ( ( section +
"/displayList" ).data(),
false);
75 std::string precType = dataFile ( ( section +
"/prectype" ).data(),
"SIMPLE" );
76 list.set (
"prectype", precType );
77 std::string SIMPLEType = dataFile ( ( section +
"/" + subsection +
"/SIMPLE_type" ).data(),
"SIMPLE" );
79 std::string fluidPrec = dataFile ( ( section +
"/" + subsection +
"/subprecs/fluid_prec" ).data(),
"ML" );
80 list.set (
"subprecs: fluid prec", fluidPrec );
81 std::string fluidPrecDataSection = dataFile ( ( section +
"/" + subsection +
"/subprecs/fluid_prec_data_section" ).data(),
"" );
82 list.set (
"subprecs: fluid prec data section", ( fluidPrecDataSection ).data() );
84 std::string schurPrec = dataFile ( ( section +
"/" + subsection +
"/subprecs/schur_prec" ).data(),
"ML" );
85 list.set (
"subprecs: Schur prec", schurPrec );
86 std::string schurPrecDataSection = dataFile ( ( section +
"/" + subsection +
"/subprecs/schur_prec_data_section" ).data(),
"" );
87 list.set (
"subprecs: Schur prec data section", ( schurPrecDataSection ).data() );
89 list.set (
"SIMPLE Type", SIMPLEType );
91 if ( displayList && verbose )
93 std::cout <<
"SIMPLE parameters list:" << std::endl;
94 std::cout <<
"-----------------------------" << std::endl;
95 list.print ( std::cout );
96 std::cout <<
"-----------------------------" << std::endl;
111 std::cout <<
"You must specified manually the pointers to the FESpaces" << std::endl;
116 this->resetPreconditioner();
118 const bool verbose ( M_comm->MyPID() == 0 );
120 std::vector<UInt> blockNumRows ( 2, 0 );
121 blockNumRows[0] = M_velocityBlockSize;
122 blockNumRows[1] = M_pressureBlockSize;
123 std::vector<UInt> blockNumColumns ( blockNumRows );
125 const bool inversed (
true );
126 const bool notInversed (
false );
127 const bool notTransposed (
false );
141 std::cout <<
" >Getting the structure of A... ";
146 F.setup ( 0, 0, blockNumRows[0], blockNumColumns[0], oper.get() );
149 Bt.setup ( 0, blockNumColumns[0], blockNumRows[0], blockNumColumns[1], oper.get() );
152 B.setup ( blockNumRows[0], 0, blockNumRows[1], blockNumColumns[0], oper.get() );
155 C.setup ( blockNumRows[0], blockNumColumns[0], blockNumRows[1], blockNumColumns[1], oper.get() );
159 std::cout <<
" done in " << timer.diff() <<
" s." << std::endl;
181 std::cout <<
" Block 1 (F)" << std::endl;
184 std::shared_ptr<matrixBlock_Type> P1a (
new matrixBlock_Type ( map ) );
185 P1a->setBlockStructure ( blockNumRows, blockNumColumns );
186 P1a->blockView ( 0, 0, B11 );
187 P1a->blockView ( 1, 1, B22 );
188 MatrixEpetraStructuredUtility::copyBlock ( F, B11 );
189 MatrixEpetraStructuredUtility::createIdentityBlock ( B22 );
190 P1a->globalAssemble();
191 std::shared_ptr<matrix_Type> p1a = P1a;
192 superPtr_Type precForBlock1 ( PRECFactory::instance().createObject ( M_fluidPrec ) );
193 precForBlock1->setDataFromGetPot ( M_dataFile, M_fluidDataSection );
199 this->pushBack ( p1a, precForBlock1, notInversed, notTransposed );
202 std::cout <<
" done in " << timer.diff() <<
" s." << std::endl;
211 std::cout <<
" Block 1 (B)" << std::endl;
214 std::shared_ptr<matrixBlock_Type> P1b (
new matrixBlock_Type ( map ) );
215 P1b->setBlockStructure ( blockNumRows, blockNumColumns );
216 P1b->blockView ( 0, 0, B11 );
217 P1b->blockView ( 1, 0, B21 );
218 P1b->blockView ( 1, 1, B22 );
219 MatrixEpetraStructuredUtility::copyBlock ( B, B21 );
221 MatrixEpetraStructuredUtility::createIdentityBlock ( B11 );
222 MatrixEpetraStructuredUtility::createIdentityBlock ( B22 );
223 P1b->globalAssemble();
224 std::shared_ptr<matrix_Type> p1b = P1b;
225 this->pushBack ( p1b, inversed, notTransposed );
228 std::cout <<
" done in " << timer.diff() <<
" s." << std::endl;
237 std::cout <<
" Block 1 (Schur)" << std::endl;
240 std::shared_ptr<matrixBlock_Type> P1c (
new matrixBlock_Type ( map ) );
242 std::shared_ptr<matrixBlock_Type> BBlockMat (
new matrixBlock_Type ( map ) );
243 BBlockMat->setBlockStructure ( blockNumRows, blockNumColumns );
244 BBlockMat->blockView ( 1, 0, B21 );
245 MatrixEpetraStructuredUtility::copyBlock ( B, B21 );
246 BBlockMat->globalAssemble();
247 std::shared_ptr<matrixBlock_Type> invDBlockMat (
new matrixBlock_Type ( map ) );
248 invDBlockMat->setBlockStructure ( blockNumRows, blockNumColumns );
249 invDBlockMat->blockView ( 0, 0, B11 );
250 if ( M_SIMPLEType ==
"SIMPLE" )
252 MatrixEpetraStructuredUtility::createInvDiagBlock ( F, B11 );
254 else if ( M_SIMPLEType ==
"SIMPLEC" )
256 MatrixEpetraStructuredUtility::createInvLumpedBlock ( F, B11 );
258 *invDBlockMat *= -1.0;
259 invDBlockMat->globalAssemble();
260 std::shared_ptr<matrixBlock_Type> tmpResultMat (
new matrixBlock_Type ( map ) );
261 BBlockMat->multiply (
false,
262 *invDBlockMat,
false,
263 *tmpResultMat,
true );
265 invDBlockMat.reset();
266 std::shared_ptr<matrixBlock_Type> BtBlockMat (
new matrixBlock_Type ( map ) );
267 BtBlockMat->setBlockStructure ( blockNumRows, blockNumColumns );
268 BtBlockMat->blockView ( 0, 1, B12 );
269 MatrixEpetraStructuredUtility::copyBlock ( Bt, B12 );
270 BtBlockMat->globalAssemble();
271 tmpResultMat->multiply (
false,
275 tmpResultMat.reset();
277 P1c->setBlockStructure ( blockNumRows, blockNumColumns );
278 P1c->blockView ( 0, 0, B11 );
279 MatrixEpetraStructuredUtility::createIdentityBlock ( B11 );
280 P1c->globalAssemble();
281 std::shared_ptr<matrix_Type> p1c = P1c;
282 superPtr_Type precForBlock2 ( PRECFactory::instance().createObject ( M_schurPrec ) );
283 precForBlock2->setDataFromGetPot ( M_dataFile, M_schurDataSection );
284 this->pushBack ( p1c, precForBlock2, notInversed, notTransposed );
287 std::cout <<
" done in " << timer.diff() <<
" s." << std::endl;
297 std::cout <<
" Block 2 (D^-1,alpha I)" << std::endl;
300 std::shared_ptr<matrixBlock_Type> P2a (
new matrixBlock_Type ( map ) );
302 P2a->setBlockStructure ( blockNumRows, blockNumColumns );
303 P2a->blockView ( 0, 0, B11 );
304 P2a->blockView ( 1, 1, B22 );
305 if ( M_SIMPLEType ==
"SIMPLE" )
307 MatrixEpetraStructuredUtility::createDiagBlock ( F, B11 );
309 else if ( M_SIMPLEType ==
"SIMPLEC" )
311 MatrixEpetraStructuredUtility::createLumpedBlock ( F, B11 );
313 MatrixEpetraStructuredUtility::createScalarBlock ( B22, 1 / M_dampingFactor );
314 P2a->globalAssemble();
315 std::shared_ptr<matrix_Type> p2a = P2a;
316 this->pushBack ( p2a, inversed, notTransposed );
319 std::cout <<
" done in " << timer.diff() <<
" s." << std::endl;
328 std::cout <<
" Block 2 (Bt)" << std::endl;
331 std::shared_ptr<matrixBlock_Type> P2b (
new matrixBlock_Type ( map ) );
332 P2b->setBlockStructure ( blockNumRows, blockNumColumns );
333 P2b->blockView ( 0, 0, B11 );
334 P2b->blockView ( 0, 1, B12 );
335 P2b->blockView ( 1, 1, B22 );
336 MatrixEpetraStructuredUtility::copyBlock ( Bt, B12 );
338 MatrixEpetraStructuredUtility::createIdentityBlock ( B11 );
339 MatrixEpetraStructuredUtility::createIdentityBlock ( B22 );
340 P2b->globalAssemble();
341 std::shared_ptr<matrix_Type> p2b = P2b;
342 this->pushBack ( p2b, inversed, notTransposed );
345 std::cout <<
" done in " << timer.diff() <<
" s." << std::endl;
354 std::cout <<
" Block2 (D)" << std::endl;
357 std::shared_ptr<matrixBlock_Type> P2c (
new matrixBlock_Type ( map ) );
359 P2c->setBlockStructure ( blockNumRows, blockNumColumns );
360 P2c->blockView ( 0, 0, B11 );
361 P2c->blockView ( 1, 1, B22 );
362 if ( M_SIMPLEType ==
"SIMPLE" )
364 MatrixEpetraStructuredUtility::createInvDiagBlock ( F, B11 );
366 else if ( M_SIMPLEType ==
"SIMPLEC" )
368 MatrixEpetraStructuredUtility::createInvLumpedBlock ( F, B11 );
370 MatrixEpetraStructuredUtility::createIdentityBlock ( B22 );
371 P2c->globalAssemble();
372 std::shared_ptr<matrix_Type> p2c = P2c;
373 this->pushBack ( p2c, inversed, notTransposed );
376 std::cout <<
" done in " << timer.diff() <<
" s." << std::endl;
381 if ( verbose ) std::cout <<
" >All the blocks are built" << std::endl
383 return ( EXIT_SUCCESS );
400 const std::string& section )
402 M_dataFile = dataFile;
403 this->createParametersList ( M_list, dataFile, section,
"SIMPLE" );
404 this->setParameters ( M_list );
410 M_precType = list.get (
"prectype",
"SIMPLE" );
411 M_SIMPLEType = list.get (
"SIMPLE Type",
"SIMPLE" );
413 M_fluidPrec = list.get (
"subprecs: fluid prec",
"ML" );
414 M_fluidDataSection = list.get (
"subprecs: fluid prec data section",
"" );
416 M_schurPrec = list.get (
"subprecs: Schur prec",
"ML" );
417 M_schurDataSection = list.get (
"subprecs: Schur prec data section",
"" );
426 M_velocityBlockSize = uFESpace->fieldDim() * uFESpace->dof().numTotalDof();
427 M_pressureBlockSize = pFESpace->dof().numTotalDof();
std::shared_ptr< FESpace< mesh_Type, map_Type > > FESpacePtr_Type
FESpacePtr_Type M_uFESpace
std::shared_ptr< super_Type > superPtr_Type
void start()
Start the timer.
PreconditionerSIMPLE(std::shared_ptr< Epetra_Comm > comm=std::shared_ptr< Epetra_Comm >(new Epetra_MpiComm(MPI_COMM_WORLD)))
default constructor
void setDataFromGetPot(const GetPot &dataFile, const std::string §ion)
Setter using GetPot.
Teuchos::ParameterList list_Type
bool M_preconditionerCreated
void updateInverseJacobian(const UInt &iQuadPt)
MatrixEpetraStructuredView< Real > matrixBlockView_Type
double condest()
Return an estimation of the conditionement number of the preconditioner.
int buildPreconditioner(matrixPtr_Type &A)
Build the preconditioner.
int numBlocksRows() const
FESpacePtr_Type M_pFESpace
double Real
Generic real data.
void createParametersList(list_Type &list, const GetPot &dataFile, const std::string §ion, const std::string &subsection="SIMPLE")
Create the list of parameters of the preconditioner.
void setFESpace(FESpacePtr_Type uFESpace, FESpacePtr_Type pFESpace)
Setter for the FESpace.
int numBlocksColumns() const
virtual void setParameters(Teuchos::ParameterList &list)
Method to setup the solver using Teuchos::ParameterList.
void setDampingFactor(const Real &dampingFactor)
Setter for the damping factor.
std::shared_ptr< matrix_Type > matrixPtr_Type
virtual ~PreconditionerSIMPLE()
constructor from matrix A.