Source code for libs.pympdata_bulk.bulk_scheme_condensation
"""Copyright (c) 2024 MPI-M, Clara Bayley----- Microphysics Test Cases -----File: bulk_scheme_condensation.pyProject: pympdata_bulkCreated Date: Monday 2nd September 2024Author: Clara Bayley (CB)Additional Contributors:-----Last Modified: Wednesday 4th September 2024Modified By: CB-----License: BSD 3-Clause "New" or "Revised" Licensehttps://opensource.org/licenses/BSD-3-Clause-----File Description:Simple bulk microphysics scheme extracted from pyMPDATAShipway and Hill 2012 example for 1-D KiD rainshaft model"""importnumpyasnpfrom..thermo.thermodynamicsimportThermodynamicsfromPyMPDATA_examplesimportShipway_and_Hill_2012askidfromcopyimportdeepcopy
[docs]defbulk_scheme_condensation(temp,press,qvap,qcond):""" Enacts saturation adjustment on qvap and qcond for a very simple bulk scheme to ensure relative humidity <= 100%. Extracted from pyMPDATA Bulk (nr=1) Microphysics Scheme for condensation in Shipway and Hill 2012 example for a 1-D KiD rainshaft model. See https://github.com/open-atmos/PyMPDATA/tree/main/examples/PyMPDATA_examples/Shipway_and_Hill_2012) for the original source code. Parameters: temp (float): Temperature in Kelvin. press (float): Pressure in Pascals. qvap (float): Specific humidity of water vapor (kg/kg). qcond (float): Specific humidity of condensed water (kg/kg). Returns: tuple: Adjusted specific humidities of water vapor and condensed water (qvap, qcond). """pvs=kid.formulae.pvs_Celsius(temp-kid.const.T0)relh=kid.formulae.pv(press,qvap)/pvsdqcond=np.maximum(0,qvap*(1-1/relh))qvap-=dqcondqcond+=dqcondreturnqvap,qcond
[docs]classMicrophysicsSchemeWrapper:def__init__(self):"""Initialize the WrappedKiDBulkMicrophysics object."""self.microphys="pyMPDATA KiD Bulk Microphysics Scheme for Condensation"self.name="Wrapper around "+self.microphys
[docs]definitialize(self)->int:"""Initialise the microphysics scheme. This method calls the microphysics initialisation Returns: int: 0 upon successful initialisation """return0
[docs]deffinalize(self)->int:"""Finalise the microphysics scheme. This method calls the microphysics finalisation. Returns: int: 0 upon successful finalisation. """return0
[docs]defrun(self,timestep:float,thermo:Thermodynamics)->Thermodynamics:"""Run the microphysics computations. This method is a wrapper of the MicrophysicsScheme object's run function to call the microphysics computations in a way that's compatible with the test and scripts in this project. Args: timestep (float): Time-step for integration of microphysics (s). thermo (Thermodynamics): Thermodynamic properties. Returns: Thermodynamics: Updated thermodynamic properties after microphysics computations. """cp_thermo=deepcopy(thermo)temp=cp_thermo.temppress=cp_thermo.pressqvap=cp_thermo.massmix_ratios[0]qcond=cp_thermo.massmix_ratios[1]qvap,qcond=bulk_scheme_condensation(temp,press,qvap,qcond)cp_thermo.massmix_ratios[0]=qvapcp_thermo.massmix_ratios[1]=qcondreturncp_thermo