diff --git a/FileIO/MPI_IO/NodePartitionedMeshReader.cpp b/FileIO/MPI_IO/NodePartitionedMeshReader.cpp index 5ceceabe0bb4f1f59d850341891ac239f56c628f..3ad2a604a94e5c81c711c799b32da4c142479bf2 100644 --- a/FileIO/MPI_IO/NodePartitionedMeshReader.cpp +++ b/FileIO/MPI_IO/NodePartitionedMeshReader.cpp @@ -10,18 +10,18 @@ See accompanying file LICENSE.txt or http://www.opengeosys.org/project/license -*/ + */ #include "NodePartitionedMeshReader.h" #include "logog/include/logog.hpp" -#include "BaseLib/RunTime.h" #include "BaseLib/FileTools.h" +#include "BaseLib/RunTime.h" #include "MeshLib/Elements/Element.h" -#include "MeshLib/Elements/Line.h" #include "MeshLib/Elements/Hex.h" +#include "MeshLib/Elements/Line.h" #include "MeshLib/Elements/Prism.h" #include "MeshLib/Elements/Pyramid.h" #include "MeshLib/Elements/Quad.h" @@ -34,7 +34,8 @@ bool is_safely_convertable(VALUE const& value) { bool const result = value <= std::numeric_limits<TYPE>::max(); - if (!result) { + if (!result) + { ERR("The value %d is too large for conversion.", value); ERR("Maximum available size is %d.", std::numeric_limits<TYPE>::max()); } @@ -43,7 +44,6 @@ is_safely_convertable(VALUE const& value) namespace FileIO { - NodePartitionedMeshReader::NodePartitionedMeshReader(MPI_Comm comm) : _mpi_comm(comm) { @@ -58,7 +58,6 @@ NodePartitionedMeshReader::~NodePartitionedMeshReader() MPI_Type_free(&_mpi_node_type); } - void NodePartitionedMeshReader::registerNodeDataMpiType() { int const count = 2; @@ -76,7 +75,7 @@ MeshLib::NodePartitionedMesh* NodePartitionedMeshReader::read( BaseLib::RunTime timer; timer.start(); - MeshLib::NodePartitionedMesh *mesh = nullptr; + MeshLib::NodePartitionedMesh* mesh = nullptr; // Always try binary file first std::string const fname_new = file_name_base + "_partitioned_msh_cfg" + @@ -105,7 +104,7 @@ MeshLib::NodePartitionedMesh* NodePartitionedMeshReader::read( template <typename DATA> bool NodePartitionedMeshReader::readBinaryDataFromFile(std::string const& filename, - MPI_Offset offset, MPI_Datatype type, DATA& data) const + MPI_Offset offset, MPI_Datatype type, DATA& data) const { // Check container size if (!is_safely_convertable<std::size_t, int>(data.size())) @@ -132,25 +131,24 @@ NodePartitionedMeshReader::readBinaryDataFromFile(std::string const& filename, MPI_File_set_view(file, offset, type, type, file_mode, MPI_INFO_NULL); // The static cast is checked above. MPI_File_read(file, data.data(), static_cast<int>(data.size()), type, - MPI_STATUS_IGNORE); + MPI_STATUS_IGNORE); MPI_File_close(&file); return true; } MeshLib::NodePartitionedMesh* NodePartitionedMeshReader::readBinary( - const std::string &file_name_base) + const std::string &file_name_base) { //---------------------------------------------------------------------------------- // Read headers - const std::string fname_header = file_name_base + "_partitioned_msh_"; const std::string fname_num_p_ext = std::to_string(_mpi_comm_size) + ".bin"; if (!readBinaryDataFromFile(fname_header + "cfg" + fname_num_p_ext, - static_cast<MPI_Offset>( - static_cast<unsigned>(_mpi_rank) * sizeof(_mesh_info)), - MPI_LONG, _mesh_info)) + static_cast<MPI_Offset>( + static_cast<unsigned>(_mpi_rank) * sizeof(_mesh_info)), + MPI_LONG, _mesh_info)) return nullptr; //---------------------------------------------------------------------------------- @@ -158,7 +156,7 @@ MeshLib::NodePartitionedMesh* NodePartitionedMeshReader::readBinary( std::vector<NodeData> nodes(_mesh_info.nodes); if (!readBinaryDataFromFile(fname_header + "nod" + fname_num_p_ext, - static_cast<MPI_Offset>(_mesh_info.offset[2]), _mpi_node_type, nodes)) + static_cast<MPI_Offset>(_mesh_info.offset[2]), _mpi_node_type, nodes)) return nullptr; std::vector<MeshLib::Node*> mesh_nodes; @@ -167,15 +165,14 @@ MeshLib::NodePartitionedMesh* NodePartitionedMeshReader::readBinary( //---------------------------------------------------------------------------------- // Read non-ghost elements - std::vector<unsigned long> elem_data( _mesh_info.regular_elements + _mesh_info.offset[0]); - if (!readBinaryDataFromFile(fname_header +"ele" + fname_num_p_ext, - static_cast<MPI_Offset>(_mesh_info.offset[3]), MPI_LONG, elem_data)) + if (!readBinaryDataFromFile(fname_header + "ele" + fname_num_p_ext, + static_cast<MPI_Offset>(_mesh_info.offset[3]), MPI_LONG, elem_data)) return nullptr; std::vector<MeshLib::Element*> mesh_elems( - _mesh_info.regular_elements + _mesh_info.ghost_elements); + _mesh_info.regular_elements + _mesh_info.ghost_elements); setElements(mesh_nodes, elem_data, mesh_elems); //---------------------------------------------------------------------------------- @@ -184,7 +181,7 @@ MeshLib::NodePartitionedMesh* NodePartitionedMeshReader::readBinary( _mesh_info.ghost_elements + _mesh_info.offset[1]); if (!readBinaryDataFromFile(fname_header + "ele_g" + fname_num_p_ext, - static_cast<MPI_Offset>(_mesh_info.offset[4]), MPI_LONG, ghost_elem_data)) + static_cast<MPI_Offset>(_mesh_info.offset[4]), MPI_LONG, ghost_elem_data)) return nullptr; const bool process_ghost = true; @@ -192,17 +189,17 @@ MeshLib::NodePartitionedMesh* NodePartitionedMeshReader::readBinary( //---------------------------------------------------------------------------------- return newMesh(BaseLib::extractBaseName(file_name_base), - mesh_nodes, glb_node_ids, mesh_elems); + mesh_nodes, glb_node_ids, mesh_elems); } bool NodePartitionedMeshReader::openASCIIFiles(std::string const& file_name_base, - std::ifstream& is_cfg, std::ifstream& is_node, std::ifstream& is_elem) const + std::ifstream& is_cfg, std::ifstream& is_node, std::ifstream& is_elem) const { const std::string fname_header = file_name_base + "_partitioned_"; const std::string fname_num_p_ext = std::to_string(_mpi_comm_size) + ".msh"; { // Configuration. - std::string const filename = fname_header + "cfg"+ fname_num_p_ext; + std::string const filename = fname_header + "cfg" + fname_num_p_ext; is_cfg.open(filename); if( !is_cfg.good() ) @@ -248,8 +245,8 @@ bool NodePartitionedMeshReader::openASCIIFiles(std::string const& file_name_base } bool NodePartitionedMeshReader::readCastNodesASCII(std::ifstream& is_node, - const int part_id, std::vector<MeshLib::Node*> &mesh_nodes, - std::vector<unsigned long> &glb_node_ids) const + const int part_id, std::vector<MeshLib::Node*> &mesh_nodes, + std::vector<unsigned long> &glb_node_ids) const { int const message_tag = 0; @@ -260,33 +257,26 @@ bool NodePartitionedMeshReader::readCastNodesASCII(std::ifstream& is_node, return false; } - //---------------------------------------------------------------------------------- - // Read Nodes std::vector<NodeData> nodes(_mesh_info.nodes); if(_mpi_rank == 0) { - for(unsigned long k=0; k < _mesh_info.nodes; k++) + for(unsigned long k = 0; k < _mesh_info.nodes; k++) { NodeData &node = nodes[k]; - is_node >> node.index - >> node.x >> node.y >> node.z >> std::ws; + is_node >> node.index >> node.x >> node.y >> node.z >> std::ws; } if(part_id == 0) - { setNodes(nodes, mesh_nodes, glb_node_ids); - } else - { MPI_Send(nodes.data(), static_cast<int>(_mesh_info.nodes), - _mpi_node_type, part_id, message_tag, _mpi_comm); - } + _mpi_node_type, part_id, message_tag, _mpi_comm); } else if(part_id > 0 && _mpi_rank == part_id) { MPI_Recv(nodes.data(), static_cast<int>(_mesh_info.nodes), - _mpi_node_type, 0, message_tag, _mpi_comm, MPI_STATUS_IGNORE); + _mpi_node_type, 0, message_tag, _mpi_comm, MPI_STATUS_IGNORE); setNodes(nodes, mesh_nodes, glb_node_ids); } @@ -294,9 +284,9 @@ bool NodePartitionedMeshReader::readCastNodesASCII(std::ifstream& is_node, } bool NodePartitionedMeshReader::readCastElemsASCII(std::ifstream& is_elem, - const int part_id, const std::size_t data_size, const bool process_ghost, - const std::vector<MeshLib::Node*> &mesh_nodes, - std::vector<MeshLib::Element*> &mesh_elems) const + const int part_id, const std::size_t data_size, const bool process_ghost, + const std::vector<MeshLib::Node*> &mesh_nodes, + std::vector<MeshLib::Element*> &mesh_elems) const { int const message_tag = 0; @@ -320,10 +310,8 @@ bool NodePartitionedMeshReader::readCastElemsASCII(std::ifstream& is_elem, setElements(mesh_nodes, elem_data, mesh_elems, process_ghost); } else - { MPI_Send(elem_data.data(), static_cast<int>(data_size), MPI_LONG, part_id, message_tag, _mpi_comm); - } } else if(part_id > 0 && _mpi_rank == part_id) { @@ -340,7 +328,7 @@ bool NodePartitionedMeshReader::readCastElemsASCII(std::ifstream& is_elem, } MeshLib::NodePartitionedMesh* NodePartitionedMeshReader::readASCII( - const std::string &file_name_base) + const std::string &file_name_base) { std::ifstream is_cfg; std::ifstream is_node; @@ -364,7 +352,7 @@ MeshLib::NodePartitionedMesh* NodePartitionedMeshReader::readASCII( if(!file_opened) return nullptr; - MeshLib::NodePartitionedMesh *np_mesh = nullptr; + MeshLib::NodePartitionedMesh* np_mesh = nullptr; std::vector<MeshLib::Node*> mesh_nodes; std::vector<unsigned long> glb_node_ids; std::vector<MeshLib::Element*> mesh_elems; @@ -407,10 +395,8 @@ MeshLib::NodePartitionedMesh* NodePartitionedMeshReader::readASCII( return nullptr; if(_mpi_rank == i) - { np_mesh = newMesh(BaseLib::extractBaseName(file_name_base), mesh_nodes, glb_node_ids, mesh_elems); - } } if(_mpi_rank == 0) @@ -422,7 +408,7 @@ MeshLib::NodePartitionedMesh* NodePartitionedMeshReader::readASCII( MPI_Barrier(_mpi_comm); - return np_mesh; + return np_mesh; } MeshLib::NodePartitionedMesh* @@ -444,13 +430,13 @@ NodePartitionedMeshReader::newMesh( } void NodePartitionedMeshReader::readElementASCII(std::ifstream &ins, - std::vector<unsigned long>& elem_data, const bool ghost) const + std::vector<unsigned long>& elem_data, const bool ghost) const { // Set number of elements. unsigned long const ne = ghost ? _mesh_info.ghost_elements : _mesh_info.regular_elements; unsigned long counter = ne; - for(unsigned long j=0; j<ne; j++) + for(unsigned long j = 0; j < ne; j++) { elem_data[j] = counter; ins >> elem_data[counter++]; //mat. idx @@ -463,8 +449,8 @@ void NodePartitionedMeshReader::readElementASCII(std::ifstream &ins, } void NodePartitionedMeshReader::setNodes(const std::vector<NodeData> &node_data, - std::vector<MeshLib::Node*> &mesh_node, - std::vector<unsigned long> &glb_node_ids) const + std::vector<MeshLib::Node*> &mesh_node, + std::vector<unsigned long> &glb_node_ids) const { mesh_node.resize(_mesh_info.nodes); glb_node_ids.resize(_mesh_info.nodes); @@ -478,9 +464,9 @@ void NodePartitionedMeshReader::setNodes(const std::vector<NodeData> &node_data, } void NodePartitionedMeshReader::setElements( - const std::vector<MeshLib::Node*> &mesh_nodes, - const std::vector<unsigned long> &elem_data, - std::vector<MeshLib::Element*> &mesh_elems, const bool ghost) const + const std::vector<MeshLib::Node*> &mesh_nodes, + const std::vector<unsigned long> &elem_data, + std::vector<MeshLib::Element*> &mesh_elems, const bool ghost) const { // Number of elements, ether ghost or regular unsigned long const ne = @@ -496,41 +482,40 @@ void NodePartitionedMeshReader::setElements( const unsigned long e_type = elem_data[counter++]; unsigned long const nnodes = elem_data[counter++]; - MeshLib::Node **elem_nodes = new MeshLib::Node*[nnodes]; - for(unsigned long k=0; k < nnodes; k++) + MeshLib::Node** elem_nodes = new MeshLib::Node*[nnodes]; + for(unsigned long k = 0; k < nnodes; k++) elem_nodes[k] = mesh_nodes[ elem_data[counter++] ]; - MeshLib::Element *elem = nullptr; + MeshLib::Element* elem = nullptr; // The element types below are defined by the mesh_partition tool // available at https://github.com/ufz/mesh_partition . switch(e_type) { - case 1: - elem = new MeshLib::Line(elem_nodes, mat_idx); - break; - case 2: - elem = new MeshLib::Quad(elem_nodes, mat_idx); - break; - case 3: - elem = new MeshLib::Hex(elem_nodes, mat_idx); - break; - case 4: - elem = new MeshLib::Tri(elem_nodes, mat_idx); - break; - case 5: - elem = new MeshLib::Tet(elem_nodes, mat_idx); - break; - case 6: - elem = new MeshLib::Prism(elem_nodes, mat_idx); - break; - case 7: - elem = new MeshLib::Pyramid(elem_nodes, mat_idx); - break; + case 1: + elem = new MeshLib::Line(elem_nodes, mat_idx); + break; + case 2: + elem = new MeshLib::Quad(elem_nodes, mat_idx); + break; + case 3: + elem = new MeshLib::Hex(elem_nodes, mat_idx); + break; + case 4: + elem = new MeshLib::Tri(elem_nodes, mat_idx); + break; + case 5: + elem = new MeshLib::Tet(elem_nodes, mat_idx); + break; + case 6: + elem = new MeshLib::Prism(elem_nodes, mat_idx); + break; + case 7: + elem = new MeshLib::Pyramid(elem_nodes, mat_idx); + break; } mesh_elems[i + id_offset] = elem; } } - } // namespace FileIO diff --git a/FileIO/MPI_IO/NodePartitionedMeshReader.h b/FileIO/MPI_IO/NodePartitionedMeshReader.h index ad7c26ceb5ad1b98fb2dc12bbed4cb6199f7a9b8..b52544ebeca91d2ef93a8fc739ab21e4c5461daa 100644 --- a/FileIO/MPI_IO/NodePartitionedMeshReader.h +++ b/FileIO/MPI_IO/NodePartitionedMeshReader.h @@ -9,7 +9,7 @@ Distributed under a Modified BSD License. See accompanying file LICENSE.txt or http://www.opengeosys.org/project/license -*/ + */ #ifndef NODE_PARTITIONED_MESH_READER_H #define NODE_PARTITIONED_MESH_READER_H @@ -34,221 +34,219 @@ namespace FileIO /// NodePartitionedMesh via MPI. class NodePartitionedMeshReader { - public: - /// \param comm MPI communicator. - NodePartitionedMeshReader(MPI_Comm comm); - - ~NodePartitionedMeshReader(); - - /*! - \brief Create a NodePartitionedMesh object, read data to it, - and return a pointer to it. Data files are either in - ASCII format or binary format. - \param file_name_base Name of file to be read, and it must be base name without name extension. - \return Pointer to Mesh object. If the creation of mesh object - fails, return a null pointer. - */ - MeshLib::NodePartitionedMesh* read(const std::string &file_name_base); - - private: - /// Pointer to MPI commumicator; - MPI_Comm _mpi_comm = MPI_COMM_WORLD; - - /// Number of processes in the communicator: _mpi_comm - int _mpi_comm_size; - - /// Rank of compute core - int _mpi_rank; - - /// MPI data type for struct NodeData. - MPI_Datatype _mpi_node_type; - - /// Node data only for parallel reading. - struct NodeData - { - std::size_t index; ///< Global node index. - double x; - double y; - double z; - }; - - /// Define MPI data type for NodeData struct. - void registerNodeDataMpiType(); - - /// A collection of integers that congfigure the partitioned mesh data. - struct PartitionedMeshInfo - { - unsigned long nodes; ///< 0: Number of all nodes of a partition, - unsigned long base_nodes; ///< 1: Number of nodes for linear elements of a parition, - unsigned long regular_elements; ///< 2: Number of non-ghost elements of a partition, - unsigned long ghost_elements; ///< 3: Number of ghost element of a partition, - unsigned long active_base_nodes; ///< 4: Number of active nodes for linear element of a parition, - unsigned long active_nodes; ///< 5: Number of all active nodes a parition, - unsigned long global_base_nodes; ///< 6: Number of nodes for linear element of global mesh, - unsigned long global_nodes; ///< 7: Number of all nodes of global mesh, - unsigned long offset[5]; ///< 8~12: Offsets of positions of partitions in the data arrays +public: + /// \param comm MPI communicator. + NodePartitionedMeshReader(MPI_Comm comm); + + ~NodePartitionedMeshReader(); + + /*! + \brief Create a NodePartitionedMesh object, read data to it, + and return a pointer to it. Data files are either in + ASCII format or binary format. + \param file_name_base Name of file to be read, and it must be base name without name extension. + \return Pointer to Mesh object. If the creation of mesh object + fails, return a null pointer. + */ + MeshLib::NodePartitionedMesh* read(const std::string &file_name_base); + +private: + /// Pointer to MPI commumicator; + MPI_Comm _mpi_comm = MPI_COMM_WORLD; + + /// Number of processes in the communicator: _mpi_comm + int _mpi_comm_size; + + /// Rank of compute core + int _mpi_rank; + + /// MPI data type for struct NodeData. + MPI_Datatype _mpi_node_type; + + /// Node data only for parallel reading. + struct NodeData + { + std::size_t index; ///< Global node index. + double x; + double y; + double z; + }; + + /// Define MPI data type for NodeData struct. + void registerNodeDataMpiType(); + + /// A collection of integers that congfigure the partitioned mesh data. + struct PartitionedMeshInfo + { + unsigned long nodes; ///< 0: Number of all nodes of a partition, + unsigned long base_nodes; ///< 1: Number of nodes for linear elements of a parition, + unsigned long regular_elements; ///< 2: Number of non-ghost elements of a partition, + unsigned long ghost_elements; ///< 3: Number of ghost element of a partition, + unsigned long active_base_nodes; ///< 4: Number of active nodes for linear element of a parition, + unsigned long active_nodes; ///< 5: Number of all active nodes a parition, + unsigned long global_base_nodes; ///< 6: Number of nodes for linear element of global mesh, + unsigned long global_nodes; ///< 7: Number of all nodes of global mesh, + unsigned long offset[5]; ///< 8~12: Offsets of positions of partitions in the data arrays /// (only 8 and 9 are used for ascii input) - unsigned long extra_flag; ///< 13: Reserved for extra flag. - - std::size_t size() const { return 14; } - unsigned long* data() { return &nodes; } - } _mesh_info; - - /*! - \brief Create a new mesh of NodePartitionedMesh after reading and processing the data - \param mesh_name Name assigned to the new mesh. - \param mesh_nodes Node data. - \param glb_node_ids Global IDs of nodes. - \param mesh_elems Element data. - \return True on success and false otherwise. - */ - MeshLib::NodePartitionedMesh* newMesh(std::string const& mesh_name, - std::vector<MeshLib::Node*> const& mesh_nodes, - std::vector<unsigned long> const& glb_node_ids, - std::vector<MeshLib::Element*> const& mesh_elems) const; - - /*! - \brief Parallel reading of a binary file via MPI_File_read, and it is called by readBinary - to read files of mesh data head, nodes, non-ghost elements and ghost elements, respectively. - \note In case of failure during opening of the file, an - error message is printed. - \note If the number of elements in container is larger than - MPI_file_read() supports (maximum of current \c int type), an - error is printed. - \param filename File name containing data. - \param offset Displacement of the data accessible from the view. - see MPI_File_set_view() documentation. - \param type Type of data. - \param data A container to be filled with data. Its size is used - to determine how many values should be read. - \tparam DATA A homogeneous contaner type supporting data() and size(). - \return True on success and false otherwise. - */ - template <typename DATA> - bool readBinaryDataFromFile(std::string const& filename, MPI_Offset offset, - MPI_Datatype type, DATA& data) const; - - /*! - \brief Create a NodePartitionedMesh object, read binary mesh data - in the manner of parallel, and return a pointer to it. - Four binary files have to been read in this function named as: - file_name_base+_partitioned_msh_cfg[number of partitions].bin - file_name_base+_partitioned_msh_nod[number of partitions].bin - file_name_base+_partitioned_msh_ele[number of partitions].bin - file_name_base+_partitioned_msh_ele_g[number of partitions].bin - in which, the first file contains an array of integers for the - PartitionMeshInfo for all partitions - - the second file contains a struct type (long, double double double) array of - nodes information of global IDs and coordinates of all partitions. - - the third file contains a long type integer array of element information of - material ID, element type and node IDs of each non-ghost element of all partitoions. - - the forth file contains a long type integer array of element information of - material ID, element type and node IDs of each ghost element of all partitoions. - \param file_name_base Name of file to be read, which must be a name with the + unsigned long extra_flag; ///< 13: Reserved for extra flag. + + std::size_t size() const { return 14; } + unsigned long* data() { return &nodes; } + } _mesh_info; + + /*! + \brief Create a new mesh of NodePartitionedMesh after reading and processing the data + \param mesh_name Name assigned to the new mesh. + \param mesh_nodes Node data. + \param glb_node_ids Global IDs of nodes. + \param mesh_elems Element data. + \return True on success and false otherwise. + */ + MeshLib::NodePartitionedMesh* newMesh(std::string const& mesh_name, + std::vector<MeshLib::Node*> const& mesh_nodes, + std::vector<unsigned long> const& glb_node_ids, + std::vector<MeshLib::Element*> const& mesh_elems) const; + + /*! + \brief Parallel reading of a binary file via MPI_File_read, and it is called by readBinary + to read files of mesh data head, nodes, non-ghost elements and ghost elements, respectively. + \note In case of failure during opening of the file, an + error message is printed. + \note If the number of elements in container is larger than + MPI_file_read() supports (maximum of current \c int type), an + error is printed. + \param filename File name containing data. + \param offset Displacement of the data accessible from the view. + see MPI_File_set_view() documentation. + \param type Type of data. + \param data A container to be filled with data. Its size is used + to determine how many values should be read. + \tparam DATA A homogeneous contaner type supporting data() and size(). + \return True on success and false otherwise. + */ + template <typename DATA> + bool readBinaryDataFromFile(std::string const& filename, MPI_Offset offset, + MPI_Datatype type, DATA& data) const; + + /*! + \brief Create a NodePartitionedMesh object, read binary mesh data + in the manner of parallel, and return a pointer to it. + Four binary files have to been read in this function named as: + file_name_base+_partitioned_msh_cfg[number of partitions].bin + file_name_base+_partitioned_msh_nod[number of partitions].bin + file_name_base+_partitioned_msh_ele[number of partitions].bin + file_name_base+_partitioned_msh_ele_g[number of partitions].bin + in which, the first file contains an array of integers for the + PartitionMeshInfo for all partitions + + the second file contains a struct type (long, double double double) array of + nodes information of global IDs and coordinates of all partitions. + + the third file contains a long type integer array of element information of + material ID, element type and node IDs of each non-ghost element of all partitoions. + + the forth file contains a long type integer array of element information of + material ID, element type and node IDs of each ghost element of all partitoions. + \param file_name_base Name of file to be read, which must be a name with the + path to the file and without file extension. + \return Pointer to Mesh object. + */ + MeshLib::NodePartitionedMesh* readBinary(const std::string &file_name_base); + + /*! + \brief Open ASCII files of node partitioned mesh data. + + \param file_name_base Name of file to be read, which must be a name with the path to the file and without file extension. - \return Pointer to Mesh object. - */ - MeshLib::NodePartitionedMesh* readBinary(const std::string &file_name_base); - - /*! - \brief Open ASCII files of node partitioned mesh data. - - \param file_name_base Name of file to be read, which must be a name with the - path to the file and without file extension. - \param is_cfg Input stream for the file contains configuration data. - \param is_node Input stream for the file contains node data. - \param is_elem Input stream for the file contains element data. - \return Return true if all files are good. - */ - bool openASCIIFiles(std::string const& file_name_base,std::ifstream& is_cfg, - std::ifstream& is_node, std::ifstream& is_elem) const; - - /*! - \brief Read mesh nodes from an ASCII file and cast to the corresponding rank. - - \param is_node Input stream for the file contains node data. - \param part_id Partition ID. - \param mesh_nodes Node vector to be filled. - \param glb_node_ids Global Node IDs to be filled. - */ - bool readCastNodesASCII(std::ifstream& is_node, const int part_id, - std::vector<MeshLib::Node*> &mesh_nodes, - std::vector<unsigned long> &glb_node_ids) const; - - /*! - \brief Read mesh elements from an ASCII file and cast to the corresponding rank. - - \param is_elem Input stream for the file contains element data. - \param part_id Partition ID. - \param data_size Total size of the data to be read. This type is an - int because of MPI_Send() implicit cast. - \param process_ghost Flag to process ghost element. - \param mesh_nodes Node vector to be filled. - \param mesh_elems Element vector to be filled. - */ - bool readCastElemsASCII(std::ifstream& is_elem, const int part_id, - const std::size_t data_size, const bool process_ghost, - const std::vector<MeshLib::Node*> &mesh_nodes, - std::vector<MeshLib::Element*> &mesh_elems) const; - - /*! - \brief Create a NodePartitionedMesh object, read ASCII mesh data, - and return a pointer to it. - Three ASCII files have to been read in this function named as: - file_name_base+_partitioned_cfg[number of partitions].msh - file_name_base+_partitioned_nodes[number of partitions].msh - file_name_base+_partitioned_elems[number of partitions].msh - in which, the first file contains an array of integers for the - PartitionMeshInfo for all partitions - - the second file contains nodes information of global IDs and coordinates - of all partitions. - - the third file contains element information of material ID, element type - and node IDs of each element of all partitoions. - \param file_name_base Name of file to be read, which must be a name with the - path to the file and without file extension. - \return Pointer to Mesh object. - */ - MeshLib::NodePartitionedMesh* readASCII(const std::string &file_name_base); - - /*! - \brief Read elements data from ASCII file. - \param ins Input stream. - \param elem_data Pointer to array that contains element data, which to be filled. - \param ghost Flag to read ghost elements. - */ - void readElementASCII(std::ifstream &ins, - std::vector<unsigned long>& elem_data, - const bool ghost = false) const; - - /*! - \brief Set mesh nodes from a tempory array containing node data read from file. - \param node_data Array containing node data read from file. - \param mesh_node Vector of mesh nodes to be set. - \param glb_node_ids Global IDs of nodes of a partition. - */ - void setNodes(const std::vector<NodeData> &node_data, - std::vector<MeshLib::Node*> &mesh_node, - std::vector<unsigned long> &glb_node_ids) const; - - /*! - \brief Set mesh elements from a tempory array containing node data read from file. - \param mesh_nodes Vector of mesh nodes used to set element nodes. - \param elem_data Array containing element data read from file. - \param mesh_elems Vector of mesh elements to be set. - \param ghost Flag of processing ghost elements. - */ - void setElements(const std::vector<MeshLib::Node*> &mesh_nodes, - const std::vector<unsigned long> &elem_data, - std::vector<MeshLib::Element*> &mesh_elems, - const bool ghost = false) const; - + \param is_cfg Input stream for the file contains configuration data. + \param is_node Input stream for the file contains node data. + \param is_elem Input stream for the file contains element data. + \return Return true if all files are good. + */ + bool openASCIIFiles(std::string const& file_name_base,std::ifstream& is_cfg, + std::ifstream& is_node, std::ifstream& is_elem) const; + + /*! + \brief Read mesh nodes from an ASCII file and cast to the corresponding rank. + + \param is_node Input stream for the file contains node data. + \param part_id Partition ID. + \param mesh_nodes Node vector to be filled. + \param glb_node_ids Global Node IDs to be filled. + */ + bool readCastNodesASCII(std::ifstream& is_node, const int part_id, + std::vector<MeshLib::Node*> &mesh_nodes, + std::vector<unsigned long> &glb_node_ids) const; + + /*! + \brief Read mesh elements from an ASCII file and cast to the corresponding rank. + + \param is_elem Input stream for the file contains element data. + \param part_id Partition ID. + \param data_size Total size of the data to be read. This type is an + int because of MPI_Send() implicit cast. + \param process_ghost Flag to process ghost element. + \param mesh_nodes Node vector to be filled. + \param mesh_elems Element vector to be filled. + */ + bool readCastElemsASCII(std::ifstream& is_elem, const int part_id, + const std::size_t data_size, const bool process_ghost, + const std::vector<MeshLib::Node*> &mesh_nodes, + std::vector<MeshLib::Element*> &mesh_elems) const; + + /*! + \brief Create a NodePartitionedMesh object, read ASCII mesh data, + and return a pointer to it. + Three ASCII files have to been read in this function named as: + file_name_base+_partitioned_cfg[number of partitions].msh + file_name_base+_partitioned_nodes[number of partitions].msh + file_name_base+_partitioned_elems[number of partitions].msh + in which, the first file contains an array of integers for the + PartitionMeshInfo for all partitions + + the second file contains nodes information of global IDs and coordinates + of all partitions. + + the third file contains element information of material ID, element type + and node IDs of each element of all partitoions. + \param file_name_base Name of file to be read, which must be a name with the + path to the file and without file extension. + \return Pointer to Mesh object. + */ + MeshLib::NodePartitionedMesh* readASCII(const std::string &file_name_base); + + /*! + \brief Read elements data from ASCII file. + \param ins Input stream. + \param elem_data Pointer to array that contains element data, which to be filled. + \param ghost Flag to read ghost elements. + */ + void readElementASCII(std::ifstream &ins, + std::vector<unsigned long>& elem_data, + const bool ghost = false) const; + + /*! + \brief Set mesh nodes from a tempory array containing node data read from file. + \param node_data Array containing node data read from file. + \param mesh_node Vector of mesh nodes to be set. + \param glb_node_ids Global IDs of nodes of a partition. + */ + void setNodes(const std::vector<NodeData> &node_data, + std::vector<MeshLib::Node*> &mesh_node, + std::vector<unsigned long> &glb_node_ids) const; + + /*! + \brief Set mesh elements from a tempory array containing node data read from file. + \param mesh_nodes Vector of mesh nodes used to set element nodes. + \param elem_data Array containing element data read from file. + \param mesh_elems Vector of mesh elements to be set. + \param ghost Flag of processing ghost elements. + */ + void setElements(const std::vector<MeshLib::Node*> &mesh_nodes, + const std::vector<unsigned long> &elem_data, + std::vector<MeshLib::Element*> &mesh_elems, + const bool ghost = false) const; }; - } // FileIO #endif // READ_NODE_PARTITIONED_MESH_H