jaxfluids.levelset package

Submodules

jaxfluids.levelset.geometry_calculator module

class jaxfluids.levelset.geometry_calculator.GeometryCalculator(domain_information: DomainInformation, first_derivative_stencil: SpatialDerivative, second_derivative_stencil: SpatialDerivative, subcell_reconstruction: bool)[source]

Bases: object

The GeometryCalculator class implements functionality to compute geometrical quantities that are required for two-phase simulations, i.e., volume fraction, apertures, interface normal and interface curvature. The volume fraction and the apertures are computed by linear interpolation of the levelset function. Interface normal and curvature are computed with user specified finite difference stencils.

compute_apertures(corner_values: Array, axis: int) Array[source]

Computes the apertures in axis direction.

Parameters:
  • corner_values (jnp.ndarray) – Levelset values at cell corners

  • axis (int) – spatial axis

Returns:

Apertures in axis direction

Return type:

jnp.ndarray

compute_corner_values(levelset: Array) Array[source]

Linear interpolation of the levelset values at the cell center to the corners of the cells.

Parameters:

levelset (jnp.ndarray) – Levelset buffer

Returns:

Levelset values at the corners of cells

Return type:

jnp.ndarray

compute_curvature(levelset: Array) Array[source]

Computes the curvature with the stencil specified in the numerical setup.

Parameters:

levelset (jnp.ndarray) – Levelset buffer

Returns:

Curvature buffer

Return type:

jnp.ndarray

compute_normal(levelset: Array) Array[source]

Computes the normal with the stencil specified in the numerical setup.

Parameters:

levelset (jnp.ndarray) – Levelset buffer

Returns:

Normal buffer

Return type:

jnp.ndarray

compute_volume_fraction(corner_values: Array, apertures: List) Array[source]

Computes the volume fraction.

Parameters:
  • corner_values (jnp.ndarray) – Levelset values at cell corners

  • apertures (List) – Apertures

Returns:

Volume fraction

Return type:

jnp.ndarray

eps = 2.220446049250313e-16
linear_interface_reconstruction(levelset: Array) Tuple[Array, List][source]

Computes the volume fraction and the apertures assuming a linear interface within each cell.

Parameters:

levelset (jnp.ndarray) – Leveset buffer

Returns:

Tuple of volume fraction and apertures

Return type:

Tuple[jnp.ndarray, List]

jaxfluids.levelset.helper_functions module

jaxfluids.levelset.helper_functions.move_source_to_target_ii(source_array: Array, normal_sign: Array, axis: int) Array[source]

Moves the source array in positive normal direction within the ii plane.

Parameters:
  • source_array (jnp.ndarray) – Source array buffer

  • normal_sign (jnp.ndarray) – Normal sign buffer

  • axis (int) – axis i

Returns:

Moved source array in ii plane

Return type:

jnp.ndarray

jaxfluids.levelset.helper_functions.move_source_to_target_ij(source_array: Array, normal_sign: Array, axis_i: int, axis_j: int) Array[source]
jaxfluids.levelset.helper_functions.move_source_to_target_ijk(source_array: Array, normal_sign: Array) Array[source]
jaxfluids.levelset.helper_functions.move_target_to_source_ii(target_array: Array, normal_sign: Array, axis: int) Array[source]

Moves the target array in negative normal direction in the ii plane.

Parameters:
  • target_array (jnp.ndarray) – Target array buffer

  • normal_sign (jnp.ndarray) – Normal sign buffer

  • axis (int) – axis i

Returns:

Moved target array in ii plane

Return type:

jnp.ndarray

jaxfluids.levelset.helper_functions.move_target_to_source_ij(target_array: Array, normal_sign: Array, axis_i: int, axis_j: int) Array[source]
jaxfluids.levelset.helper_functions.move_target_to_source_ijk(target_array: Array, normal_sign: Array) Array[source]

jaxfluids.levelset.interface_flux_computer module

class jaxfluids.levelset.interface_flux_computer.InterfaceFluxComputer(domain_information: DomainInformation, material_manager: MaterialManager, numerical_setup: Dict)[source]

Bases: object

The InterfaceFluxComputer computes the two-phase interface fluxes depending on the present interface interaction type and active physics. The Interface interaction types are 1) FLUID-SOLID-STATIC 2) FLUID-SOLID-DYNAMIC 3) FLUID-FLUID

