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

📄 ex4.php

📁 一个用来实现偏微分方程中网格的计算库
💻 PHP
📖 第 1 页 / 共 4 页
字号:
<?php $root=""; ?><?php require($root."navigation.php"); ?><html><head>  <?php load_style($root); ?></head> <body> <?php make_navigation("ex4",$root)?> <div class="content"><a name="comments"></a> <div class = "comment"><h1>Example 4 - Solving a 1D, 2D or 3D Poisson Problem in Parallel</h1><br><br>This is the fourth example program.  It builds onthe third example program by showing how to formulatethe code in a dimension-independent way.  Very minorchanges to the example will allow the problem to besolved in one, two or three dimensions.<br><br>This example will also introduce the PerfLog classas a way to monitor your code's performance.  We willuse it to instrument the matrix assembly code and lookfor bottlenecks where we should focus optimization efforts.<br><br>This example also shows how to extend example 3 to run inparallel.  Notice how litte has changed!  The significantdifferences are marked with "PARALLEL CHANGE".<br><br><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 "gnuplot_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 Gauss quadrature rules.</div><div class ="fragment"><pre>        #include "quadrature_gauss.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">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 PerfLog, a performance logging utility.It is useful for timing events in a code and givingyou an idea where bottlenecks lie.</div><div class ="fragment"><pre>        #include "perf_log.h"        </pre></div><div class = "comment">The definition of a geometric element</div><div class ="fragment"><pre>        #include "elem.h"                #include "string_to_enum.h"        #include "getpot.h"                        </pre></div><div class = "comment">Function prototype.  This is the function that will assemblethe linear system for our Poisson 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_poisson(EquationSystems& es,                              const std::string& system_name);        </pre></div><div class = "comment">Exact solution function prototype.</div><div class ="fragment"><pre>        Real exact_solution (const Real x,        		     const Real y = 0.,        		     const Real z = 0.);        </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">Declare a performance log for the main programPerfLog perf_main("Main Program");  <br><br>Braces are used to force object scope, like in example 2</div><div class ="fragment"><pre>          {</pre></div><div class = "comment">Create a GetPot object to parse the command line</div><div class ="fragment"><pre>            GetPot command_line (argc, argv);            </pre></div><div class = "comment">Check for proper calling arguments.</div><div class ="fragment"><pre>            if (argc &lt; 3)              {        	std::cerr &lt;&lt; "Usage:\n"        		  &lt;&lt;"\t " &lt;&lt; argv[0] &lt;&lt; " -d 2(3)" &lt;&lt; " -n 15"        		  &lt;&lt; std::endl;        </pre></div><div class = "comment">This handy function will print the file name, line number,and then abort.  Currrently the library does not use C++exception handling.</div><div class ="fragment"><pre>                error();              }            </pre></div><div class = "comment">Brief message to the user regarding the program nameand command line arguments.</div><div class ="fragment"><pre>            else               {        	std::cout &lt;&lt; "Running " &lt;&lt; argv[0];        	        	for (int i=1; i&lt;argc; i++)        	  std::cout &lt;&lt; " " &lt;&lt; argv[i];        	        	std::cout &lt;&lt; std::endl &lt;&lt; std::endl;              }                    </pre></div><div class = "comment">Read problem dimension from command line.  Use intinstead of unsigned since the GetPot overload is ambiguousotherwise.</div><div class ="fragment"><pre>            int dim = 2;            if ( command_line.search(1, "-d") )              dim = command_line.next(dim);            </pre></div><div class = "comment">Read number of elements from command line</div><div class ="fragment"><pre>            int ps = 15;            if ( command_line.search(1, "-n") )              ps = command_line.next(ps);            </pre></div><div class = "comment">Read FE order from command line</div><div class ="fragment"><pre>            std::string order = "SECOND";             if ( command_line.search(2, "-Order", "-o") )              order = command_line.next(order);        </pre></div><div class = "comment">Read FE Family from command line</div><div class ="fragment"><pre>            std::string family = "LAGRANGE";             if ( command_line.search(2, "-FEFamily", "-f") )              family = command_line.next(family);            </pre></div><div class = "comment">Cannot use dicontinuous basis.</div><div class ="fragment"><pre>            if ((family == "MONOMIAL") || (family == "XYZ"))              {        	std::cerr &lt;&lt; "ex4 currently requires a C^0 (or higher) FE basis." &lt;&lt; std::endl;        	error();              }              </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 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>            if ((family == "LAGRANGE") && (order == "FIRST"))              {</pre></div><div class = "comment">No reason to use high-order geometric elements if we aresolving with low-order finite elements.</div><div class ="fragment"><pre>                MeshTools::Generation::build_cube (mesh,        					   ps, ps, ps,        					   -1., 1.,        					   -1., 1.,        					   -1., 1.,        					   (dim==1)    ? EDGE2 :         					   ((dim == 2) ? QUAD4 : HEX8));              }                        else              {        	MeshTools::Generation::build_cube (mesh,        					   ps, ps, ps,        					   -1., 1.,        					   -1., 1.,        					   -1., 1.,        					   (dim==1)    ? EDGE3 :         					   ((dim == 2) ? QUAD9 : HEX27));              }                    </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 system named "Poisson"</div><div class ="fragment"><pre>              LinearImplicitSystem& system =        	equation_systems.add_system&lt;LinearImplicitSystem&gt; ("Poisson");                      </pre></div><div class = "comment">Adds the variable "u" to "Poisson".  "u"will be approximated using second-order approximation.</div><div class ="fragment"><pre>

⌨️ 快捷键说明

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