Reference

Primitive Recovery

class con2prim_mhd

Class representing conservative to primitive conversion for ideal MHD.

This function object stores EOS, required accuracy, error policies, and artificial atmosphere settings.

Public Functions

con2prim_mhd(eos_thermal eos_, real_t rho_strict_, bool ye_lenient_, real_t z_lim_, real_t b_lim_, const atmosphere &atmo_, real_t acc_, int max_iter_)

Constructor.

Parameters
  • eos_ – The EOS

  • rho_strict_ – Density above which most corrections are forbidden (strict regime)

  • ye_lenient_ – Whether to allow restricting the electron fraction to valid range also in the strict regime

  • z_lim_ – Speed limit in terms of \( z = W v \)

  • b_lim_ – Fail for magnetization \( b>b_\mathrm{lim} \)

  • atmo_ – Specifies artificial atmosphere

  • acc_ – Required accuracy \( \Delta \) (see article).

  • max_iter_ – Maximum allowed iterations for root finding.

void operator()(prim_vars_mhd &pv, cons_vars_mhd &cv, const sm_metric3 &g, report &errs) const

Convert from conserved to primitive variables.

After the call, pv and cv are fully consistent. If the input was invalid and the error policy did not allow to correct it, pv and cv members are all set to NAN, and rep.failed() == true. If the evolved variables were corrected, rep.adjust_cons == true. If artificial atmosphere was applied, rep.set_atmo == true in addition.

Parameters
  • pv – Recovered primitive variables will be stored here

  • cv – Evolved variables for which to recover primitives. If corrections are applied, this contains the corrected values after the call.

  • g – The 3-metric

  • errs – Reports the outcome (validity, corrections, etc).

inline real_t get_acc() const

Get prescribed accuracy.

inline real_t get_z_lim() const

Get prescribed limit on z.

inline real_t get_v_lim() const

Get prescribed limit on v.

inline real_t get_b_lim() const

Get prescribed limit on b.

inline const atmosphere &get_atmo() const

Get prescribed atmosphere.

struct c2p_mhd_report

Struct to represent the outcome of a con2prim call.

This should be checked after con2prim. The various members indicate success or failure, if the conserved variables were changed, or artificial atmosphere applied.

Public Types

enum err_code

Failure flags.

Values:

enumerator SUCCESS

Recovery succeeded (possibly after allowed corrections)

enumerator INVALID_DETG

3-metric determinant not positive or NAN/INF

enumerator NEG_BSQR

Negative B square, metric not positive definite.

enumerator NANS_IN_CONS

One or more evolved variables is NAN/INF.

enumerator RANGE_RHO

Mass density outside EOS range.

enumerator RANGE_EPS

Fluid internal energy outside EOS range.

enumerator SPEED_LIMIT

Speed limit exceeded.

enumerator RANGE_YE

Electron fraction outside EOS range.

enumerator B_LIMIT

Magnetization above limit.

enumerator ROOT_FAIL_CONV

Root finding did not converge (this should never happen)

enumerator ROOT_FAIL_BRACKET

Bracketing of root failed (this should never happen)

enumerator PREP_ROOT_FAIL_CONV

Auxiliary root finding did not converge (this should never happen)

enumerator PREP_ROOT_FAIL_BRACKET

Bracketing of auxiliary root failed (this should never happen)

enumerator ERR_CODE_NOT_SET

Public Functions

c2p_mhd_report() = default

Default constructor, resulting object invalid.

void raise() const

Throw an exception with the debug message.

std::string debug_message() const

This assembles a human readable debug message from the flags and numerical values stored internally (for performance reasons, no string is ever created before explicitly requested via this function).

Returns

String with debug information.

inline bool failed() const
Returns

If the input was invalid according to the error policy.

Public Members

err_code status = {ERR_CODE_NOT_SET}

SUCCESS or reason for failure.

bool adjust_cons = {false}

Whether the conserved variables were adjusted.

bool set_atmo = {false}

Whether the artificial atmosphere was enforced.

