jaxfluids.turb package

Submodules

jaxfluids.turb.turb_init_cond module

class jaxfluids.turb.turb_init_cond.TurbInitManager(input_reader: InputReader, domain_information: DomainInformation, material_manager: MaterialManager)[source]

Bases: object

The TurbInitManager implements functionality for the initialization of turbulent flow fields. The main function of the TurbInitManager is the get_turbulent_initial_condition method which returns a randomly initialized turbulent flow field according to the user-specified initial conditions. Currently there are four different options available:

  1. HIT flow field according to Ristorcelli

  2. Taylor-Green vortex

  3. Turbulent channel flow (under construction)

get_turbulent_initial_condition() Tuple[ndarray, ndarray, ndarray, ndarray, ndarray][source]

Calculates turbulent primitive variables.

Initialization is based on the turbulent case specified in the self.turb_init_params dictionary.

Returns:

Primitive variables: density, velocity vector, pressure

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray]

jaxfluids.turb.turb_init_cond.get_dilatational_field(U_field: array, Ma: float, T_ref: float, rho_ref: float, gamma: float) Tuple[ndarray, ndarray, ndarray][source]

Computes dilatational part of the velocity field and consistent pressure and density fluctuations. Pressure and density fluctuations are introduced by solving two Poisson equations in spectral space. Routine based on Ristorecelli & Blaisdell 1997.

Parameters:
  • U_field (np.array) – Solenoidal input velocity field.

  • Ma (float) – Target Mach number.

  • T_ref (float) – Reference temperature.

  • rho_ref (float) – Reference density.

  • gamma (float) – Ratio of specific heats.

Returns:

Dilatational velocity field, fluctuating density and pressure.

Return type:

np.ndarray

jaxfluids.turb.turb_init_cond.get_solenoidal_field(U: ndarray) ndarray[source]

Performs a Helmholtz decomposition of the given velocity, i.e., calculates a solenoidal velocity field.

Note that the input velocity field has to be sufficiently smooth, and that the domain has to be [0, 2pi] x [0, 2pi] x [0, 2pi].

Parameters:

U (np.ndarray) – Input velocity field.

Returns:

Projected, solenoidal velocity field.

Return type:

np.ndarray

jaxfluids.turb.turb_init_cond.get_target_spectrum(energy_spectrum: str, nx: int, xi_0: int | None = None) ndarray[source]

Returns the user-specified energy spectrum which is later used for initialization of a turbulent velocity field.

Parameters:
  • energy_spectrum (str) – String identifier for the energy spectrum.

  • nx (int) – Spatial resolution.

  • xi_0 (int, optional) – Wavenumber of energy spectrum peak, defaults to None

Raises:

NotImplementedError – Raises error if specified energy spectrum is not implemented.

Returns:

Array with energy in spectral space.

Return type:

np.ndarray

jaxfluids.turb.turb_init_cond.rescale_field(U_field: array, ek_target: array) ndarray[source]

Rescales the input velocity field such that it matches the specified target energy spectrum. Rescaling is done in spectral space.

Parameters:
  • U_field (np.array) – Input velocity field which has to be rescaled.

  • ek_target (np.array) – Target energy spectrum.

Returns:

Rescaled velocity field.

Return type:

np.ndarray

jaxfluids.turb.turb_init_cond.turb_init_TGV(X: ndarray, gamma: float, Ma: float, rho_ref: float, V_ref: float, L: float) ndarray[source]

Implements initial conditions for compressible Taylor-Green vortex (TGV).

Parameters:
  • X (np.ndarray) – Buffer of cell center coordinats.

  • gamma (float) – Ratio of specific heats.

  • Ma (float) – Mach number of the flow.

  • rho_ref (float) – Reference density scale.

  • V_ref (float) – Reference velocity scale..

  • L (float) – Reference length scale.

Returns:

Buffer with TGV initial conditions in terms of primitive variables.

Return type:

np.ndarray

jaxfluids.turb.turb_init_cond.turb_init_channel()[source]

Implements initial conditions for a turbulent channel flow. # TODO

jaxfluids.turb.turb_init_cond.turb_init_ristorcelli(N: int, gamma: float, T_ref: float, rho_ref: float, energy_spectrum: str, ma_target: float, xi_0: int, ic_type: int) Tuple[ndarray, ndarray, ndarray][source]

