Exemple #1
0
int main(int argc, char** args) {

  // init Petsc-MPI communicator
  FemusInit mpinit(argc, args, MPI_COMM_WORLD);

  // define multilevel mesh
  MultiLevelMesh mlMsh;
  // read coarse level mesh and generate finers level meshes
  double scalingFactor = 1.;
  //mlMsh.ReadCoarseMesh("./input/cube_hex.neu","seventh",scalingFactor);
  //mlMsh.ReadCoarseMesh("./input/square_quad.neu", "seventh", scalingFactor);
  mlMsh.ReadCoarseMesh("./input/quadAMR.neu", "seventh", scalingFactor);
  /* "seventh" is the order of accuracy that is used in the gauss integration scheme
     probably in the furure it is not going to be an argument of this function   */
  unsigned dim = mlMsh.GetDimension();

  unsigned numberOfUniformLevels = 3;
  unsigned numberOfSelectiveLevels = 0;
  mlMsh.RefineMesh(numberOfUniformLevels + numberOfSelectiveLevels, numberOfUniformLevels , NULL);
   
  // erase all the coarse mesh levels
  //mlMsh.EraseCoarseLevels(numberOfUniformLevels - 3);

  // print mesh info
  mlMsh.PrintInfo();

  MultiLevelSolution mlSol(&mlMsh);

  // add variables to mlSol

  mlSol.AddSolution("Error",  DISCONTINUOUS_POLYNOMIAL, ZERO);

  mlSol.AddSolution("U", LAGRANGE, SECOND);

  mlSol.Initialize("All");

  // attach the boundary condition function and generate boundary data
  mlSol.AttachSetBoundaryConditionFunction(SetBoundaryCondition);

  mlSol.GenerateBdc("All");

     
  unsigned maxNumberOfMeshes = 8;  
  for(unsigned i = 0; i < maxNumberOfMeshes; i++) {
    // define the multilevel problem attach the mlSol object to it
    MultiLevelProblem mlProb(&mlSol);

    // add system Poisson in mlProb as a Linear Implicit System
    NonLinearImplicitSystem& system = mlProb.add_system < NonLinearImplicitSystem > ("Poisson");

    // add solution "u" to system
    system.AddSolutionToSystemPDE("U");

    //system.SetLinearEquationSolverType(FEMuS_DEFAULT);
    system.SetLinearEquationSolverType(FEMuS_ASM);  // Additive Swartz Method
    // attach the assembling function to system
    system.SetAssembleFunction(AssemblePoisson_AD);

    system.SetMaxNumberOfNonLinearIterations(10);
    system.SetMaxNumberOfLinearIterations(3);
    system.SetAbsoluteLinearConvergenceTolerance(1.e-12);
    system.SetNonLinearConvergenceTolerance(1.e-8);
    system.SetMgType(F_CYCLE);

    system.SetNumberPreSmoothingStep(0);
    system.SetNumberPostSmoothingStep(2);
    // initilaize and solve the system
    system.init();

    system.SetSolverFineGrids(GMRES);
    system.SetPreconditionerFineGrids(ILU_PRECOND);
    system.SetTolerances(1.e-3, 1.e-20, 1.e+50, 5);

    system.SetNumberOfSchurVariables(1);
    system.SetElementBlockNumber(4);
   
    system.MGsolve();
    
    GetError(&mlSol);
    
    // print solutions
    std::vector < std::string > variablesToBePrinted;
    variablesToBePrinted.push_back("All");
    VTKWriter vtkIO(&mlSol);
    vtkIO.SetDebugOutput(true);
    vtkIO.Write(DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted);

    //refine the mesh
    MeshRefinement meshcoarser(*mlMsh.GetLevel(numberOfUniformLevels-1));
    bool elementsHaveBeenRefined = meshcoarser.FlagElementsToBeRefined(1.e-2, mlSol.GetSolutionLevel(numberOfUniformLevels-1)->GetSolutionName("Error"));
    
    if( !elementsHaveBeenRefined ){
      break;
    }
    mlMsh.AddAMRMeshLevel();
    mlSol.AddSolutionLevel();
    mlSol.RefineSolution(numberOfUniformLevels);
    numberOfUniformLevels += 1;
    
    

  }


  return 0;
}
Exemple #2
0
int main(int argc, char** args) {

  // init Petsc-MPI communicator
  FemusInit mpinit(argc, args, MPI_COMM_WORLD);

  // define multilevel mesh
  MultiLevelMesh mlMsh;
  // read coarse level mesh and generate finers level meshes
  double scalingFactor = 1.;
  //mlMsh.ReadCoarseMesh("./input/cube_hex.neu","seventh",scalingFactor);
  //mlMsh.ReadCoarseMesh("./input/square_quad.neu", "seventh", scalingFactor);
  mlMsh.ReadCoarseMesh("./input/quadAMR01.neu", "seventh", scalingFactor);
  /* "seventh" is the order of accuracy that is used in the gauss integration scheme
     probably in the furure it is not going to be an argument of this function   */
  unsigned dim = mlMsh.GetDimension();
  unsigned numberOfUniformLevels = 3;
  unsigned numberOfSelectiveLevels = 0;
  mlMsh.RefineMesh(numberOfUniformLevels + numberOfSelectiveLevels, numberOfUniformLevels , NULL);
  
  
  // erase all the coarse mesh levels
  //mlMsh.EraseCoarseLevels(numberOfUniformLevels - 3);

  // print mesh info
 
  // add variables to mlSol

  MultiLevelSolution mlSol(&mlMsh);
  
  mlSol.AddSolution("Error",  DISCONTINOUS_POLYNOMIAL, ZERO);

  mlSol.AddSolution("U", LAGRANGE, SECOND);

  mlSol.Initialize("All");

  // attach the boundary condition function and generate boundary data
  mlSol.AttachSetBoundaryConditionFunction(SetBoundaryCondition);

  mlSol.GenerateBdc("All");
  

  

     
  unsigned maxNumberOfMeshes = 8;  
  
  vector < vector < double > > H1normE;
  H1normE.resize (maxNumberOfMeshes);

  vector < vector < double > > H1norm;
  H1norm.resize (maxNumberOfMeshes);
  
  
  for(unsigned i = 0; i < maxNumberOfMeshes; i++) {
    // define the multilevel problem attach the mlSol object to it
    
   
    
    FEOrder feOrder[3] = {FIRST, SERENDIPITY, SECOND};
    H1normE[i].resize (3);
    H1norm[i].resize (3);

    //for (unsigned j = 0; j < 3; j++) {
    
      


      
      
      
    MultiLevelProblem mlProb(&mlSol);

    // add system Poisson in mlProb as a Linear Implicit System
    NonLinearImplicitSystem& system = mlProb.add_system < NonLinearImplicitSystem > ("Poisson");

    // add solution "u" to system
    system.AddSolutionToSystemPDE("U");

    //system.SetMgSmoother(GMRES_SMOOTHER);
    system.SetMgSmoother(ASM_SMOOTHER);  // Additive Swartz Method
    // attach the assembling function to system
    system.SetAssembleFunction(AssemblePoisson_AD);

    system.SetMaxNumberOfNonLinearIterations(10);
    system.SetMaxNumberOfLinearIterations(3);
    system.SetAbsoluteLinearConvergenceTolerance(1.e-12);
    system.SetNonLinearConvergenceTolerance(1.e-8);
    system.SetMgType(F_CYCLE);

    system.SetNumberPreSmoothingStep(0);
    system.SetNumberPostSmoothingStep(2);
    // initilaize and solve the system
    system.init();

    system.SetSolverFineGrids(GMRES);
    system.SetPreconditionerFineGrids(ILU_PRECOND);
    system.SetTolerances(1.e-3, 1.e-20, 1.e+50, 5);

    system.SetNumberOfSchurVariables(1);
    system.SetElementBlockNumber(4);
   
    system.MGsolve();
    
    GetError(&mlSol);
    
    std::pair< double , double > norm = GetError (&mlSol);
      H1normE[i][0]  = norm.first;
      H1norm[i][0] = norm.second;
    
    // print solutions
    std::vector < std::string > variablesToBePrinted;
    variablesToBePrinted.push_back("All");
    VTKWriter vtkIO(&mlSol);
    vtkIO.SetDebugOutput(true);
    vtkIO.Write(DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted);
    
    //refine the mesh
    MeshRefinement meshcoarser(*mlMsh.GetLevel(numberOfUniformLevels-1));
    bool elementsHaveBeenRefined = meshcoarser.FlagElementsToBeRefined(0.005, mlSol.GetSolutionLevel(numberOfUniformLevels-1)->GetSolutionName("Error"));  //non-uniform
    
    //bool elementsHaveBeenRefined = true; //uniform
    //meshcoarser.FlagAllElementsToBeRefined();//uniform
    if( !elementsHaveBeenRefined ){
      std::cout << " the solution has converged\n"; 
      maxNumberOfMeshes = i + 1;
      break;
    }
    mlMsh.AddAMRMeshLevel();
    mlSol.AddSolutionLevel();
    mlSol.RefineSolution(numberOfUniformLevels);
    //}
    numberOfUniformLevels += 1;
    
    

  }
  
  
  // print the seminorm of the error and the order of convergence between different levels
  std::cout << std::endl;
  std::cout << std::endl;
  std::cout << "H1 ERROR and ORDER OF CONVERGENCE:\n\n";
  std::cout << "LEVEL \n";

  for (unsigned i = 0; i < maxNumberOfMeshes; i++) {
    std::cout << i + 1 << "\t";
    std::cout.precision (14);

    //for (unsigned j = 0; j < 3; j++) {
      std::cout << H1normE[i][0] << "\t";
    //}

    std::cout << std::endl;

    if (i < maxNumberOfMeshes - 1) {
      std::cout.precision(3);
      std::cout << "\t\t";

      //for (unsigned j = 0; j < 3; j++) {
        std::cout << log(H1normE[i][0] / H1normE[i + 1][0]) / log(2.) << "\t\t\t";
      //}

      std::cout << std::endl;
    }     


  }

  std::cout << std::endl;
  std::cout << std::endl;
  std::cout << "H1 Relative ERROR and ORDER OF CONVERGENCE:\n\n";
  std::cout << "LEVEL \n";

  for (unsigned i = 0; i < maxNumberOfMeshes; i++) {
    std::cout << i + 1 << "\t";
    std::cout.precision (14);

    //for (unsigned j = 0; j < 3; j++) {
      std::cout << H1normE[i][0] / H1norm[i][0] << "\t";
    //}

    std::cout << std::endl;



  }


   mlMsh.PrintInfo();
  
  return 0;
}