Utilities (nsfds3.utils)

The utils package gathers some utilities for nsfds3. The main ones are :

nsfds3.utils.get_objects(path, fname)[source]

Get cfg and msh objects from pickles.

Parameters:
  • path (str) – path to cfg and mesh files

  • fname (str) – basename for cfg and msh files

Returns:

tuple of cfg and msh – Returns the cfg and msh objects

Return type:

tuple

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:
  • cfg (CfgSetup) – Configuration of the simulation. Must be a CfgSetup instance.

  • save (bool, default to False) – Whether to save probe to npy files or not.

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:

tuple

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:

list