-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathchef_phasta_sam_adaptLoop_sz_posix.cc
130 lines (119 loc) · 3.6 KB
/
chef_phasta_sam_adaptLoop_sz_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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "chefPhasta.h"
#include <PCU.h>
#include <pumi_version.h>
#include <chef.h>
#include <phasta.h>
#include <phstream.h>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <unistd.h>
/** \file chef_phasta_sam_adaptLoop_sz_posix.cc
\brief Example POSIX file-based driver for adaptive loops
\remark Runs Chef and then PHASTA until the user-specified maximum
PHASTA time step is reached. Size fields to drive adaptation
are defined using SAM (from
<a href=https://github.com/SCOREC/core>core</a>) in Chef
by reading the PHASTA "errors" field.
*/
namespace {
void pwd() {
if(!PCU_Comm_Self()) {
char path[4096];
getcwd(path,4096);
fprintf(stderr, "STATUS changed to %s dir\n", path);
}
}
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);
}
pwd();
}
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();
}
void freeMesh(apf::Mesh* m) {
m->destroyNative();
apf::destroyMesh(m);
}
void setupChef(ph::Input& ctrl, int step) {
//don't split or tetrahedronize
ctrl.printIOtime = 1; //report time spent streaming
ctrl.splitFactor = 1;
ctrl.tetrahedronize = 0;
ctrl.timeStepNumber = step;
ctrl.solutionMigration = 1;
ctrl.adaptStrategy = 1; //error field adapt
ctrl.adaptFlag = 1;
ctrl.restartFileName = makeRestartName();
ctrl.outMeshFileName = makeMeshName(step);
if(!PCU_Comm_Self()) {
fprintf(stderr, "STATUS error based adapt %d\n", step);
fprintf(stderr, "STATUS ctrl.attributeFileName %s step %d\n",
ctrl.attributeFileName.c_str(), step);
}
}
}
int main(int argc, char** argv) {
MPI_Init(&argc, &argv);
PCU_Comm_Init();
PCU_Protect();
if( argc != 3 ) {
if(!PCU_Comm_Self())
fprintf(stderr, "Usage: %s <maxTimeStep> <chef input config>\n",argv[0]);
exit(EXIT_FAILURE);
}
if( !PCU_Comm_Self() )
printf("PUMI Git hash %s\n", pumi_version());
int maxStep = atoi(argv[1]);
const char* chefinp = argv[2];
double t0 = PCU_Time();
chefPhasta::initModelers();
/* read chef config */
ph::Input ctrl;
ctrl.load(chefinp);
/* read restart files (and split if requested) */
ctrl.outMeshFileName = makeMeshName(ctrl.timeStepNumber);
gmi_model* g = NULL;
apf::Mesh2* m = NULL;
chef::cook(g,m,ctrl);
freeMesh(m); m = NULL;
phSolver::Input inp("solver.inp", "input.config");
int step = ctrl.timeStepNumber;
do {
double cycleStart = PCU_Time();
pwd();
/* The next Chef run needs to load the mesh from
* the solve that is about to run.*/
ctrl.meshFileName = makeMeshName(step);
step = phasta(inp);
if(!PCU_Comm_Self())
fprintf(stderr, "STATUS ran to step %d\n", step);
if( step >= maxStep )
break;
setupChef(ctrl,step);
chef::cook(g,m,ctrl);
freeMesh(m); m = NULL;
if(ctrl.adaptFlag) mychdir(step);
if(!PCU_Comm_Self())
fprintf(stderr, "cycle time %f seconds\n", PCU_Time()-cycleStart);
} while( step < maxStep );
chefPhasta::finalizeModelers();
if(!PCU_Comm_Self())
fprintf(stderr, "STATUS done %f seconds\n", PCU_Time()-t0);
PCU_Comm_Free();
MPI_Finalize();
}