discr.h 14 KB
Newer Older
Kirill Terekhov's avatar
Kirill Terekhov committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#pragma once
#ifndef _DISCR_H

#include "../../inmost.h"
using namespace INMOST;

//TODO:
//move orphan function inside class
//introduce discr_triplet_basic class 

void tensor_prod1(Storage::real * K, Storage::real v[3], Storage::real out[3]);
void tensor_prod2(Storage::real * K, Storage::real v[3], Storage::real out[3]);
void tensor_prod3(Storage::real * K, Storage::real v[3], Storage::real out[3]);
int tensor_prod(int Ktype, Storage::real_array & K, 
				Storage::real v[3], Storage::real out[3]);
void tensor_add1(Storage::real * K, Storage::real Kout[9]);
void tensor_add2(Storage::real * K, Storage::real Kout[9]);
void tensor_add3(Storage::real * K, Storage::real Kout[9]);
int tensor_add(int Ktype, Storage::real_array & K, Storage::real Kout[9]);
int average_tensor(int Ktype, Storage::real_array & K1, 
					Storage::real_array & K2, Storage::real Kout[9]);
void vec_diff(Storage::real x[3], Storage::real y[3], Storage::real out[3]);
Storage::real dot_prod(Storage::real x[3], Storage::real y[3]);


//type of the averaging point
#define AVG_NONE        0//material is homogeneous across cells - no point required
#define AVG_CENTROID    1//use centroid
#define AVG_HARMONIC    2//use harmonic averaging point
#define AVG_NONLINEAR   4//use nonlinear flux continuety to define value at the point
#define AVG_REVDIST     8//use reverse distance
#define AVG_NEUMANN     16 //use zero neumann boundary condition

#define CRITICAL_DIST_RATIO 10.0

class discr_basic
{
protected:
	Automatizator * aut;
	Mesh * m;
	Tag K;
	Tag bnd_conds;
	//Tag AvgCoord, AvgCoefs, AvgStats;
	int Ktype;
	int error;
	ElementType bnd_types;
	MIDType bnd_markers, add_markers;
	int rem_marker;
	int have_bnd;
	int allowed_types;
	// returns
	// 0 if point inside
	// 1 if distance to point by distance to farthest node is less then CRITICAL_DIST_RATIO
	// 2 otherwise
	int isPointInside(Face * f, Storage::real x[3]);
	//void InitializeSupportPoints(int allowed_types = AVG_NONE | AVG_CENTROID | AVG_HARMONIC | AVG_NONLINEAR | AVG_REVDIST);
	int FindHarmonicPoint(Face * fKL, Cell * cK, Cell * cL, 
						   Tag tensor, int tensor_type, 
						   Storage::real xK[3], Storage::real xL[3], 
						   Storage::real y[3], Storage::real & coef);
	int FindBoundaryPoint(Face * fK, Cell * cK, 
		                   Tag tensor, int tensor_type, 
						   Storage::real xK[3], Storage::real y[3]);
	virtual void Build(Face * f) = 0;
public:
	enum DiscrType {TPFA, MPFA, NTPFA, NMPFA};
	enum SchemeType{ Linear, Nonlinear };
public:
	discr_basic(Automatizator * aut, Mesh * m, std::string tensor_name);
	virtual bool needBuild(Face * f) const;
	virtual bool needUpdate(Face * f) const;
	virtual void Init() = 0;
	virtual DiscrType GetDiscrType() const = 0;
	virtual SchemeType GetSchemeType() const = 0;
	virtual expr Grad(const expr & param) const = 0;
	virtual expr BoundaryGrad(const expr & param) const = 0;
	virtual expr Interp(ElementType etype,const expr & param) const = 0;
	virtual void Update() = 0;
	virtual void Export(std::ostream & out, Storage::real trans_scale, Storage::real vol_scale) const; //export to ADGPRS
	// by default no boundary information is provided, schemes avoid using boundary
	// first marker is the marker that is used inside Automatizator to define dynamic tag domain
	// if some boundary element is not used inside scheme it will not be marked by usage_marker
	// second marker defines boundary faces/edges, if not set, it is computed automatically
	// third parameter defines what kinds of elements may be used
	void Boundary(MIDType bnd_marker = 0, ElementType bnd_types = FACE | EDGE);
	// mark additional collocation points that should be introduced into the system
	MIDType UnknownMarker() const { return add_markers; }
	MIDType BoundaryMarker() const { return bnd_markers; }
	virtual ~discr_basic();

