?? ex6.php
字號(hào):
<?php $root=""; ?><?php require($root."navigation.php"); ?><html><head> <?php load_style($root); ?></head> <body> <?php make_navigation("ex6",$root)?> <div class="content"><a name="comments"></a> <div class = "comment"><h1>Example 6 - Infinite Elements for the Wave Equation</h1><br><br>This is the sixth example program. It builds onthe previous examples, and introduces the InfiniteElement class. Note that the library must be compiledwith Infinite Elements enabled. Otherwise, thisexample will abort.This example intends to demonstrate the similaritiesbetween the \p FE and the \p InfFE classes in libMesh.The matrices are assembled according to the wave equation.However, for practical applications a time integrationscheme (as introduced in subsequent examples) should beused.<br><br>C++ include files that we need</div><div class ="fragment"><pre> #include <iostream> #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 and Infinite Element object.</div><div class ="fragment"><pre> #include "fe.h" #include "inf_fe.h" #include "inf_elem_builder.h" </pre></div><div class = "comment">Define Gauss quadrature rules.</div><div class ="fragment"><pre> #include "quadrature_gauss.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 vertex associated with a Mesh.</div><div class ="fragment"><pre> #include "node.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 is similar to the Poissonassemble function of example 4. </div><div class ="fragment"><pre> void assemble_wave (EquationSystems& es, const std::string& system_name); </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, like in example 2.</div><div class ="fragment"><pre> libMesh::init (argc, argv); </pre></div><div class = "comment">This example requires Infinite Elements </div><div class ="fragment"><pre> #ifndef ENABLE_INFINITE_ELEMENTS std::cerr << "ERROR: This example requires the library to be compiled with Infinite Element support!" << std::endl; here(); return 0; #else </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">For the moment, only allow 3D </div><div class ="fragment"><pre> const unsigned int dim = 3; </pre></div><div class = "comment">Tell the user what we are doing.</div><div class ="fragment"><pre> std::cout << "Running ex6 with dim = " << dim << std::endl << std::endl; </pre></div><div class = "comment">Create a mesh with user-defined dimension </div><div class ="fragment"><pre> Mesh mesh (dim); </pre></div><div class = "comment">Use the internal mesh generator to create elementson the square [-1,1]^3, of type Hex8.</div><div class ="fragment"><pre> MeshTools::Generation::build_cube (mesh, 4, 4, 4, -1., 1., -1., 1., -1., 1., HEX8); </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">Write the mesh before the infinite elements are added</div><div class ="fragment"><pre> GMVIO(mesh).write ("orig_mesh.gmv"); </pre></div><div class = "comment">Normally, when a mesh is imported or created inlibMesh, only conventional elements exist. The infiniteelements used here, however, require prescribednodal locations (with specified distances from an imaginaryorigin) and configurations that a conventional mesh creator in general does not offer. Therefore, an efficient methodfor building infinite elements is offered. It can accountfor symmetry planes and creates infinite elements in a fullyautomatic way.<br><br>Right now, the simplified interface is used, automaticallydetermining the origin. Check \p MeshBase for a generalizedmethod that can even return the element faces of interiorvibrating surfaces. The \p bool determines whether to be verbose.</div><div class ="fragment"><pre> InfElemBuilder builder(mesh); builder.build_inf_elem(true); </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">Write the mesh with the infinite elements added.Compare this to the original mesh.</div><div class ="fragment"><pre> GMVIO(mesh).write ("ifems_added.gmv"); </pre></div><div class = "comment">After building infinite elements, we have to let the elements find their neighbors again.</div><div class ="fragment"><pre> mesh.find_neighbors(); </pre></div><div class = "comment">Create an equation systems object, where \p ThinSystemoffers only the crucial functionality for solving a system. Use \p ThinSystem when you want the sleekestsystem possible.</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">Create a system named "Wave". This canbe a simple, steady system</div><div class ="fragment"><pre> equation_systems.add_system<LinearImplicitSystem> ("Wave"); </pre></div><div class = "comment">Create an FEType describing the approximationcharacteristics of the InfFE object. Note thatthe constructor automatically defaults to somesensible values. But use \p FIRST order approximation.</div><div class ="fragment"><pre> FEType fe_type(FIRST); </pre></div><div class = "comment">Add the variable "p" to "Wave". Note that there existvarious approaches in adding variables. In example 3, \p add_variable took the order of approximation and useddefault values for the \p FEFamily, while here the \p FEType is used.</div><div class ="fragment"><pre> equation_systems.get_system("Wave").add_variable("p", fe_type); </pre></div><div class = "comment">Give the system a pointer to the matrix assemblyfunction.</div><div class ="fragment"><pre> equation_systems.get_system("Wave").attach_assemble_function (assemble_wave); </pre></div><div class = "comment">Set the speed of sound and fluid densityas \p EquationSystems parameter,so that \p assemble_wave() can access it.</div><div class ="fragment"><pre> equation_systems.parameters.set<Real>("speed") = 1.; equation_systems.parameters.set<Real>("fluid density") = 1.; </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">Prints information about the system to the screen.</div><div class ="fragment"><pre> equation_systems.print_info(); } </pre></div><div class = "comment">Solve the system "Wave".</div><div class ="fragment"><pre> equation_systems.get_system("Wave").solve(); </pre></div><div class = "comment">Write the whole EquationSystems object to file.For infinite elements, the concept of nodal_soln()is not applicable. Therefore, writing the mesh insome format @e always gives all-zero results atthe nodes of the infinite elements. Instead,use the FEInterface::compute_data() methods todetermine physically correct results within aninfinite element.</div><div class ="fragment"><pre> equation_systems.write ("eqn_sys.dat", libMeshEnums::WRITE); } </pre></div><div class = "comment">All done. </div><div class ="fragment"><pre> return libMesh::close (); #endif // else part of ifndef ENABLE_INFINITE_ELEMENTS
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -