-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprob.cpp
219 lines (192 loc) · 6.32 KB
/
prob.cpp
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
#include "prob.H"
std::string
read_pmf_file(std::ifstream& in)
{
return static_cast<std::stringstream const&>(
std::stringstream() << in.rdbuf())
.str();
}
bool
checkQuotes(const std::string& str)
{
int count = 0;
for (char c : str) {
if (c == '"') {
count++;
}
}
return (count % 2) == 0;
}
void
read_pmf(const std::string& myfile)
{
std::string firstline;
std::string secondline;
std::string remaininglines;
unsigned int pos1;
unsigned int pos2;
int variable_count;
int line_count;
std::ifstream infile(myfile);
const std::string memfile = read_pmf_file(infile);
infile.close();
std::istringstream iss(memfile);
std::getline(iss, firstline);
if (!checkQuotes(firstline)) {
amrex::Abort("PMF file variable quotes unbalanced");
}
std::getline(iss, secondline);
pos1 = 0;
pos2 = 0;
variable_count = 0;
while ((pos1 < firstline.length() - 1) && (pos2 < firstline.length() - 1)) {
pos1 = firstline.find('"', pos1);
pos2 = firstline.find('"', pos1 + 1);
variable_count++;
pos1 = pos2 + 1;
}
pos1 = 0;
for (int i = 0; i < variable_count; i++) {
pos1 = firstline.find('"', pos1);
pos2 = firstline.find('"', pos1 + 1);
pos1 = pos2 + 1;
}
amrex::Print() << variable_count << " variables found in PMF file"
<< std::endl;
// for (int i = 0; i < variable_count; i++)
// amrex::Print() << "Variable found: " << pmf_names[i] <<
// std::endl;
line_count = 0;
while (std::getline(iss, remaininglines)) {
line_count++;
}
amrex::Print() << line_count << " data lines found in PMF file" << std::endl;
PeleC::h_prob_parm_device->pmf_N = line_count;
PeleC::h_prob_parm_device->pmf_M = variable_count - 1;
PeleC::prob_parm_host->h_pmf_X.resize(PeleC::h_prob_parm_device->pmf_N);
PeleC::prob_parm_host->pmf_X.resize(PeleC::h_prob_parm_device->pmf_N);
PeleC::prob_parm_host->h_pmf_Y.resize(
static_cast<long>(PeleC::h_prob_parm_device->pmf_N) *
PeleC::h_prob_parm_device->pmf_M);
PeleC::prob_parm_host->pmf_Y.resize(
static_cast<long>(PeleC::h_prob_parm_device->pmf_N) *
PeleC::h_prob_parm_device->pmf_M);
iss.clear();
iss.seekg(0, std::ios::beg);
std::getline(iss, firstline);
std::getline(iss, secondline);
for (int i = 0; i < PeleC::h_prob_parm_device->pmf_N; i++) {
std::getline(iss, remaininglines);
std::istringstream sinput(remaininglines);
sinput >> PeleC::prob_parm_host->h_pmf_X[i];
for (int j = 0; j < PeleC::h_prob_parm_device->pmf_M; j++) {
sinput >> PeleC::prob_parm_host
->h_pmf_Y[j * PeleC::h_prob_parm_device->pmf_N + i];
}
}
amrex::Gpu::copy(
amrex::Gpu::hostToDevice, PeleC::prob_parm_host->h_pmf_X.begin(),
PeleC::prob_parm_host->h_pmf_X.end(), PeleC::prob_parm_host->pmf_X.begin());
amrex::Gpu::copy(
amrex::Gpu::hostToDevice, PeleC::prob_parm_host->h_pmf_Y.begin(),
PeleC::prob_parm_host->h_pmf_Y.end(), PeleC::prob_parm_host->pmf_Y.begin());
PeleC::h_prob_parm_device->d_pmf_X = PeleC::prob_parm_host->pmf_X.data();
PeleC::h_prob_parm_device->d_pmf_Y = PeleC::prob_parm_host->pmf_Y.data();
}
void
init_bc()
{
amrex::Real vt;
amrex::Real ek;
amrex::Real T;
amrex::Real rho;
amrex::Real e;
amrex::Real molefrac[NUM_SPECIES];
amrex::Real massfrac[NUM_SPECIES];
amrex::GpuArray<amrex::Real, NUM_SPECIES + 4> pmf_vals = {{0.0}};
amrex::Print() << " Initiate BC" << std::endl;
const amrex::Real xl = 0.0;
const amrex::Real xr = 0.0;
// Use host pointers for host call to pmf()
PeleC::h_prob_parm_device->d_pmf_X = PeleC::prob_parm_host->h_pmf_X.data();
PeleC::h_prob_parm_device->d_pmf_Y = PeleC::prob_parm_host->h_pmf_Y.data();
pmf(xl, xr, pmf_vals, *PeleC::h_prob_parm_device);
// Switch back to device pointers
PeleC::h_prob_parm_device->d_pmf_X = PeleC::prob_parm_host->pmf_X.data();
PeleC::h_prob_parm_device->d_pmf_Y = PeleC::prob_parm_host->pmf_Y.data();
for (int n = 0; n < NUM_SPECIES; n++) {
molefrac[n] = amrex::max<amrex::Real>(0.0, pmf_vals[3 + n]);
}
T = pmf_vals[0];
PeleC::h_prob_parm_device->vn_in = pmf_vals[1];
const amrex::Real p = PeleC::h_prob_parm_device->pamb;
auto eos = pele::physics::PhysicsType::eos();
eos.X2Y(molefrac, massfrac);
eos.PYT2RE(p, massfrac, T, rho, e);
vt = PeleC::h_prob_parm_device->vn_in;
ek = 0.5 * (vt * vt);
PeleC::h_prob_parm_device->fuel_state[URHO] = rho;
PeleC::h_prob_parm_device->fuel_state[UMX] = 0.0;
PeleC::h_prob_parm_device->fuel_state[UMY] = rho * vt;
PeleC::h_prob_parm_device->fuel_state[UMZ] = 0.0;
PeleC::h_prob_parm_device->fuel_state[UEINT] = rho * e;
PeleC::h_prob_parm_device->fuel_state[UEDEN] = rho * (e + ek);
PeleC::h_prob_parm_device->fuel_state[UTEMP] = T;
for (int n = 0; n < NUM_SPECIES; n++) {
PeleC::h_prob_parm_device->fuel_state[UFS + n - 1] = rho * massfrac[n];
}
}
void
pc_prob_close()
{
}
extern "C" {
void
amrex_probinit(
const int* /*init*/,
const int* /*name*/,
const int* /*namelen*/,
const amrex::Real* problo,
const amrex::Real* probhi)
{
std::string pmf_datafile;
amrex::ParmParse pp("prob");
// Thermodynamic State Input Values
pp.query("pamb", PeleC::h_prob_parm_device->pamb);
pp.query("T_in", PeleC::h_prob_parm_device->T_in);
// Mixture Input Parameters
// Flow Input Parameters
pp.query("vn_in", PeleC::h_prob_parm_device->vn_in);
// Additional Input Parameters
pp.query("standoff", PeleC::h_prob_parm_device->standoff);
pp.query("kernel_radii", PeleC::h_prob_parm_device->kernel_radii);
pp.query("kernel_width", PeleC::h_prob_parm_device->kernel_width);
pp.query("kernel_position", PeleC::h_prob_parm_device->kernel_position);
pp.query("kernel_smoothing", PeleC::h_prob_parm_device->kernel_smoothing);
// PMF Input Parameters
pp.query("pmf_datafile", pmf_datafile);
// Spatial Domain Length
amrex::Vector<amrex::Real> local_L(AMREX_SPACEDIM, -1);
pp.queryarr("L", local_L, 0, AMREX_SPACEDIM);
for (int i = 0; i < AMREX_SPACEDIM; i++) {
PeleC::h_prob_parm_device->L[i] = (local_L[i] == 0.0) ? probhi[i] - problo[i] : local_L[i];
}
// Boundary Condition Parameters
pp.query("inlet_type", PeleC::h_prob_parm_device->inlet_type);
pp.query("outlet_type", PeleC::h_prob_parm_device->outlet_type);
read_pmf(pmf_datafile);
init_bc();
}
}
void
PeleC::problem_post_timestep()
{
}
void
PeleC::problem_post_init()
{
}
void
PeleC::problem_post_restart()
{
}