atmos.FluidSolver takes input variables (like pressure, virtual temperature, water vapor mixing ratio, etc.) and information about what assumptions you’re willing to make (hydrostatic? low water vapor? ignore virtual temperature correction? use an empirical formula for equivalent potential temperature?), and from that calculates any desired output variables that you request and can be calculated.
The main benefit of using atmos.FluidSolver instead of atmos.calculate() is that the FluidSolver object has memory. It can keep track of what assumptions you enabled, as well as what quantities you’ve given it and it has calculated.
Anything that can be calculated by equations in atmos.equations. If you find that the FluidSolver can’t do a calculation you might expect it to, check the equations it has available and make sure you’re using the right variables, or enabling the right assumptions. A common problem is using T instead of Tv and expecting the ideal gas law to work.
By default, a certain set of assumptions are used, such as that we are considering an ideal gas, and so can use ideal gas law. This allows us to do simple calculations that use the default assumptions. For example, to calculate pressure from virtual temperature and density:
>>> import atmos
>>> solver = atmos.FluidSolver(Tv=273., rho=1.27)
>>> solver.calculate('p')
99519.638400000011
Or to calculate relative humidity from water vapor mixing ratio and saturation water vapor mixing ratio (which needs no assumptions):
>>> import atmos
>>> solver = atmos.FluidSolver(rv=0.001, rvs=0.002)
>>> solver.calculate('RH')
50.0
For a full list of default assumptions, see atmos.FluidSolver.
By default, SI units are assumed. These can be overridden with keyword arguments of the form {quantity name}_unit or {quantity name}_units. Specifying units makes it so that both inputs and outputs of the quantity will be in the specified units.
To get pressure in hPa:
>>> import atmos
>>> solver = atmos.FluidSolver(Tv=273., rho=1.27, p_units='hPa')
>>> atmos.calculate('p')
995.19638400000008
To specify mixing ratio in g/kg:
>>> import atmos
>>> solver = atmos.FluidSolver(rv=1, rvs=0.002, rv_unit='g/kg')
>>> atmos.calculate('RH')
50.0
Note that either “_unit” or “_units” can be used, and that units must be specified for each quantity independently.
Unit names are the same as in the Pint package, with the exception that relative humidity can have units of “percent” or “fraction”. Remember that C in Pint is Coulombs, while degC is degrees Celsius.
Calculating pressure from virtual temperature and density, also returning a list of functions used:
>>> import atmos
>>> solver = atmos.FluidSolver(Tv=273., rho=1.27, debug=True)
>>> p, funcs = solver.calculate('p')
>>> funcs
(<function atmos.equations.p_from_rho_Tv_ideal_gas>,)
If you want to use assumptions that are not enabled by default (such as ignoring the virtual temperature correction), you can use the add_assumptions keyword argument, which takes a tuple of strings specifying assumptions. The exact string to enter for each assumption is detailed in atmos.FluidSolver. For example, to calculate T instead of Tv, neglecting the virtual temperature correction:
>>> import atmos
>>> solver = atmos.FluidSolver(T=273., rho=1.27, add_assumptions=('Tv equals T',))
>>> solver.calculate('p')
99519.638400000011
If you want to ignore the default assumptions entirely, you could specify your own assumptions:
>>> import atmos
>>> solver = atmos.FluidSolver(Tv=273., rho=1.27, assumptions=('ideal gas', 'bolton'))
>>> solver.calculate('p')
99519.638400000011
Initializes with the given assumptions enabled, and variables passed as keyword arguments stored.
Parameters: 


Returns:  out – A FluidSolver object with the specified assumptions and variables. 
Return type:  FluidSolver 
Notes
Quantity kwargs
In addition to the quantities above, kwargs of the form <quantity>_unit or <quantity>_units can be used with a string specifying a unit for the quantity. This will cause input data for that quantity to be assumed to be in that unit, and output data for that quantity to be given in that unit. Note this must be specified separately for each quantity. Acceptable units are the units available in the Pint package, with the exception that RH can be in units of “fraction” or “percent”.
Assumptions
Default assumptions are ‘ideal gas’, ‘hydrostatic’, ‘constant g’, ‘constant Lv’, ‘constant Cp’, ‘no liquid water’, ‘no ice’, ‘bolton’, ‘cimo’.
Assumption descriptions
Examples
Calculating pressure from virtual temperature and density:
>>> solver = FluidSolver(Tv=273., rho=1.27)
>>> solver.calculate('p')
99519.638400000011
Same calculation, but also returning a list of functions used:
>>> solver = FluidSolver(Tv=273., rho=1.27, debug=True)
>>> p, funcs = solver.calculate('p')
>>> funcs
(<function atmos.equations.p_from_rho_Tv_ideal_gas>,)
Same calculation with temperature instead, ignoring virtual temperature correction:
>>> solver = FluidSolver(T=273., rho=1.27, add_assumptions=('Tv equals T',))
>>> solver.calculate('p',)
99519.638400000011