Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
chemreac.core ============= In chemreac.core you will find :py:class:`ReactionDiffusion` which is the class describing the system of ODEs.
"""
""" Convenience method for making a Reaction instance for reaction index ri """ {self.substance_names[i]: self.stoich_active[ri].count(i) for i in range(self.n)}, {self.substance_names[i]: self.stoich_prod[ri].count(i) for i in range(self.n)}, {self.substance_names[i]: self.stoich_inactv[ri].count(i) for i in range(self.n)}, k=self.k[ri])
else: raise ValueError("Order must be 'C' or 'F'")
order=order) else: order=order)
# TODO: ndiag from nstencil self.N, self.n, ndiag))
def ny(self):
radyield=units['amount']/get_unit(units, 'energy'), field=get_unit(units, 'energy')/(get_unit(units, 'time') * get_unit(units, 'length')**3) )[key]
""" Object representing the numerical model, with callbacks for evaluating derivatives and jacobian.
The instance provides methods:
- ``f(t, y, fout)`` - ``dense_jac_rmaj(t, y, jout)`` - ``dense_jac_cmaj(t, y, jout)`` - ``banded_jac_cmaj(t, y, jout)`` - ``banded_packed_jac_cmaj(t, y, jout)``
some of which are used by chemreac.integrate.integrate_scipy
Additional convenience attributes (not used by underlying C++ class):
- :py:attr:`substance_names` - :py:attr:`substance_tex_names`
Parameters ---------- n: integer number of species stoich_active: list of lists of integer indices reactant index lists per reaction. stoich_prod: list of lists of integer indices product index lists per reaction. k: 1-dimensional array reaction rate coefficients N: integer number of compartments (default: 1 if x==None else len(x)-1) D: sequence of floats diffusion coefficients (of length n) z_chg: sequence of integers 1-dimensional array ion charges mobility: sequence of floats mobility of ions x: sequence of floats or pair of flats or float, optional compartment boundaries (of length N+1), default: linspace(0, 1, N+1) if x is a pair of floats it is expanded into linspace(x[0], x[1], N+1). if x is a float it is expanded into linspace(0, x, N+1) stoich_inactv: list of lists of integer indices list of inactive reactant index lists per reaction.n, default: [] geom: integer any of (FLAT, SPHERICAL, CYLINDRICAL) logy: bool f and \*_jac_\* routines operate on log(concentration) logt: bool f and \*_jac_\* routines operate on log(time) logx: bool f and \*_jac_\* routines operate on log(space) nstencil: integer number of points used in finite difference scheme lrefl: bool reflective left boundary (default: True) rrefl: bool reflective right boundary (default: True) auto_efield: bool calculate electric field from concentrations (default: False) surf_chg: pair of floats total charge of surface (defaut: (0.0, 0.0)) eps_rel: float relative permitivity of medium (dielectric constant) g_values: sequence of sequences of floats per specie yields (amount / energy) per field type g_value_parents: sequence of integers (optional) indices of parents for each g_value. -1 denotes no concentration dependence of g_values. default: [-1]*len(g_values) fields: sequence of sequence of floats per bin field strength (energy / (volume time)) per field type. May be calculated as product between density and doserate modulated_rxns: sequence of integers Indicies of reactions subject to per bin modulation modulation: sequence of sequences of floats Per bin modulation vectors for each index in modulated_rxns units: dict (optional) default: None, see ``chemreac.units.SI_base`` for an example.
Attributes ---------- units: dict
""" # not used by C++ class
# subset of extra_attrs optionally passed by user
def substance_names(self):
def substance_names(self, names):
def substance_tex_names(self):
def substance_tex_names(self, tex_names):
mobility=None, x=None, stoich_inactv=None, geom=FLAT, logy=False, logt=False, logx=False, nstencil=None, lrefl=True, rrefl=True, auto_efield=False, surf_chg=None, eps_rel=1.0, g_values=None, g_value_parents=None, fields=None, modulated_rxns=None, modulation=None, units=None, faraday=None, # deprecated vacuum_permittivity=None, # deprecated k_unitless=None, **kwargs): else: raise ValueError("N must be >= nstencil")
else:
raise ValueError("x must be strictly positive monotonic") elif len(x) == 1: raise TypeError else: raise ValueError("Don't know what to do with len(x) == %d" % len(x))
else: assert len(stoich_active) == len(k_unitless)
0.0*get_unit(units, 'charge'))
# Handle g_values else:
else:
zip(k, cls.k_units(units, reac_orders))] else: if k is not None: raise ValueError( "When passing k_unitless you must set k to None")
raise ValueError("len(modulated_rxns) != len(modulation)") raise ValueError("modulated_rxns missing.") raise ValueError("An array in modulation of size != N")
cls, n, stoich_active, stoich_prod, np.asarray(k_unitless), N, to_unitless(D, get_unit(units, 'diffusion')), z_chg, to_unitless(mobility, get_unit(units, 'electrical_mobility')), to_unitless(_x, get_unit(units, 'length')), stoich_inactv, geom, logy, logt, logx, [np.asarray([to_unitless(yld, yld_unit) for yld in gv]) for gv, yld_unit in zip(g_values, cls.g_units(units, g_value_parents))], g_value_parents, [to_unitless(fld, get_unit(units, 'field')) for fld in fields], modulated_rxns or [], modulation or [], nstencil, lrefl, rrefl, auto_efield, (to_unitless(surf_chg[0], get_unit(units, 'charge')), to_unitless(surf_chg[1], get_unit(units, 'charge'))), eps_rel, faraday or get_unitless_constant(units, 'Faraday_constant'), vacuum_permittivity or get_unitless_constant( units, 'vacuum_permittivity'), )
raise KeyError("Unkown kwargs: ", kwargs.keys())
def fields(self):
def fields(self, value): self._fields = to_unitless(value, get_unit(self.units, 'field'))
def g_units(units, g_value_parents): else: get_unit(units, 'concentration'))
def g_values(self): self._g_values, self.g_units(self.units, self.g_value_parents))]
def k_units(units, reaction_orders): 1-order)/get_unit(units, 'time') for order in reaction_orders]
def k(self): self.units, reac_orders))]
def k(self, value): reac_orders = map(len, self.stoich_active) self._k = [to_unitless(kv, ku) for kv, ku in zip(value, self.k_units( reac_orders))]
def D(self):
def D(self, value): self._D = to_unitless(value, get_unit(self.units, 'diffusion'))
def mobility(self):
def mobility(self, value): self._mobility = to_unitless(value, get_unit(self.units, 'mobility')) |