📄 ex5.php
字号:
<?php $root=""; ?><?php require($root."navigation.php"); ?><html><head> <?php load_style($root); ?></head> <body> <?php make_navigation("ex5",$root)?> <div class="content"><a name="comments"></a> <div class = "comment"><h1>Example 5 - Run-Time Quadrature Rule Selection</h1><br><br>This is the fifth example program. It builds onthe previous two examples, and extends the useof the \p AutoPtr as a convenient build method todetermine the quadrature rule at run time.<br><br><br><br>C++ include files that we need</div><div class ="fragment"><pre> #include <iostream> #include <sstream> #include <algorithm> #include <math.h> </pre></div><div class = "comment">Basic include file needed for the mesh functionality.</div><div class ="fragment"><pre> #include "libmesh.h" #include "mesh.h" #include "mesh_generation.h" #include "gmv_io.h" #include "linear_implicit_system.h" #include "equation_systems.h" </pre></div><div class = "comment">Define the Finite Element object.</div><div class ="fragment"><pre> #include "fe.h" </pre></div><div class = "comment">Define the base quadrature class, with whichspecialized quadrature rules will be built.</div><div class ="fragment"><pre> #include "quadrature.h" </pre></div><div class = "comment">Include the namespace \p QuadratureRules forsome handy descriptions.</div><div class ="fragment"><pre> #include "quadrature_rules.h" </pre></div><div class = "comment">Define useful datatypes for finite elementmatrix and vector components.</div><div class ="fragment"><pre> #include "sparse_matrix.h" #include "numeric_vector.h" #include "dense_matrix.h" #include "dense_vector.h" </pre></div><div class = "comment">Define the DofMap, which handles degree of freedomindexing.</div><div class ="fragment"><pre> #include "dof_map.h" </pre></div><div class = "comment">The definition of a geometric element</div><div class ="fragment"><pre> #include "elem.h" </pre></div><div class = "comment">Function prototype, as before.</div><div class ="fragment"><pre> void assemble_poisson(EquationSystems& es, const std::string& system_name); </pre></div><div class = "comment">Exact solution function prototype, as before.</div><div class ="fragment"><pre> Real exact_solution (const Real x, const Real y, const Real z = 0.); </pre></div><div class = "comment">The quadrature type the user requests.</div><div class ="fragment"><pre> QuadratureType quad_type=INVALID_Q_RULE; </pre></div><div class = "comment">Begin the main program.</div><div class ="fragment"><pre> int main (int argc, char** argv) { </pre></div><div class = "comment">Initialize libMesh and any dependent libaries, like in example 2.</div><div class ="fragment"><pre> libMesh::init (argc, argv); </pre></div><div class = "comment">Braces are used to force object scope, like in example 2 </div><div class ="fragment"><pre> {</pre></div><div class = "comment">Check for proper usage. The quadrature rulemust be given at run time.</div><div class ="fragment"><pre> if (argc < 3) { std::cerr << "Usage: " << argv[0] << " -q n" << std::endl; std::cerr << " where n stands for:" << std::endl; </pre></div><div class = "comment">Note that only some of all quadrature rules arevalid choices. For example, the Jacobi quadratureis actually a "helper" for higher-order rules,included in QGauss.</div><div class ="fragment"><pre> for (unsigned int n=0; n<QuadratureRules::num_valid_elem_rules; n++) std::cerr << " " << QuadratureRules::valid_elem_rules[n] << " " << QuadratureRules::name(QuadratureRules::valid_elem_rules[n]) << std::endl; std::cerr << std::endl; error(); } </pre></div><div class = "comment">Tell the user what we are doing.</div><div class ="fragment"><pre> else { std::cout << "Running " << argv[0]; for (int i=1; i<argc; i++) std::cout << " " << argv[i]; std::cout << std::endl << std::endl; } </pre></div><div class = "comment">Set the quadrature rule type that the user wants from argv[2]</div><div class ="fragment"><pre> quad_type = static_cast<QuadratureType>(std::atoi(argv[2])); </pre></div><div class = "comment">Independence of dimension has already been shown inexample 4. For the time being, restrict to 3 dimensions.</div><div class ="fragment"><pre> const unsigned int dim=3; </pre></div><div class = "comment">The following is identical to example 4, and thereforenot commented. Differences are mentioned when present.</div><div class ="fragment"><pre> Mesh mesh (dim); </pre></div><div class = "comment">We will use a linear approximation space in this example,hence 8-noded hexahedral elements are sufficient. Thisis different than example 4 where we used 27-nodedhexahedral elements to support a second-order approximationspace.</div><div class ="fragment"><pre> MeshTools::Generation::build_cube (mesh, 16, 16, 16, -1., 1., -1., 1., -1., 1., HEX8); mesh.print_info(); EquationSystems equation_systems (mesh); { equation_systems.add_system<LinearImplicitSystem> ("Poisson"); equation_systems.get_system("Poisson").add_variable("u", FIRST); equation_systems.get_system("Poisson").attach_assemble_function (assemble_poisson); equation_systems.init(); equation_systems.print_info(); } equation_systems.get_system("Poisson").solve(); </pre></div><div class = "comment">"Personalize" the output, with thenumber of the quadrature rule appended.</div><div class ="fragment"><pre> std::ostringstream f_name; f_name << "out_" << quad_type << ".gmv"; GMVIO(mesh).write_equation_systems (f_name.str(), equation_systems); } </pre></div><div class = "comment">All done.</div><div class ="fragment"><pre> return libMesh::close (); } void assemble_poisson(EquationSystems& es, const std::string& system_name) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -