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 |
| unsigned int | 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 |
| unsigned int | 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) |
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.
Definition at line 58 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 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.
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.
00035 : 00036 _mesh (m), 00037 _data_descriptor (""), 00038 _node_id_map_closed (false), 00039 _node_data_closed (false), 00040 _elem_id_map_closed (false), 00041 _elem_data_closed (false), 00042 _active (false), 00043 _compatibility_mode (false), 00044 _unv_header (NULL) 00045 { 00046 // This class isn't actively maintained, doesn't work in parallel, 00047 // and usually isn't as good a solution as adding an additional 00048 // ExplicitSystem with appropriate data field(s). 00049 libmesh_deprecated(); 00050 }
| libMesh::MeshData::~MeshData | ( | ) |
Destructor.
Definition at line 55 of file mesh_data.C.
References clear().
00056 { 00057 clear(); 00058 }
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.
00065 { 00066 #ifdef DEBUG 00067 if (_compatibility_mode) 00068 libMesh::err << "WARNING: MeshData was in compatibility mode, now being activated." 00069 << std::endl; 00070 #endif 00071 00072 _compatibility_mode = false; 00073 _active = true; 00074 _data_descriptor = descriptor; 00075 }
| bool libMesh::MeshData::active | ( | ) | const [inline] |
- Returns:
truewhen this object is active and working. Useactivate()to bring this object alive.
Definition at line 1004 of file mesh_data.h.
References _active.
Referenced by libMesh::UNVIO::element_out(), get_info(), libMesh::UNVIO::node_out(), libMesh::LegacyXdrIO::read_mesh(), slim(), and libMesh::UNVIO::write_implementation().
01005 { 01006 return _active; 01007 }
| 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 1062 of file mesh_data.h.
References _active, _elem_id, _elem_id_map_closed, and _id_elem.
Referenced by assign(), libMesh::UNVIO::element_in(), libMesh::TetGenIO::element_in(), and libMesh::LegacyXdrIO::read_mesh().
01064 { 01065 if (_active) 01066 { 01067 libmesh_assert (!_elem_id_map_closed); 01068 libmesh_assert(elem); 01069 libmesh_assert (_elem_id.find(elem) == _elem_id.end()); 01070 libmesh_assert (_id_elem.find(foreign_elem_id) == _id_elem.end()); 01071 01072 _elem_id.insert(std::make_pair(elem, foreign_elem_id)); 01073 _id_elem.insert(std::make_pair(foreign_elem_id, elem)); 01074 } 01075 }
| 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 1036 of file mesh_data.h.
References _active, _id_node, _node_id, and _node_id_map_closed.
Referenced by libMesh::UNVIO::node_in(), libMesh::TetGenIO::node_in(), libMesh::VTKIO::read(), and libMesh::LegacyXdrIO::read_mesh().
01038 { 01039 if (_active) 01040 { 01041 libmesh_assert (!_node_id_map_closed); 01042 libmesh_assert(node); 01043 libmesh_assert (_node_id.find(node) == _node_id.end()); 01044 libmesh_assert (_id_node.find(foreign_node_id) == _id_node.end()); 01045 01046 /* 01047 * _always_ insert in _id_node and _node_id. If we would 01048 * use the mesh.node(unsigned int) method or the node.id() 01049 * to get Node* and unsigned int, respectively, we would not 01050 * be safe any more when the mesh gets refined or re-numbered 01051 * within libMesh. And we could get in big trouble that would 01052 * be hard to find when importing data _after_ having refined... 01053 */ 01054 _node_id.insert(std::make_pair(node, foreign_node_id)); 01055 _id_node.insert(std::make_pair(foreign_node_id, node)); 01056 } 01057 }
| 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 722 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(), and libMesh::DofObject::id().
Referenced by libMesh::BoundaryInfo::sync().
00723 { 00724 this->_data_descriptor = omd._data_descriptor; 00725 this->_node_id_map_closed = omd._node_id_map_closed; 00726 this->_node_data_closed = omd._node_data_closed; 00727 00728 // we have to be able to modify our elem id maps 00729 libmesh_assert (!this->_elem_id_map_closed); 00730 00731 this->_elem_data_closed = omd._elem_data_closed; 00732 this->_active = omd._active; 00733 this->_compatibility_mode = omd._compatibility_mode; 00734 00735 // this is ok because we do not manage the UnvHeader 00736 // in terms of memory, but only hold a pointer to it... 00737 this->_unv_header = omd._unv_header; 00738 00739 // Now copy the foreign id maps -- but only for the 00740 // nodes. The nodes of the boundary mesh are actually 00741 // nodes of the volume mesh. 00742 this->_node_id = omd._node_id; 00743 this->_id_node = omd._id_node; 00744 00745 // The element vector of the boundary mesh contains elements 00746 // that are new, and there _cannot_ be any associated 00747 // foreign id in the maps. Therefore, fill the maps with 00748 // the libMesh id's. But only when the other MeshData 00749 // has element ids. 00750 if ((this->_active) && (omd._elem_id.size() != 0)) 00751 { 00752 00753 MeshBase::const_element_iterator elem_it = _mesh.elements_begin(); 00754 const MeshBase::const_element_iterator elem_end = _mesh.elements_end(); 00755 00756 for (; elem_it != elem_end; ++elem_it) 00757 { 00758 const Elem* elem = *elem_it; 00759 this->add_foreign_elem_id(elem, elem->id()); 00760 } 00761 } 00762 00763 // now we can safely assign omd's value 00764 this->_elem_id_map_closed = omd._elem_id_map_closed; 00765 00766 00767 // and finally the node- and element-associated data 00768 this->_node_data = omd._node_data; 00769 this->_elem_data = omd._elem_data; 00770 }
| 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().
00110 { 00111 _data_descriptor = ""; 00112 _node_data.clear(); 00113 _elem_data.clear(); 00114 _node_data_closed = false; 00115 _elem_data_closed = false; 00116 }
| 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 219 of file mesh_data.C.
References _active, _elem_id, _elem_id_map_closed, _id_elem, _id_node, _node_id, and _node_id_map_closed.
Referenced by libMesh::UNVIO::read_implementation(), libMesh::LegacyXdrIO::read_mesh(), and libMesh::TetGenIO::read_nodes_and_elem().
00220 { 00221 if (_active) 00222 { 00223 libmesh_assert (!_elem_id.empty()); 00224 libmesh_assert (!_id_elem.empty()); 00225 libmesh_assert (!_node_id.empty()); 00226 libmesh_assert (!_id_node.empty()); 00227 00228 _elem_id_map_closed = true; 00229 _node_id_map_closed = true; 00230 } 00231 }
| bool libMesh::MeshData::compatibility_mode | ( | ) | const [inline] |
- Returns:
truewhen this object is in compatibility mode. Seeenable_compatibility_mode()for details.
Definition at line 1012 of file mesh_data.h.
References _compatibility_mode.
Referenced by libMesh::UNVIO::element_out(), get_info(), libMesh::UNVIO::node_out(), read(), slim(), write(), and libMesh::UNVIO::write_implementation().
01013 { 01014 return _compatibility_mode; 01015 }
| 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 986 of file mesh_data.h.
References _elem_data.
00987 { 00988 return _elem_data.begin(); 00989 }
| 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 994 of file mesh_data.h.
References _elem_data.
00995 { 00996 return _elem_data.end(); 00997 }
| bool libMesh::MeshData::elem_initialized | ( | ) | const [inline] |
- Returns:
truewhen this object is properly initialized and ready for use for element associated data,falseotherwise.
Definition at line 1020 of file mesh_data.h.
References _active, and _elem_data_closed.
Referenced by get_info().
01021 { 01022 return (_active && _elem_data_closed); 01023 }
| unsigned int libMesh::MeshData::elem_to_foreign_id | ( | const Elem * | n | ) | const |
- Returns:
- the foreign id this
Elem*maps to.
Definition at line 499 of file mesh_data.C.
References _active, _compatibility_mode, _elem_id, _elem_id_map_closed, libMesh::err, and libMesh::DofObject::id().
Referenced by libMesh::UNVIO::element_out(), and write_xdr().
00500 { 00501 libmesh_assert(e); 00502 00503 if (_active) 00504 { 00505 // when active, use our _id_elem map 00506 libmesh_assert (_elem_id_map_closed); 00507 00508 // look it up in the map 00509 std::map<const Elem*, 00510 unsigned int>::const_iterator pos = _elem_id.find(e); 00511 00512 if (pos == _elem_id.end()) 00513 { 00514 libMesh::err << "ERROR: No foreign id stored for the element " 00515 << "with the libMesh id = " 00516 << e->id() 00517 << std::endl; 00518 libmesh_error(); 00519 return 0; 00520 } 00521 else 00522 return pos->second; 00523 } 00524 else if (_compatibility_mode) 00525 // when only in compatibility mode, 00526 // return libMesh's element id 00527 return e->id(); 00528 00529 // should never get here 00530 libmesh_error(); 00531 return 0; 00532 }
| 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().
00082 { 00083 if (!_active) 00084 { 00085 _compatibility_mode = true; 00086 _active = false; 00087 // do as if the id maps are already closed 00088 _node_id_map_closed = true; 00089 _elem_id_map_closed = true; 00090 _data_descriptor = descriptor; 00091 // we can safely clear the id maps 00092 _node_id.clear(); 00093 _id_node.clear(); 00094 _elem_id.clear(); 00095 _id_elem.clear(); 00096 } 00097 #ifdef DEBUG 00098 else 00099 libMesh::err << "WARNING: MeshData was in compatibility mode, now being activated." 00100 << std::endl; 00101 #endif 00102 }
| 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 464 of file mesh_data.C.
References _active, _compatibility_mode, _elem_id_map_closed, _id_elem, _mesh, libMesh::MeshBase::elem(), and libMesh::err.
Referenced by read_tetgen(), and read_xdr().
00465 { 00466 if (_active) 00467 { 00468 // when active, use our _id_elem map 00469 libmesh_assert (_elem_id_map_closed); 00470 00471 std::map<unsigned int, 00472 const Elem*>::const_iterator pos = _id_elem.find(fid); 00473 00474 if (pos == _id_elem.end()) 00475 { 00476 libMesh::err << "ERROR: Have no Elem* associated with the foreign id = " 00477 << fid 00478 << std::endl; 00479 libmesh_error(); 00480 return NULL; 00481 } 00482 else 00483 return pos->second; 00484 } 00485 else if (_compatibility_mode) 00486 // when only in compatibility mode, 00487 // return element using the libMesh id 00488 return this->_mesh.elem(fid); 00489 00490 // should never get here 00491 libmesh_error(); 00492 return NULL; 00493 }
| 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 386 of file mesh_data.C.
References _active, _compatibility_mode, _id_node, _mesh, _node_id_map_closed, libMesh::err, and libMesh::MeshBase::node_ptr().
Referenced by read_tetgen(), read_unv_implementation(), and read_xdr().
00387 { 00388 if (_active) 00389 { 00390 // when active, use our _id_node map 00391 libmesh_assert (_node_id_map_closed); 00392 00393 std::map<unsigned int, 00394 const Node*>::const_iterator pos = _id_node.find(fid); 00395 00396 if (pos == _id_node.end()) 00397 { 00398 libMesh::err << "ERROR: Have no Node* associated with the foreign id = " 00399 << fid 00400 << std::endl; 00401 libmesh_error(); 00402 return NULL; 00403 } 00404 else 00405 return pos->second; 00406 } 00407 else if (_compatibility_mode) 00408 // when only in compatibility mode, 00409 // return the node stored in the MeshBase 00410 // under its current id 00411 return this->_mesh.node_ptr(fid); 00412 00413 // should never get here 00414 libmesh_error(); 00415 return NULL; 00416 }
- 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 elementelem!Check existence throughhas_data()first.
Definition at line 955 of file mesh_data.h.
References _active, _compatibility_mode, _elem_data, _elem_data_closed, and libMesh::err.
00956 { 00957 libmesh_assert (_active || _compatibility_mode); 00958 libmesh_assert (_elem_data_closed); 00959 00960 std::map<const Elem*, 00961 std::vector<Number> >::const_iterator pos = _elem_data.find(elem); 00962 00963 #ifdef DEBUG 00964 if (pos == _elem_data.end()) 00965 { 00966 libMesh::err << "ERROR: No data for this element. Use has_data() first!" << std::endl; 00967 libmesh_error(); 00968 } 00969 #endif 00970 00971 return pos->second; 00972 }
- 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 nodenode!Check existence throughhas_data()first.
Definition at line 872 of file mesh_data.h.
References _active, _compatibility_mode, _node_data, and _node_data_closed.
Referenced by write_unv_implementation(), and write_xdr().
00873 { 00874 libmesh_assert (_active || _compatibility_mode); 00875 libmesh_assert (_node_data_closed); 00876 00877 std::map<const Node*, 00878 std::vector<Number> >::const_iterator pos = _node_data.find(node); 00879 00880 #ifdef DEBUG 00881 if (pos == _node_data.end()) 00882 { 00883 std::cerr << "ERROR: No data for this node. Use has_data() first!" << std::endl; 00884 libmesh_error(); 00885 } 00886 #endif 00887 00888 return pos->second; 00889 }
| std::string libMesh::MeshData::get_info | ( | ) | const |
- Returns:
- a string containing relevant information about the mesh.
Definition at line 339 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().
00340 { 00341 std::ostringstream oss; 00342 00343 if (this->active() || this->compatibility_mode()) 00344 { 00345 oss << " MeshData Information:\n"; 00346 if (this->active()) 00347 oss << " object activated.\n"; 00348 if (this->compatibility_mode()) 00349 oss << " object in compatibility mode.\n"; 00350 if (this->_data_descriptor != "") 00351 oss << " descriptor=" << this->_data_descriptor << '\n'; 00352 if (this->elem_initialized()) 00353 oss << " Element associated data initialized.\n" 00354 << " n_val_per_elem()=" << this->n_val_per_elem() << '\n' 00355 << " n_elem_data()=" << this->n_elem_data() << '\n'; 00356 if (this->node_initialized()) 00357 oss << " Node associated data initialized.\n" 00358 << " n_val_per_node()=" << this->n_val_per_node() << '\n' 00359 << " n_node_data()=" << this->n_node_data() << '\n'; 00360 } 00361 else 00362 oss << " MeshData neither active nor in compatibility mode.\n"; 00363 00364 return oss.str(); 00365 }
| const MeshDataUnvHeader & libMesh::MeshData::get_unv_header | ( | ) | const [inline] |
Read access to the MeshDataUnvHeader data structure.
Definition at line 1079 of file mesh_data.h.
References _unv_header.
01080 { 01081 libmesh_assert(this->_unv_header); 01082 return *this->_unv_header; 01083 }
| bool libMesh::MeshData::has_data | ( | const Elem * | elem | ) | const [inline] |
- Returns:
truewhen the elementelemhas data,falseotherwise.
Definition at line 941 of file mesh_data.h.
References _active, _compatibility_mode, _elem_data, and _elem_data_closed.
00942 { 00943 libmesh_assert (_active || _compatibility_mode); 00944 libmesh_assert (_elem_data_closed); 00945 00946 std::map<const Elem*, 00947 std::vector<Number> >::const_iterator pos = _elem_data.find(elem); 00948 00949 return (pos != _elem_data.end()); 00950 }
| bool libMesh::MeshData::has_data | ( | const Node * | node | ) | const [inline] |
- Returns:
truewhen the nodenodehas data,falseotherwise.
Definition at line 858 of file mesh_data.h.
References _active, _compatibility_mode, _node_data, and _node_data_closed.
Referenced by write_unv_implementation(), and write_xdr().
00859 { 00860 libmesh_assert (_active || _compatibility_mode); 00861 libmesh_assert (_node_data_closed); 00862 00863 std::map<const Node*, 00864 std::vector<Number> >::const_iterator pos = _node_data.find(node); 00865 00866 return (pos != _node_data.end()); 00867 }
| 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 604 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::err.
00607 { 00608 libmesh_assert (this->_active || this->_compatibility_mode); 00609 // these are also true in compatibility mode 00610 libmesh_assert (this->_elem_id_map_closed); 00611 00612 if (this->_elem_data_closed) 00613 { 00614 libMesh::err << "ERROR: Element data already closed! Use clear() first!" 00615 << std::endl; 00616 libmesh_error(); 00617 } 00618 00619 libmesh_assert (this->_elem_data.empty()); 00620 00621 #ifdef DEBUG 00622 std::map<const Elem*, 00623 std::vector<Number> >::const_iterator ed_pos = ed.begin(); 00624 std::map<const Elem*, 00625 std::vector<Number> >::const_iterator ed_end = ed.end(); 00626 00627 // Compare entity-by-entity that the 00628 // sizes of the std::vector's are identical. 00629 const unsigned int reference_length = (*ed_pos).second.size(); 00630 ++ed_pos; 00631 00632 for (; ed_pos != ed_end; ++ed_pos) 00633 if ( (*ed_pos).second.size() != reference_length) 00634 { 00635 libMesh::err << "ERROR: Size mismatch." 00636 << std::endl; 00637 libmesh_error(); 00638 } 00639 #endif 00640 00641 // copy over 00642 _elem_data = ed; 00643 00644 // we may freely trash the ed 00645 ed.clear(); 00646 00647 // close elem data 00648 this->_elem_data_closed = true; 00649 00650 // if user wants to, then close node data, too 00651 if (close_node_data) 00652 { 00653 libmesh_assert((this->_node_id_map_closed)); 00654 this->_node_data_closed = true; 00655 } 00656 }
| 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 540 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::err.
00543 { 00544 libmesh_assert (this->_active || this->_compatibility_mode); 00545 // these are also true in compatibility mode 00546 libmesh_assert (this->_node_id_map_closed); 00547 00548 if (this->_node_data_closed) 00549 { 00550 libMesh::err << "ERROR: Nodal data already closed! Use clear() first!" 00551 << std::endl; 00552 libmesh_error(); 00553 } 00554 00555 libmesh_assert (this->_node_data.empty()); 00556 00557 #ifdef DEBUG 00558 std::map<const Node*, 00559 std::vector<Number> >::const_iterator nd_pos = nd.begin(); 00560 std::map<const Node*, 00561 std::vector<Number> >::const_iterator nd_end = nd.end(); 00562 00563 // Compare entity-by-entity that the 00564 // sizes of the std::vector's are identical. 00565 // For this, simply take the length of the 0th 00566 // entry as reference length, and compare this 00567 // with the length of the 1st, 2nd... 00568 libmesh_assert (nd_pos != nd_end); 00569 const unsigned int reference_length = (*nd_pos).second.size(); 00570 00571 // advance, so that we compare with the 1st 00572 ++nd_pos; 00573 00574 for (; nd_pos != nd_end; ++nd_pos) 00575 if ( (*nd_pos).second.size() != reference_length) 00576 { 00577 libMesh::err << "ERROR: Size mismatch." 00578 << std::endl; 00579 libmesh_error(); 00580 } 00581 #endif 00582 00583 // copy over 00584 _node_data = nd; 00585 00586 // we may freely trash the nd 00587 nd.clear(); 00588 00589 // close node data 00590 this->_node_data_closed = true; 00591 00592 // if user wants to, then close elem data, too 00593 if (close_elem_data) 00594 { 00595 libmesh_assert((this->_elem_id_map_closed)); 00596 this->_elem_data_closed = true; 00597 } 00598 }
| unsigned int libMesh::MeshData::n_elem_data | ( | ) | const |
- Returns:
- the number of elements for which this
MeshDatahas data stored.
Definition at line 711 of file mesh_data.C.
References _active, _compatibility_mode, _elem_data, and _elem_data_closed.
Referenced by get_info().
00712 { 00713 libmesh_assert (this->_active || this->_compatibility_mode); 00714 libmesh_assert (this->_elem_data_closed); 00715 00716 return _elem_data.size(); 00717 }
| unsigned int libMesh::MeshData::n_node_data | ( | ) | const |
- Returns:
- the number of nodes for which this
MeshDatahas data stored.
Definition at line 681 of file mesh_data.C.
References _active, _compatibility_mode, _node_data, and _node_data_closed.
Referenced by get_info().
00682 { 00683 libmesh_assert (this->_active || this->_compatibility_mode); 00684 libmesh_assert (this->_node_data_closed); 00685 00686 return this->_node_data.size(); 00687 }
| unsigned int libMesh::MeshData::n_val_per_elem | ( | ) | const |
- Returns:
- the number of
Number-type data (i.e., the size of thestd::vector<Number>returned through theoperator()methods) associated with an element. Returns 0 when there is no element-associated data.
Definition at line 692 of file mesh_data.C.
References _active, _compatibility_mode, _elem_data, and _elem_data_closed.
Referenced by get_info().
00693 { 00694 libmesh_assert (this->_active || this->_compatibility_mode); 00695 libmesh_assert (this->_elem_data_closed); 00696 00697 if (!_elem_data.empty()) 00698 { 00699 std::map<const Elem*, 00700 std::vector<Number> >::const_iterator pos = _elem_data.begin(); 00701 libmesh_assert (pos != _elem_data.end()); 00702 return (pos->second.size()); 00703 } 00704 else 00705 return 0; 00706 }
| unsigned int libMesh::MeshData::n_val_per_node | ( | ) | const |
- Returns:
- the number of
Number-type data (i.e., the size of thestd::vector<Number>returned through theoperator()methods) associated with a node. Returns 0 when no nodal data exists.
Definition at line 662 of file mesh_data.C.
References _active, _compatibility_mode, _node_data, and _node_data_closed.
Referenced by get_info(), translate(), and write_unv_implementation().
00663 { 00664 libmesh_assert (this->_active || this->_compatibility_mode); 00665 libmesh_assert (this->_node_data_closed); 00666 00667 if (!this->_node_data.empty()) 00668 { 00669 std::map<const Node*, 00670 std::vector<Number> >::const_iterator pos = _node_data.begin(); 00671 libmesh_assert (pos != _node_data.end()); 00672 return (pos->second.size()); 00673 } 00674 else 00675 return 0; 00676 }
| 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 903 of file mesh_data.h.
References _node_data.
00904 { 00905 return _node_data.begin(); 00906 }
| 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 911 of file mesh_data.h.
References _node_data.
00912 { 00913 return _node_data.end(); 00914 }
| bool libMesh::MeshData::node_initialized | ( | ) | const [inline] |
- Returns:
truewhen this object is properly initialized and ready for use for nodal data,falseotherwise.
Definition at line 1028 of file mesh_data.h.
References _active, and _node_data_closed.
Referenced by get_info().
01029 { 01030 return (_active && _node_data_closed); 01031 }
| unsigned int libMesh::MeshData::node_to_foreign_id | ( | const Node * | n | ) | const |
- Returns:
- the foreign id this
Node*maps to.
Definition at line 422 of file mesh_data.C.
References _active, _compatibility_mode, _node_id, _node_id_map_closed, libMesh::err, and libMesh::DofObject::id().
Referenced by libMesh::UNVIO::element_out(), libMesh::UNVIO::node_out(), write_unv_implementation(), and write_xdr().
00423 { 00424 libmesh_assert(n); 00425 00426 if (_active) 00427 { 00428 // when active, use our _node_id map 00429 libmesh_assert (_node_id_map_closed); 00430 00431 // look it up in the map 00432 std::map<const Node*, 00433 unsigned int>::const_iterator pos = _node_id.find(n); 00434 00435 if (pos == _node_id.end()) 00436 { 00437 libMesh::err << "ERROR: No foreign id stored for the node " 00438 << "with the libMesh id = " 00439 << n->id() 00440 << std::endl; 00441 libmesh_error(); 00442 return 0; 00443 } 00444 else 00445 return pos->second; 00446 } 00447 else if (_compatibility_mode) 00448 // when only in compatibility mode, 00449 // return libMesh's node id 00450 return n->id(); 00451 00452 // should never get here 00453 libmesh_error(); 00454 return 0; 00455 }
- Returns:
- the
value (defaults to 0) associated with element elem. ReturnslibMesh::zerowhen there is no data forelemin the map.
Definition at line 921 of file mesh_data.h.
References _active, _compatibility_mode, _elem_data, _elem_data_closed, and libMesh::zero.
00923 { 00924 libmesh_assert (_active || _compatibility_mode); 00925 libmesh_assert (_elem_data_closed); 00926 00927 std::map<const Elem*, 00928 std::vector<Number> >::const_iterator pos = _elem_data.find(elem); 00929 00930 if (pos == _elem_data.end()) 00931 return libMesh::zero; 00932 00933 // we only get here when pos != _elem_data.end() 00934 libmesh_assert_less (i, pos->second.size()); 00935 return pos->second[i]; 00936 }
- Returns:
- the
value (defaults to 0) associated with node node. ReturnslibMesh::zerowhen there is no suchnodein the map.
Definition at line 838 of file mesh_data.h.
References _active, _compatibility_mode, _node_data, _node_data_closed, and libMesh::zero.
00840 { 00841 libmesh_assert (_active || _compatibility_mode); 00842 libmesh_assert (_node_data_closed); 00843 00844 std::map<const Node*, 00845 std::vector<Number> >::const_iterator pos = _node_data.find(node); 00846 00847 if (pos == _node_data.end()) 00848 return libMesh::zero; 00849 00850 // we only get here when pos != _node_data.end() 00851 libmesh_assert_less (i, pos->second.size()); 00852 return pos->second[i]; 00853 }
| void libMesh::MeshData::print_info | ( | std::ostream & | os = libMesh::out |
) | const |
Prints relevant information about the mesh.
Definition at line 370 of file mesh_data.C.
References get_info().
Referenced by libMesh::operator<<().
00371 { 00372 os << this->get_info() 00373 << std::endl; 00374 }
| 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(), libMeshEnums::DECODE, libMesh::err, libMeshEnums::READ, read_tetgen(), read_unv(), and read_xdr().
00238 { 00239 START_LOG("read()", "MeshData"); 00240 00241 libmesh_assert (_active || _compatibility_mode); 00242 00243 // the id maps have to be closed before reading 00244 // (note that in compatibility mode these are also true) 00245 libmesh_assert (_elem_id_map_closed && _node_id_map_closed); 00246 00247 #ifdef DEBUG 00248 if (this->compatibility_mode()) 00249 libMesh::err << "WARNING: MeshData in compatibility mode, node and element ids" << std::endl 00250 << " stored in file may be totally different from libMesh ids!" << std::endl; 00251 #endif 00252 00253 // Read the file based on extension. We let all processors read the 00254 // data because it would be inaccurate to let only one processor 00255 // have it and we're too lazy to code up a proper parallel read or 00256 // read+broadcast right now. 00257 00258 //if (libMesh::processor_id() == 0) 00259 // { 00260 if (name.rfind(".xta") < name.size()) 00261 this->read_xdr (name, READ); 00262 00263 else if (name.rfind(".xtr") < name.size()) 00264 this->read_xdr (name, DECODE); 00265 00266 else if (name.rfind(".unv") < name.size()) 00267 this->read_unv (name); 00268 00269 else if ((name.rfind(".node") < name.size()) || 00270 (name.rfind(".ele") < name.size())) 00271 this->read_tetgen (name); 00272 00273 else 00274 { 00275 libMesh::err << " ERROR: Unrecognized file extension: " << name 00276 << "\n I understand the following:\n\n" 00277 << " *.xta -- Internal ASCII data format\n" 00278 << " *.xtr -- Internal binary data format\n" 00279 << " *.unv -- I-deas format\n" 00280 << std::endl; 00281 libmesh_error(); 00282 00283 } 00284 //} 00285 STOP_LOG("read()", "MeshData"); 00286 }
| 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, libMesh::err, foreign_id_to_elem(), foreign_id_to_node(), libMesh::MeshTools::n_elem(), n_nodes, and libMesh::Real.
Referenced by read().
00035 { 00036 std::string name_node, name_ele, dummy; 00037 std::string desc = name; 00038 00039 00040 // Check name for *.node or *.ele extension. 00041 // Set std::istream for node_stream and ele_stream. 00042 if (name.rfind(".node") < name.size()) 00043 { 00044 name_node = name; 00045 dummy = name; 00046 std::size_t position = dummy.rfind(".node"); 00047 name_ele = dummy.replace(position, 5, ".ele"); 00048 desc.erase(position); 00049 } 00050 else if (name.rfind(".ele") < name.size()) 00051 { 00052 name_ele = name; 00053 dummy = name; 00054 std::size_t position = dummy.rfind(".ele"); 00055 name_node = dummy.replace(position, 4, ".node"); 00056 desc.erase(position); 00057 } 00058 else 00059 { 00060 libMesh::err << "ERROR: Unrecognized file name: " 00061 << name << std::endl; 00062 libmesh_error(); 00063 } 00064 00065 // Set the streams from which to read in. 00066 std::ifstream node_stream (name_node.c_str()); 00067 std::ifstream ele_stream (name_ele.c_str()); 00068 00069 if ( !node_stream.good() || !ele_stream.good() ) 00070 { 00071 libMesh::err << "ERROR: One or both Input file(s) not good." << std::endl 00072 << "Error checking files " 00073 << name_node << " and " 00074 << name_ele << std::endl; 00075 libmesh_error(); 00076 } 00077 00078 00079 // Set the descriptive name. 00080 // TetGen won't give a name, so we use the filename. 00081 this->_data_descriptor = desc; 00082 00083 00084 //-------------------------------------------------- 00085 // Read in the data associated with the nodes. 00086 { 00087 unsigned int n_node=0, f_n_id=0, nAttri=0, BoundMark=0; 00088 Real dummy_val=0.0; 00089 std::vector<Number> AttriValue; 00090 00091 // Read the parameters from the node_stream. 00092 node_stream >> n_node // Read the number of nodes 00093 >> dummy_val // Read the dimension 00094 >> nAttri // Read the number of attributes 00095 >> BoundMark; // (0 or 1) boundary markers are in the stream or not. 00096 00097 // Resize the values vector. 00098 AttriValue.resize(nAttri); 00099 00100 for (unsigned int i=0; i<n_node; i++) 00101 { 00102 node_stream >> f_n_id; 00103 00104 00105 // Read the nodal coordinates for this node into dummy_val, 00106 // since we don't need them. 00107 for (unsigned int j=0; j<3; j++) 00108 node_stream >> dummy_val; 00109 00110 // Read the attributes from the stream. 00111 for (unsigned int j=0; j<nAttri; j++) 00112 node_stream >> AttriValue[j]; 00113 00114 // Read boundary marker if BoundaryMarker=1. 00115 if (BoundMark == 1) 00116 node_stream >> dummy_val; 00117 00118 // For the foreign node id locate the Node*. 00119 const Node* node = foreign_id_to_node(f_n_id); 00120 00121 // Insert this node and the values in our _node_data. 00122 _node_data.insert (std::make_pair(node, AttriValue)); 00123 } 00124 } 00125 00126 00127 //-------------------------------------------------- 00128 // Read in the data associated with the elements. 00129 { 00130 unsigned int n_elem, f_e_id, n_nodes, nAttri=0; 00131 Real dummy_val=0.0; 00132 std::vector<Number> AttriValue; 00133 00134 // Read the parameters from the ele_stream. 00135 ele_stream >> n_elem // Read the number of tetrahedrons 00136 >> n_nodes // Read the points per tetrahedron 00137 >> nAttri; // Read the number of attributes 00138 00139 // Resize the values vector. 00140 AttriValue.resize(nAttri); 00141 00142 for (unsigned int i=0; i<n_elem; i++) 00143 { 00144 ele_stream >> f_e_id; 00145 00146 // For the number of nodes for this element read them into dummy_val, 00147 // since we don't need them. 00148 for (unsigned int n=0; n<n_nodes; n++) 00149 ele_stream >> dummy_val; 00150 00151 // Read the attributes from the stream. 00152 for (unsigned int j=0; j<nAttri; j++) 00153 ele_stream >> AttriValue[j]; 00154 00155 // For the foreign elem id locate the Elem*. 00156 const Elem* elem = foreign_id_to_elem(f_e_id); 00157 00158 // Insert this elem and the values in our _elem_data. 00159 _elem_data.insert (std::make_pair(elem, AttriValue)); 00160 } 00161 } 00162 00163 //-------------------------------------------------- 00164 // Finished reading. Now ready for use. 00165 this->_node_data_closed = true; 00166 this->_elem_data_closed = true; 00167 00168 node_stream.close(); 00169 ele_stream.close(); 00170 }
| 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::err, and read_unv_implementation().
Referenced by read().
00040 { 00041 /* 00042 * we should better be active or in compatibility mode 00043 */ 00044 libmesh_assert (this->_active || this->_compatibility_mode); 00045 00046 /* 00047 * When reading data, make sure the id maps are ok 00048 */ 00049 libmesh_assert (this->_node_id_map_closed); 00050 libmesh_assert (this->_elem_id_map_closed); 00051 00052 /* 00053 * clear the data, but keep the id maps 00054 */ 00055 this->clear(); 00056 00057 /* 00058 * We can read either ".unv", or ".unv.gz" 00059 * files, provided zlib.h is there 00060 */ 00061 if (file_name.rfind(".gz") < file_name.size()) 00062 { 00063 #ifdef LIBMESH_HAVE_GZSTREAM 00064 igzstream in_stream(file_name.c_str()); 00065 this->read_unv_implementation (in_stream); 00066 #else 00067 libMesh::err << "ERROR: You must have the zlib.h header " 00068 << "files and libraries to read and write " 00069 << "compressed streams." 00070 << std::endl; 00071 libmesh_error(); 00072 #endif 00073 return; 00074 } 00075 00076 else 00077 { 00078 std::ifstream in_stream(file_name.c_str()); 00079 this->read_unv_implementation (in_stream); 00080 return; 00081 } 00082 }
| 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 89 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, libMesh::err, foreign_id_to_node(), libMesh::MeshDataUnvHeader::need_D_to_e(), libMesh::MeshDataUnvHeader::nvaldc, libMesh::MeshDataUnvHeader::read(), and libMesh::Real.
Referenced by read_unv().
00090 { 00091 /* 00092 * This is the actual implementation of 00093 * reading in UNV format. This enables 00094 * to read either through the conventional 00095 * C++ stream, or through a stream that 00096 * allows to read .gz'ed files. 00097 */ 00098 if ( !in_file.good() ) 00099 { 00100 libMesh::err << "ERROR: Input file not good." 00101 << std::endl; 00102 libmesh_error(); 00103 } 00104 00105 const std::string _label_dataset_mesh_data = "2414"; 00106 00107 /* 00108 * locate the beginning of data set 00109 * and read it. 00110 */ 00111 { 00112 std::string olds, news; 00113 00114 while (true) 00115 { 00116 in_file >> olds >> news; 00117 00118 /* 00119 * Yes, really dirty: 00120 * 00121 * When we found a dataset, and the user does 00122 * not want this dataset, we jump back here 00123 */ 00124 go_and_find_the_next_dataset: 00125 00126 /* 00127 * a "-1" followed by a number means the beginning of a dataset 00128 * stop combing at the end of the file 00129 */ 00130 while( ((olds != "-1") || (news == "-1") ) && !in_file.eof() ) 00131 { 00132 olds = news; 00133 in_file >> news; 00134 } 00135 00136 if(in_file.eof()) 00137 break; 00138 00139 /* 00140 * if beginning of dataset 00141 */ 00142 if (news == _label_dataset_mesh_data) 00143 { 00144 00145 /* 00146 * Now read the data of interest. 00147 * Start with the header. For 00148 * explanation of the variable 00149 * dataset_location, see below. 00150 */ 00151 unsigned int dataset_location; 00152 00153 /* 00154 * the type of data (complex, real, 00155 * float, double etc, see below) 00156 */ 00157 unsigned int data_type; 00158 00159 /* 00160 * the number of floating-point values per entity 00161 */ 00162 unsigned int NVALDC; 00163 00164 00165 /* 00166 * If there is no MeshDataUnvHeader object 00167 * attached 00168 */ 00169 if (_unv_header==NULL) 00170 { 00171 /* 00172 * Ignore the first lines that stand for 00173 * analysis dataset label and name. 00174 */ 00175 for(unsigned int i=0; i<3; i++) 00176 in_file.ignore(256,'\n'); 00177 00178 /* 00179 * Read the dataset location, where 00180 * 1: Data at nodes 00181 * 2: Data on elements 00182 * other sets are currently not supported. 00183 */ 00184 in_file >> dataset_location; 00185 00186 /* 00187 * Ignore five ID lines. 00188 */ 00189 for(unsigned int i=0; i<6; i++) 00190 in_file.ignore(256,'\n'); 00191 00192 /* 00193 * These data are all of no interest to us... 00194 */ 00195 unsigned int model_type, 00196 analysis_type, 00197 data_characteristic, 00198 result_type; 00199 00200 /* 00201 * Read record 9. 00202 */ 00203 in_file >> model_type // not used here 00204 >> analysis_type // not used here 00205 >> data_characteristic // not used here 00206 >> result_type // not used here 00207 >> data_type 00208 >> NVALDC; 00209 00210 00211 /* 00212 * Ignore record 10 and 11 00213 * (Integer analysis type specific data). 00214 */ 00215 for (unsigned int i=0; i<3; i++) 00216 in_file.ignore(256,'\n'); 00217 00218 /* 00219 * Ignore record 12 and record 13. Since there 00220 * exist UNV files with 'D' instead of 'e' as 00221 * 10th-power char, it is safer to use a string 00222 * to read the dummy reals. 00223 */ 00224 { 00225 std::string dummy_Real; 00226 for (unsigned int i=0; i<12; i++) 00227 in_file >> dummy_Real; 00228 } 00229 00230 } 00231 else 00232 { 00233 00234 /* 00235 * the read() method returns false when 00236 * the user wanted a special header, and 00237 * when the current header is _not_ the correct 00238 * header 00239 */ 00240 if (_unv_header->read(in_file)) 00241 { 00242 dataset_location = _unv_header->dataset_location; 00243 NVALDC = _unv_header->nvaldc; 00244 data_type = _unv_header->data_type; 00245 } 00246 else 00247 { 00248 /* 00249 * This is not the correct header. Go 00250 * and find the next. For this to 00251 * work correctly, shift to the 00252 * next line, so that the "-1" 00253 * disappears from olds 00254 */ 00255 olds = news; 00256 in_file >> news; 00257 00258 /* 00259 * No good style, i know... 00260 */ 00261 goto go_and_find_the_next_dataset; 00262 } 00263 00264 } 00265 00266 /* 00267 * Check the location of the dataset. 00268 */ 00269 if (dataset_location != 1) 00270 { 00271 libMesh::err << "ERROR: Currently only Data at nodes is supported." 00272 << std::endl; 00273 libmesh_error(); 00274 } 00275 00276 00277 /* 00278 * Now get the foreign node id number and the respective nodal data. 00279 */ 00280 int f_n_id; 00281 std::vector<Number> values; 00282 00283 while(true) 00284 { 00285 in_file >> f_n_id; 00286 00287 /* 00288 * if node_nr = -1 then we have reached the end of the dataset. 00289 */ 00290 if (f_n_id==-1) 00291 break; 00292 00293 /* 00294 * Resize the values vector (usually data in three 00295 * principle directions, i.e. NVALDC = 3). 00296 */ 00297 values.resize(NVALDC); 00298 00299 /* 00300 * Read the meshdata for the respective node. 00301 */ 00302 for (unsigned int data_cnt=0; data_cnt<NVALDC; data_cnt++) 00303 { 00304 /* 00305 * Check what data type we are reading. 00306 * 2,4: Real 00307 * 5,6: Complex 00308 * other data types are not supported yet. 00309 * As again, these floats may also be written 00310 * using a 'D' instead of an 'e'. 00311 */ 00312 if (data_type == 2 || data_type == 4) 00313 { 00314 std::string buf; 00315 in_file >> buf; 00316 MeshDataUnvHeader::need_D_to_e(buf); 00317 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 00318 values[data_cnt] = Complex(std::atof(buf.c_str()), 0.); 00319 #else 00320 values[data_cnt] = std::atof(buf.c_str()); 00321 #endif 00322 } 00323 00324 else if(data_type == 5 || data_type == 6) 00325 00326 { 00327 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 00328 Real re_val, im_val; 00329 00330 std::string buf; 00331 in_file >> buf; 00332 00333 if (MeshDataUnvHeader::need_D_to_e(buf)) 00334 { 00335 re_val = std::atof(buf.c_str()); 00336 in_file >> buf; 00337 MeshDataUnvHeader::need_D_to_e(buf); 00338 im_val = std::atof(buf.c_str()); 00339 } 00340 else 00341 { 00342 re_val = std::atof(buf.c_str()); 00343 in_file >> im_val; 00344 } 00345 00346 values[data_cnt] = Complex(re_val,im_val); 00347 #else 00348 00349 libMesh::err << "ERROR: Complex data only supported" << std::endl 00350 << "when libMesh is configured with --enable-complex!" 00351 << std::endl; 00352 libmesh_error(); 00353 #endif 00354 } 00355 00356 else 00357 { 00358 libMesh::err << "ERROR: Data type not supported." 00359 << std::endl; 00360 libmesh_error(); 00361 } 00362 00363 } // end loop data_cnt 00364 00365 /* 00366 * Add the values vector to the MeshData data structure. 00367 */ 00368 const Node* node = foreign_id_to_node(f_n_id); 00369 _node_data.insert (std::make_pair(node, values)); 00370 00371 } // while(true) 00372 } 00373 00374 00375 else 00376 { 00377 /* 00378 * all other datasets are ignored 00379 */ 00380 } 00381 00382 } 00383 } 00384 00385 00386 /* 00387 * finished reading. Ready for use, provided 00388 * there was any data contained in the file. 00389 */ 00390 libmesh_assert ((this->_node_data.size() != 0) || (this->_elem_data.size() != 0)); 00391 00392 this->_node_data_closed = true; 00393 this->_elem_data_closed = true; 00394 }
| 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(), libMesh::err, foreign_id_to_elem(), foreign_id_to_node(), libMesh::MeshTools::n_elem(), libMesh::DofObject::processor_id(), and libMesh::MeshBase::processor_id().
Referenced by read().
00037 { 00077 // we should better be active or in compatibility mode 00078 libmesh_assert (_active || _compatibility_mode); 00079 00080 00081 // make sure the id maps are ready 00082 libmesh_assert (_node_id_map_closed); 00083 libmesh_assert (_elem_id_map_closed); 00084 00085 00089 this->clear(); 00090 00091 00092 Xdr io(name, mode); 00093 00094 00095 /* 00096 * all processors read the data in the same format, 00097 * but only the processor that owns the element stores 00098 * element-associated data. For nodes, i haven't come 00099 * up with such asmart idea, yet... :-P 00100 */ 00101 const unsigned int proc_id = _mesh.processor_id(); 00102 00103 00104 00110 { 00111 std::string desc = ""; 00112 io.data (desc); 00113 this->_data_descriptor = desc; 00114 } 00115 00116 00117 00123 { 00124 std::string vtype=""; 00125 io.data (vtype); 00126 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 00127 if (vtype != "COMPLEX") 00128 { 00129 libMesh::err << "ERROR: File does not contain complex-valued data!" 00130 << std::endl; 00131 libmesh_error(); 00132 } 00133 #elif LIBMESH_USE_REAL_NUMBERS 00134 if (vtype != "REAL") 00135 { 00136 libMesh::err << "ERROR: File does not contain real-valued data!" 00137 << std::endl; 00138 libmesh_error(); 00139 } 00140 #else 00141 /* 00142 * What number type is this? 00143 */ 00144 libmesh_error(); 00145 #endif 00146 } 00147 00148 00149 00155 unsigned int n_node = 0; 00156 io.data (n_node); 00157 00158 00164 unsigned int n_elem = 0; 00165 io.data (n_elem); 00166 00167 #ifdef DEBUG 00168 unsigned int previous_values_size = 0; 00169 #endif 00170 00171 for (unsigned int n_cnt=0; n_cnt < n_node; n_cnt++) 00172 { 00179 unsigned int f_id = 0; 00180 io.data (f_id); 00181 00182 const Node* node = foreign_id_to_node(f_id); 00183 00184 00191 { 00192 std::vector<Number> values; 00193 io.data (values); 00194 00195 00196 #ifdef DEBUG 00197 /* 00198 * make sure the size of the values vectors 00199 * are identical for all nodes 00200 */ 00201 if (n_cnt == 0) 00202 previous_values_size = values.size(); 00203 else 00204 { 00205 if (previous_values_size != values.size()) 00206 { 00207 libMesh::err << "ERROR: Size mismatch for n_cnt = " << n_cnt << std::endl; 00208 libmesh_error(); 00209 } 00210 } 00211 #endif 00212 00213 00217 _node_data.insert (std::make_pair(node, values)); 00218 } 00219 } 00220 00221 00222 00223 #ifdef DEBUG 00224 previous_values_size = 0; 00225 #endif 00226 00227 for (unsigned int n_cnt=0; n_cnt < n_elem; n_cnt++) 00228 { 00234 unsigned int f_id = 0; 00235 io.data (f_id); 00236 00237 const Elem* elem = foreign_id_to_elem(f_id); 00238 00239 00246 { 00247 std::vector<Number> values; 00248 io.data (values); 00249 00250 00251 #ifdef DEBUG 00252 /* 00253 * make sure the size of the values vectors 00254 * are identical for all elements 00255 */ 00256 if (n_cnt == 0) 00257 previous_values_size = values.size(); 00258 else 00259 { 00260 if (previous_values_size != values.size()) 00261 { 00262 libMesh::err << "ERROR: Size mismatch for n_cnt = " << n_cnt << std::endl; 00263 libmesh_error(); 00264 } 00265 } 00266 #endif 00267 00268 00273 if (elem->processor_id() == proc_id) 00274 _elem_data.insert (std::make_pair(elem, values)); 00275 } 00276 } 00277 00278 00279 /* 00280 * finished reading. Now ready for use, provided 00281 * there was any data contained in the file. 00282 */ 00283 libmesh_assert ((this->_node_data.size() != 0) || (this->_elem_data.size() != 0)); 00284 00285 this->_node_data_closed = true; 00286 this->_elem_data_closed = true; 00287 }
Sets all the data values associated with the element elem, overwriting any existing vector
Definition at line 977 of file mesh_data.h.
References _elem_data.
00979 { 00980 this->_elem_data[elem] = val; 00981 }
Sets all the data values associated with the node node, overwriting any existing vector
Definition at line 894 of file mesh_data.h.
References _node_data.
00896 { 00897 this->_node_data[node] = val; 00898 }
| void libMesh::MeshData::set_unv_header | ( | MeshDataUnvHeader * | unv_header | ) | [inline] |
Set the MeshDataUnvHeader data structure that will be used for output.
Definition at line 1087 of file mesh_data.h.
References _unv_header.
01088 { 01089 libmesh_assert(unv_header); 01090 this->_unv_header = unv_header; 01091 }
| 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(), and libMesh::err.
00124 { 00125 if (this->active()) 00126 { 00127 00128 if (node_id_map) 00129 { 00130 // dumb check 00131 libmesh_assert (_node_id_map_closed); 00132 00133 _node_id_map_closed = false; 00134 _node_id.clear(); 00135 _id_node.clear(); 00136 } 00137 00138 if (elem_id_map) 00139 { 00140 // dumb check 00141 libmesh_assert (_elem_id_map_closed); 00142 00143 _elem_id_map_closed = false; 00144 _elem_id.clear(); 00145 _id_elem.clear(); 00146 } 00147 } 00148 00149 #ifdef DEBUG 00150 else if (this->compatibility_mode()) 00151 { 00152 libMesh::err << "WARNING: No need for MeshData::slim() in compatibility mode." << std::endl; 00153 } 00154 #endif 00155 }
| 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::MeshBase::n_nodes(), n_val_per_node(), libMesh::MeshBase::nodes_begin(), and libMesh::MeshBase::nodes_end().
00163 { 00164 libmesh_assert (_active || _compatibility_mode); 00165 00166 START_LOG("translate()", "MeshData"); 00167 00168 const unsigned int n_comp = this->n_val_per_node(); 00169 00170 // transfer our nodal data to a vector 00171 // that may be written concurrently 00172 // with the \p out_mesh. 00173 { 00174 // reserve memory for the nodal data 00175 values.reserve(n_comp*out_mesh.n_nodes()); 00176 00177 // iterate over the mesh's nodes 00178 MeshBase::const_node_iterator nodes_it = out_mesh.nodes_begin(); 00179 const MeshBase::const_node_iterator nodes_end = out_mesh.nodes_end(); 00180 00181 // Do not use the \p get_data() method, but the operator() 00182 // method, since this returns by default a zero value, 00183 // when there is no nodal data. 00184 for (; nodes_it != nodes_end; ++nodes_it) 00185 { 00186 const Node* node = *nodes_it; 00187 00188 for (unsigned int c= 0; c<n_comp; c++) 00189 values.push_back(this->operator()(node, c)); 00190 } 00191 } 00192 00193 00194 00195 // Now we have the data, nicely stored in \p values. 00196 // It remains to give names to the data, then write to 00197 // file. 00198 { 00199 names.reserve(n_comp); 00200 00201 // this naming scheme only works up to n_comp=100 00202 // (at least for gmv-accepted variable names) 00203 libmesh_assert_less (n_comp, 100); 00204 00205 for (unsigned int n=0; n<n_comp; n++) 00206 { 00207 std::ostringstream name_buf; 00208 name_buf << "bc_" << n; 00209 names.push_back(name_buf.str()); 00210 } 00211 } 00212 00213 STOP_LOG("translate()", "MeshData"); 00214 }
| void libMesh::MeshData::write | ( | const std::string & | name | ) |
Write mesh data to file named name. Guess format from the file extension.
Definition at line 293 of file mesh_data.C.
References _active, _compatibility_mode, _elem_id_map_closed, _node_id_map_closed, compatibility_mode(), libMeshEnums::ENCODE, libMesh::err, libMeshEnums::WRITE, write_unv(), and write_xdr().
00294 { 00295 START_LOG("write()", "MeshData"); 00296 00297 libmesh_assert (_active || _compatibility_mode); 00298 00299 // the id maps have to be closed before writing 00300 // (note that in compatibility mode these are also true) 00301 libmesh_assert (_elem_id_map_closed && _node_id_map_closed); 00302 00303 #ifdef DEBUG 00304 if (this->compatibility_mode()) 00305 libMesh::err << "WARNING: MeshData in compatibility mode. Node and element ids" << std::endl 00306 << " written to file may differ from libMesh numbering" << std::endl 00307 << " next time this file is read!" << std::endl; 00308 #endif 00309 00310 // Read the file based on extension 00311 { 00312 if (name.rfind(".xta") < name.size()) 00313 write_xdr (name, WRITE); 00314 00315 else if (name.rfind(".xtr") < name.size()) 00316 write_xdr (name, ENCODE); 00317 00318 else if (name.rfind(".unv") < name.size()) 00319 write_unv (name); 00320 00321 else 00322 { 00323 libMesh::err << " ERROR: Unrecognized file extension: " << name 00324 << "\n I understand the following:\n\n" 00325 << " *.xta -- Internal ASCII data format\n" 00326 << " *.xtr -- Internal binary data format\n" 00327 << " *.unv -- I-deas format\n" 00328 << std::endl; 00329 libmesh_error(); 00330 00331 } 00332 } 00333 STOP_LOG("write()", "MeshData"); 00334 }
| 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 401 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::err, and write_unv_implementation().
Referenced by write().
00402 { 00403 /* 00404 * we should better be active or in compatibility mode 00405 */ 00406 libmesh_assert (this->_active || this->_compatibility_mode); 00407 00408 /* 00409 * make sure the id maps are ready 00410 * and that we have data to write 00411 */ 00412 libmesh_assert (this->_node_id_map_closed); 00413 libmesh_assert (this->_elem_id_map_closed); 00414 00415 libmesh_assert (this->_node_data_closed); 00416 libmesh_assert (this->_elem_data_closed); 00417 00418 if (file_name.rfind(".gz") < file_name.size()) 00419 { 00420 #ifdef LIBMESH_HAVE_GZSTREAM 00421 ogzstream out_stream(file_name.c_str()); 00422 this->write_unv_implementation (out_stream); 00423 #else 00424 libMesh::err << "ERROR: You must have the zlib.h header " 00425 << "files and libraries to read and write " 00426 << "compressed streams." 00427 << std::endl; 00428 libmesh_error(); 00429 #endif 00430 return; 00431 00432 } 00433 00434 else 00435 { 00436 std::ofstream out_stream(file_name.c_str()); 00437 this->write_unv_implementation (out_stream); 00438 return; 00439 } 00440 }
| 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 447 of file mesh_data_unv_support.C.
References _elem_data, _node_data, _unv_header, libMesh::MeshDataUnvHeader::data_type, libMesh::err, get_data(), has_data(), n_val_per_node(), node_to_foreign_id(), libMesh::MeshDataUnvHeader::nvaldc, and libMesh::MeshDataUnvHeader::write().
Referenced by write_unv().
00448 { 00449 /* 00450 * This is the actual implementation of writing 00451 * unv files, either as .unv or as .unv.gz file 00452 */ 00453 if ( !out_file.good() ) 00454 { 00455 libMesh::err << "ERROR: Output file not good." 00456 << std::endl; 00457 libmesh_error(); 00458 } 00459 00460 00461 /* 00462 * the beginning marker of the dataset block for 00463 * nodal/element-associated data (not to be confused 00464 * with _desired_dataset_label!) 00465 */ 00466 const std::string _label_dataset_mesh_data = "2414"; 00467 00468 /* 00469 * Currently this function handles only nodal data. 00470 */ 00471 libmesh_assert (!_node_data.empty()); 00472 00473 if (!_elem_data.empty()) 00474 libMesh::err << "WARNING: MeshData currently only supports nodal data for Universal files." 00475 << std::endl 00476 << " Will proceed writing only nodal data, ignoring element data." 00477 << std::endl; 00478 00479 00480 /* 00481 * Write the beginning of the dataset. 00482 */ 00483 out_file << " -1\n" 00484 << " " 00485 << _label_dataset_mesh_data 00486 << "\n"; 00487 00488 /* 00489 * Write the header 00490 */ 00491 if (_unv_header==NULL) 00492 { 00493 /* 00494 * create a header that holds at 00495 * least sufficient data to specify 00496 * what this data set currently holds. 00497 * 00498 * The empty constructor automatically 00499 * takes care of \p dataset_location 00500 * and \p data_type. 00501 */ 00502 MeshDataUnvHeader my_header; 00503 00504 /* 00505 * It remains to set the correct nvaldc... 00506 */ 00507 my_header.nvaldc = this->n_val_per_node(); 00508 00509 /* 00510 * and the correct data type. By default 00511 * only distinguish complex or real data. 00512 */ 00513 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 00514 my_header.data_type = 5; 00515 #else 00516 my_header.data_type = 2; 00517 #endif 00518 00519 /* 00520 * write this default header, then let 00521 * the AutoPtr go out of scope. This 00522 * will take care of memory management. 00523 */ 00524 my_header.write (out_file); 00525 } 00526 00527 else 00528 { 00529 /* 00530 * make sure our nvaldc coincide. 00531 */ 00532 if (this->n_val_per_node() != _unv_header->nvaldc) 00533 { 00534 libMesh::err << "WARNING: nvaldc=" << _unv_header->nvaldc 00535 << " of attached MeshDataUnvHeader object not valid!" << std::endl 00536 << " re-set nvaldc to " << this->n_val_per_node() << std::endl; 00537 _unv_header->nvaldc = this->n_val_per_node(); 00538 } 00539 00540 00541 /* 00542 * only issue a warning when data_type does 00543 * not coincide. Perhaps user provided some 00544 * other header in order to convert complex 00545 * to real... 00546 */ 00547 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 00548 const unsigned int my_data_type = 5; 00549 #else 00550 const unsigned int my_data_type = 2; 00551 #endif 00552 if (my_data_type != _unv_header->data_type) 00553 { 00554 libMesh::err << "WARNING: data_type=" << _unv_header->data_type 00555 << " of attached MeshDataUnvHeader differs from" << std::endl 00556 << " default value=" << my_data_type 00557 << " Perhaps the user wanted this," << std::endl 00558 << " so I use the value from the MeshDataUnvHeader." 00559 << std::endl; 00560 } 00561 _unv_header->write (out_file); 00562 } 00563 00564 00565 /* 00566 * Write the foreign node number and the respective data. 00567 */ 00568 std::map<const Node*, 00569 std::vector<Number> >::const_iterator nit = _node_data.begin(); 00570 00571 char buf[27]; 00572 for (; nit != _node_data.end(); ++nit) 00573 { 00574 const Node* node = (*nit).first; 00575 00576 unsigned int f_n_id = node_to_foreign_id (node); 00577 std::sprintf(buf, "%10i\n", f_n_id); 00578 out_file << buf; 00579 00580 /* since we are iterating over our own map, this libmesh_assert 00581 * should never break... 00582 */ 00583 libmesh_assert (this->has_data(node)); 00584 00585 // const reference to the nodal values 00586 const std::vector<Number>& values = this->get_data(node); 00587 00588 for (unsigned int v_cnt=0; v_cnt<values.size(); v_cnt++) 00589 { 00590 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 00591 std::sprintf(buf, "%13.5E%13.5E", values[v_cnt].real(), 00592 values[v_cnt].imag()); 00593 out_file << buf; 00594 #else 00595 std::sprintf(buf, "%13.5E", 00596 static_cast<double>(values[v_cnt])); 00597 out_file << buf; 00598 #endif 00599 } 00600 00601 out_file << "\n"; 00602 00603 00604 } 00605 00606 /* 00607 * Write end of the dataset. 00608 */ 00609 out_file << " -1\n"; 00610 }
| 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 294 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::MeshTools::n_elem(), and node_to_foreign_id().
Referenced by write().
00296 { 00335 /* 00336 * make sure the id maps are ready 00337 * and that we have data to write 00338 */ 00339 libmesh_assert (_node_id_map_closed); 00340 libmesh_assert (_elem_id_map_closed); 00341 00342 libmesh_assert (_node_data_closed); 00343 libmesh_assert (_elem_data_closed); 00344 00345 00346 Xdr io(name, mode); 00347 00348 00349 // all processors write the data in the same format 00350 //const unsigned int proc_id = _mesh.processor_id(); 00351 00357 { 00358 std::string desc = this->_data_descriptor; 00359 io.data (desc, "# Data description"); 00360 } 00361 00362 00363 00369 { 00370 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 00371 std::string desc = "COMPLEX"; 00372 #elif LIBMESH_USE_REAL_NUMBERS 00373 std::string desc = "REAL"; 00374 #else 00375 better_you_choke_this... 00376 #endif 00377 io.data (desc, "# type of values"); 00378 } 00379 00380 00381 00387 { 00388 unsigned int n_node = this->_node_data.size(); 00389 io.data (n_node, "# No. of nodes for which data is stored"); 00390 } 00391 00392 00398 { 00399 unsigned int n_elem = this->_elem_data.size(); 00400 io.data (n_elem, "# No. of elements for which data is stored"); 00401 } 00402 00403 00404 00405 00406 std::map<const Node*, 00407 std::vector<Number> >::const_iterator nit = _node_data.begin (); 00408 00409 for (; nit != _node_data.end(); ++nit) 00410 { 00411 const Node* node = (*nit).first; 00412 00418 { 00419 unsigned int f_id = node_to_foreign_id (node); 00420 io.data (f_id, "# Foreign node id"); 00421 } 00422 00423 00429 { 00430 /* 00431 * since we are iterating over our @e own 00432 * map, this libmesh_assert should never break... 00433 */ 00434 libmesh_assert (this->has_data(node)); 00435 00436 const std::vector<Number>& values = this->get_data(node); 00437 00438 /* 00439 * copy the data to a local buf, since 00440 * the Xdr class needs write access, even 00441 * when only reading data 00442 */ 00443 std::vector<Number> buf = values; 00444 io.data (buf, "# Values"); 00445 } 00446 } 00447 00448 00449 00450 00451 00452 00453 00454 std::map<const Elem*, 00455 std::vector<Number> >::const_iterator eit = _elem_data.begin (); 00456 00457 for (; eit != _elem_data.end(); ++eit) 00458 { 00459 const Elem* elem = (*eit).first; 00460 00466 { 00467 unsigned int f_id = elem_to_foreign_id (elem); 00468 io.data (f_id, "# Foreign element id"); 00469 } 00470 00471 00477 { 00478 /* 00479 * since we are iterating over our @e own 00480 * map, this libmesh_assert should never break... 00481 */ 00482 libmesh_assert (this->has_data(elem)); 00483 00484 const std::vector<Number>& values = this->get_data(elem); 00485 00486 /* 00487 * copy the data to a local buf, since 00488 * the Xdr class needs write access, even 00489 * when only reading data 00490 */ 00491 std::vector<Number> buf = values; 00492 io.data (buf, "# Values"); 00493 } 00494 } 00495 }
Friends And Related Function Documentation
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.
Member Data Documentation
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().
The documentation for this class was generated from the following files:
Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:29 UTC
Hosted By: