$extrastylesheet
#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 Node * | foreign_id_to_node (const unsigned int fid) const |
| const Elem * | foreign_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 MeshDataUnvHeader & | get_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) |
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.
Definition at line 58 of file mesh_data.h.
| 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 83 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 73 of file mesh_data.h.
| 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.
: _mesh (m), _data_descriptor (""), _node_id_map_closed (false), _node_data_closed (false), _elem_id_map_closed (false), _elem_data_closed (false), _active (false), _compatibility_mode (false), _unv_header (NULL) { // This class isn't actively maintained, doesn't work in parallel, // and usually isn't as good a solution as adding an additional // ExplicitSystem with appropriate data field(s). libmesh_deprecated(); }
| 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.
{
#ifdef DEBUG
if (_compatibility_mode)
libMesh::err << "WARNING: MeshData was in compatibility mode, now being activated."
<< std::endl;
#endif
_compatibility_mode = false;
_active = true;
_data_descriptor = descriptor;
}
| bool libMesh::MeshData::active | ( | ) | const [inline] |
true when this object is active and working. Use activate() to bring this object alive. Definition at line 998 of file mesh_data.h.
References _active.
Referenced by libMesh::UNVIO::elements_out(), get_info(), libMesh::UNVIO::nodes_out(), libMesh::LegacyXdrIO::read_mesh(), slim(), and libMesh::UNVIO::write_implementation().
{
return _active;
}
| 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 1056 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(), libMesh::UNVIO::elements_in(), and libMesh::LegacyXdrIO::read_mesh().
{
if (_active)
{
libmesh_assert (!_elem_id_map_closed);
libmesh_assert(elem);
libmesh_assert (_elem_id.find(elem) == _elem_id.end());
libmesh_assert (_id_elem.find(foreign_elem_id) == _id_elem.end());
_elem_id.insert(std::make_pair(elem, foreign_elem_id));
_id_elem.insert(std::make_pair(foreign_elem_id, elem));
}
}
| 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 1030 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(), libMesh::UNVIO::nodes_in(), libMesh::VTKIO::read(), and libMesh::LegacyXdrIO::read_mesh().
{
if (_active)
{
libmesh_assert (!_node_id_map_closed);
libmesh_assert(node);
libmesh_assert (_node_id.find(node) == _node_id.end());
libmesh_assert (_id_node.find(foreign_node_id) == _id_node.end());
/*
* _always_ insert in _id_node and _node_id. If we would
* use the mesh.node(unsigned int) method or the node.id()
* to get Node* and unsigned int, respectively, we would not
* be safe any more when the mesh gets refined or re-numbered
* within libMesh. And we could get in big trouble that would
* be hard to find when importing data _after_ having refined...
*/
_node_id.insert(std::make_pair(node, foreign_node_id));
_id_node.insert(std::make_pair(foreign_node_id, node));
}
}
| 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 668 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().
{
this->_data_descriptor = omd._data_descriptor;
this->_node_id_map_closed = omd._node_id_map_closed;
this->_node_data_closed = omd._node_data_closed;
// we have to be able to modify our elem id maps
libmesh_assert (!this->_elem_id_map_closed);
this->_elem_data_closed = omd._elem_data_closed;
this->_active = omd._active;
this->_compatibility_mode = omd._compatibility_mode;
// this is ok because we do not manage the UnvHeader
// in terms of memory, but only hold a pointer to it...
this->_unv_header = omd._unv_header;
// Now copy the foreign id maps -- but only for the
// nodes. The nodes of the boundary mesh are actually
// nodes of the volume mesh.
this->_node_id = omd._node_id;
this->_id_node = omd._id_node;
// The element vector of the boundary mesh contains elements
// that are new, and there _cannot_ be any associated
// foreign id in the maps. Therefore, fill the maps with
// the libMesh id's. But only when the other MeshData
// has element ids.
if ((this->_active) && (omd._elem_id.size() != 0))
{
MeshBase::const_element_iterator elem_it = _mesh.elements_begin();
const MeshBase::const_element_iterator elem_end = _mesh.elements_end();
for (; elem_it != elem_end; ++elem_it)
{
const Elem* elem = *elem_it;
this->add_foreign_elem_id(elem, elem->id());
}
}
// now we can safely assign omd's value
this->_elem_id_map_closed = omd._elem_id_map_closed;
// and finally the node- and element-associated data
this->_node_data = omd._node_data;
this->_elem_data = omd._elem_data;
}
| 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().
{
_data_descriptor = "";
_node_data.clear();
_elem_data.clear();
_node_data_closed = false;
_elem_data_closed = false;
}
Signal to this object that the mesh importer finished adding node and element foreign-id maps.
Definition at line 219 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(), libMesh::LegacyXdrIO::read_mesh(), and libMesh::TetGenIO::read_nodes_and_elem().
{
if (_active)
{
libmesh_assert (!_elem_id.empty());
libmesh_assert (!_id_elem.empty());
libmesh_assert (!_node_id.empty());
libmesh_assert (!_id_node.empty());
_elem_id_map_closed = true;
_node_id_map_closed = true;
}
}
| bool libMesh::MeshData::compatibility_mode | ( | ) | const [inline] |
true when this object is in compatibility mode. See enable_compatibility_mode() for details. Definition at line 1006 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().
{
return _compatibility_mode;
}
| 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 980 of file mesh_data.h.
References _elem_data.
{
return _elem_data.begin();
}
| 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 988 of file mesh_data.h.
References _elem_data.
{
return _elem_data.end();
}
| bool libMesh::MeshData::elem_initialized | ( | ) | const [inline] |
true when this object is properly initialized and ready for use for element associated data, false otherwise. Definition at line 1014 of file mesh_data.h.
References _active, and _elem_data_closed.
Referenced by get_info().
{
return (_active && _elem_data_closed);
}
| unsigned int libMesh::MeshData::elem_to_foreign_id | ( | const Elem * | n | ) | const |
Elem* maps to. Definition at line 468 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().
{
libmesh_assert(e);
if (_active)
{
// when active, use our _id_elem map
libmesh_assert (_elem_id_map_closed);
// look it up in the map
std::map<const Elem*,
unsigned int>::const_iterator pos = _elem_id.find(e);
if (pos == _elem_id.end())
libmesh_error_msg("ERROR: No foreign id stored for the element with the libMesh id = " << e->id());
else
return pos->second;
}
else if (_compatibility_mode)
// when only in compatibility mode,
// return libMesh's element id
return e->id();
libmesh_error_msg("We'll never get here!");
return 0;
}
| 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().
{
if (!_active)
{
_compatibility_mode = true;
_active = false;
// do as if the id maps are already closed
_node_id_map_closed = true;
_elem_id_map_closed = true;
_data_descriptor = descriptor;
// we can safely clear the id maps
_node_id.clear();
_id_node.clear();
_elem_id.clear();
_id_elem.clear();
}
#ifdef DEBUG
else
libMesh::err << "WARNING: MeshData was in compatibility mode, now being activated."
<< std::endl;
#endif
}
| const Elem * libMesh::MeshData::foreign_id_to_elem | ( | const unsigned int | fid | ) | const |
Elem* that this foreign id maps to. Definition at line 439 of file mesh_data.C.
References _active, _compatibility_mode, _elem_id_map_closed, _id_elem, _mesh, libMesh::MeshBase::elem(), and libMesh::libmesh_assert().
Referenced by read_tetgen(), and read_xdr().
{
if (_active)
{
// when active, use our _id_elem map
libmesh_assert (_elem_id_map_closed);
std::map<unsigned int,
const Elem*>::const_iterator pos = _id_elem.find(fid);
if (pos == _id_elem.end())
libmesh_error_msg("ERROR: Have no Elem* associated with the foreign id = " << fid);
else
return pos->second;
}
else if (_compatibility_mode)
// when only in compatibility mode,
// return element using the libMesh id
return this->_mesh.elem(fid);
libmesh_error_msg("We'll never get here!");
return NULL;
}
| const Node * libMesh::MeshData::foreign_id_to_node | ( | const unsigned int | fid | ) | const |
Node* that this foreign id maps to. Definition at line 374 of file mesh_data.C.
References _active, _compatibility_mode, _id_node, _mesh, _node_id_map_closed, libMesh::libmesh_assert(), and libMesh::MeshBase::node_ptr().
Referenced by read_tetgen(), read_unv_implementation(), and read_xdr().
{
if (_active)
{
// when active, use our _id_node map
libmesh_assert (_node_id_map_closed);
std::map<unsigned int,
const Node*>::const_iterator pos = _id_node.find(fid);
if (pos == _id_node.end())
libmesh_error_msg("ERROR: Have no Node* associated with the foreign id = " << fid);
else
return pos->second;
}
else if (_compatibility_mode)
// when only in compatibility mode,
// return the node stored in the MeshBase
// under its current id
return this->_mesh.node_ptr(fid);
libmesh_error_msg("We'll never get here!");
return NULL;
}
| const std::vector< Number > & libMesh::MeshData::get_data | ( | const Node * | node | ) | const [inline] |
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 872 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().
{
libmesh_assert (_active || _compatibility_mode);
libmesh_assert (_node_data_closed);
std::map<const Node*,
std::vector<Number> >::const_iterator pos = _node_data.find(node);
#ifdef DEBUG
if (pos == _node_data.end())
libmesh_error_msg("ERROR: No data for this node. Use has_data() first!");
#endif
return pos->second;
}
| const std::vector< Number > & libMesh::MeshData::get_data | ( | const Elem * | elem | ) | const [inline] |
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 952 of file mesh_data.h.
References _active, _compatibility_mode, _elem_data, _elem_data_closed, and libMesh::libmesh_assert().
{
libmesh_assert (_active || _compatibility_mode);
libmesh_assert (_elem_data_closed);
std::map<const Elem*,
std::vector<Number> >::const_iterator pos = _elem_data.find(elem);
#ifdef DEBUG
if (pos == _elem_data.end())
libmesh_error_msg("ERROR: No data for this element. Use has_data() first!");
#endif
return pos->second;
}
| std::string libMesh::MeshData::get_info | ( | ) | const |
Definition at line 327 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().
{
std::ostringstream oss;
if (this->active() || this->compatibility_mode())
{
oss << " MeshData Information:\n";
if (this->active())
oss << " object activated.\n";
if (this->compatibility_mode())
oss << " object in compatibility mode.\n";
if (this->_data_descriptor != "")
oss << " descriptor=" << this->_data_descriptor << '\n';
if (this->elem_initialized())
oss << " Element associated data initialized.\n"
<< " n_val_per_elem()=" << this->n_val_per_elem() << '\n'
<< " n_elem_data()=" << this->n_elem_data() << '\n';
if (this->node_initialized())
oss << " Node associated data initialized.\n"
<< " n_val_per_node()=" << this->n_val_per_node() << '\n'
<< " n_node_data()=" << this->n_node_data() << '\n';
}
else
oss << " MeshData neither active nor in compatibility mode.\n";
return oss.str();
}
| const MeshDataUnvHeader & libMesh::MeshData::get_unv_header | ( | ) | const [inline] |
Read access to the MeshDataUnvHeader data structure.
Definition at line 1073 of file mesh_data.h.
References _unv_header, and libMesh::libmesh_assert().
{
libmesh_assert(this->_unv_header);
return *this->_unv_header;
}
| bool libMesh::MeshData::has_data | ( | const Node * | node | ) | const [inline] |
true when the node node has data, false otherwise. Definition at line 858 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().
{
libmesh_assert (_active || _compatibility_mode);
libmesh_assert (_node_data_closed);
std::map<const Node*,
std::vector<Number> >::const_iterator pos = _node_data.find(node);
return (pos != _node_data.end());
}
| bool libMesh::MeshData::has_data | ( | const Elem * | elem | ) | const [inline] |
true when the element elem has data, false otherwise. Definition at line 938 of file mesh_data.h.
References _active, _compatibility_mode, _elem_data, _elem_data_closed, and libMesh::libmesh_assert().
{
libmesh_assert (_active || _compatibility_mode);
libmesh_assert (_elem_data_closed);
std::map<const Elem*,
std::vector<Number> >::const_iterator pos = _elem_data.find(elem);
return (pos != _elem_data.end());
}
| 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* point 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 558 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().
{
libmesh_assert (this->_active || this->_compatibility_mode);
// these are also true in compatibility mode
libmesh_assert (this->_elem_id_map_closed);
if (this->_elem_data_closed)
libmesh_error_msg("ERROR: Element data already closed! Use clear() first!");
libmesh_assert (this->_elem_data.empty());
#ifdef DEBUG
std::map<const Elem*,
std::vector<Number> >::const_iterator ed_pos = ed.begin();
std::map<const Elem*,
std::vector<Number> >::const_iterator ed_end = ed.end();
// Compare entity-by-entity that the
// sizes of the std::vector's are identical.
const std::size_t reference_length = (*ed_pos).second.size();
++ed_pos;
for (; ed_pos != ed_end; ++ed_pos)
if ( (*ed_pos).second.size() != reference_length)
libmesh_error_msg("ERROR: Size mismatch.");
#endif
// copy over
_elem_data = ed;
// we may freely trash the ed
ed.clear();
// close elem data
this->_elem_data_closed = true;
// if user wants to, then close node data, too
if (close_node_data)
{
libmesh_assert((this->_node_id_map_closed));
this->_node_data_closed = true;
}
}
| 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 502 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().
{
libmesh_assert (this->_active || this->_compatibility_mode);
// these are also true in compatibility mode
libmesh_assert (this->_node_id_map_closed);
if (this->_node_data_closed)
libmesh_error_msg("ERROR: Nodal data already closed! Use clear() first!");
libmesh_assert (this->_node_data.empty());
#ifdef DEBUG
std::map<const Node*,
std::vector<Number> >::const_iterator nd_pos = nd.begin();
std::map<const Node*,
std::vector<Number> >::const_iterator nd_end = nd.end();
// Compare entity-by-entity that the
// sizes of the std::vector's are identical.
// For this, simply take the length of the 0th
// entry as reference length, and compare this
// with the length of the 1st, 2nd...
libmesh_assert (nd_pos != nd_end);
const std::size_t reference_length = (*nd_pos).second.size();
// advance, so that we compare with the 1st
++nd_pos;
for (; nd_pos != nd_end; ++nd_pos)
if ( (*nd_pos).second.size() != reference_length)
libmesh_error_msg("ERROR: Size mismatch.");
#endif
// copy over
_node_data = nd;
// we may freely trash the nd
nd.clear();
// close node data
this->_node_data_closed = true;
// if user wants to, then close elem data, too
if (close_elem_data)
{
libmesh_assert((this->_elem_id_map_closed));
this->_elem_data_closed = true;
}
}
| dof_id_type libMesh::MeshData::n_elem_data | ( | ) | const |
MeshData has data stored. Definition at line 657 of file mesh_data.C.
References _active, _compatibility_mode, _elem_data, _elem_data_closed, and libMesh::libmesh_assert().
Referenced by get_info().
{
libmesh_assert (this->_active || this->_compatibility_mode);
libmesh_assert (this->_elem_data_closed);
return cast_int<dof_id_type>(_elem_data.size());
}
| dof_id_type libMesh::MeshData::n_node_data | ( | ) | const |
MeshData has data stored. Definition at line 627 of file mesh_data.C.
References _active, _compatibility_mode, _node_data, _node_data_closed, and libMesh::libmesh_assert().
Referenced by get_info().
{
libmesh_assert (this->_active || this->_compatibility_mode);
libmesh_assert (this->_node_data_closed);
return cast_int<dof_id_type>(this->_node_data.size());
}
| unsigned int libMesh::MeshData::n_val_per_elem | ( | ) | const |
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 638 of file mesh_data.C.
References _active, _compatibility_mode, _elem_data, _elem_data_closed, and libMesh::libmesh_assert().
Referenced by get_info().
{
libmesh_assert (this->_active || this->_compatibility_mode);
libmesh_assert (this->_elem_data_closed);
if (!_elem_data.empty())
{
std::map<const Elem*,
std::vector<Number> >::const_iterator pos = _elem_data.begin();
libmesh_assert (pos != _elem_data.end());
return cast_int<unsigned int>(pos->second.size());
}
else
return 0;
}
| unsigned int libMesh::MeshData::n_val_per_node | ( | ) | const |
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 608 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().
{
libmesh_assert (this->_active || this->_compatibility_mode);
libmesh_assert (this->_node_data_closed);
if (!this->_node_data.empty())
{
std::map<const Node*,
std::vector<Number> >::const_iterator pos = _node_data.begin();
libmesh_assert (pos != _node_data.end());
return cast_int<unsigned int>(pos->second.size());
}
else
return 0;
}
| 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 900 of file mesh_data.h.
References _node_data.
{
return _node_data.begin();
}
| 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 908 of file mesh_data.h.
References _node_data.
{
return _node_data.end();
}
| bool libMesh::MeshData::node_initialized | ( | ) | const [inline] |
true when this object is properly initialized and ready for use for nodal data, false otherwise. Definition at line 1022 of file mesh_data.h.
References _active, and _node_data_closed.
Referenced by get_info().
{
return (_active && _node_data_closed);
}
| unsigned int libMesh::MeshData::node_to_foreign_id | ( | const Node * | n | ) | const |
Node* maps to. Definition at line 404 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().
{
libmesh_assert(n);
if (_active)
{
// when active, use our _node_id map
libmesh_assert (_node_id_map_closed);
// look it up in the map
std::map<const Node*,
unsigned int>::const_iterator pos = _node_id.find(n);
if (pos == _node_id.end())
libmesh_error_msg("ERROR: No foreign id stored for the node with the libMesh id = " << n->id());
else
return pos->second;
}
else if (_compatibility_mode)
// when only in compatibility mode,
// return libMesh's node id
return n->id();
libmesh_error_msg("We'll never get here!");
return 0;
}
value (defaults to 0) associated with node node. Returns libMesh::zero when there is no such node in the map. Definition at line 838 of file mesh_data.h.
References _active, _compatibility_mode, _node_data, _node_data_closed, libMesh::libmesh_assert(), and libMesh::zero.
{
libmesh_assert (_active || _compatibility_mode);
libmesh_assert (_node_data_closed);
std::map<const Node*,
std::vector<Number> >::const_iterator pos = _node_data.find(node);
if (pos == _node_data.end())
return libMesh::zero;
// we only get here when pos != _node_data.end()
libmesh_assert_less (i, pos->second.size());
return pos->second[i];
}
value (defaults to 0) associated with element elem. Returns libMesh::zero when there is no data for elem in the map. Definition at line 918 of file mesh_data.h.
References _active, _compatibility_mode, _elem_data, _elem_data_closed, libMesh::libmesh_assert(), and libMesh::zero.
{
libmesh_assert (_active || _compatibility_mode);
libmesh_assert (_elem_data_closed);
std::map<const Elem*,
std::vector<Number> >::const_iterator pos = _elem_data.find(elem);
if (pos == _elem_data.end())
return libMesh::zero;
// we only get here when pos != _elem_data.end()
libmesh_assert_less (i, pos->second.size());
return pos->second[i];
}
| void libMesh::MeshData::print_info | ( | std::ostream & | os = libMesh::out | ) | const |
Prints relevant information about the mesh.
Definition at line 358 of file mesh_data.C.
References get_info().
Referenced by libMesh::operator<<().
{
os << this->get_info()
<< std::endl;
}
| 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 237 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(), read_xdr(), and libMesh::START_LOG().
{
START_LOG("read()", "MeshData");
libmesh_assert (_active || _compatibility_mode);
// the id maps have to be closed before reading
// (note that in compatibility mode these are also true)
libmesh_assert (_elem_id_map_closed && _node_id_map_closed);
#ifdef DEBUG
if (this->compatibility_mode())
libMesh::err << "WARNING: MeshData in compatibility mode, node and element ids" << std::endl
<< " stored in file may be totally different from libMesh ids!" << std::endl;
#endif
// Read the file based on extension. We let all processors read the
// data because it would be inaccurate to let only one processor
// have it and we're too lazy to code up a proper parallel read or
// read+broadcast right now.
if (name.rfind(".xta") < name.size())
this->read_xdr (name, READ);
else if (name.rfind(".xtr") < name.size())
this->read_xdr (name, DECODE);
else if (name.rfind(".unv") < name.size())
this->read_unv (name);
else if ((name.rfind(".node") < name.size()) ||
(name.rfind(".ele") < name.size()))
this->read_tetgen (name);
else
libmesh_error_msg(" ERROR: Unrecognized file extension: " << name \
<< "\n I understand the following:\n\n" \
<< " *.xta -- Internal ASCII data format\n" \
<< " *.xtr -- Internal binary data format\n" \
<< " *.unv -- I-deas format");
STOP_LOG("read()", "MeshData");
}
| 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().
{
std::string name_node, name_ele, dummy;
std::string desc = name;
// Check name for *.node or *.ele extension.
// Set std::istream for node_stream and ele_stream.
if (name.rfind(".node") < name.size())
{
name_node = name;
dummy = name;
std::size_t position = dummy.rfind(".node");
name_ele = dummy.replace(position, 5, ".ele");
desc.erase(position);
}
else if (name.rfind(".ele") < name.size())
{
name_ele = name;
dummy = name;
std::size_t position = dummy.rfind(".ele");
name_node = dummy.replace(position, 4, ".node");
desc.erase(position);
}
else
libmesh_error_msg("ERROR: Unrecognized file name: " << name);
// Set the streams from which to read in.
std::ifstream node_stream (name_node.c_str());
std::ifstream ele_stream (name_ele.c_str());
if ( !node_stream.good() || !ele_stream.good() )
libmesh_error_msg("ERROR: One or both Input file(s) not good.\n" \
<< "Error opening files " \
<< name_node \
<< " and " \
<< name_ele);
// Set the descriptive name.
// TetGen won't give a name, so we use the filename.
this->_data_descriptor = desc;
//--------------------------------------------------
// Read in the data associated with the nodes.
{
unsigned int n_node=0, f_n_id=0, nAttri=0, BoundMark=0;
Real dummy_val=0.0;
std::vector<Number> AttriValue;
// Read the parameters from the node_stream.
node_stream >> n_node // Read the number of nodes
>> dummy_val // Read the dimension
>> nAttri // Read the number of attributes
>> BoundMark; // (0 or 1) boundary markers are in the stream or not.
// Resize the values vector.
AttriValue.resize(nAttri);
for (unsigned int i=0; i<n_node; i++)
{
node_stream >> f_n_id;
// Read the nodal coordinates for this node into dummy_val,
// since we don't need them.
for (unsigned int j=0; j<3; j++)
node_stream >> dummy_val;
// Read the attributes from the stream.
for (unsigned int j=0; j<nAttri; j++)
node_stream >> AttriValue[j];
// Read boundary marker if BoundaryMarker=1.
if (BoundMark == 1)
node_stream >> dummy_val;
// For the foreign node id locate the Node*.
const Node* node = foreign_id_to_node(f_n_id);
// Insert this node and the values in our _node_data.
_node_data.insert (std::make_pair(node, AttriValue));
}
}
//--------------------------------------------------
// Read in the data associated with the elements.
{
unsigned int n_elem, f_e_id, n_nodes, nAttri=0;
Real dummy_val=0.0;
std::vector<Number> AttriValue;
// Read the parameters from the ele_stream.
ele_stream >> n_elem // Read the number of tetrahedrons
>> n_nodes // Read the points per tetrahedron
>> nAttri; // Read the number of attributes
// Resize the values vector.
AttriValue.resize(nAttri);
for (unsigned int i=0; i<n_elem; i++)
{
ele_stream >> f_e_id;
// For the number of nodes for this element read them into dummy_val,
// since we don't need them.
for (unsigned int n=0; n<n_nodes; n++)
ele_stream >> dummy_val;
// Read the attributes from the stream.
for (unsigned int j=0; j<nAttri; j++)
ele_stream >> AttriValue[j];
// For the foreign elem id locate the Elem*.
const Elem* elem = foreign_id_to_elem(f_e_id);
// Insert this elem and the values in our _elem_data.
_elem_data.insert (std::make_pair(elem, AttriValue));
}
}
//--------------------------------------------------
// Finished reading. Now ready for use.
this->_node_data_closed = true;
this->_elem_data_closed = true;
node_stream.close();
ele_stream.close();
}
| 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().
{
/*
* we should better be active or in compatibility mode
*/
libmesh_assert (this->_active || this->_compatibility_mode);
/*
* When reading data, make sure the id maps are ok
*/
libmesh_assert (this->_node_id_map_closed);
libmesh_assert (this->_elem_id_map_closed);
/*
* clear the data, but keep the id maps
*/
this->clear();
/*
* We can read either ".unv", or ".unv.gz"
* files, provided zlib.h is there
*/
if (file_name.rfind(".gz") < file_name.size())
{
#ifdef LIBMESH_HAVE_GZSTREAM
igzstream in_stream(file_name.c_str());
this->read_unv_implementation (in_stream);
#else
libmesh_error_msg("ERROR: You must have the zlib.h header files and libraries to read and write compressed streams.");
#endif
return;
}
else
{
std::ifstream in_stream(file_name.c_str());
this->read_unv_implementation (in_stream);
return;
}
}
| 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::MeshDataUnvHeader::need_D_to_e(), libMesh::MeshDataUnvHeader::nvaldc, libMesh::MeshDataUnvHeader::read(), and libMesh::Real.
Referenced by read_unv().
{
/*
* This is the actual implementation of
* reading in UNV format. This enables
* to read either through the conventional
* C++ stream, or through a stream that
* allows to read .gz'ed files.
*/
if ( !in_file.good() )
libmesh_error_msg("ERROR: Input file not good.");
const std::string _label_dataset_mesh_data = "2414";
/*
* locate the beginning of data set
* and read it.
*/
{
std::string olds, news;
while (true)
{
in_file >> olds >> news;
/*
* Yes, really dirty:
*
* When we found a dataset, and the user does
* not want this dataset, we jump back here
*/
go_and_find_the_next_dataset:
/*
* a "-1" followed by a number means the beginning of a dataset
* stop combing at the end of the file
*/
while( ((olds != "-1") || (news == "-1") ) && !in_file.eof() )
{
olds = news;
in_file >> news;
}
if(in_file.eof())
break;
/*
* if beginning of dataset
*/
if (news == _label_dataset_mesh_data)
{
/*
* Now read the data of interest.
* Start with the header. For
* explanation of the variable
* dataset_location, see below.
*/
unsigned int dataset_location;
/*
* the type of data (complex, real,
* float, double etc, see below)
*/
unsigned int data_type;
/*
* the number of floating-point values per entity
*/
unsigned int NVALDC;
/*
* If there is no MeshDataUnvHeader object
* attached
*/
if (_unv_header==NULL)
{
/*
* Ignore the first lines that stand for
* analysis dataset label and name.
*/
for(unsigned int i=0; i<3; i++)
in_file.ignore(256,'\n');
/*
* Read the dataset location, where
* 1: Data at nodes
* 2: Data on elements
* other sets are currently not supported.
*/
in_file >> dataset_location;
/*
* Ignore five ID lines.
*/
for(unsigned int i=0; i<6; i++)
in_file.ignore(256,'\n');
/*
* These data are all of no interest to us...
*/
unsigned int model_type,
analysis_type,
data_characteristic,
result_type;
/*
* Read record 9.
*/
in_file >> model_type // not used here
>> analysis_type // not used here
>> data_characteristic // not used here
>> result_type // not used here
>> data_type
>> NVALDC;
/*
* Ignore record 10 and 11
* (Integer analysis type specific data).
*/
for (unsigned int i=0; i<3; i++)
in_file.ignore(256,'\n');
/*
* Ignore record 12 and record 13. Since there
* exist UNV files with 'D' instead of 'e' as
* 10th-power char, it is safer to use a string
* to read the dummy reals.
*/
{
std::string dummy_Real;
for (unsigned int i=0; i<12; i++)
in_file >> dummy_Real;
}
}
else
{
/*
* the read() method returns false when
* the user wanted a special header, and
* when the current header is _not_ the correct
* header
*/
if (_unv_header->read(in_file))
{
dataset_location = _unv_header->dataset_location;
NVALDC = _unv_header->nvaldc;
data_type = _unv_header->data_type;
}
else
{
/*
* This is not the correct header. Go
* and find the next. For this to
* work correctly, shift to the
* next line, so that the "-1"
* disappears from olds
*/
olds = news;
in_file >> news;
/*
* No good style, i know...
*/
goto go_and_find_the_next_dataset;
}
}
/*
* Check the location of the dataset.
*/
if (dataset_location != 1)
libmesh_error_msg("ERROR: Currently only Data at nodes is supported.");
/*
* Now get the foreign node id number and the respective nodal data.
*/
int f_n_id;
std::vector<Number> values;
while(true)
{
in_file >> f_n_id;
/*
* if node_nr = -1 then we have reached the end of the dataset.
*/
if (f_n_id==-1)
break;
/*
* Resize the values vector (usually data in three
* principle directions, i.e. NVALDC = 3).
*/
values.resize(NVALDC);
/*
* Read the meshdata for the respective node.
*/
for (unsigned int data_cnt=0; data_cnt<NVALDC; data_cnt++)
{
/*
* Check what data type we are reading.
* 2,4: Real
* 5,6: Complex
* other data types are not supported yet.
* As again, these floats may also be written
* using a 'D' instead of an 'e'.
*/
if (data_type == 2 || data_type == 4)
{
std::string buf;
in_file >> buf;
MeshDataUnvHeader::need_D_to_e(buf);
#ifdef LIBMESH_USE_COMPLEX_NUMBERS
values[data_cnt] = Complex(std::atof(buf.c_str()), 0.);
#else
values[data_cnt] = std::atof(buf.c_str());
#endif
}
else if(data_type == 5 || data_type == 6)
{
#ifdef LIBMESH_USE_COMPLEX_NUMBERS
Real re_val, im_val;
std::string buf;
in_file >> buf;
if (MeshDataUnvHeader::need_D_to_e(buf))
{
re_val = std::atof(buf.c_str());
in_file >> buf;
MeshDataUnvHeader::need_D_to_e(buf);
im_val = std::atof(buf.c_str());
}
else
{
re_val = std::atof(buf.c_str());
in_file >> im_val;
}
values[data_cnt] = Complex(re_val,im_val);
#else
libmesh_error_msg("ERROR: Complex data only supported when libMesh is configured with --enable-complex!");
#endif
}
else
libmesh_error_msg("ERROR: Data type not supported.");
} // end loop data_cnt
/*
* Add the values vector to the MeshData data structure.
*/
const Node* node = foreign_id_to_node(f_n_id);
_node_data.insert (std::make_pair(node, values));
} // while(true)
}
else
{
/*
* all other datasets are ignored
*/
}
}
}
/*
* finished reading. Ready for use, provided
* there was any data contained in the file.
*/
libmesh_assert ((this->_node_data.size() != 0) || (this->_elem_data.size() != 0));
this->_node_data_closed = true;
this->_elem_data_closed = true;
}
| 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().
{
// we should better be active or in compatibility mode
libmesh_assert (_active || _compatibility_mode);
// make sure the id maps are ready
libmesh_assert (_node_id_map_closed);
libmesh_assert (_elem_id_map_closed);
this->clear();
Xdr io(name, mode);
/*
* all processors read the data in the same format,
* but only the processor that owns the element stores
* element-associated data. For nodes, i haven't come
* up with such asmart idea, yet... :-P
*/
const unsigned int proc_id = _mesh.processor_id();
{
std::string desc = "";
io.data (desc);
this->_data_descriptor = desc;
}
{
std::string vtype="";
io.data (vtype);
#ifdef LIBMESH_USE_COMPLEX_NUMBERS
if (vtype != "COMPLEX")
libmesh_error_msg("ERROR: File does not contain complex-valued data!");
#elif LIBMESH_USE_REAL_NUMBERS
if (vtype != "REAL")
libmesh_error_msg("ERROR: File does not contain real-valued data!");
#else
/*
* What number type is this?
*/
libmesh_error_msg("Must be using either real or complex numbers!");
#endif
}
unsigned int n_node = 0;
io.data (n_node);
unsigned int n_elem = 0;
io.data (n_elem);
#ifdef DEBUG
std::size_t previous_values_size = 0;
#endif
for (unsigned int n_cnt=0; n_cnt < n_node; n_cnt++)
{
unsigned int f_id = 0;
io.data (f_id);
const Node* node = foreign_id_to_node(f_id);
{
std::vector<Number> values;
io.data (values);
#ifdef DEBUG
/*
* make sure the size of the values vectors
* are identical for all nodes
*/
if (n_cnt == 0)
previous_values_size = values.size();
else
{
if (previous_values_size != values.size())
libmesh_error_msg("ERROR: Size mismatch for n_cnt = " << n_cnt);
}
#endif
_node_data.insert (std::make_pair(node, values));
}
}
#ifdef DEBUG
previous_values_size = 0;
#endif
for (unsigned int n_cnt=0; n_cnt < n_elem; n_cnt++)
{
unsigned int f_id = 0;
io.data (f_id);
const Elem* elem = foreign_id_to_elem(f_id);
{
std::vector<Number> values;
io.data (values);
#ifdef DEBUG
/*
* make sure the size of the values vectors
* are identical for all elements
*/
if (n_cnt == 0)
previous_values_size = values.size();
else
{
if (previous_values_size != values.size())
libmesh_error_msg("ERROR: Size mismatch for n_cnt = " << n_cnt);
}
#endif
if (elem->processor_id() == proc_id)
_elem_data.insert (std::make_pair(elem, values));
}
}
/*
* finished reading. Now ready for use, provided
* there was any data contained in the file.
*/
libmesh_assert ((this->_node_data.size() != 0) || (this->_elem_data.size() != 0));
this->_node_data_closed = true;
this->_elem_data_closed = true;
}
| 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 891 of file mesh_data.h.
References _node_data.
{
this->_node_data[node] = val;
}
| 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 971 of file mesh_data.h.
References _elem_data.
{
this->_elem_data[elem] = val;
}
| void libMesh::MeshData::set_unv_header | ( | MeshDataUnvHeader * | unv_header | ) | [inline] |
Set the MeshDataUnvHeader data structure that will be used for output.
Definition at line 1081 of file mesh_data.h.
References _unv_header, and libMesh::libmesh_assert().
{
libmesh_assert(unv_header);
this->_unv_header = unv_header;
}
| 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 better 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().
{
if (this->active())
{
if (node_id_map)
{
// dumb check
libmesh_assert (_node_id_map_closed);
_node_id_map_closed = false;
_node_id.clear();
_id_node.clear();
}
if (elem_id_map)
{
// dumb check
libmesh_assert (_elem_id_map_closed);
_elem_id_map_closed = false;
_elem_id.clear();
_id_elem.clear();
}
}
#ifdef DEBUG
else if (this->compatibility_mode())
{
libMesh::err << "WARNING: No need for MeshData::slim() in compatibility mode." << std::endl;
}
#endif
}
| 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(), libMesh::MeshBase::nodes_end(), and libMesh::START_LOG().
{
libmesh_assert (_active || _compatibility_mode);
START_LOG("translate()", "MeshData");
const unsigned int n_comp = this->n_val_per_node();
// transfer our nodal data to a vector
// that may be written concurrently
// with the \p out_mesh.
{
// reserve memory for the nodal data
values.reserve(n_comp*out_mesh.n_nodes());
// iterate over the mesh's nodes
MeshBase::const_node_iterator nodes_it = out_mesh.nodes_begin();
const MeshBase::const_node_iterator nodes_end = out_mesh.nodes_end();
// Do not use the \p get_data() method, but the operator()
// method, since this returns by default a zero value,
// when there is no nodal data.
for (; nodes_it != nodes_end; ++nodes_it)
{
const Node* node = *nodes_it;
for (unsigned int c= 0; c<n_comp; c++)
values.push_back(this->operator()(node, c));
}
}
// Now we have the data, nicely stored in \p values.
// It remains to give names to the data, then write to
// file.
{
names.reserve(n_comp);
// this naming scheme only works up to n_comp=100
// (at least for gmv-accepted variable names)
libmesh_assert_less (n_comp, 100);
for (unsigned int n=0; n<n_comp; n++)
{
std::ostringstream name_buf;
name_buf << "bc_" << n;
names.push_back(name_buf.str());
}
}
STOP_LOG("translate()", "MeshData");
}
| void libMesh::MeshData::write | ( | const std::string & | name | ) |
Write mesh data to file named name. Guess format from the file extension.
Definition at line 286 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::START_LOG(), libMesh::WRITE, write_unv(), and write_xdr().
{
START_LOG("write()", "MeshData");
libmesh_assert (_active || _compatibility_mode);
// the id maps have to be closed before writing
// (note that in compatibility mode these are also true)
libmesh_assert (_elem_id_map_closed && _node_id_map_closed);
#ifdef DEBUG
if (this->compatibility_mode())
libMesh::err << "WARNING: MeshData in compatibility mode. Node and element ids" << std::endl
<< " written to file may differ from libMesh numbering" << std::endl
<< " next time this file is read!" << std::endl;
#endif
// Read the file based on extension
{
if (name.rfind(".xta") < name.size())
write_xdr (name, WRITE);
else if (name.rfind(".xtr") < name.size())
write_xdr (name, ENCODE);
else if (name.rfind(".unv") < name.size())
write_unv (name);
else
libmesh_error_msg(" ERROR: Unrecognized file extension: " << name \
<< "\n I understand the following:\n\n" \
<< " *.xta -- Internal ASCII data format\n" \
<< " *.xtr -- Internal binary data format\n" \
<< " *.unv -- I-deas format");
}
STOP_LOG("write()", "MeshData");
}
| 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().
{
/*
* we should better be active or in compatibility mode
*/
libmesh_assert (this->_active || this->_compatibility_mode);
/*
* make sure the id maps are ready
* and that we have data to write
*/
libmesh_assert (this->_node_id_map_closed);
libmesh_assert (this->_elem_id_map_closed);
libmesh_assert (this->_node_data_closed);
libmesh_assert (this->_elem_data_closed);
if (file_name.rfind(".gz") < file_name.size())
{
#ifdef LIBMESH_HAVE_GZSTREAM
ogzstream out_stream(file_name.c_str());
this->write_unv_implementation (out_stream);
#else
libmesh_error_msg("ERROR: You must have the zlib.h header files and libraries to read and write compressed streams.");
#endif
return;
}
else
{
std::ofstream out_stream(file_name.c_str());
this->write_unv_implementation (out_stream);
return;
}
}
| 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(), n_val_per_node(), node_to_foreign_id(), libMesh::MeshDataUnvHeader::nvaldc, and libMesh::MeshDataUnvHeader::write().
Referenced by write_unv().
{
/*
* This is the actual implementation of writing
* unv files, either as .unv or as .unv.gz file
*/
if ( !out_file.good() )
libmesh_error_msg("ERROR: Output file not good.");
/*
* the beginning marker of the dataset block for
* nodal/element-associated data (not to be confused
* with _desired_dataset_label!)
*/
const std::string _label_dataset_mesh_data = "2414";
/*
* Currently this function handles only nodal data.
*/
libmesh_assert (!_node_data.empty());
if (!_elem_data.empty())
libMesh::err << "WARNING: MeshData currently only supports nodal data for Universal files."
<< std::endl
<< " Will proceed writing only nodal data, ignoring element data."
<< std::endl;
/*
* Write the beginning of the dataset.
*/
out_file << " -1\n"
<< " "
<< _label_dataset_mesh_data
<< "\n";
/*
* Write the header
*/
if (_unv_header==NULL)
{
/*
* create a header that holds at
* least sufficient data to specify
* what this data set currently holds.
*
* The empty constructor automatically
* takes care of \p dataset_location
* and \p data_type.
*/
MeshDataUnvHeader my_header;
/*
* It remains to set the correct nvaldc...
*/
my_header.nvaldc = this->n_val_per_node();
/*
* and the correct data type. By default
* only distinguish complex or real data.
*/
#ifdef LIBMESH_USE_COMPLEX_NUMBERS
my_header.data_type = 5;
#else
my_header.data_type = 2;
#endif
/*
* write this default header, then let
* the UniquePtr go out of scope. This
* will take care of memory management.
*/
my_header.write (out_file);
}
else
{
/*
* make sure our nvaldc coincide.
*/
if (this->n_val_per_node() != _unv_header->nvaldc)
{
libMesh::err << "WARNING: nvaldc=" << _unv_header->nvaldc
<< " of attached MeshDataUnvHeader object not valid!" << std::endl
<< " re-set nvaldc to " << this->n_val_per_node() << std::endl;
_unv_header->nvaldc = this->n_val_per_node();
}
/*
* only issue a warning when data_type does
* not coincide. Perhaps user provided some
* other header in order to convert complex
* to real...
*/
#ifdef LIBMESH_USE_COMPLEX_NUMBERS
const unsigned int my_data_type = 5;
#else
const unsigned int my_data_type = 2;
#endif
if (my_data_type != _unv_header->data_type)
{
libMesh::err << "WARNING: data_type=" << _unv_header->data_type
<< " of attached MeshDataUnvHeader differs from" << std::endl
<< " default value=" << my_data_type
<< " Perhaps the user wanted this," << std::endl
<< " so I use the value from the MeshDataUnvHeader."
<< std::endl;
}
_unv_header->write (out_file);
}
/*
* Write the foreign node number and the respective data.
*/
std::map<const Node*,
std::vector<Number> >::const_iterator nit = _node_data.begin();
char buf[27];
for (; nit != _node_data.end(); ++nit)
{
const Node* node = (*nit).first;
unsigned int f_n_id = node_to_foreign_id (node);
std::sprintf(buf, "%10u\n", f_n_id);
out_file << buf;
/* since we are iterating over our own map, this libmesh_assert
* should never break...
*/
libmesh_assert (this->has_data(node));
// const reference to the nodal values
const std::vector<Number>& values = this->get_data(node);
for (unsigned int v_cnt=0; v_cnt<values.size(); v_cnt++)
{
#ifdef LIBMESH_USE_COMPLEX_NUMBERS
std::sprintf(buf, "%13.5E%13.5E", values[v_cnt].real(),
values[v_cnt].imag());
out_file << buf;
#else
std::sprintf(buf, "%13.5E",
static_cast<double>(values[v_cnt]));
out_file << buf;
#endif
}
out_file << "\n";
}
/*
* Write end of the dataset.
*/
out_file << " -1\n";
}
| 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().
{
/*
* make sure the id maps are ready
* and that we have data to write
*/
libmesh_assert (_node_id_map_closed);
libmesh_assert (_elem_id_map_closed);
libmesh_assert (_node_data_closed);
libmesh_assert (_elem_data_closed);
Xdr io(name, mode);
// all processors write the data in the same format
//const unsigned int proc_id = _mesh.processor_id();
{
std::string desc = this->_data_descriptor;
io.data (desc, "# Data description");
}
{
#ifdef LIBMESH_USE_COMPLEX_NUMBERS
std::string desc = "COMPLEX";
#elif LIBMESH_USE_REAL_NUMBERS
std::string desc = "REAL";
#else
better_you_choke_this...
#endif
io.data (desc, "# type of values");
}
{
unsigned int n_node =
cast_int<unsigned int>(this->_node_data.size());
io.data (n_node, "# No. of nodes for which data is stored");
}
{
unsigned int n_elem =
cast_int<unsigned int>(this->_elem_data.size());
io.data (n_elem, "# No. of elements for which data is stored");
}
std::map<const Node*,
std::vector<Number> >::const_iterator nit = _node_data.begin ();
for (; nit != _node_data.end(); ++nit)
{
const Node* node = (*nit).first;
{
unsigned int f_id = node_to_foreign_id (node);
io.data (f_id, "# Foreign node id");
}
{
/*
* since we are iterating over our @e own
* map, this libmesh_assert should never break...
*/
libmesh_assert (this->has_data(node));
const std::vector<Number>& values = this->get_data(node);
/*
* copy the data to a local buf, since
* the Xdr class needs write access, even
* when only reading data
*/
std::vector<Number> buf = values;
io.data (buf, "# Values");
}
}
std::map<const Elem*,
std::vector<Number> >::const_iterator eit = _elem_data.begin ();
for (; eit != _elem_data.end(); ++eit)
{
const Elem* elem = (*eit).first;
{
unsigned int f_id = elem_to_foreign_id (elem);
io.data (f_id, "# Foreign element id");
}
{
/*
* since we are iterating over our @e own
* map, this libmesh_assert should never break...
*/
libmesh_assert (this->has_data(elem));
const std::vector<Number>& values = this->get_data(elem);
/*
* copy the data to a local buf, since
* the Xdr class needs write access, even
* when only reading data
*/
std::vector<Number> buf = values;
io.data (buf, "# Values");
}
}
}
friend class MeshDataUnvHeader [friend] |
Make the MeshDataUnvHeader class a friend.
Definition at line 631 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 365 of file mesh_data.C.
{
m.print_info(os);
return os;
}
bool libMesh::MeshData::_active [protected] |
true when this object is set active (to gather data during mesh import).
Definition at line 614 of file mesh_data.h.
Referenced by activate(), active(), add_foreign_elem_id(), add_foreign_node_id(), assign(), close_foreign_id_maps(), elem_initialized(), elem_to_foreign_id(), enable_compatibility_mode(), foreign_id_to_elem(), foreign_id_to_node(), get_data(), has_data(), insert_elem_data(), insert_node_data(), n_elem_data(), n_node_data(), n_val_per_elem(), n_val_per_node(), node_initialized(), node_to_foreign_id(), operator()(), read(), read_unv(), read_xdr(), translate(), write(), and write_unv().
bool libMesh::MeshData::_compatibility_mode [protected] |
true when this object is in compatibility mode (use libMesh's node and element numbers as fake foreign id's)
Definition at line 621 of file mesh_data.h.
Referenced by activate(), assign(), compatibility_mode(), elem_to_foreign_id(), enable_compatibility_mode(), foreign_id_to_elem(), foreign_id_to_node(), get_data(), has_data(), insert_elem_data(), insert_node_data(), n_elem_data(), n_node_data(), n_val_per_elem(), n_val_per_node(), node_to_foreign_id(), operator()(), read(), read_unv(), read_xdr(), translate(), write(), and write_unv().
std::string libMesh::MeshData::_data_descriptor [protected] |
Some name the user gave to the data when this object got activated
Definition at line 522 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] |
Maps element pointers to the element-associated data
Definition at line 556 of file mesh_data.h.
Referenced by assign(), clear(), elem_data_begin(), elem_data_end(), get_data(), has_data(), insert_elem_data(), n_elem_data(), n_val_per_elem(), operator()(), read_tetgen(), read_unv_implementation(), read_xdr(), set_data(), write_unv_implementation(), and write_xdr().
bool libMesh::MeshData::_elem_data_closed [protected] |
true when the element based data are properly initialized, false otherwise.
Definition at line 606 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 563 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 600 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 569 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 546 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 516 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 532 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 588 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 539 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 582 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 626 of file mesh_data.h.
Referenced by assign(), get_unv_header(), read_unv_implementation(), set_unv_header(), and write_unv_implementation().