meshImport.hh

Go to the documentation of this file.
1 
6 #ifndef meshImport_hh
7 #define meshImport_hh
8 
9 #include <vector>
10 #include "mesh.hh"
11 #include "toolbox/array.hh"
12 #include "toolbox/multiArray.hh"
14 #include "basics/debug.hh"
15 
16 #define ImportMeshReadInts_D 0
17 #define ImportMeshReadLine_D 0
18 
19 namespace concepts {
20 
21  // ************************************************************ ImportMesh **
22 
32  class ImportMesh {
33  public:
37  ImportMesh(const uint idxStart = 1)
38  : idxStart_(idxStart), Edg_(true), twoAttr_(true), threeAttr_(true),
39  fourAttr_(true), sixAttr_(true), eightAttr_(true) {}
40  virtual ~ImportMesh();
41  protected:
43  const uint idxStart_;
44 
46  std::vector<Vertex*> vtx_;
47  std::vector<Connector1*> edg_;
49  MultiArray<1, Vertex*> Vtx_; // map from vertex index in the file to Vertex
50  MultiArray<2, Edge*> Edg_; // map from vertex indices in the file to Edge
51 
59 
61  virtual void createEntity_(const MultiIndex<1>& idx);
62  virtual void createEntity_(const MultiIndex<2>& idx);
67  virtual void createEntity_(const MultiIndex<3>& idx)
69  virtual void createEntity_(const MultiIndex<4>& idx)
71  virtual void createEntity_(const MultiIndex<6>& idx)
73  virtual void createEntity_(const MultiIndex<8>& idx)
75 
80  virtual void createCell_(const MultiIndex<2>& idx)
82  virtual void createCell_(const MultiIndex<3>& idx)
84  virtual void createCell_(const MultiIndex<4>& idx)
86  virtual void createCell_(const MultiIndex<6>& idx)
88  virtual void createCell_(const MultiIndex<8>& idx)
90 
94  uint readInts_(const std::string& i, std::vector<int>& v) const;
101  template<class F>
102  uint readLine_(const std::string& i, Array<F>& a,
103  bool first = false) const;
104 
108  void readCells_(const std::string& elms, const Array<bool>& dimensions,
109  const std::vector<Real3d>& vertices);
111  template<uint dim>
113 
114  void readAttributes_(const std::string& bound,
115  const Array<bool>& dimensions);
116 
118  template<class T>
119  void clear_(std::vector<T*>& field);
120  };
121 
122  template<class F>
123  uint ImportMesh::readLine_(const std::string& i, Array<F>& a,
124  bool first) const {
125  std::istringstream input(i.c_str());
126  F number = 0;
128  std::vector<F> v;
129  if (!first) input >> number;
130  while (input >> number) {
131  v.push_back(number);
132  DEBUGL(ImportMeshReadLine_D, "inserted " << v.back());
133  }
134  a.resize(v.size());
135  for(uint i = 0; i < a.size(); ++i) a[i] = v[i];
136  DEBUGL(ImportMeshReadLine_D, "array = " << a);
137  return a.size();
138  }
139 
140  template<class T>
141  void ImportMesh::clear_(std::vector<T*>& field) {
142  for (typename std::vector<T*>::iterator i = field.begin();
143  i != field.end(); ++i) {
144  delete *i; *i = 0;
145  }
146  }
147 
148  template<class T>
149  std::ostream& operator<<(std::ostream& os, const std::vector<T*>& field) {
150  uint j=0;
151  for (typename std::vector<T*>::const_iterator i = field.begin();
152  i != field.end(); ++j) {
153  if (i != field.begin()) os << ", ";
154  T* val = *i++;
155  os << '(' << j << ',';
156  if (val) os << *val; else os << '0';
157  os << ')';
158  }
159  return os;
160  }
161 
162 } // namespace concepts
163 
164 #endif // meshImport_hh
uint size() const
Returns the requested size of the array.
Definition: array.hh:259
virtual void createEntity_(const MultiIndex< 8 > &idx)
virtual void createEntity_(const MultiIndex< 2 > &idx)
MultiArray< 4, Attribute > fourAttr_
Definition: meshImport.hh:56
std::vector< Connector1 * > edg_
Definition: meshImport.hh:47
const uint idxStart_
Starting point of indices in the files (1 or 0)
Definition: meshImport.hh:43
MultiArray< 1, Attribute > oneAttr_
Attributes of entities.
Definition: meshImport.hh:53
void clear_(std::vector< T * > &field)
Deletes the content of field of pointers.
Definition: meshImport.hh:141
virtual void createCell_(const MultiIndex< 8 > &idx)
#define ImportMeshReadLine_D
Definition: meshImport.hh:17
virtual void createCell_(const MultiIndex< 3 > &idx)
MultiArray< 1, Vertex * > Vtx_
Array of the entities.
Definition: meshImport.hh:49
#define DEBUGL(doit, msg)
std::vector< Vertex * > vtx_
List of entities.
Definition: meshImport.hh:46
uint readInts_(const std::string &i, std::vector< int > &v) const
Reads integers from the string.
MultiArray< 2, Attribute > twoAttr_
Definition: meshImport.hh:54
ImportMesh(const uint idxStart=1)
Constructor.
Definition: meshImport.hh:37
An array of objects.
Definition: bilinearForm.hh:23
virtual void createCell_(const MultiIndex< 6 > &idx)
void readAttributes_(const std::string &bound, const Array< bool > &dimensions)
Base class for reading a mesh from a file.
Definition: meshImport.hh:32
std::ostream & operator<<(std::ostream &os, const Level< dim > &c)
Name traits for number types.
Definition: typedefs.hh:68
Container typename for multidimensional Array which is based on std::map.
Definition: multiArray.hh:33
uint readLine_(const std::string &i, Array< F > &a, bool first=false) const
Reads line of numbers from the string.
Definition: meshImport.hh:123
void newCell_(MultiIndex< dim > i)
Creates topological entities and a geometrical cell.
void resize(const uint sz)
Resizes the array.
Definition: array.hh:281
virtual void createEntity_(const MultiIndex< 4 > &idx)
Exception class to express a missing feature.
Definition: exceptions.hh:206
virtual void createEntity_(const MultiIndex< 3 > &idx)
Creation of topological entities.
MultiArray< 8, Attribute > eightAttr_
Definition: meshImport.hh:58
virtual void createCell_(const MultiIndex< 2 > &idx)
Creation of geometrical cells with element mapping.
MultiArray< 6, Attribute > sixAttr_
Definition: meshImport.hh:57
void readCells_(const std::string &elms, const Array< bool > &dimensions, const std::vector< Real3d > &vertices)
Reads the file with cell information and creates topological entities and geometrical cells.
MultiArray< 2, Edge * > Edg_
Definition: meshImport.hh:50
MultiArray< 3, Attribute > threeAttr_
Definition: meshImport.hh:55
virtual void createCell_(const MultiIndex< 4 > &idx)
virtual void createEntity_(const MultiIndex< 6 > &idx)
virtual void createEntity_(const MultiIndex< 1 > &idx)
Creation of topological entities Vertex and Edge.
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich