Source code for pycif.plugins.transforms.complex.moist2dry.adjoint



[docs] def adjoint( transf, inout_datastore, controlvect, obsvect, mapper, di, df, mode, runsubdir, workdir, onlyinit=False, **kwargs ): """Apply the moist-to-dry conversion factor to the adjoint sensitivity. The adjoint of :func:`forward`: multiplies ``adj_out`` of the species input by the same ``dry_coef`` scalar used in the forward pass. Note: the sensitivity w.r.t. specific humidity ``q`` is not computed (``q`` is treated as a fixed diagnostic field, not a control variable). Args: transf (Plugin): moist2dry plugin instance. inout_datastore (dict): mutable datastore. controlvect: unused. obsvect: unused. mapper (dict): transform mapper. di (datetime): sub-simulation start date. df (datetime): sub-simulation end date. mode (str): ``'adj'``. runsubdir (str): unused. workdir (str): unused. onlyinit (bool): if ``True``, return immediately. **kwargs: unused. """ ddi = min(di, df) if onlyinit: return # Constants Rdry = 287.05 Rvapor = 461.5 R = 8.314462 beta = (Rvapor - Rdry) / Rvapor trid_out = (transf.component[0], transf.parameter[0]) q = inout_datastore["inputs"][ ("specific_humidity", transf.parameter[0])][ddi]["spec"] dry_coef = (1 - beta * q / (1 - q)) \ * R / Rdry / transf.molmass * 1000 * 1e9 inout_datastore["inputs"][trid_out][ddi]["adj_out"] \ = inout_datastore["inputs"][trid_out][ddi]["adj_out"] * dry_coef