mesh_data.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_MESH_DATA_H 00021 #define LIBMESH_MESH_DATA_H 00022 00023 // Local Includes 00024 #include "libmesh/libmesh.h" 00025 #include "libmesh/enum_xdr_mode.h" 00026 00027 // C++ includes 00028 #include <cstddef> 00029 #include <map> 00030 #include <vector> 00031 00032 namespace libMesh 00033 { 00034 00035 00036 // Forward Declarations 00037 class Node; 00038 class Elem; 00039 class MeshBase; 00040 class MeshDataUnvHeader; 00041 00042 00056 // ------------------------------------------------------------ 00057 // MeshData class definition 00058 class MeshData 00059 { 00060 public: 00061 00062 00063 //---------------------------------------------------------- 00064 // convenient typedefs 00073 typedef std::map<const Node*, std::vector<Number> >::const_iterator const_node_data_iterator; 00074 00083 typedef std::map<const Elem*, std::vector<Number> >::const_iterator const_elem_data_iterator; 00084 00085 00086 //---------------------------------------------------------- 00091 MeshData (const MeshBase& m); 00092 00096 ~MeshData (); 00097 00107 void activate (const std::string& descriptor=""); 00108 00121 void enable_compatibility_mode (const std::string& descriptor=""); 00122 00128 void clear (); 00129 00138 void slim (const bool node_id_map = true, 00139 const bool elem_id_map = true); 00140 00155 void translate (const MeshBase& out_mesh, 00156 std::vector<Number>& data_values, 00157 std::vector<std::string>& data_names) const; 00158 00165 void read (const std::string& name); 00166 00171 void write (const std::string& name); 00172 00177 std::string get_info () const; 00178 00182 void print_info (std::ostream& os=libMesh::out) const; 00183 00187 friend std::ostream& operator << (std::ostream& os, const MeshData& m); 00188 00189 00190 //---------------------------------------------------------- 00191 // Node-associated data 00197 Number operator() (const Node* node, 00198 const unsigned int i=0) const; 00199 00204 bool has_data (const Node* node) const; 00205 00212 const std::vector<Number>& get_data (const Node* node) const; 00213 00218 void set_data (const Node* node, const std::vector<Number>& val); 00219 00227 unsigned int n_val_per_node () const; 00228 00233 unsigned int n_node_data () const; 00234 00240 const_node_data_iterator node_data_begin () const; 00241 00246 const_node_data_iterator node_data_end () const; 00247 00263 void insert_node_data (std::map<const Node*, 00264 std::vector<Number> >& nd, 00265 const bool close_elem_data = true); 00266 00267 00268 //---------------------------------------------------------- 00269 // Element-associated data 00275 Number operator() (const Elem* elem, 00276 const unsigned int i=0) const; 00277 00282 bool has_data (const Elem* elem) const; 00283 00290 const std::vector<Number>& get_data (const Elem* elem) const; 00291 00296 void set_data (const Elem* elem, const std::vector<Number> &val); 00297 00305 unsigned int n_val_per_elem () const; 00306 00311 unsigned int n_elem_data () const; 00312 00318 const_elem_data_iterator elem_data_begin () const; 00319 00324 const_elem_data_iterator elem_data_end () const; 00325 00342 void insert_elem_data (std::map<const Elem*, 00343 std::vector<Number> >& ed, 00344 const bool close_node_data = true); 00345 00346 00347 //---------------------------------------------------------- 00352 bool active () const; 00357 bool compatibility_mode () const; 00358 00364 bool elem_initialized () const; 00365 00370 bool node_initialized () const; 00371 00372 00373 //---------------------------------------------------------- 00374 // Methods for accessing the node and element maps. 00375 // Heavily used by the \p read() and \p write() methods. 00379 const Node* foreign_id_to_node (const unsigned int fid) const; 00380 00384 const Elem* foreign_id_to_elem (const unsigned int fid) const; 00385 00389 unsigned int node_to_foreign_id (const Node* n) const; 00390 00394 unsigned int elem_to_foreign_id (const Elem* n) const; 00395 00396 //---------------------------------------------------------- 00397 // Methods for the header information in universal formated 00398 // datasets. 00399 00403 const MeshDataUnvHeader & get_unv_header() const; 00404 00409 void set_unv_header(MeshDataUnvHeader* unv_header); 00410 00411 00418 void assign (const MeshData& omd); 00419 00420 00421 //---------------------------------------------------------- 00422 // Methods used by mesh importes to communicate node/element 00423 // labels to this \p MeshData 00424 00432 void add_foreign_node_id (const Node* node, 00433 const unsigned int foreign_node_id); 00434 00442 void add_foreign_elem_id (const Elem* elem, 00443 const unsigned int foreign_elem_id); 00444 00449 void close_foreign_id_maps (); 00450 00451 00452 protected: 00453 00454 00455 //---------------------------------------------------------- 00456 // read/write Methods 00460 void read_tetgen (const std::string& name); 00461 00467 void read_unv (const std::string& file_name); 00468 00475 void read_unv_implementation (std::istream& in_file); 00476 00482 void write_unv (const std::string& file_name); 00483 00490 void write_unv_implementation (std::ostream& out_file); 00491 00492 00500 void read_xdr (const std::string& name, 00501 const XdrMODE mode = READ); 00502 00509 void write_xdr (const std::string& name, 00510 const XdrMODE mode = WRITE); 00511 00512 00516 const MeshBase& _mesh; 00517 00522 std::string _data_descriptor; 00523 00524 00525 //-------------------------------------------------- 00526 // node associated data & maps 00531 std::map<const Node*, 00532 std::vector<Number> > _node_data; 00533 00538 std::map<const Node*, 00539 unsigned int> _node_id; 00540 00545 std::map<unsigned int, 00546 const Node*> _id_node; 00547 00548 00549 00550 //-------------------------------------------------- 00551 // element associated data & maps 00555 std::map<const Elem*, 00556 std::vector<Number> > _elem_data; 00557 00562 std::map<const Elem*, 00563 unsigned int> _elem_id; 00568 std::map<unsigned int, 00569 const Elem*> _id_elem; 00570 00571 00572 00573 //-------------------------------------------------------- 00582 bool _node_id_map_closed; 00583 00588 bool _node_data_closed; 00589 00590 00591 //-------------------------------------------------------- 00600 bool _elem_id_map_closed; 00601 00606 bool _elem_data_closed; 00607 00608 00609 //-------------------------------------------------------- 00614 bool _active; 00615 00621 bool _compatibility_mode; 00622 00626 MeshDataUnvHeader* _unv_header; 00627 00631 friend class MeshDataUnvHeader; 00632 00633 }; 00634 00635 00636 00637 //----------------------------------------------------------- 00638 // MeshDataUnvHeader class definition 00639 00683 class MeshDataUnvHeader 00684 { 00685 public: 00686 00691 MeshDataUnvHeader (); 00692 00696 ~MeshDataUnvHeader (); 00697 00712 void which_dataset (const unsigned int ds_label); 00713 00718 void operator = (const MeshDataUnvHeader& omduh); 00719 00724 bool operator == (const MeshDataUnvHeader& omduh) const; 00725 00729 unsigned int dataset_label; 00730 00734 std::string dataset_name; 00735 00740 unsigned int dataset_location; 00741 00745 std::vector<std::string> id_lines_1_to_5; 00746 00756 unsigned int model_type, 00757 analysis_type, 00758 data_characteristic, 00759 result_type; 00760 00766 unsigned int data_type; 00767 00772 unsigned int nvaldc; 00773 00778 std::vector<int> record_10, 00779 record_11; 00780 00785 std::vector<Real> record_12, 00786 record_13; 00787 00788 00789 protected: 00790 00799 bool read (std::istream& in_file); 00800 00804 void write (std::ostream& out_file); 00805 00806 00807 private: 00808 00813 unsigned int _desired_dataset_label; 00814 00821 static bool need_D_to_e (std::string& number); 00822 00826 friend class MeshData; 00827 00828 }; 00829 00830 00831 00832 // ------------------------------------------------------------ 00833 // MeshData inline methods 00834 00835 //------------------------------------------------------------- 00836 // element data inline methods 00837 inline 00838 Number MeshData::operator() (const Node* node, 00839 const unsigned int i) const 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 } 00854 00855 00856 00857 inline 00858 bool MeshData::has_data (const Node* node) const 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 } 00868 00869 00870 00871 inline 00872 const std::vector<Number>& MeshData::get_data (const Node* node) const 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 } 00890 00891 00892 00893 inline 00894 void MeshData::set_data (const Node* node, 00895 const std::vector<Number> &val) 00896 { 00897 this->_node_data[node] = val; 00898 } 00899 00900 00901 00902 inline 00903 MeshData::const_node_data_iterator MeshData::node_data_begin () const 00904 { 00905 return _node_data.begin(); 00906 } 00907 00908 00909 00910 inline 00911 MeshData::const_node_data_iterator MeshData::node_data_end () const 00912 { 00913 return _node_data.end(); 00914 } 00915 00916 00917 00918 //------------------------------------------------------------- 00919 // element data inline methods 00920 inline 00921 Number MeshData::operator() (const Elem* elem, 00922 const unsigned int i) const 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 } 00937 00938 00939 00940 inline 00941 bool MeshData::has_data (const Elem* elem) const 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 } 00951 00952 00953 00954 inline 00955 const std::vector<Number>& MeshData::get_data (const Elem* elem) const 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 } 00973 00974 00975 00976 inline 00977 void MeshData::set_data (const Elem* elem, 00978 const std::vector<Number> &val) 00979 { 00980 this->_elem_data[elem] = val; 00981 } 00982 00983 00984 00985 inline 00986 MeshData::const_elem_data_iterator MeshData::elem_data_begin () const 00987 { 00988 return _elem_data.begin(); 00989 } 00990 00991 00992 00993 inline 00994 MeshData::const_elem_data_iterator MeshData::elem_data_end () const 00995 { 00996 return _elem_data.end(); 00997 } 00998 00999 01000 01001 //------------------------------------------------------------- 01002 // other inline methods 01003 inline 01004 bool MeshData::active() const 01005 { 01006 return _active; 01007 } 01008 01009 01010 01011 inline 01012 bool MeshData::compatibility_mode() const 01013 { 01014 return _compatibility_mode; 01015 } 01016 01017 01018 01019 inline 01020 bool MeshData::elem_initialized() const 01021 { 01022 return (_active && _elem_data_closed); 01023 } 01024 01025 01026 01027 inline 01028 bool MeshData::node_initialized() const 01029 { 01030 return (_active && _node_data_closed); 01031 } 01032 01033 01034 01035 inline 01036 void MeshData::add_foreign_node_id (const Node* node, 01037 const unsigned int foreign_node_id) 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 } 01058 01059 01060 01061 inline 01062 void MeshData::add_foreign_elem_id (const Elem* elem, 01063 const unsigned int foreign_elem_id) 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 } 01076 01077 01078 inline 01079 const MeshDataUnvHeader & MeshData::get_unv_header () const 01080 { 01081 libmesh_assert(this->_unv_header); 01082 return *this->_unv_header; 01083 } 01084 01085 01086 inline 01087 void MeshData::set_unv_header (MeshDataUnvHeader* unv_header) 01088 { 01089 libmesh_assert(unv_header); 01090 this->_unv_header = unv_header; 01091 } 01092 01093 01094 //----------------------------------------------------------- 01095 // MeshDataUnvHeader inline methods 01096 01097 01098 } // namespace libMesh 01099 01100 #endif // LIBMESH_MESH_DATA_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:47 UTC
Hosted By: