📄 ex15.php
字号:
<?php $root=""; ?><?php require($root."navigation.php"); ?><html><head> <?php load_style($root); ?></head> <body> <?php make_navigation("ex15",$root)?> <div class="content"><a name="comments"></a> <div class = "comment"><h1>Example 15 - Biharmonic Equation</h1><br><br>This example solves the Biharmonic equation on a square or cube,using a Galerkin formulation with C1 elements approximating theH^2_0 function space.The initial mesh contains two TRI6, one QUAD9 or one HEX27An input file named "ex15.in"is provided which allows the user to set several parameters forthe solution so that the problem can be re-run without are-compile. The solution technique employed is to have arefinement loop with a linear solve inside followed by arefinement of the grid and projection of the solution to the new gridIn the final loop iteration, there is no additionalrefinement after the solve. In the input file "ex15.in", the variable"max_r_steps" controls the number of refinement steps, and"max_r_level" controls the maximum element refinement level.<br><br>LibMesh include files.</div><div class ="fragment"><pre> #include "mesh.h" #include "equation_systems.h" #include "linear_implicit_system.h" #include "gmv_io.h" #include "fe.h" #include "quadrature.h" #include "dense_matrix.h" #include "dense_vector.h" #include "sparse_matrix.h" #include "mesh_generation.h" #include "mesh_modification.h" #include "mesh_refinement.h" #include "error_vector.h" #include "fourth_error_estimators.h" #include "getpot.h" #include "exact_solution.h" #include "dof_map.h" #include "numeric_vector.h" #include "elem.h" #include "tensor_value.h" </pre></div><div class = "comment">Function prototype. This is the function that will assemblethe linear system for our Biharmonic problem. Note that thefunction will take the \p EquationSystems object and thename of the system we are assembling as input. From the\p EquationSystems object we have acess to the \p Mesh andother objects we might need.</div><div class ="fragment"><pre> void assemble_biharmonic(EquationSystems& es, const std::string& system_name); </pre></div><div class = "comment">Prototypes for calculation of the exact solution. Necessaryfor setting boundary conditions.</div><div class ="fragment"><pre> Number exact_2D_solution(const Point& p, const Parameters&, // parameters, not needed const std::string&, // sys_name, not needed const std::string&); // unk_name, not needed); Number exact_3D_solution(const Point& p, const Parameters&, const std::string&, const std::string&); </pre></div><div class = "comment">Prototypes for calculation of the gradient of the exact solution. Necessary for setting boundary conditions in H^2_0 and testingH^1 convergence of the solution</div><div class ="fragment"><pre> Gradient exact_2D_derivative(const Point& p, const Parameters&, const std::string&, const std::string&); Gradient exact_3D_derivative(const Point& p, const Parameters&, const std::string&, const std::string&); Tensor exact_2D_hessian(const Point& p, const Parameters&, const std::string&, const std::string&); Tensor exact_3D_hessian(const Point& p, const Parameters&, const std::string&, const std::string&); Number forcing_function_2D(const Point& p); Number forcing_function_3D(const Point& p); </pre></div><div class = "comment">Pointers to dimension-independent functions</div><div class ="fragment"><pre> Number (*exact_solution)(const Point& p, const Parameters&, const std::string&, const std::string&); Gradient (*exact_derivative)(const Point& p, const Parameters&, const std::string&, const std::string&); Tensor (*exact_hessian)(const Point& p, const Parameters&, const std::string&, const std::string&); Number (*forcing_function)(const Point& p); int main(int argc, char** argv) {</pre></div><div class = "comment">Initialize libMesh.</div><div class ="fragment"><pre> libMesh::init (argc, argv); #ifndef ENABLE_AMR std::cerr << "ERROR: This example requires libMesh to be\n" << "compiled with AMR support!" << std::endl; return 0; #else #ifndef ENABLE_SECOND_DERIVATIVES std::cerr << "ERROR: This example requires the library to be " << "compiled with second derivatives support!" << std::endl; return 0; #else { </pre></div><div class = "comment">Parse the input file</div><div class ="fragment"><pre> GetPot input_file("ex15.in"); </pre></div><div class = "comment">Read in parameters from the input file</div><div class ="fragment"><pre> const unsigned int max_r_level = input_file("max_r_level", 10); const unsigned int max_r_steps = input_file("max_r_steps", 4); const std::string approx_type = input_file("approx_type", "HERMITE"); const unsigned int uniform_refine = input_file("uniform_refine", 0); const Real refine_percentage = input_file("refine_percentage", 0.5); const Real coarsen_percentage = input_file("coarsen_percentage", 0.5); const unsigned int dim = input_file("dimension", 2); const unsigned int max_linear_iterations = input_file("max_linear_iterations", 10000); </pre></div><div class = "comment">We have only defined 2 and 3 dimensional problems</div><div class ="fragment"><pre> assert (dim == 2 || dim == 3); </pre></div><div class = "comment">Currently only the Hermite cubics give a 3D C^1 basis</div><div class ="fragment"><pre> assert (dim == 2 || approx_type == "HERMITE"); </pre></div><div class = "comment">Create a dim-dimensional mesh.</div><div class ="fragment"><pre> Mesh mesh (dim); </pre></div><div class = "comment">Output file for plotting the error </div><div class ="fragment"><pre> std::string output_file = ""; if (dim == 2) output_file += "2D_"; else if (dim == 3) output_file += "3D_"; if (approx_type == "HERMITE") output_file += "hermite_"; else if (approx_type == "SECOND") output_file += "reducedclough_"; else output_file += "clough_"; if (uniform_refine == 0) output_file += "adaptive"; else output_file += "uniform"; std::string gmv_file = output_file; gmv_file += ".gmv"; output_file += ".m"; std::ofstream out (output_file.c_str()); out << "% dofs L2-error H1-error H2-error\n" << "e = [\n"; </pre></div><div class = "comment">Set up the dimension-dependent coarse mesh and solutionWe build more than one cell so as to avoid bugs on fewer than 4 processors in 2D or 8 in 3D.</div><div class ="fragment"><pre> if (dim == 2) { MeshTools::Generation::build_square(mesh, 2, 2); exact_solution = &exact_2D_solution; exact_derivative = &exact_2D_derivative; exact_hessian = &exact_2D_hessian; forcing_function = &forcing_function_2D; } else if (dim == 3) { MeshTools::Generation::build_cube(mesh, 2, 2, 2); exact_solution = &exact_3D_solution; exact_derivative = &exact_3D_derivative; exact_hessian = &exact_3D_hessian; forcing_function = &forcing_function_3D; } </pre></div><div class = "comment">Convert the mesh to second order: necessary for computing withClough-Tocher elements, useful for getting slightly less broken gmv output with Hermite elements</div><div class ="fragment"><pre> mesh.all_second_order(); </pre></div><div class = "comment">Convert it to triangles if necessary</div><div class ="fragment"><pre> if (approx_type != "HERMITE") MeshTools::Modification::all_tri(mesh); </pre></div><div class = "comment">Mesh Refinement object</div><div class ="fragment"><pre> MeshRefinement mesh_refinement(mesh); mesh_refinement.refine_fraction() = refine_percentage; mesh_refinement.coarsen_fraction() = coarsen_percentage; mesh_refinement.max_h_level() = max_r_level; </pre></div><div class = "comment">Create an equation systems object.</div><div class ="fragment"><pre> EquationSystems equation_systems (mesh); </pre></div><div class = "comment">Declare the system and its variables.</div><div class ="fragment"><pre> {</pre></div><div class = "comment">Creates a system named "Biharmonic"</div><div class ="fragment"><pre> LinearImplicitSystem& system = equation_systems.add_system<LinearImplicitSystem> ("Biharmonic"); </pre></div><div class = "comment">Adds the variable "u" to "Biharmonic". "u"will be approximated using Hermite tensor product squaresor (possibly reduced) cubic Clough-Tocher triangles</div><div class ="fragment"><pre> if (approx_type == "HERMITE") system.add_variable("u", THIRD, HERMITE); else if (approx_type == "SECOND") system.add_variable("u", SECOND, CLOUGH); else if (approx_type == "CLOUGH") system.add_variable("u", THIRD, CLOUGH); else error(); </pre></div><div class = "comment">Give the system a pointer to the matrix assemblyfunction.</div><div class ="fragment"><pre> system.attach_assemble_function (assemble_biharmonic); </pre></div><div class = "comment">Initialize the data structures for the equation system.</div><div class ="fragment"><pre> equation_systems.init(); </pre></div><div class = "comment">Set linear solver max iterations</div>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -