jacobi_oo_STL
Loading...
Searching...
No Matches
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
11class Mesh
12{
13public:
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
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
180protected:
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
206private:
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
220{
221public:
231 Mesh_2d_3_square(int nx, int ny, int myid = 0, int procx = 1, int procy = 1);
232
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
278private:
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
302private:
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 !!
329void GetBound(int ib, int nx, int ny, double const w[], double s[]);
330
331
341void AddBound(int ib, int nx, int ny, double w[], double const s[]);
342
343// #################### Mesh from Matlab ############################
348{
349public:
357 explicit Mesh_2d_3_matlab(std::string const &fname);
358
365 std::vector<int> Index_DirichletNodes() const override;
366
367private:
372 int Nnbedges() const
373 {
374 return static_cast<int>(bedges.size());
375 }
376
377 std::vector<int> bedges;
378
379};
380
381#endif
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
std::vector< int > Index_DirichletNodes() const override
Definition geom.cpp:495
void SetU(std::vector< double > &u) const
Definition geom.cpp:168
~Mesh_2d_3_square() override
Definition geom.h:236
std::vector< int > Index_DirichletNodes() const override
Definition geom.cpp:197
void SaveVectorP(std::string const &name, std::vector< double > const &u) const
Definition geom.cpp:227
void SetF(std::vector< double > &f) const
Definition geom.cpp:182
Definition geom.h:12
const std::vector< double > & GetCoords() const
Definition geom.h:124
void Resize_Connectivity(int nelem, int nvert_e)
Definition geom.h:82
void Debug() const
Definition geom.cpp:32
void Resize_Coords(int nnodes, int ndim)
Definition geom.h:113
std::vector< double > & GetCoords()
Definition geom.h:133
int Ndims() const
Definition geom.h:71
void SetNdofsElement(int ndof)
Definition geom.h:191
virtual ~Mesh()
Definition geom.cpp:18
virtual std::vector< int > Index_DirichletNodes() const =0
int Nelems() const
Definition geom.h:35
void Write_ascii_matlab(std::string const &fname, std::vector< double > const &v) const
Definition geom.cpp:56
int Nnodes() const
Definition geom.h:62
void SetNdim(int ndim)
Definition geom.h:201
int NverticesElements() const
Definition geom.h:44
std::vector< int > & GetConnectivity()
Definition geom.h:102
void SetNnode(int nnode)
Definition geom.h:196
void SetNelem(int nelem)
Definition geom.h:181
int NdofsElement() const
Definition geom.h:53
void SetNverticesElement(int nvert)
Definition geom.h:186
const std::vector< int > & GetConnectivity() const
Definition geom.h:93
void SetValues(std::vector< double > &v, const std::function< double(double, double)> &func) const
Definition geom.cpp:21
void Visualize(std::vector< double > const &v) const
Definition geom.cpp:106
void GetBound(int ib, int nx, int ny, double const w[], double s[])
Definition geom.cpp:301
void AddBound(int ib, int nx, int ny, double w[], double const s[])
Definition geom.cpp:347