def get_simulation_mesh(self, event_name: str, iteration="current") -> str: """ Get path to correct simulation mesh for a simulation :param event_name: Name of event :type event_name: str :return: Path to a mesh :rtype: str """ if iteration == "current": iteration = self.comm.project.current_iteration if self.comm.project.meshes == "multi-mesh": return lapi.get_simulation_mesh( self.lasif_comm, event_name, iteration, ) else: # return self.lasif_comm.project.lasif_config["domain_settings"][ # "domain_file" # ] if "validation" in iteration: iteration = iteration[11:] return os.path.join( self.comm.project.lasif_root, "MODELS", f"ITERATION_{iteration}", "mesh.h5", )
def move_mesh(self, event: str, iteration: str): """ Move mesh to simulation mesh path, where model will be added to it :param event: Name of event :type event: str :param iteration: Name of iteration :type iteration: str """ import shutil has, event_mesh = lapi.find_event_mesh(self.lasif_comm, event) if not has: raise ValueError(f"{event_mesh} does not exist") else: event_iteration_mesh = lapi.get_simulation_mesh( self.lasif_comm, event, iteration) if not os.path.exists(event_iteration_mesh): if not os.path.exists(os.path.dirname(event_iteration_mesh)): os.makedirs(os.path.dirname(event_iteration_mesh)) shutil.copy(event_mesh, event_iteration_mesh) print( f"Mesh for event: {event} has been moved to correct path for " f"iteration: {iteration} and is ready for interpolation.") else: print(f"Mesh for event: {event} already exists in the " f"correct path for iteration {iteration}. " f"Will not move new one.")
def interpolate_to_simulation_mesh(self, event: str, interp_folder=None): """ Interpolate current master model to a simulation mesh. :param event: Name of event :type event: str """ iteration = self.comm.project.current_iteration mode = self.comm.project.model_interpolation_mode simulation_mesh = lapi.get_simulation_mesh(self.comm.lasif.lasif_comm, event, iteration) if mode == "gll_2_gll": model = os.path.join(self.physical_models, iteration + ".h5") # There are many more knobs to tune but for now lets stick to # defaults. mapi.gll_2_gll(from_gll=model, to_gll=simulation_mesh, nelem_to_search=50, from_model_path="MODEL/data", to_model_path="MODEL/data", from_coordinates_path="MODEL/coordinates", to_coordinates_path="MODEL/coordinates", parameters=self.comm.project.modelling_params, stored_array=interp_folder) elif mode == "exodus_2_gll": model = os.path.join(self.physical_models, iteration + ".e") # This function can be further specified for different inputs. # For now, let's leave it at the default values. # This part is not really maintained for now mapi.exodus2gll(mesh=model, gll_model=simulation_mesh) else: raise ValueError(f"Mode: {mode} not supported")
def get_simulation_mesh(self, event_name: str, iteration="current") -> str: """ Get path to correct simulation mesh for a simulation :param event_name: Name of event :type event_name: str :return: Path to a mesh :rtype: str """ if iteration == "current": iteration = self.comm.project.current_iteration if self.comm.project.meshes == "multi-mesh": if self.comm.project.interpolation_mode == "remote": path = str( self.find_remote_mesh( event=event_name, iteration=iteration, already_interpolated=True, )) return path return lapi.get_simulation_mesh( self.lasif_comm, event_name, iteration, ) else: optimizer = self.comm.project.get_optimizer() if (self.comm.project.is_validation_event(event_name) and self.comm.project.use_model_averaging and "00000" not in self.comm.project.current_iteration): model = optimizer.get_average_model_name() else: model = optimizer.model_path return model
def move_mesh(self, event: str, iteration: str): """ Move mesh to simulation mesh path, where model will be added to it :param event: Name of event :type event: str :param iteration: Name of iteration :type iteration: str """ import shutil # If we use mono-mesh we copy the salvus opt mesh here. if self.comm.project.meshes == "mono-mesh": self.comm.salvus_mesher.write_new_opt_fields_to_simulation_mesh() return has, event_mesh = lapi.find_event_mesh(self.lasif_comm, event) if not has: raise ValueError(f"{event_mesh} does not exist") else: event_iteration_mesh = lapi.get_simulation_mesh( self.lasif_comm, event, iteration ) if not os.path.exists(event_iteration_mesh): if not os.path.exists(os.path.dirname(event_iteration_mesh)): os.makedirs(os.path.dirname(event_iteration_mesh)) shutil.copy(event_mesh, event_iteration_mesh) event_xdmf = event_mesh[:-2] + "xdmf" event_iteration_xdmf = event_iteration_mesh[:-2] + "xdmf" shutil.copy(event_xdmf, event_iteration_xdmf) print( f"Mesh for event: {event} has been moved to correct path for " f"iteration: {iteration} and is ready for interpolation." ) else: print( f"Mesh for event: {event} already exists in the " f"correct path for iteration {iteration}. " f"Will not move new one." )
def get_simulation_mesh(self, event_name: str) -> str: """ Get path to correct simulation mesh for a simulation :param event_name: Name of event :type event_name: str :return: Path to a mesh :rtype: str """ if self.comm.project.info["meshes"] == "wavefield-adapted": return lapi.get_simulation_mesh( self.lasif_comm, event_name, self.comm.project.current_iteration, ) else: iteration = self.comm.project.current_iteration return os.path.join( self.comm.project.lasif_root, "MODELS", f"ITERATION_{iteration}", "mesh.h5", )
def interpolate_to_simulation_mesh(self, event: str, interp_folder=None): """ Interpolate current master model to a simulation mesh. :param event: Name of event :type event: str """ iteration = self.comm.project.current_iteration mode = self.comm.project.model_interpolation_mode simulation_mesh = lapi.get_simulation_mesh( self.comm.lasif.lasif_comm, event, iteration ) if mode == "gll_2_gll": model = os.path.join(self.physical_models, iteration + ".h5") if "validation" in iteration: iteration = iteration.replace("validation_", "") if ( self.comm.project.when_to_validate > 1 and iteration != "it0000_model" ): it_number = ( self.comm.salvus_opt.get_number_of_newest_iteration() ) old_it = it_number - self.comm.project.when_to_validate + 1 model = ( self.comm.salvus_mesher.average_meshes / f"it_{old_it}_to_{it_number}" / "mesh.h5" ) else: model = os.path.join( self.physical_models, iteration + ".h5" ) # There are many more knobs to tune but for now lets stick to # defaults. self.comm.salvus_mesher.add_field_from_one_mesh_to_another( from_mesh=self.comm.project.domain_file, to_mesh=model, field_name="layer", elemental=True, overwrite=False, ) self.comm.salvus_mesher.add_field_from_one_mesh_to_another( from_mesh=self.comm.project.domain_file, to_mesh=model, field_name="fluid", elemental=True, overwrite=False, ) self.comm.salvus_mesher.add_field_from_one_mesh_to_another( from_mesh=self.comm.project.domain_file, to_mesh=model, field_name="moho_idx", global_string=True, overwrite=False, ) mapi.gll_2_gll_layered( from_gll=model, to_gll=simulation_mesh, layers="nocore", nelem_to_search=20, parameters=self.comm.project.modelling_params, stored_array=interp_folder, ) elif mode == "exodus_2_gll": model = os.path.join(self.physical_models, iteration + ".e") # This function can be further specified for different inputs. # For now, let's leave it at the default values. # This part is not really maintained for now mapi.exodus2gll(mesh=model, gll_model=simulation_mesh) else: raise ValueError(f"Mode: {mode} not supported")
def move_mesh(self, event: str, iteration: str, hpc_cluster=None, validation=False): """ Move mesh to simulation mesh path, where model will be added to it :param event: Name of event :type event: str :param iteration: Name of iteration :type iteration: str """ import shutil # If we use mono-mesh we copy the salvus opt mesh here. if self.comm.project.meshes == "mono-mesh": optimizer = self.comm.project.get_optimizer() model = optimizer.model_path # copy to lasif project and also move to cluster simulation_mesh = self.comm.lasif.get_simulation_mesh( event_name=None) shutil.copy(model, simulation_mesh) self._move_model_to_cluster(hpc_cluster=hpc_cluster, overwrite=False, validation=validation) return if self.comm.project.interpolation_mode == "remote": if event is None: self._move_model_to_cluster( hpc_cluster=hpc_cluster, overwrite=False, validation=validation, ) else: self._move_mesh_to_cluster(event=event, hpc_cluster=hpc_cluster) return has, event_mesh = lapi.find_event_mesh(self.lasif_comm, event) if not has: raise ValueError(f"{event_mesh} does not exist") else: event_iteration_mesh = lapi.get_simulation_mesh( self.lasif_comm, event, iteration) if not os.path.exists(event_iteration_mesh): if not os.path.exists(os.path.dirname(event_iteration_mesh)): os.makedirs(os.path.dirname(event_iteration_mesh)) shutil.copy(event_mesh, event_iteration_mesh) event_xdmf = event_mesh[:-2] + "xdmf" event_iteration_xdmf = event_iteration_mesh[:-2] + "xdmf" shutil.copy(event_xdmf, event_iteration_xdmf) self.print( f"Mesh for event: {event} has been moved to correct path for " f"iteration: {iteration} and is ready for interpolation.", emoji_alias=":package:", ) else: self.print( f"Mesh for event: {event} already exists in the " f"correct path for iteration {iteration}. " f"Will not move new one.", emoji_alias=":white_check_mark", )