Skip to content

Commit f1dadcc

Browse files
authored
Merge pull request #190 from bendudson/fix-boundaries
WIP: Boundaries and misc fixes
2 parents 59a4910 + b25db54 commit f1dadcc

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

src/electron_force_balance.cxx

+6-19
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,8 @@ void ElectronForceBalance::transform(Options &state) {
1818
// Note: The pressure boundary can be set in sheath boundary condition
1919
// which depends on the electron velocity being set here first.
2020
Options& electrons = state["species"]["e"];
21-
Field3D Pe = getNoBoundary<Field3D>(electrons["pressure"]);
22-
23-
// Note: only parallel boundaries needed
24-
for (RangeIterator r = mesh->iterateBndryLowerY(); !r.isDone(); r++) {
25-
for (int jz = 0; jz < mesh->LocalNz; jz++) {
26-
Pe(r.ind, mesh->ystart - 1, jz) = Pe(r.ind, mesh->ystart, jz);
27-
}
28-
}
29-
for (RangeIterator r = mesh->iterateBndryUpperY(); !r.isDone(); r++) {
30-
for (int jz = 0; jz < mesh->LocalNz; jz++) {
31-
Pe(r.ind, mesh->yend + 1, jz) = Pe(r.ind, mesh->yend, jz);
32-
}
33-
}
34-
35-
Field3D Ne = getNoBoundary<Field3D>(electrons["density"]);
21+
Field3D Pe = GET_VALUE(Field3D, electrons["pressure"]);
22+
Field3D Ne = GET_NOBOUNDARY(Field3D, electrons["density"]);
3623

3724
ASSERT1(get<BoutReal>(electrons["charge"]) == -1.0);
3825

@@ -41,8 +28,8 @@ void ElectronForceBalance::transform(Options &state) {
4128

4229
if (IS_SET(electrons["momentum_source"])) {
4330
// Balance other forces from e.g. collisions
44-
// Note: marked as final so can't be set later
45-
force_density += get<Field3D>(electrons["momentum_source"]);
31+
// Note: marked as final so can't be changed later
32+
force_density += GET_VALUE(Field3D, electrons["momentum_source"]);
4633
}
4734
const Field3D Epar = force_density / floor(Ne, 1e-5);
4835

@@ -54,11 +41,11 @@ void ElectronForceBalance::transform(Options &state) {
5441
}
5542
Options& species = allspecies[kv.first]; // Note: Need non-const
5643

57-
if (!(species.isSet("density") and species.isSet("charge"))) {
44+
if (!(IS_SET(species["density"]) and IS_SET(species["charge"]))) {
5845
continue; // Needs both density and charge to experience a force
5946
}
6047

61-
const Field3D N = getNoBoundary<Field3D>(species["density"]);
48+
const Field3D N = GET_NOBOUNDARY(Field3D, species["density"]);
6249
const BoutReal charge = get<BoutReal>(species["charge"]);
6350

6451
add(species["momentum_source"],

src/evolve_energy.cxx

+32-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ void EvolveEnergy::transform(Options& state) {
144144
P[i] = 0.0;
145145
}
146146
}
147-
148147
P.applyBoundary("neumann");
149148

150149
if (neumann_boundary_average_z) {
@@ -200,6 +199,37 @@ void EvolveEnergy::finally(const Options& state) {
200199
T = get<Field3D>(species["temperature"]);
201200
N = get<Field3D>(species["density"]);
202201
const Field3D V = get<Field3D>(species["velocity"]);
202+
const BoutReal AA = get<BoutReal>(species["AA"]);
203+
204+
// Update boundaries of E from boundaries of P and V
205+
E = toFieldAligned(E);
206+
for (RangeIterator r = mesh->iterateBndryLowerY(); !r.isDone(); r++) {
207+
for (int jz = 0; jz < mesh->LocalNz; jz++) {
208+
auto i = indexAt(N, r.ind, mesh->ystart, jz);
209+
auto im = i.ym();
210+
211+
const BoutReal psheath = 0.5 * (P[im] + P[i]);
212+
const BoutReal nsheath = 0.5 * (N[im] + N[i]);
213+
const BoutReal vsheath = 0.5 * (V[im] + V[i]);
214+
215+
const BoutReal Esheath = Cv * psheath + 0.5 * AA * nsheath * SQ(vsheath);
216+
E[im] = 2 * Esheath - E[i];
217+
}
218+
}
219+
for (RangeIterator r = mesh->iterateBndryUpperY(); !r.isDone(); r++) {
220+
for (int jz = 0; jz < mesh->LocalNz; jz++) {
221+
auto i = indexAt(N, r.ind, mesh->yend, jz);
222+
auto ip = i.yp();
223+
224+
const BoutReal psheath = 0.5 * (P[ip] + P[i]);
225+
const BoutReal nsheath = 0.5 * (N[ip] + N[i]);
226+
const BoutReal vsheath = 0.5 * (V[ip] + V[i]);
227+
228+
const BoutReal Esheath = Cv * psheath + 0.5 * AA * nsheath * SQ(vsheath);
229+
E[ip] = 2 * Esheath - E[i];
230+
}
231+
}
232+
E = fromFieldAligned(E);
203233

204234
Field3D Pfloor = P;
205235

@@ -306,7 +336,7 @@ void EvolveEnergy::finally(const Options& state) {
306336
if (species.isSet("energy_source")) {
307337
Se += get<Field3D>(species["energy_source"]); // For diagnostic output
308338
}
309-
if (species.isSet("energy_source")) {
339+
if (species.isSet("momentum_source")) {
310340
Se += V * get<Field3D>(species["momentum_source"]);
311341
}
312342
ddt(E) += Se;

0 commit comments

Comments
 (0)