Esempio n. 1
0
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 );
}
Esempio n. 2
0
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 );
}
Esempio n. 3
0
// ===================================================
//! 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);
    }



}