unsigned int iters = {0}

Number of calls to the EOS needed for the root finding.

Primitive Variables

struct prim_vars

Structure to represent the primitive hydrodynamic variables.

Subclassed by EOS_Toolkit::prim_vars_mhd

Public Functions

prim_vars() = default

Default constructor. Leaves all members uninitialized.

prim_vars(const prim_vars&) = default

Trivial copy constructor.

prim_vars(prim_vars&&) = default

Trivial move constructor.

prim_vars &operator=(const prim_vars&) = default

Trivial copy assignment.

prim_vars &operator=(prim_vars&&) = default

Trivial move assignment.

inline prim_vars(real_t rho_, real_t eps_, real_t ye_, real_t press_, sm_vec3u vel_, real_t w_lor_)

Construct from single variables.

void scatter(real_t &rho_, real_t &eps_, real_t &ye_, real_t &press_, real_t &velx_, real_t &vely_, real_t &velz_, real_t &w_lor_) const

Convenience method to copy the members into single variables.

void set_to_nan()

Set all data to NAN.

Public Members

real_t rho

Rest mass density \( \rho \).

real_t eps

Specific internal energy \( \epsilon \).

real_t ye

Electron fraction \( Y_e \).

real_t press

Pressure \( P \).

sm_vec3u vel

3-velocity \( v^i \)

real_t w_lor

Lorentz factor \( W \).

struct prim_vars_mhd : public EOS_Toolkit::prim_vars

Class representing magnetohydrodynamic primitive variables.

Public Functions

prim_vars_mhd() = default

Default constructor, no initialization.

prim_vars_mhd(const prim_vars_mhd&) = default

Trivial copy constructor.

prim_vars_mhd(prim_vars_mhd&&) = default

Trivial move constructor.

prim_vars_mhd &operator=(const prim_vars_mhd&) = default

Trivial copy assignment.

prim_vars_mhd &operator=(prim_vars_mhd&&) = default

Trivial move assignment.

inline prim_vars_mhd(real_t rho_, real_t eps_, real_t ye_, real_t press_, sm_vec3u vel_, real_t w_lor_, sm_vec3u E_, sm_vec3u B_)

Construct from single variables.

void scatter(real_t &rho_, real_t &eps_, real_t &ye_, real_t &press_, real_t &velx_, real_t &vely_, real_t &velz_, real_t &w_lor_, real_t &E_x_, real_t &E_y_, real_t &E_z_, real_t &B_x_, real_t &B_y_, real_t &B_z_) const

Convenience method to copy the members into single variables.

void set_to_nan()

Set all data to NAN.

Public Members

sm_vec3u E

Electric field \( E^i \).

sm_vec3u B

Magnetic field \( B^i \).

Conserved Variables

struct cons_vars

Structure to represent conserved variables for pure hydrodynamics.

Subclassed by EOS_Toolkit::cons_vars_mhd

Public Functions

cons_vars() = default

Default constructor, no initialization.

cons_vars(const cons_vars&) = default

Trivial copy constructor.

cons_vars(cons_vars&&) = default

Trivial move constructor.

cons_vars &operator=(cons_vars&&) = default

Trivial copy assignment.

cons_vars &operator=(const cons_vars&) = default

Trivial move assignment.

inline cons_vars(real_t dens_, real_t tau_, real_t tracer_ye_, sm_vec3l scon_)

Construct from single variables.

void from_prim(const prim_vars &pv, const sm_metric3 &g)

Compute conserved variables from primitives and 3-metric.

The conserved variables are computed from

\[\begin{split}D &= V_c W \rho \\ S_i &= V_c W^2 \rho h v_i \\ \tau &= V_c W^2 \left( v^2 \left( \rho \frac{W}{1 + W} + P \right) + \rho \epsilon \right) \\ Y_e^T &= D Y_e \end{split}\]

where \(V_c = \sqrt{\det(g_{ij})}\) is the 3-metric volume element. The formula for \(\tau\) is written in a way which is accurate also in the Newtonian limit, i.e. for \(v^2 \ll 1, \epsilon \ll 1\).

void scatter(real_t &dens_, real_t &tau_, real_t &tracer_ye_, real_t &sconx_, real_t &scony_, real_t &sconz_) const

Convenience method to copy all members into single variables.

void set_to_nan()

Set all data to NAN.

Public Members

real_t dens

Conserved density \( D \).

real_t tau

Conserved energy \( \tau \).

real_t tracer_ye

Conserved tracer \( Y_e^T \) for the electron fraction.

sm_vec3l scon

Conserved momentum \( S_i \).

struct cons_vars_mhd : public EOS_Toolkit::cons_vars

Class to represent ideal MHD conserved variables.

Public Functions

cons_vars_mhd() = default

Default constructor, no initialization.

cons_vars_mhd(const cons_vars_mhd&) = default

Trivial copy constructor.

cons_vars_mhd(cons_vars_mhd&&) = default

Trivial move constructor.

cons_vars_mhd &operator=(cons_vars_mhd&&) = default

Trivial copy assignment.

cons_vars_mhd &operator=(const cons_vars_mhd&) = default

Trivial move assignment.

inline cons_vars_mhd(real_t dens_, real_t tau_, real_t tracer_ye_, sm_vec3l scon_, sm_vec3u bcons_)

Construct from single variables.

void from_prim(const prim_vars_mhd &pv, const sm_metric3 &g)

Compute conserved variables from primitives and 3-metric.

void scatter(real_t &dens_, real_t &tau_, real_t &tracer_ye_, real_t &sconx_, real_t &scony_, real_t &sconz_, real_t &bconx_, real_t &bcony_, real_t &bconz_) const

Convenience method to copy all members into single variables.

void set_to_nan()

Set all data to NAN.

Public Members

sm_vec3u bcons

Densitized magnetic field.

Artificial Atmosphere

struct atmosphere

Class representing an artificial atmosphere.

Public Functions

atmosphere(real_t rho_, real_t eps_, real_t ye_, real_t press_, real_t rho_cut_)

Constructor.

Parameters
  • rho_ – Atmosphere mass density

  • eps_ – Atmosphere specific internal energy

  • ye_ – Atmosphere electron fraction

  • press_ – Atmosphere pressure

  • rho_cut_ – Mass density below which to apply atmosphere

atmosphere(const atmosphere&) = default

Trivial copy constructor

void set(prim_vars &pv) const

Set pure hydro primitive variables to atmosphere.

Parameters

pv – Primitive variables (hydro)

void set(cons_vars &cv, const sm_metric3 &g) const

Set pure hydro evolved vars to atmosphere.

Parameters
  • cv – Evolved variables (hydro)

  • g – 3-metric

void set(prim_vars &pv, cons_vars &cv, const sm_metric3 &g) const

Set pure hydro primitive and evolved variables to atmosphere.

Parameters
  • pv – Primitive variables (hydro)

  • cv – Evolved variables (hydro)

  • g – 3-metric

void set(prim_vars_mhd &pv) const

Set ideal MHD primitive variables to atmosphere.

Parameters

pv – Primitive variables (GRMHD)

void set(cons_vars_mhd &cv, const sm_metric3 &g) const

Set ideal MHD conserved variables to atmosphere.

Parameters
  • cv – Conserved vars

  • g – The 3-metric

  • cv – Evolved variables (GRMHD)

  • g – 3-metric

void set(prim_vars_mhd &pv, cons_vars_mhd &cv, const sm_metric3 &g) const

Set ideal MHD primitives and conserved variables to atmosphere.

Parameters
  • pv – Primitive variables (GRMHD)

  • cv – Evolved variables (GRMHD)

  • g – 3-metric

Public Members

const real_t rho

Rest mass density of the atmosphere.

const real_t eps

Specific internal energy.

const real_t ye

Electron fraction.

const real_t press

Pressure.

const real_t rho_cut

Cutoff density below which we set to atmosphere.