compute_interface_flux_xi(primes: Array, interface_velocity: Array, interface_pressure: Array, volume_fraction: Array, apertures: Array, normal: Array, axis: int) Array[source]

Computes the interface flux in axis direction.

Parameters:
  • primes (jnp.ndarray) – Primitive variable buffer

  • interface_velocity (jnp.ndarray) – Interface velocity buffer

  • interface_pressure (jnp.ndarray) – Interface pressure buffer

  • volume_fraction (jnp.ndarray) – Volume fraction buffer

  • apertures (jnp.ndarray) – Aperture buffers

  • normal (jnp.ndarray) – Normal buffer

  • axis (int) – axis direction

Returns:

Interface flux in axis direction

Return type:

jnp.ndarray

jaxfluids.levelset.interface_quantity_computer module

class jaxfluids.levelset.interface_quantity_computer.InterfaceQuantityComputer(domain_information: DomainInformation, material_manager: MaterialManager, unit_handler: UnitHandler, solid_interface_velocity: Dict, numerical_setup: Dict)[source]

Bases: object

The InterfaceQuantityComputer class 1) solves the two-material Riemann problem, i.e., computes the interface velocity

and interface pressure for FLUID-FLUID interface interactions

  1. computes the solid interface velocity for FLUID-SOLID-DYNAMIC interface interactions

compute_solid_interface_velocity(current_time: float) Array[source]

Computes the solid interface velocity for FLUID-SOLID-DYNAMIC interface interactions.

Parameters:

current_time (float) – Current physical simulation time

Returns:

Solid interface velocity

Return type:

jnp.ndarray

eps = 2.220446049250313e-16
solve_interface_interaction(primes: Array, normal: Array, curvature: Array) Tuple[Array, Array][source]

Solves the two-material Riemann problem for FLUID-FLUID interface interactions.

Parameters:
  • primes (jnp.ndarray) – Primitive variable buffer

  • normal (jnp.ndarray) – Interface normal buffer

  • curvature (jnp.ndarray) – Interface curvature buffer

Returns:

Interface velocity and interface pressure

Return type:

Tuple[jnp.ndarray, jnp.ndarray]

jaxfluids.levelset.levelset_creator module

class jaxfluids.levelset.levelset_creator.LevelsetCreator(domain_information: DomainInformation, unit_handler: UnitHandler, initial_levelset: str | List, narrow_band_cutoff: int)[source]

Bases: object

The LevelsetCreator implements functionality to create initial levelset fields. The initial levelset field in one of two ways: 1) Lambda function via case setup file 2) List of building blocks. A single building block includes a shape

and a lambda function for the bounding domain.

create_levelset() Array[source]

Creates the levelset field either from the user defined lambda or from the user defined building blocks.

Returns:

Levelset buffer

Return type:

jnp.ndarray

get_circle(radius: float, position: List) Array[source]

Creates the levelset field for a circle.

Parameters:
  • radius (float) – Radius

  • position (List) – Center position

Returns:

Levelset buffer

Return type:

jnp.ndarray

get_rectangle(length: float, position: List, height: float | None = None, radius: float | None = None) Array[source]

Creates the levelset field for a rectangle. If the radius argument is specified, the rectangle corners will be rounded using that radius. If the height argument is not specified, a square will be created.

Parameters:
  • length (float) – Length

  • position (List) – Center position

  • height (float, optional) – Height, defaults to None

  • radius (float, optional) – Radius of the corners, defaults to None

Returns:

Leveset buffer

Return type:

jnp.ndarray

get_sphere(radius: float, position: float) Array[source]

Creates the levelset field for a sphere.

Parameters:
  • radius (float) – Radius

  • position (float) – Center position

Returns:

_description_

Return type:

jnp.ndarray

jaxfluids.levelset.levelset_handler module

class jaxfluids.levelset.levelset_handler.LevelsetHandler(domain_information: DomainInformation, numerical_setup: Dict, material_manager: MaterialManager, unit_handler: UnitHandler, solid_interface_velocity: List | function, boundary_condition: BoundaryCondition)[source]

Bases: object

