-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathchef_phasta_adaptLoop_posix.cc
110 lines (101 loc) · 2.77 KB
/
chef_phasta_adaptLoop_posix.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
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
#include <PCU.h>
#include <chef.h>
#include <phasta.h>
#include <phstream.h>
#include <iostream>
#include <sstream>
#include "chefPhasta.h"
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
/** \file chef_phasta_adaptLoop_posix.cc
\brief Example file-based 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 mychdir(int step) {
std::stringstream path;
path << step;
string s = path.str();
const int fail = chdir(s.c_str());
if(fail) {
fprintf(stderr, "ERROR failed to change to %d dir... exiting\n", step);
exit(1);
}
}
std::string makeMeshName(int step) {
std::stringstream meshname;
meshname << "bz2:" << "t" << step << "p" << PCU_Comm_Peers() << "/";
return meshname.str();
}
std::string makeRestartName() {
std::stringstream restartname;
restartname << PCU_Comm_Peers() << "-procs_case/restart";
return restartname.str();
}
std::string prefixCwd(std::string name) {
char cwd[4096] = "\0";
getcwd(cwd,4096);
std::stringstream s;
s << cwd << "/" << name;
return s.str();
}
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; //error field adapt
ctrl.adaptErrorThreshold = 1e-2;
ctrl.adaptErrorFieldName = "errors";
ctrl.adaptErrorFieldIndex = 0;
ctrl.adaptFlag = 1;
}
ctrl.outMeshFileName = makeMeshName(step);
ctrl.restartFileName = makeRestartName();
}
}
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;
ph::Input ctrl;
ctrl.load("adapt.inp");
ctrl.modelFileName = prefixCwd(ctrl.modelFileName);
ctrl.attributeFileName = prefixCwd(ctrl.attributeFileName);
ctrl.outMeshFileName = makeMeshName(0);
chef::cook(g,m,ctrl);
freeMesh(m); m = NULL;
phSolver::Input inp("solver.inp", "input.config");
int step = 0;
do {
ctrl.meshFileName = makeMeshName(step);
step = phasta(inp);
assert(step >= 0);
if(!PCU_Comm_Self())
fprintf(stderr, "CAKE ran to step %d\n", step);
setupChef(ctrl,step);
chef::cook(g,m,ctrl);
freeMesh(m); m = NULL;
mychdir(step);
} while( step < maxStep );
chefPhasta::finalizeModelers();
PCU_Comm_Free();
MPI_Finalize();
}