libMesh
|
Reading and writing meshes in the Gmsh format. More...
#include <gmsh_io.h>
Classes | |
struct | ElementDefinition |
Defines mapping from libMesh element types to Gmsh element types or vice-versa. More... | |
struct | ElementMaps |
struct which holds a map from Gmsh to libMesh element numberings and vice-versa. More... | |
Public Member Functions | |
GmshIO (MeshBase &mesh) | |
Constructor. More... | |
GmshIO (const MeshBase &mesh) | |
Constructor. More... | |
virtual void | read (const std::string &name) override |
Reads in a mesh in the Gmsh *.msh format from the ASCII file given by name. More... | |
virtual void | write (const std::string &name) override |
This method implements writing a mesh to a specified file in the Gmsh *.msh format. More... | |
virtual void | write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override |
This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided. More... | |
bool & | binary () |
Flag indicating whether or not to write a binary file. More... | |
bool & | write_lower_dimensional_elements () |
Access to the flag which controls whether boundary elements are written to the Mesh file. More... | |
bool | is_parallel_format () const |
Returns true iff this mesh file format and input class are parallelized, so that all processors can read their share of the data at once. More... | |
virtual void | write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr) |
This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object. More... | |
virtual void | write_discontinuous_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr) |
This method implements writing a mesh with discontinuous data to a specified file where the data is taken from the EquationSystems object. More... | |
virtual void | write_nodal_data (const std::string &, const NumericVector< Number > &, const std::vector< std::string > &) |
This method may be overridden by "parallel" output formats for writing nodal data. More... | |
virtual void | write_nodal_data (const std::string &, const EquationSystems &, const std::set< std::string > *) |
This method should be overridden by "parallel" output formats for writing nodal data. More... | |
virtual void | write_nodal_data_discontinuous (const std::string &, const std::vector< Number > &, const std::vector< std::string > &) |
This method implements writing a mesh with discontinuous data to a specified file where the nodal data and variables names are provided. More... | |
unsigned int & | ascii_precision () |
Return/set the precision to use when writing ASCII files. More... | |
Protected Member Functions | |
MeshBase & | mesh () |
void | set_n_partitions (unsigned int n_parts) |
Sets the number of partitions in the mesh. More... | |
void | skip_comment_lines (std::istream &in, const char comment_start) |
Reads input from in , skipping all the lines that start with the character comment_start . More... | |
const MeshBase & | mesh () const |
virtual bool | get_add_sides () |
Protected Attributes | |
std::vector< bool > | elems_of_dimension |
A vector of bools describing what dimension elements have been encountered when reading a mesh. More... | |
const bool | _is_parallel_format |
Flag specifying whether this format is parallel-capable. More... | |
const bool | _serial_only_needed_on_proc_0 |
Flag specifying whether this format can be written by only serializing the mesh to processor zero. More... | |
Private Member Functions | |
void | read_mesh (std::istream &in) |
Implementation of the read() function. More... | |
void | write_mesh (std::ostream &out) |
This method implements writing a mesh to a specified file. More... | |
void | write_post (const std::string &, const std::vector< Number > *=nullptr, const std::vector< std::string > *=nullptr) |
This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are optionally provided. More... | |
Static Private Member Functions | |
static ElementMaps | build_element_maps () |
A static function used to construct the _element_maps struct, statically. More... | |
Private Attributes | |
bool | _binary |
Flag to write binary data. More... | |
bool | _write_lower_dimensional_elements |
If true, lower-dimensional elements based on the boundary conditions get written to the output file. More... | |
Static Private Attributes | |
static ElementMaps | _element_maps = GmshIO::build_element_maps() |
A static ElementMaps object that is built statically and used by all instances of this class. More... | |
Reading and writing meshes in the Gmsh format.
For a full description of the Gmsh format and to obtain the GMSH software see the Gmsh home page
|
explicit |
Constructor.
Takes a non-const Mesh reference which it will fill up with elements via the read() command.
Definition at line 124 of file gmsh_io.C.
|
explicit |
Constructor.
Takes a reference to a constant mesh object. This constructor will only allow us to write the mesh.
Definition at line 115 of file gmsh_io.C.
|
inlineinherited |
Return/set the precision to use when writing ASCII files.
By default we use numeric_limits<Real>::max_digits10, which should be enough to write out to ASCII and get the exact same Real back when reading in.
Definition at line 269 of file mesh_output.h.
Referenced by libMesh::UNVIO::nodes_out(), libMesh::FroIO::write(), libMesh::MEDITIO::write_ascii(), libMesh::TecplotIO::write_ascii(), libMesh::GMVIO::write_ascii_new_impl(), and libMesh::GMVIO::write_ascii_old_impl().
bool & libMesh::GmshIO::binary | ( | ) |
Flag indicating whether or not to write a binary file.
While binary files may end up being smaller than equivalent ASCII files, they will almost certainly take longer to write. The reason for this is that the ostream::write() function which is used to write "binary" data to streams, only takes a pointer to char as its first argument. This means if you want to write anything other than a buffer of chars, you first have to use a strange memcpy hack to get the data into the desired format. See the templated to_binary_stream() function below.
Definition at line 134 of file gmsh_io.C.
References _binary.
Referenced by write_post().
|
staticprivate |
A static function used to construct the _element_maps struct, statically.
Definition at line 46 of file gmsh_io.C.
References libMesh::GmshIO::ElementMaps::add_def(), libMesh::EDGE2, libMesh::EDGE3, libMesh::HEX20, libMesh::HEX27, libMesh::HEX8, libMesh::GmshIO::ElementMaps::in, libMesh::GmshIO::ElementDefinition::nnodes, libMesh::NODEELEM, libMesh::GmshIO::ElementDefinition::nodes, libMesh::PRISM15, libMesh::PRISM18, libMesh::PRISM6, libMesh::PYRAMID5, libMesh::QUAD4, libMesh::QUAD8, libMesh::QUAD9, libMesh::TET10, libMesh::TET4, libMesh::TRI3, and libMesh::TRI6.
|
inlineprotectedvirtualinherited |
Reimplemented in libMesh::ExodusII_IO.
Definition at line 176 of file mesh_output.h.
|
inlineinherited |
Returns true iff this mesh file format and input class are parallelized, so that all processors can read their share of the data at once.
Definition at line 87 of file mesh_input.h.
References libMesh::MeshInput< MT >::_is_parallel_format.
|
inlineprotectedinherited |
Definition at line 178 of file mesh_input.h.
Referenced by libMesh::GMVIO::_read_one_cell(), libMesh::VTKIO::cells_to_vtk(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::Nemesis_IO::copy_elemental_solution(), libMesh::ExodusII_IO::copy_nodal_solution(), libMesh::TetGenIO::element_in(), libMesh::UNVIO::elements_in(), libMesh::UNVIO::elements_out(), libMesh::VTKIO::get_local_node_values(), libMesh::ExodusII_IO::get_sideset_data_indices(), libMesh::UNVIO::groups_in(), libMesh::TetGenIO::node_in(), libMesh::UNVIO::nodes_in(), libMesh::UNVIO::nodes_out(), libMesh::VTKIO::nodes_to_vtk(), libMesh::Nemesis_IO::prepare_to_write_nodal_data(), libMesh::GMVIO::read(), libMesh::Nemesis_IO::read(), libMesh::ExodusII_IO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read(), libMesh::VTKIO::read(), libMesh::CheckpointIO::read_bcs(), libMesh::CheckpointIO::read_connectivity(), libMesh::ExodusII_IO::read_header(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::UCDIO::read_implementation(), libMesh::UNVIO::read_implementation(), read_mesh(), libMesh::DynaIO::read_mesh(), libMesh::CheckpointIO::read_nodes(), libMesh::CheckpointIO::read_nodesets(), libMesh::CheckpointIO::read_remote_elem(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::ExodusII_IO::read_sideset_data(), libMesh::OFFIO::read_stream(), libMesh::MatlabIO::read_stream(), libMesh::CheckpointIO::read_subdomain_names(), libMesh::TetGenIO::write(), libMesh::Nemesis_IO::write(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), libMesh::ExodusII_IO::write(), libMesh::GMVIO::write_ascii_new_impl(), libMesh::GMVIO::write_ascii_old_impl(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::Nemesis_IO::write_element_data(), libMesh::ExodusII_IO::write_element_data(), libMesh::ExodusII_IO::write_elemsets(), libMesh::UCDIO::write_header(), libMesh::UCDIO::write_implementation(), libMesh::UCDIO::write_interior_elems(), write_mesh(), libMesh::UCDIO::write_nodal_data(), libMesh::VTKIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_common(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::UCDIO::write_nodes(), libMesh::CheckpointIO::write_nodesets(), libMesh::XdrIO::write_parallel(), write_post(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::ExodusII_IO::write_sideset_data(), libMesh::UCDIO::write_soln(), and libMesh::CheckpointIO::write_subdomain_names().
|
inlineprotectedinherited |
Definition at line 259 of file mesh_output.h.
References libMesh::libmesh_assert().
Referenced by libMesh::FroIO::write(), libMesh::TecplotIO::write(), libMesh::MEDITIO::write(), libMesh::PostscriptIO::write(), libMesh::EnsightIO::write(), libMesh::TecplotIO::write_ascii(), libMesh::TecplotIO::write_binary(), libMesh::TecplotIO::write_nodal_data(), libMesh::MEDITIO::write_nodal_data(), and libMesh::GnuPlotIO::write_solution().
|
overridevirtual |
Reads in a mesh in the Gmsh *.msh format from the ASCII file given by name.
The physical group names defined in the Gmsh-file are stored, depending on the element dimension, as either subdomain name or as side name. The IDs of the former can be retrieved by using the MeshBase::get_id_by_name method; the IDs of the latter can be retrieved by using the MeshBase::get_boundary_info and the BoundaryInfo::get_id_by_name methods.
Implements libMesh::MeshInput< MeshBase >.
Definition at line 148 of file gmsh_io.C.
References libMesh::Quality::name(), and read_mesh().
Referenced by libMesh::NameBasedIO::read().
|
private |
Implementation of the read() function.
This function is called by the public interface function and implements reading the file.
Definition at line 156 of file gmsh_io.C.
References _element_maps, libMesh::MeshBase::add_elem(), libMesh::BoundaryInfo::add_node(), libMesh::MeshBase::add_point(), libMesh::BoundaryInfo::add_side(), libMesh::as_range(), libMesh::Elem::build_with_id(), libMesh::MeshBase::clear(), libMesh::MeshBase::delete_elem(), libMesh::GmshIO::ElementDefinition::dim, libMesh::err, libMesh::MeshBase::get_boundary_info(), libMesh::GmshIO::ElementMaps::in, libMesh::index_range(), libMesh::is, libMesh::libmesh_assert(), libMesh::MeshInput< MT >::mesh(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::Elem::n_nodes(), libMesh::GmshIO::ElementDefinition::nnodes, libMesh::MeshBase::node_ptr(), libMesh::GmshIO::ElementDefinition::nodes, libMesh::BoundaryInfo::nodeset_name(), libMesh::Real, libMesh::MeshBase::reserve_elem(), libMesh::MeshBase::reserve_nodes(), libMesh::MeshBase::set_mesh_dimension(), libMesh::Elem::set_node(), libMesh::BoundaryInfo::sideset_name(), libMesh::Elem::subdomain_id(), libMesh::MeshBase::subdomain_name(), and libMesh::GmshIO::ElementDefinition::type.
Referenced by read().
|
inlineprotectedinherited |
Sets the number of partitions in the mesh.
Typically this gets done by the partitioner, but some parallel file formats begin "pre-partitioned".
Definition at line 101 of file mesh_input.h.
References libMesh::MeshInput< MT >::mesh().
Referenced by libMesh::Nemesis_IO::read(), and libMesh::XdrIO::read_header().
|
protectedinherited |
Reads input from in
, skipping all the lines that start with the character comment_start
.
Definition at line 187 of file mesh_input.h.
Referenced by libMesh::TetGenIO::read(), and libMesh::UCDIO::read_implementation().
|
overridevirtual |
This method implements writing a mesh to a specified file in the Gmsh *.msh format.
Implements libMesh::MeshOutput< MeshBase >.
Definition at line 835 of file gmsh_io.C.
References libMesh::Quality::name(), and write_mesh().
Referenced by libMesh::NameBasedIO::write().
|
virtualinherited |
This method implements writing a mesh with discontinuous data to a specified file where the data is taken from the EquationSystems
object.
Definition at line 89 of file mesh_output.C.
References libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::EquationSystems::build_variable_names(), libMesh::EquationSystems::get_mesh(), libMesh::libmesh_assert(), and libMesh::out.
Referenced by libMesh::ExodusII_IO::write_timestep_discontinuous().
|
virtualinherited |
This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems
object.
Reimplemented in libMesh::NameBasedIO.
Definition at line 31 of file mesh_output.C.
References libMesh::EquationSystems::build_solution_vector(), libMesh::EquationSystems::build_variable_names(), libMesh::EquationSystems::get_mesh(), libMesh::libmesh_assert(), and libMesh::out.
Referenced by libMesh::Nemesis_IO::write_timestep(), and libMesh::ExodusII_IO::write_timestep().
bool & libMesh::GmshIO::write_lower_dimensional_elements | ( | ) |
Access to the flag which controls whether boundary elements are written to the Mesh file.
Definition at line 141 of file gmsh_io.C.
References _write_lower_dimensional_elements.
Referenced by write_mesh().
|
private |
This method implements writing a mesh to a specified file.
This will write an ASCII *.msh file.
Definition at line 864 of file gmsh_io.C.
References _element_maps, libMesh::BoundaryInfo::build_side_list(), libMesh::Elem::build_side_ptr(), libMesh::MeshBase::elem_ref(), libMesh::MeshBase::get_boundary_info(), libMesh::GmshIO::ElementDefinition::gmsh_type, libMesh::DofObject::id(), libMesh::libmesh_assert(), libMesh::make_range(), libMesh::MeshBase::max_elem_id(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshOutput< MT >::mesh(), libMesh::MeshBase::n_active_elem(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::MeshBase::n_nodes(), libMesh::MeshBase::node_ref(), libMesh::GmshIO::ElementDefinition::nodes, libMesh::GmshIO::ElementMaps::out, libMesh::DofObject::processor_id(), libMesh::Real, and write_lower_dimensional_elements().
Referenced by write().
|
overridevirtual |
This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided.
Reimplemented from libMesh::MeshOutput< MeshBase >.
Definition at line 852 of file gmsh_io.C.
References write_post().
Referenced by libMesh::NameBasedIO::write_nodal_data().
|
virtualinherited |
This method may be overridden by "parallel" output formats for writing nodal data.
Instead of getting a localized copy of the nodal solution vector, it is passed a NumericVector of type=PARALLEL which is in node-major order i.e. (u0,v0,w0, u1,v1,w1, u2,v2,w2, u3,v3,w3, ...) and contains n_nodes*n_vars total entries. Then, it is up to the individual I/O class to extract the required solution values from this vector and write them in parallel.
If not implemented, localizes the parallel vector into a std::vector and calls the other version of this function.
Reimplemented in libMesh::Nemesis_IO.
Definition at line 149 of file mesh_output.C.
References libMesh::NumericVector< T >::localize().
|
virtualinherited |
This method should be overridden by "parallel" output formats for writing nodal data.
Instead of getting a localized copy of the nodal solution vector, it directly uses EquationSystems current_local_solution vectors to look up nodal values.
If not implemented, reorders the solutions into a nodal-only NumericVector and calls the above version of this function.
Reimplemented in libMesh::Nemesis_IO.
Definition at line 162 of file mesh_output.C.
References libMesh::EquationSystems::build_parallel_solution_vector(), and libMesh::EquationSystems::build_variable_names().
|
inlinevirtualinherited |
This method implements writing a mesh with discontinuous data to a specified file where the nodal data and variables names are provided.
Reimplemented in libMesh::ExodusII_IO.
Definition at line 118 of file mesh_output.h.
|
private |
This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are optionally provided.
This will write an ASCII or binary *.pos file, depending on the binary flag.
Definition at line 1010 of file gmsh_io.C.
References binary(), libMesh::EDGE2, libMesh::EDGE3, libMesh::EDGE4, libMesh::Utility::enum_to_string(), libMesh::err, libMesh::HEX20, libMesh::HEX27, libMesh::HEX8, libMesh::libmesh_real(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshOutput< MT >::mesh(), libMesh::MeshBase::n_nodes(), n_vars, libMesh::out, libMesh::PRISM15, libMesh::PRISM18, libMesh::PRISM6, libMesh::PYRAMID5, libMesh::QUAD4, libMesh::QUAD8, libMesh::QUAD9, libMesh::TET10, libMesh::TET4, libMesh::TRI3, and libMesh::TRI6.
Referenced by write_nodal_data().
|
private |
|
staticprivate |
A static ElementMaps object that is built statically and used by all instances of this class.
Definition at line 200 of file gmsh_io.h.
Referenced by read_mesh(), and write_mesh().
|
protectedinherited |
Flag specifying whether this format is parallel-capable.
If this is false (default) I/O is only permitted when the mesh has been serialized.
Definition at line 184 of file mesh_output.h.
Referenced by libMesh::FroIO::write(), libMesh::PostscriptIO::write(), and libMesh::EnsightIO::write().
|
protectedinherited |
Flag specifying whether this format can be written by only serializing the mesh to processor zero.
If this is false (default) the mesh will be serialized to all processors
Definition at line 193 of file mesh_output.h.
|
private |
If true, lower-dimensional elements based on the boundary conditions get written to the output file.
Definition at line 155 of file gmsh_io.h.
Referenced by write_lower_dimensional_elements().
|
protectedinherited |
A vector of bools describing what dimension elements have been encountered when reading a mesh.
Definition at line 107 of file mesh_input.h.
Referenced by libMesh::GMVIO::_read_one_cell(), libMesh::UNVIO::elements_in(), libMesh::UNVIO::max_elem_dimension_seen(), libMesh::AbaqusIO::max_elem_dimension_seen(), libMesh::AbaqusIO::read(), libMesh::GMVIO::read(), libMesh::Nemesis_IO::read(), libMesh::ExodusII_IO::read(), libMesh::VTKIO::read(), libMesh::AbaqusIO::read_elements(), libMesh::UCDIO::read_implementation(), libMesh::UNVIO::read_implementation(), and libMesh::XdrIO::read_serialized_connectivity().