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/square_quad.neu", "seventh", scalingFactor); /* "seventh" is the order of accuracy that is used in the gauss integration scheme probably in the future it is not going to be an argument of this function */ unsigned maxNumberOfMeshes = 5; vector < vector < double > > l2Norm; l2Norm.resize(maxNumberOfMeshes); vector < vector < double > > semiNorm; semiNorm.resize(maxNumberOfMeshes); for (unsigned i = 0; i < maxNumberOfMeshes; i++) { // loop on the mesh level unsigned numberOfUniformLevels = i + 1; unsigned numberOfSelectiveLevels = 0; mlMsh.RefineMesh( numberOfUniformLevels + numberOfSelectiveLevels, numberOfUniformLevels , NULL); // erase all the coarse mesh levels mlMsh.EraseCoarseLevels(numberOfUniformLevels - 1); // 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++) { // loop on the FE Order std::cout << "level = " << i << " FEM = " << j << std::endl; // define the multilevel solution and attach the mlMsh object to it MultiLevelSolution mlSol(&mlMsh); // add variables to mlSol mlSol.AddSolution("u", LAGRANGE, feOrder[j]); mlSol.AddSolution("v", LAGRANGE, feOrder[j]); mlSol.Initialize("All"); // attach the boundary condition function and generate boundary data mlSol.AttachSetBoundaryConditionFunction(SetBoundaryCondition); mlSol.GenerateBdc("u"); mlSol.GenerateBdc("v"); // 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"); // attach the assembling function to system system.SetAssembleFunction(AssembleBilaplaceProblem_AD); // initilaize and solve the system system.init(); 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.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 = 0; 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; if (i < maxNumberOfMeshes - 1) { std::cout.precision(3); std::cout << "\t\t"; for (unsigned j = 0; j < 3; j++) { std::cout << log(l2Norm[i][j] / l2Norm[i + 1][j]) / log(2.) << "\t\t\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 = 0; 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; if (i < maxNumberOfMeshes - 1) { std::cout.precision(3); std::cout << "\t\t"; for (unsigned j = 0; j < 3; j++) { std::cout << log(semiNorm[i][j] / semiNorm[i + 1][j]) / log(2.) << "\t\t\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 ); /* "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); // erase all the coarse mesh levels mlMsh.EraseCoarseLevels(numberOfUniformLevels - 1); // print mesh info mlMsh.PrintInfo(); MultiLevelSolution mlSol(&mlMsh); // add variables to mlSol mlSol.AddSolution("U", LAGRANGE, SECOND); mlSol.AddSolution("V", LAGRANGE, SECOND); if (dim == 3) mlSol.AddSolution("W", LAGRANGE, SECOND); mlSol.AddSolution("P", LAGRANGE, FIRST); 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 > ("NS"); // add solution "u" to system system.AddSolutionToSystemPDE("U"); system.AddSolutionToSystemPDE("V"); if (dim == 3) system.AddSolutionToSystemPDE("W"); system.AddSolutionToSystemPDE("P"); // attach the assembling function to system system.SetAssembleFunction(AssembleBoussinesqAppoximation_AD); // initilaize and solve the system system.init(); system.solve(); // print solutions std::vector < std::string > variablesToBePrinted; variablesToBePrinted.push_back("All"); VTKWriter vtkIO(&mlSol); vtkIO.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
int main(int argc, char** args) { // init Petsc-MPI communicator FemusInit mpinit(argc, args, MPI_COMM_WORLD); // define multilevel mesh unsigned maxNumberOfMeshes; maxNumberOfMeshes = 1; vector < vector < double > > l2Norm; l2Norm.resize(maxNumberOfMeshes); vector < vector < double > > semiNorm; semiNorm.resize(maxNumberOfMeshes); for (unsigned i = 0; i < maxNumberOfMeshes; i++) { // loop on the mesh level std::ostringstream filename; filename << "./input/sphere.neu"; MultiLevelMesh mlMsh; // read coarse level mesh and generate finers level meshes double scalingFactor = 2.; //mlMsh.ReadCoarseMesh("./input/circle_quad.neu","seventh", scalingFactor); mlMsh.ReadCoarseMesh(filename.str().c_str(), "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 = 4; unsigned numberOfSelectiveLevels = 0; mlMsh.RefineMesh(numberOfUniformLevels , numberOfUniformLevels + numberOfSelectiveLevels, NULL); // erase all the coarse mesh levels mlMsh.EraseCoarseLevels(numberOfUniformLevels - 1); // print mesh info mlMsh.PrintInfo(); FEOrder feOrder = SECOND; l2Norm[i].resize(1); semiNorm[i].resize(1); // define the multilevel solution and attach the mlMsh object to it MultiLevelSolution mlSol(&mlMsh); // add variables to mlSol mlSol.AddSolution("X", LAGRANGE, feOrder, 2); mlSol.AddSolution("Y", LAGRANGE, feOrder, 2); mlSol.AddSolution("Z", LAGRANGE, feOrder, 2); mlSol.AddSolution("H", LAGRANGE, feOrder, 2); mlSol.Initialize("X", InitalValueXTorus); mlSol.Initialize("Y", InitalValueYTorus); mlSol.Initialize("Z", InitalValueZTorus); mlSol.Initialize("H", InitalValueHTorus); // attach the boundary condition function and generate boundary data mlSol.AttachSetBoundaryConditionFunction(SetBoundaryConditionTorus); // mlSol.Initialize("X", InitalValueXSphere); // mlSol.Initialize("Y", InitalValueYSphere); // mlSol.Initialize("Z", InitalValueZSphere); // mlSol.Initialize("H", InitalValueHSphere); // // attach the boundary condition function and generate boundary data // mlSol.AttachSetBoundaryConditionFunction(SetBoundaryConditionSphere); mlSol.GenerateBdc("X", "Steady"); mlSol.GenerateBdc("Y", "Steady"); mlSol.GenerateBdc("Z", "Steady"); mlSol.GenerateBdc("H", "Steady"); // define the multilevel problem attach the mlSol object to it MultiLevelProblem mlProb(&mlSol); // add system Wilmore in mlProb as a Linear Implicit System TransientNonlinearImplicitSystem& system = mlProb.add_system < TransientNonlinearImplicitSystem > ("Willmore"); // add solution "X", "Y", "Z" and "H" to the system system.AddSolutionToSystemPDE("X"); system.AddSolutionToSystemPDE("Y"); system.AddSolutionToSystemPDE("Z"); system.AddSolutionToSystemPDE("H"); system.SetMaxNumberOfNonLinearIterations(6); // attach the assembling function to system system.SetAssembleFunction(AssembleWillmoreFlow_AD); // initilaize and solve the system system.init(); std::vector < std::string > variablesToBePrinted; variablesToBePrinted.push_back("All"); std::vector < std::string > surfaceVariables; surfaceVariables.push_back("X"); surfaceVariables.push_back("Y"); surfaceVariables.push_back("Z"); VTKWriter vtkIO(&mlSol); vtkIO.SetSurfaceVariables(surfaceVariables); GMVWriter gmvIO(&mlSol); gmvIO.SetSurfaceVariables(surfaceVariables); gmvIO.SetDebugOutput(true); // time loop parameter system.AttachGetTimeIntervalFunction(SetVariableTimeStep); const unsigned int n_timesteps = 1; vtkIO.Write(DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted, 0); gmvIO.Write(DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted, 0); system.SetMgType(V_CYCLE); for (unsigned time_step = 0; time_step < n_timesteps; time_step++) { if (time_step > 0) system.SetMgType(V_CYCLE); system.CopySolutionToOldSolution(); system.MGsolve(); vtkIO.Write(DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted, time_step + 1); gmvIO.Write(DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted, time_step + 1); } /* 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"); std::vector < std::string > surfaceVariables; surfaceVariables.push_back("X"); surfaceVariables.push_back("Y"); surfaceVariables.push_back("Z"); VTKWriter vtkIO(&mlSol); vtkIO.SetSurfaceVariables(surfaceVariables); vtkIO.write(DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted, i); GMVWriter gmvIO(&mlSol); gmvIO.SetSurfaceVariables(surfaceVariables); gmvIO.SetDebugOutput(true); gmvIO.Pwrite(DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted, i); */ } // std::vector < std::string > variablesToBePrinted; // variablesToBePrinted.push_back("All"); // // std::vector < std::string > surfaceVariables; // surfaceVariables.push_back("X"); // surfaceVariables.push_back("Y"); // surfaceVariables.push_back("Z"); // // VTKWriter vtkIO(&mlSol); // vtkIO.SetSurfaceVariables(surfaceVariables); // // GMVWriter gmvIO(&mlSol); // gmvIO.SetSurfaceVariables(surfaceVariables); // gmvIO.SetDebugOutput(true); // // // time loop parameter // //system.AttachGetTimeIntervalFunction(SetVariableTimeStep); // const unsigned int n_timesteps = 500; // // vtkIO.write(DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted, 0); // gmvIO.Pwrite(DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted, 0); // // //system.SetMgType(F_CYCLE); // // for (unsigned time_step = 0; time_step < n_timesteps; time_step++) { // // //if( time_step > 0 ) // //system.SetMgType(V_CYCLE); // // system.MGsolve(); // // //system.UpdateSolution(); // // // vtkIO.write(DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted, time_step+1); // gmvIO.Pwrite(DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted, time_step+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 << "l2 ERROR and ORDER OF CONVERGENCE:\n\n"; // std::cout << "LEVEL\tFIRST\t\t\tSERENDIPITY\t\tSECOND\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 << l2Norm[i][j] << "\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(l2Norm[i][j] / l2Norm[i + 1][j]) / log(2.) << "\t\t\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 = 0; 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; // // if (i < maxNumberOfMeshes - 1) { // std::cout.precision(3); // std::cout << "\t\t"; // // for (unsigned j = 0; j < 3; j++) { // std::cout << log(semiNorm[i][j] / semiNorm[i + 1][j]) / log(2.) << "\t\t\t"; // } // // std::cout << std::endl; // } // // } return 0; }
int main(int argc, char** args) { unsigned precType = 0; if (argc >= 2) { Miu = strtod(args[1], NULL); std::cout << Miu << std::endl; } // 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/quad_square.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 = 8; unsigned numberOfSelectiveLevels = 0; mlMsh.RefineMesh(numberOfUniformLevels + numberOfSelectiveLevels, numberOfUniformLevels, SetRefinementFlag); // mlMsh.RefineMesh(numberOfUniformLevels , numberOfUniformLevels + numberOfSelectiveLevels, NULL); // erase all the coarse mesh levels mlMsh.EraseCoarseLevels(3); // print mesh info mlMsh.PrintInfo(); MultiLevelSolution mlSol(&mlMsh); // add variables to mlSol mlSol.AddSolution("U", LAGRANGE, SECOND); mlSol.AddSolution("V", LAGRANGE, SECOND); if (dim == 3) mlSol.AddSolution("W", LAGRANGE, SECOND); mlSol.AddSolution("P", DISCONTINUOUS_POLYNOMIAL, FIRST); mlSol.AssociatePropertyToSolution("P", "Pressure"); mlSol.Initialize("All"); // mlSol.Initialize("U", InitalValueU); // attach the boundary condition function and generate boundary data mlSol.AttachSetBoundaryConditionFunction(SetBoundaryCondition); mlSol.FixSolutionAtOnePoint("P"); 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 > ("NS"); // add solution "u" to system system.AddSolutionToSystemPDE("U"); system.AddSolutionToSystemPDE("V"); if (dim == 3) system.AddSolutionToSystemPDE("W"); system.AddSolutionToSystemPDE("P"); //system.SetLinearEquationSolverType(FEMuS_DEFAULT); system.SetLinearEquationSolverType(FEMuS_ASM); // attach the assembling function to system system.SetAssembleFunction(AssembleBoussinesqAppoximation); system.SetMaxNumberOfNonLinearIterations(20); system.SetNonLinearConvergenceTolerance(1.e-8); //system.SetMaxNumberOfResidualUpdatesForNonlinearIteration(10); //system.SetResidualUpdateConvergenceTolerance(1.e-15); system.SetMaxNumberOfLinearIterations(1); system.SetAbsoluteLinearConvergenceTolerance(1.e-15); system.SetMgType(V_CYCLE); system.SetNumberPreSmoothingStep(1); system.SetNumberPostSmoothingStep(1); // initilaize and solve the system system.init(); system.SetSolverFineGrids(RICHARDSON); system.SetPreconditionerFineGrids(MLU_PRECOND); system.SetTolerances(1.e-5, 1.e-8, 1.e+50, 30, 30); //GMRES tolerances system.ClearVariablesToBeSolved(); system.AddVariableToBeSolved("All"); system.SetNumberOfSchurVariables(1); system.SetElementBlockNumber("All"); system.MGsolve(); // print solutions std::vector < std::string > variablesToBePrinted; variablesToBePrinted.push_back("All"); VTKWriter vtkIO(&mlSol); vtkIO.Write(DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted); mlMsh.PrintInfo(); char *stdOutfile = new char[100]; char *outfile = new char[100]; sprintf(stdOutfile, "trueResidualMiu=%s.txt", args[1]); sprintf(outfile, "convergenceMiu=%s.txt", args[1]); std::cout << stdOutfile << std::endl; PrintConvergenceInfo(stdOutfile, outfile, numberOfUniformLevels); return 0; }
int main(int argc, char** args) { unsigned precType = 0; if(argc >= 2) { if(!strcmp("FS_VT", args[1])) precType = FS_VTp; else if(!strcmp("FS_TV", args[1])) precType = FS_TVp; else if(!strcmp("ASM_VT", args[1])) precType = ASM_VTp; else if(!strcmp("ASM_TV", args[1])) precType = ASM_TVp; else if(!strcmp("ILU_VT", args[1])) precType = ILU_VTp; if(!strcmp("ILU_TV", args[1])) precType = ILU_TVp; if(precType == 0) { std::cout << "wrong input arguments!" << std::endl; abort(); } } else { std::cout << "No input argument set default preconditioner = NS+T" << std::endl; precType = FS_VTp; } if(argc >= 3) { Prandtl = strtod(args[2], NULL); std::cout << Prandtl << std::endl; } if(argc >= 4) { Rayleigh = strtod(args[3], NULL); std::cout << Rayleigh << std::endl; } // 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/rectangle_w4_h1.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 = 7; unsigned numberOfSelectiveLevels = 0; mlMsh.RefineMesh(numberOfUniformLevels , numberOfUniformLevels + numberOfSelectiveLevels, NULL); // erase all the coarse mesh levels //mlMsh.EraseCoarseLevels(numberOfUniformLevels - 3); mlMsh.EraseCoarseLevels(3); // print mesh info mlMsh.PrintInfo(); MultiLevelSolution mlSol(&mlMsh); // add variables to mlSol mlSol.AddSolution("T", LAGRANGE, SERENDIPITY, 2); mlSol.AddSolution("U", LAGRANGE, SECOND, 2); mlSol.AddSolution("V", LAGRANGE, SECOND, 2); if(dim == 3) mlSol.AddSolution("W", LAGRANGE, SECOND, 2); //mlSol.AddSolution("P", LAGRANGE, FIRST); mlSol.AddSolution("P", DISCONTINUOUS_POLYNOMIAL, FIRST, 2); mlSol.AssociatePropertyToSolution("P", "Pressure"); mlSol.Initialize("All"); mlSol.Initialize("T", InitalValueT); // attach the boundary condition function and generate boundary data mlSol.AttachSetBoundaryConditionFunction(SetBoundaryCondition); mlSol.FixSolutionAtOnePoint("P"); mlSol.GenerateBdc("U"); mlSol.GenerateBdc("V"); mlSol.GenerateBdc("P"); mlSol.GenerateBdc("T", "Time_dependent"); // define the multilevel problem attach the mlSol object to it MultiLevelProblem mlProb(&mlSol); // add system Poisson in mlProb as a Linear Implicit System TransientNonlinearImplicitSystem& system = mlProb.add_system < TransientNonlinearImplicitSystem > ("NS"); if(precType == FS_TVp || precType == ASM_TVp || precType == ILU_TVp) system.AddSolutionToSystemPDE("T"); // add solution "u" to system system.AddSolutionToSystemPDE("U"); system.AddSolutionToSystemPDE("V"); if(precType == ASM_VTp) system.AddSolutionToSystemPDE("T"); if(dim == 3) system.AddSolutionToSystemPDE("W"); system.AddSolutionToSystemPDE("P"); if(precType == FS_VTp || precType == ILU_VTp) system.AddSolutionToSystemPDE("T"); //BEGIN buid fieldSplitTree (only for FieldSplitPreconditioner) std::vector < unsigned > fieldUVP(3); fieldUVP[0] = system.GetSolPdeIndex("U"); fieldUVP[1] = system.GetSolPdeIndex("V"); fieldUVP[2] = system.GetSolPdeIndex("P"); std::vector < unsigned > solutionTypeUVP(3); solutionTypeUVP[0] = mlSol.GetSolutionType("U"); solutionTypeUVP[1] = mlSol.GetSolutionType("V"); solutionTypeUVP[2] = mlSol.GetSolutionType("P"); FieldSplitTree FS_NS(PREONLY, ASM_PRECOND, fieldUVP, solutionTypeUVP, "Navier-Stokes"); FS_NS.SetAsmBlockSize(4); FS_NS.SetAsmNumeberOfSchurVariables(1); std::vector < unsigned > fieldT(1); fieldT[0] = system.GetSolPdeIndex("T"); std::vector < unsigned > solutionTypeT(1); solutionTypeT[0] = mlSol.GetSolutionType("T"); FieldSplitTree FS_T(PREONLY, ASM_PRECOND, fieldT, solutionTypeT, "Temperature"); FS_T.SetAsmBlockSize(4); FS_T.SetAsmNumeberOfSchurVariables(0); // why here change 1 to 0 std::vector < FieldSplitTree *> FS2; FS2.reserve(2); if(precType == FS_VTp) FS2.push_back(&FS_NS); //Navier-Stokes block first FS2.push_back(&FS_T); if(precType == FS_TVp) FS2.push_back(&FS_NS); //Navier-Stokes block last FieldSplitTree FS_NST(RICHARDSON, FIELDSPLIT_PRECOND, FS2, "Benard"); //END buid fieldSplitTree if(precType == FS_VTp || precType == FS_TVp) system.SetLinearEquationSolverType(FEMuS_FIELDSPLIT); // Field-Split preconditioned else if(precType == ASM_VTp || precType == ASM_TVp) system.SetLinearEquationSolverType(FEMuS_ASM); // Additive Swartz preconditioner else if(precType == ILU_VTp || precType == ILU_TVp) system.SetLinearEquationSolverType(FEMuS_DEFAULT); // attach the assembling function to system system.SetAssembleFunction(AssembleBoussinesqAppoximation_AD); system.SetMaxNumberOfNonLinearIterations(10); system.SetNonLinearConvergenceTolerance(1.e-8); //system.SetMaxNumberOfResidualUpdatesForNonlinearIteration(2); //system.SetResidualUpdateConvergenceTolerance(1.e-12); // system.SetMaxNumberOfLinearIterations(1); // system.SetAbsoluteLinearConvergenceTolerance(1.e-15); system.SetMgType(F_CYCLE); system.SetNumberPreSmoothingStep(1); system.SetNumberPostSmoothingStep(1); // initilaize and solve the system system.init(); system.SetSolverFineGrids(RICHARDSON); system.SetPreconditionerFineGrids(ILU_PRECOND); system.SetFieldSplitTree(&FS_NST); system.SetTolerances(1.e-5, 1.e-8, 1.e+50, 20, 20); system.ClearVariablesToBeSolved(); system.AddVariableToBeSolved("All"); system.SetNumberOfSchurVariables(1); system.SetElementBlockNumber(4); std::vector< double > x(3); x[0] = -1.9; //the marker is in element 117 (proc 1) x[1] = -0.4; x[2] = 0.; // print solutions std::vector < std::string > variablesToBePrinted; variablesToBePrinted.push_back("All"); VTKWriter vtkIO(&mlSol); vtkIO.Write(DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted, 0); double dt = 0.25; system.SetIntervalTime(dt); unsigned n_timesteps = 1200; Marker marker(x, 0., VOLUME, mlSol.GetLevel(numberOfUniformLevels - 1), 2, true); unsigned elem = marker.GetMarkerElement(); std::vector<double> xi; marker.GetMarkerLocalCoordinates(xi); char out_file1[100]=""; strcpy(out_file1,"Uvelocity.dat"); ofstream outfile1(out_file1,ios::out|ios::trunc|ios::binary); char out_file2[100]=""; strcpy(out_file2,"Vvelocity.dat"); ofstream outfile2(out_file2,ios::out|ios::trunc|ios::binary); char out_file3[100]=""; strcpy(out_file3,"Pressure.dat"); ofstream outfile3(out_file3,ios::out|ios::trunc|ios::binary); char out_file4[100]=""; strcpy(out_file4,"Temperature.dat"); ofstream outfile4(out_file4,ios::out|ios::trunc|ios::binary); /* double kineticEnergy; char out_file5[100]=""; strcpy(out_file5,"Energy.dat"); ofstream outfile5(out_file5,ios::out|ios::trunc|ios::binary); */ vector <double> solV_pt(2); vector <double> solPT_pt(2); vector <double> ptCoord(2); std::pair < vector <double>, vector <double> > out_value; for(unsigned time_step = 0; time_step < n_timesteps; time_step++) { if(time_step > 0) system.SetMgType(V_CYCLE); system.MGsolve(); system.CopySolutionToOldSolution(); out_value = GetVaribleValues(mlProb, elem, xi); solV_pt = out_value.first; solPT_pt = out_value.second; outfile1 << (time_step + 1) * dt <<" "<< solV_pt[0] << std::endl; outfile2 << (time_step + 1) * dt <<" "<< solV_pt[1] << std::endl; outfile3 << (time_step + 1) * dt <<" "<< solPT_pt[0] << std::endl; outfile4 << (time_step + 1) * dt <<" "<< solPT_pt[1] << std::endl; /* std::pair < double, vector <double> > out_value1 = GetKineandPointValue(&mlSol) ; kineticEnergy = out_value1.first; ptCoord = out_value1.second; outfile5 << (time_step + 1) * dt <<" "<< sqrt(kineticEnergy/2.0/8.0) << std::endl; */ if ((time_step + 1) % 10 ==0) vtkIO.Write(DEFAULT_OUTPUTDIR, "biquadratic", variablesToBePrinted, time_step + 1); } outfile1.close(); outfile2.close(); outfile3.close(); outfile4.close(); // outfile5.close(); mlMsh.PrintInfo(); char *stdOutfile1 = new char[100]; char *outfile6 = new char[100]; sprintf(stdOutfile1, "%sprintout_infoPr=%sRa=%s_time.txt", args[1], args[2], args[3]); sprintf(outfile6, "%scomputational_timePr=%sRa=%s_time.txt", args[1], args[2], args[3]); PrintNonlinearTime(n_timesteps,stdOutfile1, outfile6, numberOfUniformLevels); return 0; }