	void AllowTypes(int types) {allowed_types = types;}
};

class discr_triplet_basic : public discr_basic
{
protected:
	int find_triplet(Element * r, Element * f, Face * harmonic_face, Storage::real v[3],
					 Storage::real dir, Storage::real area, 
					 Element * t[3], Storage::real coefs[3], int ptypes[3], 
					 int allowed = AVG_HARMONIC | AVG_NONLINEAR | AVG_REVDIST, bool f_necessery = false);
public:
	discr_triplet_basic(Automatizator * aut, Mesh * m, std::string tensor_name) : discr_basic(aut,m,tensor_name) {}
	virtual ~discr_triplet_basic();
};


class tpfa : public discr_basic
{
	INMOST_DATA_ENUM_TYPE stncl;
	Tag trans;
	Tag elems;
	void Build(Face * f);
public:
	tpfa(Automatizator * aut, Mesh *m, std::string tensor);
	DiscrType GetDiscrType() const { return TPFA; }
	SchemeType GetSchemeType() const { return Linear; }
	expr Grad(const expr & param) const;
	expr BoundaryGrad(const expr & param) const {return Grad(param);}
	expr Interp(ElementType etype,const expr & param) const;
	void Export(std::ostream & out, Storage::real trans_scale, Storage::real vol_scale) const;
	void Init();
	void Update();
	bool needBuild(Face * f) const { return discr_basic::needBuild(f); }
	bool needUpdate(Face * f) const { return discr_basic::needUpdate(f); }
	~tpfa();
};

class tpfa2 : public discr_basic
{
	INMOST_DATA_ENUM_TYPE stncl;
	Tag trans;
	Tag elems;
	void Build(Face * f);
public:
	tpfa2(Automatizator * aut, Mesh *m, std::string tensor);
	DiscrType GetDiscrType() const { return TPFA; }
	SchemeType GetSchemeType() const { return Linear; }
	expr Grad(const expr & param) const;
	expr BoundaryGrad(const expr & param) const {return Grad(param);}
	expr Interp(ElementType etype,const expr & param) const;
	void Export(std::ostream & out, Storage::real trans_scale, Storage::real vol_scale) const;
	void Init();
	void Update();
	bool needBuild(Face * f) const { return discr_basic::needBuild(f); }
	bool needUpdate(Face * f) const { return discr_basic::needUpdate(f); }
	~tpfa2();
};



class mpfa_o : public discr_basic
{
	INMOST_DATA_ENUM_TYPE stncl;
	Tag trans;
	Tag elems;
	void Build(Face * f);
public:
	mpfa_o(Automatizator * out, Mesh *m, std::string tensor);
	DiscrType GetDiscrType() const { return MPFA; }
	SchemeType GetSchemeType() const { return Linear; }
	expr Grad(const expr & param) const;
	expr BoundaryGrad(const expr & param) const {return Grad(param);}
	expr Interp(ElementType etype,const expr & param) const;
	void Export(std::ostream & out, Storage::real trans_scale, Storage::real vol_scale) const;
	void Init();
	void Update();
	bool needBuild(Face * f) const { return discr_basic::needBuild(f); } //TODO
	bool needUpdate(Face * f) const { return discr_basic::needBuild(f); } //TODO
	~mpfa_o();
};

class basic_a : public discr_triplet_basic
{
	MIDType mark_next;
	INMOST_DATA_ENUM_TYPE dwn, upw, intrp, add;
	INMOST_DATA_ENUM_TYPE trpr;
	INMOST_DATA_ENUM_TYPE trpl;
	Tag trpl_elems, trpr_elems;
	Tag trpl_coefs, trpr_coefs;
	Tag trans;
	Tag intrp_stncl, intrp_coefs;
	Tag pos;
	void MarkRecursive(Element * f);
	void Build(Face * f);
	static void get_r(Storage * e, Automatizator::stencil_pairs & out, void * user_data);
	static void get_l(Storage * e, Automatizator::stencil_pairs & out, void * user_data);
public:
	basic_a(Automatizator * out, Mesh *m, std::string tensor);
	void Init();
	void Update();
	bool needBuild(Face * f) const { return discr_basic::needBuild(f); } //TODO
	bool needUpdate(Face * f) const { return discr_basic::needBuild(f); } //TODO
	virtual ~basic_a();
};

