MHD - #123
Conversation
…he LLF face fluxes. Only do mhd fluxes for n=0 species. Add a divB diagnostic variable.
…e cell field from the face field
…ion. This comes at increased complexity.
|
|
||
| // Add the "flux source terms" | ||
| for (int n = 0; n < nspecies; ++n) { | ||
| const bool mhd = (F == Fluid::gas) && do_mhd && (n == 0); |
There was a problem hiding this comment.
| const bool mhd = (F == Fluid::gas) && do_mhd && (n == 0); | |
| const bool mhd = do_mhd && (F == Fluid::gas) && (n == 0); |
|
This is now ready for review @pdmullen |
pdmullen
left a comment
There was a problem hiding this comment.
I'd like to see the linear modes test adapted to MHD and the field loop advection test before this goes in.
| @@ -0,0 +1,2050 @@ | |||
| # Athena++ data at time=8.000000e-02 cycle=1559 variables=prim | |||
There was a problem hiding this comment.
Does this need an Athena++ copyright?
| const auto xv = coords.GetCellCenter(vg, b, k, j, i); | ||
| const auto &bnds = coords.GetBounds(); | ||
| const Real bx = | ||
| ((bnds.x1[1] - xv[0]) * vmesh(b, TE::F1, field::face::B(), k, j, i) + |
There was a problem hiding this comment.
Maybe we should make a helper function for this. Maybe it can be templated on coordinates so that we can just do arithmetic average for cartesian.
| vmesh(b, TE::F3, field::face::B(), k + threed, j, i)) / | ||
| (bnds.x3[1] - bnds.x3[0])) | ||
| : vmesh(b, TE::F3, field::face::B(), k, j, i); | ||
| emag = MHD::MagneticEnergyDensity(bx, by, bz, mu0_code); |
There was a problem hiding this comment.
Maybe a helper function for cell-centered fields would be nice too. Would clean up duplicated above with below in this file.
| // Compute SIE via dual energy formalism and apply floor | ||
| Real sieg = ArtemisUtils::DualEnergySIE(vmesh, b, n, k, j, i, de_switch, hx); | ||
| const Real emag = | ||
| (do_mhd && (n == 0)) ? vmesh(b, field::cell::energy(), k, j, i) : 0.0; |
There was a problem hiding this comment.
why only n==0? I suspect that this is just a placeholder bc not all physics packages respect multiple gas species... but the magnetic field should inform all fields if all are coupled.
| // Compute SIE via dual energy formalism and apply floor | ||
| Real sie = ArtemisUtils::DualEnergySIE(vmesh, b, n, k, j, i, de_switch, hx); | ||
| const Real emag = | ||
| (do_mhd && (n == 0)) ? vmesh(b, field::cell::energy(), k, j, i) : 0.0; |
There was a problem hiding this comment.
same comments as above.... won't repeat hereafter.
| const bool do_moment = do_radiation && pin->DoesBlockExist("radiation/moment"); | ||
| const bool update_fluxes = pin->GetOrAddBoolean("gas", "update_fluxes", true); | ||
|
|
||
| // Check configuration selection compatibility |
There was a problem hiding this comment.
Shouldn't mhd require do_gas and update_fluxes (with the latter so that we can get upwind direction)?
| const Real t1 = SQR(vp_(b, IVX, k, j, i) + rfv[0]) - | ||
| (mhd ? SQR(vp_(b, field::cell::B(0), k, j, i)) / mu0 : 0.0); | ||
| const Real t2 = SQR(vp_(b, IVY, k, j, i) + rfv[1]) - | ||
| (mhd ? SQR(vp_(b, field::cell::B(1), k, j, i)) / mu0 : 0.0); | ||
| const Real t3 = SQR(vp_(b, IVZ, k, j, i) + rfv[2]) - | ||
| (mhd ? SQR(vp_(b, field::cell::B(2), k, j, i)) / mu0 : 0.0); |
There was a problem hiding this comment.
should these divide out rho since wdt contains rho?
| // a = (a < 0.0) ? 0.0 : sqrt(gm1 * a); | ||
| // Einfeldt (1988) | ||
| const Real ngam = 0.5 * sqrtdl * sqrtdr * SQR(isdlpdr); | ||
| Real a = |
There was a problem hiding this comment.
I am confused about the dimensionality of this... can you check?
qa is a fast magnetosonic speed and the second term has units of velocity squared?
| const Real ke = 0.5 * w_d * (SQR(vel1) + SQR(vel2) + SQR(vel3)); | ||
| Real me = 0.0; | ||
| if (do_mhd && (n == 0)) { | ||
| const Real bx = 0.5 * (vmesh(b, TE::F1, field::face::B(), k, j, i) + |
There was a problem hiding this comment.
no fancy centroid stuff here?
| coords.template GetScaleFactorsFace<X2DIR>(vg, b, k, j, i - 1); | ||
| const Real h3e = coords.template GetEdgeScaleFactor<X3DIR>(vg, b, k, j, i); | ||
| Real &emf = v.flux(b, TE::E3, field::face::B(), k, j, i); | ||
| emf = h3e * 0.25 * |
There was a problem hiding this comment.
straight averaging? no upwinding a la Gardiner & Stone?
Background
This adds ideal MHD. It should work with AMR and all coordinate systems. I have tested on the magnetized blast problem in cartesian/cylindrical coordinates with/without AMR (modified the existing pgen), the Orszag-Tang vortex (new pgen), and the Brio-Wu shock tube (new input file).
The outline of new features/changed things:
Overall, it's not too many new things and there isn't much in the input file that needed to change.
Some things I'm not too happy with that we might want to change:
This was done in concert with GPT.
I haven't tested on GPUs yet or anything high res. Initial testing looks pretty good though, I added a diagnostic div(B) field at that remains at machine epsilon even through AMR in cylindrical/cartesian coordinates.
Description of Changes
Closes #122
Checklist
// This file was created in part or in whole by generative AI