libMesh::FroIO Class Reference

#include <fro_io.h>

Inheritance diagram for libMesh::FroIO:

Public Member Functions

 FroIO (const MeshBase &)
 
virtual void write (const std::string &) libmesh_override
 
virtual void write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=libmesh_nullptr)
 
virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
 
virtual void write_nodal_data (const std::string &, const NumericVector< Number > &, const std::vector< std::string > &)
 
unsigned int & ascii_precision ()
 

Protected Member Functions

const MeshBasemesh () const
 

Protected Attributes

const bool _is_parallel_format
 
const bool _serial_only_needed_on_proc_0
 

Detailed Description

This class implements writing meshes in the .fro format used by the MIT ACDL. Valid only for triangular meshes.

Author
Benjamin S. Kirk
Date
2007

Definition at line 42 of file fro_io.h.

Constructor & Destructor Documentation

libMesh::FroIO::FroIO ( const MeshBase mesh_in)
inlineexplicit

Constructor. Takes a reference to a constant mesh object. This constructor will only allow us to write the mesh.

Definition at line 64 of file fro_io.h.

64  :
65  MeshOutput<MeshBase> (mesh_in)
66 {
67 }

Member Function Documentation

unsigned int& libMesh::MeshOutput< MeshBase >::ascii_precision ( )
inherited

Return/set the precision to use when writing ASCII files.

By default we use numeric_limits<Real>::digits10 + 2, which should be enough to write out to ASCII and get the exact same Real back when reading in.

Referenced by libMesh::TecplotIO::write_ascii(), libMesh::GMVIO::write_ascii_new_impl(), and libMesh::GMVIO::write_ascii_old_impl().

void libMesh::FroIO::write ( const std::string &  fname)
virtual

This method implements writing a mesh to a specified file.

Implements libMesh::MeshOutput< MeshBase >.

Definition at line 41 of file fro_io.C.

References libMesh::MeshOutput< MeshBase >::_is_parallel_format, libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), bc_id, libMesh::BoundaryInfo::build_side_list(), libMesh::Elem::build_side_ptr(), libMesh::MeshBase::elem_ref(), end, libMesh::BoundaryInfo::get_boundary_ids(), libMesh::MeshBase::get_boundary_info(), libMesh::libmesh_assert(), libMesh::MeshOutput< MeshBase >::mesh(), libMesh::MeshOutput< MT >::mesh(), libMesh::BoundaryInfo::n_boundary_ids(), libMesh::MeshBase::n_elem(), libMesh::MeshBase::n_nodes(), libMesh::MeshBase::point(), libMesh::processor_id(), side, and libMesh::TRI3.

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