class ntpfa_a : public discr_triplet_basic
{
	MIDType mark_next;
	INMOST_DATA_ENUM_TYPE dwn, upw, intrp;
	INMOST_DATA_ENUM_TYPE trpr, addr;
	INMOST_DATA_ENUM_TYPE trpl, addl;
	Tag trpl_elems, trpr_elems;
	Tag trpl_coefs, trpr_coefs; 
	Tag trpl_add, trpr_add;
	Tag intrp_stncl, intrp_coefs;
	Tag pos;
	void MarkRecursive(Element * f);
	void MarkRecursiveEdge(Element * f);
	void Build(Face * f);
	static void get_r(Storage * e, Automatizator::stencil_pairs & out, void * user_data);
	static void get_l(Storage * e, Automatizator::stencil_pairs & out, void * user_data);
public:
	ntpfa_a(Automatizator * out, Mesh *m, std::string tensor);
	DiscrType GetDiscrType() const { return NTPFA; }
	SchemeType GetSchemeType() const { return Nonlinear; }
	expr Grad(const expr & param) const;
	expr BoundaryGrad(const expr & param) const {return Grad(param);}
	expr Interp(ElementType etype,const expr & param) const;
	void Export(std::ostream & out, Storage::real trans_scale, Storage::real vol_scale) const;
	void Init();
	void Update();
	bool needBuild(Face * f) const { return discr_basic::needBuild(f); } //TODO
	bool needUpdate(Face * f) const { return discr_basic::needBuild(f); } //TODO
	~ntpfa_a();
};

class nmpfa_a : public basic_a
{
public:
	nmpfa_a(Automatizator * out, Mesh *m, std::string tensor);
	DiscrType GetDiscrType() const { return NMPFA; }
	SchemeType GetSchemeType() const { return Nonlinear; }
	expr Grad(const expr & param) const;
	expr BoundaryGrad(const expr & param) const {return Grad(param);}
	expr Interp(ElementType etype,const expr & param) const;
	void Export(std::ostream & out, Storage::real trans_scale, Storage::real vol_scale) const;
	~nmpfa_a();
};


class ntpfa_c : public discr_triplet_basic
{
	MIDType mark_next;
	INMOST_DATA_ENUM_TYPE dwn, upw, intrp;
	INMOST_DATA_ENUM_TYPE trpr1, trpl1, addl1, addr1;
	INMOST_DATA_ENUM_TYPE trpr2, trpl2, addl2, addr2;
	Tag trpl1_elems, trpl2_elems, trpr1_elems, trpr2_elems;
	Tag trpl1_coefs, trpl2_coefs, trpr1_coefs, trpr2_coefs; 
	Tag trpl1_add, trpl2_add, trpr1_add, trpr2_add;
	Tag intrp_stncl, intrp_coefs;
	void MarkRecursive(Element * f);
	void MarkRecursiveEdge(Element * f);
	void Build(Face * f);
	static void get_r(Storage * e, Automatizator::stencil_pairs & out, void * user_data);
	static void get_l(Storage * e, Automatizator::stencil_pairs & out, void * user_data);
public:
	ntpfa_c(Automatizator * out, Mesh *m, std::string tensor);
	DiscrType GetDiscrType() const { return NTPFA; }
	SchemeType GetSchemeType() const { return Nonlinear; }
	expr Grad(const expr & param) const;
	expr BoundaryGrad(const expr & param) const;
	expr Interp(ElementType etype,const expr & param) const;
	void Export(std::ostream & out, Storage::real trans_scale, Storage::real vol_scale) const;
	void Init();
	void Update();
	bool needBuild(Face * f) const { return discr_basic::needBuild(f); } //TODO
	bool needUpdate(Face * f) const { return discr_basic::needBuild(f); } //TODO
	~ntpfa_c();
};

