EppicChooseParams
- class PlasmaCalcs.hookups.eppic.eppic_choose_params.EppicChooseParams(ec, var=None, *, values={}, **kw_call_self)
Bases:
EppicChooseParamsBaseclass to help with choosing parameters for eppic.i file.
ec: EppicCalculator object
the EppicCalculator to use for getting values and directory of original eppic.i file.var: None, str, or list of stringstells which getters to use when getting values. See self.GETTERS.keys() for options.None –> use all vars in self.GETTERS.str –> use this var.list –> use these vars.Use [] to use no vars, i.e. initialize only with user-provided values.if getting vars gives keys also provided in`values``, use the value from``values`instead.values: dict{varname: value} for pairs to update in new eppic.i file.Can also provide {dist number: dict of {varname: value} pairs to update for this dist}(inside of dist number dicts, varname can end with dist number or not;assume it does end with dist number in the file itself though)Will be immediately converted to self.values_flat format.additional kwargs:passed as self(var, **kw_call) when determining initial values.Examples:Basic usage:choices = EppicChooseParams(eppic_calculator_object) # create instance;# ^ will also fill choices with defaults based on calculations,# e.g. including vtherm calculated from temperatures, and dx from ldebye from electrons.choices.update(…) # any choices of params you specifically want to set can go here.choices.write(…) # write a new eppic.i file based on the original, and choices.Other common use case - learn info about timescales:choices.timescales() # EppicTimescales objectMethods
__call__([var, precision, checks, units])return dict of {key: value} to use in input deck, based on current values in self.ec.
__init__(ec[, var, values])create EppicChooseParameters by reading values from EppicCalculator.get_vals_for_inputs()
check([var, mode])check current values in self.ec for "reasonable-ness".
check_dt()checks that input_deck dt is smaller than or equal to the value from self.get_dt().
check_dx()checks that input_deck dx is smaller than or equal to the value from self.get_dx().
check_rosenberg_qn(*[, rosenberg_safety])check the rosenberg criterion for quasineutrality, for each fluid: (nusn / wplasma)^2 << 1.
failed_check(msg)what to do when a check fails.
get_dt([precision, dt_safety, units])return dict of {'dt': EppicParam(value to use for dt, old=dt from input deck)}.
get_dx([precision, ldebye_safety, units])return dict of values to use for dx, dy, dz.
get_n([precision, units])return dict of values to use for n0d for all fluids in self.ec.fluid.
get_v0([precision, units])return dict of values to use for vx0d, vy0d, vz0d for all fluids in self.ec.fluid,
get_vtherm([precision, units])return dict of values to use for vxthd, vythd, vzthd for all fluids in self.ec.fluid,
get_vtherm_n([precision, units])return dict of {'vth_neutral': EppicParam(value to use for vth_neutral, old=value from input deck)}.
items()keys()setdefault([values])setdefault for self.values.
str_from([src, missing_values_ok, comment])return str to use for the entire contents of the new, updated eppic.i file.
timescales(*[, units])returns an EppicTimescales object, to help with understanding the relevant timescales.
update([values])update self.values with values.
values_flat([values])return these values as a 'flat' dict, suitable for using to update eppic.i file.
write([src, dst, exists_ok, ...])write updated eppic.i file to dst.
_param_checker([checkers])return f after putting f.__name__ into checkers
_param_getter([getters])return f after putting f.__name__ into getters
Attributes
CHECKERSGETTERSchecks_modealias to __call__
- __call__(var=None, *, precision=UNSET, checks=UNSET, units='raw', **kw)
return dict of {key: value} to use in input deck, based on current values in self.ec.
(Ignores current values of self. Consider using: self.setdefault(self()).)Or, checks current values in self.ec for “reasonable-ness”.var: None, str, or list of stringstells which getters & checkers to include.See self.GETTERS.keys() and self.CHECKERS.keys() for options.None –> use all vars in self.GETTERS and all vars in self.CHECKERS.str –> use this var.list –> use these vars.precision: UNSET, dict, or intdigits of precision for exponential values when converting to strings.UNSET –> use each var’s default, defined within its getter function.dict –> {{var: precision to use for var}}, for var in self.GETTERS.checks: UNSET, bool, ‘warn’, or ‘crash’whether to check values for “reasonable-ness”, and how to behave if a check fails.UNSET –> use self.checks_mode.False –> don’t check.True –> equivalent to ‘warn’‘warn’ –> print warning message for any failed checks.‘crash’ –> raise AssertionError for any failed checks.units, kw:passed to self.ec.using(…) while using this method.
- __init__(ec, var=None, *, values={}, **kw_call_self)
create EppicChooseParameters by reading values from EppicCalculator.get_vals_for_inputs()
- _param_checker(checkers={'dt': 'check_dt', 'dx': 'check_dx', 'rosenberg_qn': 'check_rosenberg_qn'})
return f after putting f.__name__ into checkers
assert f.__name__ looks like ‘check_{var}’, then puts {var: f.__name__} into checkers.
- _param_getter(getters={'dt': 'get_dt', 'dx': 'get_dx', 'n': 'get_n', 'v0': 'get_v0', 'vtherm': 'get_vtherm', 'vtherm_n': 'get_vtherm_n'})
return f after putting f.__name__ into getters
assert f.__name__ looks like ‘get_{var}’, then puts {var: f.__name__} into getters.
- check(var=None, *, mode=UNSET, **kw_checker)
check current values in self.ec for “reasonable-ness”.
var: None, str, or list of strings
tells which checkers to include. See self.CHECKERS.keys() for options.None –> use all vars in self.CHECKERS.str –> use this var.list –> use these vars.mode: UNSET, bool, ‘warn’, or ‘crash’whether to check values for “reasonable-ness”, and how to behave if a check fails.UNSET –> use self.checks_mode.False –> don’t check.True –> equivalent to ‘warn’‘warn’ –> print warning message for any failed checks.‘crash’ –> raise AssertionError for any failed checks.additional kwargs are passed to every used checker.returns dict {v: result from check_v} for each v in var.
- check_dt()
checks that input_deck dt is smaller than or equal to the value from self.get_dt().
returns self.get_dt(units=’raw’), since it tells the suggested and old values for dt.
- check_dx()
checks that input_deck dx is smaller than or equal to the value from self.get_dx().
returns self.get_dx(units=’raw’), since it tells the suggested and old values for dx.
- check_rosenberg_qn(*, rosenberg_safety=UNSET)
check the rosenberg criterion for quasineutrality, for each fluid: (nusn / wplasma)^2 << 1.
rosenberg_safety: UNSET or number
the check passes iff (nusn / wplasma)^2 <= rosenberg_safety.UNSET –> use DEFAULTS.EPPIC.ROSENBERG_SAFETY (default: 0.5)return xarray of (mean(nusn / wplasma))^2 for each fluid
- failed_check(msg)
what to do when a check fails. depends on self.checks_mode.
‘warn’ –> print warning message.‘crash’ –> raise AssertionError.True –> equivalent to ‘warn’False –> do nothing.
- property get
alias to __call__
- get_dt(precision=1, *, dt_safety=UNSET, units='raw', **kw)
return dict of {‘dt’: EppicParam(value to use for dt, old=dt from input deck)}.
precision is for converting to str in exponential form.dt_safety: UNSET or numberdt = dt_safety * minimum timescale.UNSET –> use DEFAULTS.EPPIC.DT_SAFETY (default: 0.9)units, kw:passed to self.ec.using(…) while using this method.
- get_dx(precision=1, *, ldebye_safety=UNSET, units='raw', **kw)
return dict of values to use for dx, dy, dz.
keys are dx, dy, dz. values are EppicParam objects, with old=dx, dy, dz from input deck.precision is for converting to str in exponential form.ldebye_safety: UNSET or numberdx, dy, dz = ldebye_safety * debye length of electrons.UNSET –> use DEFAULTS.EPPIC.DSPACE_SAFETY (default: 1.1)units, kw:passed to self.ec.using(…) while using this method.
- get_n(precision=3, *, units='raw', **kw)
return dict of values to use for n0d for all fluids in self.ec.fluid.
keys are n0d0, n0d1, etc. values are EppicParam objects, with old=n0d from input deck.precision is for converting to str in exponential form.units, kw:passed to self.ec.using(…) while using this method.
- get_v0(precision=3, *, units='raw', **kw)
return dict of values to use for vx0d, vy0d, vz0d for all fluids in self.ec.fluid,
for component in ec.component (e.g. use ec.component=(‘x’, ‘y’) to ignore ‘z’)keys are vx0d0, vx0d1, etc. values are EppicParam objects, with old=vx0d from input deck.precision is for converting to str in exponential form.units, kw:passed to self.ec.using(…) while using this method.
- get_vtherm(precision=3, *, units='raw', **kw)
return dict of values to use for vxthd, vythd, vzthd for all fluids in self.ec.fluid,
for component in ec.component (e.g. use ec.component=(‘x’, ‘y’) to ignore ‘z’)keys are vxthd0, vxthd1, etc. values are EppicParam objects, with old=vxthd from input deck.precision is for converting to str in exponential form.units, kw:passed to self.ec.using(…) while using this method.
- get_vtherm_n(precision=3, *, units='raw', **kw)
return dict of {‘vth_neutral’: EppicParam(value to use for vth_neutral, old=value from input deck)}.
units, kw:
passed to self.ec.using(…) while using this method.
- setdefault(values={}, **values_as_kw)
setdefault for self.values. returns self.
Like self.update, but doesn’t overwrite existing values.
- str_from(src='eppic.i', missing_values_ok=True, comment='previously={old}', **kw)
return str to use for the entire contents of the new, updated eppic.i file.
src: strpath to source file to use as template.missing_values_ok: boolwhether it is okay for some of the varnames in values to not exist in eppic.icomment: None or strif not None, append comment as a comment to all updated lines.Also, this comment will be hit by .format(old=old value)additional kw passed to get_updated_eppic_i_str
- timescales(*, units='raw', **kw_init)
returns an EppicTimescales object, to help with understanding the relevant timescales.
kwargs are pased to EppicTimescales(…)
- update(values={}, **values_as_kw)
update self.values with values. returns self
- static values_flat(values={}, **values_as_kw)
return these values as a ‘flat’ dict, suitable for using to update eppic.i file.
This is a dict of {key: value} pairs, appending dist number to key name where appropriate.
- write(src='eppic.i', dst='eppic_updated.i', *, exists_ok=False, missing_values_ok=True, comment='previously={old}', **kw)
write updated eppic.i file to dst.
src: strpath to source file to use as template.dst: strpath to destination file to write.exists_ok: bool, default Falsewhether it is okay for dst to already exist.missing_values_ok: boolwhether it is okay for some of the varnames in values to not exist in eppic.icomment: None or strif not None, append comment as a comment to all updated lines.Also, this comment will be hit by .format(old=old value)additional kw passed to update_eppic_i_file.return abspath to dst.