11#include < bout/fv_ops.hxx>
2+ #include < vecops.hxx>
23
34#include " ../include/diamagnetic_drift.hxx"
45
@@ -13,6 +14,10 @@ DiamagneticDrift::DiamagneticDrift(std::string name, Options& alloptions,
1314 bndry_flux =
1415 options[" bndry_flux" ].doc (" Allow fluxes through boundary?" ).withDefault <bool >(true );
1516
17+ diamag_form = options[" diamag_form" ]
18+ .doc (" Form of diamagnetic drift: 0 = gradient; 1 = divergence" )
19+ .withDefault (Field2D (1.0 ));
20+
1621 // Read curvature vector
1722 Curlb_B.covariant = false ; // Contravariant
1823 if (mesh->get (Curlb_B, " bxcv" )) {
@@ -41,6 +46,15 @@ DiamagneticDrift::DiamagneticDrift(std::string name, Options& alloptions,
4146 Curlb_B.z *= SQ (Lnorm);
4247
4348 Curlb_B *= 2 . / mesh->getCoordinates ()->Bxy ;
49+
50+ // Set drift to zero through sheath boundaries.
51+ // Flux through those cell faces should be set by sheath.
52+ for (RangeIterator r = mesh->iterateBndryLowerY (); !r.isDone (); r++) {
53+ Curlb_B.y (r.ind , mesh->ystart - 1 ) = -Curlb_B.y (r.ind , mesh->ystart );
54+ }
55+ for (RangeIterator r = mesh->iterateBndryUpperY (); !r.isDone (); r++) {
56+ Curlb_B.y (r.ind , mesh->yend + 1 ) = -Curlb_B.y (r.ind , mesh->yend );
57+ }
4458}
4559
4660void DiamagneticDrift::transform (Options& state) {
@@ -62,17 +76,28 @@ void DiamagneticDrift::transform(Options& state) {
6276
6377 if (IS_SET (species[" density" ])) {
6478 auto N = GET_VALUE (Field3D, species[" density" ]);
65- subtract (species[" density_source" ], FV::Div_f_v (N, vD, bndry_flux));
79+
80+ // Divergence form: Div(n v_D)
81+ Field3D div_form = FV::Div_f_v (N, vD, bndry_flux);
82+ // Gradient form: Curlb_B dot Grad(N T / q)
83+ Field3D grad_form = Curlb_B * Grad (N * T / q);
84+
85+ subtract (species[" density_source" ], diamag_form * div_form + (1 . - diamag_form) * grad_form);
6686 }
6787
6888 if (IS_SET (species[" pressure" ])) {
6989 auto P = get<Field3D>(species[" pressure" ]);
70- subtract (species[" energy_source" ], (5 . / 2 ) * FV::Div_f_v (P, vD, bndry_flux));
90+
91+ Field3D div_form = FV::Div_f_v (P, vD, bndry_flux);
92+ Field3D grad_form = Curlb_B * Grad (P * T / q);
93+ subtract (species[" energy_source" ], (5 . / 2 ) * (diamag_form * div_form + (1 . - diamag_form) * grad_form));
7194 }
7295
7396 if (IS_SET (species[" momentum" ])) {
7497 auto NV = get<Field3D>(species[" momentum" ]);
75- subtract (species[" momentum_source" ], FV::Div_f_v (NV, vD, bndry_flux));
98+ Field3D div_form = FV::Div_f_v (NV, vD, bndry_flux);
99+ Field3D grad_form = Curlb_B * Grad (NV * T / q);
100+ subtract (species[" momentum_source" ], diamag_form * div_form + (1 . - diamag_form) * grad_form);
76101 }
77102 }
78103}
0 commit comments