Source code for conesToolBox.conesClasses.conesSettings.conesSettings_MNH

from ...conesFunctions import printCones
from ..conesParams import conesParams
from ..conesClip import conesClip
from .conesSettingsAbstract import conesSettingsAbstract
import f90nml


[docs] class conesSettings_MNH(conesSettingsAbstract): """ A class that groups settings for cones """ def __init__(self, case_path, model, nens, n_model_procs, local_commn, world_comm): """ Initialize the class :param case_path: the path of the source Meso-NH case :type case_path: str :param model: the coupled model, always 'MNH' for this settings class :type model: str :param nens: int :param n_model_procs: the number of processors used by each Meso-NH simulation :type n_model_procs: int :param local_comm: python-only MPI intracommunicator :param world_comm: Global MPI communicator """ super(conesSettings_MNH, self).__init__(case_path, model, nens, n_model_procs) self.cones_namelist = dict(f90nml.read(self.case_path + 'NAM_DA.nam')) self.exseg_namelist = dict(f90nml.read(self.case_path + 'EXSEG1.nam')) printCones(self.cones_namelist['nam_da']['CDA_OBS_FILE']) self.obs_file = self.case_path + str(self.cones_namelist['nam_da']['CDA_OBS_FILE']) self.checkPath(self.obs_file) self.global_cells = self.set_model_global_cells_ids(local_commn, world_comm) self.local_cells = self.setLocalCells() printCones("local_cells = ", self.local_cells) self.stateVar = str(self.cones_namelist['nam_da']['CDA_STATE_VAR']) self.obs_var = str(self.cones_namelist['nam_da']['CDA_OBS_VAR']) self.obs_dof = 1 if self.obs_var =='BMAP' else len(self.obs_var) self.nParams = int(self.cones_namelist['nam_da']['NDA_NB_PARAMS']) self.stateEstSwitch = bool(self.cones_namelist['nam_da']['LDA_STATE_EST_SWITCH']) self.paramEstSwitch = bool(self.cones_namelist['nam_da']['LDA_PARAM_EST_SWITCH']) self.hyper_loc_switch = bool(self.cones_namelist['nam_da']['LDA_HYPER_LOCALISATION_SWITCH']) self.stateCovarianceLocalisation = bool(self.cones_namelist['nam_da']['LDA_COVARIANCE_LOCALISATION_SWITCH']) if (self.stateCovarianceLocalisation): self.localisationLength = float(self.cones_namelist['nam_da']['XDA_LOCALISATION_LENGTH']) self.inflationType = str(self.cones_namelist['nam_da']['CDA_INFL_TYPE']) self.stateInflation = float(self.cones_namelist['nam_da']['XDA_STATE_INFL']) self.parametersInflation = float(self.cones_namelist['nam_da']['XDA_PARAMS_INFL']) self.obsWindow = int(self.cones_namelist['nam_da']['NDA_OBS_WINDOW']) printCones(self.obsWindow) self.endTimeSim = float(self.exseg_namelist['nam_dyn']['XSEGLEN']) self.deltaTSim = float(self.exseg_namelist['nam_dynn']['XTSTEP']) self.total_it = int(self.endTimeSim / (self.obsWindow * self.deltaTSim)) self.mda_iterations = int(self.cones_namelist['nam_da']['NDA_MDA_ITERATIONS']) # We define the clippings if not self.hyper_loc_switch: self.Clips = self.no_clippings() else: self.Clips = self.get_clippings() # We merge those clips that shares cells self.mergedClips = self.mergeClips() # This is provisional and not used yet self.params = [] for i in range(0, self.nParams): self.params.append(conesParams()) return
[docs] def set_model_global_cells_ids(self, local_comm, world_comm) -> list[list[int]]: """ Generate a list of global cell ids splitted by ranks :returns: list of global cells ids :rtype: list """ from ...conesMPI import conesRecvInt, conesRecvIntField global_model_cells_ids_list = [] if (local_comm.Get_rank() == 0): for irank in range(0, self.nRanks): printCones("Receiving information from rank ", irank) nb_cells_model_proc = conesRecvInt(irank, world_comm) printCones("nb_cells_model_proc = ", nb_cells_model_proc) cells_ids_list_proc = conesRecvIntField(irank, nb_cells_model_proc, world_comm).astype(int).tolist() # printCones("cells_ids_list_proc = ", cells_ids_list_proc) global_model_cells_ids_list.append(cells_ids_list_proc) printCones("Broadcasting the global_model_cells_ids_list") global_model_cells_ids_list = local_comm.bcast(global_model_cells_ids_list, root=0) if (self.verbose): printCones("Global Cell List :", global_model_cells_ids_list) return global_model_cells_ids_list
[docs] def no_clippings(self): """ Function that consideres the entire domain as a clipping Returns a list of one clipping :returns: list of clippings :rtype: list """ clipList = [] clipList.append(conesClip("uniqueClip")) clipList[0].path = self.case_path clipList[0].nRanks = self.nRanks clipList[0].localCellList = self.local_cells clipList[0].globalCellList = self.global_cells if (self.verbose): printCones("There is no clipping, the entire domain is considered") if (self.verbose): for ii, clip in enumerate(clipList): printCones(ii, "Global", clip.globalCellList) printCones(ii, "Local", clip.localCellList) return clipList