The LevelsetHandler class manages computations to perform two-phase simulations using the levelset method. The main functionality includes

  • Transformation of the conservative states from volume-averages to actual conserved quantities according to the volume fraction

  • Weighting of the cell face fluxes according to the apertures

  • Computation of the interface fluxes

  • Computation of the levelset advection right-hand-side

  • Extension of the primitive state from the real fluid cells to the ghost fluid cells

  • Mixing of the integrated conservatives

  • Computation of geometrical quantities, i.e., volume fraction, apertures and real fluid/cut cell masks

compute_cut_cell_mask(volume_fraction: Array) Array[source]

Computes the cut cell mask, i.e., cells where the volume fraction is > 0.0 and < 1.0

Parameters:

volume_fraction (jnp.ndarray) – Volume fraction buffer

Returns:

Cut cell mask

Return type:

jnp.ndarray

compute_interface_flux_xi(primes: Array, levelset: Array, interface_velocity: Array, interface_pressure: Array | None, volume_fraction: Array, apertures: Array, axis: int) Array[source]

Computes the interface flux depending on the present interface interaction type.

Parameters:
  • primes (jnp.ndarray) – Buffer of primitive variables

  • levelset (jnp.ndarray) – Levelset buffer

  • interface_velocity (jnp.ndarray) – Interface velocity buffer

  • interface_pressure (Union[jnp.ndarray, None]) – Interface pressure buffer

  • volume_fraction (jnp.ndarray) – Volume fraction buffer

  • apertures (jnp.ndarray) – Aperture buffer

  • axis (int) – Current axis

Returns:

Interface fluxes

Return type:

jnp.ndarray

compute_interface_quantities(primes: Array, levelset: Array, volume_fraction: Array) Tuple[Array, Array, float][source]

Computes interface velocity and pressure for FLUID-FLUID interface interaction and extends the values into the narrow_band_compute.

Parameters:
  • primes (jnp.ndarray) – Buffer of primitive variables

  • levelset (jnp.ndarray) – Levelset buffer

  • volume_fraction (jnp.ndarray) – Volume fractio buffer

Returns:

Tuple of interface velocity, interface pressure and maximum residual of the extension

Return type:

Tuple[jnp.ndarray, jnp.ndarray, float]

compute_levelset_advection_rhs(levelset: Array, interface_velocity: Array, axis: int) Array[source]

Computes the right-hand-side of the levelset advection equation.

Parameters:
  • levelset (jnp.ndarray) – Levelset buffer

  • interface_velocity (jnp.ndarray) – Interface velocity buffer

  • axis (int) – Current axis

Returns:

right-hand-side contribution for current axis

Return type:

jnp.ndarray

compute_masks(levelset: Array, volume_fraction: Array) Tuple[Array, Array][source]

Computes the real mask and the cut cell mask

Parameters:
  • levelset (jnp.ndarray) – Levelset buffer

  • volume_fraction (jnp.ndarray) – Volume fraction buffer

Returns:

Tuple containing the real mask and the cut cell mask

Return type:

Tuple[jnp.ndarray, jnp.ndarray]

compute_primitives_from_conservatives_in_real_fluid(cons: Array, primes: Array, levelset: Array, volume_fraction: Array, mask_small_cells: Array) Array[source]

Computes the primitive variables from the mixed conservatives within the real fluid.

Parameters:
  • cons (jnp.ndarray) – Buffer of primitive variables

  • primes (jnp.ndarray) – _description_

  • levelset (jnp.ndarray) – _description_

  • volume_fraction (jnp.ndarray) – _description_

  • mask_small_cells (jnp.ndarray) – _description_

Returns:

_description_

Return type:

jnp.ndarray

compute_solid_interface_velocity(current_time: float) Array[source]

Computes the interface velocity for FLUID-SOLID-DYNAMIC interface interaction.

Parameters:

current_time (float) – Current physical simulation time

Returns:

Interface velocity buffer

Return type:

jnp.ndarray

compute_volume_fraction_and_apertures(levelset: Array) Tuple[Array, List][source]

Computes the volume fraction and apertures via linear interface reconstruction

Parameters:

levelset (jnp.ndarray) – Levelset buffer

Returns:

Tuple containing the volume fraction buffer and the aperture buffers

Return type:

Tuple[jnp.ndarray, List]

