fluidsim.util
Utilities for FluidSim
Provides:
Utilities for the numerical simulations (fluidsim.util.util) |
|
Utilities for the unittests (fluidsim.util.testing) |
|
Console Utilities for FluidSim See fluidsim -h |
|
Utilities for fluidsim scripts (fluidsim.util.scripts) |
|
Mini operator to modify the resolution (Fourier) |
- fluidsim.util.load_sim_for_plot(name_dir=None, merge_missing_params=False, hide_stdout=False)[source]
Create a object Simul from a dir result.
Creating simulation objects with this function should be fast because the state is not initialized with the output file and only a coarse operator is created.
- Parameters:
- name_dirstr (optional)
Name of the directory of the simulation. If nothing is given, we load the data in the current directory. Can be an absolute path, a relative path, or even simply just the name of the directory under $FLUIDSIM_PATH.
- merge_missing_paramsbool (optional, default == False)
Can be used to load old simulations carried out with an old fluidsim version.
- hide_stdoutbool (optional, default == False)
If True, without stdout.
- fluidsim.util.load_state_phys_file(name_dir=None, t_approx='last', modif_save_params=True, merge_missing_params=False, init_with_initialized_state=True, hide_stdout=False)[source]
Create a simulation from a file.
For large resolution, creating a simulation object with this function can be slow because the state is initialized with the output file.
- Parameters:
- name_dirstr (optional)
Name of the directory of the simulation. If nothing is given, we load the data in the current directory. Can be an absolute path, a relative path, or even simply just the name of the directory under $FLUIDSIM_PATH.
- t_approxnumber (optional)
Approximate time of the file to be loaded.
- modif_save_paramsbool (optional, default == True)
If True, the parameters of the simulation are modified before loading:
params.output.HAS_TO_SAVE = False params.output.ONLINE_PLOT_OK = False
- merge_missing_paramsbool (optional, default == False)
Can be used to load old simulations carried out with an old fluidsim version.
- init_with_initialized_statebool (optional, default == True)
If True, call sim.output.init_with_initialized_state.
- hide_stdoutbool (optional, default == False)
If True, without stdout.
- fluidsim.util.load_for_restart(name_dir=None, t_approx='last', merge_missing_params=False)[source]
Load params and Simul for a restart.
>>> params, Simul = load_for_restart(name_dir)
- Parameters:
- name_dirstr (optional)
Name of the directory of the simulation. If nothing is given, we load the data in the current directory. Can be an absolute path, a relative path, or even simply just the name of the directory under $FLUIDSIM_PATH.
- t_approxnumber (optional)
Approximate time of the file to be loaded.
- merge_missing_paramsbool (optional, default == False)
Can be used to load old simulations carried out with an old fluidsim version.
- fluidsim.util.load_params_simul(path=None, only_mpi_rank0=True)
Load the parameters and return a Parameters instance.
- fluidsim.util.modif_resolution_from_dir(name_dir=None, t_approx='last', coef_modif_resol=2, PLOT=True)[source]
Save a file with a modified resolution.
- fluidsim.util.modif_resolution_from_dir_memory_efficient(name_dir=None, t_approx='last', coef_modif_resol=2)[source]
Save a file with a modified resolution.
Faster and more memory efficient than
modif_resolution_from_dir
(but not plot).
- fluidsim.util.times_start_last_from_path(path)[source]
Return the start and last times from a result directory path.
- fluidsim.util.get_mean_values_from_path(path, tmin=None, tmax=None, use_cache=True, customize=None)
Get a dict of scalar values characterizing the simulation
- Parameters:
- tmin: float
Minimum time
- tmax: float
Maximum time
- use_cache: bool
If True, return the cached result
- customize: callable
If not None, called as
customize(result, self.sim)
to modify the returned dict.
Examples
def customize(result, sim): result["Rb"] = float(sim.params.short_name_type_run.split("_Rb")[-1]) get_mean_values_from_path(path, customize=customize)
- fluidsim.util.get_dataframe_from_paths(paths, tmin=None, tmax=None, use_cache=True, customize=None)
Produce a dataframe from a set of simulations.
Uses
sim.output.get_mean_values
- fluidsim.util.get_last_estimated_remaining_duration(path)[source]
Get last estimated remaining duration written in stdout.txt
- fluidsim.util.open_patient(path, *args, time_wait_total=200, time_wait_once=2, class_file=<class 'h5py._hl.files.File'>, **kwargs)[source]
Open a hdf5 type file in a “patient” way.
If the file is already opened by another process (
errno==11
for hdf5), the error is caught and we retry later.- Parameters:
- time_wait_totalnumber (optional)
Time to wait before raising the error.
- time_wait_oncenumber (optional)
Time between attempts.
- class_filetype (optional)
Class of the file (default
h5py.File
, but could beh5netcdf.File
).