本文整理汇总了C++中MultiLevelMesh::AddAMRMeshLevel方法的典型用法代码示例。如果您正苦于以下问题:C++ MultiLevelMesh::AddAMRMeshLevel方法的具体用法?C++ MultiLevelMesh::AddAMRMeshLevel怎么用?C++ MultiLevelMesh::AddAMRMeshLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MultiLevelMesh
的用法示例。
在下文中一共展示了MultiLevelMesh::AddAMRMeshLevel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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;
//.........这里部分代码省略.........
示例2: main
//.........这里部分代码省略.........
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;
}