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

📄 system_io.c

📁 一个用来实现偏微分方程中网格的计算库
💻 C
📖 第 1 页 / 共 4 页
字号:
   * documentation.  The output of this part    * consists of 5 sections:   *   * for this system   *   *   5.) The number of variables in the system (unsigned int)   *   *   for each variable in the system   *        *     6.) The name of the variable (string)   *        *     7.) Combined in an FEType:   *         - The approximation order(s) of the variable    *           (Order Enum, cast to int/s)   *         - The finite element family/ies of the variable    *           (FEFamily Enum, cast to int/s)   *    *   end variable loop   *   *   8.) The number of additional vectors (unsigned int),         *   *     for each additional vector in the system object   *    *     9.) the name of the additional vector  (string)   *   * end system   */   libmesh_assert (io.writing());  // Only write the header information  // if we are processor 0.  if (this->get_mesh().processor_id() != 0)    return;    std::string comment;  char buf[80];  // 5.)   // Write the number of variables in the system  {    // set up the comment    comment = "# No. of Variables in System \"";    comment += this->name();    comment += "\"";    	      unsigned int n_vars = this->n_vars();       io.data (n_vars, comment.c_str());  }  for (unsigned int var=0; var<this->n_vars(); var++)    {      // 6.)      // Write the name of the var-th variable      {	// set up the comment	comment  = "#   Name, Variable No. ";	std::sprintf(buf, "%d", var);	comment += buf;	comment += ", System \"";	comment += this->name();	comment += "\"";	      	std::string var_name = this->variable_name(var);	     	io.data (var_name, comment.c_str());      }            // 7.)      // Write the approximation order of the var-th variable       // in this system      {	// set up the comment	comment = "#     Approximation Order, Variable \"";	std::sprintf(buf, "%s", this->variable_name(var).c_str());	comment += buf;	comment += "\", System \"";	comment += this->name();	comment += "\"";	      	int order = static_cast<int>(this->variable_type(var).order);	      	io.data (order, comment.c_str());      }#ifdef ENABLE_INFINITE_ELEMENTS            // do the same for radial_order      {	comment = "#     Radial Approximation Order, Variable \"";	std::sprintf(buf, "%s", this->variable_name(var).c_str());	comment += buf;	comment += "\", System \"";	comment += this->name();	comment += "\"";      	int rad_order = static_cast<int>(this->variable_type(var).radial_order);	      	io.data (rad_order, comment.c_str());      }#endif            // Write the Finite Element type of the var-th variable       // in this System      {	// set up the comment	comment = "#     FE Family, Variable \"";	std::sprintf(buf, "%s", this->variable_name(var).c_str());	comment += buf;	comment += "\", System \"";	comment += this->name();	comment += "\"";      	const FEType& type = this->variable_type(var);	      	int fam = static_cast<int>(type.family);	      	io.data (fam, comment.c_str());#ifdef ENABLE_INFINITE_ELEMENTS		comment = "#     Radial FE Family, Variable \"";	std::sprintf(buf, "%s", this->variable_name(var).c_str());	comment += buf;	comment += "\", System \"";	comment += this->name();	comment += "\"";      	int radial_fam = static_cast<int>(type.radial_family);	io.data (radial_fam, comment.c_str());			comment = "#     Infinite Mapping Type, Variable \"";	std::sprintf(buf, "%s", this->variable_name(var).c_str());	comment += buf;	comment += "\", System \"";	comment += this->name();	comment += "\"";	int i_map = static_cast<int>(type.inf_map);	      	io.data (i_map, comment.c_str());#endif      }    } // end of the variable loop   // 8.)   // Write the number of additional vectors in the System.  // If write_additional_data==false, then write zero for  // the number of additional vectors.  {	      {      // set up the comment      comment = "# No. of Additional Vectors, System \"";      comment += this->name();      comment += "\"";          unsigned int n_vectors = write_additional_data ? this->n_vectors () : 0;      io.data (n_vectors, comment.c_str());    }            if (write_additional_data)      {	std::map<std::string, NumericVector<Number>* >::const_iterator	  vec_pos = this->_vectors.begin();	unsigned int cnt=0;		for (; vec_pos != this->_vectors.end(); ++vec_pos)	  {	    // 9.)	    // write the name of the cnt-th additional vector	    comment =  "# Name of ";	    std::sprintf(buf, "%d", cnt++);	    comment += buf;	    comment += "th vector";	    std::string vec_name = vec_pos->first;	    	    io.data (vec_name, comment.c_str());	  }      }  }}// void System::write_data (Xdr& io,// 			 const bool write_additional_data) const// {//   // This is deprecated -- use write_serialized_data() instead.  This will be kept for reference//   // for a little while, then dropped.  There is no need call this method any more.//   deprecated();  //   /**//    * This method implements the output of the vectors//    * contained in this System object, embedded in the //    * output of an EquationSystems<T_sys>. //    *//    *   9.) The global solution vector, re-ordered to be node-major //    *       (More on this later.)                                    //    *                                                                //    *      for each additional vector in the object          //    *                                                                //    *      10.) The global additional vector, re-ordered to be       //    *           node-major (More on this later.)//    *//    * Note that the actual IO is handled through the Xdr class //    * (to be renamed later?) which provides a uniform interface to //    * both the XDR (eXternal Data Representation) interface and standard//    * ASCII output.  Thus this one section of code will read XDR or ASCII//    * files with no changes.//    */ //   libmesh_assert (io.writing());//   const unsigned int proc_id = this->get_mesh().processor_id(); //   std::string comment;  //   // All processors contribute numeric vector values//   std::vector<Number> global_vector;//   // Collect the global solution on one processor//   this->solution->localize_to_one (global_vector, 0);       //   // Only processor 0 actually writes out the soltuion vector.  //   if (proc_id == 0)//     {	       //       // First we need to re-order the solution so that it//       // is dof_map agnostic.  This is necessary so that the //       // vector might be re-read with a different partitioning//       // or DOF distribution.  //       ////       // Currently the vector is written in node-major order.//       std::vector<Number> reordered_soln(global_vector.size());	  //       unsigned int cnt=0;//       const unsigned int sys_num = this->number();//       const unsigned int n_vars  = this->n_vars();//       // Build a set of non subactive node indices. //       std::set<unsigned int> not_subactive_node_ids;//       MeshTools::get_not_subactive_node_ids(this->get_mesh(), not_subactive_node_ids);//       // Loop over each variable and each node, and write out the value.//       for (unsigned int var=0; var<n_vars; var++)//         {		// 	  // First write the nodal DOF values//           std::set<unsigned int>::iterator it = not_subactive_node_ids.begin();//           const std::set<unsigned int>::iterator end = not_subactive_node_ids.end();          //           for (; it != end; ++it)//           {//             // Get the global index of this node//             const unsigned int node = *it;// 	    for (unsigned int index=0; index<this->get_mesh().node(node).n_comp(sys_num, var); index++)// 	      {//                 libmesh_assert (this->get_mesh().node(node).id() == node);// 		libmesh_assert (this->get_mesh().node(node).dof_number(sys_num, var, index) !=// 			DofObject::invalid_id);// 		libmesh_assert (cnt < reordered_soln.size());		// 		reordered_soln[cnt++] = // 		  global_vector[this->get_mesh().node(node).dof_number(sys_num, var, index)];// 	      }//           }// 	  // Then write the element DOF values// 	  {// 	    MeshBase::const_element_iterator// 	      it  = this->get_mesh().active_elements_begin(),// 	      end = this->get_mesh().active_elements_end();// 	    for (; it!=end; ++it)// 	      for (unsigned int index=0; index<(*it)->n_comp(sys_num, var); index++)// 	        {// 		  libmesh_assert ((*it)->dof_number(sys_num, var, index) !=// 			  DofObject::invalid_id);			// 		  libmesh_assert (cnt < reordered_soln.size());			// 		  reordered_soln[cnt++] = // 		      global_vector[(*it)->dof_number(sys_num, var, index)];// 		}// 	  }// 	}//       // 9.)//       ////       // Actually write the reordered solution vector //       // for the ith system to disk//       // set up the comment//       {// 	comment = "# System \"";// 	comment += this->name();// 	comment += "\" Solution Vector";//       }//       io.data (reordered_soln, comment.c_str());	  //     }  //   // Only write additional vectors if wanted  //   if (write_additional_data)//     {	  //       std::map<std::string, NumericVector<Number>* >::const_iterator// 	pos = _vectors.begin();  //       for(; pos != this->_vectors.end(); ++pos)//         {// 	  // fill with zero.  In general, a resize is not necessary	       // 	  std::fill (global_vector.begin(), global_vector.end(), libMesh::zero);// 	  // Collect the global solution on one processor// 	  pos->second->localize_to_one (global_vector, 0);           // 	  // Only processor 0 actually writes out the  vector.  // 	  if (proc_id == 0)// 	    {	  // 	      // First we need to re-order the solution so that it// 	      // is dof_map agnostic.  This is necessary so that the // 	      // vector might be re-read with a different partitioning// 	      // or DOF distribution.  // 	      //// 	      // Currently the vector is written in node-major order.// 	      std::vector<Number> reordered_soln(global_vector.size());	  // 	      unsigned int cnt=0;	      // 	      const unsigned int sys_num = this->number();// 	      const unsigned int n_vars  = this->n_vars();	      // 	      for (unsigned int var=0; var<n_vars; var++)// 		{		// 		  // First write the nodal DOF values// 		  {// 		    MeshBase::const_node_iterator// 		      it  = this->get_mesh().nodes_begin(),// 		      end = this->get_mesh().nodes_end();		    // 		    for (; it !=end; ++it)// 		      for (unsigned int index=0; index<(*it)->n_comp(sys_num, var); index++)// 			{// 			  libmesh_assert ((*it)->dof_number(sys_num, var, index) !=// 				  DofObject::invalid_id);			  // 			  libmesh_assert (cnt < reordered_soln.size());			  // 			  reordered_soln[cnt++] = // 			    global_vector[(*it)->dof_number(sys_num, var, index)];// 			}// 		  }		  // 		  // Then write the element DOF values// 		  {// 		    MeshBase::const_element_iterator// 		      it  = this->get_mesh().active_elements_begin(),// 		      end = this->get_mesh().active_elements_end();		    // 		    for (; it!=end; ++it)// 		      for (unsigned int index=0; index<(*it)->n_comp(sys_num, var); index++)// 			{// 			  libmesh_assert ((*it)->dof_number(sys_num, var, index) !=// 				  DofObject::invalid_id);			    // 			  libmesh_assert (cnt < reordered_soln.size());			  // 			  reordered_soln[cnt++] = // 			    global_vector[(*it)->dof_number(sys_num, var, index)];// 			}// 		  }// 		}	    // 	      // 10.)// 	      //// 	      // Actually write the reordered additional vector // 	      // for this system to disk// 	      // set up the comment// 	      {// 		comment = "# System \"";// 		comment += this->name(); // 		comment += "\" Additional Vector \"";// 		comment += pos->first;// 		comment += "\"";// 	      }	      // 	      io.data (reordered_soln, comment.c_str());	  // 	    }// 	}//     }// }void System::write_parallel_data (Xdr &io,				  const bool write_additional_data) const{  /**   * This method implements the output of the vectors   * contained in this System object, embedded in the    * output of an EquationSystems<T_sys>.    *   *   9.) The global solution vector, re-ordered to be node-major    *       (More on this later.)                                       *                                                                   *      for each additional vector in the object             *                                                                   *      10.) The global additional vector, re-ordered to be          *           node-major (More on this later.)

⌨️ 快捷键说明

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