class ntpfa_b : public discr_triplet_basic
{
	MIDType mark_next;
	INMOST_DATA_ENUM_TYPE dwn, upw, intrp;
	INMOST_DATA_ENUM_TYPE trpr, addr;
	INMOST_DATA_ENUM_TYPE trpl, addl;
	Tag trpl_elems, trpr_elems;
	Tag trpl_coefs, trpr_coefs; 
	Tag trpl_add, trpr_add;
	Tag intrp_stncl, intrp_coefs;
	Tag pos;
	void MarkRecursive(Element * f);
	void MarkRecursiveEdge(Element * f);
	void Build(Face * f);
	static void get_r(Storage * e, Automatizator::stencil_pairs & out, void * user_data);
	static void get_l(Storage * e, Automatizator::stencil_pairs & out, void * user_data);
public:
	ntpfa_b(Automatizator * out, Mesh *m, std::string tensor);
	DiscrType GetDiscrType() const { return NTPFA; }
	SchemeType GetSchemeType() const { return Nonlinear; }
	expr Grad(const expr & param) const;
	expr BoundaryGrad(const expr & param) const {return Grad(param);}
	expr Interp(ElementType etype,const expr & param) const;
	void Export(std::ostream & out, Storage::real trans_scale, Storage::real vol_scale) const;
	void Init();
	void Update();
	bool needBuild(Face * f) const { return discr_basic::needBuild(f); } //TODO
	bool needUpdate(Face * f) const { return discr_basic::needBuild(f); } //TODO
	~ntpfa_b();
};



class nmpfa : public discr_triplet_basic
{
	MIDType mark_next;
	INMOST_DATA_ENUM_TYPE dwn, upw, intrp, add;
	INMOST_DATA_ENUM_TYPE trpr;
	INMOST_DATA_ENUM_TYPE trpl;
	Tag trpl_elems, trpr_elems;
	Tag trpl_coefs, trpr_coefs;
	Tag addval;
	Tag intrp_stncl, intrp_coefs;
	Tag pos;
	void MarkRecursive(Element * f);
	void Build(Face * f);
	static void get_r(Storage * e, Automatizator::stencil_pairs & out, void * user_data);
	static void get_l(Storage * e, Automatizator::stencil_pairs & out, void * user_data);
public:
	nmpfa(Automatizator * out, Mesh *m, std::string tensor);
	DiscrType GetDiscrType() const { return NMPFA; }
	SchemeType GetSchemeType() const { return Nonlinear; }
	expr Grad(const expr & param) const;
	expr BoundaryGrad(const expr & param) const {return Interp(FACE,param);}
	expr Interp(ElementType etype,const expr & param) const;
	void Export(std::ostream & out, Storage::real trans_scale, Storage::real vol_scale) const;
	void Init();
	void Update();
	bool needBuild(Face * f) const { return discr_basic::needBuild(f); } //TODO
	bool needUpdate(Face * f) const { return discr_basic::needBuild(f); } //TODO
	~nmpfa();
};



class mpfa_t : public discr_triplet_basic
{
	MIDType mark_next;
	INMOST_DATA_ENUM_TYPE scheme, interp;
	Tag stncl, coefs, interp_stncl, interp_coefs;
	void MarkRecursive(Element * f);
	void Build(Face * f);
public:
	mpfa_t(Automatizator * out, Mesh *m, std::string tensor);
	DiscrType GetDiscrType() const { return NMPFA; }
	SchemeType GetSchemeType() const { return Linear; }
	expr Grad(const expr & param) const;
	expr BoundaryGrad(const expr & param) const {return Grad(param);}
	expr Interp(ElementType etype,const expr & param) const;
	void Export(std::ostream & out, Storage::real trans_scale, Storage::real vol_scale) const;
	void Init();
	void Update();
	bool needBuild(Face * f) const { return discr_basic::needBuild(f); } //TODO
	bool needUpdate(Face * f) const { return discr_basic::needBuild(f); } //TODO
	~mpfa_t();
};

class mpfa_y : public discr_triplet_basic
{
	MIDType mark_next;
	INMOST_DATA_ENUM_TYPE scheme, interp;
	Tag stncl, coefs, interp_stncl, interp_coefs;
	void MarkRecursive(Element * f);
	void Build(Face * f);
public:
	mpfa_y(Automatizator * out, Mesh *m, std::string tensor);
	DiscrType GetDiscrType() const { return NMPFA; }
	SchemeType GetSchemeType() const { return Linear; }
	expr Grad(const expr & param) const;
	expr BoundaryGrad(const expr & param) const {return Grad(param);}
	expr Interp(ElementType etype,const expr & param) const;
	void Export(std::ostream & out, Storage::real trans_scale, Storage::real vol_scale) const;
	void Init();
	void Update();
	bool needBuild(Face * f) const { return discr_basic::needBuild(f); } //TODO
	bool needUpdate(Face * f) const { return discr_basic::needBuild(f); } //TODO
	~mpfa_y();
};

#endif