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

📄 equation_systems_io.c

📁 一个用来实现偏微分方程中网格的计算库
💻 C
📖 第 1 页 / 共 2 页
字号:
            for (; pos != _systems.end(); ++pos)	if (read_legacy_format)	  {	    deprecated();	    pos->second->read_legacy_data (io, read_additional_data);	  }	else	  if (read_parallel_files)	    pos->second->read_parallel_data   (local_io, read_additional_data);	  else	    pos->second->read_serialized_data (io, read_additional_data);            // Undo the temporary numbering.      if (!read_legacy_format)	{	  if (dynamic_cast<ParallelMesh*>(const_cast<MeshBase*>(&_mesh)))	    {	      ParallelMesh *mesh = dynamic_cast<ParallelMesh*>(const_cast<MeshBase*>(&_mesh));    	      MeshTools::Private::fix_broken_node_and_element_numbering(*mesh);	    }	  else if (dynamic_cast<SerialMesh*>(const_cast<MeshBase*>(&_mesh)))	    {	      SerialMesh *mesh = dynamic_cast<SerialMesh*>(const_cast<MeshBase*>(&_mesh));    	      MeshTools::Private::fix_broken_node_and_element_numbering(*mesh);	    }	  else	    {	      std::cerr << "ERROR:  dynamic_cast<> to ParallelMesh and SerialMesh failed!"			<< std::endl;	      libmesh_error();	    }	  	}    }    STOP_LOG("read()","EquationSystems");    // Localize each system's data  this->update();}void EquationSystems::write(const std::string& name,			    const libMeshEnums::XdrMODE mode,                            const unsigned int write_flags) const{  /**   * This program implements the output of an    * EquationSystems object.  This warrants some    * documentation.  The output file essentially   * consists of 11 sections:   \verbatim     1.) The version header.     2.) The number of individual equation systems (unsigned int)            for each system                                                                  3.)  The name of the system (string)                    4.)  The type of the system (string)                       handled through System::read():        +-------------------------------------------------------------+     |  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 equation system object |     |                                                             |     |    9.) the name of the additional vector  (string)          |     +-------------------------------------------------------------+       end system loop          for each system, handled through System::write_{serialized,parallel}_data():            +--------------------------------------------------------------+     | 10.) The global solution vector, re-ordered to be node-major |     |     (More on this later.)                                    |     |                                                              |     |    for each additional vector in the equation system object  |     |                                                              |     |    11.) The global additional vector, re-ordered to be       |     |         node-major (More on this later.)                     |     +--------------------------------------------------------------+    end system loop   \endverbatim   *   * 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 write XDR or ASCII   * files with no changes.   */    // the EquationSystems::write() method should look constant,  // but we need to assign a temporary numbering to the nodes  // and elements in the mesh, which requires that we abuse const_cast  {    MeshBase &mesh = const_cast<MeshBase&>(this->get_mesh());    MeshTools::Private::globally_renumber_nodes_and_elements(mesh);  }     // set booleans from write_flags argument   const bool write_data            = write_flags & EquationSystems::WRITE_DATA;   const bool write_parallel_files  = write_flags & EquationSystems::WRITE_PARALLEL_FILES;   const bool write_additional_data = write_flags & EquationSystems::WRITE_ADDITIONAL_DATA;  // New scope so that io will close before we try to zip the file  {    Xdr io((libMesh::processor_id()==0) ? name : "", mode);        libmesh_assert (io.writing());        START_LOG("write()","EquationSystems");    const unsigned int proc_id = libMesh::processor_id();    unsigned int n_sys         = this->n_systems();        std::map<std::string, System*>::const_iterator      pos = _systems.begin();        std::string comment;    char buf[256];        // Only write the header information    // if we are processor 0.    if (proc_id == 0)       {	// 1.)	// Write the version header	std::string version = "libMesh-0.7.0+";	if (write_parallel_files) version += " parallel";	io.data (version, "# File Format Identifier");		// 2.)  	// Write the number of equation systems	io.data (n_sys, "# No. of Equation Systems");        	while (pos != _systems.end())	  {	    // 3.)	    // Write the name of the sys_num-th system	    {	      const unsigned int sys_num = pos->second->number();	      std::string sys_name       = pos->first;	      	      comment =  "# Name, System No. ";	      std::sprintf(buf, "%d", sys_num);	      comment += buf;	  	      io.data (sys_name, comment.c_str());	    }	  	    // 4.)	    // Write the type of system handled	    {	      const unsigned int sys_num = pos->second->number();	      std::string sys_type       = pos->second->system_type();	      comment =  "# Type, System No. ";	      std::sprintf(buf, "%d", sys_num);	      comment += buf;	  	      io.data (sys_type, comment.c_str());	    }		    // 5.) - 9.)	    // Let System::write_header() do the job	    pos->second->write_header (io, write_additional_data);	    	    ++pos;	  }      }    // Start from the first system, again,    // to write vectors to disk, if wanted    if (write_data)      {	// open a parallel buffer if warranted.	Xdr local_io (write_parallel_files ? local_file_name(name) : "", mode);		for (pos = _systems.begin(); pos != _systems.end(); ++pos) 	  {	    // 10.) + 11.)	    if (write_parallel_files)	      pos->second->write_parallel_data (local_io,write_additional_data);	    else	      pos->second->write_serialized_data (io,write_additional_data);	  }      }	    STOP_LOG("write()","EquationSystems");  }   // the EquationSystems::write() method should look constant,  // but we need to undo the temporary numbering of the nodes  // and elements in the mesh, which requires that we abuse const_cast  if (dynamic_cast<ParallelMesh*>(const_cast<MeshBase*>(&_mesh)))    {      ParallelMesh *mesh = dynamic_cast<ParallelMesh*>(const_cast<MeshBase*>(&_mesh));          MeshTools::Private::fix_broken_node_and_element_numbering(*mesh);    }  else if (dynamic_cast<SerialMesh*>(const_cast<MeshBase*>(&_mesh)))    {      SerialMesh *mesh = dynamic_cast<SerialMesh*>(const_cast<MeshBase*>(&_mesh));          MeshTools::Private::fix_broken_node_and_element_numbering(*mesh);    }  else    {      std::cerr << "ERROR:  dynamic_cast<> to ParallelMesh and SerialMesh failed!"		<< std::endl;      libmesh_error();    }}

⌨️ 快捷键说明

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