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