jacobi_oo_STL
geom.h
Go to the documentation of this file.
1 #ifndef GEOM_FILE
2 #define GEOM_FILE
3 #include <array>
4 #include <functional> // function; C++11
5 #include <string>
6 #include <vector>
7 
11 class Mesh
12 {
13 public:
21  explicit Mesh(int ndim, int nvert_e = 0, int ndof_e = 0);
22 
29  virtual ~Mesh();
30 
35  int Nelems() const
36  {
37  return _nelem;
38  }
39 
44  int NverticesElements() const
45  {
46  return _nvert_e;
47  }
48 
53  int NdofsElement() const
54  {
55  return _ndof_e;
56  }
57 
62  int Nnodes() const
63  {
64  return _nnode;
65  }
66 
71  int Ndims() const
72  {
73  return _ndim;
74  }
75 
83  {
84  SetNelem(nelem); // number of elements
85  SetNverticesElement(nvert_e); // vertices per element
86  _ia.resize(nelem * nvert_e);
87  }
88 
93  const std::vector<int> &GetConnectivity() const
94  {
95  return _ia;
96  }
97 
102  std::vector<int> &GetConnectivity()
103  {
104  return _ia;
105  }
106 
113  void Resize_Coords(int nnodes, int ndim)
114  {
115  SetNnode(nnodes); // number of nodes
116  SetNdim(ndim); // space dimension
117  _xc.resize(nnodes * ndim);
118  }
119 
124  const std::vector<double> &GetCoords() const
125  {
126  return _xc;
127  }
128 
133  std::vector<double> &GetCoords()
134  {
135  return _xc;
136  }
137 
143  void SetValues(std::vector<double> &v, const std::function<double(double, double)> &func) const;
144 
148  void Debug() const;
149 
154  virtual std::vector<int> Index_DirichletNodes() const = 0;
155 
164  void Write_ascii_matlab(std::string const &fname, std::vector<double> const &v) const;
165 
177  void Visualize(std::vector<double> const &v) const;
178 
179 
180 protected:
181  void SetNelem(int nelem)
182  {
183  _nelem = nelem;
184  }
185 
187  {
188  _nvert_e = nvert;
189  }
190 
191  void SetNdofsElement(int ndof)
192  {
193  _ndof_e = ndof;
194  }
195 
196  void SetNnode(int nnode)
197  {
198  _nnode = nnode;
199  }
200 
201  void SetNdim(int ndim)
202  {
203  _ndim = ndim;
204  }
205 
206 private:
207  int _nelem;
208  int _nvert_e;
209  int _ndof_e;
210  int _nnode;
211  int _ndim;
212  std::vector<int> _ia;
213  std::vector<double> _xc;
214 };
215 
219 class Mesh_2d_3_square: public Mesh
220 {
221 public:
231  Mesh_2d_3_square(int nx, int ny, int myid = 0, int procx = 1, int procy = 1);
232 
236  ~Mesh_2d_3_square() override
237  {}
238 
243  void SetU(std::vector<double> &u) const;
244 
249  void SetF(std::vector<double> &f) const;
250 
255  std::vector<int> Index_DirichletNodes() const override;
256 
272  void SaveVectorP(std::string const &name, std::vector<double> const &u) const;
273 
274  // here will still need to implement in the class
275  // GetBound(), AddBound()
276  // or better a generalized way with indices and their appropriate ranks for MPI communication
277 
278 private:
291  void GetCoordsInRectangle(int nx, int ny, double xl, double xr, double yb, double yt,
292  double xc[]);
300  void GetConnectivityInRectangle(int nx, int ny, int ia[]);
301 
302 private:
303  int _myid;
304  int _procx;
305  int _procy;
306  std::array<int, 4> _neigh;
307  int _color;
308 
309  double _xl;
310  double _xr;
311  double _yb;
312  double _yt;
313  int _nx;
314  int _ny;
315 };
316 
317 // #################### still some old code (--> MPI) ############################
328 // GH_NOTE: Absicherung bei s !!
329 void GetBound(int ib, int nx, int ny, double const w[], double s[]);
330 
331 
341 void AddBound(int ib, int nx, int ny, double w[], double const s[]);
342 
343 // #################### Mesh from Matlab ############################
347 class Mesh_2d_3_matlab: public Mesh
348 {
349 public:
357  explicit Mesh_2d_3_matlab(std::string const &fname);
358 
365  std::vector<int> Index_DirichletNodes() const override;
366 
367 private:
372  int Nnbedges() const
373  {
374  return static_cast<int>(bedges.size());
375  }
376 
377  std::vector<int> bedges;
378 
379 };
380 
381 #endif
Mesh::Write_ascii_matlab
void Write_ascii_matlab(std::string const &fname, std::vector< double > const &v) const
Definition: geom.cpp:56
Mesh::SetNelem
void SetNelem(int nelem)
Definition: geom.h:181
xc
xc
Definition: ascii_read_meshvector.m:30
function
function[xc, ia, v]
Definition: ascii_read_meshvector.m:1
Mesh::Ndims
int Ndims() const
Definition: geom.h:71
Mesh::Index_DirichletNodes
virtual std::vector< int > Index_DirichletNodes() const =0
Mesh::Resize_Coords
void Resize_Coords(int nnodes, int ndim)
Definition: geom.h:113
Mesh::Resize_Connectivity
void Resize_Connectivity(int nelem, int nvert_e)
Definition: geom.h:82
Mesh_2d_3_square
Definition: geom.h:219
Mesh::GetConnectivity
const std::vector< int > & GetConnectivity() const
Definition: geom.h:93
Mesh::Mesh
Mesh(int ndim, int nvert_e=0, int ndof_e=0)
Definition: geom.cpp:13
Mesh::SetNverticesElement
void SetNverticesElement(int nvert)
Definition: geom.h:186
Mesh_2d_3_matlab
Definition: geom.h:347
Mesh::GetCoords
std::vector< double > & GetCoords()
Definition: geom.h:133
Mesh
Definition: geom.h:11
Mesh::SetValues
void SetValues(std::vector< double > &v, const std::function< double(double, double)> &func) const
Definition: geom.cpp:21
Mesh_2d_3_square::Mesh_2d_3_square
Mesh_2d_3_square(int nx, int ny, int myid=0, int procx=1, int procy=1)
Definition: geom.cpp:130
AddBound
void AddBound(int ib, int nx, int ny, double w[], double const s[])
Definition: geom.cpp:347
Mesh::Nnodes
int Nnodes() const
Definition: geom.h:62
GetBound
void GetBound(int ib, int nx, int ny, double const w[], double s[])
Definition: geom.cpp:301
v
v
Definition: ascii_read_meshvector.m:40
Mesh_2d_3_square::~Mesh_2d_3_square
~Mesh_2d_3_square() override
Definition: geom.h:236
Mesh_2d_3_square::SetU
void SetU(std::vector< double > &u) const
Definition: geom.cpp:168
Mesh_2d_3_square::SetF
void SetF(std::vector< double > &f) const
Definition: geom.cpp:182
Mesh::Visualize
void Visualize(std::vector< double > const &v) const
Definition: geom.cpp:106
Mesh::~Mesh
virtual ~Mesh()
Definition: geom.cpp:18
Mesh_2d_3_matlab::Index_DirichletNodes
std::vector< int > Index_DirichletNodes() const override
Definition: geom.cpp:495
Mesh_2d_3_square::SaveVectorP
void SaveVectorP(std::string const &name, std::vector< double > const &u) const
Definition: geom.cpp:227
ndim
ndim
Definition: ascii_read_meshvector.m:23
Mesh_2d_3_matlab::Mesh_2d_3_matlab
Mesh_2d_3_matlab(std::string const &fname)
Definition: geom.cpp:391
ia
ia
Definition: ascii_read_meshvector.m:35
nnode
function vertex minimal boundary edge info in an ASCII file Matlab indexing is stored(starts with 1). % % The output file format is compatible with Mesh_2d_3_matlab nnode
Definition: ascii_write_mesh.m:23
Mesh::SetNdofsElement
void SetNdofsElement(int ndof)
Definition: geom.h:191
Mesh_2d_3_square::Index_DirichletNodes
std::vector< int > Index_DirichletNodes() const override
Definition: geom.cpp:197
Mesh::GetConnectivity
std::vector< int > & GetConnectivity()
Definition: geom.h:102
Mesh::SetNnode
void SetNnode(int nnode)
Definition: geom.h:196
Mesh::NverticesElements
int NverticesElements() const
Definition: geom.h:44
Mesh::SetNdim
void SetNdim(int ndim)
Definition: geom.h:201
nelem
nelem
Definition: ascii_read_meshvector.m:24
Mesh::Debug
void Debug() const
Definition: geom.cpp:32
nvert_e
nvert_e
Definition: ascii_write_mesh.m:26
Mesh::GetCoords
const std::vector< double > & GetCoords() const
Definition: geom.h:124
nvert
nvert
Definition: ascii_read_meshvector.m:25
Mesh::Nelems
int Nelems() const
Definition: geom.h:35
Mesh::NdofsElement
int NdofsElement() const
Definition: geom.h:53