示例#1
0
文件: ex2.cpp 项目: FeMTTU/femus
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 , numberOfUniformLevels + numberOfSelectiveLevels, NULL);

  unsigned numberOfUniformLevels = 4;
  unsigned numberOfSelectiveLevels = 3;
  mlMsh.RefineMesh (numberOfUniformLevels + numberOfSelectiveLevels, numberOfUniformLevels , SetRefinementFlag);

  // erase all the coarse mesh levels
  //mlMsh.EraseCoarseLevels(numberOfUniformLevels - 3);

  // print mesh info
  mlMsh.PrintInfo();

  MultiLevelSolution mlSol (&mlMsh);

  // add variables to mlSol


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


  mlSol.Initialize ("All");

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

  mlSol.GenerateBdc ("All");

  // 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.AddSolutionToSystemPDE ("V");

  //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); // Q1 What's 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.SetDirichletBCsHandling(ELIMINATION);
  //system.solve();
  system.MGsolve();

  // print solutions
  std::vector < std::string > variablesToBePrinted;
  variablesToBePrinted.push_back ("All");

  VTKWriter vtkIO (&mlSol);
  vtkIO.Write (DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted);

  GMVWriter gmvIO (&mlSol);
  variablesToBePrinted.push_back ("all");
  gmvIO.SetDebugOutput (true);
  gmvIO.Write (DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted);


  return 0;
}
示例#2
0
文件: ex3.cpp 项目: rjayawar/femus
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 maxNumberOfMeshes = 5;


  vector < vector < double > > l2Norm;
  l2Norm.resize (maxNumberOfMeshes);

  vector < vector < double > > semiNorm;
  semiNorm.resize (maxNumberOfMeshes);

//   unsigned numberOfUniformLevels = 3;
//   unsigned numberOfSelectiveLevels = 0;
//   mlMsh.RefineMesh(numberOfUniformLevels , numberOfUniformLevels + numberOfSelectiveLevels, NULL);

  for (unsigned i = 1; i < maxNumberOfMeshes; i++) {

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

    // print mesh info
    mlMsh.PrintInfo();

    FEOrder feOrder[3] = {FIRST, SERENDIPITY, SECOND};
    l2Norm[i].resize (3);
    semiNorm[i].resize (3);

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

      MultiLevelSolution mlSol (&mlMsh);

      // add variables to mlSol

      mlSol.AddSolution("Flag",  DISCONTINOUS_POLYNOMIAL, ZERO);

      mlSol.AddSolution ("U", LAGRANGE, feOrder[j]);

      mlSol.Initialize ("All");

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

      mlSol.GenerateBdc ("All");

      // 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.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.SetDirichletBCsHandling(ELIMINATION);
      //system.solve();
      system.MGsolve();

      std::pair< double , double > norm = GetErrorNorm (&mlSol);
      l2Norm[i][j]  = norm.first;
      semiNorm[i][j] = 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, i);

//       GMVWriter gmvIO (&mlSol);
//       variablesToBePrinted.push_back ("all");
//       gmvIO.SetDebugOutput (true);
//       gmvIO.Write (DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted, i);

    }

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

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

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

    std::cout << std::endl;



  }

  std::cout << std::endl;
  std::cout << std::endl;
  std::cout << "SEMINORM ERROR and ORDER OF CONVERGENCE:\n\n";
  std::cout << "LEVEL\tFIRST\t\t\tSERENDIPITY\t\tSECOND\n";

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

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

    std::cout << std::endl;



  }

  return 0;
}