Utilities (nsfds3.utils)
The utils package gathers some utilities for nsfds3. The main ones are :
get_objects()
: get cfg and msh from pickles.
get_pressure()
: get pressure from conservative variables
get_probes()
: get probe values.
probes_to_wavfile()
: Make .wav files from probes signals.
- nsfds3.utils.get_objects(path, fname)[source]
Get cfg and msh objects from pickles.
- Parameters:
- Returns:
tuple of cfg and msh – Returns the cfg and msh objects
- Return type:
Examples
.cfg and .msh files are created for each simulation. They contain the configuration and grid objects relative to the simulation. To retrieve them, simply do:
from nsfds3.utils import get_objects cfg, msh = get_objects('path_to_cfg_and_msh_files', 'basename_of_these_files')
- nsfds3.utils.get_pressure(r=None, ru=None, rv=None, rw=None, re=None, gamma=1.4)[source]
Get pressure from conservative variables.
- Parameters:
r (numpy.array, optional) – Conservative variables
ru (numpy.array, optional) – Conservative variables
rv (numpy.array, optional) – Conservative variables
rw (numpy.array, optional) – Conservative variables
re (numpy.array, optional) – Conservative variables
gamma (float, optional) – Heat capacity ratio
- Returns:
p – Pressure
- Return type:
numpy.array
Example
The pressure is not directly provided. To access acoustic pressure, one can use
from nsfds3.utils import get_pressure p = get_pressure(r=r, ru=ru, rv=rv, rw=rw, re=re, gamma=gamma)
- nsfds3.utils.get_probes(cfg, save=False)[source]
Get probe location and values from cfg file.
- Parameters:
- Returns:
(locations, values, time) – locations are the spacial positions of the probes. values are the values of the probes. Each line corresponds to the values of a probe time is the time axis.
- Return type:
Example
from nsfds3.solver import CfgSetup from nsfds3.utils import get_probes cfg = CfgSetup('config_file.conf') locations, values, time = get_probes(cfg)
- nsfds3.utils.probes_to_wavfile(datafile, dtype=<class 'numpy.int16'>, path=None)[source]
Make .wav files from probes signals.
- Parameters:
datafile (hdf5 file) – the hdf5 file
dtype – type of the output wave file (np.int8, np.int16)
path – path to save wavefiles
- Returns:
out – list of probe signals saved in the wave files
- Return type: