mesh_data.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_MESH_DATA_H
21 #define LIBMESH_MESH_DATA_H
22 
23 // Local Includes
24 #include "libmesh/libmesh.h"
25 #include "libmesh/enum_xdr_mode.h"
26 
27 // C++ includes
28 #include <cstddef>
29 #include <map>
30 #include <vector>
31 
32 namespace libMesh
33 {
34 
35 
36 // Forward Declarations
37 class Node;
38 class Elem;
39 class MeshBase;
40 class MeshDataUnvHeader;
41 
42 
56 // ------------------------------------------------------------
57 // MeshData class definition
58 class MeshData
59 {
60 public:
61 
62 
63  //----------------------------------------------------------
64  // convenient typedefs
73  typedef std::map<const Node*, std::vector<Number> >::const_iterator const_node_data_iterator;
74 
83  typedef std::map<const Elem*, std::vector<Number> >::const_iterator const_elem_data_iterator;
84 
85 
86  //----------------------------------------------------------
91  MeshData (const MeshBase& m);
92 
96  ~MeshData ();
97 
107  void activate (const std::string& descriptor="");
108 
121  void enable_compatibility_mode (const std::string& descriptor="");
122 
128  void clear ();
129 
138  void slim (const bool node_id_map = true,
139  const bool elem_id_map = true);
140 
155  void translate (const MeshBase& out_mesh,
156  std::vector<Number>& data_values,
157  std::vector<std::string>& data_names) const;
158 
165  void read (const std::string& name);
166 
171  void write (const std::string& name);
172 
177  std::string get_info () const;
178 
182  void print_info (std::ostream& os=libMesh::out) const;
183 
187  friend std::ostream& operator << (std::ostream& os, const MeshData& m);
188 
189 
190  //----------------------------------------------------------
191  // Node-associated data
197  Number operator() (const Node* node,
198  const unsigned int i=0) const;
199 
204  bool has_data (const Node* node) const;
205 
212  const std::vector<Number>& get_data (const Node* node) const;
213 
218  void set_data (const Node* node, const std::vector<Number>& val);
219 
227  unsigned int n_val_per_node () const;
228 
233  unsigned int n_node_data () const;
234 
241 
247 
263  void insert_node_data (std::map<const Node*,
264  std::vector<Number> >& nd,
265  const bool close_elem_data = true);
266 
267 
268  //----------------------------------------------------------
269  // Element-associated data
275  Number operator() (const Elem* elem,
276  const unsigned int i=0) const;
277 
282  bool has_data (const Elem* elem) const;
283 
290  const std::vector<Number>& get_data (const Elem* elem) const;
291 
296  void set_data (const Elem* elem, const std::vector<Number> &val);
297 
305  unsigned int n_val_per_elem () const;
306 
311  unsigned int n_elem_data () const;
312 
319 
325 
342  void insert_elem_data (std::map<const Elem*,
343  std::vector<Number> >& ed,
344  const bool close_node_data = true);
345 
346 
347  //----------------------------------------------------------
352  bool active () const;
357  bool compatibility_mode () const;
358 
364  bool elem_initialized () const;
365 
370  bool node_initialized () const;
371 
372 
373  //----------------------------------------------------------
374  // Methods for accessing the node and element maps.
375  // Heavily used by the \p read() and \p write() methods.
379  const Node* foreign_id_to_node (const unsigned int fid) const;
380 
384  const Elem* foreign_id_to_elem (const unsigned int fid) const;
385 
389  unsigned int node_to_foreign_id (const Node* n) const;
390 
394  unsigned int elem_to_foreign_id (const Elem* n) const;
395 
396  //----------------------------------------------------------
397  // Methods for the header information in universal formated
398  // datasets.
399 
403  const MeshDataUnvHeader & get_unv_header() const;
404 
409  void set_unv_header(MeshDataUnvHeader* unv_header);
410 
411 
418  void assign (const MeshData& omd);
419 
420 
421  //----------------------------------------------------------
422  // Methods used by mesh importes to communicate node/element
423  // labels to this \p MeshData
424 
432  void add_foreign_node_id (const Node* node,
433  const unsigned int foreign_node_id);
434 
442  void add_foreign_elem_id (const Elem* elem,
443  const unsigned int foreign_elem_id);
444 
449  void close_foreign_id_maps ();
450 
451 
452 protected:
453 
454 
455  //----------------------------------------------------------
456  // read/write Methods
460  void read_tetgen (const std::string& name);
461 
467  void read_unv (const std::string& file_name);
468 
475  void read_unv_implementation (std::istream& in_file);
476 
482  void write_unv (const std::string& file_name);
483 
490  void write_unv_implementation (std::ostream& out_file);
491 
492 
500  void read_xdr (const std::string& name,
501  const XdrMODE mode = READ);
502 
509  void write_xdr (const std::string& name,
510  const XdrMODE mode = WRITE);
511 
512 
516  const MeshBase& _mesh;
517 
522  std::string _data_descriptor;
523 
524 
525  //--------------------------------------------------
526  // node associated data & maps
531  std::map<const Node*,
532  std::vector<Number> > _node_data;
533 
538  std::map<const Node*,
539  unsigned int> _node_id;
540 
545  std::map<unsigned int,
546  const Node*> _id_node;
547 
548 
549 
550  //--------------------------------------------------
551  // element associated data & maps
555  std::map<const Elem*,
556  std::vector<Number> > _elem_data;
557 
562  std::map<const Elem*,
563  unsigned int> _elem_id;
568  std::map<unsigned int,
569  const Elem*> _id_elem;
570 
571 
572 
573  //--------------------------------------------------------
583 
589 
590 
591  //--------------------------------------------------------
601 
607 
608 
609  //--------------------------------------------------------
614  bool _active;
615 
622 
627 
631  friend class MeshDataUnvHeader;
632 
633 };
634 
635 
636 
637 //-----------------------------------------------------------
638 // MeshDataUnvHeader class definition
639 
684 {
685 public:
686 
692 
697 
712  void which_dataset (const unsigned int ds_label);
713 
718  void operator = (const MeshDataUnvHeader& omduh);
719 
724  bool operator == (const MeshDataUnvHeader& omduh) const;
725 
729  unsigned int dataset_label;
730 
734  std::string dataset_name;
735 
740  unsigned int dataset_location;
741 
745  std::vector<std::string> id_lines_1_to_5;
746 
756  unsigned int model_type,
759  result_type;
760 
766  unsigned int data_type;
767 
772  unsigned int nvaldc;
773 
778  std::vector<int> record_10,
779  record_11;
780 
785  std::vector<Real> record_12,
786  record_13;
787 
788 
789 protected:
790 
799  bool read (std::istream& in_file);
800 
804  void write (std::ostream& out_file);
805 
806 
807 private:
808 
814 
821  static bool need_D_to_e (std::string& number);
822 
826  friend class MeshData;
827 
828 };
829 
830 
831 
832 // ------------------------------------------------------------
833 // MeshData inline methods
834 
835 //-------------------------------------------------------------
836 // element data inline methods
837 inline
839  const unsigned int i) const
840 {
843 
844  std::map<const Node*,
845  std::vector<Number> >::const_iterator pos = _node_data.find(node);
846 
847  if (pos == _node_data.end())
848  return libMesh::zero;
849 
850  // we only get here when pos != _node_data.end()
851  libmesh_assert_less (i, pos->second.size());
852  return pos->second[i];
853 }
854 
855 
856 
857 inline
858 bool MeshData::has_data (const Node* node) const
859 {
862 
863  std::map<const Node*,
864  std::vector<Number> >::const_iterator pos = _node_data.find(node);
865 
866  return (pos != _node_data.end());
867 }
868 
869 
870 
871 inline
872 const std::vector<Number>& MeshData::get_data (const Node* node) const
873 {
876 
877  std::map<const Node*,
878  std::vector<Number> >::const_iterator pos = _node_data.find(node);
879 
880 #ifdef DEBUG
881  if (pos == _node_data.end())
882  {
883  libMesh::err << "ERROR: No data for this node. Use has_data() first!" << std::endl;
884  libmesh_error();
885  }
886 #endif
887 
888  return pos->second;
889 }
890 
891 
892 
893 inline
894 void MeshData::set_data (const Node* node,
895  const std::vector<Number> &val)
896 {
897  this->_node_data[node] = val;
898 }
899 
900 
901 
902 inline
904 {
905  return _node_data.begin();
906 }
907 
908 
909 
910 inline
912 {
913  return _node_data.end();
914 }
915 
916 
917 
918 //-------------------------------------------------------------
919 // element data inline methods
920 inline
922  const unsigned int i) const
923 {
926 
927  std::map<const Elem*,
928  std::vector<Number> >::const_iterator pos = _elem_data.find(elem);
929 
930  if (pos == _elem_data.end())
931  return libMesh::zero;
932 
933  // we only get here when pos != _elem_data.end()
934  libmesh_assert_less (i, pos->second.size());
935  return pos->second[i];
936 }
937 
938 
939 
940 inline
941 bool MeshData::has_data (const Elem* elem) const
942 {
945 
946  std::map<const Elem*,
947  std::vector<Number> >::const_iterator pos = _elem_data.find(elem);
948 
949  return (pos != _elem_data.end());
950 }
951 
952 
953 
954 inline
955 const std::vector<Number>& MeshData::get_data (const Elem* elem) const
956 {
959 
960  std::map<const Elem*,
961  std::vector<Number> >::const_iterator pos = _elem_data.find(elem);
962 
963 #ifdef DEBUG
964  if (pos == _elem_data.end())
965  {
966  libMesh::err << "ERROR: No data for this element. Use has_data() first!" << std::endl;
967  libmesh_error();
968  }
969 #endif
970 
971  return pos->second;
972 }
973 
974 
975 
976 inline
977 void MeshData::set_data (const Elem* elem,
978  const std::vector<Number> &val)
979 {
980  this->_elem_data[elem] = val;
981 }
982 
983 
984 
985 inline
987 {
988  return _elem_data.begin();
989 }
990 
991 
992 
993 inline
995 {
996  return _elem_data.end();
997 }
998 
999 
1000 
1001 //-------------------------------------------------------------
1002 // other inline methods
1003 inline
1004 bool MeshData::active() const
1005 {
1006  return _active;
1007 }
1008 
1009 
1010 
1011 inline
1013 {
1014  return _compatibility_mode;
1015 }
1016 
1017 
1018 
1019 inline
1021 {
1022  return (_active && _elem_data_closed);
1023 }
1024 
1025 
1026 
1027 inline
1029 {
1030  return (_active && _node_data_closed);
1031 }
1032 
1033 
1034 
1035 inline
1037  const unsigned int foreign_node_id)
1038 {
1039  if (_active)
1040  {
1042  libmesh_assert(node);
1043  libmesh_assert (_node_id.find(node) == _node_id.end());
1044  libmesh_assert (_id_node.find(foreign_node_id) == _id_node.end());
1045 
1046  /*
1047  * _always_ insert in _id_node and _node_id. If we would
1048  * use the mesh.node(unsigned int) method or the node.id()
1049  * to get Node* and unsigned int, respectively, we would not
1050  * be safe any more when the mesh gets refined or re-numbered
1051  * within libMesh. And we could get in big trouble that would
1052  * be hard to find when importing data _after_ having refined...
1053  */
1054  _node_id.insert(std::make_pair(node, foreign_node_id));
1055  _id_node.insert(std::make_pair(foreign_node_id, node));
1056  }
1057 }
1058 
1059 
1060 
1061 inline
1063  const unsigned int foreign_elem_id)
1064 {
1065  if (_active)
1066  {
1068  libmesh_assert(elem);
1069  libmesh_assert (_elem_id.find(elem) == _elem_id.end());
1070  libmesh_assert (_id_elem.find(foreign_elem_id) == _id_elem.end());
1071 
1072  _elem_id.insert(std::make_pair(elem, foreign_elem_id));
1073  _id_elem.insert(std::make_pair(foreign_elem_id, elem));
1074  }
1075 }
1076 
1077 
1078 inline
1080 {
1081  libmesh_assert(this->_unv_header);
1082  return *this->_unv_header;
1083 }
1084 
1085 
1086 inline
1088 {
1089  libmesh_assert(unv_header);
1090  this->_unv_header = unv_header;
1091 }
1092 
1093 
1094 //-----------------------------------------------------------
1095 // MeshDataUnvHeader inline methods
1096 
1097 
1098 } // namespace libMesh
1099 
1100 #endif // LIBMESH_MESH_DATA_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:06 UTC

Hosted By:
SourceForge.net Logo