⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex11.php

📁 一个用来实现偏微分方程中网格的计算库
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?php $root=""; ?><?php require($root."navigation.php"); ?><html><head>  <?php load_style($root); ?></head> <body> <?php make_navigation("ex11",$root)?> <div class="content"><a name="comments"></a> <div class = "comment"><h1>Example 11 - Stokes Equations - Systems of Equations</h1><br><br>This example shows how a simple, linear system of equationscan be solved in parallel.  The system of equations are the familiarStokes equations for low-speed incompressible fluid flow.<br><br>C++ include files that we need</div><div class ="fragment"><pre>        #include &lt;iostream&gt;        #include &lt;algorithm&gt;        #include &lt;math.h&gt;        </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 "equation_systems.h"        #include "fe.h"        #include "quadrature_gauss.h"        #include "dof_map.h"        #include "sparse_matrix.h"        #include "numeric_vector.h"        #include "dense_matrix.h"        #include "dense_vector.h"        #include "linear_implicit_system.h"        </pre></div><div class = "comment">For systems of equations the \p DenseSubMatrixand \p DenseSubVector provide convenient ways forassembling the element matrix and vector on acomponent-by-component basis.</div><div class ="fragment"><pre>        #include "dense_submatrix.h"        #include "dense_subvector.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.  This function will assemble the systemmatrix and right-hand-side.</div><div class ="fragment"><pre>        void assemble_stokes (EquationSystems& es,        		      const std::string& system_name);        </pre></div><div class = "comment">The main program.</div><div class ="fragment"><pre>        int main (int argc, char** argv)        {</pre></div><div class = "comment">Initialize libMesh.</div><div class ="fragment"><pre>          libMesh::init (argc, argv);          {    </pre></div><div class = "comment">Set the dimensionality of the mesh = 2</div><div class ="fragment"><pre>            const unsigned int dim = 2;                 </pre></div><div class = "comment">Create a two-dimensional mesh.</div><div class ="fragment"><pre>            Mesh mesh (dim);            </pre></div><div class = "comment">Use the MeshTools::Generation mesh generator to create a uniformgrid on the square [-1,1]^D.  We instruct the mesh generatorto build a mesh of 8x8 \p Quad9 elements in 2D, or \p Hex27elements in 3D.  Building these higher-order elements allowsus to use higher-order approximation, as in example 3.</div><div class ="fragment"><pre>            MeshTools::Generation::build_square (mesh,        					 15, 15,        					 0., 1.,        					 0., 1.,        					 QUAD9);            </pre></div><div class = "comment">Print information about the mesh to the screen.</div><div class ="fragment"><pre>            mesh.print_info();            </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 transient system named "Convection-Diffusion"</div><div class ="fragment"><pre>              LinearImplicitSystem & system =         	equation_systems.add_system&lt;LinearImplicitSystem&gt; ("Stokes");              </pre></div><div class = "comment">Add the variables "u" & "v" to "Stokes".  Theywill be approximated using second-order approximation.</div><div class ="fragment"><pre>              system.add_variable ("u", SECOND);              system.add_variable ("v", SECOND);        </pre></div><div class = "comment">Add the variable "p" to "Stokes". This willbe approximated with a first-order basis,providing an LBB-stable pressure-velocity pair.</div><div class ="fragment"><pre>              system.add_variable ("p", FIRST);        </pre></div><div class = "comment">Give the system a pointer to the matrix assemblyfunction.</div><div class ="fragment"><pre>              system.attach_assemble_function (assemble_stokes);              </pre></div><div class = "comment">Initialize the data structures for the equation system.</div><div class ="fragment"><pre>              equation_systems.init ();                      equation_systems.parameters.set&lt;unsigned int&gt;("linear solver maximum iterations") = 250;              equation_systems.parameters.set&lt;Real&gt;        ("linear solver tolerance") = TOLERANCE;              </pre></div><div class = "comment">Prints information about the system to the screen.</div><div class ="fragment"><pre>              equation_systems.print_info();            }            </pre></div><div class = "comment">Assemble & solve the linear system,then write the solution.</div><div class ="fragment"><pre>            equation_systems.get_system("Stokes").solve();                    GMVIO(mesh).write_equation_systems ("out.gmv",        					equation_systems);          }          </pre></div><div class = "comment">All done.  </div><div class ="fragment"><pre>          return libMesh::close ();        }                void assemble_stokes (EquationSystems& es,        		      const std::string& system_name)        {</pre></div><div class = "comment">It is a good idea to make sure we are assemblingthe proper system.</div><div class ="fragment"><pre>          assert (system_name == "Stokes");          </pre></div><div class = "comment">Get a constant reference to the mesh object.</div><div class ="fragment"><pre>          const Mesh& mesh = es.get_mesh();          </pre></div><div class = "comment">The dimension that we are running</div><div class ="fragment"><pre>          const unsigned int dim = mesh.mesh_dimension();          </pre></div><div class = "comment">Get a reference to the Convection-Diffusion system object.</div><div class ="fragment"><pre>          LinearImplicitSystem & system =            es.get_system&lt;LinearImplicitSystem&gt; ("Stokes");        </pre></div><div class = "comment">Numeric ids corresponding to each variable in the system</div><div class ="fragment"><pre>          const unsigned int u_var = system.variable_number ("u");          const unsigned int v_var = system.variable_number ("v");          const unsigned int p_var = system.variable_number ("p");          </pre></div><div class = "comment">Get the Finite Element type for "u".  Note this will bethe same as the type for "v".</div><div class ="fragment"><pre>          FEType fe_vel_type = system.variable_type(u_var);          </pre></div><div class = "comment">Get the Finite Element type for "p".</div><div class ="fragment"><pre>          FEType fe_pres_type = system.variable_type(p_var);        </pre></div><div class = "comment">Build a Finite Element object of the specified type forthe velocity variables.</div><div class ="fragment"><pre>          AutoPtr&lt;FEBase&gt; fe_vel  (FEBase::build(dim, fe_vel_type));            </pre></div><div class = "comment">Build a Finite Element object of the specified type forthe pressure variables.</div><div class ="fragment"><pre>          AutoPtr&lt;FEBase&gt; fe_pres (FEBase::build(dim, fe_pres_type));          </pre></div><div class = "comment">A Gauss quadrature rule for numerical integration.Let the \p FEType object decide what order rule is appropriate.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -