libMesh::MeshData Class Reference

#include <mesh_data.h>

Public Types

typedef std::map< const Node *, std::vector< Number > >::const_iterator const_node_data_iterator
 
typedef std::map< const Elem *, std::vector< Number > >::const_iterator const_elem_data_iterator
 

Public Member Functions

 MeshData (const MeshBase &m)
 
 ~MeshData ()
 
void activate (const std::string &descriptor="")
 
void enable_compatibility_mode (const std::string &descriptor="")
 
void clear ()
 
void slim (const bool node_id_map=true, const bool elem_id_map=true)
 
void translate (const MeshBase &out_mesh, std::vector< Number > &data_values, std::vector< std::string > &data_names) const
 
void read (const std::string &name)
 
void write (const std::string &name)
 
std::string get_info () const
 
void print_info (std::ostream &os=libMesh::out) const
 
Number operator() (const Node *node, const unsigned int i=0) const
 
bool has_data (const Node *node) const
 
const std::vector< Number > & get_data (const Node *node) const
 
void set_data (const Node *node, const std::vector< Number > &val)
 
unsigned int n_val_per_node () const
 
dof_id_type n_node_data () const
 
const_node_data_iterator node_data_begin () const
 
const_node_data_iterator node_data_end () const
 
void insert_node_data (std::map< const Node *, std::vector< Number > > &nd, const bool close_elem_data=true)
 
Number operator() (const Elem *elem, const unsigned int i=0) const
 
bool has_data (const Elem *elem) const
 
const std::vector< Number > & get_data (const Elem *elem) const
 
void set_data (const Elem *elem, const std::vector< Number > &val)
 
unsigned int n_val_per_elem () const
 
dof_id_type n_elem_data () const
 
const_elem_data_iterator elem_data_begin () const
 
const_elem_data_iterator elem_data_end () const
 
void insert_elem_data (std::map< const Elem *, std::vector< Number > > &ed, const bool close_node_data=true)
 
bool active () const
 
bool compatibility_mode () const
 
bool elem_initialized () const
 
bool node_initialized () const
 
const Nodeforeign_id_to_node (const unsigned int fid) const
 
const Elemforeign_id_to_elem (const unsigned int fid) const
 
unsigned int node_to_foreign_id (const Node *n) const
 
unsigned int elem_to_foreign_id (const Elem *n) const
 
const MeshDataUnvHeaderget_unv_header () const
 
void set_unv_header (MeshDataUnvHeader *unv_header)
 
void assign (const MeshData &omd)
 
void add_foreign_node_id (const Node *node, const unsigned int foreign_node_id)
 
void add_foreign_elem_id (const Elem *elem, const unsigned int foreign_elem_id)
 
void close_foreign_id_maps ()
 

Protected Member Functions

void read_tetgen (const std::string &name)
 
void read_unv (const std::string &file_name)
 
void read_unv_implementation (std::istream &in_file)
 
void write_unv (const std::string &file_name)
 
void write_unv_implementation (std::ostream &out_file)
 
void read_xdr (const std::string &name, const XdrMODE mode=READ)
 
void write_xdr (const std::string &name, const XdrMODE mode=WRITE)
 

Protected Attributes

const MeshBase_mesh
 
std::string _data_descriptor
 
std::map< const Node *, std::vector< Number > > _node_data
 
std::map< const Node *, unsigned int > _node_id
 
std::map< unsigned int, const Node * > _id_node
 
std::map< const Elem *, std::vector< Number > > _elem_data
 
std::map< const Elem *, unsigned int > _elem_id
 
std::map< unsigned int, const Elem * > _id_elem
 
bool _node_id_map_closed
 
bool _node_data_closed
 
bool _elem_id_map_closed
 
bool _elem_data_closed
 
bool _active
 
bool _compatibility_mode
 
MeshDataUnvHeader_unv_header
 

Friends

class MeshDataUnvHeader
 
std::ostream & operator<< (std::ostream &os, const MeshData &m)
 

Detailed Description

The MeshData class handles actual data and the corresponding I/O on entities (nodes, elements) of meshes. The MeshData can be used when dealing with files that contain nodal or element-oriented data, numbered in the same format as a corresponding mesh file (when activated) or with the libMesh element and node indices (when in compatibility mode). To use MeshData, it has to be either activated or the compatibility mode has to be enabled.

Author
Daniel Dreyer
Date
2003

Definition at line 54 of file mesh_data.h.

Member Typedef Documentation

typedef std::map<const Elem *, std::vector<Number> >::const_iterator libMesh::MeshData::const_elem_data_iterator

A const iterator over the element-associated data entries of MeshData. Use this when a loop over all Node * in the MeshData is wanted. Note that only const versions are provided. Also these iterators should not be confused with the node_iterators provided for the Mesh classes!

Definition at line 77 of file mesh_data.h.

typedef std::map<const Node *, std::vector<Number> >::const_iterator libMesh::MeshData::const_node_data_iterator

A const iterator over the nodal data entries of MeshData. Use this when a loop over all Node * in the MeshData is wanted. Note that only const versions are provided. Also these iterators should not be confused with the node_iterators provided for the Mesh classes!

Definition at line 67 of file mesh_data.h.

Constructor & Destructor Documentation

libMesh::MeshData::MeshData ( const MeshBase m)

Default Constructor. Takes const reference to the mesh it belongs to.

Definition at line 35 of file mesh_data.C.

35  :
36  _mesh (m),
37  _data_descriptor (""),
38  _node_id_map_closed (false),
39  _node_data_closed (false),
40  _elem_id_map_closed (false),
41  _elem_data_closed (false),
42  _active (false),
43  _compatibility_mode (false),
45 {
46  // This class isn't actively maintained, doesn't work in parallel,
47  // and usually isn't as good a solution as adding an additional
48  // ExplicitSystem with appropriate data field(s).
49  libmesh_deprecated();
50 }
bool _node_id_map_closed
Definition: mesh_data.h:575
const class libmesh_nullptr_t libmesh_nullptr
bool _elem_id_map_closed
Definition: mesh_data.h:593
bool _compatibility_mode
Definition: mesh_data.h:614
bool _elem_data_closed
Definition: mesh_data.h:599
std::string _data_descriptor
Definition: mesh_data.h:515
const MeshBase & _mesh
Definition: mesh_data.h:509
MeshDataUnvHeader * _unv_header
Definition: mesh_data.h:619
bool _node_data_closed
Definition: mesh_data.h:581
libMesh::MeshData::~MeshData ( )

Destructor.

Definition at line 55 of file mesh_data.C.

References clear().

56 {
57  clear();
58 }

Member Function Documentation

void libMesh::MeshData::activate ( const std::string &  descriptor = "")

When MeshData should be used, it has to be activated first, prior to reading in a mesh with the Mesh::read() methods. This will ensure that element and node ids given in the mesh file, i.e. the foreign node and element ids, are stored in the corresponding id maps. Optionally takes a string that should help the user in identifying the data later on.

Definition at line 64 of file mesh_data.C.

References _active, _compatibility_mode, _data_descriptor, and libMesh::err.

65 {
66 #ifdef DEBUG
68  libMesh::err << "WARNING: MeshData was in compatibility mode, now being activated."
69  << std::endl;
70 #endif
71 
72  _compatibility_mode = false;
73  _active = true;
74  _data_descriptor = descriptor;
75 }
bool _compatibility_mode
Definition: mesh_data.h:614
OStreamProxy err(std::cerr)
std::string _data_descriptor
Definition: mesh_data.h:515
bool libMesh::MeshData::active ( ) const
inline
Returns
true when this object is active and working. Use activate() to bring this object alive.

Definition at line 988 of file mesh_data.h.

References _active.

Referenced by libMesh::UNVIO::elements_out(), get_info(), libMesh::UNVIO::nodes_out(), slim(), and libMesh::UNVIO::write_implementation().

989 {
990  return _active;
991 }
void libMesh::MeshData::add_foreign_elem_id ( const Elem elem,
const unsigned int  foreign_elem_id 
)
inline

In general, MeshData gathers element-associated data from file, but it needs to relate this data with the Elem * of the current mesh. Mesh importers simply use this method to add such a map.

Definition at line 1046 of file mesh_data.h.

References _active, _elem_id, _elem_id_map_closed, _id_elem, and libMesh::libmesh_assert().

Referenced by assign(), libMesh::TetGenIO::element_in(), and libMesh::UNVIO::elements_in().

1048 {
1049  if (_active)
1050  {
1052  libmesh_assert(elem);
1053  libmesh_assert (_elem_id.find(elem) == _elem_id.end());
1054  libmesh_assert (_id_elem.find(foreign_elem_id) == _id_elem.end());
1055 
1056  _elem_id.insert(std::make_pair(elem, foreign_elem_id));
1057  _id_elem.insert(std::make_pair(foreign_elem_id, elem));
1058  }
1059 }
libmesh_assert(remote_elem)
bool _elem_id_map_closed
Definition: mesh_data.h:593
std::map< const Elem *, unsigned int > _elem_id
Definition: mesh_data.h:556
std::map< unsigned int, const Elem * > _id_elem
Definition: mesh_data.h:562
void libMesh::MeshData::add_foreign_node_id ( const Node node,
const unsigned int  foreign_node_id 
)
inline

In general, MeshData gathers nodal data from a file, but it needs to relate this data with the Node * of the current mesh. Mesh importers simply use this method to add such a map.

Definition at line 1020 of file mesh_data.h.

References _active, _id_node, _node_id, _node_id_map_closed, and libMesh::libmesh_assert().

Referenced by libMesh::TetGenIO::node_in(), and libMesh::UNVIO::nodes_in().

1022 {
1023  if (_active)
1024  {
1026  libmesh_assert(node);
1027  libmesh_assert (_node_id.find(node) == _node_id.end());
1028  libmesh_assert (_id_node.find(foreign_node_id) == _id_node.end());
1029 
1030  /*
1031  * _always_ insert in _id_node and _node_id. If we would
1032  * use the mesh.node(unsigned int) method or the node.id()
1033  * to get Node * and unsigned int, respectively, we would not
1034  * be safe any more when the mesh gets refined or re-numbered
1035  * within libMesh. And we could get in big trouble that would
1036  * be hard to find when importing data _after_ having refined...
1037  */
1038  _node_id.insert(std::make_pair(node, foreign_node_id));
1039  _id_node.insert(std::make_pair(foreign_node_id, node));
1040  }
1041 }
bool _node_id_map_closed
Definition: mesh_data.h:575
libmesh_assert(remote_elem)
std::map< unsigned int, const Node * > _id_node
Definition: mesh_data.h:539
std::map< const Node *, unsigned int > _node_id
Definition: mesh_data.h:532
void libMesh::MeshData::assign ( const MeshData omd)

Assign to this the data from the other MeshData. Used by BoundaryInfo when copying the MeshData from the d dimensional mesh to the d-1 dimensional mesh (the boundary mesh).

Definition at line 663 of file mesh_data.C.

References _active, _compatibility_mode, _data_descriptor, _elem_data, _elem_data_closed, _elem_id, _elem_id_map_closed, _id_node, _mesh, _node_data, _node_data_closed, _node_id, _node_id_map_closed, _unv_header, add_foreign_elem_id(), libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::DofObject::id(), and libMesh::libmesh_assert().

Referenced by libMesh::BoundaryInfo::sync().

664 {
665  this->_data_descriptor = omd._data_descriptor;
666  this->_node_id_map_closed = omd._node_id_map_closed;
667  this->_node_data_closed = omd._node_data_closed;
668 
669  // we have to be able to modify our elem id maps
671 
672  this->_elem_data_closed = omd._elem_data_closed;
673  this->_active = omd._active;
674  this->_compatibility_mode = omd._compatibility_mode;
675 
676  // this is ok because we do not manage the UnvHeader
677  // in terms of memory, but only hold a pointer to it...
678  this->_unv_header = omd._unv_header;
679 
680  // Now copy the foreign id maps -- but only for the
681  // nodes. The nodes of the boundary mesh are actually
682  // nodes of the volume mesh.
683  this->_node_id = omd._node_id;
684  this->_id_node = omd._id_node;
685 
686  // The element vector of the boundary mesh contains elements
687  // that are new, and there _cannot_ be any associated
688  // foreign id in the maps. Therefore, fill the maps with
689  // the libMesh id's. But only when the other MeshData
690  // has element ids.
691  if ((this->_active) && (omd._elem_id.size() != 0))
692  {
693 
694  MeshBase::const_element_iterator elem_it = _mesh.elements_begin();
695  const MeshBase::const_element_iterator elem_end = _mesh.elements_end();
696 
697  for (; elem_it != elem_end; ++elem_it)
698  {
699  const Elem * elem = *elem_it;
700  this->add_foreign_elem_id(elem, elem->id());
701  }
702  }
703 
704  // now we can safely assign omd's value
705  this->_elem_id_map_closed = omd._elem_id_map_closed;
706 
707 
708  // and finally the node- and element-associated data
709  this->_node_data = omd._node_data;
710  this->_elem_data = omd._elem_data;
711 }
bool _node_id_map_closed
Definition: mesh_data.h:575
libmesh_assert(remote_elem)
bool _elem_id_map_closed
Definition: mesh_data.h:593
std::map< unsigned int, const Node * > _id_node
Definition: mesh_data.h:539
virtual element_iterator elements_begin()=0
bool _compatibility_mode
Definition: mesh_data.h:614
virtual element_iterator elements_end()=0
bool _elem_data_closed
Definition: mesh_data.h:599
std::string _data_descriptor
Definition: mesh_data.h:515
const MeshBase & _mesh
Definition: mesh_data.h:509
MeshDataUnvHeader * _unv_header
Definition: mesh_data.h:619
void add_foreign_elem_id(const Elem *elem, const unsigned int foreign_elem_id)
Definition: mesh_data.h:1046
std::map< const Node *, unsigned int > _node_id
Definition: mesh_data.h:532
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
bool _node_data_closed
Definition: mesh_data.h:581
void libMesh::MeshData::clear ( )

Clears the data fields, but leaves the id maps untouched. Useful for clearing data for a new data file. Use slim() to delete the maps.

Definition at line 109 of file mesh_data.C.

References _data_descriptor, _elem_data, _elem_data_closed, _node_data, and _node_data_closed.

Referenced by read_unv(), read_xdr(), and ~MeshData().

110 {
111  _data_descriptor = "";
112  _node_data.clear();
113  _elem_data.clear();
114  _node_data_closed = false;
115  _elem_data_closed = false;
116 }
bool _elem_data_closed
Definition: mesh_data.h:599
std::string _data_descriptor
Definition: mesh_data.h:515
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
bool _node_data_closed
Definition: mesh_data.h:581
void libMesh::MeshData::close_foreign_id_maps ( )

Signal to this object that the mesh importer finished adding node and element foreign-id maps.

Definition at line 217 of file mesh_data.C.

References _active, _elem_id, _elem_id_map_closed, _id_elem, _id_node, _node_id, _node_id_map_closed, and libMesh::libmesh_assert().

Referenced by libMesh::UNVIO::read_implementation(), and libMesh::TetGenIO::read_nodes_and_elem().

218 {
219  if (_active)
220  {
221  libmesh_assert (!_elem_id.empty());
222  libmesh_assert (!_id_elem.empty());
223  libmesh_assert (!_node_id.empty());
224  libmesh_assert (!_id_node.empty());
225 
226  _elem_id_map_closed = true;
227  _node_id_map_closed = true;
228  }
229 }
bool _node_id_map_closed
Definition: mesh_data.h:575
libmesh_assert(remote_elem)
bool _elem_id_map_closed
Definition: mesh_data.h:593
std::map< unsigned int, const Node * > _id_node
Definition: mesh_data.h:539
std::map< const Elem *, unsigned int > _elem_id
Definition: mesh_data.h:556
std::map< unsigned int, const Elem * > _id_elem
Definition: mesh_data.h:562
std::map< const Node *, unsigned int > _node_id
Definition: mesh_data.h:532
bool libMesh::MeshData::compatibility_mode ( ) const
inline
Returns
true when this object is in compatibility mode. See enable_compatibility_mode() for details.

Definition at line 996 of file mesh_data.h.

References _compatibility_mode.

Referenced by libMesh::UNVIO::elements_out(), get_info(), libMesh::UNVIO::nodes_out(), read(), slim(), write(), and libMesh::UNVIO::write_implementation().

997 {
998  return _compatibility_mode;
999 }
bool _compatibility_mode
Definition: mesh_data.h:614
MeshData::const_elem_data_iterator libMesh::MeshData::elem_data_begin ( ) const
inline

Returns a MeshData::const_elem_data_iterators which points to the beginning of the Elem * data containers used here.

Definition at line 970 of file mesh_data.h.

References _elem_data.

971 {
972  return _elem_data.begin();
973 }
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
MeshData::const_elem_data_iterator libMesh::MeshData::elem_data_end ( ) const
inline

Returns a MeshData::const_elem_data_iterators which points to the end of the Elem * data containers used here.

Definition at line 978 of file mesh_data.h.

References _elem_data.

979 {
980  return _elem_data.end();
981 }
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
bool libMesh::MeshData::elem_initialized ( ) const
inline
Returns
true when this object is properly initialized and ready for use for element associated data, false otherwise.

Definition at line 1004 of file mesh_data.h.

References _active, and _elem_data_closed.

Referenced by get_info().

1005 {
1006  return (_active && _elem_data_closed);
1007 }
bool _elem_data_closed
Definition: mesh_data.h:599
unsigned int libMesh::MeshData::elem_to_foreign_id ( const Elem n) const
Returns
the foreign id this Elem * maps to.

Definition at line 463 of file mesh_data.C.

References _active, _compatibility_mode, _elem_id, _elem_id_map_closed, libMesh::DofObject::id(), and libMesh::libmesh_assert().

Referenced by libMesh::UNVIO::elements_out(), and write_xdr().

464 {
465  libmesh_assert(e);
466 
467  if (_active)
468  {
469  // when active, use our _id_elem map
471 
472  // look it up in the map
473  std::map<const Elem *,
474  unsigned int>::const_iterator pos = _elem_id.find(e);
475 
476  if (pos == _elem_id.end())
477  libmesh_error_msg("ERROR: No foreign id stored for the element with the libMesh id = " << e->id());
478 
479  else
480  return pos->second;
481  }
482  else if (_compatibility_mode)
483  // when only in compatibility mode,
484  // return libMesh's element id
485  return e->id();
486 
487  libmesh_error_msg("We'll never get here!");
488  return 0;
489 }
libmesh_assert(remote_elem)
bool _elem_id_map_closed
Definition: mesh_data.h:593
bool _compatibility_mode
Definition: mesh_data.h:614
std::map< const Elem *, unsigned int > _elem_id
Definition: mesh_data.h:556
void libMesh::MeshData::enable_compatibility_mode ( const std::string &  descriptor = "")

When the MeshData should be used, but was not activated prior to reading in a mesh, then the compatibility mode enables to still use this object as if the MeshData was active. The foreign node and element ids are simply assigned the indices used in libMesh. Note that the compatibility mode should be used with caution, since the node and element indices in libMesh may be renumbered any time. This MeshData always employs the current node and element ids, it does not create an image of ids when compatibility mode was activated.

Definition at line 81 of file mesh_data.C.

References _active, _compatibility_mode, _data_descriptor, _elem_id, _elem_id_map_closed, _id_elem, _id_node, _node_id, _node_id_map_closed, and libMesh::err.

Referenced by libMesh::UNVIO::write_implementation().

82 {
83  if (!_active)
84  {
85  _compatibility_mode = true;
86  _active = false;
87  // do as if the id maps are already closed
88  _node_id_map_closed = true;
89  _elem_id_map_closed = true;
90  _data_descriptor = descriptor;
91  // we can safely clear the id maps
92  _node_id.clear();
93  _id_node.clear();
94  _elem_id.clear();
95  _id_elem.clear();
96  }
97 #ifdef DEBUG
98  else
99  libMesh::err << "WARNING: MeshData was in compatibility mode, now being activated."
100  << std::endl;
101 #endif
102 }
bool _node_id_map_closed
Definition: mesh_data.h:575
bool _elem_id_map_closed
Definition: mesh_data.h:593
std::map< unsigned int, const Node * > _id_node
Definition: mesh_data.h:539
bool _compatibility_mode
Definition: mesh_data.h:614
OStreamProxy err(std::cerr)
std::string _data_descriptor
Definition: mesh_data.h:515
std::map< const Elem *, unsigned int > _elem_id
Definition: mesh_data.h:556
std::map< unsigned int, const Elem * > _id_elem
Definition: mesh_data.h:562
std::map< const Node *, unsigned int > _node_id
Definition: mesh_data.h:532
const Elem * libMesh::MeshData::foreign_id_to_elem ( const unsigned int  fid) const
Returns
the Elem * that this foreign id maps to.

Definition at line 434 of file mesh_data.C.

References _active, _compatibility_mode, _elem_id_map_closed, _id_elem, _mesh, libMesh::MeshBase::elem_ptr(), libMesh::libmesh_assert(), and libmesh_nullptr.

Referenced by read_tetgen(), and read_xdr().

435 {
436  if (_active)
437  {
438  // when active, use our _id_elem map
440 
441  std::map<unsigned int,
442  const Elem *>::const_iterator pos = _id_elem.find(fid);
443 
444  if (pos == _id_elem.end())
445  libmesh_error_msg("ERROR: Have no Elem * associated with the foreign id = " << fid);
446 
447  else
448  return pos->second;
449  }
450  else if (_compatibility_mode)
451  // when only in compatibility mode,
452  // return element using the libMesh id
453  return this->_mesh.elem_ptr(fid);
454 
455  libmesh_error_msg("We'll never get here!");
456  return libmesh_nullptr;
457 }
libmesh_assert(remote_elem)
const class libmesh_nullptr_t libmesh_nullptr
bool _elem_id_map_closed
Definition: mesh_data.h:593
bool _compatibility_mode
Definition: mesh_data.h:614
virtual const Elem * elem_ptr(const dof_id_type i) const =0
const MeshBase & _mesh
Definition: mesh_data.h:509
std::map< unsigned int, const Elem * > _id_elem
Definition: mesh_data.h:562
const Node * libMesh::MeshData::foreign_id_to_node ( const unsigned int  fid) const
Returns
the Node * that this foreign id maps to.

Definition at line 369 of file mesh_data.C.

References _active, _compatibility_mode, _id_node, _mesh, _node_id_map_closed, libMesh::libmesh_assert(), libmesh_nullptr, and libMesh::MeshBase::node_ptr().

Referenced by read_tetgen(), read_unv_implementation(), and read_xdr().

370 {
371  if (_active)
372  {
373  // when active, use our _id_node map
375 
376  std::map<unsigned int,
377  const Node *>::const_iterator pos = _id_node.find(fid);
378 
379  if (pos == _id_node.end())
380  libmesh_error_msg("ERROR: Have no Node * associated with the foreign id = " << fid);
381 
382  else
383  return pos->second;
384  }
385  else if (_compatibility_mode)
386  // when only in compatibility mode,
387  // return the node stored in the MeshBase
388  // under its current id
389  return this->_mesh.node_ptr(fid);
390 
391  libmesh_error_msg("We'll never get here!");
392  return libmesh_nullptr;
393 }
bool _node_id_map_closed
Definition: mesh_data.h:575
libmesh_assert(remote_elem)
const class libmesh_nullptr_t libmesh_nullptr
std::map< unsigned int, const Node * > _id_node
Definition: mesh_data.h:539
bool _compatibility_mode
Definition: mesh_data.h:614
const MeshBase & _mesh
Definition: mesh_data.h:509
virtual const Node * node_ptr(const dof_id_type i) const =0
const std::vector< Number > & libMesh::MeshData::get_data ( const Node node) const
inline
Returns
a const reference to the values associated with the node node. Beware: this method will crash when there is no data associated with the node node! Check existence through has_data() first.

Definition at line 862 of file mesh_data.h.

References _active, _compatibility_mode, _node_data, _node_data_closed, and libMesh::libmesh_assert().

Referenced by write_unv_implementation(), and write_xdr().

863 {
866 
867  std::map<const Node *,
868  std::vector<Number> >::const_iterator pos = _node_data.find(node);
869 
870 #ifdef DEBUG
871  if (pos == _node_data.end())
872  libmesh_error_msg("ERROR: No data for this node. Use has_data() first!");
873 #endif
874 
875  return pos->second;
876 }
libmesh_assert(remote_elem)
bool _compatibility_mode
Definition: mesh_data.h:614
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
bool _node_data_closed
Definition: mesh_data.h:581
const std::vector< Number > & libMesh::MeshData::get_data ( const Elem elem) const
inline
Returns
a const reference to the values associated with the element elem. Beware: this method will crash when there is no data associated with the element elem! Check existence through has_data() first.

Definition at line 942 of file mesh_data.h.

References _active, _compatibility_mode, _elem_data, _elem_data_closed, and libMesh::libmesh_assert().

943 {
946 
947  std::map<const Elem *,
948  std::vector<Number> >::const_iterator pos = _elem_data.find(elem);
949 
950 #ifdef DEBUG
951  if (pos == _elem_data.end())
952  libmesh_error_msg("ERROR: No data for this element. Use has_data() first!");
953 #endif
954 
955  return pos->second;
956 }
libmesh_assert(remote_elem)
bool _compatibility_mode
Definition: mesh_data.h:614
bool _elem_data_closed
Definition: mesh_data.h:599
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
std::string libMesh::MeshData::get_info ( ) const
Returns
a string containing relevant information about the mesh.

Definition at line 322 of file mesh_data.C.

References _data_descriptor, active(), compatibility_mode(), elem_initialized(), n_elem_data(), n_node_data(), n_val_per_elem(), n_val_per_node(), and node_initialized().

Referenced by print_info().

323 {
324  std::ostringstream oss;
325 
326  if (this->active() || this->compatibility_mode())
327  {
328  oss << " MeshData Information:\n";
329  if (this->active())
330  oss << " object activated.\n";
331  if (this->compatibility_mode())
332  oss << " object in compatibility mode.\n";
333  if (this->_data_descriptor != "")
334  oss << " descriptor=" << this->_data_descriptor << '\n';
335  if (this->elem_initialized())
336  oss << " Element associated data initialized.\n"
337  << " n_val_per_elem()=" << this->n_val_per_elem() << '\n'
338  << " n_elem_data()=" << this->n_elem_data() << '\n';
339  if (this->node_initialized())
340  oss << " Node associated data initialized.\n"
341  << " n_val_per_node()=" << this->n_val_per_node() << '\n'
342  << " n_node_data()=" << this->n_node_data() << '\n';
343  }
344  else
345  oss << " MeshData neither active nor in compatibility mode.\n";
346 
347  return oss.str();
348 }
unsigned int n_val_per_elem() const
Definition: mesh_data.C:633
bool active() const
Definition: mesh_data.h:988
bool elem_initialized() const
Definition: mesh_data.h:1004
std::string _data_descriptor
Definition: mesh_data.h:515
dof_id_type n_elem_data() const
Definition: mesh_data.C:652
dof_id_type n_node_data() const
Definition: mesh_data.C:622
unsigned int n_val_per_node() const
Definition: mesh_data.C:603
bool compatibility_mode() const
Definition: mesh_data.h:996
bool node_initialized() const
Definition: mesh_data.h:1012
const MeshDataUnvHeader & libMesh::MeshData::get_unv_header ( ) const
inline

Read access to the MeshDataUnvHeader data structure.

Definition at line 1063 of file mesh_data.h.

References _unv_header, and libMesh::libmesh_assert().

1064 {
1065  libmesh_assert(this->_unv_header);
1066  return *this->_unv_header;
1067 }
libmesh_assert(remote_elem)
MeshDataUnvHeader * _unv_header
Definition: mesh_data.h:619
bool libMesh::MeshData::has_data ( const Node node) const
inline
Returns
true when the node node has data, false otherwise.

Definition at line 848 of file mesh_data.h.

References _active, _compatibility_mode, _node_data, _node_data_closed, and libMesh::libmesh_assert().

Referenced by write_unv_implementation(), and write_xdr().

849 {
852 
853  std::map<const Node *,
854  std::vector<Number> >::const_iterator pos = _node_data.find(node);
855 
856  return (pos != _node_data.end());
857 }
libmesh_assert(remote_elem)
bool _compatibility_mode
Definition: mesh_data.h:614
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
bool _node_data_closed
Definition: mesh_data.h:581
bool libMesh::MeshData::has_data ( const Elem elem) const
inline
Returns
true when the element elem has data, false otherwise.

Definition at line 928 of file mesh_data.h.

References _active, _compatibility_mode, _elem_data, _elem_data_closed, and libMesh::libmesh_assert().

929 {
932 
933  std::map<const Elem *,
934  std::vector<Number> >::const_iterator pos = _elem_data.find(elem);
935 
936  return (pos != _elem_data.end());
937 }
libmesh_assert(remote_elem)
bool _compatibility_mode
Definition: mesh_data.h:614
bool _elem_data_closed
Definition: mesh_data.h:599
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
void libMesh::MeshData::insert_elem_data ( std::map< const Elem *, std::vector< Number > > &  ed,
const bool  close_node_data = true 
)

For the desperate user, element-associated boundary conditions may be inserted directly through the map ed. Similar to the version for nodal data, it is imperative that the local _elem_data is empty, that the id maps are closed, that the size of the std::vector's of each map have identical length and that the Elem points to elements of the associated mesh. Note that this method takes a non-const reference and essentially clears the passed-in data. If close_node_data is true (default), then this MeshData is ready for use: write to file, use the operator() methods etc. If false, the user has to add nodal data, too.

Definition at line 553 of file mesh_data.C.

References _active, _compatibility_mode, _elem_data, _elem_data_closed, _elem_id_map_closed, _node_data_closed, _node_id_map_closed, and libMesh::libmesh_assert().

556 {
557  libmesh_assert (this->_active || this->_compatibility_mode);
558  // these are also true in compatibility mode
560 
561  if (this->_elem_data_closed)
562  libmesh_error_msg("ERROR: Element data already closed! Use clear() first!");
563 
564  libmesh_assert (this->_elem_data.empty());
565 
566 #ifdef DEBUG
567  std::map<const Elem *,
568  std::vector<Number> >::const_iterator ed_pos = ed.begin();
569  std::map<const Elem *,
570  std::vector<Number> >::const_iterator ed_end = ed.end();
571 
572  // Compare entity-by-entity that the
573  // sizes of the std::vector's are identical.
574  const std::size_t reference_length = (*ed_pos).second.size();
575  ++ed_pos;
576 
577  for (; ed_pos != ed_end; ++ed_pos)
578  if ( (*ed_pos).second.size() != reference_length)
579  libmesh_error_msg("ERROR: Size mismatch.");
580 #endif
581 
582  // copy over
583  _elem_data = ed;
584 
585  // we may freely trash the ed
586  ed.clear();
587 
588  // close elem data
589  this->_elem_data_closed = true;
590 
591  // if user wants to, then close node data, too
592  if (close_node_data)
593  {
595  this->_node_data_closed = true;
596  }
597 }
bool _node_id_map_closed
Definition: mesh_data.h:575
libmesh_assert(remote_elem)
bool _elem_id_map_closed
Definition: mesh_data.h:593
bool _compatibility_mode
Definition: mesh_data.h:614
bool _elem_data_closed
Definition: mesh_data.h:599
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
bool _node_data_closed
Definition: mesh_data.h:581
void libMesh::MeshData::insert_node_data ( std::map< const Node *, std::vector< Number > > &  nd,
const bool  close_elem_data = true 
)

For the desperate user, nodal boundary conditions may be inserted directly through the map nd. It is mandatory that there does not yet exist any other node data in this object, that the id maps are closed, that the size of the std::vector's of each map have identical length and that the Node * point to nodes of the associated mesh. Note that this method takes a non-const reference and essentially clears the passed-in data. If close_elem_data is true (default), then this MeshData is ready for use: write to file, use the operator() methods etc. If false, the user has to add element-associated data, too.

Definition at line 497 of file mesh_data.C.

References _active, _compatibility_mode, _elem_data_closed, _elem_id_map_closed, _node_data, _node_data_closed, _node_id_map_closed, and libMesh::libmesh_assert().

500 {
501  libmesh_assert (this->_active || this->_compatibility_mode);
502  // these are also true in compatibility mode
504 
505  if (this->_node_data_closed)
506  libmesh_error_msg("ERROR: Nodal data already closed! Use clear() first!");
507 
508  libmesh_assert (this->_node_data.empty());
509 
510 #ifdef DEBUG
511  std::map<const Node *,
512  std::vector<Number> >::const_iterator nd_pos = nd.begin();
513  std::map<const Node *,
514  std::vector<Number> >::const_iterator nd_end = nd.end();
515 
516  // Compare entity-by-entity that the
517  // sizes of the std::vector's are identical.
518  // For this, simply take the length of the 0th
519  // entry as reference length, and compare this
520  // with the length of the 1st, 2nd...
521  libmesh_assert (nd_pos != nd_end);
522  const std::size_t reference_length = (*nd_pos).second.size();
523 
524  // advance, so that we compare with the 1st
525  ++nd_pos;
526 
527  for (; nd_pos != nd_end; ++nd_pos)
528  if ( (*nd_pos).second.size() != reference_length)
529  libmesh_error_msg("ERROR: Size mismatch.");
530 #endif
531 
532  // copy over
533  _node_data = nd;
534 
535  // we may freely trash the nd
536  nd.clear();
537 
538  // close node data
539  this->_node_data_closed = true;
540 
541  // if user wants to, then close elem data, too
542  if (close_elem_data)
543  {
545  this->_elem_data_closed = true;
546  }
547 }
bool _node_id_map_closed
Definition: mesh_data.h:575
libmesh_assert(remote_elem)
bool _elem_id_map_closed
Definition: mesh_data.h:593
bool _compatibility_mode
Definition: mesh_data.h:614
bool _elem_data_closed
Definition: mesh_data.h:599
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
bool _node_data_closed
Definition: mesh_data.h:581
dof_id_type libMesh::MeshData::n_elem_data ( ) const
Returns
the number of elements for which this MeshData has data stored.

Definition at line 652 of file mesh_data.C.

References _active, _compatibility_mode, _elem_data, _elem_data_closed, and libMesh::libmesh_assert().

Referenced by get_info().

653 {
654  libmesh_assert (this->_active || this->_compatibility_mode);
656 
657  return cast_int<dof_id_type>(_elem_data.size());
658 }
libmesh_assert(remote_elem)
bool _compatibility_mode
Definition: mesh_data.h:614
bool _elem_data_closed
Definition: mesh_data.h:599
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
dof_id_type libMesh::MeshData::n_node_data ( ) const
Returns
the number of nodes for which this MeshData has data stored.

Definition at line 622 of file mesh_data.C.

References _active, _compatibility_mode, _node_data, _node_data_closed, and libMesh::libmesh_assert().

Referenced by get_info().

623 {
624  libmesh_assert (this->_active || this->_compatibility_mode);
626 
627  return cast_int<dof_id_type>(this->_node_data.size());
628 }
libmesh_assert(remote_elem)
bool _compatibility_mode
Definition: mesh_data.h:614
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
bool _node_data_closed
Definition: mesh_data.h:581
unsigned int libMesh::MeshData::n_val_per_elem ( ) const
Returns
the number of Number -type data (i.e., the size of the std::vector<Number> returned through the operator() methods) associated with an element. Returns 0 when there is no element-associated data.

Definition at line 633 of file mesh_data.C.

References _active, _compatibility_mode, _elem_data, _elem_data_closed, and libMesh::libmesh_assert().

Referenced by get_info().

634 {
635  libmesh_assert (this->_active || this->_compatibility_mode);
637 
638  if (!_elem_data.empty())
639  {
640  std::map<const Elem *,
641  std::vector<Number> >::const_iterator pos = _elem_data.begin();
642  libmesh_assert (pos != _elem_data.end());
643  return cast_int<unsigned int>(pos->second.size());
644  }
645  else
646  return 0;
647 }
libmesh_assert(remote_elem)
bool _compatibility_mode
Definition: mesh_data.h:614
bool _elem_data_closed
Definition: mesh_data.h:599
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
unsigned int libMesh::MeshData::n_val_per_node ( ) const
Returns
the number of Number -type data (i.e., the size of the std::vector<Number> returned through the operator() methods) associated with a node. Returns 0 when no nodal data exists.

Definition at line 603 of file mesh_data.C.

References _active, _compatibility_mode, _node_data, _node_data_closed, and libMesh::libmesh_assert().

Referenced by get_info(), translate(), and write_unv_implementation().

604 {
605  libmesh_assert (this->_active || this->_compatibility_mode);
607 
608  if (!this->_node_data.empty())
609  {
610  std::map<const Node *,
611  std::vector<Number> >::const_iterator pos = _node_data.begin();
612  libmesh_assert (pos != _node_data.end());
613  return cast_int<unsigned int>(pos->second.size());
614  }
615  else
616  return 0;
617 }
libmesh_assert(remote_elem)
bool _compatibility_mode
Definition: mesh_data.h:614
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
bool _node_data_closed
Definition: mesh_data.h:581
MeshData::const_node_data_iterator libMesh::MeshData::node_data_begin ( ) const
inline

Returns the MeshData::const_node_data_iterator which points to the beginning of the Node * data containers used here.

Definition at line 890 of file mesh_data.h.

References _node_data.

891 {
892  return _node_data.begin();
893 }
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
MeshData::const_node_data_iterator libMesh::MeshData::node_data_end ( ) const
inline

Returns the MeshData::const_node_data_iterator which points to the end of the Node * data containers used here.

Definition at line 898 of file mesh_data.h.

References _node_data.

899 {
900  return _node_data.end();
901 }
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
bool libMesh::MeshData::node_initialized ( ) const
inline
Returns
true when this object is properly initialized and ready for use for nodal data, false otherwise.

Definition at line 1012 of file mesh_data.h.

References _active, and _node_data_closed.

Referenced by get_info().

1013 {
1014  return (_active && _node_data_closed);
1015 }
bool _node_data_closed
Definition: mesh_data.h:581
unsigned int libMesh::MeshData::node_to_foreign_id ( const Node n) const
Returns
the foreign id this Node * maps to.

Definition at line 399 of file mesh_data.C.

References _active, _compatibility_mode, _node_id, _node_id_map_closed, libMesh::DofObject::id(), and libMesh::libmesh_assert().

Referenced by libMesh::UNVIO::elements_out(), libMesh::UNVIO::nodes_out(), write_unv_implementation(), and write_xdr().

400 {
401  libmesh_assert(n);
402 
403  if (_active)
404  {
405  // when active, use our _node_id map
407 
408  // look it up in the map
409  std::map<const Node *,
410  unsigned int>::const_iterator pos = _node_id.find(n);
411 
412  if (pos == _node_id.end())
413  libmesh_error_msg("ERROR: No foreign id stored for the node with the libMesh id = " << n->id());
414 
415  else
416  return pos->second;
417  }
418  else if (_compatibility_mode)
419  // when only in compatibility mode,
420  // return libMesh's node id
421  return n->id();
422 
423  libmesh_error_msg("We'll never get here!");
424  return 0;
425 }
bool _node_id_map_closed
Definition: mesh_data.h:575
libmesh_assert(remote_elem)
bool _compatibility_mode
Definition: mesh_data.h:614
std::map< const Node *, unsigned int > _node_id
Definition: mesh_data.h:532
Number libMesh::MeshData::operator() ( const Node node,
const unsigned int  i = 0 
) const
inline
Returns
the $ i^{th} $ value (defaults to 0) associated with node node. Returns libMesh::zero when there is no such node in the map.

Definition at line 828 of file mesh_data.h.

References _active, _compatibility_mode, _node_data, _node_data_closed, libMesh::libmesh_assert(), and libMesh::zero.

830 {
833 
834  std::map<const Node *,
835  std::vector<Number> >::const_iterator pos = _node_data.find(node);
836 
837  if (pos == _node_data.end())
838  return libMesh::zero;
839 
840  // we only get here when pos != _node_data.end()
841  libmesh_assert_less (i, pos->second.size());
842  return pos->second[i];
843 }
libmesh_assert(remote_elem)
const Number zero
Definition: libmesh.h:179
bool _compatibility_mode
Definition: mesh_data.h:614
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
bool _node_data_closed
Definition: mesh_data.h:581
Number libMesh::MeshData::operator() ( const Elem elem,
const unsigned int  i = 0 
) const
inline
Returns
the $ i^{th} $ value (defaults to 0) associated with element elem. Returns libMesh::zero when there is no data for elem in the map.

Definition at line 908 of file mesh_data.h.

References _active, _compatibility_mode, _elem_data, _elem_data_closed, libMesh::libmesh_assert(), and libMesh::zero.

910 {
913 
914  std::map<const Elem *,
915  std::vector<Number> >::const_iterator pos = _elem_data.find(elem);
916 
917  if (pos == _elem_data.end())
918  return libMesh::zero;
919 
920  // we only get here when pos != _elem_data.end()
921  libmesh_assert_less (i, pos->second.size());
922  return pos->second[i];
923 }
libmesh_assert(remote_elem)
const Number zero
Definition: libmesh.h:179
bool _compatibility_mode
Definition: mesh_data.h:614
bool _elem_data_closed
Definition: mesh_data.h:599
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
void libMesh::MeshData::print_info ( std::ostream &  os = libMesh::out) const

Prints relevant information about the mesh.

Definition at line 353 of file mesh_data.C.

References get_info().

Referenced by libMesh::operator<<().

354 {
355  os << this->get_info()
356  << std::endl;
357 }
std::string get_info() const
Definition: mesh_data.C:322
void libMesh::MeshData::read ( const std::string &  name)

Read mesh data from file named name. Guess format from the file extension. Note that prior to this you have to at least either close_node_map() or close_elem_map().

Definition at line 235 of file mesh_data.C.

References _active, _compatibility_mode, _elem_id_map_closed, _node_id_map_closed, compatibility_mode(), libMesh::DECODE, libMesh::err, libMesh::libmesh_assert(), libMesh::READ, read_tetgen(), read_unv(), and read_xdr().

236 {
237  LOG_SCOPE("read()", "MeshData");
238 
240 
241  // the id maps have to be closed before reading
242  // (note that in compatibility mode these are also true)
244 
245 #ifdef DEBUG
246  if (this->compatibility_mode())
247  libMesh::err << "WARNING: MeshData in compatibility mode, node and element ids" << std::endl
248  << " stored in file may be totally different from libMesh ids!" << std::endl;
249 #endif
250 
251  // Read the file based on extension. We let all processors read the
252  // data because it would be inaccurate to let only one processor
253  // have it and we're too lazy to code up a proper parallel read or
254  // read+broadcast right now.
255 
256  if (name.rfind(".xta") < name.size())
257  this->read_xdr (name, READ);
258 
259  else if (name.rfind(".xtr") < name.size())
260  this->read_xdr (name, DECODE);
261 
262  else if (name.rfind(".unv") < name.size())
263  this->read_unv (name);
264 
265  else if ((name.rfind(".node") < name.size()) ||
266  (name.rfind(".ele") < name.size()))
267  this->read_tetgen (name);
268 
269  else
270  libmesh_error_msg(" ERROR: Unrecognized file extension: " << name \
271  << "\n I understand the following:\n\n" \
272  << " *.xta -- Internal ASCII data format\n" \
273  << " *.xtr -- Internal binary data format\n" \
274  << " *.unv -- I-deas format");
275 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
bool _node_id_map_closed
Definition: mesh_data.h:575
libmesh_assert(remote_elem)
bool _elem_id_map_closed
Definition: mesh_data.h:593
bool _compatibility_mode
Definition: mesh_data.h:614
void read_unv(const std::string &file_name)
OStreamProxy err(std::cerr)
void read_xdr(const std::string &name, const XdrMODE mode=READ)
void read_tetgen(const std::string &name)
bool compatibility_mode() const
Definition: mesh_data.h:996
void libMesh::MeshData::read_tetgen ( const std::string &  name)
protected

Read nodal/element oriented data in TetGen format.

Definition at line 34 of file mesh_data_tetgen_support.C.

References _data_descriptor, _elem_data, _elem_data_closed, _node_data, _node_data_closed, foreign_id_to_elem(), foreign_id_to_node(), libMesh::MeshTools::n_elem(), n_nodes, libMesh::Quality::name(), and libMesh::Real.

Referenced by read().

35 {
36  std::string name_node, name_ele, dummy;
37  std::string desc = name;
38 
39 
40  // Check name for *.node or *.ele extension.
41  // Set std::istream for node_stream and ele_stream.
42  if (name.rfind(".node") < name.size())
43  {
44  name_node = name;
45  dummy = name;
46  std::size_t position = dummy.rfind(".node");
47  name_ele = dummy.replace(position, 5, ".ele");
48  desc.erase(position);
49  }
50  else if (name.rfind(".ele") < name.size())
51  {
52  name_ele = name;
53  dummy = name;
54  std::size_t position = dummy.rfind(".ele");
55  name_node = dummy.replace(position, 4, ".node");
56  desc.erase(position);
57  }
58  else
59  libmesh_error_msg("ERROR: Unrecognized file name: " << name);
60 
61  // Set the streams from which to read in.
62  std::ifstream node_stream (name_node.c_str());
63  std::ifstream ele_stream (name_ele.c_str());
64 
65  if ( !node_stream.good() || !ele_stream.good() )
66  libmesh_error_msg("ERROR: One or both Input file(s) not good.\n" \
67  << "Error opening files " \
68  << name_node \
69  << " and " \
70  << name_ele);
71 
72 
73  // Set the descriptive name.
74  // TetGen won't give a name, so we use the filename.
75  this->_data_descriptor = desc;
76 
77 
78  //--------------------------------------------------
79  // Read in the data associated with the nodes.
80  {
81  unsigned int n_node=0, f_n_id=0, nAttri=0, BoundMark=0;
82  Real dummy_val=0.0;
83  std::vector<Number> AttriValue;
84 
85  // Read the parameters from the node_stream.
86  node_stream >> n_node // Read the number of nodes
87  >> dummy_val // Read the dimension
88  >> nAttri // Read the number of attributes
89  >> BoundMark; // (0 or 1) boundary markers are in the stream or not.
90 
91  // Resize the values vector.
92  AttriValue.resize(nAttri);
93 
94  for (unsigned int i=0; i<n_node; i++)
95  {
96  node_stream >> f_n_id;
97 
98 
99  // Read the nodal coordinates for this node into dummy_val,
100  // since we don't need them.
101  for (unsigned int j=0; j<3; j++)
102  node_stream >> dummy_val;
103 
104  // Read the attributes from the stream.
105  for (unsigned int j=0; j<nAttri; j++)
106  node_stream >> AttriValue[j];
107 
108  // Read boundary marker if BoundaryMarker=1.
109  if (BoundMark == 1)
110  node_stream >> dummy_val;
111 
112  // For the foreign node id locate the Node *.
113  const Node * node = foreign_id_to_node(f_n_id);
114 
115  // Insert this node and the values in our _node_data.
116  _node_data.insert (std::make_pair(node, AttriValue));
117  }
118  }
119 
120 
121  //--------------------------------------------------
122  // Read in the data associated with the elements.
123  {
124  unsigned int n_elem, f_e_id, n_nodes, nAttri=0;
125  Real dummy_val=0.0;
126  std::vector<Number> AttriValue;
127 
128  // Read the parameters from the ele_stream.
129  ele_stream >> n_elem // Read the number of tetrahedrons
130  >> n_nodes // Read the points per tetrahedron
131  >> nAttri; // Read the number of attributes
132 
133  // Resize the values vector.
134  AttriValue.resize(nAttri);
135 
136  for (unsigned int i=0; i<n_elem; i++)
137  {
138  ele_stream >> f_e_id;
139 
140  // For the number of nodes for this element read them into dummy_val,
141  // since we don't need them.
142  for (unsigned int n=0; n<n_nodes; n++)
143  ele_stream >> dummy_val;
144 
145  // Read the attributes from the stream.
146  for (unsigned int j=0; j<nAttri; j++)
147  ele_stream >> AttriValue[j];
148 
149  // For the foreign elem id locate the Elem *.
150  const Elem * elem = foreign_id_to_elem(f_e_id);
151 
152  // Insert this elem and the values in our _elem_data.
153  _elem_data.insert (std::make_pair(elem, AttriValue));
154  }
155  }
156 
157  //--------------------------------------------------
158  // Finished reading. Now ready for use.
159  this->_node_data_closed = true;
160  this->_elem_data_closed = true;
161 
162  node_stream.close();
163  ele_stream.close();
164 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
Definition: mesh_tools.C:669
const dof_id_type n_nodes
Definition: tecplot_io.C:67
const Elem * foreign_id_to_elem(const unsigned int fid) const
Definition: mesh_data.C:434
bool _elem_data_closed
Definition: mesh_data.h:599
std::string _data_descriptor
Definition: mesh_data.h:515
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Node * foreign_id_to_node(const unsigned int fid) const
Definition: mesh_data.C:369
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
bool _node_data_closed
Definition: mesh_data.h:581
void libMesh::MeshData::read_unv ( const std::string &  file_name)
protected

Read nodal/element oriented data in UNV format, either from an ASCII file or from a gzip'ed ASCII file, using the C++ wrapper gzstream to zlib.h.

Definition at line 39 of file mesh_data_unv_support.C.

References _active, _compatibility_mode, _elem_id_map_closed, _node_id_map_closed, clear(), libMesh::libmesh_assert(), and read_unv_implementation().

Referenced by read().

40 {
41  /*
42  * We better be active or in compatibility mode
43  */
45 
46  /*
47  * When reading data, make sure the id maps are ok
48  */
51 
52  /*
53  * clear the data, but keep the id maps
54  */
55  this->clear();
56 
57  /*
58  * We can read either ".unv", or ".unv.gz"
59  * files, provided zlib.h is there
60  */
61  if (file_name.rfind(".gz") < file_name.size())
62  {
63 #ifdef LIBMESH_HAVE_GZSTREAM
64  igzstream in_stream(file_name.c_str());
65  this->read_unv_implementation (in_stream);
66 #else
67  libmesh_error_msg("ERROR: You must have the zlib.h header files and libraries to read and write compressed streams.");
68 #endif
69  return;
70  }
71 
72  else
73  {
74  std::ifstream in_stream(file_name.c_str());
75  this->read_unv_implementation (in_stream);
76  return;
77  }
78 }
bool _node_id_map_closed
Definition: mesh_data.h:575
void read_unv_implementation(std::istream &in_file)
libmesh_assert(remote_elem)
bool _elem_id_map_closed
Definition: mesh_data.h:593
bool _compatibility_mode
Definition: mesh_data.h:614
void libMesh::MeshData::read_unv_implementation ( std::istream &  in_file)
protected

Actual implementation of reading nodal/element oriented data in UNV format. This has to be decoupled from read_unv() in order to allow reading both .unv and .unv.gz files.

Definition at line 85 of file mesh_data_unv_support.C.

References _elem_data, _elem_data_closed, _node_data, _node_data_closed, _unv_header, libMesh::MeshDataUnvHeader::data_type, libMesh::MeshDataUnvHeader::dataset_location, foreign_id_to_node(), libMesh::libmesh_assert(), libmesh_nullptr, libMesh::MeshDataUnvHeader::need_D_to_e(), libMesh::MeshDataUnvHeader::nvaldc, libMesh::MeshDataUnvHeader::read(), and libMesh::Real.

Referenced by read_unv().

86 {
87  /*
88  * This is the actual implementation of
89  * reading in UNV format. This enables
90  * to read either through the conventional
91  * C++ stream, or through a stream that
92  * allows to read .gz'ed files.
93  */
94  if ( !in_file.good() )
95  libmesh_error_msg("ERROR: Input file not good.");
96 
97  const std::string _label_dataset_mesh_data = "2414";
98 
99  /*
100  * locate the beginning of data set
101  * and read it.
102  */
103  {
104  std::string olds, news;
105 
106  while (true)
107  {
108  in_file >> olds >> news;
109 
110  /*
111  * Yes, really dirty:
112  *
113  * When we found a dataset, and the user does
114  * not want this dataset, we jump back here
115  */
116  go_and_find_the_next_dataset:
117 
118  /*
119  * a "-1" followed by a number means the beginning of a dataset
120  * stop combing at the end of the file
121  */
122  while( ((olds != "-1") || (news == "-1") ) && !in_file.eof() )
123  {
124  olds = news;
125  in_file >> news;
126  }
127 
128  if(in_file.eof())
129  break;
130 
131  /*
132  * if beginning of dataset
133  */
134  if (news == _label_dataset_mesh_data)
135  {
136 
137  /*
138  * Now read the data of interest.
139  * Start with the header. For
140  * explanation of the variable
141  * dataset_location, see below.
142  */
143  unsigned int dataset_location;
144 
145  /*
146  * the type of data (complex, real,
147  * float, double etc, see below)
148  */
149  unsigned int data_type;
150 
151  /*
152  * the number of floating-point values per entity
153  */
154  unsigned int NVALDC;
155 
156 
157  /*
158  * If there is no MeshDataUnvHeader object
159  * attached
160  */
162  {
163  /*
164  * Ignore the first lines that stand for
165  * analysis dataset label and name.
166  */
167  for(unsigned int i=0; i<3; i++)
168  in_file.ignore(256,'\n');
169 
170  /*
171  * Read the dataset location, where
172  * 1: Data at nodes
173  * 2: Data on elements
174  * other sets are currently not supported.
175  */
176  in_file >> dataset_location;
177 
178  /*
179  * Ignore five ID lines.
180  */
181  for(unsigned int i=0; i<6; i++)
182  in_file.ignore(256,'\n');
183 
184  /*
185  * These data are all of no interest to us...
186  */
187  unsigned int model_type,
188  analysis_type,
189  data_characteristic,
190  result_type;
191 
192  /*
193  * Read record 9.
194  */
195  in_file >> model_type // not used here
196  >> analysis_type // not used here
197  >> data_characteristic // not used here
198  >> result_type // not used here
199  >> data_type
200  >> NVALDC;
201 
202 
203  /*
204  * Ignore record 10 and 11
205  * (Integer analysis type specific data).
206  */
207  for (unsigned int i=0; i<3; i++)
208  in_file.ignore(256,'\n');
209 
210  /*
211  * Ignore record 12 and record 13. Since there
212  * exist UNV files with 'D' instead of 'e' as
213  * 10th-power char, it is safer to use a string
214  * to read the dummy reals.
215  */
216  {
217  std::string dummy_Real;
218  for (unsigned int i=0; i<12; i++)
219  in_file >> dummy_Real;
220  }
221 
222  }
223  else
224  {
225 
226  /*
227  * the read() method returns false when
228  * the user wanted a special header, and
229  * when the current header is _not_ the correct
230  * header
231  */
232  if (_unv_header->read(in_file))
233  {
234  dataset_location = _unv_header->dataset_location;
235  NVALDC = _unv_header->nvaldc;
236  data_type = _unv_header->data_type;
237  }
238  else
239  {
240  /*
241  * This is not the correct header. Go
242  * and find the next. For this to
243  * work correctly, shift to the
244  * next line, so that the "-1"
245  * disappears from olds
246  */
247  olds = news;
248  in_file >> news;
249 
250  /*
251  * No good style, i know...
252  */
253  goto go_and_find_the_next_dataset;
254  }
255 
256  }
257 
258  /*
259  * Check the location of the dataset.
260  */
261  if (dataset_location != 1)
262  libmesh_error_msg("ERROR: Currently only Data at nodes is supported.");
263 
264 
265  /*
266  * Now get the foreign node id number and the respective nodal data.
267  */
268  int f_n_id;
269  std::vector<Number> values;
270 
271  while(true)
272  {
273  in_file >> f_n_id;
274 
275  /*
276  * if node_nr = -1 then we have reached the end of the dataset.
277  */
278  if (f_n_id==-1)
279  break;
280 
281  /*
282  * Resize the values vector (usually data in three
283  * principle directions, i.e. NVALDC = 3).
284  */
285  values.resize(NVALDC);
286 
287  /*
288  * Read the meshdata for the respective node.
289  */
290  for (unsigned int data_cnt=0; data_cnt<NVALDC; data_cnt++)
291  {
292  /*
293  * Check what data type we are reading.
294  * 2,4: Real
295  * 5,6: Complex
296  * other data types are not supported yet.
297  * As again, these floats may also be written
298  * using a 'D' instead of an 'e'.
299  */
300  if (data_type == 2 || data_type == 4)
301  {
302  std::string buf;
303  in_file >> buf;
305 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
306  values[data_cnt] = Complex(std::atof(buf.c_str()), 0.);
307 #else
308  values[data_cnt] = std::atof(buf.c_str());
309 #endif
310  }
311 
312  else if(data_type == 5 || data_type == 6)
313 
314  {
315 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
316  Real re_val, im_val;
317 
318  std::string buf;
319  in_file >> buf;
320 
322  {
323  re_val = std::atof(buf.c_str());
324  in_file >> buf;
326  im_val = std::atof(buf.c_str());
327  }
328  else
329  {
330  re_val = std::atof(buf.c_str());
331  in_file >> im_val;
332  }
333 
334  values[data_cnt] = Complex(re_val,im_val);
335 #else
336 
337  libmesh_error_msg("ERROR: Complex data only supported when libMesh is configured with --enable-complex!");
338 #endif
339  }
340 
341  else
342  libmesh_error_msg("ERROR: Data type not supported.");
343 
344  } // end loop data_cnt
345 
346  /*
347  * Add the values vector to the MeshData data structure.
348  */
349  const Node * node = foreign_id_to_node(f_n_id);
350  _node_data.insert (std::make_pair(node, values));
351 
352  } // while(true)
353  }
354 
355 
356  else
357  {
358  /*
359  * all other datasets are ignored
360  */
361  }
362 
363  }
364  }
365 
366 
367  /*
368  * finished reading. Ready for use, provided
369  * there was any data contained in the file.
370  */
371  libmesh_assert ((this->_node_data.size() != 0) || (this->_elem_data.size() != 0));
372 
373  this->_node_data_closed = true;
374  this->_elem_data_closed = true;
375 }
libmesh_assert(remote_elem)
const class libmesh_nullptr_t libmesh_nullptr
MPI_Datatype data_type
Definition: parallel.h:162
static bool need_D_to_e(std::string &number)
bool _elem_data_closed
Definition: mesh_data.h:599
std::complex< Real > Complex
bool read(std::istream &in_file)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
MeshDataUnvHeader * _unv_header
Definition: mesh_data.h:619
const Node * foreign_id_to_node(const unsigned int fid) const
Definition: mesh_data.C:369
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
unsigned int dataset_location
Definition: mesh_data.h:730
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
bool _node_data_closed
Definition: mesh_data.h:581
void libMesh::MeshData::read_xdr ( const std::string &  name,
const XdrMODE  mode = READ 
)
protected

Read nodal/element oriented data using the Xdr class that enables both ASCII and binary format through the same interface. By default uses ASCII format, but may easily be changed setting mode to DECODE.

This code implements the output of the MeshData object in XDR format. This warrants some documentation. The output consists of 8 sections:

1.) The name of the data stored, if provided (string)

2.) A switch whether real or complex data is stored (string)

