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

📄 ex15.php

📁 一个用来实现偏微分方程中网格的计算库
💻 PHP
📖 第 1 页 / 共 5 页
字号:
</pre></div><div class = "comment">xyz coordinates in space</div><div class ="fragment"><pre>          const Real x = p(0);          const Real y = p(1);          const Real z = p(2);          </pre></div><div class = "comment">analytic solution value</div><div class ="fragment"><pre>          return 4096.*(x-x*x)*(x-x*x)*(y-y*y)*(y-y*y)*(z-z*z)*(z-z*z);        }                        Gradient exact_3D_derivative(const Point& p,        			     const Parameters&,  // parameters, not needed        			     const std::string&, // sys_name, not needed        			     const std::string&) // unk_name, not needed        {</pre></div><div class = "comment">First derivatives to be returned.</div><div class ="fragment"><pre>          Gradient gradu;          </pre></div><div class = "comment">xyz coordinates in space</div><div class ="fragment"><pre>          const Real x = p(0);          const Real y = p(1);          const Real z = p(2);                  gradu(0) = 4096.*2.*(x-x*x)*(1.-2.*x)*(y-y*y)*(y-y*y)*(z-z*z)*(z-z*z);          gradu(1) = 4096.*2.*(x-x*x)*(x-x*x)*(y-y*y)*(1.-2.*y)*(z-z*z)*(z-z*z);          gradu(2) = 4096.*2.*(x-x*x)*(x-x*x)*(y-y*y)*(y-y*y)*(z-z*z)*(1.-2.*z);                  return gradu;        }                </pre></div><div class = "comment">We now define the hessian of the exact solution</div><div class ="fragment"><pre>        Tensor exact_3D_hessian(const Point& p,        			const Parameters&,  // parameters, not needed        			const std::string&, // sys_name, not needed        			const std::string&) // unk_name, not needed        {</pre></div><div class = "comment">Second derivatives to be returned.</div><div class ="fragment"><pre>          Tensor hessu;          </pre></div><div class = "comment">xyz coordinates in space</div><div class ="fragment"><pre>          const Real x = p(0);          const Real y = p(1);          const Real z = p(2);                  hessu(0,0) = 4096.*(2.-12.*x+12.*x*x)*(y-y*y)*(y-y*y)*(z-z*z)*(z-z*z);          hessu(0,1) = 4096.*4.*(x-x*x)*(1.-2.*x)*(y-y*y)*(1.-2.*y)*(z-z*z)*(z-z*z);          hessu(0,2) = 4096.*4.*(x-x*x)*(1.-2.*x)*(y-y*y)*(y-y*y)*(z-z*z)*(1.-2.*z);          hessu(1,1) = 4096.*(x-x*x)*(x-x*x)*(2.-12.*y+12.*y*y)*(z-z*z)*(z-z*z);          hessu(1,2) = 4096.*4.*(x-x*x)*(x-x*x)*(y-y*y)*(1.-2.*y)*(z-z*z)*(1.-2.*z);          hessu(2,2) = 4096.*(x-x*x)*(x-x*x)*(y-y*y)*(y-y*y)*(2.-12.*z+12.*z*z);        </pre></div><div class = "comment">Hessians are always symmetric</div><div class ="fragment"><pre>          hessu(1,0) = hessu(0,1);          hessu(2,0) = hessu(0,2);          hessu(2,1) = hessu(1,2);                  return hessu;        }                                Number forcing_function_3D(const Point& p)        {</pre></div><div class = "comment">xyz coordinates in space</div><div class ="fragment"><pre>          const Real x = p(0);          const Real y = p(1);          const Real z = p(2);        </pre></div><div class = "comment">Equals laplacian(laplacian(u))</div><div class ="fragment"><pre>          return 4096. * 8. * (3.*((y-y*y)*(y-y*y)*(x-x*x)*(x-x*x) +                                   (z-z*z)*(z-z*z)*(x-x*x)*(x-x*x) +                                   (z-z*z)*(z-z*z)*(y-y*y)*(y-y*y)) +                 (1.-6.*x+6.*x*x)*(1.-6.*y+6.*y*y)*(z-z*z)*(z-z*z) +                 (1.-6.*x+6.*x*x)*(1.-6.*z+6.*z*z)*(y-y*y)*(y-y*y) +                 (1.-6.*y+6.*y*y)*(1.-6.*z+6.*z*z)*(x-x*x)*(x-x*x));        }                        </pre></div><div class = "comment">We now define the matrix assembly function for theBiharmonic 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_biharmonic(EquationSystems& es,                              const std::string& system_name)        {        #ifdef ENABLE_AMR        #ifdef ENABLE_SECOND_DERIVATIVES        </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 == "Biharmonic");        </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",false);          </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;("Biharmonic");          </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">Quadrature rule for numerical integration.With 2D triangles, the Clough quadrature rule puts a Gaussianquadrature rule on each of the 3 subelements</div><div class ="fragment"><pre>          AutoPtr&lt;QBase&gt; qrule(fe_type.default_quadrature_rule(dim));        </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.get());        </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 another quadraure rule,with dimensionality one less than the dimensionalityof the element.In 1D, the Clough and Gauss quadrature rules are identical.</div><div class ="fragment"><pre>          AutoPtr&lt;QBase&gt; qface(fe_type.default_quadrature_rule(dim-1));        </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.get());        </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 second derivatives evaluated at thequadrature points.  Note that for the simple biharmonic, shapefunction first derivatives are unnecessary.</div><div class ="fragment"><pre>          const std::vector&lt;std::vector&lt;RealTensor&gt; &gt;& d2phi = fe-&gt;get_d2phi();        </pre></div><div class = "comment">For efficiency we will compute shape function laplacians n times,not n^2</div><div class ="fragment"><pre>          std::vector&lt;Real&gt; shape_laplacian;        </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">

⌨️ 快捷键说明

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