Source code for libs.mock_microphys.microphysics_scheme_wrapper
"""Copyright (c) 2024 MPI-M, Clara Bayley----- Microphysics Test Cases -----File: microphysics_scheme_wrapper.pyProject: mock_microphysCreated Date: Wednesday 28th February 2024Author: Clara Bayley (CB)Additional Contributors:-----Last Modified: Monday 11th November 2024Modified By: CB-----License: BSD 3-Clause "New" or "Revised" Licensehttps://opensource.org/licenses/BSD-3-Clause-----File Description:wrapper function for an instance of MicrophysicsScheme so it can be used by generic test casesand run scripts"""from..thermo.thermodynamicsimportThermodynamicsfrom.mock_microphysics_schemeimportMicrophysicsSchemefromcopyimportdeepcopy
[docs]classMicrophysicsSchemeWrapper:"""A class wrapping around Python MicrophysicsScheme for compatibility purposes. This class wraps around the MicrophysicsScheme class to provide compatibility with the Python run scripts and tests in this project. It initializes a MicrophysicsScheme object and provides wrappers around methods to initialize, finalize, and run the microphysics. Args: nvec (int): Number of horizontal points. ke (int): Number of grid points in vertical direction. ivstart (int): Start index for horizontal direction. dz (np.ndarray): Layer thickness of full levels (m). qnc (float): Cloud number concentration. Attributes: nvec (int): Number of horizontal points. ke (int): Number of grid points in vertical direction. ivstart (int): Start index for horizontal direction. dz (np.ndarray): Layer thickness of full levels (m). qnc (float): Cloud number concentration. microphys (MicrophysicsScheme): instance of Python MicrophysicsScheme. """def__init__(self,nvec,ke,ivstart,dz,qnc):"""Initialize the MicrophysicsSchemeWrapper object. Args: nvec (int): Number of horizontal points. ke (int): Number of grid points in vertical direction. ivstart (int): Start index for horizontal direction. dz (np.ndarray): Layer thickness of full levels (m). qnc (float): Cloud number concentration. """self.nvec=nvecself.ke=keself.ivstart=ivstartself.dz=dzself.qnc=qncself.microphys=MicrophysicsScheme()self.name="Wrapper around "+self.microphys.name
[docs]definitialize(self)->int:"""Initialise the microphysics scheme. This method calls the microphysics initialisation Returns: int: 0 upon successful initialisation """self.microphys.initialize()return0
[docs]deffinalize(self)->int:"""Finalise the microphysics scheme. This method calls the microphysics finalisation. Returns: int: 0 upon successful finalisation. """self.microphys.finalize()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)dt=timestept=cp_thermo.temprho=cp_thermo.rhop=cp_thermo.pressqv,qc,qi,qr,qs,qg=cp_thermo.unpack_massmix_ratios()t,qv,qc,qi,qr,qs,qg,prr_gsp,pflx=self.microphys.run(self.nvec,self.ke,self.ivstart,dt,self.dz,t,rho,p,qv,qc,qi,qr,qs,qg,self.qnc,)cp_thermo.temp[:]=tcp_thermo.copy_massmix_ratios(qv,qc,qi,qr,qs,qg)returncp_thermo