Ristorcelli & Blaisdell 1997 Incompressible/compressible random initial velocity field with prescribed energy spectrum

Currently three variants are implemented which can be selected via the ic_type argument: IC1) Solenoidal velocity field with uniform pressure and density IC2) Solenoidal velocity field with pressure obtained from Poisson equation and uniform density IC3) Compressible velocity field with pressure and density obtained from Poisson equations

Parameters:
  • N (int) – Spatial resolution.

  • gamma (float) – Ratio of specific heats.

  • T_ref (float) – Temperature reference.

  • rho_ref (float) – Density reference.

  • energy_spectrum (str) – Target energy spectrum.

  • ma_target (float) – Target Mach number.

  • xi_0 (int) – Wavenumber at which energy spectrum is maximal.

  • ic_type (int) – String identifier which determines the type of thermodynamic fluctuations.

Returns:

Initial density, velocity, and pressure fields.

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray]

jaxfluids.turb.turb_stats module

jaxfluids.turb.turb_stats.calculate_sheartensor_OLD(U_field: array) array[source]

Calculate shear tensor in spectral space

U_field: (3, Nx, Ny, Nz) array

duidj = [

du1/dx1 du1/dx2 du1/dx3 du2/dx1 du2/dx2 du2/dx3 du3/dx1 du3/dx2 du3/dx3

]

jaxfluids.turb.turb_stats.get_energy_spectrum(vel)[source]
jaxfluids.turb.turb_stats.get_energy_spectrum_np(vel)[source]
jaxfluids.turb.turb_stats.get_energy_spectrum_np_OLD(vel)[source]

SHOWS equality of energy in physical and spectral space and also via integration of energy spectrum

jaxfluids.turb.turb_stats.get_quick_stats_hit(rho, velocityX, velocityY, velocityZ, pressure, mu: float, gamma: float = 1.4)[source]
jaxfluids.turb.turb_stats.get_scalar_energy_spectrum(vel)[source]
jaxfluids.turb.turb_stats.get_stats_hit(rho: array, velocityX: array, velocityY: array, velocityZ: array, pressure: array, material_manager: MaterialManager)[source]

jaxfluids.turb.turb_stats_manager module

class jaxfluids.turb.turb_stats_manager.TurbStatsManager(domain_information: DomainInformation, material_manager: MaterialManager | None = None)[source]

Bases: object

Provides functionality to calculate statistics of turbulent flows. The TurbStatsManager provides turbulent statistics of the initial flow field as well as cumulative statistics over the course of a simulation.

calculate_dilatation(velocity: Array) Array[source]

_summary_

Calculates dilatation in spectral space

velocity: (3, Nx, Ny, Nz) array

dilatation: (Nx, Ny, Nz) array dilatation = du1/dx1 + du2/dx2 + du3/dx3

Parameters:

velocity (jnp.ndarray) – Buffer of velocities in physical space.

Returns:

Buffer of dilatational field.

Return type:

jnp.ndarray

calculate_dilatation_spectral(velocity_hat: Array) Array[source]

Calculates the dilatation of the given velocity field in spectral space.

Parameters:

velocity_hat (jnp.ndarray) – Buffer of velocities in spectral space.

Returns:

Buffer of the dilatational field.

Return type:

jnp.ndarray

calculate_sheartensor(velocity: Array) Array[source]

Calculates the shear tensor in spectral space. Wrapper around self.calculate_sheartensor_spectral().

duidj = [

du1/dx1 du1/dx2 du1/dx3 du2/dx1 du2/dx2 du2/dx3 du3/dx1 du3/dx2 du3/dx3

]

Parameters:

velocity (jnp.ndarray) – Buffer of velocities in physical space.

Returns:

Buffer of the shear tensor.

Return type:

jnp.ndarray

calculate_sheartensor_spectral(velocity_hat: Array) Array[source]

Calculates the shear tensor in spectral space.

dui/dxj = IFFT ( 1j * k_j * u_i_hat )

Parameters:

velocity_hat (jnp.ndarray) – Buffer of velocities in spectral space.

Returns:

Buffer of the shear tensor.

Return type:

jnp.ndarray

calculate_strain() Array[source]

Calculates the strain given the velocity gradient tensor.

Parameters:

duidj (jnp.ndarray) – Buffer of velocity gradient.

Returns:

Buffer of strain tensor.

Return type:

jnp.ndarray

