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; }
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; }
int main ( int argc, char** argv ) { // init Petsc-MPI communicator FemusInit mpinit ( argc, argv, MPI_COMM_WORLD ); MultiLevelMesh mlMsh; double scalingFactor = 1.; unsigned numberOfSelectiveLevels = 0; // mlMsh.ReadCoarseMesh ( "../input/nonlocal_boundary_test.neu", "second", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/interface.neu", "second", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/maxTest1.neu", "eighth", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/maxTest2.neu", "second", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/maxTest3.neu", "second", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/maxTest4.neu", "eighth", scalingFactor ); mlMsh.ReadCoarseMesh ( "../input/maxTest5.neu", "eighth", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/maxTest6.neu", "eighth", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/maxTest7.neu", "eighth", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/maxTest8.neu", "eighth", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/maxTest9.neu", "eighth", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/maxTest10.neu", "eighth", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/maxTest2Continuous.neu", "second", scalingFactor ); //mlMsh.ReadCoarseMesh ( "../input/martaTest0.neu", "second", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/martaTest1.neu", "second", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/martaTest2.neu", "second", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/martaTest3.neu", "second", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/martaTest4.neu", "second", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/martaTest5.neu", "fifth", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/martaTest7.neu", "fifth", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/martaTest8.neu", "fifth", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/martaTest9.neu", "fifth", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/martaTest4Coarser.neu", "second", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/trial1.neu", "second", scalingFactor ); // mlMsh.ReadCoarseMesh ( "../input/trial2.neu", "second", scalingFactor ); mlMsh.RefineMesh ( numberOfUniformLevels + numberOfSelectiveLevels, numberOfUniformLevels , NULL ); mlMsh.EraseCoarseLevels ( numberOfUniformLevels - 1 ); // numberOfUniformLevels = 1; unsigned dim = mlMsh.GetDimension(); MultiLevelSolution mlSol ( &mlMsh ); // add variables to mlSol mlSol.AddSolution ( "u", LAGRANGE, FIRST, 2 ); mlSol.AddSolution ( "u_local", LAGRANGE, FIRST, 2 ); mlSol.AddSolution ( "u_exact", LAGRANGE, FIRST, 2 ); mlSol.Initialize ( "All" ); mlSol.Initialize ( "u_exact", InitalValueU ); mlSol.AttachSetBoundaryConditionFunction ( SetBoundaryCondition ); // ******* Set boundary conditions ******* mlSol.GenerateBdc ( "All" ); //BEGIN assemble and solve nonlocal problem MultiLevelProblem ml_prob ( &mlSol ); // ******* Add FEM system to the MultiLevel problem ******* LinearImplicitSystem& system = ml_prob.add_system < LinearImplicitSystem > ( "NonLocal" ); system.AddSolutionToSystemPDE ( "u" ); // ******* System FEM Assembly ******* system.SetAssembleFunction ( AssembleNonLocalSys ); system.SetMaxNumberOfLinearIterations ( 1 ); // ******* set MG-Solver ******* system.SetMgType ( V_CYCLE ); system.SetAbsoluteLinearConvergenceTolerance ( 1.e-50 ); // system.SetNonLinearConvergenceTolerance(1.e-9); // system.SetMaxNumberOfNonLinearIterations(20); system.SetNumberPreSmoothingStep ( 1 ); system.SetNumberPostSmoothingStep ( 1 ); // ******* Set Preconditioner ******* system.SetLinearEquationSolverType ( FEMuS_DEFAULT ); system.SetSparsityPatternMinimumSize ( 500u ); //TODO tune system.init(); // ******* Set Smoother ******* system.SetSolverFineGrids ( GMRES ); system.SetPreconditionerFineGrids ( ILU_PRECOND ); system.SetTolerances ( 1.e-20, 1.e-20, 1.e+50, 100 ); // ******* Solution ******* system.MGsolve(); //END assemble and solve nonlocal problem //BEGIN assemble and solve local problem MultiLevelProblem ml_prob2 ( &mlSol ); // ******* Add FEM system to the MultiLevel problem ******* LinearImplicitSystem& system2 = ml_prob2.add_system < LinearImplicitSystem > ( "Local" ); system2.AddSolutionToSystemPDE ( "u_local" ); // ******* System FEM Assembly ******* system2.SetAssembleFunction ( AssembleLocalSys ); system2.SetMaxNumberOfLinearIterations ( 1 ); // ******* set MG-Solver ******* system2.SetMgType ( V_CYCLE ); system2.SetAbsoluteLinearConvergenceTolerance ( 1.e-50 ); system2.SetNumberPreSmoothingStep ( 1 ); system2.SetNumberPostSmoothingStep ( 1 ); // ******* Set Preconditioner ******* system2.SetLinearEquationSolverType ( FEMuS_DEFAULT ); system2.init(); // ******* Set Smoother ******* system2.SetSolverFineGrids ( GMRES ); system2.SetPreconditionerFineGrids ( ILU_PRECOND ); system2.SetTolerances ( 1.e-20, 1.e-20, 1.e+50, 100 ); // ******* Solution ******* system2.MGsolve(); //END assemble and solve local problem //BEGIN compute errors GetL2Norm ( ml_prob, ml_prob2 ); //END compute errors // ******* Print solution ******* mlSol.SetWriter ( VTK ); std::vector<std::string> print_vars; print_vars.push_back ( "All" ); mlSol.GetWriter()->SetDebugOutput ( true ); mlSol.GetWriter()->Write ( DEFAULT_OUTPUTDIR, "biquadratic", print_vars, 0 ); return 0; } //end main