示例#1
0
def get_charge(obj, SL, units='e'):
    '''return the charge fluid SL in [units]. default is elementary charge units.
    units: one of ['e', 'elementary', 'esu', 'c', 'cgs', 'si', 'simu']. Default 'elementary'.
        'e' or 'elementary' -> charge in elementary charge units. For these units, qH+ ~= 1.
        'c' or 'si'         -> charge in SI units (Coulombs).     For these units, qH+ ~= 1.6E-19
        'esu' or 'cgs'      -> charge in cgs units (esu).         For these units, qH+ ~= 4.8E-10
        'simu'              -> charge in simulation units.
    '''
    units = units.lower()
    VALID_UNITS = ['e', 'elementary', 'esu', 'c', 'cgs', 'si', 'simu']
    assert units in VALID_UNITS, "Units invalid; got units={}".format(units)
    # get charge, in 'elementary charge' units:
    if (SL==-1) or (SL[0] < 0):
        # electron
        charge = -1.
    else:
        # not electron
        charge = fl.Fluids(dd=obj)[SL].ionization
    # convert to proper units and return:
    if units in ['e', 'elementary']:
        return charge
    elif units in ['esu', 'cgs']:
        return charge * obj.uni.q_electron
    elif units in ['c', 'si']:
        return charge * obj.uni.qsi_electron
    else: #units=='simu'
        return charge * obj.uni.simu_qsi_e
示例#2
0
def iter_fluid_SLs(dd, with_electrons=True):
    '''returns an iterator over the fluids of dd, and electrons.
    yields SL pairs; NOT at_tools.fluids.Fluid objects!
    example: list(iter_fluids(dd)) = [(-1,0), (1,1), (1,2)].
    '''
    if with_electrons:
        yield (-1,0)
    for fluid in fl.Fluids(dd=dd):
        yield fluid.SL
示例#3
0
def get_fluid_name(obj, fluid):
    '''return fluid's name: 'e-' for electrons; element & ionization for other fluids (e.g. 'H II').
    fluid can be at_tools.fluids.Fluid object, (species, level) pair, or -1 (for electrons).
    '''
    try:
        return fluid.name
    except AttributeError:
        try:
            specie = fluid[0]
            electrons_or_bust = False
        except TypeError:
            specie = fluid
            if not (specie < 0):
                errmsg_badfluid = ('Expected at_tools.fluids.Fluid object or (species, level) for fluid, '
                                   'but got fluid = {}'.format(fluid))
                raise TypeError(errmsg_badfluid)
        if specie < 0:
            return 'e-'
        else:
            return fl.Fluids(dd=obj)[fluid].name
示例#4
0
def _get_fluids_and_f(obj, fluids=None, f=lambda fluid: fluid):
    '''returns fluids, f.
    if fluids is None:
        fluids = fl.Fluids(dd=obj)
        f = lambda fluid: fluid.SL
    if we failed to import at_tools.fluids, try fluids=obj.fluids, before giving up.
    '''
    if fluids is None:
        f = lambda fluid: fluid.SL
        if fl is None:
            if not obj.hasattr('fluids'):
                errmsg = (
                    "{} has no attribute 'fluids', we failed to import at_tools.fluids "
                    "and you didn't input fluids, so we don't know which fluids to use!"
                )
                errmsg = errmsg.format(obj)
                raise NameError(
                    errmsg
                )  # choosing NameError type because "fluids" is "not defined".
            else:
                fluids = obj.fluids
        else:
            fluids = fl.Fluids(dd=obj)
    return (fluids, f)
示例#5
0
 def fluids(self):
     '''at_tools.fluids.Fluids object describing the fluids in self.'''
     if hasattr(self, '_fluids'):
         return self._fluids
     else:
         return fl.Fluids(dd=self)