-
Notifications
You must be signed in to change notification settings - Fork 5
/
chef_phasta_adaptLoop.cc
73 lines (69 loc) · 1.72 KB
/
chef_phasta_adaptLoop.cc
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
#include <PCU.h>
#include <chef.h>
#include <phasta.h>
#include <phstream.h>
#include <iostream>
#include <sstream>
#include "chefPhasta.h"
#include <stdlib.h>
/** \file chef_phasta_adaptLoop.cc
\brief Example in-memory driver for adaptive loops
\remark Runs Chef and then PHASTA until the user-specified maximum
PHASTA time step is reached.
*/
namespace {
void freeMesh(apf::Mesh* m) {
m->destroyNative();
apf::destroyMesh(m);
}
}
void setupChef(ph::Input& ctrl, int step) {
//don't split or tetrahedronize
ctrl.splitFactor = 1;
ctrl.tetrahedronize = 0;
ctrl.timeStepNumber = step;
ctrl.solutionMigration = 1;
if(step>1) {
ctrl.adaptStrategy = 2;
ctrl.adaptErrorThreshold = 1e-2;
ctrl.adaptErrorFieldName = "errors";
ctrl.adaptErrorFieldIndex = 0;
ctrl.adaptFlag = 1;
}
}
int main(int argc, char** argv) {
MPI_Init(&argc, &argv);
PCU_Comm_Init();
PCU_Protect();
if( argc != 2 ) {
if(!PCU_Comm_Self())
fprintf(stderr, "Usage: %s <maxTimeStep>\n",argv[0]);
exit(EXIT_FAILURE);
}
int maxStep = atoi(argv[1]);
chefPhasta::initModelers();
gmi_model* g = 0;
apf::Mesh2* m = 0;
grstream grs = makeGRStream();
ph::Input ctrl;
ctrl.load("adapt.inp");
chef::cook(g,m,ctrl,grs);
rstream rs = makeRStream();
phSolver::Input inp("solver.inp", "input.config");
int step = 0;
do {
step = phasta(inp,grs,rs);
clearGRStream(grs);
if(!PCU_Comm_Self())
fprintf(stderr, "CAKE ran to step %d\n", step);
setupChef(ctrl,step);
chef::cook(g,m,ctrl,rs,grs);
clearRStream(rs);
} while( step < maxStep );
destroyGRStream(grs);
destroyRStream(rs);
freeMesh(m);
chefPhasta::finalizeModelers();
PCU_Comm_Free();
MPI_Finalize();
}