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

📄 ex6.php

📁 一个用来实现偏微分方程中网格的计算库
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<div class ="fragment"><pre>                  for (unsigned int i=0; i&lt;n_sf; i++)        	    for (unsigned int j=0; j&lt;n_sf; j++)        	      {</pre></div><div class = "comment">(ndt*Ht + nHt*d) * nH </div><div class ="fragment"><pre>                        Ke(i,j) +=        		  (                            //    (                                 		   (                           //      (                               		    dweight[qp] * phi[i][qp]   //        Point * Real  = Point         		    +                          //        +                             		    dphi[i][qp] * weight[qp]   //        Point * Real  = Point         		    ) * dphi[j][qp]            //      )       * Point = Real          		   ) * JxW[qp];                //    )         * Real  = Real          </pre></div><div class = "comment">(d*Ht*nmut*nH - ndt*nmu*Ht*H - d*nHt*nmu*H)</div><div class ="fragment"><pre>                        Ce(i,j) +=        		  (                                //    (                                 		   (dphase[qp] * dphi[j][qp])      //      (Point * Point) = Real          		   * weight[qp] * phi[i][qp]       //      * Real * Real   = Real          		   -                               //      -                               		   (dweight[qp] * dphase[qp])      //      (Point * Point) = Real          		   * phi[i][qp] * phi[j][qp]       //      * Real * Real   = Real          		   -                               //      -                               		   (dphi[i][qp] * dphase[qp])      //      (Point * Point) = Real          		   * weight[qp] * phi[j][qp]       //      * Real * Real   = Real          		   ) * JxW[qp];                    //    )         * Real  = Real          		</pre></div><div class = "comment">(d*Ht*H * (1 - nmut*nmu))</div><div class ="fragment"><pre>                        Me(i,j) +=        		  (                                       //    (                                          		   (1. - (dphase[qp] * dphase[qp]))       //      (Real  - (Point * Point)) = Real         		   * phi[i][qp] * phi[j][qp] * weight[qp] //      * Real *  Real  * Real    = Real         		   ) * JxW[qp];                           //    ) * Real                    = Real                 	      } // end of the matrix summation loop        	} // end of quadrature point loop        </pre></div><div class = "comment">The element matrices are now built for this element.  Collect them in Ke, and then add them to the global matrix.  The \p SparseMatrix::add_matrix() member does this for us.</div><div class ="fragment"><pre>              Ke.add(1./speed        , Ce);              Ke.add(1./(speed*speed), Me);                      system.matrix-&gt;add_matrix (Ke, dof_indices);            } // end of element loop        </pre></div><div class = "comment">Note that we have not applied any boundary conditions so far.Here we apply a unit load at the node located at (0,0,0).</div><div class ="fragment"><pre>          {</pre></div><div class = "comment">Number of nodes in the mesh.     </div><div class ="fragment"><pre>            const unsigned int n_nodes = mesh.n_nodes();                        for (unsigned int n_cnt=0; n_cnt&lt;n_nodes; n_cnt++)              {	</pre></div><div class = "comment">Get a reference to the current node.</div><div class ="fragment"><pre>                const Node& curr_node = mesh.node(n_cnt);        	</pre></div><div class = "comment">Check the location of the current node.</div><div class ="fragment"><pre>                if (fabs(curr_node(0)) &lt; TOLERANCE &&        	    fabs(curr_node(1)) &lt; TOLERANCE &&        	    fabs(curr_node(2)) &lt; TOLERANCE)        	  {</pre></div><div class = "comment">The global number of the respective degree of freedom.</div><div class ="fragment"><pre>                    unsigned int dn = curr_node.dof_number(0,0,0);                	    system.rhs-&gt;add (dn, 1.);        	  }              }          }                #else        </pre></div><div class = "comment">dummy assert </div><div class ="fragment"><pre>          assert(es.get_mesh().mesh_dimension() != 1);                #endif //ifdef ENABLE_INFINITE_ELEMENTS          </pre></div><div class = "comment">All done!   </div><div class ="fragment"><pre>          return;        }        </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;inf_fe.h&quot;</FONT></B>  #include <B><FONT COLOR="#BC8F8F">&quot;inf_elem_builder.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;dof_map.h&quot;</FONT></B>    #include <B><FONT COLOR="#BC8F8F">&quot;node.h&quot;</FONT></B>    #include <B><FONT COLOR="#BC8F8F">&quot;elem.h&quot;</FONT></B>    <B><FONT COLOR="#228B22">void</FONT></B> assemble_wave (EquationSystems&amp; es,  		    <B><FONT COLOR="#228B22">const</FONT></B> std::string&amp; system_name);    <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);      #ifndef ENABLE_INFINITE_ELEMENTS      <B><FONT COLOR="#5F9EA0">std</FONT></B>::cerr &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;ERROR: This example requires the library to be compiled with Infinite Element support!&quot;</FONT></B>  	    &lt;&lt; std::endl;    here();      <B><FONT COLOR="#A020F0">return</FONT></B> 0;    #<B><FONT COLOR="#A020F0">else</FONT></B>        {              <B><FONT COLOR="#228B22">const</FONT></B> <B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> dim = 3;             <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;Running ex6 with dim = &quot;</FONT></B> &lt;&lt; dim &lt;&lt; std::endl &lt;&lt; std::endl;                    Mesh mesh (dim);        <B><FONT COLOR="#5F9EA0">MeshTools</FONT></B>::Generation::build_cube (mesh,  				       4, 4, 4,  				       -1., 1.,  				       -1., 1.,  				       -1., 1.,  				       HEX8);            mesh.print_info();        GMVIO(mesh).write (<B><FONT COLOR="#BC8F8F">&quot;orig_mesh.gmv&quot;</FONT></B>);            InfElemBuilder builder(mesh);      builder.build_inf_elem(true);        mesh.print_info();        GMVIO(mesh).write (<B><FONT COLOR="#BC8F8F">&quot;ifems_added.gmv&quot;</FONT></B>);            mesh.find_neighbors();            EquationSystems equation_systems (mesh);            {        equation_systems.add_system&lt;LinearImplicitSystem&gt; (<B><FONT COLOR="#BC8F8F">&quot;Wave&quot;</FONT></B>);                      FEType fe_type(FIRST);                equation_systems.get_system(<B><FONT COLOR="#BC8F8F">&quot;Wave&quot;</FONT></B>).add_variable(<B><FONT COLOR="#BC8F8F">&quot;p&quot;</FONT></B>, fe_type);                equation_systems.get_system(<B><FONT COLOR="#BC8F8F">&quot;Wave&quot;</FONT></B>).attach_assemble_function (assemble_wave);                equation_systems.parameters.set&lt;Real&gt;(<B><FONT COLOR="#BC8F8F">&quot;speed&quot;</FONT></B>)          = 1.;        equation_systems.parameters.set&lt;Real&gt;(<B><FONT COLOR="#BC8F8F">&quot;fluid density&quot;</FONT></B>)  = 1.;                equation_systems.init();                equation_systems.print_info();      }            equation_systems.get_system(<B><FONT COLOR="#BC8F8F">&quot;Wave&quot;</FONT></B>).solve();            equation_systems.write (<B><FONT COLOR="#BC8F8F">&quot;eqn_sys.dat&quot;</FONT></B>, libMeshEnums::WRITE);    }        <B><FONT COLOR="#A020F0">return</FONT></B> libMesh::close ();    #endif <I><FONT COLOR="#B22222">// else part of ifndef ENABLE_INFINITE_ELEMENTS</FONT></I>  }    <B><FONT COLOR="#228B22">void</FONT></B> assemble_wave(EquationSystems&amp; es,  		   <B><FONT COLOR="#228B22">const</FONT></B> std::string&amp; system_name)  {    assert (system_name == <B><FONT COLOR="#BC8F8F">&quot;Wave&quot;</FONT></B>);      #ifdef ENABLE_INFINITE_ELEMENTS        <B><FONT COLOR="#228B22">const</FONT></B> Mesh&amp; mesh = es.get_mesh();      LinearImplicitSystem &amp; system = es.get_system&lt;LinearImplicitSystem&gt;(<B><FONT COLOR="#BC8F8F">&quot;Wave&quot;</FONT></B>);        <B><FONT COLOR="#228B22">const</FONT></B> DofMap&amp; dof_map = system.get_dof_map();        <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();        <B><FONT COLOR="#228B22">const</FONT></B> Real speed = es.parameters.get&lt;Real&gt;(<B><FONT COLOR="#BC8F8F">&quot;speed&quot;</FONT></B>);        <B><FONT COLOR="#228B22">const</FONT></B> FEType&amp; fe_type = dof_map.variable_type(0);        AutoPtr&lt;FEBase&gt; fe (FEBase::build(dim, fe_type));        AutoPtr&lt;FEBase&gt; inf_fe (FEBase::build_InfFE(dim, fe_type));        QGauss qrule (dim, SECOND);        fe-&gt;attach_quadrature_rule (&amp;qrule);        inf_fe-&gt;attach_quadrature_rule (&amp;qrule);        DenseMatrix&lt;Number&gt; Ke;    DenseMatrix&lt;Number&gt; Ce;    DenseMatrix&lt;Number&gt; Me;    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.local_elements_begin();    <B><FONT COLOR="#228B22">const</FONT></B> MeshBase::const_element_iterator end_el = mesh.local_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);                  FEBase* cfe=NULL;                <B><FONT COLOR="#A020F0">if</FONT></B> (elem-&gt;infinite())          {	     	  cfe = inf_fe.get();   	}        <B><FONT COLOR="#A020F0">else</FONT></B>          {    	  cfe = fe.get();  	    	  {	        	    Fe.resize (dof_indices.size());  	      	    system.rhs-&gt;add_vector (Fe, dof_indices);  	  } <I><FONT COLOR="#B22222">// end boundary condition section	     </FONT></I>  	} <I><FONT COLOR="#B22222">// else ( if (elem-&gt;infinite())) )</FONT></I>          <B><FONT COLOR="#228B22">const</FONT></B> std::vector&lt;Real&gt;&amp; JxW = cfe-&gt;get_JxW();                <B><FONT COLOR="#228B22">const</FONT></B> std::vector&lt;std::vector&lt;Real&gt; &gt;&amp; phi = cfe-&gt;get_phi();                <B><FONT COLOR="#228B22">const</FONT></B> std::vector&lt;std::vector&lt;RealGradient&gt; &gt;&amp; dphi = cfe-&gt;get_dphi();          <B><FONT COLOR="#228B22">const</FONT></B> std::vector&lt;RealGradient&gt;&amp; dphase  = cfe-&gt;get_dphase();        <B><FONT COLOR="#228B22">const</FONT></B> std::vector&lt;Real&gt;&amp;         weight  = cfe-&gt;get_Sobolev_weight();        <B><FONT COLOR="#228B22">const</FONT></B> std::vector&lt;RealGradient&gt;&amp; dweight = cfe-&gt;get_Sobolev_dweight();          cfe-&gt;reinit (elem);                Ke.resize (dof_indices.size(), dof_indices.size());        Ce.resize (dof_indices.size(), dof_indices.size());        Me.resize (dof_indices.size(), dof_indices.size());                <B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> max_qp = cfe-&gt;n_quadrature_points();                <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;max_qp; qp++)          {	    	  <B><FONT COLOR="#228B22">const</FONT></B> <B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> n_sf = cfe-&gt;n_shape_functions();    	  <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;n_sf; 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;n_sf; j++)  	      {  		Ke(i,j) +=  		  (                            <I><FONT COLOR="#B22222">//    (                         </FONT></I>  		   (                           <I><FONT COLOR="#B22222">//      (                       </FONT></I>  		    dweight[qp] * phi[i][qp]   <I><FONT COLOR="#B22222">//        Point * Real  = Point </FONT></I>  		    +                          <I><FONT COLOR="#B22222">//        +                     </FONT></I>  		    dphi[i][qp] * weight[qp]   <I><FONT COLOR="#B22222">//        Point * Real  = Point </FONT></I>  		    ) * dphi[j][qp]            <I><FONT COLOR="#B22222">//      )       * Point = Real  </FONT></I>  		   ) * JxW[qp];                <I><FONT COLOR="#B22222">//    )         * Real  = Real  </FONT></I>    		Ce(i,j) +=  		  (                                <I><FONT COLOR="#B22222">//    (                         </FONT></I>  		   (dphase[qp] * dphi[j][qp])      <I><FONT COLOR="#B22222">//      (Point * Point) = Real  </FONT></I>  		   * weight[qp] * phi[i][qp]       <I><FONT COLOR="#B22222">//      * Real * Real   = Real  </FONT></I>  		   -                               <I><FONT COLOR="#B22222">//      -                       </FONT></I>  		   (dweight[qp] * dphase[qp])      <I><FONT COLOR="#B22222">//      (Point * Point) = Real  </FONT></I>  		   * phi[i][qp] * phi[j][qp]       <I><FONT COLOR="#B22222">//      * Real * Real   = Real  </FONT></I>  		   -                               <I><FONT COLOR="#B22222">//      -                       </FONT></I>  		   (dphi[i][qp] * dphase[qp])      <I><FONT COLOR="#B22222">//      (Point * Point) = Real  </FONT></I>  		   * weight[qp] * phi[j][qp]       <I><FONT COLOR="#B22222">//      * Real * Real   = Real  </FONT></I>  		   ) * JxW[qp];                    <I><FONT COLOR="#B22222">//    )         * Real  = Real  </FONT></I>  		  		Me(i,j) +=  		  (                                       <I><FONT COLOR="#B22222">//    (                                  </FONT></I>  		   (1. - (dphase[qp] * dphase[qp]))       <I><FONT COLOR="#B22222">//      (Real  - (Point * Point)) = Real </FONT></I>  		   * phi[i][qp] * phi[j][qp] * weight[qp] <I><FONT COLOR="#B22222">//      * Real *  Real  * Real    = Real </FONT></I>  		   ) * JxW[qp];                           <I><FONT COLOR="#B22222">//    ) * Real                    = Real </FONT></I>    	      } <I><FONT COLOR="#B22222">// end of the matrix summation loop</FONT></I>  	} <I><FONT COLOR="#B22222">// end of quadrature point loop</FONT></I>          Ke.add(1./speed        , Ce);        Ke.add(1./(speed*speed), Me);          system.matrix-&gt;add_matrix (Ke, dof_indices);      } <I><FONT COLOR="#B22222">// end of element loop</FONT></I>      {      <B><FONT COLOR="#228B22">const</FONT></B> <B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> n_nodes = mesh.n_nodes();            <B><FONT COLOR="#A020F0">for</FONT></B> (<B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> n_cnt=0; n_cnt&lt;n_nodes; n_cnt++)        {	  	<B><FONT COLOR="#228B22">const</FONT></B> Node&amp; curr_node = mesh.node(n_cnt);  	  	<B><FONT COLOR="#A020F0">if</FONT></B> (fabs(curr_node(0)) &lt; TOLERANCE &amp;&amp;  	    fabs(curr_node(1)) &lt; TOLERANCE &amp;&amp;  	    fabs(curr_node(2)) &lt; TOLERANCE)  	  {  	    <B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> dn = curr_node.dof_number(0,0,0);    	    system.rhs-&gt;add (dn, 1.);  	  }        }    }    #<B><FONT COLOR="#A020F0">else</FONT></B>      assert(es.get_mesh().mesh_dimension() != 1);    #endif <I><FONT COLOR="#B22222">//ifdef ENABLE_INFINITE_ELEMENTS</FONT></I>        <B><FONT COLOR="#A020F0">return</FONT></B>;  }  </pre> <a name="output"></a> <br><br><br> <h1> The console output of the program: </h1> <pre>**************************************************************** Running Example  ./ex6-devel*************************************************************** ERROR: This example requires the library to be compiled with Infinite Element support![0] ex6.C, line 91, compiled Jun  6 2007 at 11:54:44 **************************************************************** Done Running Example  ./ex6-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 + -