-
Notifications
You must be signed in to change notification settings - Fork 0
/
phParAdapt.h
471 lines (384 loc) · 16.9 KB
/
phParAdapt.h
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
#ifndef _PHADAPT_H_
#define _PHADAPT_H_
#include <string>
#include <iostream>
#include <map>
#include "mpi.h"
#include "MeshSimInternal.h"
#include "MeshSimAdapt.h"
#include "mesh_interface.h"
#include "parallel.h" //include definition of globalInfo
using namespace std;
#ifndef ibm
#define ludcmp ludcmp_
#define lubksb lubksb_
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define ABS(x) ((x) < 0 ? -(x) : (x))
#define MAX(x,y) ((x)<(y) ? (y) : (x))
struct Hessian {
double h[3];
double dir[3][3];
};
typedef struct Hessian Hessian;
int phParAdaptProcSize();
// sim call back
// typedef int (*MSA_CallbackFunc)(pPList , pPList, int);
// main routine to control mesh adaptation, solution transfer and communication with PHASTA
int adapt( // parallel mesh
pParMesh pmesh,
//serial mesh (BLAdapt)
pMesh mesh,
// model
pGModel model,
//time step
int timeStepNumber,
// strategy is to specify
// how to do adaptation (i.e., size-field or tag driven)
// 1-2 : size-field driven (for anisotropic)
// 3-4 : tag driven (for isotropic)
// 5-6 : size-field driven (for isotropic)
// < 0 sets a manual mesh size-field
int strategy,
// factor is the constant appearing in the error expression
// for tag driven it is used to define threshold for refinement
// for size-field driven it is used to define the error tolerance
double factor,
// number of solution variables (5 for incompressible)
int ndof,
// number of variables for error indicators (EI)
// (e.g., 5 for ybar & 10 for residual-based)
int nvar,
// the maximal mesh edge length allowed in mesh size
double hmax,
// the minimal mesh edge length allowed in mesh size
double hmin,
// option is used to decide how to compute the error value
// provides different choices like analytic hessian, manual size-field etc.
// for isotropic (ta or size-field driven :
// use 3 EI for flow problem or use 1 EI for scalar problem
int option);
// piecewise linear mesh size field definition in terms of Hessian
// void setSizeFieldUsingHessians(pMesh,pMSAdapt,double,double,double,int option=1);
void partitionMeshToLoadBalanceForAdaptivity(pParMesh pmesh, pMesh mesh, int option, int nCurrentErrorVars);
double estimateNumNewRegions(pRegion rgn, int option);
void getGlobalErrorInfo(pMesh mesh, double& totalError, double& sumOfError);
void computeOldMeshSize(pMesh, int option);
void commuOldMeshSize(pParMesh, pMesh);
void setIsotropicSizeField(pGModel,pParMesh,pMesh,pMSAdapt,double,double,double,int option );
void setManualSizeField(pParMesh pmesh, pMesh mesh, pMSAdapt simAdapter, int comp, int option);
void setSizeFieldUsingHessians(pParMesh pmesh,
pMesh mesh,
pMSAdapt simAdapter,
double factor,
double hmax,
double hmin,
int option);
void setSizeFieldUsingCombined(pParMesh pmesh,
pMesh mesh,
pMSAdapt simAdapter,
double factor,
double hmax,
double hmin,
int option);
void SizeQuality(pMesh mesh);
void setSizeFieldFromFile(pMesh mesh,
pMSAdapt simAdapter,
char* sfFilename);
// for tag driven refinement (i.e., isotropic)
void tagEntitiesForRefinement(pMesh,pMSAdapt,double, double,double,int option);
int applyMarkingStrategy(pMesh mesh,
pMSAdapt simAdapter,
double factor,
double hmax,
double hmin,
double totalError,
double maxError,
double minError,
double threshold,
int option);
double getErrorThreshold(pMesh mesh,
double factor,
double totalError,
double maxError,
double minError,
int option);
void V_reordering(pMesh mesh, globalInfo* ginfo, int ipart);
void R_reordering(pMesh mesh, int ipart);
double getErrorValue(double *nodalValues,int option);
// get interpolation error values from hessians
double maxLocalError(pVertex vertex, double H[3][3]);
// attach the max local interpolation error LOCAL
// to each partition via locMaxInterpolErrorID;
void maxLocalPartLocError(pMesh mesh);
// attach the max local interpolation error GLOBAL
// to the parallel mesh via globMaxInterpolErrorID;
void commuMaxLocalPartLocError(pParMesh pmesh,pMesh mesh);
double E_error(pEdge edge, double H[3][3]);
// get hessians computed from phasta
void V_getHessians(double*,pMesh,int,int,double*);
// for doing hessians computation outside phasta
void V_Hessian(pVertex v, double T[3][3]);
void V_AnalyticHessian(pVertex v, double T[3][3], int option);
void buildSystem(pRegion region, double* eltMatrix);
void buildSystemXYZ(dArray *xyz, double* eltMatrix);
void elementGradient(pRegion region, double* elemGradient);
void gradientsFromPatch(pMesh mesh);
void elementHessian(pRegion region, double* elemHessian);
void hessiansFromSolution(pParMesh pmesh, pMesh mesh,int stepNumber);
void hessiansFromPatch(pMesh mesh);
void ModifyHessiansAtBdry(pMesh mesh);
void writeRestartHessians(pMesh mesh );
void SmoothHessians(pMesh mesh);
void SmoothSize(pMesh mesh, int num);
void SmoothDir(pMesh mesh);
void commuSmoothDir(pParMesh pmesh, pMesh mesh);
void SmoothWallField(pMesh mesh, pMeshDataId field, int ndof);
void SizeLimit(pMesh mesh);
void SizePropogate(pMesh mesh);
void SmoothSizeOnBdry(pMesh mesh, int numPasses, int genDim);
void SmoothErrorIndicators(pMesh mesh,int option);
void writeSmoothEIs(pMesh mesh);
/// ad hoc things
void WriteSizeField(pMesh mesh);
void ReadSizeField(double* SizeField);
void ModifyMetric(pVertex vertex, double dir[3][3], double* h);
// nvar mis number of error indicators attached via errorIndicatorID
void transformToScalarErrorVal(pMesh mesh, int nvar, int option);
// double processErrorAG(double* nodalErrorSet,int nvar);
double processErrorAG(double* nodalErrorSet,double* nodalSolutionSet,int nvar, int option, double* coord);
// for solving linear system (small)
void ludcmp( double*, int*, int*, int*, double* );
// the last array is the right hand side
// it is being passed as a reference and overridden
// to contain the linear system's solution !
void lubksb( double*, int*, int*, int*, double* );
// for viewing results in medit
void writeMEDITSizeField(Hessian *hess,pMesh mesh, int currentTimestep, int gprocID );
void writeMEDITSolution(pMesh mesh);
// void MSA_setCallback(pMSAdapt, MSA_CallbackFunc);
#ifdef SIM
void phastaTransferTopSIM(MeshModType mtype, pMeshChanges mco, void *userData);
typedef MeshModType modType;
int delDblArray(void *ent, pAttachDataId id, int cb, void** data, void* c);
int delDbl(void *ent, pAttachDataId id, int cb, void** data, void* c);
#endif
#ifdef FMDB
void phastaTransferTopSCOREC(pPList oldEnts, pPList newRgn, void *userData, modType mtype, pEntity ent);
int delDblArray(pAttachableData ad, pAttachDataId id, int cb, void** data, void* c);
int delDbl(pAttachableData ad, pAttachDataId id, int cb, void** data, void* c);
void phastaTransferBottomE(pPList old, pPList fresh, pPList oldVertices, modType mtype);
#endif
void phastaTransferBottom(pPList old, pPList fresh, pPList oldVertices, modType mtype);
#ifdef SIM
void phastaTransferSIMBottom(pPList Vertices, pPList Edges, pPList Faces, pPList Regions, int ndof, modType mtype);
#endif
void fix4SolutionTransfer(pMesh mesh);
void commuFix4SolutionTransfer(pParMesh pmesh, pMesh mesh);
void BCInflowFaceInfo(pGModel model, pParMesh pmesh, pMesh mesh);
int BCInflowFaceNodesInfo(pGModel model, pMesh mesh);
int BCInflowFaceConnectInfo(pGModel model, pMesh mesh);
void commuBCInflowFaceInfo(pParMesh pmesh, pMesh mesh);
void BCInflowFaceGlobalInfoInVtk(int nodesTot, int facesTot);
void printTimeStatsToFile(int);
int
inverseMap( pRegion region,
double gpt[3],
double xisol[3] ) ;
int
inverseMapE( pEdge edge,
double gpt[3],
double xisol[3] );
double*
InterpolateSolution( pRegion region,
double xi[3],
int ndof,
pMeshDataId modes);
double*
InterpolateSolutionE( pEdge edge,
double xi[3],
int dof,
pMeshDataId modes);
void
R_entitiesAdapt( pRegion region,
pVertex *vrts,
pEdge *edgs,
pFace *fcs ) ;
void
display_region( pRegion region );
// for debug
void check(pMesh);
////////////////////////////////////////////////////////////////////////////////////////////
// function that reads in erro files in restart format
// using phastaIO library
////////////////////////////////////////////////////////////////////////////////////////////
void
readErrorFiles(double* nodalErrors, int stepNumber);
////////////////////////////////////////////////////////////////////////////////////////////
// function that reads in erro files in restart format
// using phastaIO library --> directly from restart format
////////////////////////////////////////////////////////////////////////////////////////////
void
readErrorFromRestart(double* nodalErrors, int stepNumber);
////////////////////////////////////////////////////////////////////////////////
// for solution transfer onto new mesh:
// read in solution and attach it to current mesh
// also provide for inter-proc transfer
////////////////////////////////////////////////////////////////////////////////
void
readAttachSolution(pMesh mesh,int stepNumber);
////////////////////////////////////////////////////////////////////////////////
// transfer the previously attached solution data onto
// new nodes (linear case)
// another migtation ID is required
////////////////////////////////////////////////////////////////////////////////
void
transferSolution(pMesh mesh,
pMeshDataId nodalAverageID,
int stepNumber);
////////////////////////////////////////////////////////////////////////////////
// in localSolutionContrib.cc
//
// retrieve the solution values on vertices that surround vertex.
// If surrounding vertex DOES carry an old solution AND is owned
// by proc/part the solution vals are added up and stored in
// nodalValues
////////////////////////////////////////////////////////////////////////////////
/* void */
/* thisPartsSolutionContribVal(pVertex vertex, */
/* pMeshDataId nodalSolutionID, */
/* double* nodalValues); */
////////////////////////////////////////////////////////////////////////////////
// get number of vertices that contribute to this vertex' average
// counted are all the vertices which actually DO carry a solution
// and if they are on a partition bdry this proc must be owner
////////////////////////////////////////////////////////////////////////////////
/* int */
/* thisPartsSolutionContribNN(pVertex vertex, */
/* pMeshDataId nodalSolutionID); */
////////////////////////////////////////////////////////////////////////////////
// gather solution values for vertices on partition bdries
// this function operates on
// the data ptr attached to vertices via
// nodalAverageID
// and is migrated tru partitions
// for each part, the data ptr carrying num of contribution nodes and their
// values is modifies (added to)
////////////////////////////////////////////////////////////////////////////////
/* void */
/* gatherNodalSolution(pParMesh pmesh,pMeshDataId nodalSolutionID,pMeshDataId nodalAverageID); */
////////////////////////////////////////////////////////////////////////////////
// write out the restart files
////////////////////////////////////////////////////////////////////////////////
void
writeRestartFiles(double* q, int nshg_fine, int stepNumber);
////////////////////////////////////////////////////////////////////////////////////////////
// get the global node number
// via incorp
// the mapping in the files that were created during partitioning
// returns the global number of DOFs
////////////////////////////////////////////////////////////////////////////////////////////
/* int */
/* getGlobalNodeId(pMesh mesh, pMeshDataId incorp, char* meshDirName); */
////////////////////////////////////////////////////////////////////////////////////////////
// just get the global (total) number of nodes
////////////////////////////////////////////////////////////////////////////////////////////
int
getNSHGTOT(pMesh mesh);
////////////////////////////////////////////////////////////////////////////////////////////
// assign new global IDs to the new mesh
// old node nums are kept
// the IDs for the new nodes are set according to their
// frequency in each partition
// also needs the total number of DOFs
// which has been determined in getGlobalNodeId
// (which has to be broadcasted)
// argument list : nshgTot : the old nshgTot
// returns new nshgTot
////////////////////////////////////////////////////////////////////////////////////////////
int
assignNewGlobalNodeId(pParMesh pmesh, pMesh mesh,pMeshDataId incorp, int nshgTot);
void
assignGlobalVars();
// replacement for the Simmetrix model attach data functions
// why replacement???? Min Zhou
#ifdef SIM
int
GEN_dataP(pGEntity g, char* str, void** data);
void
GEN_attachDataP(pGEntity g, char* str, void* data);
int
GEN_dataI(pGEntity g, char* str, int* data);
void
GEN_attachDataI(pGEntity g, char* str, int data);
#endif
////////////////////////////////////////////////////////////////////////////////////////////
// do the solution transfer
////////////////////////////////////////////////////////////////////////////////////////////
/* int */
/* solutionTransfer(pMesh mesh,int stepNumber); */
// parallel communication tasks for the adaptor
void
commuSmoothHessians(pParMesh pmesh, pMesh mesh);
void
commuSmoothSize(pParMesh pmesh, pMesh mesh, int num);
void
commuGradientsFromPatch(pParMesh pmesh, pMesh mesh);
void
commuHessiansFromPatch(pParMesh pmesh, pMesh mesh);
#ifdef __cplusplus
}
#endif
///////////////////////////////////////////////////////////////////////////////////
//This functions need to be overloaded, do NOT move them inside above
///////////////////////////////////////////////////////////////////////////////////
void PMU_commuArr(void **s, int *ns, void **r, int *nr, MPI_Datatype type, int mult);
void PMU_commuArr(void ***s, int **ns, void ***r, int **nr, map<int,int> *nsmap, map<int,int> *nrmap, MPI_Datatype type, int mult);
void PMU_commuInt(int *ns, int *nr);
void PMU_commuInt(int **ns, int **nr, map<int,int> *nsmap, map<int,int> *nrmap);
//////////////////////////////////////////////////////////////////////////////////
//Adding function from M_writeVTKFile
/////////////////////////////////////////////////////////////////////////////////
void exportPVTK(const char* fname, int numPtn, int numdof);
void exportVTK(const char* fname, pMesh mesh, pMeshDataId field, int numdof);
void M_writeVTKFile(pMesh mesh,const char * fname, pMeshDataId field, int numdof);
/////Thickness Adaptation
pPList V_growthCurveVertices(pVertex vertex);
int V_isOriginatingNode(pVertex vertex);
void WallStress(pMesh mesh);
void SpaldingLaw(double ydist, double u, double& uTau, double& yplus);
double DispThickness(pVertex vertex);
void TotalBLHeight(pMesh mesh);
void CalcYPlus(pMesh mesh);
double BLHeightVort(pVertex vertex, pPList VGrowth);
double BLHeightVel(pPList VGrowth);
double BLConstraint(pVertex vert, double distGC);
void DetectShock(pParMesh pmesh, pMesh mesh);
void DistOffWall(pMesh mesh, pMSAdapt simAdapter);
double SeparatedBL(pVertex vertex);
double GrowthCurveIntersect(pVertex vertex);
void Vorticity(pParMesh pmesh, pMesh mesh);
void VortelementGradient(pRegion region, double* elemGradient, int fieldIndexForGrad);
void VortgradientsFromPatch(pMesh mesh, int fieldIndexForGrad);
////Simmetrix development functions
double E_normalizedLength(pEdge);
double E_normalizedLengthSq(pEdge);
void MSA_setPrebalance(pMSAdapt, int);
void MSA_setCoarsenMode(pMSAdapt, int);
void MSA_setBLSnapping(pMSAdapt, int);
void MSA_setBLMinLayerAspectRatio(pMSAdapt, double);
void MSA_setExposedBLBehavior(pMSAdapt, int);
void MSA_setMaxIterations(pMSAdapt, int);
void MSA_setSizeBounds(pMSAdapt, double,double);
void MSA_setSnapping(pMSAdapt, int);
pAManager SModel_attManager(pModel model);
/////// calculating volume for pyramids in simmetrix
double XYZ_volumeSim (double xyz[4][3]);
double R_VolumeSim(pRegion region);
//debug functions
void VolumeDebug(pMesh mesh);
void EdgeLength(pMesh pmesh);
void NormalizedEdgeLength(pMesh pmesh);
#endif