42 {
43  // We may need to gather a DistributedMesh to output it, making that
44  // const qualifier in our constructor a dirty lie
45  MeshSerializer serialize(const_cast<MeshBase &>(this->mesh()), !_is_parallel_format);
46 
47  if (this->mesh().processor_id() == 0)
48  {
49  // Open the output file stream
50  std::ofstream out_stream (fname.c_str());
51  libmesh_assert (out_stream.good());
52 
53  // Make sure it opened correctly
54  if (!out_stream.good())
55  libmesh_file_error(fname.c_str());
56 
57  // Get a reference to the mesh
58  const MeshBase & the_mesh = MeshOutput<MeshBase>::mesh();
59 
60  // Write the header
61  out_stream << the_mesh.n_elem() << " "
62  << the_mesh.n_nodes() << " "
63  << "0 0 "
64  << the_mesh.get_boundary_info().n_boundary_ids() << " 1\n";
65 
66  // Write the nodes -- 1-based!
67  for (unsigned int n=0; n<the_mesh.n_nodes(); n++)
68  out_stream << n+1 << " \t"
69  << std::scientific
70  << std::setprecision(12)
71  << the_mesh.point(n)(0) << " \t"
72  << the_mesh.point(n)(1) << " \t"
73  << 0. << '\n';
74 
75  // Write the elements -- 1-based!
76  MeshBase::const_element_iterator it = the_mesh.active_elements_begin();
77  const MeshBase::const_element_iterator end = the_mesh.active_elements_end();
78 
79  for (unsigned int e=0 ; it != end; ++it)
80  {
81  // .fro likes TRI3's
82  if ((*it)->type() != TRI3)
83  libmesh_error_msg("ERROR: .fro format only valid for triangles!\n" \
84  << " writing of " << fname << " aborted.");
85 
86  out_stream << ++e << " \t";
87 
88  for (unsigned int n=0; n<(*it)->n_nodes(); n++)
89  out_stream << (*it)->node_id(n)+1 << " \t";
90 
91  // // LHS -> RHS Mapping, for inverted triangles
92  // out_stream << (*it)->node_id(0)+1 << " \t";
93  // out_stream << (*it)->node_id(2)+1 << " \t";
94  // out_stream << (*it)->node_id(1)+1 << " \t";
95 
96  out_stream << "1\n";
97  }
98 
99  // Write BCs.
100  {
101  const std::set<boundary_id_type> & bc_ids =
102  the_mesh.get_boundary_info().get_boundary_ids();
103 
104  std::vector<dof_id_type> el;
105  std::vector<unsigned short int> sl;
106  std::vector<boundary_id_type> il;
107 
108  the_mesh.get_boundary_info().build_side_list (el, sl, il);
109 
110 
111  // Map the boundary ids into [1,n_bc_ids],
112  // treat them one at a time.
114  for (std::set<boundary_id_type>::const_iterator id = bc_ids.begin();
115  id != bc_ids.end(); ++id)
116  {
117  std::deque<dof_id_type> node_list;
118 
119  std::map<dof_id_type, dof_id_type>
120  forward_edges, backward_edges;
121 
122  // Get all sides on this element with the relevant BC id.
123  for (std::size_t e=0; e<el.size(); e++)
124  if (il[e] == *id)
125  {
126  // need to build up node_list as a sorted array of edge nodes...
127  // for the following:
128  // a---b---c---d---e
129  // node_list [ a b c d e];
130  //
131  // the issue is just how to get this out of the elem/side based data structure.
132  // the approach is to build up 'chain links' like this:
133  // a---b b---c c---d d---e
134  // and piece them together.
135  //
136  // so, for an arbitray edge n0---n1, we build the
137  // "forward_edges" map n0-->n1
138  // "backward_edges" map n1-->n0
139  // and then start with one chain link, and add on...
140  //
141  UniquePtr<const Elem> side =
142  the_mesh.elem_ref(el[e]).build_side_ptr(sl[e]);
143 
144  const dof_id_type
145  n0 = side->node_id(0),
146  n1 = side->node_id(1);
147 
148  // insert into forward-edge set
149  forward_edges.insert (std::make_pair(n0, n1));
150 
151  // insert into backward-edge set
152  backward_edges.insert (std::make_pair(n1, n0));
153 
154  // go ahead and add one edge to the list -- this will give us the beginning of a
155  // chain to work from!
156  if (node_list.empty())
157  {
158  node_list.push_front(n0);
159  node_list.push_back (n1);
160  }
161  }
162 
163  // we now have the node_list with one edge, the forward_edges, and the backward_edges
164  // the node_list will be filled when (node_list.size() == (n_edges+1))
165  // until that is the case simply add on to the beginning and end of the node_list,
166  // building up a chain of ordered nodes...
167  const std::size_t n_edges = forward_edges.size();
168 
169  while (node_list.size() != (n_edges+1))
170  {
171  const dof_id_type
172  front_node = node_list.front(),
173  back_node = node_list.back();
174 
175  // look for front_pair in the backward_edges list
176  {
177  std::map<dof_id_type, dof_id_type>::iterator
178  pos = backward_edges.find(front_node);
179 
180  if (pos != backward_edges.end())
181  {
182  node_list.push_front(pos->second);
183 
184  backward_edges.erase(pos);
185  }
186  }
187 
188  // look for back_pair in the forward_edges list
189  {
190  std::map<dof_id_type, dof_id_type>::iterator
191  pos = forward_edges.find(back_node);
192 
193  if (pos != forward_edges.end())
194  {
195  node_list.push_back(pos->second);
196 
197  forward_edges.erase(pos);
198  }
199  }
200 
201  // libMesh::out << "node_list.size()=" << node_list.size()
202  // << ", n_edges+1=" << n_edges+1 << std::endl;
203  }
204 
205 
206  out_stream << ++bc_id << " " << node_list.size() << '\n';
207 
208  std::deque<dof_id_type>::iterator pos = node_list.begin();
209  for ( ; pos != node_list.end(); ++pos)
210  out_stream << *pos+1 << " \t0\n";
211  }
212  }
213  }
214 }
unsigned short int side
Definition: xdr_io.C:49
IterBase * end
const MeshBase & mesh() const
boundary_id_type bc_id
Definition: xdr_io.C:50
libmesh_assert(j)
int8_t boundary_id_type
Definition: id_types.h:51
processor_id_type processor_id()
Definition: libmesh_base.h:96
uint8_t dof_id_type
Definition: id_types.h:64
virtual void libMesh::MeshOutput< MeshBase >::write_equation_systems ( const std::string &  ,
const EquationSystems ,
const std::set< std::string > *  system_names = libmesh_nullptr 
)
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.

Referenced by libMesh::Nemesis_IO::write_timestep(), and libMesh::ExodusII_IO::write_timestep().

virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
)
inlinevirtualinherited

This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided.

Reimplemented in libMesh::ExodusII_IO, libMesh::NameBasedIO, libMesh::GmshIO, libMesh::Nemesis_IO, libMesh::UCDIO, libMesh::VTKIO, libMesh::GMVIO, libMesh::MEDITIO, libMesh::GnuPlotIO, and libMesh::TecplotIO.

Definition at line 96 of file mesh_output.h.

References libMesh::MeshOutput< MT >::ascii_precision(), libMesh::MeshOutput< MT >::mesh(), and libMesh::MeshOutput< MT >::write_nodal_data().

99  { libmesh_not_implemented(); }
virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  ,
const NumericVector< Number > &  ,
const std::vector< std::string > &   
)
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 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.

Member Data Documentation

const bool libMesh::MeshOutput< MeshBase >::_is_parallel_format
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 141 of file mesh_output.h.

Referenced by write(), libMesh::PostscriptIO::write(), and libMesh::EnsightIO::write().

const bool libMesh::MeshOutput< MeshBase >::_serial_only_needed_on_proc_0
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 150 of file mesh_output.h.


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