3.) The number of nodes for which values are stored (unsigned int)

4.) The number of elements for which values are stored (unsigned int)

for each node

5.) The foreign node id (unsigned int)

6.) The actual values (vector of real/complex)

end node loop

for each element

7.) The foreign element id (unsigned int)

8.) The actual values (vector of real/complex)

end node loop

Note that the actual IO is handled through the Xdr class (to be renamed later?) which provides a uniform interface to both the XDR (eXternal Data Representation) interface and standard ASCII output. Thus this one section of code will write XDR or ASCII files with no changes.

clear the data, but keep the id maps

1.)

Read the descriptive name

2.)

Read: either real or complex

3.)

Read the number of nodes for which data is there

4.)

Read the number of elements for which data is there

5.)

Read the foreign node id, locate the Node * associated with this foreign id

6.)

the actual values for this node, Xdr knows the length

insert this node and the values in the _node_data

7.)

Read the foreign elem id, locate the Elem *

8.)

the actual values for this elem, Xdr knows how many

insert this elem and the values in our _elem_data only when we own this element!

Definition at line 35 of file mesh_data_xdr_support.C.

References _active, _compatibility_mode, _data_descriptor, _elem_data, _elem_data_closed, _elem_id_map_closed, _mesh, _node_data, _node_data_closed, _node_id_map_closed, clear(), libMesh::Xdr::data(), foreign_id_to_elem(), foreign_id_to_node(), libMesh::libmesh_assert(), libMesh::MeshTools::n_elem(), libMesh::ParallelObject::processor_id(), and libMesh::DofObject::processor_id().

Referenced by read().

37 {
77  // Better be active or in compatibility mode
79 
80 
81  // make sure the id maps are ready
84 
85 
89  this->clear();
90 
91 
92  Xdr io(name, mode);
93 
94 
95  /*
96  * all processors read the data in the same format,
97  * but only the processor that owns the element stores
98  * element-associated data. For nodes, i haven't come
99  * up with such asmart idea, yet... :-P
100  */
101  const unsigned int proc_id = _mesh.processor_id();
102 
103 
104 
110  {
111  std::string desc = "";
112  io.data (desc);
113  this->_data_descriptor = desc;
114  }
115 
116 
117 
123  {
124  std::string vtype="";
125  io.data (vtype);
126 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
127  if (vtype != "COMPLEX")
128  libmesh_error_msg("ERROR: File does not contain complex-valued data!");
129 
130 #elif LIBMESH_USE_REAL_NUMBERS
131  if (vtype != "REAL")
132  libmesh_error_msg("ERROR: File does not contain real-valued data!");
133 
134 #else
135  /*
136  * What number type is this?
137  */
138  libmesh_error_msg("Must be using either real or complex numbers!");
139 #endif
140  }
141 
142 
143 
149  unsigned int n_node = 0;
150  io.data (n_node);
151 
152 
158  unsigned int n_elem = 0;
159  io.data (n_elem);
160 
161 #ifdef DEBUG
162  std::size_t previous_values_size = 0;
163 #endif
164 
165  for (unsigned int n_cnt=0; n_cnt < n_node; n_cnt++)
166  {
173  unsigned int f_id = 0;
174  io.data (f_id);
175 
176  const Node * node = foreign_id_to_node(f_id);
177 
178 
185  {
186  std::vector<Number> values;
187  io.data (values);
188 
189 
190 #ifdef DEBUG
191  /*
192  * make sure the size of the values vectors
193  * are identical for all nodes
194  */
195  if (n_cnt == 0)
196  previous_values_size = values.size();
197  else
198  {
199  if (previous_values_size != values.size())
200  libmesh_error_msg("ERROR: Size mismatch for n_cnt = " << n_cnt);
201  }
202 #endif
203 
204 
208  _node_data.insert (std::make_pair(node, values));
209  }
210  }
211 
212 
213 
214 #ifdef DEBUG
215  previous_values_size = 0;
216 #endif
217 
218  for (unsigned int n_cnt=0; n_cnt < n_elem; n_cnt++)
219  {
225  unsigned int f_id = 0;
226  io.data (f_id);
227 
228  const Elem * elem = foreign_id_to_elem(f_id);
229 
230 
237  {
238  std::vector<Number> values;
239  io.data (values);
240 
241 
242 #ifdef DEBUG
243  /*
244  * make sure the size of the values vectors
245  * are identical for all elements
246  */
247  if (n_cnt == 0)
248  previous_values_size = values.size();
249  else
250  {
251  if (previous_values_size != values.size())
252  libmesh_error_msg("ERROR: Size mismatch for n_cnt = " << n_cnt);
253  }
254 #endif
255 
256 
261  if (elem->processor_id() == proc_id)
262  _elem_data.insert (std::make_pair(elem, values));
263  }
264  }
265 
266 
267  /*
268  * finished reading. Now ready for use, provided
269  * there was any data contained in the file.
270  */
271  libmesh_assert ((this->_node_data.size() != 0) || (this->_elem_data.size() != 0));
272 
273  this->_node_data_closed = true;
274  this->_elem_data_closed = true;
275 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
bool _node_id_map_closed
Definition: mesh_data.h:575
libmesh_assert(remote_elem)
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
Definition: mesh_tools.C:669
bool _elem_id_map_closed
Definition: mesh_data.h:593
bool _compatibility_mode
Definition: mesh_data.h:614
const Elem * foreign_id_to_elem(const unsigned int fid) const
Definition: mesh_data.C:434
bool _elem_data_closed
Definition: mesh_data.h:599
std::string _data_descriptor
Definition: mesh_data.h:515
const MeshBase & _mesh
Definition: mesh_data.h:509
const Node * foreign_id_to_node(const unsigned int fid) const
Definition: mesh_data.C:369
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
processor_id_type processor_id() const
bool _node_data_closed
Definition: mesh_data.h:581
void libMesh::MeshData::set_data ( const Node node,
const std::vector< Number > &  val 
)
inline

Sets all the data values associated with the node node, overwriting any existing vector

Definition at line 881 of file mesh_data.h.

References _node_data.

883 {
884  this->_node_data[node] = val;
885 }
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
void libMesh::MeshData::set_data ( const Elem elem,
const std::vector< Number > &  val 
)
inline

Sets all the data values associated with the element elem, overwriting any existing vector

Definition at line 961 of file mesh_data.h.

References _elem_data.

963 {
964  this->_elem_data[elem] = val;
965 }
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
void libMesh::MeshData::set_unv_header ( MeshDataUnvHeader unv_header)
inline

Set the MeshDataUnvHeader data structure that will be used for output.

Definition at line 1071 of file mesh_data.h.

References _unv_header, and libMesh::libmesh_assert().

1072 {
1073  libmesh_assert(unv_header);
1074  this->_unv_header = unv_header;
1075 }
libmesh_assert(remote_elem)
MeshDataUnvHeader * _unv_header
Definition: mesh_data.h:619
void libMesh::MeshData::slim ( const bool  node_id_map = true,
const bool  elem_id_map = true 
)

Once the data is properly read from file, the id maps can safely be cleared. However, if this object should remain able to write nodal or element oriented data to file, this method should not be used. Use the appropriate bool to select the id map that should be cleared. By default, both id maps are deleted.

Definition at line 122 of file mesh_data.C.

References _elem_id, _elem_id_map_closed, _id_elem, _id_node, _node_id, _node_id_map_closed, active(), compatibility_mode(), libMesh::err, and libMesh::libmesh_assert().

124 {
125  if (this->active())
126  {
127 
128  if (node_id_map)
129  {
130  // dumb check
132 
133  _node_id_map_closed = false;
134  _node_id.clear();
135  _id_node.clear();
136  }
137 
138  if (elem_id_map)
139  {
140  // dumb check
142 
143  _elem_id_map_closed = false;
144  _elem_id.clear();
145  _id_elem.clear();
146  }
147  }
148 
149 #ifdef DEBUG
150  else if (this->compatibility_mode())
151  {
152  libMesh::err << "WARNING: No need for MeshData::slim() in compatibility mode." << std::endl;
153  }
154 #endif
155 }
bool _node_id_map_closed
Definition: mesh_data.h:575
libmesh_assert(remote_elem)
bool active() const
Definition: mesh_data.h:988
bool _elem_id_map_closed
Definition: mesh_data.h:593
std::map< unsigned int, const Node * > _id_node
Definition: mesh_data.h:539
OStreamProxy err(std::cerr)
std::map< const Elem *, unsigned int > _elem_id
Definition: mesh_data.h:556
std::map< unsigned int, const Elem * > _id_elem
Definition: mesh_data.h:562
std::map< const Node *, unsigned int > _node_id
Definition: mesh_data.h:532
bool compatibility_mode() const
Definition: mesh_data.h:996
void libMesh::MeshData::translate ( const MeshBase out_mesh,
std::vector< Number > &  data_values,
std::vector< std::string > &  data_names 
) const

Translates the nodal data contained in this object to data_values and data_names. These two vectors are particularly suitable for use with the MeshBase::write method that takes nodal data. E.g., the export method may be used for inspecting boundary conditions. A reference to the mesh for which the data should be written has to be provided. Note that this mesh has to contain the nodes for which this MeshData holds data. I.e., out_mesh may only refer to the MeshBase itself (that this MeshData belongs to), or its BoundaryMesh, cf. Mesh.

Definition at line 160 of file mesh_data.C.

References _active, _compatibility_mode, libMesh::libmesh_assert(), libMesh::MeshBase::n_nodes(), n_val_per_node(), libMesh::MeshBase::nodes_begin(), and libMesh::MeshBase::nodes_end().

163 {
165 
166  LOG_SCOPE("translate()", "MeshData");
167 
168  const unsigned int n_comp = this->n_val_per_node();
169 
170  // transfer our nodal data to a vector
171  // that may be written concurrently
172  // with the \p out_mesh.
173  {
174  // reserve memory for the nodal data
175  values.reserve(n_comp*out_mesh.n_nodes());
176 
177  // iterate over the mesh's nodes
178  MeshBase::const_node_iterator nodes_it = out_mesh.nodes_begin();
179  const MeshBase::const_node_iterator nodes_end = out_mesh.nodes_end();
180 
181  // Do not use the \p get_data() method, but the operator()
182  // method, since this returns by default a zero value,
183  // when there is no nodal data.
184  for (; nodes_it != nodes_end; ++nodes_it)
185  {
186  const Node * node = *nodes_it;
187 
188  for (unsigned int c= 0; c<n_comp; c++)
189  values.push_back(this->operator()(node, c));
190  }
191  }
192 
193 
194 
195  // Now we have the data, nicely stored in \p values.
196  // It remains to give names to the data, then write to
197  // file.
198  {
199  names.reserve(n_comp);
200 
201  // this naming scheme only works up to n_comp=100
202  // (at least for gmv-accepted variable names)
203  libmesh_assert_less (n_comp, 100);
204 
205  for (unsigned int n=0; n<n_comp; n++)
206  {
207  std::ostringstream name_buf;
208  name_buf << "bc_" << n;
209  names.push_back(name_buf.str());
210  }
211  }
212 }
libmesh_assert(remote_elem)
bool _compatibility_mode
Definition: mesh_data.h:614
unsigned int n_val_per_node() const
Definition: mesh_data.C:603
void libMesh::MeshData::write ( const std::string &  name)

Write mesh data to file named name. Guess format from the file extension.

Definition at line 282 of file mesh_data.C.

References _active, _compatibility_mode, _elem_id_map_closed, _node_id_map_closed, compatibility_mode(), libMesh::ENCODE, libMesh::err, libMesh::libmesh_assert(), libMesh::WRITE, write_unv(), and write_xdr().

283 {
284  LOG_SCOPE("write()", "MeshData");
285 
287 
288  // the id maps have to be closed before writing
289  // (note that in compatibility mode these are also true)
291 
292 #ifdef DEBUG
293  if (this->compatibility_mode())
294  libMesh::err << "WARNING: MeshData in compatibility mode. Node and element ids" << std::endl
295  << " written to file may differ from libMesh numbering" << std::endl
296  << " next time this file is read!" << std::endl;
297 #endif
298 
299  // Read the file based on extension
300  {
301  if (name.rfind(".xta") < name.size())
302  write_xdr (name, WRITE);
303 
304  else if (name.rfind(".xtr") < name.size())
305  write_xdr (name, ENCODE);
306 
307  else if (name.rfind(".unv") < name.size())
308  write_unv (name);
309 
310  else
311  libmesh_error_msg(" ERROR: Unrecognized file extension: " << name \
312  << "\n I understand the following:\n\n" \
313  << " *.xta -- Internal ASCII data format\n" \
314  << " *.xtr -- Internal binary data format\n" \
315  << " *.unv -- I-deas format");
316  }
317 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
bool _node_id_map_closed
Definition: mesh_data.h:575
libmesh_assert(remote_elem)
void write_xdr(const std::string &name, const XdrMODE mode=WRITE)
bool _elem_id_map_closed
Definition: mesh_data.h:593
bool _compatibility_mode
Definition: mesh_data.h:614
OStreamProxy err(std::cerr)
void write_unv(const std::string &file_name)
bool compatibility_mode() const
Definition: mesh_data.h:996
void libMesh::MeshData::write_unv ( const std::string &  file_name)
protected

Write nodal/element oriented data in UNV format, either to an ASCII file or to a gzip'ed ASCII file, using the C++ wrapper gzstream to zlib.h.

Definition at line 382 of file mesh_data_unv_support.C.

References _active, _compatibility_mode, _elem_data_closed, _elem_id_map_closed, _node_data_closed, _node_id_map_closed, libMesh::libmesh_assert(), and write_unv_implementation().

Referenced by write().

383 {
384  /*
385  * We better be active or in compatibility mode
386  */
387  libmesh_assert (this->_active || this->_compatibility_mode);
388 
389  /*
390  * make sure the id maps are ready
391  * and that we have data to write
392  */
395 
398 
399  if (file_name.rfind(".gz") < file_name.size())
400  {
401 #ifdef LIBMESH_HAVE_GZSTREAM
402  ogzstream out_stream(file_name.c_str());
403  this->write_unv_implementation (out_stream);
404 #else
405  libmesh_error_msg("ERROR: You must have the zlib.h header files and libraries to read and write compressed streams.");
406 #endif
407  return;
408 
409  }
410 
411  else
412  {
413  std::ofstream out_stream(file_name.c_str());
414  this->write_unv_implementation (out_stream);
415  return;
416  }
417 }
bool _node_id_map_closed
Definition: mesh_data.h:575
libmesh_assert(remote_elem)
bool _elem_id_map_closed
Definition: mesh_data.h:593
bool _compatibility_mode
Definition: mesh_data.h:614
bool _elem_data_closed
Definition: mesh_data.h:599
void write_unv_implementation(std::ostream &out_file)
bool _node_data_closed
Definition: mesh_data.h:581
void libMesh::MeshData::write_unv_implementation ( std::ostream &  out_file)
protected

Actual implementation of writing nodal/element oriented data in UNV format. This has to be decoupled from write_unv() in order to allow writing both .unv and .unv.gz files.

Definition at line 424 of file mesh_data_unv_support.C.

References _elem_data, _node_data, _unv_header, libMesh::MeshDataUnvHeader::data_type, libMesh::err, get_data(), has_data(), libMesh::libmesh_assert(), libmesh_nullptr, n_val_per_node(), node_to_foreign_id(), libMesh::MeshDataUnvHeader::nvaldc, and libMesh::MeshDataUnvHeader::write().

Referenced by write_unv().

425 {
426  /*
427  * This is the actual implementation of writing
428  * unv files, either as .unv or as .unv.gz file
429  */
430  if ( !out_file.good() )
431  libmesh_error_msg("ERROR: Output file not good.");
432 
433 
434  /*
435  * the beginning marker of the dataset block for
436  * nodal/element-associated data (not to be confused
437  * with _desired_dataset_label!)
438  */
439  const std::string _label_dataset_mesh_data = "2414";
440 
441  /*
442  * Currently this function handles only nodal data.
443  */
444  libmesh_assert (!_node_data.empty());
445 
446  if (!_elem_data.empty())
447  libMesh::err << "WARNING: MeshData currently only supports nodal data for Universal files."
448  << std::endl
449  << " Will proceed writing only nodal data, ignoring element data."
450  << std::endl;
451 
452 
453  /*
454  * Write the beginning of the dataset.
455  */
456  out_file << " -1\n"
457  << " "
458  << _label_dataset_mesh_data
459  << "\n";
460 
461  /*
462  * Write the header
463  */
465  {
466  /*
467  * create a header that holds at
468  * least sufficient data to specify
469  * what this data set currently holds.
470  *
471  * The empty constructor automatically
472  * takes care of \p dataset_location
473  * and \p data_type.
474  */
475  MeshDataUnvHeader my_header;
476 
477  /*
478  * It remains to set the correct nvaldc...
479  */
480  my_header.nvaldc = this->n_val_per_node();
481 
482  /*
483  * and the correct data type. By default
484  * only distinguish complex or real data.
485  */
486 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
487  my_header.data_type = 5;
488 #else
489  my_header.data_type = 2;
490 #endif
491 
492  /*
493  * write this default header, then let
494  * the UniquePtr go out of scope. This
495  * will take care of memory management.
496  */
497  my_header.write (out_file);
498  }
499 
500  else
501  {
502  /*
503  * make sure our nvaldc coincide.
504  */
505  if (this->n_val_per_node() != _unv_header->nvaldc)
506  {
507  libMesh::err << "WARNING: nvaldc=" << _unv_header->nvaldc
508  << " of attached MeshDataUnvHeader object not valid!" << std::endl
509  << " re-set nvaldc to " << this->n_val_per_node() << std::endl;
510  _unv_header->nvaldc = this->n_val_per_node();
511  }
512 
513 
514  /*
515  * only issue a warning when data_type does
516  * not coincide. Perhaps user provided some
517  * other header in order to convert complex
518  * to real...
519  */
520 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
521  const unsigned int my_data_type = 5;
522 #else
523  const unsigned int my_data_type = 2;
524 #endif
525  if (my_data_type != _unv_header->data_type)
526  {
527  libMesh::err << "WARNING: data_type=" << _unv_header->data_type
528  << " of attached MeshDataUnvHeader differs from" << std::endl
529  << " default value=" << my_data_type
530  << " Perhaps the user wanted this," << std::endl
531  << " so I use the value from the MeshDataUnvHeader."
532  << std::endl;
533  }
534  _unv_header->write (out_file);
535  }
536 
537 
538  /*
539  * Write the foreign node number and the respective data.
540  */
541  std::map<const Node *,
542  std::vector<Number> >::const_iterator nit = _node_data.begin();
543 
544  char buf[27];
545  for (; nit != _node_data.end(); ++nit)
546  {
547  const Node * node = (*nit).first;
548 
549  unsigned int f_n_id = node_to_foreign_id (node);
550  std::sprintf(buf, "%10u\n", f_n_id);
551  out_file << buf;
552 
553  /* since we are iterating over our own map, this libmesh_assert
554  * should never break...
555  */
556  libmesh_assert (this->has_data(node));
557 
558  // const reference to the nodal values
559  const std::vector<Number> & values = this->get_data(node);
560 
561  for (unsigned int v_cnt=0; v_cnt<values.size(); v_cnt++)
562  {
563 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
564  std::sprintf(buf, "%13.5E%13.5E", values[v_cnt].real(),
565  values[v_cnt].imag());
566  out_file << buf;
567 #else
568  std::sprintf(buf, "%13.5E",
569  static_cast<double>(values[v_cnt]));
570  out_file << buf;
571 #endif
572  }
573 
574  out_file << "\n";
575 
576 
577  }
578 
579  /*
580  * Write end of the dataset.
581  */
582  out_file << " -1\n";
583 }
const std::vector< Number > & get_data(const Node *node) const
Definition: mesh_data.h:862
bool has_data(const Node *node) const
Definition: mesh_data.h:848
libmesh_assert(remote_elem)
const class libmesh_nullptr_t libmesh_nullptr
unsigned int node_to_foreign_id(const Node *n) const
Definition: mesh_data.C:399
OStreamProxy err(std::cerr)
friend class MeshDataUnvHeader
Definition: mesh_data.h:624
MeshDataUnvHeader * _unv_header
Definition: mesh_data.h:619
unsigned int n_val_per_node() const
Definition: mesh_data.C:603
void write(std::ostream &out_file)
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
void libMesh::MeshData::write_xdr ( const std::string &  name,
const XdrMODE  mode = WRITE 
)
protected

Write nodal data in format comparable to the XDR format already known from Mesh. By default uses ASCII format, but may easily be changed setting mode to ENCODE.

This code implements the output of the MeshData object in XDR format. This warrants some documentation. The output consists of 8 sections:

1.) The name of the data stored, if provided (string)

2.) A switch whether real or complex data is stored (string)

3.) The number of nodes for which values are stored (unsigned int)

4.) The number of elements for which values are stored (unsigned int)

for each node

5.) The foreign node id (unsigned int)

6.) The actual values (vector of real/complex)

end node loop

for each element

7.) The foreign element id (unsigned int)

8.) The actual values (vector of real/complex)

end node loop

Note that the actual IO is handled through the Xdr class (to be renamed later?) which provides a uniform interface to both the XDR (eXternal Data Representation) interface and standard ASCII output. Thus this one section of code will write XDR or ASCII files with no changes.

1.)

Write the descriptive name

2.)

Write: either real or complex

3.)

Write the number of nodes for which data is there

4.)

Write the number of elements for which data is there

5.)

Write the foreign node id

6.)

the actual values for this node

7.)

Write the foreign element id

8.)

the actual values for this element

Definition at line 282 of file mesh_data_xdr_support.C.

References _data_descriptor, _elem_data, _elem_data_closed, _elem_id_map_closed, _node_data, _node_data_closed, _node_id_map_closed, libMesh::Xdr::data(), elem_to_foreign_id(), get_data(), has_data(), libMesh::libmesh_assert(), libMesh::MeshTools::n_elem(), and node_to_foreign_id().

Referenced by write().

284 {
323  /*
324  * make sure the id maps are ready
325  * and that we have data to write
326  */
329 
332 
333 
334  Xdr io(name, mode);
335 
336 
337  // all processors write the data in the same format
338  //const unsigned int proc_id = _mesh.processor_id();
339 
345  {
346  std::string desc = this->_data_descriptor;
347  io.data (desc, "# Data description");
348  }
349 
350 
351 
357  {
358 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
359  std::string desc = "COMPLEX";
360 #elif LIBMESH_USE_REAL_NUMBERS
361  std::string desc = "REAL";
362 #else
363  better_you_choke_this...
364 #endif
365  io.data (desc, "# type of values");
366  }
367 
368 
369 
375  {
376  unsigned int n_node =
377  cast_int<unsigned int>(this->_node_data.size());
378  io.data (n_node, "# No. of nodes for which data is stored");
379  }
380 
381 
387  {
388  unsigned int n_elem =
389  cast_int<unsigned int>(this->_elem_data.size());
390  io.data (n_elem, "# No. of elements for which data is stored");
391  }
392 
393 
394 
395 
396  std::map<const Node *,
397  std::vector<Number> >::const_iterator nit = _node_data.begin ();
398 
399  for (; nit != _node_data.end(); ++nit)
400  {
401  const Node * node = (*nit).first;
402 
408  {
409  unsigned int f_id = node_to_foreign_id (node);
410  io.data (f_id, "# Foreign node id");
411  }
412 
413 
419  {
420  /*
421  * since we are iterating over our @e own
422  * map, this libmesh_assert should never break...
423  */
424  libmesh_assert (this->has_data(node));
425 
426  const std::vector<Number> & values = this->get_data(node);
427 
428  /*
429  * copy the data to a local buf, since
430  * the Xdr class needs write access, even
431  * when only reading data
432  */
433  std::vector<Number> buf = values;
434  io.data (buf, "# Values");
435  }
436  }
437 
438 
439 
440 
441 
442 
443 
444  std::map<const Elem *,
445  std::vector<Number> >::const_iterator eit = _elem_data.begin ();
446 
447  for (; eit != _elem_data.end(); ++eit)
448  {
449  const Elem * elem = (*eit).first;
450 
456  {
457  unsigned int f_id = elem_to_foreign_id (elem);
458  io.data (f_id, "# Foreign element id");
459  }
460 
461 
467  {
468  /*
469  * since we are iterating over our @e own
470  * map, this libmesh_assert should never break...
471  */
472  libmesh_assert (this->has_data(elem));
473 
474  const std::vector<Number> & values = this->get_data(elem);
475 
476  /*
477  * copy the data to a local buf, since
478  * the Xdr class needs write access, even
479  * when only reading data
480  */
481  std::vector<Number> buf = values;
482  io.data (buf, "# Values");
483  }
484  }
485 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
bool _node_id_map_closed
Definition: mesh_data.h:575
const std::vector< Number > & get_data(const Node *node) const
Definition: mesh_data.h:862
bool has_data(const Node *node) const
Definition: mesh_data.h:848
libmesh_assert(remote_elem)
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
Definition: mesh_tools.C:669
bool _elem_id_map_closed
Definition: mesh_data.h:593
unsigned int node_to_foreign_id(const Node *n) const
Definition: mesh_data.C:399
bool _elem_data_closed
Definition: mesh_data.h:599
std::string _data_descriptor
Definition: mesh_data.h:515
unsigned int elem_to_foreign_id(const Elem *n) const
Definition: mesh_data.C:463
std::map< const Node *, std::vector< Number > > _node_data
Definition: mesh_data.h:525
std::map< const Elem *, std::vector< Number > > _elem_data
Definition: mesh_data.h:549
bool _node_data_closed
Definition: mesh_data.h:581

Friends And Related Function Documentation

friend class MeshDataUnvHeader
friend

Make the MeshDataUnvHeader class a friend.

Definition at line 624 of file mesh_data.h.

std::ostream& operator<< ( std::ostream &  os,
const MeshData m 
)
friend

Same as above, but allows you to use the stream syntax.

Definition at line 360 of file mesh_data.C.

361 {
362  m.print_info(os);
363  return os;
364 }

Member Data Documentation

bool libMesh::MeshData::_compatibility_mode
protected
std::string libMesh::MeshData::_data_descriptor
protected

Some name the user gave to the data when this object got activated

Definition at line 515 of file mesh_data.h.

Referenced by activate(), assign(), clear(), enable_compatibility_mode(), get_info(), read_tetgen(), read_xdr(), and write_xdr().

std::map<const Elem *, std::vector<Number> > libMesh::MeshData::_elem_data
protected
bool libMesh::MeshData::_elem_data_closed
protected

true when the element based data are properly initialized, false otherwise.

Definition at line 599 of file mesh_data.h.

Referenced by assign(), clear(), elem_initialized(), get_data(), has_data(), insert_elem_data(), insert_node_data(), n_elem_data(), n_val_per_elem(), operator()(), read_tetgen(), read_unv_implementation(), read_xdr(), write_unv(), and write_xdr().

std::map<const Elem *, unsigned int> libMesh::MeshData::_elem_id
protected

Maps element pointers to element labels in the foreign format.

Definition at line 556 of file mesh_data.h.

Referenced by add_foreign_elem_id(), assign(), close_foreign_id_maps(), elem_to_foreign_id(), enable_compatibility_mode(), and slim().

bool libMesh::MeshData::_elem_id_map_closed
protected

true when the mesh importer finished adding element-id maps, and the element-id maps exist. Note that these maps may be deleted through slim() to save memory. Then the data is still accessible through the Elem *, but the foreign element id's are lost.

Definition at line 593 of file mesh_data.h.

Referenced by add_foreign_elem_id(), assign(), close_foreign_id_maps(), elem_to_foreign_id(), enable_compatibility_mode(), foreign_id_to_elem(), insert_elem_data(), insert_node_data(), read(), read_unv(), read_xdr(), slim(), write(), write_unv(), and write_xdr().

std::map<unsigned int, const Elem *> libMesh::MeshData::_id_elem
protected

Maps foreign element labels to element pointers of the current mesh.

Definition at line 562 of file mesh_data.h.

Referenced by add_foreign_elem_id(), close_foreign_id_maps(), enable_compatibility_mode(), foreign_id_to_elem(), and slim().

std::map<unsigned int, const Node *> libMesh::MeshData::_id_node
protected

Maps foreign node ids to node pointers of the current mesh.

Definition at line 539 of file mesh_data.h.

Referenced by add_foreign_node_id(), assign(), close_foreign_id_maps(), enable_compatibility_mode(), foreign_id_to_node(), and slim().

const MeshBase& libMesh::MeshData::_mesh
protected

The mesh this object belongs to

Definition at line 509 of file mesh_data.h.

Referenced by assign(), foreign_id_to_elem(), foreign_id_to_node(), and read_xdr().

std::map<const Node *, std::vector<Number> > libMesh::MeshData::_node_data
protected

The map containing pointers to nodes in the mesh and the corresponding data.

Definition at line 525 of file mesh_data.h.

Referenced by assign(), clear(), get_data(), has_data(), insert_node_data(), n_node_data(), n_val_per_node(), node_data_begin(), node_data_end(), operator()(), read_tetgen(), read_unv_implementation(), read_xdr(), set_data(), write_unv_implementation(), and write_xdr().

bool libMesh::MeshData::_node_data_closed
protected

true when the nodal data are properly initialized, false otherwise.

Definition at line 581 of file mesh_data.h.

Referenced by assign(), clear(), get_data(), has_data(), insert_elem_data(), insert_node_data(), n_node_data(), n_val_per_node(), node_initialized(), operator()(), read_tetgen(), read_unv_implementation(), read_xdr(), write_unv(), and write_xdr().

std::map<const Node *, unsigned int> libMesh::MeshData::_node_id
protected

Maps node pointers to node numbers in the foreign format.

Definition at line 532 of file mesh_data.h.

Referenced by add_foreign_node_id(), assign(), close_foreign_id_maps(), enable_compatibility_mode(), node_to_foreign_id(), and slim().

bool libMesh::MeshData::_node_id_map_closed
protected

true when the mesh importer finished adding node-foreign-id maps, and the node-foreign-id maps exist. Note that these maps may be deleted through slim() to save memory. Then the data is still accessible through the Node * or Elem *, but the foreign id's are lost.

Definition at line 575 of file mesh_data.h.

Referenced by add_foreign_node_id(), assign(), close_foreign_id_maps(), enable_compatibility_mode(), foreign_id_to_node(), insert_elem_data(), insert_node_data(), node_to_foreign_id(), read(), read_unv(), read_xdr(), slim(), write(), write_unv(), and write_xdr().

MeshDataUnvHeader* libMesh::MeshData::_unv_header
protected

The header information of universal files.

Definition at line 619 of file mesh_data.h.

Referenced by assign(), get_unv_header(), read_unv_implementation(), set_unv_header(), and write_unv_implementation().


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