TfbiSolver

class PlasmaCalcs.addons.tfbi.tfbi_solver.TfbiSolver(cc, ions=None, *, kres='low', mod=UNSET, lmod=UNSET, ang=UNSET, tfbi_all=True, drel_cls=None)

Bases: object

high-level interface for solving TFBI theory across many physical parameters.

Call TfbiSolver to solve TFBI.

Example:
import PlasmaCalcs as pc
cc = pc.PlasmaCalculator(…) # <– your PlasmaCalculator of choice
solver = pc.TfbiSolver(cc)
solution = solver() # alias: solver.solve()
solution is an xarray.Dataset with all relevant quantities (see TfbiLoader.get_tfbi_all),
and ‘omega’ telling roots with largest imaginary part.
If you need more precise control over the solving process, use the pattern:
import tfbi_theory as tt
import PlasmaCalcs as pc
cc = … # any PlasmaCalculator object from PlasmaCalcs.
ds0 = cc.tfbi_ds()
kp = tt.kPickerLowres(ds0)
dsk = kp.get_ds() # copy of ds0, but with ds[‘k’] = k from kPicker.
drel = tt.TfbiDisprelC.from_ds(dsk)
dsR = drel.solve() # copy of dsk, but with ds[‘omega’] = solution to TFBI theory!
Notes:
if cc has more than ~4 ions, you will want to drop some or group them somehow.
e.g. for MhdMultifluidCalculator, before calling tfbi_ds():
cc.use_mix_heavy_ions(0.3, m_mean_mode=’density’)
You can also pick ions directly during cc.tfbi_ds().
e.g. for Bifrost chromosphere analysis, where n[He_II] < 1e-6 * ne, I use:
cc.tfbi_ds(ions=[i for i in cc.fluids if i.q==1 and i!=’He_II’])
After finishing solving, you might want to save the result,
e.g. dsR.pc.save(‘filename’) saves result to ‘filename.pcxarr’;
can load it later via pc.xarray_load(‘filename.pcxarr’).
If you are solving across “many” points (e.g., more than ~5000),
you might want to use chunking instead. see TfbiChunkSolver;
also note cc.tfbi_solver(…) automatically uses TfbiChunkSolver
if appropriate, i.e. if cc.chunks is set (where cc is a TfbiLoader).
TfbiSolver internally stores self.cc, ds0, kp, dsk, drel, and dsR,
as defined by the pattern above.
cc: PlasmaCalculator
PlasmaCalculator object used to load the data.
Should be a TfbiLoader subclass. (PlasmaCalculator satisfies this by default,
assuming successful import SymSolver and import tfbi_theory.)
ions: None or specifier of multiple fluids (e.g. slice, or list of strs)
None –> use cc.fluids.ions()
ions are determined when called, not during __init__.
print warning if this specifies more than DEFAULTS.ADDONS.TFBI_MAX_NUM_IONS ions
(default: 5), because then solving will be slow and may be inaccurate.
kres: ‘low’, ‘mid’, or ‘high’
resolution in k-space. Tells which self.kPicker_cls to use.
‘low’ –> tfbi_theory.kPickerLowres. Recommended if solving across many (e.g. >1000) points.
‘mid’ –> tfbi_theory.kPickerMidres. Recommended if solving across a few (e.g. 10 to 100) points.
‘high’ –> tfbi_theory.kPickerHighres. Recommended if solving at only 1 point.
mod, lmod, ang: UNSET or dict
passed directly to kPicker if provided. Can specify k values other than the defaults.
see help(self.kPicker_cls) for more details.
tfbi_all: bool
whether to compute all relevant tfbi vars, ds0 = cc(‘tfbi_all’).
False –> compute only the necessary vars, ds0 = cc(‘tfbi_inputs’).
drel_cls: None, str, or class
tfbi_theory class to use for solving TFBI theory.
None –> use self.drel_cls default: tt.TfbiDisprelC
str –> use getattr(tt, drel_cls) to get the class.

Methods

solve(*[, verbose])

solve TFBI theory.

_default_drel_cls()

default drel_cls.

_repr_contents()

return list of strings for contents inside of __repr__

_warn_if_too_many_ions()

print warning if self.ions specifies too many ions.

Attributes

drel_cls

class to use for solving TFBI theory.

drel_cls_name

elastic

whether this solver assumes elastic collisions for all species

ions_explicit

list of ions from self.cc which would be used during self.cc.tfbi_ds()

kPickerHighres_cls_name

kPickerLowres_cls_name

kPickerMidres_cls_name

kPicker_cls

kPicker class to use for choosing wavevectors to consider.

solution

result of self.solve(); alias to self.dsR.

solved

tells whether self.solution exists

_default_drel_cls()

default drel_cls. getattr(tt, self.drel_cls_name)

_repr_contents()

return list of strings for contents inside of __repr__

_warn_if_too_many_ions()

print warning if self.ions specifies too many ions.

property drel_cls

class to use for solving TFBI theory. Default: tt.TfbiDisprelC.

property elastic

whether this solver assumes elastic collisions for all species

property ions_explicit

list of ions from self.cc which would be used during self.cc.tfbi_ds()

property kPicker_cls

kPicker class to use for choosing wavevectors to consider. Depends on self.kres:

‘low’ –> tfbi_theory.kPickerLowres
‘mid’ –> tfbi_theory.kPickerMidres
‘high’ –> tfbi_theory.kPickerHighres
property solution

result of self.solve(); alias to self.dsR.

solve(*, verbose=True, **kw_growth_root)

solve TFBI theory. Assigns self.ds0, kp, dsk, drel, and dsR.

Does not do any caching at this level; if the code crashes you will need to restart it completely.
For more precise control including possibility for caching, use the pattern directly:
import tfbi_theory as tt
import PlasmaCalcs as pc
cc = … # any PlasmaCalculator object from PlasmaCalcs.
ds0 = cc.tfbi_ds()
kp = tt.kPickerLowres(ds0)
dsk = kp.get_ds() # copy of ds0, but with ds[‘k’] = k from kPicker.
drel = tt.TfbiDisprelC.from_ds(dsk)
dsR = drel.solve() # copy of dsk, but with ds[‘omega’] = solution to TFBI theory!
verbose: bool
whether to print progress updates (highly recommended).
additional kwargs get passed directly to drel.solve().
(options include: ncpu, ncoarse, careful)
property solved

tells whether self.solution exists