eps = 2.220446049250313e-16
extend_primes(cons: Array, primes: Array, levelset: Array, volume_fraction: Array, current_time: float, mask_small_cells: Array | None = None) Tuple[Array, float][source]

Extends the primitives from the real fluid cells into the ghost fluid cells within the narrow_band_compute. Subsequently, the corresponding conservatives are computed from the extended primitives.

Parameters:
  • cons (jnp.ndarray) – Buffer of conservative variables

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

  • levelset (jnp.ndarray) – Levelset buffer

  • volume_fraction (jnp.ndarray) – Volume fraction buffer

  • current_time (float) – Current physical simulation time

  • mask_small_cells (jnp.ndarray, optional) – Mask indicating small negative cells, defaults to None

Returns:

Tuple of primitive and conservative buffer and maximum extension residual

Return type:

Tuple[jnp.ndarray, float]

mixing(cons: Array, levelset_new: Array, volume_fraction_new: Array, volume_fraction_old: Array) Tuple[Array, Array][source]

Performs a mixing procedure on the integrated conservatives enabling stable integration of small cut cells with the CFL criterion for full cells. For small cells that are in the process of vanishing (becoming ghost cells), this procedure may produce negative mass/energy. To prevent numerical instability, we track these cells with the mask_small_cells buffer and perform a prime extension into these cells.

Parameters:
  • cons (jnp.ndarray) – Buffer of integrated conservative variables

  • levelset_new (jnp.ndarray) – Integrated levelset buffer

  • volume_fraction_new (jnp.ndarray) – Integrated volume fraction buffer

  • volume_fraction_old (jnp.ndarray) – Volume fraction buffer of previous time step (RK stage)

Returns:

Tuple containing the mixed conservatives and a mask indicating small cells with negative energy/mass.

Return type:

Tuple[jnp.ndarray, jnp.ndarray]

reinitialize(levelset: Array, initializer: bool) Tuple[Array, float][source]

Reinitializes the levelset buffer and subsequently applies cut off to values that lie outside the narrow_band_cutoff. If the initializer flag is True, cut cells are always reinitialized. This is required to initialize levelset fields that are provided as no signed distance functions, e.g., an ellipse. If cut_cell_reinitialization is True (specified in numerical setup), then cut cells are also reinitialized. The residual is only computed in the narrow_band_computations.

Parameters:
  • levelset (jnp.ndarray) – Levelset buffer

  • initializer (bool) – Bool indicating if the reinitialization is performed in the jaxfluids initializer or the jaxfluids simulation manager

Returns:

Reinitialized levelset buffer and the corresponding maximum residual

Return type:

Tuple[jnp.ndarray, float]

transform_to_conservatives(cons: Array, volume_fraction: Array) Array[source]

Transforms the volume-averaged conservatives to actual conservatives that can be integrated according to the volume fraction.

Parameters:
  • cons (jnp.ndarray) – Buffer of conservative variables

  • volume_fraction (jnp.ndarray) – Volume fraction buffer

Returns:

Buffer of actual conservative variables

Return type:

jnp.ndarray

transform_to_volume_averages(cons: Array, volume_fraction: Array) Array[source]

Transforms the mixed conservatives to volume-averaged conservatives. Emtpy cells are filled with eps. Negative small cells (which may occur after mixing) are filled with eps. We extend the integrated primitive state into the negative small cells cells.

Parameters:
  • cons (jnp.ndarray) – Buffer of mixed conservative variables

  • volume_fraction (jnp.ndarray) – Volume fraction buffer

Returns:

Volume-averaged conservatives

Return type:

jnp.ndarray

weight_cell_face_flux_xi(flux_xi: Array, apertures: Array) Array[source]

Weights the cell face fluxes according to the apertures.

Parameters:
  • flux_xi (jnp.ndarray) – Cell face flux at xi

  • apertures (jnp.ndarray) – Aperture buffer

Returns:

Weighted cell face flux at xi

Return type:

jnp.ndarray

weight_volume_force(volume_force: Array, volume_fraction: Array) Array[source]

Weights the volume forces according to the volume fraction.

Parameters:
  • volume_force (jnp.ndarray) – Volume force buffer

  • volume_fraction (jnp.ndarray) – Volume fraction buffer

