Skip to content

Commit 5689ab1

Browse files
committed
format, add div by 0 mod to SRK transport, const protect Yloc
1 parent 90f1a19 commit 5689ab1

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

Source/Transport/Simple.H

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ struct BinaryDiff
164164
}
165165
}
166166
for (int i = 0; i < NUM_SPECIES; ++i) {
167-
amrex::Real term1 = 0;
168-
for (int j = 0; j < NUM_SPECIES; ++j) {
169-
if (i != j) {
170-
term1 += Yloc[j];
171-
}
167+
amrex::Real term1 = 0;
168+
for (int j = 0; j < NUM_SPECIES; ++j) {
169+
if (i != j) {
170+
term1 += Yloc[j];
172171
}
172+
}
173173
Ddiag[i] = tparm->wt[i] * term1 / Ddiag[i] * scale;
174174
}
175175
}
@@ -190,9 +190,7 @@ struct BinaryDiff<eos::SRK>
190190
TransParm<eos::SRK, SimpleTransport> const* tparm)
191191
{
192192

193-
amrex::Real sum_of_Yloc = 0.0;
194193
for (int i = 0; i < NUM_SPECIES; ++i) {
195-
sum_of_Yloc += Yloc[i];
196194
Ddiag[i] = 0.0;
197195
}
198196

@@ -219,7 +217,12 @@ struct BinaryDiff<eos::SRK>
219217
}
220218
}
221219
for (int i = 0; i < NUM_SPECIES; ++i) {
222-
const amrex::Real term1 = sum_of_Yloc - Yloc[i];
220+
amrex::Real term1 = 0;
221+
for (int j = 0; j < NUM_SPECIES; ++j) {
222+
if (i != j) {
223+
term1 += Yloc[j];
224+
}
225+
}
223226
Ddiag[i] = tparm->wt[i] * term1 / Ddiag[i];
224227
}
225228
}
@@ -296,7 +299,7 @@ struct SimpleTransport
296299
const bool wtr_get_chi,
297300
const amrex::Real Tloc,
298301
const amrex::Real rholoc,
299-
amrex::Real* Yloc,
302+
const amrex::Real* Yloc,
300303
amrex::Real* Ddiag,
301304
amrex::Real* chi_mix,
302305
amrex::Real& mu,
@@ -306,6 +309,7 @@ struct SimpleTransport
306309
{
307310
amrex::Real trace = 1.e-15;
308311
amrex::Real Xloc[NUM_SPECIES] = {0.0};
312+
amrex::Real Yloc_mod[NUM_SPECIES] = {0.0};
309313
amrex::Real muloc[NUM_SPECIES] = {0.0};
310314
amrex::Real xiloc[NUM_SPECIES] = {0.0};
311315
amrex::Real logT[NUM_FIT - 1] = {0.0};
@@ -314,23 +318,22 @@ struct SimpleTransport
314318
logT[1] = logT[0] * logT[0];
315319
logT[2] = logT[0] * logT[1];
316320

321+
// Modify Yloc to avoid potential divide by 0 for pure components
317322
amrex::Real sum = 0.0;
318-
319323
for (int i = 0; i < NUM_SPECIES; ++i) {
320324
sum += Yloc[i];
321325
}
322-
323326
for (int i = 0; i < NUM_SPECIES; ++i) {
324-
Yloc[i] += trace * (sum / NUM_SPECIES - Yloc[i]);
327+
Yloc_mod[i] = Yloc[i] + trace * (sum / NUM_SPECIES - Yloc[i]);
325328
}
326329

327330
amrex::Real wbar = 0.0;
328331
for (int i = 0; i < NUM_SPECIES; ++i) {
329-
wbar += Yloc[i] * tparm->iwt[i];
332+
wbar += Yloc_mod[i] * tparm->iwt[i];
330333
}
331334
wbar = 1.0 / wbar;
332335
for (int i = 0; i < NUM_SPECIES; ++i) {
333-
Xloc[i] = Yloc[i] * wbar * tparm->iwt[i];
336+
Xloc[i] = Yloc_mod[i] * wbar * tparm->iwt[i];
334337
}
335338
if (wtr_get_mu) {
336339
for (int i = 0; i < NUM_SPECIES; ++i) {
@@ -382,7 +385,7 @@ struct SimpleTransport
382385
wtr_get_mu, wtr_get_lam, Tloc, Xloc, rholoc, wbar, mu, lam, tparm);
383386

384387
if (wtr_get_Ddiag) {
385-
BinaryDiff<EosType>()(Xloc, Yloc, logT, rholoc, Tloc, Ddiag, tparm);
388+
BinaryDiff<EosType>()(Xloc, Yloc_mod, logT, rholoc, Tloc, Ddiag, tparm);
386389
}
387390

388391
if (wtr_get_chi) {

0 commit comments

Comments
 (0)