Module phi.physics.diffuse
Functions to simulate diffusion processes on Field
objects.
Functions
def differential(u: phi.field._field.Field, diffusivity: Union[float, phiml.math._tensors.Tensor, phi.field._field.Field], gradient: phi.field._field.Field = None, order: int = 2, implicit: phiml.math._optimize.Solve = None, upwind: phi.field._field.Field = None, correct_skew=True) ‑> phi.field._field.Field
-
Compute the differential diffusion term, d·∇²u. For grids, uses a finite difference scheme specified by
order
andimplicit()
. For FVM, the scheme is specified viaorder
andupwind
.In contrast to
explicit()
andimplicit()
, accuracy can be increased by using stencils of higher-order rather than calculating sub-steps.Args
u
- Scalar or vector-valued
Field
sampled on aCenteredGrid
,StaggeredGrid
or centeredMesh
. diffusivity
- Dynamic viscosity, i.e. diffusion per time. Constant or varying by cell.
gradient
- Only used by FVM at the moment. Approximate gradient of
u
, e.g. ∇u of the previous time step. IfNone
, approximates the gradient as(u_neighbor - u_self) / distance
. order
- Spatial order of accuracy.
Higher orders entail larger stencils and more computation time but result in more accurate results assuming a large enough resolution.
Supported: 2 explicit, 4 explicit, 6 implicit (inherited from
laplace()
). For FVM, the order is used when interpolatingv
andprev_v
to cell faces if needed. implicit
- When a
Solve
object is passed, performs an implicit operation with the specified solver and tolerances. Otherwise, an explicit stencil is used. upwind
- For unstructured meshes only. Whether to use upwind interpolation.
correct_skew
- If
True
, adds a correction term for cell skewness. This requiresgradient
to be passed.
Returns
Differential diffusion as a
Field
on the same geometry. def explicit(u: phi.field._field.Field, diffusivity: Union[float, phiml.math._tensors.Tensor, phi.field._field.Field], dt: Union[phiml.math._tensors.Tensor, float], substeps: int = 1, order: int = 2, implicit: phiml.math._optimize.Solve = None, gradient: phi.field._field.Field = None, upwind: phi.field._field.Field = None, correct_skew=True) ‑> phi.field._field.Field
-
Explicit Euler diffusion with substeps.
Simulate a finite-time diffusion process of the form dF/dt = α · ΔF on a given
Field
Field with diffusion coefficient α.Args
u
- CenteredGrid, StaggeredGrid or ConstantField
diffusivity
- Diffusion per time.
diffusion_amount = diffusivity * dt
Can be a number,phi.Tensor
orField
. If a channel dimension is present, it will be interpreted as non-isotropic diffusion. dt
- Time interval.
diffusion_amount = diffusivity * dt
substeps
- number of iterations to use (Default value = 1)
order
- Spatial order of accuracy.
Higher orders entail larger stencils and more computation time but result in more accurate results assuming a large enough resolution.
Supported: 2 explicit, 4 explicit, 6 implicit (inherited from
laplace()
). For FVM, the order is used when interpolatingv
andprev_v
to cell faces if needed. implicit
- When a
Solve
object is passed, performs a spatially implicit operation with the specified solver and tolerances. Otherwise, an explicit stencil is used. gradient
- Only used by FVM at the moment. Approximate gradient of
u
, e.g. ∇u of the previous time step. IfNone
, approximates the gradient as(u_neighbor - u_self) / distance
. upwind
- For unstructured meshes only. Whether to use upwind interpolation.
correct_skew
- If
True
, adds a correction term for cell skewness. This requiresgradient
to be passed.
Returns
Diffused field of same type as
field
. def finite_difference(u: phi.field._field.Field, diffusivity: Union[float, phiml.math._tensors.Tensor, phi.field._field.Field], gradient: phi.field._field.Field = None, order: int = 2, implicit: phiml.math._optimize.Solve = None, upwind: phi.field._field.Field = None, correct_skew=True) ‑> phi.field._field.Field
-
Compute the differential diffusion term, d·∇²u. For grids, uses a finite difference scheme specified by
order
andimplicit()
. For FVM, the scheme is specified viaorder
andupwind
.In contrast to
explicit()
andimplicit()
, accuracy can be increased by using stencils of higher-order rather than calculating sub-steps.Args
u
- Scalar or vector-valued
Field
sampled on aCenteredGrid
,StaggeredGrid
or centeredMesh
. diffusivity
- Dynamic viscosity, i.e. diffusion per time. Constant or varying by cell.
gradient
- Only used by FVM at the moment. Approximate gradient of
u
, e.g. ∇u of the previous time step. IfNone
, approximates the gradient as(u_neighbor - u_self) / distance
. order
- Spatial order of accuracy.
Higher orders entail larger stencils and more computation time but result in more accurate results assuming a large enough resolution.
Supported: 2 explicit, 4 explicit, 6 implicit (inherited from
laplace()
). For FVM, the order is used when interpolatingv
andprev_v
to cell faces if needed. implicit
- When a
Solve
object is passed, performs an implicit operation with the specified solver and tolerances. Otherwise, an explicit stencil is used. upwind
- For unstructured meshes only. Whether to use upwind interpolation.
correct_skew
- If
True
, adds a correction term for cell skewness. This requiresgradient
to be passed.
Returns
Differential diffusion as a
Field
on the same geometry. def fourier(field: phi.field._field.Field, diffusivity: Union[phiml.math._tensors.Tensor, float], dt: Union[phiml.math._tensors.Tensor, float]) ‑> phi.field._field.Field
-
Exact diffusion of a periodic field in frequency space.
For non-periodic fields or non-constant diffusivity, use another diffusion function such as
explicit()
.Args
- field:
diffusivity
- Diffusion per time.
diffusion_amount = diffusivity * dt
dt
- Time interval.
diffusion_amount = diffusivity * dt
Returns
Diffused field of same type as
field
. def implicit(field: phi.field._field.Field, diffusivity: Union[float, phiml.math._tensors.Tensor, phi.field._field.Field], dt: Union[phiml.math._tensors.Tensor, float], solve=CG with tolerance None (rel), None (abs), max_iterations=1000, gradient: phi.field._field.Field = None, upwind: phi.field._field.Field = None, correct_skew=True, gradient_for_diffusivity=True) ‑> phi.field._field.Field
-
Implicit Euler diffusion.
Diffusion by solving a linear system of equations.
Args
field
Field
to diffuse.diffusivity
- Diffusion per time.
diffusion_amount = diffusivity * dt
dt
- Time interval.
diffusion_amount = diffusivity * dt
solve
- Implicit solve parameters.
gradient
- Only used by FVM at the moment. Approximate gradient of
u
, e.g. ∇u of the previous time step. IfNone
, approximates the gradient as(u_neighbor - u_self) / distance
. upwind
- For unstructured meshes only. Whether to use upwind interpolation.
correct_skew
- If
True
, adds a correction term for cell skewness. This requiresgradient
to be passed. gradient_for_diffusivity
- Whether to compute the gradient w.r.t. the diffusivity parameters.
Returns
Diffused field of same type as
field
.