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

📄 ex4.php

📁 一个用来实现偏微分方程中网格的计算库
💻 PHP
📖 第 1 页 / 共 4 页
字号:
              system.add_variable("u",        			  Utility::string_to_enum&lt;Order&gt;   (order),        			  Utility::string_to_enum&lt;FEFamily&gt;(family));        </pre></div><div class = "comment">Give the system a pointer to the matrix assemblyfunction.</div><div class ="fragment"><pre>              system.attach_assemble_function (assemble_poisson);              </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 "Poisson", just like example 2.</div><div class ="fragment"><pre>            equation_systems.get_system("Poisson").solve();        </pre></div><div class = "comment">After solving the system write the solutionto a GMV-formatted plot file.</div><div class ="fragment"><pre>            if(dim == 1)            {                      GnuPlotIO plot(mesh,"Example 4, 1D",GnuPlotIO::GRID_ON);              plot.write_equation_systems("out_1",equation_systems);            }            else            {              GMVIO (mesh).write_equation_systems ((dim == 3) ?                 "out_3.gmv" : "out_2.gmv",equation_systems);            }          }          </pre></div><div class = "comment">All done.  </div><div class ="fragment"><pre>          return libMesh::close ();        }                                </pre></div><div class = "comment"><br><br><br><br><br><br>We now define the matrix assembly function for thePoisson system.  We need to first compute elementmatrices and right-hand sides, and then take intoaccount the boundary conditions, which will be handledvia a penalty method.</div><div class ="fragment"><pre>        void assemble_poisson(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 == "Poisson");                </pre></div><div class = "comment">Declare a performance log.  Give it a descriptivestring to identify what part of the code we arelogging, since there may be many PerfLogs in anapplication.</div><div class ="fragment"><pre>          PerfLog perf_log ("Matrix Assembly");          </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 LinearImplicitSystem we are solving</div><div class ="fragment"><pre>          LinearImplicitSystem& system = es.get_system&lt;LinearImplicitSystem&gt;("Poisson");          </pre></div><div class = "comment">A reference to the \p DofMap object for this system.  The \p DofMapobject handles the index translation from node and element numbersto degree of freedom numbers.  We will talk more about the \p DofMapin future examples.</div><div class ="fragment"><pre>          const DofMap& dof_map = system.get_dof_map();        </pre></div><div class = "comment">Get a constant reference to the Finite Element typefor the first (and only) variable in the system.</div><div class ="fragment"><pre>          FEType fe_type = dof_map.variable_type(0);        </pre></div><div class = "comment">Build a Finite Element object of the specified type.  Since the\p FEBase::build() member dynamically creates memory we willstore the object as an \p AutoPtr<FEBase>.  This can be thoughtof as a pointer that will clean up after itself.</div><div class ="fragment"><pre>          AutoPtr&lt;FEBase&gt; fe (FEBase::build(dim, fe_type));          </pre></div><div class = "comment">A 5th order Gauss quadrature rule for numerical integration.</div><div class ="fragment"><pre>          QGauss qrule (dim, FIFTH);        </pre></div><div class = "comment">Tell the finite element object to use our quadrature rule.</div><div class ="fragment"><pre>          fe-&gt;attach_quadrature_rule (&qrule);        </pre></div><div class = "comment">Declare a special finite element object forboundary integration.</div><div class ="fragment"><pre>          AutoPtr&lt;FEBase&gt; fe_face (FEBase::build(dim, fe_type));        	      </pre></div><div class = "comment">Boundary integration requires one quadraure rule,with dimensionality one less than the dimensionalityof the element.</div><div class ="fragment"><pre>          QGauss qface(dim-1, FIFTH);          </pre></div><div class = "comment">Tell the finte element object to use ourquadrature rule.</div><div class ="fragment"><pre>          fe_face-&gt;attach_quadrature_rule (&qface);        </pre></div><div class = "comment">Here we define some references to cell-specific data thatwill be used to assemble the linear system.We begin with the element Jacobian * quadrature weight at eachintegration point.   </div><div class ="fragment"><pre>          const std::vector&lt;Real&gt;& JxW = fe-&gt;get_JxW();        </pre></div><div class = "comment">The physical XY locations of the quadrature points on the element.These might be useful for evaluating spatially varying materialproperties at the quadrature points.</div><div class ="fragment"><pre>          const std::vector&lt;Point&gt;& q_point = fe-&gt;get_xyz();        </pre></div><div class = "comment">The element shape functions evaluated at the quadrature points.</div><div class ="fragment"><pre>          const std::vector&lt;std::vector&lt;Real&gt; &gt;& phi = fe-&gt;get_phi();        </pre></div><div class = "comment">The element shape function gradients evaluated at the quadraturepoints.</div><div class ="fragment"><pre>          const std::vector&lt;std::vector&lt;RealGradient&gt; &gt;& dphi = fe-&gt;get_dphi();        </pre></div><div class = "comment">Define data structures to contain the element matrixand right-hand-side vector contribution.  Followingbasic finite element terminology we will denote these"Ke" and "Fe". More detail is in example 3.</div><div class ="fragment"><pre>          DenseMatrix&lt;Number&gt; Ke;          DenseVector&lt;Number&gt; Fe;        </pre></div><div class = "comment">This vector will hold the degree of freedom indices forthe element.  These define where in the global systemthe element degrees of freedom get mapped.</div><div class ="fragment"><pre>          std::vector&lt;unsigned int&gt; dof_indices;        </pre></div><div class = "comment">Now we will loop over all the elements in the mesh.We will compute the element matrix and right-hand-sidecontribution.  See example 3 for a discussion of theelement iterators.  Here we use the \p const_local_elem_iteratorto indicate we only want to loop over elements that are assignedto the local processor.  This allows each processor to computeits components of the global matrix.<br><br>"PARALLEL CHANGE"</div><div class ="fragment"><pre>          MeshBase::const_element_iterator       el     = mesh.local_elements_begin();          const MeshBase::const_element_iterator end_el = mesh.local_elements_end();                  for ( ; el != end_el; ++el)            {</pre></div><div class = "comment">Start logging the shape function initialization.This is done through a simple function call withthe name of the event to log.</div><div class ="fragment"><pre>              perf_log.start_event("elem init");              </pre></div><div class = "comment">Store a pointer to the element we are currentlyworking on.  This allows for nicer syntax later.</div><div class ="fragment"><pre>              const Elem* elem = *el;        </pre></div><div class = "comment">Get the degree of freedom indices for thecurrent element.  These define where in the globalmatrix and right-hand-side this element willcontribute to.</div><div class ="fragment"><pre>              dof_map.dof_indices (elem, dof_indices);        </pre></div><div class = "comment">Compute the element-specific data for the currentelement.  This involves computing the location of thequadrature points (q_point) and the shape functions(phi, dphi) for the current element.</div><div class ="fragment"><pre>              fe-&gt;reinit (elem);        </pre></div><div class = "comment">Zero the element matrix and right-hand side beforesumming them.  We use the resize member here becausethe number of degrees of freedom might have changed fromthe last element.  Note that this will be the case if theelement type is different (i.e. the last element was atriangle, now we are on a quadrilateral).</div><div class ="fragment"><pre>              Ke.resize (dof_indices.size(),        		 dof_indices.size());                      Fe.resize (dof_indices.size());        </pre></div><div class = "comment">Stop logging the shape function initialization.If you forget to stop logging an event the PerfLogobject will probably catch the error and abort.</div><div class ="fragment"><pre>              perf_log.stop_event("elem init");              </pre></div>

⌨️ 快捷键说明

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