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

📄 ex12.php

📁 一个用来实现偏微分方程中网格的计算库
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<pre>              std::vector&lt;Number&gt; node_data;              node_data.resize(2);        </pre></div><div class = "comment">Use a sin curve in z-direction and a linearincrease in x-direction</div><div class ="fragment"><pre>              const Point& p = **node_it;        	              const Real z_normalized = (p(2)-z_min)/(z_max-z_min);              const Real x_normalized = (p(0)-x_min)/(x_max-x_min);                      node_data[0] = sin(2*libMesh::pi*z_normalized);              node_data[1] = x_normalized;              </pre></div><div class = "comment">Insert the current data together with a pointer tothe current node in the map.</div><div class ="fragment"><pre>              art_data.insert (std::make_pair(*node_it,node_data));            }        }</pre></div><a name="nocomments"></a> <br><br><br> <h1> The program without comments: </h1> <pre>     #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_tools.h&quot;</FONT></B>  #include <B><FONT COLOR="#BC8F8F">&quot;mesh_data.h&quot;</FONT></B>  #include <B><FONT COLOR="#BC8F8F">&quot;unv_io.h&quot;</FONT></B>  #include <B><FONT COLOR="#BC8F8F">&quot;gmv_io.h&quot;</FONT></B>    #include <B><FONT COLOR="#BC8F8F">&quot;node.h&quot;</FONT></B>    <B><FONT COLOR="#228B22">void</FONT></B> create_artificial_data (<B><FONT COLOR="#228B22">const</FONT></B> Mesh&amp; mesh,  			     <B><FONT COLOR="#5F9EA0">std</FONT></B>::map&lt;<B><FONT COLOR="#228B22">const</FONT></B> Node*, std::vector&lt;Number&gt; &gt;&amp; art_data);    <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="#A020F0">if</FONT></B> (argc &lt; 4)        {  	<B><FONT COLOR="#5F9EA0">std</FONT></B>::cerr &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;Usage: &quot;</FONT></B> &lt;&lt; argv[0] &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot; -d &lt;dim&gt; in_mesh.unv&quot;</FONT></B>  		  &lt;&lt; std::endl;  	  	error();        }        <B><FONT COLOR="#228B22">const</FONT></B> <B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">int</FONT></B> dim = std::atoi(argv[2]);            <B><FONT COLOR="#228B22">const</FONT></B> std::string mesh_file = argv[3];        <B><FONT COLOR="#A020F0">if</FONT></B> (mesh_file.rfind(<B><FONT COLOR="#BC8F8F">&quot;.unv&quot;</FONT></B>) &gt;= mesh_file.size())        {  	<B><FONT COLOR="#5F9EA0">std</FONT></B>::cerr &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;ERROR:  This example works only properly with a Universal mesh file!&quot;</FONT></B>  		  &lt;&lt; std::endl;  	  	error();        }          {        assert (dim == 3);        Mesh mesh(dim);        MeshData mesh_data(mesh);                mesh_data.activate();          mesh.read (mesh_file, &amp;mesh_data);                <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; std::endl   		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;Finished reading the mesh.  MeshData is active but empty:&quot;</FONT></B> &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;---------------------------------------------------------&quot;</FONT></B> &lt;&lt; std::endl;                mesh.print_info();        mesh_data.print_info();              {  	<B><FONT COLOR="#5F9EA0">std</FONT></B>::map&lt;<B><FONT COLOR="#228B22">const</FONT></B> Node*, std::vector&lt;Number&gt; &gt; artificial_data;  	  	create_artificial_data (mesh, artificial_data);  	  	mesh_data.insert_node_data(artificial_data);          }                <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; std::endl   		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;After inserting artificial data into the MeshData:&quot;</FONT></B> &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;--------------------------------------------------&quot;</FONT></B> &lt;&lt; std::endl;                mesh_data.print_info();          <B><FONT COLOR="#5F9EA0">std</FONT></B>::string first_out_data=<B><FONT COLOR="#BC8F8F">&quot;data_first_out_with_default_header.unv&quot;</FONT></B>;        <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;Writing MeshData to: &quot;</FONT></B> &lt;&lt; first_out_data &lt;&lt; std::endl;        mesh_data.write(first_out_data);          <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; std::endl   		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;Attach our own MeshDataUnvHeader to the MeshData:&quot;</FONT></B> &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;-------------------------------------------------&quot;</FONT></B> &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot; (note the warning: the number of values per node in&quot;</FONT></B> &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;  my_header is not correct)&quot;</FONT></B> &lt;&lt; std::endl &lt;&lt; std::endl;        MeshDataUnvHeader my_header;          my_header.dataset_label = 3;          my_header.id_lines_1_to_5[0] = <B><FONT COLOR="#BC8F8F">&quot;Artificial data&quot;</FONT></B>;        my_header.id_lines_1_to_5[1] = <B><FONT COLOR="#BC8F8F">&quot;sin curve in z-direction&quot;</FONT></B>;        my_header.id_lines_1_to_5[2] = <B><FONT COLOR="#BC8F8F">&quot;line in x-direction&quot;</FONT></B>;                my_header.record_12[0] = libMesh::pi;                mesh_data.set_unv_header(&amp;my_header);          <B><FONT COLOR="#5F9EA0">std</FONT></B>::string second_out_data=<B><FONT COLOR="#BC8F8F">&quot;data_second_with_header_out.unv&quot;</FONT></B>;        <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;Writing MeshData to: &quot;</FONT></B> &lt;&lt; second_out_data &lt;&lt; std::endl;        mesh_data.write(second_out_data);                <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; std::endl   		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;Before clearing the MeshData:&quot;</FONT></B> &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;-----------------------------&quot;</FONT></B> &lt;&lt; std::endl;        mesh_data.print_info();          mesh_data.clear();          <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; std::endl   		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;After clearing the MeshData:&quot;</FONT></B> &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;----------------------------&quot;</FONT></B> &lt;&lt; std::endl;        mesh_data.print_info();          mesh_data.read(first_out_data);                <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; std::endl   		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;After re-reading the first file:&quot;</FONT></B> &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;--------------------------------&quot;</FONT></B> &lt;&lt; std::endl;        mesh_data.print_info();        }                                  <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; std::endl   	      &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;----------------------------------------------&quot;</FONT></B> &lt;&lt; std::endl  	      &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;---------- next example with MeshData --------&quot;</FONT></B> &lt;&lt; std::endl  	      &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;----------------------------------------------&quot;</FONT></B> &lt;&lt; std::endl;        {        Mesh mesh(dim);        MeshData mesh_data(mesh);                mesh.read(mesh_file, &amp;mesh_data);                <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; std::endl   		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;De-activated MeshData:&quot;</FONT></B> &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;----------------------&quot;</FONT></B> &lt;&lt; std::endl;        mesh.print_info();        mesh_data.print_info();           <B><FONT COLOR="#228B22">const</FONT></B> std::string out_mesh = <B><FONT COLOR="#BC8F8F">&quot;mesh_with_libmesh_ids.unv&quot;</FONT></B>;        <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;Writing _Mesh_ to: &quot;</FONT></B> &lt;&lt; out_mesh &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;Try 'diff &quot;</FONT></B> &lt;&lt; out_mesh &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot; &quot;</FONT></B> &lt;&lt; mesh_file &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;'&quot;</FONT></B> &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;to see the differences in node numbers.&quot;</FONT></B> &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;---------------------------------------&quot;</FONT></B> &lt;&lt; std::endl  		&lt;&lt; std::endl;        mesh.write(out_mesh, &amp;mesh_data);          {  	<B><FONT COLOR="#5F9EA0">std</FONT></B>::map&lt;<B><FONT COLOR="#228B22">const</FONT></B> Node*, std::vector&lt;Number&gt; &gt; artificial_data;  	create_artificial_data (mesh, artificial_data);  	mesh_data.insert_node_data(artificial_data);        }          mesh_data.enable_compatibility_mode();          <B><FONT COLOR="#5F9EA0">std</FONT></B>::string mesh_data_file = <B><FONT COLOR="#BC8F8F">&quot;data_third_with_libmesh_ids_out.unv&quot;</FONT></B>;        <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; std::endl   		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;Writing MeshData to: &quot;</FONT></B> &lt;&lt; mesh_data_file &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;----------------------------------------------------------&quot;</FONT></B>   		&lt;&lt; std::endl &lt;&lt; std::endl;        mesh_data.write (mesh_data_file);    #ifdef HAVE_ZLIB_H          <B><FONT COLOR="#5F9EA0">std</FONT></B>::string packed_mesh_data_file =  <B><FONT COLOR="#BC8F8F">&quot;packed_&quot;</FONT></B> + mesh_data_file + <B><FONT COLOR="#BC8F8F">&quot;.gz&quot;</FONT></B>;        <B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; std::endl   		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;Writing gzip'ed MeshData to: &quot;</FONT></B> &lt;&lt; packed_mesh_data_file &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;---------------------------------------------------------------------------&quot;</FONT></B> &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot; To verify the integrity of the packed version, type:&quot;</FONT></B> &lt;&lt; std::endl &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;   gunzip &quot;</FONT></B> &lt;&lt; packed_mesh_data_file &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;; &quot;</FONT></B> &lt;&lt; std::endl  		&lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;   diff packed_&quot;</FONT></B> &lt;&lt; mesh_data_file &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot; &quot;</FONT></B>   		&lt;&lt; mesh_data_file &lt;&lt; std::endl &lt;&lt; std::endl;                mesh_data.write (packed_mesh_data_file);          #endif                            {  	<B><FONT COLOR="#5F9EA0">std</FONT></B>::vector&lt;Number&gt; translated_data;  	<B><FONT COLOR="#5F9EA0">std</FONT></B>::vector&lt;std::string&gt; data_names;  	  	mesh_data.translate (mesh,  			     translated_data,  			     data_names);      	<B><FONT COLOR="#228B22">const</FONT></B> std::string gmv_file = <B><FONT COLOR="#BC8F8F">&quot;data_and_mesh_out.gmv&quot;</FONT></B>;  	<B><FONT COLOR="#5F9EA0">std</FONT></B>::cout &lt;&lt; std::endl   		  &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;Writing the data from the MeshData to the GMV file &quot;</FONT></B>   		  &lt;&lt; gmv_file &lt;&lt; std::endl  		  &lt;&lt; <B><FONT COLOR="#BC8F8F">&quot;------------------------------------------------------------------------&quot;</FONT></B>   		  &lt;&lt; std::endl;  	  	GMVIO(mesh).write_nodal_data (gmv_file,  				      translated_data,  				      data_names);  	        }              }    }      <B><FONT COLOR="#A020F0">return</FONT></B> libMesh::close();  }                  <B><FONT COLOR="#228B22">void</FONT></B> create_artificial_data (<B><FONT COLOR="#228B22">const</FONT></B> Mesh&amp; mesh,  			     <B><FONT COLOR="#5F9EA0">std</FONT></B>::map&lt;<B><FONT COLOR="#228B22">const</FONT></B> Node*, std::vector&lt;Number&gt; &gt;&amp; art_data)  {    <B><FONT COLOR="#5F9EA0">MeshTools</FONT></B>::BoundingBox b_box = MeshTools::bounding_box(mesh);      <B><FONT COLOR="#228B22">const</FONT></B> Real z_min = b_box.first (2);    <B><FONT COLOR="#228B22">const</FONT></B> Real z_max = b_box.second(2);    assert (fabs(z_max-z_min) &gt; TOLERANCE);      <B><FONT COLOR="#228B22">const</FONT></B> Real x_min = b_box.first (0);    <B><FONT COLOR="#228B22">const</FONT></B> Real x_max = b_box.second(0);    assert (fabs(x_max-x_min) &gt; TOLERANCE);          <B><FONT COLOR="#5F9EA0">MeshBase</FONT></B>::const_node_iterator       node_it  = mesh.nodes_begin();    <B><FONT COLOR="#228B22">const</FONT></B> MeshBase::const_node_iterator node_end = mesh.nodes_end();      <B><FONT COLOR="#A020F0">for</FONT></B> (; node_it != node_end; ++node_it)      {        <B><FONT COLOR="#5F9EA0">std</FONT></B>::vector&lt;Number&gt; node_data;        node_data.resize(2);          <B><FONT COLOR="#228B22">const</FONT></B> Point&amp; p = **node_it;  	        <B><FONT COLOR="#228B22">const</FONT></B> Real z_normalized = (p(2)-z_min)/(z_max-z_min);        <B><FONT COLOR="#228B22">const</FONT></B> Real x_normalized = (p(0)-x_min)/(x_max-x_min);          node_data[0] = sin(2*libMesh::pi*z_normalized);        node_data[1] = x_normalized;                art_data.insert (std::make_pair(*node_it,node_data));      }  }</pre> <a name="output"></a> <br><br><br> <h1> The console output of the program: </h1> <pre>**************************************************************** Running Example  ./ex12-devel -d 3 ../../examples/ex8/pipe-mesh.unv*************************************************************** Finished reading the mesh.  MeshData is active but empty:--------------------------------------------------------- Mesh Information:  mesh_dimension()=3  spatial_dimension()=3  n_nodes()=3977  n_elem()=3520   n_local_elem()=3520   n_active_elem()=3520  n_subdomains()=1  n_processors()=1  processor_id()=0 MeshData Information:  object activated.After inserting artificial data into the MeshData:-------------------------------------------------- MeshData Information:  object activated.  Element associated data initialized.   n_val_per_elem()=0   n_elem_data()=0  Node associated data initialized.   n_val_per_node()=2   n_node_data()=3977Writing MeshData to: data_first_out_with_default_header.unvAttach our own MeshDataUnvHeader to the MeshData:------------------------------------------------- (note the warning: the number of values per node in  my_header is not correct)Writing MeshData to: data_second_with_header_out.unvWARNING: nvaldc=3 of attached MeshDataUnvHeader object not valid!         re-set nvaldc to 2Before clearing the MeshData:----------------------------- MeshData Information:  object activated.  Element associated data initialized.   n_val_per_elem()=0   n_elem_data()=0  Node associated data initialized.   n_val_per_node()=2   n_node_data()=3977After clearing the MeshData:---------------------------- MeshData Information:  object activated.After re-reading the first file:-------------------------------- MeshData Information:  object activated.  Element associated data initialized.   n_val_per_elem()=0   n_elem_data()=0  Node associated data initialized.   n_val_per_node()=2   n_node_data()=3977-------------------------------------------------------- next example with MeshData ------------------------------------------------------De-activated MeshData:---------------------- Mesh Information:  mesh_dimension()=3  spatial_dimension()=3  n_nodes()=3977  n_elem()=3520   n_local_elem()=3520   n_active_elem()=3520  n_subdomains()=1  n_processors()=1  processor_id()=0 MeshData neither active nor in compatibility mode.Writing _Mesh_ to: mesh_with_libmesh_ids.unvTry 'diff mesh_with_libmesh_ids.unv ../../examples/ex8/pipe-mesh.unv'to see the differences in node numbers.---------------------------------------************************************************************************** WARNING: MeshData neither active nor in compatibility mode.           **          Enable compatibility mode for MeshData.  Use this Universal  **          file with caution: libMesh node and element ids are used.    **************************************************************************Writing MeshData to: data_third_with_libmesh_ids_out.unv----------------------------------------------------------Writing gzip'ed MeshData to: packed_data_third_with_libmesh_ids_out.unv.gz--------------------------------------------------------------------------- To verify the integrity of the packed version, type:   gunzip packed_data_third_with_libmesh_ids_out.unv.gz;    diff packed_data_third_with_libmesh_ids_out.unv data_third_with_libmesh_ids_out.unvWriting the data from the MeshData to the GMV file data_and_mesh_out.gmv------------------------------------------------------------------------ **************************************************************** Done Running Example  ./ex12-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 + -