calculate_vorticity(velocity: Array) Array[source]

Calculates the vortiticy of the input velocity field. Calculation done in spectral space.

omega = [ du3/dx2 - du2/dx3

du1/dx3 - du3/dx1 du2/dx1 - du1/dx2]

Parameters:

velocity (jnp.ndarray) – Buffer of velocities in physical space.

Returns:

Vorticity vector in physical space.

Return type:

jnp.ndarray

calculate_vorticity_spectral(velocity_hat: Array) Array[source]

Calculates the vortiticy of the input velocity field. Calculation done in spectral space.

omega = (du3/dx2 - du2/dx3, du1/dx3 - du3/dx1, du2/dx1 - du1/dx2)

Parameters:

velocity_hat (jnp.ndarray) – Buffer of velocities in spectral space.

Returns:

Vorticity vector in physical space.

Return type:

jnp.ndarray

energy_spectrum_physical(velocity: Array) Array[source]

Calculates the three-dimensional spectral energy spectrum of the input velocity. Wrapper around self.energy_spectrum_spectral

Parameters:

velocity (jnp.ndarray) – Velocity vector in physical space.

Returns:

Spectral energy spectrum.

Return type:

jnp.ndarray

energy_spectrum_spectral(velocity_hat: Array) Array[source]

Calculates the three-dimensional spectral energy spectrum of the input velocity.

Parameters:

velocity_hat (jnp.ndarray) – Velocity vector in spectral space.

Returns:

Spectral energy spectrum.

Return type:

jnp.ndarray

get_turbulent_statistics(primes: Array) Dict[source]

Computes the turbulent statistics for the given primitive buffer.

Parameters:

primes (jnp.ndarray) – Buffer of primitive variables.

Returns:

Dictionary with turbulent statistics.

Return type:

Dict

hit_statistics(primes: Array) Dict[source]

Calculates statistics for homogeneous isotropic turbulence.

Parameters:

primes (jnp.ndarray) – Buffer of primitive variables.

Returns:

Dictionary with information on the HIT statistics.

Return type:

Dict

initialize() None[source]

jaxfluids.turb.turb_utils module

jaxfluids.turb.turb_utils.calculate_dilatation(velocity)[source]

Calculates dilatation in spectral space

velocity: (3, Nx, Ny, Nz) array

dilatation: (Nx, Ny, Nz) array dilatation = du1/dx1 + du2/dx2 + du3/dx3

jaxfluids.turb.turb_utils.calculate_dilatation_spectral(velocity_hat: ~numpy.array, k_field: ~numpy.array, dtype: ~numpy.dtype = <class 'numpy.float64'>) array[source]
jaxfluids.turb.turb_utils.calculate_sheartensor(velocity: array) array[source]

Calculates shear tensor in spectral space

velocity: (3, Nx, Ny, Nz) array

duidj: (3, 3, Nx, Ny, Nz) array duidj = [

du1/dx1 du1/dx2 du1/dx3 du2/dx1 du2/dx2 du2/dx3 du3/dx1 du3/dx2 du3/dx3

]

jaxfluids.turb.turb_utils.calculate_sheartensor_spectral(velocity_hat: ~numpy.array, k_field: ~numpy.array, dtype: ~numpy.dtype = <class 'numpy.float64'>) array[source]
jaxfluids.turb.turb_utils.calculate_strain(duidj: array) array[source]

duidj: (3,3,Nx,Ny,Nz)

jaxfluids.turb.turb_utils.calculate_vorticity(velocity: array) array[source]

Calculates vorticity in spectral space velocity: (3, Nx, Ny, Nz)

omega: (3, Nx, Ny, Nz) omega = [ du3/dx2 - du2/dx3

du1/dx3 - du3/dx1 du2/dx1 - du1/dx2]

jaxfluids.turb.turb_utils.calculate_vorticity_spectral(velocity_hat: ~numpy.array, k_field: ~numpy.array, dtype: ~numpy.dtype = <class 'numpy.float64'>) array[source]
jaxfluids.turb.turb_utils.get_real_wavenumber_grid(N)[source]
jaxfluids.turb.turb_utils.is_power_of_two(a)[source]
jaxfluids.turb.turb_utils.velocity_rfftn(velocity: array) array[source]

RFFTN velocity : (3, Nx, Ny, Nz) velocity_hat: (3, Nfx, Ny, Nz)

Module contents