libMesh
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
libMesh::OFFIO Class Reference

This class is responsible for reading an unstructured, triangulated surface in the standard OFF OOGL format. More...

#include <off_io.h>

Inheritance diagram for libMesh::OFFIO:
[legend]

Public Member Functions

 OFFIO (MeshBase &)
 Constructor.
 
virtual void read (const std::string &name) override
 Reads in an OFF OOGL data file based on the string you pass it.
 
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.
 

Protected Member Functions

MeshBasemesh ()
 
void set_n_partitions (unsigned int n_parts)
 Sets the number of partitions in the mesh.
 
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.
 

Protected Attributes

std::vector< bool > elems_of_dimension
 A vector of bools describing what dimension elements have been encountered when reading a mesh.
 

Private Member Functions

void read_stream (std::istream &in)
 Implementation of the read() function.
 

Private Attributes

MeshBase_obj
 A pointer to a non-const object object.
 
const bool _is_parallel_format
 Flag specifying whether this format is parallel-capable.
 

Detailed Description

This class is responsible for reading an unstructured, triangulated surface in the standard OFF OOGL format.

Author
John W. Peterson
Date
2004

Reads OOF OOGL triangulated surface files.

Definition at line 39 of file off_io.h.

Constructor & Destructor Documentation

◆ OFFIO()

libMesh::OFFIO::OFFIO ( MeshBase mesh_in)
inlineexplicit

Constructor.

Takes a non-const Mesh reference which it will fill up with elements.

Definition at line 68 of file off_io.h.

68 :
69 MeshInput<MeshBase> (mesh_in)
70{}

Member Function Documentation

◆ is_parallel_format()

bool libMesh::MeshInput< MeshBase >::is_parallel_format ( ) const
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.

87{ return this->_is_parallel_format; }
const bool _is_parallel_format
Flag specifying whether this format is parallel-capable.
Definition mesh_input.h:130

◆ mesh()

MeshBase & libMesh::MeshInput< MeshBase >::mesh ( )
inlineprotectedinherited
Returns
The object as a writable reference.

Definition at line 94 of file mesh_input.h.

179{
180 libmesh_error_msg_if(_obj == nullptr, "ERROR: _obj should not be nullptr!");
181 return *_obj;
182}
MeshBase * _obj
A pointer to a non-const object object.
Definition mesh_input.h:123

◆ read()

void libMesh::OFFIO::read ( const std::string &  name)
overridevirtual

Reads in an OFF OOGL data file based on the string you pass it.

Implements libMesh::MeshInput< MeshBase >.

Definition at line 35 of file off_io.C.

36{
37 std::ifstream in (name.c_str());
38
39 read_stream(in);
40}
void read_stream(std::istream &in)
Implementation of the read() function.
Definition off_io.C:44
std::string name(const ElemQuality q)
This function returns a string containing some name for q.

References read_stream().

Referenced by libMesh::NameBasedIO::read().

◆ read_stream()

void libMesh::OFFIO::read_stream ( std::istream &  in)
private

Implementation of the read() function.

This function is called by the public interface function and implements reading the file.

Definition at line 44 of file off_io.C.

45{
46 // This is a serial-only process for now;
47 // the Mesh should be read on processor 0 and
48 // broadcast later
49 libmesh_assert_equal_to (this->mesh().processor_id(), 0);
50
51 // Get a reference to the mesh
52 MeshBase & the_mesh = MeshInput<MeshBase>::mesh();
53
54 // Clear any existing mesh data
55 the_mesh.clear();
56
57 // Check the input buffer
58 libmesh_assert (in.good());
59
60 unsigned int nn, ne, nf;
61
62 std::string label;
63
64 // Read the first string. It should say "OFF"
65 in >> label;
66
67 libmesh_assert_equal_to (label, "OFF");
68
69 // read the number of nodes, faces, and edges
70 in >> nn >> nf >> ne;
71
72
73 Real x=0., y=0., z=0.;
74
75 // Read the nodes
76 for (unsigned int n=0; n<nn; n++)
77 {
78 libmesh_assert (in.good());
79
80 in >> x
81 >> y
82 >> z;
83
84 the_mesh.add_point ( Point(x,y,z), n );
85 }
86
87 unsigned int nv, nid;
88
89 // Read the elements
90 for (unsigned int e=0; e<nf; e++)
91 {
92 libmesh_assert (in.good());
93
94 // The number of vertices in the element
95 in >> nv;
96
97 libmesh_assert(nv == 2 || nv == 3);
98 if (e == 0)
99 {
100 the_mesh.set_mesh_dimension(cast_int<unsigned char>(nv-1));
101 if (nv == 3)
102 {
103#if LIBMESH_DIM < 2
104 libmesh_error_msg("Cannot open dimension 2 mesh file when configured without 2D support.");
105#endif
106 }
107 }
108
109 std::unique_ptr<Elem> elem;
110 switch (nv)
111 {
112 case 2:
113 elem = Elem::build(EDGE2);
114 break;
115
116 case 3:
117 elem = Elem::build(TRI3);
118 break;
119
120 default:
121 libmesh_error_msg("Unsupported nv = " << nv);
122 }
123
124 elem->set_id(e);
125
126 for (unsigned int i=0; i<nv; i++)
127 {
128 in >> nid;
129 elem->set_node(i, the_mesh.node_ptr(nid));
130 }
131
132 the_mesh.add_elem(std::move(elem));
133 }
134}
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition elem.C:442
libmesh_assert(ctx)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References libMesh::MeshBase::add_elem(), libMesh::MeshBase::add_point(), libMesh::Elem::build(), libMesh::MeshBase::clear(), libMesh::EDGE2, libMesh::libmesh_assert(), libMesh::MeshInput< MT >::mesh(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshBase::node_ptr(), libMesh::Real, libMesh::MeshBase::set_mesh_dimension(), and libMesh::TRI3.

Referenced by read().

◆ set_n_partitions()

void libMesh::MeshInput< MeshBase >::set_n_partitions ( unsigned int  n_parts)
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.

101{ this->mesh().set_n_partitions() = n_parts; }
MeshBase & mesh

◆ skip_comment_lines()

void libMesh::MeshInput< MeshBase >::skip_comment_lines ( std::istream &  in,
const char  comment_start 
)
protectedinherited

Reads input from in, skipping all the lines that start with the character comment_start.

Definition at line 113 of file mesh_input.h.

189{
190 char c, line[256];
191
192 while (in.get(c), c==comment_start)
193 in.getline (line, 255);
194
195 // put back first character of
196 // first non-comment line
197 in.putback (c);
198}

Member Data Documentation

◆ _is_parallel_format

const bool libMesh::MeshInput< MeshBase >::_is_parallel_format
privateinherited

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 130 of file mesh_input.h.

◆ _obj

MeshBase * libMesh::MeshInput< MeshBase >::_obj
privateinherited

A pointer to a non-const object object.

This allows us to read the object from file.

Definition at line 123 of file mesh_input.h.

◆ elems_of_dimension

std::vector<bool> libMesh::MeshInput< MeshBase >::elems_of_dimension
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.


The documentation for this class was generated from the following files: