void postProcessFluxesPressures( OseenSolver< mesh_Type >& nssolver, BCHandler& bcHandler, const LifeV::Real& t, bool _verbose ) { LifeV::Real Q, P; UInt flag; for ( BCHandler::bcBaseIterator_Type it = bcHandler.begin(); it != bcHandler.end(); ++it ) { flag = it->flag(); Q = nssolver.flux(flag); P = nssolver.pressure(flag); if ( _verbose ) { std::ofstream outfile; std::stringstream filenamess; std::string filename; // file name contains the label filenamess << flag; // writing down fluxes filename = "flux_label" + filenamess.str() + ".m"; outfile.open(filename.c_str(),std::ios::app); outfile << Q << " " << t << "\n"; outfile.close(); // writing down pressures filename = "pressure_label" + filenamess.str() + ".m"; outfile.open(filename.c_str(),std::ios::app); outfile << P << " " << t << "\n"; outfile.close(); // reset ostringstream filenamess.str(""); } } }
int main( int argc, char* argv[] ) { #ifdef HAVE_MPI MPI_Init(&argc, &argv); #endif { // needed to properly destroy all objects inside before mpi finalize #ifdef HAVE_MPI boost::shared_ptr<Epetra_Comm> Comm(new Epetra_MpiComm(MPI_COMM_WORLD)); ASSERT ( Comm->NumProc() < 2, "The test does not run in parallel." ); #else boost::shared_ptr<Epetra_Comm> Comm(new Epetra_SerialComm); #endif typedef RegionMesh<LinearLine> mesh_Type; typedef MatrixEpetra<Real> matrix_Type; typedef VectorEpetra vector_Type; typedef FESpace<mesh_Type, MapEpetra> feSpace_Type; typedef boost::shared_ptr<feSpace_Type> feSpacePtr_Type; const bool verbose(Comm->MyPID()==0); // Read first the data needed if (verbose) std::cout << " -- Reading the data ... " << std::flush; GetPot dataFile( "data" ); if (verbose) std::cout << " done ! " << std::endl; // Build the mesh if (verbose) std::cout << " -- Reading the mesh ... " << std::flush; MeshData meshData(dataFile, "mesh"); boost::shared_ptr< mesh_Type > meshPtr( new mesh_Type( Comm ) ); // Set up the structured mesh regularMesh1D( *meshPtr, 0, dataFile( "mesh/n", 20 ), dataFile( "mesh/verbose", false ), dataFile( "mesh/length", 1. ), dataFile( "mesh/origin", 0. ) ); if (verbose) std::cout << " done ! " << std::endl; // Build the FESpaces if (verbose) std::cout << " -- Building FESpaces ... " << std::flush; feSpacePtr_Type uFESpace( new feSpace_Type( meshPtr, feSegP1, quadRuleSeg1pt, quadRuleNode1pt, 1, Comm ) ); if (verbose) std::cout << " done ! " << std::endl; if (verbose) std::cout << " ---> Dofs: " << uFESpace->dof().numTotalDof() << std::endl; // Build the assembler and the matrices if (verbose) std::cout << " -- Building assembler ... " << std::flush; ADRAssembler<mesh_Type,matrix_Type,vector_Type> adrAssembler; if (verbose) std::cout << " done! " << std::endl; if (verbose) std::cout << " -- Setting up assembler ... " << std::flush; adrAssembler.setFespace(uFESpace); if (verbose) std::cout << " done! " << std::endl; if (verbose) std::cout << " -- Defining the matrix ... " << std::flush; boost::shared_ptr<matrix_Type> systemMatrix(new matrix_Type( uFESpace->map() )); if (verbose) std::cout << " done! " << std::endl; // Perform the assembly of the matrix if (verbose) std::cout << " -- Adding the diffusion ... " << std::flush; adrAssembler.addDiffusion(systemMatrix, 1.); if (verbose) std::cout << " done! " << std::endl; if (verbose) std::cout << " Time needed : " << adrAssembler.diffusionAssemblyChrono().diffCumul() << std::endl; if (verbose) std::cout << " -- Adding the mass ... " << std::flush; adrAssembler.addMass(systemMatrix, M_PI * M_PI ); if (verbose) std::cout << " done! " << std::endl; if (verbose) std::cout << " -- Closing the matrix ... " << std::flush; systemMatrix->globalAssemble(); if (verbose) std::cout << " done ! " << std::endl; // Definition and assembly of the RHS if (verbose) std::cout << " -- Building the RHS ... " << std::flush; vector_Type rhs(uFESpace->map(),Repeated); vector_Type fInterpolated(uFESpace->map(),Repeated); uFESpace->interpolate( static_cast<feSpace_Type::function_Type>( fRhs ), fInterpolated, 0.0 ); adrAssembler.addMassRhs(rhs,fInterpolated); rhs.globalAssemble(); if (verbose) std::cout << " done ! " << std::endl; // Definition and application of the BCs if (verbose) std::cout << " -- Building the BCHandler ... " << std::flush; BCHandler bchandler; BCFunctionBase BCu( static_cast<feSpace_Type::function_Type>( exactSolution ) ); bchandler.addBC("Dirichlet", Structured1DLabel::LEFT,Essential,Full,BCu,1); bchandler.addBC("Dirichlet", Structured1DLabel::RIGHT,Essential,Full,BCu,1); if (verbose) std::cout << " done ! " << std::endl; if (verbose) std::cout << " -- Updating the BCs ... " << std::flush; bchandler.bcUpdate(*uFESpace->mesh(),uFESpace->feBd(),uFESpace->dof()); if (verbose) std::cout << " done ! " << std::endl; if (verbose) std::cout << " -- Applying the BCs ... " << std::flush; vector_Type rhsBC(rhs,Unique); bcManage(*systemMatrix,rhsBC,*uFESpace->mesh(),uFESpace->dof(),bchandler,uFESpace->feBd(),1.0,0.0); rhs = rhsBC; if (verbose) std::cout << " done ! " << std::endl; // Definition of the solver if (verbose) std::cout << " -- Building the solver ... " << std::flush; SolverAztecOO linearSolver; if (verbose) std::cout << " done ! " << std::endl; if (verbose) std::cout << " -- Setting up the solver ... " << std::flush; linearSolver.setDataFromGetPot(dataFile,"solver"); linearSolver.setupPreconditioner(dataFile,"prec"); if (verbose) std::cout << " done ! " << std::endl; if (verbose) std::cout << " -- Setting matrix in the solver ... " << std::flush; linearSolver.setMatrix(*systemMatrix); if (verbose) std::cout << " done ! " << std::endl; linearSolver.setCommunicator(Comm); // Definition of the solution if (verbose) std::cout << " -- Defining the solution ... " << std::flush; vector_Type solution(uFESpace->map(),Unique); if (verbose) std::cout << " done ! " << std::endl; // Solve the solution if (verbose) std::cout << " -- Solving the system ... " << std::flush; linearSolver.solveSystem(rhsBC,solution,systemMatrix); if (verbose) std::cout << " done ! " << std::endl; // Error computation if (verbose) std::cout << " -- Computing the error ... " << std::flush; vector_Type solutionErr(solution); uFESpace->interpolate( static_cast<feSpace_Type::function_Type>( exactSolution ), solutionErr, 0.0 ); solutionErr-=solution; solutionErr.abs(); Real l2error(uFESpace->l2Error(exactSolution,vector_Type(solution,Repeated),0.0)); if (verbose) std::cout << " -- done ! " << std::endl; if (verbose) std::cout << " ---> Norm L2 : " << l2error << std::endl; Real linferror( solutionErr.normInf()); if (verbose) std::cout << " ---> Norm Inf : " << linferror << std::endl; // Exporter definition and use if (verbose) std::cout << " -- Defining the exporter ... " << std::flush; #ifdef HAVE_HDF5 ExporterHDF5<mesh_Type> exporter ( dataFile, "solution" ); #else ExporterVTK<mesh_Type> exporter ( dataFile, "solution" ); #endif exporter.setMeshProcId( meshPtr, Comm->MyPID()) ; if (verbose) std::cout << " done ! " << std::endl; if (verbose) std::cout << " -- Defining the exported quantities ... " << std::flush; boost::shared_ptr<vector_Type> solutionPtr (new vector_Type(solution,Repeated)); boost::shared_ptr<vector_Type> solutionErrPtr (new vector_Type(solutionErr,Repeated)); if (verbose) std::cout << " done ! " << std::endl; if (verbose) std::cout << " -- Updating the exporter ... " << std::flush; exporter.addVariable( ExporterData<mesh_Type>::ScalarField, "solution", uFESpace, solutionPtr, UInt(0) ); exporter.addVariable( ExporterData<mesh_Type>::ScalarField, "error", uFESpace, solutionErrPtr, UInt(0) ); if (verbose) std::cout << " done ! " << std::endl; if (verbose) std::cout << " -- Exporting ... " << std::flush; exporter.postProcess(0); if (verbose) std::cout << " done ! " << std::endl; if ( std::fabs( l2error - 0.0006169843149652788l ) > 1e-10 ) { std::cout << " <!> Solution has changed !!! <!> " << std::endl; return EXIT_FAILURE; } if ( std::fabs( linferror - 0.0001092814405985187l ) > 1e-10 ) { std::cout << " <!> Solution has changed !!! <!> " << std::endl; return EXIT_FAILURE; } if (verbose) std::cout << "End Result: TEST PASSED" << std::endl; } // needed to properly destroy all objects inside before mpi finalize #ifdef HAVE_MPI MPI_Finalize(); #endif return( EXIT_SUCCESS ); }
void Heart::run() { typedef FESpace< mesh_Type, MapEpetra > feSpace_Type; typedef boost::shared_ptr<feSpace_Type> feSpacePtr_Type; LifeChrono chronoinitialsettings; LifeChrono chronototaliterations; chronoinitialsettings.start(); Real normu; Real meanu; Real minu; //! Construction of data classes #ifdef MONODOMAIN HeartMonodomainData _data (M_heart_fct); #else HeartBidomainData _data (M_heart_fct); #endif HeartIonicData _dataIonic (M_heart_fct->M_dataFile); MeshData meshData; meshData.setup (M_heart_fct->M_dataFile, "electric/space_discretization"); boost::shared_ptr<mesh_Type > fullMeshPtr ( new mesh_Type ( M_heart_fct->M_comm ) ); readMesh (*fullMeshPtr, meshData); bool verbose = (M_heart_fct->M_comm->MyPID() == 0); //! Boundary conditions handler and function BCFunctionBase uZero ( zero_scalar ); BCHandler bcH; bcH.addBC ( "Endo", ENDOCARDIUM, Natural, Full, uZero, 1 ); bcH.addBC ( "Epi", EPICARDIUM, Natural, Full, uZero, 1 ); bcH.addBC ( "Trunc", TRUNC_SEC, Natural, Full, uZero, 1 ); const ReferenceFE* refFE_w; const QuadratureRule* qR_w; const QuadratureRule* bdQr_w; const ReferenceFE* refFE_u; const QuadratureRule* qR_u; const QuadratureRule* bdQr_u; //! Construction of the partitioned mesh boost::shared_ptr<mesh_Type> localMeshPtr; { MeshPartitioner< mesh_Type > meshPart (fullMeshPtr, M_heart_fct->M_comm); localMeshPtr = meshPart.meshPartition(); } std::string uOrder = M_heart_fct->M_dataFile ( "electric/space_discretization/u_order", "P1"); //! Initialization of the FE type and quadrature rules for both the variables if ( uOrder.compare ("P1") == 0 ) { if (verbose) { std::cout << "P1 potential " << std::flush; } refFE_u = &feTetraP1; qR_u = &quadRuleTetra15pt; bdQr_u = &quadRuleTria3pt; } else { cout << "\n " << uOrder << " finite element not implemented yet \n"; exit (1); } std::string wOrder = M_heart_fct->M_dataFile ( "electric/space_discretization/w_order", "P1"); if ( wOrder.compare ("P1") == 0 ) { if (verbose) { std::cout << "P1 recovery variable " << std::flush; } refFE_w = &feTetraP1; qR_w = &quadRuleTetra4pt; bdQr_w = &quadRuleTria3pt; } else { cout << "\n " << wOrder << " finite element not implemented yet \n"; exit (1); } //! Construction of the FE spaces if (verbose) { std::cout << "Building the potential FE space ... " << std::flush; } feSpacePtr_Type uFESpacePtr ( new feSpace_Type ( localMeshPtr, *refFE_u, *qR_u, *bdQr_u, 1, M_heart_fct->M_comm) ); #ifdef BIDOMAIN feSpacePtr_Type _FESpacePtr ( new feSpace_Type (localMeshPtr, *refFE_u, *qR_u, *bdQr_u, 2, M_heart_fct->M_comm) ); #endif if (verbose) { std::cout << "ok." << std::endl; } if (verbose) { std::cout << "Building the recovery variable FE space ... " << std::flush; } if (verbose) { std::cout << "ok." << std::endl; } UInt totalUDof = uFESpacePtr->map().map (Unique)->NumGlobalElements(); if (verbose) { std::cout << "Total Potential DOF = " << totalUDof << std::endl; } if (verbose) { std::cout << "Calling the electric model constructor ... "; } #ifdef MONODOMAIN HeartMonodomainSolver< mesh_Type > electricModel (_data, *uFESpacePtr, bcH, M_heart_fct->M_comm); #else HeartBidomainSolver< mesh_Type > electricModel (_data, *_FESpacePtr, *uFESpacePtr, bcH, M_heart_fct->M_comm); #endif if (verbose) { std::cout << "ok." << std::endl; } MapEpetra fullMap (electricModel.getMap() ); vector_Type rhs ( fullMap); electricModel.setup ( M_heart_fct->M_dataFile ); std::cout << "setup ok" << std::endl; if (verbose) { std::cout << "Calling the ionic model constructor ... "; } boost::shared_ptr< HeartIonicSolver< mesh_Type > > ionicModel; if (ion_model == 1) { if (verbose) { std::cout << "Ion Model = Rogers-McCulloch" << std::endl << std::flush; } ionicModel.reset (new RogersMcCulloch< mesh_Type > (_dataIonic, *localMeshPtr, *uFESpacePtr, *M_heart_fct->M_comm) ); } else if (ion_model == 2) { if (verbose) { std::cout << "Ion Model = Luo-Rudy" << std::endl << std::flush; } ionicModel.reset (new LuoRudy< mesh_Type > (_dataIonic, *localMeshPtr, *uFESpacePtr, *M_heart_fct->M_comm) ); } else if (ion_model == 3) { if (verbose) { std::cout << "Ion Model = Mitchell-Schaeffer" << std::endl << std::flush; } ionicModel.reset (new MitchellSchaeffer< mesh_Type > (_dataIonic, *localMeshPtr, *uFESpacePtr, *M_heart_fct->M_comm) ); } #ifdef MONODOMAIN electricModel.initialize ( M_heart_fct->initialScalar() ); #else electricModel.initialize ( M_heart_fct->initialScalar(), M_heart_fct->zeroScalar() ); #endif if (verbose) { std::cout << "ok." << std::endl; } ionicModel->initialize( ); //! Building time-independent part of the system electricModel.buildSystem( ); std::cout << "buildsystem ok" << std::endl; //! Initialization Real dt = _data.timeStep(); Real t0 = 0; Real tFinal = _data.endTime(); MPI_Barrier (MPI_COMM_WORLD); if (verbose) { std::cout << "Setting the initial solution ... " << std::endl << std::endl; } _data.setTime (t0); electricModel.resetPreconditioner(); if (verbose) { std::cout << " ok " << std::endl; } //! Setting generic Exporter postprocessing boost::shared_ptr< Exporter<mesh_Type > > exporter; std::string const exporterType = M_heart_fct->M_dataFile ( "exporter/type", "ensight"); #ifdef HAVE_HDF5 if (exporterType.compare ("hdf5") == 0) { exporter.reset ( new ExporterHDF5<mesh_Type > ( M_heart_fct->M_dataFile, "heart" ) ); exporter->setPostDir ( "./" ); // This is a test to see if M_post_dir is working exporter->setMeshProcId ( localMeshPtr, M_heart_fct->M_comm->MyPID() ); } else #endif { if (exporterType.compare ("none") == 0) { exporter.reset ( new ExporterEmpty<mesh_Type > ( M_heart_fct->M_dataFile, localMeshPtr, "heart", M_heart_fct->M_comm->MyPID() ) ); } else { exporter.reset ( new ExporterEnsight<mesh_Type > ( M_heart_fct->M_dataFile, localMeshPtr, "heart", M_heart_fct->M_comm->MyPID() ) ); } } vectorPtr_Type Uptr ( new vector_Type (electricModel.solutionTransmembranePotential(), Repeated ) ); exporter->addVariable ( ExporterData<mesh_Type>::ScalarField, "potential", uFESpacePtr, Uptr, UInt (0) ); #ifdef BIDOMAIN vectorPtr_Type Ueptr ( new vector_Type (electricModel.solutionExtraPotential(), Repeated ) ); exporter->addVariable ( ExporterData<mesh_Type>::ScalarField, "potential_e", _FESpacePtr, Ueptr, UInt (0) ); #endif vectorPtr_Type Fptr ( new vector_Type (electricModel.fiberVector(), Repeated ) ); if (_data.hasFibers() ) exporter->addVariable ( ExporterData<mesh_Type>::VectorField, "fibers", uFESpacePtr, Fptr, UInt (0) ); exporter->postProcess ( 0 ); MPI_Barrier (MPI_COMM_WORLD); chronoinitialsettings.stop(); //! Temporal loop LifeChrono chrono; Int iter = 1; chronototaliterations.start(); for ( Real time = t0 + dt ; time <= tFinal + dt / 2.; time += dt, iter++) { _data.setTime (time); if (verbose) { std::cout << std::endl; std::cout << "We are now at time " << _data.time() << " s. " << std::endl; std::cout << std::endl; } chrono.start(); MPI_Barrier (MPI_COMM_WORLD); ionicModel->solveIonicModel ( electricModel.solutionTransmembranePotential(), _data.timeStep() ); rhs *= 0; computeRhs ( rhs, electricModel, ionicModel, _data ); electricModel.updatePDESystem ( rhs ); electricModel.PDEiterate ( bcH ); normu = electricModel.solutionTransmembranePotential().norm2(); electricModel.solutionTransmembranePotential().epetraVector().MeanValue (&meanu); electricModel.solutionTransmembranePotential().epetraVector().MaxValue (&minu); if (verbose) { std::cout << "norm u " << normu << std::endl; std::cout << "mean u " << meanu << std::endl; std::cout << "max u " << minu << std::endl << std::flush; } *Uptr = electricModel.solutionTransmembranePotential(); #ifdef BIDOMAIN *Ueptr = electricModel.solutionExtraPotential(); #endif exporter->postProcess ( time ); MPI_Barrier (MPI_COMM_WORLD); chrono.stop(); if (verbose) { std::cout << "Total iteration time " << chrono.diff() << " s." << std::endl; } chronototaliterations.stop(); } if (verbose) { std::cout << "Total iterations time " << chronototaliterations.diff() << " s." << std::endl; } if (verbose) { std::cout << "Total initial settings time " << chronoinitialsettings.diff() << " s." << std::endl; } if (verbose) { std::cout << "Total execution time " << chronoinitialsettings.diff() + chronototaliterations.diff() << " s." << std::endl; } }
int main(int argc, char *argv[]) { #ifdef HAVE_MPI MPI_Init(&argc,&argv); { boost::shared_ptr<Epetra_Comm> Comm (new Epetra_MpiComm (MPI_COMM_WORLD)); #else std::shared_ptr<Epetra_Comm> Comm (new Epetra_SerialComm) ; #endif typedef RegionMesh<LinearTetra> mesh_Type; if (Comm->MyPID()==0) std::cout << "Testing solver class..." << std::endl; bool verbose = true; // Load data GetPot command_line(argc,argv); const std::string dataFileName = command_line.follow("data",2,"-f","--file"); GetPot dataFile(dataFileName); // Build mesh if(verbose && Comm->MyPID() == 0 ) std::cout << "[Loading mesh]" << std::endl; meshPtr_Type fullMeshPtr(new mesh_Type(Comm)); regularMesh3D( *fullMeshPtr , 0 , dataFile("mesh/nx",15) , dataFile("mesh/ny",15) , dataFile("mesh/nz",15) , dataFile("mesh/verbose",false) , 2.0 , 2.0 , 2.0 , -1.0 , -1.0 , -1.0 ) ; const UInt overlap(dataFile("mesh/overlap",0)); meshPtr_Type localMeshPtr; { MeshPartitioner<mesh_Type> meshPart; if (overlap) meshPart.setPartitionOverlap(overlap); meshPart.doPartition(fullMeshPtr , Comm); localMeshPtr = meshPart.meshPartition(); } fullMeshPtr.reset(); // manage bc const int BACK = 1; const int FRONT = 2; const int LEFT = 3; const int RIGHT = 4; const int TOP = 5; const int BOTTOM = 6; BCHandler bcHandler; BCFunctionBase ZeroBC (zeroFunction) ; bcHandler.addBC("Back", BACK , Essential , Scalar , ZeroBC , 1) ; bcHandler.addBC("Left" , LEFT , Essential , Scalar , ZeroBC , 1); bcHandler.addBC("Top" , TOP , Essential , Scalar , ZeroBC , 1); bcHandler.addBC("Front" , FRONT , Essential , Scalar , ZeroBC , 1); bcHandler.addBC("Right" , RIGHT , Essential , Scalar , ZeroBC , 1); bcHandler.addBC("Bottom" , BOTTOM , Essential , Scalar , ZeroBC , 1); // Set exporter ExporterHDF5 <mesh_Type > exporter (dataFile , "fwd"); exporter.setMeshProcId (localMeshPtr , Comm->MyPID()); exporter.setPrefix("test_fwd"); exporter.setPostDir("./"); // Instantiate class InverseETAEllipticSolver<mesh_Type> solver( dataFile , localMeshPtr , "SolverParamList2.xml" , bcHandler , &torsoLocation ); solver.solveFwd(exporter); // Exporter post-processing exporter.postProcess(0); exporter.closeFile(); // // Assemble matrix and rhs // if(verbose) // std::cout << "[Building graph and matrix]" << std::endl; // graphPtr_Type systemGraph; // matrixPtr_Type systemMatrix; // if (overlap) // { // systemGraph.reset( new graph_Type( Copy , * (uFESpace->map().map(Unique)), // 50,true ) ); // } // else // { // systemGraph.reset( new graph_Type( Copy , * (uFESpace->map().map(Unique)), // 50 ) ); // } // { // using namespace ExpressionAssembly ; // buildGraph ( // elements(localMeshPtr) , // uFESpace->qr() , // ETuFESpace, // ETuFESpace, // dot(grad(phi_i) , grad(phi_j) ) // ) // >> systemGraph ; // } // systemGraph->GlobalAssemble(); // if(overlap) // { // systemMatrix.reset( new matrix_Type ( ETuFESpace->map() , *systemGraph , true)); // } // else // { // systemMatrix.reset( new matrix_Type ( ETuFESpace->map() , *systemGraph )); // } // systemMatrix->zero(); // { // using namespace ExpressionAssembly; // integrate ( // elements(localMeshPtr) , // uFESpace->qr() , // ETuFESpace, // ETuFESpace, // dot (grad ( phi_i) , grad(phi_j) ) // ) // >> systemMatrix ; // } #ifdef HAVE_MPI } MPI_Finalize(); #endif return EXIT_SUCCESS; }
int main ( int argc, char** argv ) { #ifdef HAVE_HDF5 #ifdef HAVE_MPI MPI_Init (&argc, &argv); boost::shared_ptr<Epetra_Comm> comm (new Epetra_MpiComm (MPI_COMM_WORLD) ); const bool verbose (comm->MyPID() == 0); // Read first the data needed if (verbose) { std::cout << " -- Reading the data ... " << std::flush; } GetPot dataFile ( "data" ); if (verbose) { std::cout << " done ! " << std::endl; } const UInt Nelements (dataFile ("mesh/nelements", 10) ); if (verbose) std::cout << " ---> Number of elements : " << Nelements << std::endl; // Load mesh part from HDF5 const std::string partsFileName (dataFile ("test/hdf5_file_name", "cube.h5") ); const std::string ioClass (dataFile ("test/io_class", "new") ); boost::shared_ptr<mesh_Type> mesh; if (! ioClass.compare ("old") ) { ExporterHDF5Mesh3D<mesh_Type> HDF5Input (dataFile, partsFileName); HDF5Input.setComm (comm); mesh = HDF5Input.getMeshPartition(); HDF5Input.closeFile(); } else { PartitionIO<RegionMesh<LinearTetra> > partitionIO (partsFileName, comm); partitionIO.read (mesh); } // Build the FESpaces if (verbose) { std::cout << " -- Building FESpaces ... " << std::flush; } std::string uOrder ("P1"); std::string bOrder ("P1"); boost::shared_ptr<FESpace<mesh_Type, MapEpetra> > uFESpace (new FESpace<mesh_Type, MapEpetra> (mesh, uOrder, 1, comm) ); boost::shared_ptr<FESpace<mesh_Type, MapEpetra> > betaFESpace (new FESpace<mesh_Type, MapEpetra> (mesh, bOrder, 3, comm) ); if (verbose) { std::cout << " done ! " << std::endl; } if (verbose) std::cout << " ---> Dofs: " << uFESpace->dof().numTotalDof() << std::endl; // Build the assembler and the matrices if (verbose) { std::cout << " -- Building assembler ... " << std::flush; } ADRAssembler<mesh_Type, matrix_Type, vector_Type> adrAssembler; if (verbose) { std::cout << " done! " << std::endl; } if (verbose) { std::cout << " -- Setting up assembler ... " << std::flush; } adrAssembler.setup (uFESpace, betaFESpace); if (verbose) { std::cout << " done! " << std::endl; } if (verbose) { std::cout << " -- Defining the matrix ... " << std::flush; } boost::shared_ptr<matrix_Type> systemMatrix (new matrix_Type (uFESpace->map() ) ); *systemMatrix *= 0.0; if (verbose) { std::cout << " done! " << std::endl; } // Perform the assembly of the matrix if (verbose) { std::cout << " -- Adding the diffusion ... " << std::flush; } adrAssembler.addDiffusion (systemMatrix, 1); if (verbose) { std::cout << " done! " << std::endl; } if (verbose) std::cout << " Time needed : " << adrAssembler.diffusionAssemblyChrono().diffCumul() << std::endl; if (verbose) { std::cout << " -- Closing the matrix ... " << std::flush; } systemMatrix->globalAssemble(); if (verbose) { std::cout << " done ! " << std::endl; } Real matrixNorm (systemMatrix->norm1() ); if (verbose) { std::cout << " ---> Norm 1 : " << matrixNorm << std::endl; } if (std::fabs (matrixNorm - 1.68421) > 1e-3) { std::cout << " <!> Matrix has changed !!! <!> " << std::endl; return EXIT_FAILURE; } // Definition and assembly of the RHS if (verbose) { std::cout << " -- Building the RHS ... " << std::flush; } vector_Type rhs (uFESpace->map(), Repeated); rhs *= 0.0; vector_Type fInterpolated (uFESpace->map(), Repeated); fInterpolated *= 0.0; uFESpace->interpolate ( static_cast<function_Type> ( fRhs ), fInterpolated, 0.0); adrAssembler.addMassRhs (rhs, fInterpolated); rhs.globalAssemble(); if (verbose) { std::cout << " done ! " << std::endl; } // Definition and application of the BCs if (verbose) { std::cout << " -- Building the BCHandler ... " << std::flush; } BCHandler bchandler; BCFunctionBase BCu (exactSolution); bchandler.addBC ("Dirichlet", 1, Essential, Full, BCu, 1); for (UInt i (2); i <= 6; ++i) { bchandler.addBC ("Dirichlet", i, Essential, Full, BCu, 1); } if (verbose) { std::cout << " done ! " << std::endl; } if (verbose) { std::cout << " -- Updating the BCs ... " << std::flush; } bchandler.bcUpdate (*uFESpace->mesh(), uFESpace->feBd(), uFESpace->dof() ); if (verbose) { std::cout << " done ! " << std::endl; } if (verbose) { std::cout << " -- Applying the BCs ... " << std::flush; } vector_Type rhsBC (rhs, Unique); bcManage (*systemMatrix, rhsBC, *uFESpace->mesh(), uFESpace->dof(), bchandler, uFESpace->feBd(), 1.0, 0.0); rhs = rhsBC; if (verbose) { std::cout << " done ! " << std::endl; } // Definition of the solver if (verbose) { std::cout << " -- Building the solver ... " << std::flush; } SolverAztecOO linearSolver; if (verbose) { std::cout << " done ! " << std::endl; } if (verbose) { std::cout << " -- Setting up the solver ... " << std::flush; } linearSolver.setDataFromGetPot (dataFile, "solver"); linearSolver.setupPreconditioner (dataFile, "prec"); if (verbose) { std::cout << " done ! " << std::endl; } if (verbose) std::cout << " -- Setting matrix in the solver ... " << std::flush; linearSolver.setMatrix (*systemMatrix); if (verbose) { std::cout << " done ! " << std::endl; } linearSolver.setCommunicator (comm); // Definition of the solution if (verbose) { std::cout << " -- Defining the solution ... " << std::flush; } vector_Type solution (uFESpace->map(), Unique); solution *= 0.0; if (verbose) { std::cout << " done ! " << std::endl; } // Solve the solution if (verbose) { std::cout << " -- Solving the system ... " << std::flush; } linearSolver.solveSystem (rhsBC, solution, systemMatrix); if (verbose) { std::cout << " done ! " << std::endl; } // Error computation if (verbose) { std::cout << " -- Computing the error ... " << std::flush; } vector_Type solutionErr (solution); solutionErr *= 0.0; uFESpace->interpolate ( static_cast<function_Type> ( exactSolution ), solutionErr, 0.0); solutionErr -= solution; solutionErr.abs(); Real l2error (uFESpace->l2Error (exactSolution, vector_Type (solution, Repeated), 0.0) ); if (verbose) { std::cout << " -- done ! " << std::endl; } if (verbose) { std::cout << " ---> Norm L2 : " << l2error << std::endl; } Real linferror (solutionErr.normInf() ); if (verbose) { std::cout << " ---> Norm Inf : " << linferror << std::endl; } if (l2error > 0.0055) { std::cout << " <!> Solution has changed !!! <!> " << std::endl; return EXIT_FAILURE; } if (linferror > 0.0046) { std::cout << " <!> Solution has changed !!! <!> " << std::endl; return EXIT_FAILURE; } // Exporter definition and use if (verbose) { std::cout << " -- Defining the exporter ... " << std::flush; } ExporterHDF5<mesh_Type> exporter (dataFile, mesh, "solution", comm->MyPID() ) ; if (verbose) { std::cout << " done ! " << std::endl; } if (verbose) std::cout << " -- Defining the exported quantities ... " << std::flush; boost::shared_ptr<vector_Type> solutionPtr (new vector_Type (solution, Repeated) ); boost::shared_ptr<vector_Type> solutionErrPtr (new vector_Type (solutionErr, Repeated) ); if (verbose) { std::cout << " done ! " << std::endl; } if (verbose) std::cout << " -- Updating the exporter ... " << std::flush; exporter.addVariable ( ExporterData<mesh_Type>::ScalarField, "solution", uFESpace, solutionPtr, UInt (0) ); exporter.addVariable ( ExporterData<mesh_Type>::ScalarField, "error", uFESpace, solutionErrPtr, UInt (0) ); if (verbose) { std::cout << " done ! " << std::endl; } if (verbose) { std::cout << " -- Exporting ... " << std::flush; } exporter.postProcess (0); exporter.closeFile(); if (verbose) { std::cout << " done ! " << std::endl; } if (verbose) { std::cout << "End Result: TEST PASSED" << std::endl; } MPI_Finalize(); #else std::cout << "This test needs MPI to run. Aborting." << std::endl; return (EXIT_FAILURE); #endif /* HAVE_MPI */ #else std::cout << "This test needs HDF5 to run. Aborting." << std::endl; return (EXIT_FAILURE); #endif /* HAVE_HDF5 */ return ( EXIT_SUCCESS ); }
// =================================================== //! Methods // =================================================== void test_bdf::run() { //Useful typedef typedef SolverAztecOO solver_type; typedef VectorEpetra vector_type; typedef boost::shared_ptr<vector_type> vector_ptrtype; // Reading from data file GetPot dataFile(Members->data_file_name.c_str()); // Select Pid(0) to write on std output bool verbose = (Members->comm->MyPID() == 0); if (verbose) std::cout << "The BDF Solver" << std::flush; //the forcing term SourceFct sf; // the boundary conditions BCFunctionBase g_Ess(AnalyticalSol::u); BCHandler bc; bc.addBC("Top", TOP, Essential, Full, g_Ess, 1); bc.addBC("Bottom", BOTTOM, Essential, Full, g_Ess, 1); bc.addBC("Left", LEFT, Essential, Full, g_Ess, 1); bc.addBC("Right", RIGHT, Essential, Full, g_Ess, 1); bc.addBC("Front", FRONT, Essential, Full, g_Ess, 1); bc.addBC("Back", BACK, Essential, Full, g_Ess, 1); //============================================================================= //Mesh stuff Members->comm->Barrier(); MeshData meshData(dataFile, ("bdf/" + discretization_section).c_str()); boost::shared_ptr<regionMesh> fullMeshPtr( new regionMesh( Members->comm ) ); readMesh(*fullMeshPtr,meshData); boost::shared_ptr<regionMesh> meshPtr; { MeshPartitioner<regionMesh> meshPart( fullMeshPtr, Members->comm ); meshPtr = meshPart.meshPartition(); } //============================================================================= //finite element space of the solution boost::shared_ptr<FESpace<regionMesh, MapEpetra> > feSpacePtr( new FESpace<regionMesh, MapEpetra> ( meshPtr, dataFile(("bdf/"+discretization_section + "/order").c_str(), "P2"), 1, Members->comm) ); if (verbose) std::cout << " Number of unknowns : " << feSpacePtr->map().map(Unique)->NumGlobalElements() << std::endl; bc.bcUpdate(*(feSpacePtr->mesh()), feSpacePtr->feBd(), feSpacePtr->dof()); //============================================================================= //Fe Matrices and vectors MatrixElemental elmat(feSpacePtr->fe().nbFEDof(), 1, 1); //local matrix MatrixEpetra<double> matM(feSpacePtr->map()); //mass matrix boost::shared_ptr<MatrixEpetra<double> > matA_ptr( new MatrixEpetra<double> (feSpacePtr->map())); //stiff matrix VectorEpetra u(feSpacePtr->map(), Unique); // solution vector VectorEpetra f(feSpacePtr->map(), Unique); // forcing term vector LifeChrono chrono; //Assembling Matrix M Members->comm->Barrier(); chrono.start(); for (UInt iVol = 0; iVol < feSpacePtr->mesh()->numElements(); iVol++) { feSpacePtr->fe().updateJac(feSpacePtr->mesh()->element(iVol)); elmat.zero(); mass(1., elmat, feSpacePtr->fe(), 0, 0); assembleMatrix(matM, elmat, feSpacePtr->fe(), feSpacePtr->fe(), feSpacePtr->dof(), feSpacePtr->dof(), 0, 0, 0, 0); } matM.globalAssemble(); Members->comm->Barrier(); chrono.stop(); if (verbose) std::cout << "\n \n -- Mass matrix assembling time = " << chrono.diff() << std::endl << std::endl; // ========================================== // Definition of the time integration stuff // ========================================== Real Tfin = dataFile("bdf/endtime", 10.0); Real delta_t = dataFile("bdf/timestep", 0.5); Real t0 = 1.; UInt ord_bdf = dataFile("bdf/order", 3); TimeAdvanceBDFVariableStep<VectorEpetra> bdf; bdf.setup(ord_bdf); //Initialization bdf.setInitialCondition<Real(*) (Real, Real, Real, Real, UInt), FESpace<regionMesh, MapEpetra> >(AnalyticalSol::u, u, *feSpacePtr, t0, delta_t); if (verbose) bdf.showMe(); Members->comm->Barrier(); //=================================================== // post processing setup boost::shared_ptr<Exporter<regionMesh> > exporter; std::string const exporterType = dataFile( "exporter/type", "hdf5"); #ifdef HAVE_HDF5 if (exporterType.compare("hdf5") == 0) { exporter.reset( new ExporterHDF5<regionMesh > ( dataFile, "bdf_test" ) ); } else #endif { if (exporterType.compare("none") == 0) { exporter.reset( new ExporterEmpty<regionMesh > ( dataFile, meshPtr, "bdf_test", Members->comm->MyPID()) ); } else { exporter.reset( new ExporterEnsight<regionMesh > ( dataFile, meshPtr, "bdf_test", Members->comm->MyPID()) ); } } exporter->setPostDir( "./" ); exporter->setMeshProcId( meshPtr, Members->comm->MyPID() ); boost::shared_ptr<VectorEpetra> u_display_ptr(new VectorEpetra( feSpacePtr->map(), exporter->mapType())); exporter->addVariable(ExporterData<regionMesh >::ScalarField, "u", feSpacePtr, u_display_ptr, UInt(0)); *u_display_ptr = u; exporter->postProcess(0); //=================================================== //Definition of the linear solver SolverAztecOO az_A(Members->comm); az_A.setDataFromGetPot(dataFile, "bdf/solver"); az_A.setupPreconditioner(dataFile, "bdf/prec"); //=================================================== // TIME LOOP //=================================================== matA_ptr.reset(new MatrixEpetra<double> (feSpacePtr->map())); for (Real t = t0 + delta_t; t <= Tfin; t += delta_t) { Members->comm->Barrier(); if (verbose) cout << "Now we are at time " << t << endl; chrono.start(); //Assemble A Real coeff = bdf.coefficientDerivative(0) / delta_t; Real visc = nu(t); Real s = sigma(t); for (UInt i = 0; i < feSpacePtr->mesh()->numElements(); i++) { feSpacePtr->fe().updateFirstDerivQuadPt(feSpacePtr->mesh()->element(i)); elmat.zero(); mass(coeff + s, elmat, feSpacePtr->fe()); stiff(visc, elmat, feSpacePtr->fe()); assembleMatrix(*matA_ptr, elmat, feSpacePtr->fe(), feSpacePtr->fe(), feSpacePtr->dof(), feSpacePtr->dof(), 0, 0, 0, 0); } chrono.stop(); if (verbose) cout << "A has been constructed in "<< chrono.diff() << "s." << endl; // Handling of the right hand side f = (matM*bdf.rhsContribution()); //f = M*\sum_{i=1}^{orderBdf} \alpha_i u_{n-i} feSpacePtr->l2ScalarProduct(sf, f, t); //f +=\int_\Omega{ volumeForces *v dV} Members->comm->Barrier(); // Treatment of the Boundary conditions if (verbose) cout << "*** BC Management: " << endl; Real tgv = 1.; chrono.start(); bcManage(*matA_ptr, f, *feSpacePtr->mesh(), feSpacePtr->dof(), bc, feSpacePtr->feBd(), tgv, t); matA_ptr->globalAssemble(); chrono.stop(); if (verbose) cout << chrono.diff() << "s." << endl; //Set Up the linear system Members->comm->Barrier(); chrono.start(); az_A.setMatrix(*matA_ptr); az_A.setReusePreconditioner(false); Members->comm->Barrier(); az_A.solveSystem(f, u, matA_ptr); chrono.stop(); bdf.shiftRight(u); if (verbose) cout << "*** Solution computed in " << chrono.diff() << "s." << endl; Members->comm->Barrier(); // Error in the L2 vector_type uComputed(u, Repeated); Real L2_Error, L2_RelError; L2_Error = feSpacePtr->l2Error(AnalyticalSol::u, uComputed, t, &L2_RelError); if (verbose) std::cout << "Error Norm L2: " << L2_Error << "\nRelative Error Norm L2: " << L2_RelError << std::endl; Members->errorNorm = L2_Error; //transfer the solution at time t. *u_display_ptr = u; matA_ptr->zero(); exporter->postProcess(t); } }
void Cylinder::run() { typedef FESpace< mesh_Type, MapEpetra > feSpace_Type; typedef boost::shared_ptr<feSpace_Type> feSpacePtr_Type; typedef OseenSolver< mesh_Type >::vector_Type vector_Type; typedef boost::shared_ptr<vector_Type> vectorPtr_Type; // Reading from data file // GetPot dataFile( d->data_file_name ); // int save = dataFile("fluid/miscellaneous/save", 1); bool verbose = (d->comm->MyPID() == 0); // Boundary conditions BCHandler bcH; BCFunctionBase uZero( zero_scalar ); std::vector<ID> zComp(1); zComp[0] = 3; BCFunctionBase uIn ( d->getU_2d() ); BCFunctionBase uOne ( d->getU_one() ); BCFunctionBase uPois( d->getU_pois() ); //BCFunctionBase unormal( d->get_normal() ); //cylinder bcH.addBC( "Inlet", INLET, Essential, Full, uPois , 3 ); bcH.addBC( "Ringin", RINGIN, Essential, Full, uZero , 3 ); bcH.addBC( "Ringout", RINGOUT, Essential, Full, uZero , 3 ); bcH.addBC( "Outlet", OUTLET, Natural, Full, uZero, 3 ); bcH.addBC( "Wall", WALL, Essential, Full, uZero, 3 ); int numLM = 0; boost::shared_ptr<OseenData> oseenData(new OseenData()); oseenData->setup( dataFile ); MeshData meshData; meshData.setup(dataFile, "fluid/space_discretization"); boost::shared_ptr<mesh_Type> fullMeshPtr ( new mesh_Type( d->comm ) ); readMesh(*fullMeshPtr, meshData); boost::shared_ptr<mesh_Type> meshPtr; { MeshPartitioner< mesh_Type > meshPart(fullMeshPtr, d->comm); meshPtr = meshPart.meshPartition(); } if (verbose) std::cout << std::endl; if (verbose) std::cout << "Time discretization order " << oseenData->dataTime()->orderBDF() << std::endl; //oseenData.meshData()->setMesh(meshPtr); std::string uOrder = dataFile( "fluid/space_discretization/vel_order", "P1"); if (verbose) std::cout << "Building the velocity FE space ... " << std::flush; feSpacePtr_Type uFESpacePtr( new feSpace_Type(meshPtr,uOrder,3,d->comm) ); if (verbose) std::cout << "ok." << std::endl; std::string pOrder = dataFile( "fluid/space_discretization/press_order", "P1"); if (verbose) std::cout << "Building the pressure FE space ... " << std::flush; feSpacePtr_Type pFESpacePtr( new feSpace_Type(meshPtr,pOrder,1,d->comm) ); if (verbose) std::cout << "ok." << std::endl; UInt totalVelDof = uFESpacePtr->map().map(Unique)->NumGlobalElements(); UInt totalPressDof = pFESpacePtr->map().map(Unique)->NumGlobalElements(); if (verbose) std::cout << "Total Velocity DOF = " << totalVelDof << std::endl; if (verbose) std::cout << "Total Pressure DOF = " << totalPressDof << std::endl; if (verbose) std::cout << "Calling the fluid constructor ... "; bcH.setOffset( "Inlet", totalVelDof + totalPressDof - 1 ); OseenSolver< mesh_Type > fluid (oseenData, *uFESpacePtr, *pFESpacePtr, d->comm, numLM); MapEpetra fullMap(fluid.getMap()); if (verbose) std::cout << "ok." << std::endl; fluid.setUp(dataFile); fluid.buildSystem(); MPI_Barrier(MPI_COMM_WORLD); // Initialization Real dt = oseenData->dataTime()->timeStep(); Real t0 = oseenData->dataTime()->initialTime(); Real tFinal = oseenData->dataTime()->endTime(); // bdf object to store the previous solutions TimeAdvanceBDFNavierStokes<vector_Type> bdf; bdf.setup(oseenData->dataTime()->orderBDF()); vector_Type beta( fullMap ); vector_Type rhs ( fullMap ); #ifdef HAVE_HDF5 ExporterHDF5<mesh_Type > ensight( dataFile, meshPtr, "cylinder", d->comm->MyPID()); #else ExporterEnsight<mesh_Type > ensight( dataFile, meshPtr, "cylinder", d->comm->MyPID()); #endif vectorPtr_Type velAndPressure ( new vector_Type(*fluid.solution(), ensight.mapType() ) ); ensight.addVariable( ExporterData<mesh_Type>::VectorField, "velocity", uFESpacePtr, velAndPressure, UInt(0) ); ensight.addVariable( ExporterData<mesh_Type>::ScalarField, "pressure", pFESpacePtr, velAndPressure, UInt(3*uFESpacePtr->dof().numTotalDof() ) ); // initialization with stokes solution if (d->initial_sol == "stokes") { if (verbose) std::cout << std::endl; if (verbose) std::cout << "Computing the stokes solution ... " << std::endl << std::endl; oseenData->dataTime()->setTime(t0); MPI_Barrier(MPI_COMM_WORLD); beta *= 0.; rhs *= 0.; fluid.updateSystem(0, beta, rhs ); fluid.iterate( bcH ); // fluid.postProcess(); *velAndPressure = *fluid.solution(); ensight.postProcess( 0 ); fluid.resetPreconditioner(); } bdf.bdfVelocity().setInitialCondition( *fluid.solution() ); // Temporal loop LifeChrono chrono; int iter = 1; for ( Real time = t0 + dt ; time <= tFinal + dt/2.; time += dt, iter++) { oseenData->dataTime()->setTime(time); if (verbose) { std::cout << std::endl; std::cout << "We are now at time "<< oseenData->dataTime()->time() << " s. " << std::endl; std::cout << std::endl; } chrono.start(); double alpha = bdf.bdfVelocity().coefficientFirstDerivative( 0 ) / oseenData->dataTime()->timeStep(); beta = bdf.bdfVelocity().extrapolation(); bdf.bdfVelocity().updateRHSContribution( oseenData->dataTime()->timeStep()); rhs = fluid.matrixMass()*bdf.bdfVelocity().rhsContributionFirstDerivative(); fluid.updateSystem( alpha, beta, rhs ); fluid.iterate( bcH ); bdf.bdfVelocity().shiftRight( *fluid.solution() ); // if (((iter % save == 0) || (iter == 1 ))) // { *velAndPressure = *fluid.solution(); ensight.postProcess( time ); // } // postProcessFluxesPressures(fluid, bcH, time, verbose); MPI_Barrier(MPI_COMM_WORLD); chrono.stop(); if (verbose) std::cout << "Total iteration time " << chrono.diff() << " s." << std::endl; } }
// =================================================== //! Methods // =================================================== void problem::run() { typedef RegionMesh<LinearTetra> mesh_Type; typedef VenantKirchhoffViscoelasticSolver< mesh_Type >::vector_type vector_Type; typedef boost::shared_ptr<vector_Type> vectorPtr_Type; typedef boost::shared_ptr< TimeAdvance< vector_Type > > TimeAdvance_type; typedef FESpace< mesh_Type, MapEpetra > FESpace_type; typedef boost::shared_ptr<FESpace_type> FESpace_ptrtype; bool verbose = (members->comm->MyPID() == 0); // // VenantKirchhoffViscoelasticData // GetPot dataFile( members->data_file_name.c_str() ); boost::shared_ptr<VenantKirchhoffViscoelasticData> dataProblem(new VenantKirchhoffViscoelasticData( )); dataProblem->setup(dataFile, "problem"); MeshData meshData; meshData.setup(dataFile, "problem/space_discretization"); boost::shared_ptr<mesh_Type > fullMeshPtr( new mesh_Type( members->comm ) ); readMesh(*fullMeshPtr, meshData); boost::shared_ptr<mesh_Type > localMeshPtr; { MeshPartitioner< mesh_Type > meshPart( fullMeshPtr, members->comm ); localMeshPtr = meshPart.meshPartition(); } // // The Problem Solver // if (verbose) std::cout << "The Problem Solver" << std::flush; // Scalar Solution Space: std::string Order = dataFile( "problem/space_discretization/order", "P1"); if ( Order.compare("P1") == 0 ) { if (verbose) std::cout << " Space order : P1" << std::flush; } else if ( Order.compare("P2") == 0 ) { if (verbose) std::cout << " Space order : P2"; } if (verbose) std::cout << std::endl; // finite element space of the solution // finite element space of the solution std::string dOrder = dataFile( "problem/space_discretization/order", "P1"); FESpace_ptrtype feSpace( new FESpace_type(localMeshPtr,dOrder,1,members->comm) ); // instantiation of the VenantKirchhoffViscoelasticSolver class VenantKirchhoffViscoelasticSolver< mesh_Type > problem; problem.setup(dataProblem, feSpace, members->comm); problem.setDataFromGetPot(dataFile); // the boundary conditions BCFunctionBase uZero ( members->getUZero() ); BCFunctionBase uEx(uexact); BCHandler bcH; bcH.addBC( "Top", TOP, Essential, Full, uEx, 1 ); bcH.addBC( "Bottom", BOTTOM, Essential, Full, uEx, 1 ); bcH.addBC( "Left", LEFT, Essential, Full, uEx, 1 ); bcH.addBC( "Right", RIGHT, Essential, Full, uEx, 1 ); bcH.addBC( "Front", FRONT, Essential, Full, uEx, 1 ); bcH.addBC( "Back", BACK, Essential, Full, uEx, 1 ); std::ofstream out_norm; if (verbose) { out_norm.open("norm.txt"); out_norm << " time " <<" L2_Error " <<" H1_Error " <<" L2_RelError " <<" H1_RelError \n"; out_norm.close(); } LifeChrono chrono; std::string TimeAdvanceMethod = dataFile( "problem/time_discretization/method", "Newmark"); TimeAdvance_type timeAdvance( TimeAdvanceFactory::instance().createObject( TimeAdvanceMethod ) ); UInt OrderDev = 1; //! initialization of parameters of time Advance method: if (TimeAdvanceMethod =="Newmark") timeAdvance->setup( dataProblem->dataTimeAdvance()->coefficientsNewmark() , OrderDev); if (TimeAdvanceMethod =="BDF") timeAdvance->setup(dataProblem->dataTimeAdvance()->orderBDF() , OrderDev); Real dt = dataProblem->dataTime()->timeStep(); Real T = dataProblem->dataTime()->endTime(); chrono.start(); dataProblem->setup(dataFile, "problem"); double alpha = timeAdvance->coefficientFirstDerivative( 0 ) / ( dataProblem->dataTime()->timeStep()); problem.buildSystem(alpha); MPI_Barrier(MPI_COMM_WORLD); if (verbose ) std::cout << "ok." << std::endl; // building some vectors: MapEpetra uMap = problem.solution()->map(); // computing the rhs vector_Type rhs ( uMap, Unique ); vector_Type rhsV( uMap, Unique ); // postProcess boost::shared_ptr< Exporter<mesh_Type > > exporter; std::string const exporterType = dataFile( "exporter/type", "ensight"); #ifdef HAVE_HDF5 if (exporterType.compare("hdf5") == 0) exporter.reset( new ExporterHDF5<mesh_Type > ( dataFile, "problem" ) ); else #endif { if (exporterType.compare("none") == 0) exporter.reset( new ExporterEmpty<mesh_Type > ( dataFile, localMeshPtr, "problem", members ->comm->MyPID()) ); else exporter.reset( new ExporterEnsight<mesh_Type > ( dataFile, localMeshPtr, "problem", members->comm->MyPID()) ); } exporter->setPostDir( "./" ); // This is a test to see if M_post_dir is working exporter->setMeshProcId( localMeshPtr, members->comm->MyPID() ); vectorPtr_Type U ( new vector_Type(*problem.solution(), exporter->mapType() ) ); vectorPtr_Type V ( new vector_Type(*problem.solution(), exporter->mapType() ) ); vectorPtr_Type Exact ( new vector_Type(*problem.solution(), exporter->mapType() ) ); vectorPtr_Type vExact ( new vector_Type(*problem.solution(), exporter->mapType() ) ); vectorPtr_Type RHS ( new vector_Type(*problem.solution(), exporter->mapType() ) ); exporter->addVariable( ExporterData<mesh_Type>::ScalarField, "displacement", feSpace, U, UInt(0) ); exporter->addVariable( ExporterData<mesh_Type>::ScalarField, "velocity", feSpace, V, UInt(0) ); exporter->addVariable( ExporterData<mesh_Type>::ScalarField, "uexact", feSpace, Exact, UInt(0) ); exporter->addVariable( ExporterData<mesh_Type>::ScalarField, "vexact", feSpace, vExact, UInt(0) ); exporter->postProcess( 0 ); //initialization of unk //evaluate disp and vel as interpolate the bcFunction d0 and v0 feSpace->interpolate( static_cast<FESpace_type::function_Type>( d0 ), *U, 0.0 ); feSpace->interpolate( static_cast<FESpace_type::function_Type>( v0 ), *V, 0.0 ); //evaluate disp and vel as interpolate the bcFunction d0 and v0 std::vector<vectorPtr_Type> uv0; if (TimeAdvanceMethod =="Newmark") { uv0.push_back(U); uv0.push_back(V); } if (TimeAdvanceMethod =="BDF") { for ( UInt previousPass=0; previousPass < dataProblem->dataTimeAdvance()->orderBDF() ; previousPass++) { Real previousTimeStep = -previousPass*dt; // <<<<<<< HEAD feSpace->interpolate(uexact, *U, previousTimeStep ); uv0.push_back(U); // ======= // feSpace->interpolate( static_cast<FESpace_type::function_Type>( uexact ), *U, previousTimeStep ); // uv0.push_back(*U); //>>>>>>> master } } //the uv0[0] should be the displacement //the uv0[1] should be the velocity //timeAdvance->setInitialCondition(uv0[0],uv0[1]); timeAdvance->setInitialCondition(uv0); timeAdvance-> setTimeStep(dataProblem->dataTime()->timeStep()); timeAdvance->showMe(); feSpace->interpolate( static_cast<FESpace_type::function_Type>( uexact ), *Exact , 0); feSpace->interpolate( static_cast<FESpace_type::function_Type>( v0 ), *vExact , 0); *U = timeAdvance->solution(); *V = timeAdvance->firstDerivative(); for (Real time = dt; time <= T; time += dt) { dataProblem->dataTime()->setTime(time); if (verbose) { std::cout << std::endl; std::cout << " P - Now we are at time " << dataProblem->dataTime()->time() << " s." << std::endl; } //evaluate rhs rhs *=0; timeAdvance->updateRHSContribution(dt); rhsV = timeAdvance->rhsContributionFirstDerivative(); feSpace->l2ScalarProduct(source_in, rhs, time); rhs += problem.matrMass() *rhsV; //updateRHS problem.updateRHS(rhs); //solver system problem.iterate( bcH ); // Computes the matrices and solves the system //update unknowns of timeAdvance timeAdvance->shiftRight(*problem.solution()); //evaluate uexact solution feSpace->interpolate( static_cast<FESpace_type::function_Type>( uexact ), *Exact , time); feSpace->interpolate( static_cast<FESpace_type::function_Type>( v0 ), *vExact , time); *U = timeAdvance->solution(); *V =timeAdvance->firstDerivative(); //postProcess exporter->postProcess(time); // Error L2 and H1 Norms AnalyticalSol uExact; vector_Type u (*problem.solution(), Repeated); Real H1_Error, H1_RelError, L2_Error, L2_RelError; L2_Error = feSpace->l2Error(uexact, u, time ,&L2_RelError); H1_Error = feSpace->h1Error(uExact, u, time ,&H1_RelError); //save the norm if (verbose) { out_norm.open("norm.txt", std::ios::app); out_norm << time << " " << L2_Error << " " << H1_Error << " " << L2_RelError << " " << H1_RelError << "\n"; out_norm.close(); } MPI_Barrier(MPI_COMM_WORLD); } chrono.stop(); if (verbose) std::cout << "Total iteration time " << chrono.diff() << " s." << std::endl; }