📄 ex13.php
字号:
<?php $root=""; ?><?php require($root."navigation.php"); ?><html><head> <?php load_style($root); ?></head> <body> <?php make_navigation("ex13",$root)?> <div class="content"><a name="comments"></a> <div class = "comment"><h1>Example 13 - Unsteady Navier-Stokes Equations - Unsteady Nonlinear Systems of Equations</h1><br><br>This example shows how a simple, unsteady, nonlinear system of equationscan be solved in parallel. The system of equations are the familiarNavier-Stokes equations for low-speed incompressible fluid flow. Thisexample introduces the concept of the inner nonlinear loop for eachtimestep, and requires a good deal of linear algebra number-crunchingat each step. If you have the General Mesh Viewer (GMV) installed,the script movie.sh in this directory will also take appropriate screenshots of each of the solution files in the time sequence. These rgb filescan then be animated with the "animate" utility of ImageMagick if it isinstalled on your system. On a PIII 1GHz machine in debug mode, thisexample takes a little over a minute to run. If you would like to seea more detailed time history, or compute more timesteps, that is certainlypossible by changing the n_timesteps and dt variables below.<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 "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" #include "transient_system.h" #include "perf_log.h" #include "boundary_info.h" #include "utility.h" </pre></div><div class = "comment">Some (older) compilers do not offer full stream functionality, OStringStream works around this.</div><div class ="fragment"><pre> #include "o_string_stream.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, 20, 20, 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 "Navier-Stokes"</div><div class ="fragment"><pre> TransientLinearImplicitSystem & system = equation_systems.add_system<TransientLinearImplicitSystem> ("Navier-Stokes"); </pre></div><div class = "comment">Add the variables "u" & "v" to "Navier-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 "Navier-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 (); </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">Create a performance-logging object for this example</div><div class ="fragment"><pre> PerfLog perf_log("Example 13"); </pre></div><div class = "comment">Now we begin the timestep loop to compute the time-accuratesolution of the equations.</div><div class ="fragment"><pre> const Real dt = 0.01; Real time = 0.0; const unsigned int n_timesteps = 15; </pre></div><div class = "comment">The number of steps and the stopping criterion are also requiredfor the nonlinear iterations.</div><div class ="fragment"><pre> const unsigned int n_nonlinear_steps = 15; const Real nonlinear_tolerance = 1.e-3; </pre></div><div class = "comment">We also set a standard linear solver flag in the EquationSystems objectwhich controls the maxiumum number of linear solver iterations allowed.</div><div class ="fragment"><pre> equation_systems.parameters.set<unsigned int>("linear solver maximum iterations") = 250; </pre></div><div class = "comment">Tell the system of equations what the timestep is by usingthe set_parameter function. The matrix assembly routine canthen reference this parameter.</div><div class ="fragment"><pre> equation_systems.parameters.set<Real> ("dt") = dt; </pre></div><div class = "comment">Get a reference to the Stokes system to use later.</div><div class ="fragment"><pre> TransientLinearImplicitSystem& navier_stokes_system = equation_systems.get_system<TransientLinearImplicitSystem>("Navier-Stokes"); </pre></div><div class = "comment">The first thing to do is to get a copy of the solution atthe current nonlinear iteration. This value will be used todetermine if we can exit the nonlinear loop.</div><div class ="fragment"><pre> AutoPtr<NumericVector<Number> > last_nonlinear_soln (navier_stokes_system.solution->clone()); for (unsigned int t_step=0; t_step<n_timesteps; ++t_step) {</pre></div><div class = "comment">Incremenet the time counter, set the time and thetime step size as parameters in the EquationSystem.</div><div class ="fragment"><pre> time += dt; </pre></div><div class = "comment">Let the system of equations know the current time.This might be necessary for a time-dependent forcingfunction for example.</div><div class ="fragment"><pre> equation_systems.parameters.set<Real> ("time") = time; </pre>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -