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

Protected Member Functions

MeshBasemesh ()
 
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...
 

Protected Attributes

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

Private Member Functions

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

Private Attributes

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

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

◆ mesh()

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

Definition at line 169 of file mesh_input.h.

170 {
171  if (_obj == nullptr)
172  libmesh_error_msg("ERROR: _obj should not be nullptr!");
173  return *_obj;
174 }

◆ 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 }

References libMesh::Quality::name(), and 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  Elem * elem;
110  switch (nv)
111  {
112  case 2:
113  elem = new Edge2;
114  break;
115 
116  case 3:
117  elem = new Tri3;
118  break;
119 
120  default:
121  libmesh_error_msg("Unsupported nv = " << nv);
122  }
123 
124  elem->set_id(e);
125  the_mesh.add_elem (elem);
126 
127  for (unsigned int i=0; i<nv; i++)
128  {
129  in >> nid;
130  elem->set_node(i) = the_mesh.node_ptr(nid);
131  }
132  }
133 }

References libMesh::MeshBase::add_elem(), libMesh::MeshBase::add_point(), libMesh::MeshBase::clear(), libMesh::libmesh_assert(), libMesh::MeshInput< MT >::mesh(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshBase::node_ptr(), libMesh::Real, libMesh::DofObject::set_id(), libMesh::MeshBase::set_mesh_dimension(), and libMesh::Elem::set_node().

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

91 { this->mesh().set_n_partitions() = n_parts; }

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

181 {
182  char c, line[256];
183 
184  while (in.get(c), c==comment_start)
185  in.getline (line, 255);
186 
187  // put back first character of
188  // first non-comment line
189  in.putback (c);
190 }

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 121 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 114 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 97 of file mesh_input.h.


The documentation for this class was generated from the following files:
libMesh::MeshBase::set_n_partitions
unsigned int & set_n_partitions()
Definition: mesh_base.h:1667
libMesh::OFFIO::read_stream
void read_stream(std::istream &in)
Implementation of the read() function.
Definition: off_io.C:44
libMesh::MeshInput< MeshBase >::_obj
MeshBase * _obj
A pointer to a non-const object object.
Definition: mesh_input.h:114
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::MeshInput< MeshBase >::mesh
MeshBase & mesh()
Definition: mesh_input.h:169
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::Quality::name
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42