50 #include <Epetra_ConfigDefs.h> 52 #include <Epetra_MpiComm.h> 54 #include <Epetra_SerialComm.h> 57 #include <lifev/core/LifeV.hpp> 58 #include <lifev/core/util/LifeChronoManager.hpp> 60 #include <lifev/core/mesh/MeshPartitioner.hpp> 61 #include <lifev/core/mesh/RegionMesh3DStructured.hpp> 62 #include <lifev/core/mesh/RegionMesh.hpp> 63 #include <lifev/core/array/MatrixEpetra.hpp> 65 #include <lifev/core/fem/BCManage.hpp> 66 #include <lifev/eta/fem/ETFESpace.hpp> 67 #include <lifev/eta/expression/BuildGraph.hpp> 68 #include <lifev/eta/expression/Integrate.hpp> 69 #include <Epetra_FECrsGraph.h> 71 #include <Teuchos_ParameterList.hpp> 72 #include <Teuchos_XMLParameterListHelpers.hpp> 73 #include <Teuchos_RCP.hpp> 74 #include <lifev/core/algorithm/LinearSolver.hpp> 75 #include <lifev/core/algorithm/PreconditionerIfpack.hpp> 77 #include <lifev/core/filter/ExporterHDF5.hpp> 79 #include <lifev/eta/examples/laplacian/laplacianFunctor.hpp> 80 #include <lifev/core/mesh/RegionMesh.hpp> 81 #include <lifev/core/mesh/ElementShapes.hpp> 82 #include <lifev/core/mesh/MeshEntityContainer.hpp> 83 #include <lifev/core/mesh/MeshData.hpp> 84 #include <lifev/core/mesh/MeshVolumeSubdivision.hpp> 86 using namespace LifeV;
111 if( z<0.5 && y < 0.5 )
return 1.0;
117 if( z>0.5 && y < 0.5 )
return 1.0;
124 if( z<0.5 && y > 0.5 )
return 1.0;
130 if( z>0.5 && y > 0.5 )
return 1.0;
142 if( z<0.5 && y < 0.5 )
return mu1;
143 if( z>0.5 && y < 0.5 )
return mu2;
144 if( z<0.5 && y > 0.5 )
return mu3;
150 int main (
int argc,
char** argv )
155 MPI_Init ( &argc, &argv );
156 std::shared_ptr< Epetra_Comm > Comm (
new Epetra_MpiComm ( MPI_COMM_WORLD ) );
158 std::shared_ptr< Epetra_Comm > Comm (
new Epetra_SerialComm );
162 GetPot command_line ( argc, argv );
163 const std::string dataFileName = command_line.follow (
"data", 2,
"-f",
"--file" );
164 GetPot dataFile ( dataFileName );
166 const bool verbose ( Comm->MyPID() == 0 );
170 std::cout <<
"-- Building and partitioning the mesh... " << std::flush;
178 typedef RegionMesh< LinearTetra > mesh_Type;
180 std::shared_ptr< mesh_Type > fullMeshPtr (
new mesh_Type ( Comm ) );
183 meshData.setup ( dataFile,
"mesh");
184 readMesh (*fullMeshPtr, meshData);
186 std::shared_ptr< mesh_Type > localMeshPtr;
188 MeshPartitioner< mesh_Type > meshPart;
190 meshPart.doPartition ( fullMeshPtr, Comm );
191 localMeshPtr = meshPart.meshPartition();
198 std::cout <<
" done" << std::endl;
205 typedef FESpace< mesh_Type, MapEpetra > uSpaceStd_Type;
206 typedef std::shared_ptr< uSpaceStd_Type > uSpaceStdPtr_Type;
208 typedef ETFESpace< mesh_Type, MapEpetra, 3, 1 > uSpaceETA_Type;
209 typedef std::shared_ptr< uSpaceETA_Type > uSpaceETAPtr_Type;
211 typedef FESpace<mesh_Type, MapEpetra>::function_Type function_Type;
215 std::cout <<
"-- Building finite elements spaces... " << std::flush;
219 uSpaceStdPtr_Type uFESpace (
new uSpaceStd_Type ( localMeshPtr, dataFile(
"finite_element/degree",
"P1" ), 1, Comm ) );
220 uSpaceETAPtr_Type ETuFESpace (
new uSpaceETA_Type ( localMeshPtr, & ( uFESpace->refFE() ), & ( uFESpace->fe().geoMap() ), Comm ) );
224 std::cout <<
" done. " <<
" (Dofs: " << uFESpace->dof().numTotalDof() <<
")" << std::endl;
227 typedef MatrixEpetra< Real > matrix_Type;
228 typedef std::shared_ptr< MatrixEpetra< Real > > matrixPtr_Type;
229 typedef VectorEpetra vector_Type;
230 typedef std::shared_ptr<VectorEpetra> vectorPtr_Type;
234 std::cout <<
" done " << std::endl;
240 std::cout <<
"-- Subdividing the mesh... " << std::flush;
243 int numSubregions = dataFile(
"physicalParameters/numSubregions", 1 );
245 typedef LifeV::MeshVolumeSubdivision<RegionMesh<LinearTetra> > meshSub_Type;
246 typedef std::shared_ptr<meshSub_Type> meshSubPtr_Type;
250 Epetra_IntSerialDenseVector regions(numSubregions);
257 meshSubPtr_Type meshSub;
258 meshSub.reset(
new meshSub_Type( Comm, localMeshPtr, regions, numSubregions ) );
260 meshSub->makeSubDivision();
266 std::cout <<
"-- Assembling the Laplace submatrices... " << std::flush;
269 matrixPtr_Type systemMatrixMeshSub1(
new matrix_Type( ETuFESpace->map(), 100 ) );
270 matrixPtr_Type systemMatrixMeshSub2(
new matrix_Type( ETuFESpace->map(), 100 ) );
271 matrixPtr_Type systemMatrixMeshSub3(
new matrix_Type( ETuFESpace->map(), 100 ) );
272 matrixPtr_Type systemMatrixMeshSub4(
new matrix_Type( ETuFESpace->map(), 100 ) );
275 using namespace ExpressionAssembly;
279 std::cout <<
"Building with MeshSub" << std::endl;
282 integrate ( elements ( localMeshPtr, meshSub->getFlag(0),
283 meshSub->getNumElements( 0 ), meshSub->getSubmesh( 0 ),
288 value(1.0) * dot( grad( phi_j ), grad( phi_i ) )
290 >> systemMatrixMeshSub1;
292 integrate ( elements ( localMeshPtr, meshSub->getFlag(1),
293 meshSub->getNumElements( 1 ), meshSub->getSubmesh( 1 ),
298 value(1.0) * dot( grad( phi_j ), grad( phi_i ) )
300 >> systemMatrixMeshSub2;
302 integrate ( elements ( localMeshPtr, meshSub->getFlag(2),
303 meshSub->getNumElements( 2 ), meshSub->getSubmesh( 2 ),
308 value(1.0) * dot( grad( phi_j ), grad( phi_i ) )
310 >> systemMatrixMeshSub3;
312 integrate ( elements ( localMeshPtr, meshSub->getFlag(3),
313 meshSub->getNumElements( 3 ), meshSub->getSubmesh( 3 ),
318 value(1.0) * dot( grad( phi_j ), grad( phi_i ) )
320 >> systemMatrixMeshSub4;
324 systemMatrixMeshSub1->globalAssemble();
325 systemMatrixMeshSub2->globalAssemble();
326 systemMatrixMeshSub3->globalAssemble();
327 systemMatrixMeshSub4->globalAssemble();
330 mu1 = dataFile(
"physicalParameters/mu1", 1 );
331 mu2 = dataFile(
"physicalParameters/mu2", 1 );
332 mu3 = dataFile(
"physicalParameters/mu3", 1 );
333 mu4 = dataFile(
"physicalParameters/mu4", 1 );
335 matrixPtr_Type matrixMeshSubFull(
new matrix_Type( ETuFESpace->map(), 100 ) );
337 *matrixMeshSubFull += ( *systemMatrixMeshSub1 ) * mu1;
338 *matrixMeshSubFull += ( *systemMatrixMeshSub2 ) * mu2;
339 *matrixMeshSubFull += ( *systemMatrixMeshSub3 ) * mu3;
340 *matrixMeshSubFull += ( *systemMatrixMeshSub4 ) * mu4;
344 std::cout <<
" done" << std::endl;
351 vectorPtr_Type rhsLap;
352 vectorPtr_Type solutionLap;
354 rhsLap.reset (
new vector_Type ( uFESpace->map(), Unique ) );
355 solutionLap.reset (
new vector_Type ( uFESpace->map(), Unique ) );
360 std::shared_ptr<laplacianFunctor< Real > > laplacianSourceFunctor (
new laplacianFunctor< Real >( sourceFunction ) );
363 using namespace ExpressionAssembly;
366 elements ( localMeshPtr ),
369 eval(laplacianSourceFunctor, X) * phi_i
376 ExporterHDF5< mesh_Type > exporter ( dataFile,
"exporter" );
377 exporter.setMeshProcId( localMeshPtr, Comm->MyPID() );
378 exporter.setPrefix(
"mesh_volume_subdivision_laplace" );
379 exporter.setPostDir(
"./" );
381 exporter.addVariable ( ExporterData< mesh_Type >::ScalarField,
"temperature", uFESpace, solutionLap, UInt ( 0 ) );
389 std::cout <<
"-- Setting boundary conditions... " << std::flush;
394 BCFunctionBase ZeroBC ( zeroFunction );
396 bcHandler.addBC(
"Back", BACK, Essential, Full, ZeroBC, 1 );
397 bcHandler.addBC(
"Left", LEFT, Essential, Full, ZeroBC, 1 );
398 bcHandler.addBC(
"Top", TOP, Essential, Full, ZeroBC, 1 );
401 bcHandler.addBC(
"Front", FRONT, Essential, Full, ZeroBC, 1 );
402 bcHandler.addBC(
"Right", RIGHT, Essential, Full, ZeroBC, 1 );
403 bcHandler.addBC(
"Bottom", BOTTOM, Essential, Full, ZeroBC, 1 );
405 bcHandler.bcUpdate( *uFESpace->mesh(), uFESpace->feBd(), uFESpace->dof() );
407 matrixMeshSubFull->globalAssemble();
408 rhsLap->globalAssemble();
410 bcManage ( *matrixMeshSubFull, *rhsLap, *uFESpace->mesh(), uFESpace->dof(), bcHandler, uFESpace->feBd(), 1.0, 0.0 );
414 std::cout <<
" done " << std::endl;
421 typedef LinearSolver::SolverType solver_Type;
423 typedef LifeV::Preconditioner basePrec_Type;
424 typedef std::shared_ptr<basePrec_Type> basePrecPtr_Type;
425 typedef PreconditionerIfpack prec_Type;
426 typedef std::shared_ptr<prec_Type> precPtr_Type;
431 std::cout <<
"-- Setting up the solver ... " << std::flush;
434 LinearSolver linearSolver ( Comm );
435 linearSolver.setOperator ( matrixMeshSubFull );
437 Teuchos::RCP< Teuchos::ParameterList > aztecList = Teuchos::rcp (
new Teuchos::ParameterList );
438 aztecList = Teuchos::getParametersFromXmlFile (
"SolverParamList.xml" );
440 linearSolver.setParameters ( *aztecList );
442 prec_Type* precRawPtr;
443 basePrecPtr_Type precPtr;
444 precRawPtr =
new prec_Type;
445 precRawPtr->setDataFromGetPot ( dataFile,
"prec" );
446 precPtr.reset ( precRawPtr );
448 linearSolver.setPreconditioner ( precPtr );
453 std::cout <<
" done" << std::endl;
463 std::cout <<
"-- Solving problem ... " << std::flush;
466 linearSolver.setRightHandSide( rhsLap );
467 linearSolver.solve( solutionLap );
469 exporter.postProcess( 0.0 );
473 matrixPtr_Type standardSystemMatrix1(
new matrix_Type( ETuFESpace->map(), 100 ) );
474 matrixPtr_Type standardSystemMatrix2(
new matrix_Type( ETuFESpace->map(), 100 ) );
475 matrixPtr_Type standardSystemMatrix3(
new matrix_Type( ETuFESpace->map(), 100 ) );
476 matrixPtr_Type standardSystemMatrix4(
new matrix_Type( ETuFESpace->map(), 100 ) );
477 matrixPtr_Type systemMatrixTotal(
new matrix_Type( ETuFESpace->map(), 100 ) );
479 std::shared_ptr<laplacianFunctor< Real > > laplacianDiffusionFunctor1 (
new laplacianFunctor< Real >( diffusion4Function1 ) );
480 std::shared_ptr<laplacianFunctor< Real > > laplacianDiffusionFunctor2 (
new laplacianFunctor< Real >( diffusion4Function2 ) );
481 std::shared_ptr<laplacianFunctor< Real > > laplacianDiffusionFunctor3 (
new laplacianFunctor< Real >( diffusion4Function3 ) );
482 std::shared_ptr<laplacianFunctor< Real > > laplacianDiffusionFunctor4 (
new laplacianFunctor< Real >( diffusion4Function4 ) );
483 std::shared_ptr<laplacianFunctor< Real > > laplacianDiffusionFunctorTotal (
new laplacianFunctor< Real >( diffusion4FunctionTotal ) );
486 using namespace ExpressionAssembly;
488 elements ( localMeshPtr ),
492 eval(laplacianDiffusionFunctor1, X) * dot ( grad ( phi_i ) , grad ( phi_j ) )
494 >> standardSystemMatrix1;
497 elements ( localMeshPtr ),
501 eval(laplacianDiffusionFunctor2, X) * dot ( grad ( phi_i ) , grad ( phi_j ) )
503 >> standardSystemMatrix2;
506 elements ( localMeshPtr ),
510 eval(laplacianDiffusionFunctor3, X) * dot ( grad ( phi_i ) , grad ( phi_j ) )
512 >> standardSystemMatrix3;
515 elements ( localMeshPtr ),
519 eval(laplacianDiffusionFunctor4, X) * dot ( grad ( phi_i ) , grad ( phi_j ) )
521 >> standardSystemMatrix4;
524 elements ( localMeshPtr ),
528 eval(laplacianDiffusionFunctorTotal, X) * dot ( grad ( phi_i ) , grad ( phi_j ) )
530 >> systemMatrixTotal;
534 std::stringstream convertNumProc, convertProc;
536 convertNumProc << Comm->NumProc();
537 convertProc << Comm->MyPID();
539 bcManage ( *standardSystemMatrix1, *rhsLap, *uFESpace->mesh(), uFESpace->dof(), bcHandler, uFESpace->feBd(), 1.0, 0.0 );
540 bcManage ( *standardSystemMatrix2, *rhsLap, *uFESpace->mesh(), uFESpace->dof(), bcHandler, uFESpace->feBd(), 1.0, 0.0 );
541 bcManage ( *standardSystemMatrix3, *rhsLap, *uFESpace->mesh(), uFESpace->dof(), bcHandler, uFESpace->feBd(), 1.0, 0.0 );
542 bcManage ( *standardSystemMatrix4, *rhsLap, *uFESpace->mesh(), uFESpace->dof(), bcHandler, uFESpace->feBd(), 1.0, 0.0 );
543 bcManage ( *systemMatrixTotal, *rhsLap, *uFESpace->mesh(), uFESpace->dof(), bcHandler, uFESpace->feBd(), 1.0, 0.0 );
545 bcManage ( *systemMatrixMeshSub1, *rhsLap, *uFESpace->mesh(), uFESpace->dof(), bcHandler, uFESpace->feBd(), 1.0, 0.0 );
546 bcManage ( *systemMatrixMeshSub2, *rhsLap, *uFESpace->mesh(), uFESpace->dof(), bcHandler, uFESpace->feBd(), 1.0, 0.0 );
547 bcManage ( *systemMatrixMeshSub3, *rhsLap, *uFESpace->mesh(), uFESpace->dof(), bcHandler, uFESpace->feBd(), 1.0, 0.0 );
548 bcManage ( *systemMatrixMeshSub4, *rhsLap, *uFESpace->mesh(), uFESpace->dof(), bcHandler, uFESpace->feBd(), 1.0, 0.0 );
550 standardSystemMatrix1->globalAssemble();
551 standardSystemMatrix2->globalAssemble();
552 standardSystemMatrix3->globalAssemble();
553 standardSystemMatrix4->globalAssemble();
554 systemMatrixTotal->globalAssemble();
572 linearSolver.setOperator ( systemMatrixTotal );
573 linearSolver.setPreconditioner ( precPtr );
574 linearSolver.solve( solutionLap );
576 exporter.postProcess( 1.0 );
584 exporter.closeFile();
590 return ( EXIT_SUCCESS );
int main(int argc, char **argv)
Real diffusion4Function4(const Real &, const Real &x, const Real &y, const Real &z, const ID &)
Real diffusion4FunctionTotal(const Real &, const Real &x, const Real &y, const Real &z, const ID &)
Real diffusion4Function1(const Real &, const Real &x, const Real &y, const Real &z, const ID &)
Real diffusion4Function3(const Real &, const Real &x, const Real &y, const Real &z, const ID &)
Real sourceFunction(const Real &, const Real &x, const Real &y, const Real &z, const ID &)
double Real
Generic real data.
Real zeroFunction(const Real &, const Real &, const Real &, const Real &, const ID &)
Real diffusion4Function2(const Real &, const Real &x, const Real &y, const Real &z, const ID &)