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

📄 ex3.php

📁 一个用来实现偏微分方程中网格的计算库
💻 PHP
📖 第 1 页 / 共 3 页
字号:
points on the face.</div><div class ="fragment"><pre>                      const std::vector&lt;Real&gt;& JxW_face = fe_face-&gt;get_JxW();        	      </pre></div><div class = "comment">The XYZ locations (in physical space) of thequadrature points on the face.  This is wherewe will interpolate the boundary value function.</div><div class ="fragment"><pre>                      const std::vector&lt;Point &gt;& qface_point = fe_face-&gt;get_xyz();        	      </pre></div><div class = "comment">Compute the shape function values on the elementface.</div><div class ="fragment"><pre>                      fe_face-&gt;reinit(elem, side);        	      </pre></div><div class = "comment">Loop over the face quadrature points for integration.</div><div class ="fragment"><pre>                      for (unsigned int qp=0; qp&lt;qface.n_points(); qp++)        		{        </pre></div><div class = "comment">The location on the boundary of the currentface quadrature point.</div><div class ="fragment"><pre>                          const Real xf = qface_point[qp](0);        		  const Real yf = qface_point[qp](1);        </pre></div><div class = "comment">The penalty value.  \frac{1}{\epsilon}in the discussion above.</div><div class ="fragment"><pre>                          const Real penalty = 1.e10;        </pre></div><div class = "comment">The boundary value.</div><div class ="fragment"><pre>                          const Real value = exact_solution(xf, yf);        		  </pre></div><div class = "comment">Matrix contribution of the L2 projection. </div><div class ="fragment"><pre>                          for (unsigned int i=0; i&lt;phi_face.size(); i++)        		    for (unsigned int j=0; j&lt;phi_face.size(); j++)        		      Ke(i,j) += JxW_face[qp]*penalty*phi_face[i][qp]*phi_face[j][qp];        </pre></div><div class = "comment">Right-hand-side contribution of the L2projection.</div><div class ="fragment"><pre>                          for (unsigned int i=0; i&lt;phi_face.size(); i++)        		    Fe(i) += JxW_face[qp]*penalty*value*phi_face[i][qp];        		}         	    }              }              </pre></div><div class = "comment">We have now finished the quadrature point loop,and have therefore applied all the boundary conditions.<br><br>The element matrix and right-hand-side are now builtfor this element.  Add them to the global matrix andright-hand-side vector.  The  SparseMatrix::add_matrix()and  NumericVector::add_vector() members do this for us.</div><div class ="fragment"><pre>              system.matrix-&gt;add_matrix (Ke, dof_indices);              system.rhs-&gt;add_vector    (Fe, dof_indices);            }          </pre></div><div class = "comment">All done!</div><div class ="fragment"><pre>        }</pre></div><a name="nocomments"></a> <br><br><br> <h1> The program without comments: </h1> <pre>     #include &lt;iostream&gt;  #include &lt;algorithm&gt;  #include &lt;math.h&gt;    #include <B><FONT COLOR="#BC8F8F">&quot;libmesh.h&quot;</FONT></B>  #include <B><FONT COLOR="#BC8F8F">&quot;mesh.h&quot;</FONT></B>  #include <B><FONT COLOR="#BC8F8F">&quot;mesh_generation.h&quot;</FONT></B>  #include <B><FONT COLOR="#BC8F8F">&quot;gmv_io.h&quot;</FONT></B>  #include <B><FONT COLOR="#BC8F8F">&quot;linear_implicit_system.h&quot;</FONT></B>  #include <B><FONT COLOR="#BC8F8F">&quot;equation_systems.h&quot;</FONT></B>    #include <B><FONT COLOR="#BC8F8F">&quot;fe.h&quot;</FONT></B>    #include <B><FONT COLOR="#BC8F8F">&quot;quadrature_gauss.h&quot;</FONT></B>    #include <B><FONT COLOR="#BC8F8F">&quot;sparse_matrix.h&quot;</FONT></B>  #include <B><FONT COLOR="#BC8F8F">&quot;numeric_vector.h&quot;</FONT></B>  #include <B><FONT COLOR="#BC8F8F">&quot;dense_matrix.h&quot;</FONT></B>  #include <B><FONT COLOR="#BC8F8F">&quot;dense_vector.h&quot;</FONT></B>  #include <B><FONT COLOR="#BC8F8F">&quot;elem.h&quot;</FONT></B>    #include <B><FONT COLOR="#BC8F8F">&quot;dof_map.h&quot;</FONT></B>  #include <B><FONT COLOR="#BC8F8F">&quot;boundary_mesh.h&quot;</FONT></B>  #include <B><FONT COLOR="#BC8F8F">&quot;boundary_info.h&quot;</FONT></B>    <B><FONT COLOR="#228B22">void</FONT></B> assemble_poisson(EquationSystems&amp; es,                        <B><FONT COLOR="#228B22">const</FONT></B> std::string&amp; system_name);    Real exact_solution (<B><FONT COLOR="#228B22">const</FONT></B> Real x,  		     <B><FONT COLOR="#228B22">const</FONT></B> Real y,  		     <B><FONT COLOR="#228B22">const</FONT></B> Real z = 0.);    <B><FONT COLOR="#228B22">int</FONT></B> main (<B><FONT COLOR="#228B22">int</FONT></B> argc, <B><FONT COLOR="#228B22">char</FONT></B>** argv)  {        <B><FONT COLOR="#5F9EA0">libMesh</FONT></B>::init (argc, argv);          {            <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;Running &quot;</FONT></B> &lt;&lt; argv[0];            <B><FONT COLOR="#A020F0">for</FONT></B> (<B><FONT COLOR="#228B22">int</FONT></B> i=1; i&lt;argc; i++)        <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot; &quot;</FONT></B> &lt;&lt; argv[i];            <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; std::endl &lt;&lt; std::endl;            Mesh mesh (2);                  <B><FONT COLOR="#5F9EA0">MeshTools</FONT></B>::Generation::build_square (mesh,   					 15, 15,  					 -1., 1.,  					 -1., 1.,  					 QUAD9);        mesh.print_info();            EquationSystems equation_systems (mesh);            equation_systems.add_system&lt;LinearImplicitSystem&gt; (<B><FONT COLOR="#BC8F8F">&quot;Poisson&quot;</FONT></B>);        equation_systems.get_system(<B><FONT COLOR="#BC8F8F">&quot;Poisson&quot;</FONT></B>).add_variable(<B><FONT COLOR="#BC8F8F">&quot;u&quot;</FONT></B>, SECOND);        equation_systems.get_system(<B><FONT COLOR="#BC8F8F">&quot;Poisson&quot;</FONT></B>).attach_assemble_function (assemble_poisson);            equation_systems.init();            equation_systems.print_info();        equation_systems.get_system(<B><FONT COLOR="#BC8F8F">&quot;Poisson&quot;</FONT></B>).solve();        GMVIO (mesh).write_equation_systems (<B><FONT COLOR="#BC8F8F">&quot;out.gmv&quot;</FONT></B>, equation_systems);        <B><FONT COLOR="#A020F0">for</FONT></B> (<B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> i=0; i&lt;3; i++)        {  	here();  	equation_systems.get_system(<B><FONT COLOR="#BC8F8F">&quot;Poisson&quot;</FONT></B>).solve();          BoundaryMesh boundary_mesh (mesh.mesh_dimension()-1);          mesh.boundary_info-&gt;sync(boundary_mesh, false);        }      }      <B><FONT COLOR="#A020F0">return</FONT></B> libMesh::close();  }        <B><FONT COLOR="#228B22">void</FONT></B> assemble_poisson(EquationSystems&amp; es,                        <B><FONT COLOR="#228B22">const</FONT></B> std::string&amp; system_name)  {        assert (system_name == <B><FONT COLOR="#BC8F8F">&quot;Poisson&quot;</FONT></B>);          <B><FONT COLOR="#228B22">const</FONT></B> Mesh&amp; mesh = es.get_mesh();      <B><FONT COLOR="#228B22">const</FONT></B> <B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> dim = mesh.mesh_dimension();      LinearImplicitSystem&amp; system = es.get_system&lt;LinearImplicitSystem&gt; (<B><FONT COLOR="#BC8F8F">&quot;Poisson&quot;</FONT></B>);      <B><FONT COLOR="#228B22">const</FONT></B> DofMap&amp; dof_map = system.get_dof_map();        FEType fe_type = dof_map.variable_type(0);        AutoPtr&lt;FEBase&gt; fe (FEBase::build(dim, fe_type));        QGauss qrule (dim, FIFTH);        fe-&gt;attach_quadrature_rule (&amp;qrule);        AutoPtr&lt;FEBase&gt; fe_face (FEBase::build(dim, fe_type));        QGauss qface(dim-1, FIFTH);        fe_face-&gt;attach_quadrature_rule (&amp;qface);      <B><FONT COLOR="#228B22">const</FONT></B> std::vector&lt;Real&gt;&amp; JxW = fe-&gt;get_JxW();      <B><FONT COLOR="#228B22">const</FONT></B> std::vector&lt;Point&gt;&amp; q_point = fe-&gt;get_xyz();      <B><FONT COLOR="#228B22">const</FONT></B> std::vector&lt;std::vector&lt;Real&gt; &gt;&amp; phi = fe-&gt;get_phi();      <B><FONT COLOR="#228B22">const</FONT></B> std::vector&lt;std::vector&lt;RealGradient&gt; &gt;&amp; dphi = fe-&gt;get_dphi();      DenseMatrix&lt;Number&gt; Ke;    DenseVector&lt;Number&gt; Fe;        <B><FONT COLOR="#5F9EA0">std</FONT></B>::vector&lt;<B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B>&gt; dof_indices;        <B><FONT COLOR="#5F9EA0">MeshBase</FONT></B>::const_element_iterator       el     = mesh.elements_begin();    <B><FONT COLOR="#228B22">const</FONT></B> MeshBase::const_element_iterator end_el = mesh.elements_end();        <B><FONT COLOR="#A020F0">for</FONT></B> ( ; el != end_el ; ++el)      {        <B><FONT COLOR="#228B22">const</FONT></B> Elem* elem = *el;          dof_map.dof_indices (elem, dof_indices);          fe-&gt;reinit (elem);              Ke.resize (dof_indices.size(),  		 dof_indices.size());          Fe.resize (dof_indices.size());          <B><FONT COLOR="#A020F0">for</FONT></B> (<B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> qp=0; qp&lt;qrule.n_points(); qp++)  	{    	  <B><FONT COLOR="#A020F0">for</FONT></B> (<B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> i=0; i&lt;phi.size(); i++)  	    <B><FONT COLOR="#A020F0">for</FONT></B> (<B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> j=0; j&lt;phi.size(); j++)  	      {  		Ke(i,j) += JxW[qp]*(dphi[i][qp]*dphi[j][qp]);  	      }  	    	  {  	    <B><FONT COLOR="#228B22">const</FONT></B> Real x = q_point[qp](0);  	    <B><FONT COLOR="#228B22">const</FONT></B> Real y = q_point[qp](1);  	    <B><FONT COLOR="#228B22">const</FONT></B> Real eps = 1.e-3;  	        	    <B><FONT COLOR="#228B22">const</FONT></B> Real fxy = -(exact_solution(x,y-eps) +  			       exact_solution(x,y+eps) +  			       exact_solution(x-eps,y) +  			       exact_solution(x+eps,y) -  			       4.*exact_solution(x,y))/eps/eps;  	      	    <B><FONT COLOR="#A020F0">for</FONT></B> (<B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> i=0; i&lt;phi.size(); i++)  	      Fe(i) += JxW[qp]*fxy*phi[i][qp];  	  }   	}                 {    	<B><FONT COLOR="#A020F0">for</FONT></B> (<B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> side=0; side&lt;elem-&gt;n_sides(); side++)  	  <B><FONT COLOR="#A020F0">if</FONT></B> (elem-&gt;neighbor(side) == NULL)  	    {  	      <B><FONT COLOR="#228B22">const</FONT></B> std::vector&lt;std::vector&lt;Real&gt; &gt;&amp;  phi_face = fe_face-&gt;get_phi();  	        	      <B><FONT COLOR="#228B22">const</FONT></B> std::vector&lt;Real&gt;&amp; JxW_face = fe_face-&gt;get_JxW();  	        	      <B><FONT COLOR="#228B22">const</FONT></B> std::vector&lt;Point &gt;&amp; qface_point = fe_face-&gt;get_xyz();  	        	      fe_face-&gt;reinit(elem, side);  	        	      <B><FONT COLOR="#A020F0">for</FONT></B> (<B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> qp=0; qp&lt;qface.n_points(); qp++)  		{    		  <B><FONT COLOR="#228B22">const</FONT></B> Real xf = qface_point[qp](0);  		  <B><FONT COLOR="#228B22">const</FONT></B> Real yf = qface_point[qp](1);    		  <B><FONT COLOR="#228B22">const</FONT></B> Real penalty = 1.e10;    		  <B><FONT COLOR="#228B22">const</FONT></B> Real value = exact_solution(xf, yf);  		    		  <B><FONT COLOR="#A020F0">for</FONT></B> (<B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> i=0; i&lt;phi_face.size(); i++)  		    <B><FONT COLOR="#A020F0">for</FONT></B> (<B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> j=0; j&lt;phi_face.size(); j++)  		      Ke(i,j) += JxW_face[qp]*penalty*phi_face[i][qp]*phi_face[j][qp];    		  <B><FONT COLOR="#A020F0">for</FONT></B> (<B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> i=0; i&lt;phi_face.size(); i++)  		    Fe(i) += JxW_face[qp]*penalty*value*phi_face[i][qp];  		}   	    }        }                system.matrix-&gt;add_matrix (Ke, dof_indices);        system.rhs-&gt;add_vector    (Fe, dof_indices);      }      }</pre> <a name="output"></a> <br><br><br> <h1> The console output of the program: </h1> <pre>**************************************************************** Running Example  ./ex3-devel*************************************************************** Running ./ex3-devel Mesh Information:  mesh_dimension()=2  spatial_dimension()=3  n_nodes()=961  n_elem()=225   n_local_elem()=225   n_active_elem()=225  n_subdomains()=1  n_processors()=1  processor_id()=0 EquationSystems  n_systems()=1   System "Poisson"    Type "LinearImplicit"    Variables="u"     Finite Element Types="LAGRANGE"     Approximation Orders="SECOND"     n_dofs()=961    n_local_dofs()=961    n_constrained_dofs()=0    n_vectors()=1[0] ex3.C, line 162, compiled Jun  6 2007 at 11:54:25[0] ex3.C, line 162, compiled Jun  6 2007 at 11:54:25[0] ex3.C, line 162, compiled Jun  6 2007 at 11:54:25 **************************************************************** Done Running Example  ./ex3-devel***************************************************************</pre></div><?php make_footer() ?></body></html><?php if (0) { ?>\#Local Variables:\#mode: html\#End:<?php } ?>

⌨️ 快捷键说明

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