Returns:

Weighted volume force

Return type:

jnp.ndarray

jaxfluids.levelset.levelset_reinitializer module

class jaxfluids.levelset.levelset_reinitializer.LevelsetReinitializer(domain_information: DomainInformation, boundary_condition: BoundaryCondition, time_integrator: TimeIntegrator, derivative_stencil: SpatialDerivative)[source]

Bases: object

The LevelsetReinitializer class implements functionality to reinitialize the levelset buffer.

compute_rhs(levelset: Array, levelset_0: Array, mask: Array) Tuple[Array, Array][source]

Computes the right-hand-side of the levelset reinitialization equation.

Parameters:
  • levelset (jnp.ndarray) – Levelset buffer

  • levelset_0 (jnp.ndarray) – Levelset buffer at fictitious time = 0.0

  • mask (jnp.ndarray) – Mask for right-hand-side

Returns:

Tuple of right-hand-side and signed distance residual

Return type:

Tuple[jnp.ndarray, jnp.ndarray]

do_integration_step(levelset: Array, levelset_0: Array, mask: Array, timestep_size: float) Tuple[Array, Array][source]

Performs an integration step of the levelset reinitialization equation.

Parameters:
  • levelset (jnp.ndarray) – Levelset buffer

  • levelset_0 (jnp.ndarray) – Levelset buffer at fictitious time = 0.0

  • mask (jnp.ndarray) – Mask for right-hand-side

  • timestep_size (float) – Timestep size

Returns:

Tuple containing integrated levelset buffer and signed distance residual

Return type:

Tuple[jnp.ndarray, jnp.ndarray]

eps = 2.220446049250313e-16
reinitialize(levelset: Array, mask_reinitialize: Array, mask_residual: Array, CFL: float, steps: int) Tuple[Array, float][source]

Reinitializes the levelset buffer.

Parameters:
  • levelset (jnp.ndarray) – Levelset buffer

  • mask_reinitialize (jnp.ndarray) – Mask indicating which cells to reinitialize

  • mask_residual (jnp.ndarray) – Mask indicating where to compute the maximum residual of the reinitialization equation

  • CFL (float) – CFL number

  • steps (int) – Number of integration steps

Returns:

Reinitialized levelset buffer and maximum residual of the reinitialization equation

Return type:

Tuple[jnp.ndarray, float]

jaxfluids.levelset.quantity_extender module

class jaxfluids.levelset.quantity_extender.QuantityExtender(domain_information: DomainInformation, boundary_condition: BoundaryCondition, time_integrator: TimeIntegrator, spatial_stencil: SpatialDerivative, is_interface: bool)[source]

Bases: object

The QuantiyExtender performs a zero-gradient extension in interface normal direction of an arbitrary quantity.

compute_rhs(quantity: Array, normal: Array, mask: Array) Array[source]

Computes the right-hand-side of the exension equation.

Parameters:
  • quantity (jnp.ndarray) – Quantity buffer

  • normal (jnp.ndarray) – Normal buffer

  • mask (jnp.ndarray) – Mask indiciating where to extend

Returns:

Right-hand-side of the extension equation

Return type:

jnp.ndarray

do_integration_step(quantity: Array, normal: Array, mask: Array, timestep_size: float) Tuple[Array, Array][source]

Performs an integration step of the extension equation.

Parameters:
  • quantity (jnp.ndarray) – Quantity buffer

  • normal (jnp.ndarray) – Normal buffer

  • mask (jnp.ndarray) – Mask indicating where to extend

  • timestep_size (float) – Fictitious time step size

Returns:

Integrated quantity buffer and corresponding right-hand-side buffer

Return type:

Tuple[jnp.ndarray, jnp.ndarray]

extend(quantity: Array, normal: Array, mask: Array, CFL: float, steps: int) Tuple[Array, float][source]

Extends the quantity in normal direction.

Parameters:
  • quantity (jnp.ndarray) – Quantity buffer

  • normal (jnp.ndarray) – Normal buffer

  • mask (jnp.ndarray) – Mask indicating where to extend

  • CFL (float) – CFL number

  • steps (int) – Number of integration steps

Returns:

Extended quantity buffer and corresponding residual

Return type:

Tuple[jnp.ndarray, float]

Module contents