Class pylset_field¶
Scalar field, such as temperature or concentration, on the grid of a level set simulation, with transient diffusion, sources and boundary conditions on each face of the domain. Created by setup_simulation.add_scalar_field().
Scalar field, such as temperature or concentration, on the grid of a level set simulation.
The field u follows the transient diffusion equation
c du/dt = div(k grad u) + Q,
with the capacity c, the conductivity k and the volumetric source Q. It is
discretized by finite volumes on the cell centered grid of the simulation,
with the conductivity at a face between two cells taken as the harmonic mean
of the cell values, which keeps the flux continuous where k jumps. Each face
of the domain has its own boundary condition (set_bc()). Axes that are
periodic for the level sets are periodic for the field.
A field is created by setup_simulation.add_scalar_field() and advanced to
the time of the level sets by setup_simulation.do_field_update(), or by a
chosen time step with do_update().
Methods:¶
__init__ ¶
__init__(sim: Any, name: str, value: Value = 0.0, capacity: Value = 1.0, conductivity: Value = 1.0, source: Value = 0.0, time_scheme: str = 'Implicit', tolerance: float = 1e-08, max_iterations: int = 2000, cfl: float = 0.5, preconditioner: str = 'Multigrid') -> None
Initialize a scalar field. Use setup_simulation.add_scalar_field() rather than calling this directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim
|
setup_simulation
|
Simulation whose grid, device and precision the field uses. |
required |
name
|
str
|
Name of the field. |
required |
value
|
(float, ndarray or callable)
|
Initial value, a number, an array of shape |
0.0
|
capacity
|
(float, ndarray or callable)
|
Capacity c (for heat conduction the density times the specific heat).
A function is called with the field |
1.0
|
conductivity
|
(float, ndarray or callable)
|
Conductivity k, given like the capacity. |
1.0
|
source
|
(float, ndarray or callable)
|
Volumetric source Q. A function is called as |
0.0
|
time_scheme
|
str
|
'Implicit' (backward Euler, the default), 'Crank-Nicolson', 'Explicit' (forward Euler with substeps within the stability limit) or 'Steady' (the steady state for the current sources and boundary values at each update). The case is ignored. |
'Implicit'
|
tolerance
|
float
|
Relative residual at which the conjugate gradient iterations stop. |
1e-08
|
max_iterations
|
int
|
Largest number of conjugate gradient iterations per update. |
2000
|
cfl
|
float
|
Safety factor on the stability limit of the 'Explicit' scheme. |
0.5
|
preconditioner
|
str
|
'Multigrid' (a geometric multigrid V-cycle, the default) or 'Jacobi' (the diagonal) for the conjugate gradient iterations. The case is ignored. |
'Multigrid'
|
add_source ¶
add_source(power: Union[float, Callable], radius: float, center: Optional[Any] = None, path: Optional[Union[ndarray, Callable]] = None, profile: str = 'Gaussian', time: Optional[Tuple[float, float]] = None, name: Optional[str] = None) -> str
Add a localized source, at rest or moving, for example a laser or electron beam.
The source deposits the total power (the integral of Q over the
domain, energy per time for heat), distributed as a Gaussian
Q ~ exp(-2 r^2 / radius^2), so that radius is the 1/e^2 radius as is
common for laser beams, or uniformly over a disc (2D) or sphere (3D) of
the given radius with an edge smoothed over one grid spacing. The
discrete profile is normalized so that the deposited power is exact on
any grid, and the part of a source that lies outside a nonperiodic face
is lost. In each update the source is averaged over the step, with the
center sampled along the path at intervals of at most half the radius,
so a fast source leaves a continuous track. Sources are evaluated in a
box around their path, not on the whole grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
power
|
float or callable
|
Total power, a number or a function of the time |
required |
radius
|
float
|
The 1/e^2 radius of a 'Gaussian' source or the radius of a 'Uniform' source. |
required |
center
|
sequence of float
|
Position of a source at rest. |
None
|
path
|
ndarray or callable
|
Position of a moving source, an array of rows (t, x, y) or
(t, x, y, z) interpolated linearly in time and constant before the
first and after the last row, or a function |
None
|
profile
|
str
|
'Gaussian' (default) or 'Uniform'. The case is ignored. |
'Gaussian'
|
time
|
tuple of float
|
Interval (t_on, t_off) in which the source is active. Always active if None. |
None
|
name
|
str
|
Name of the source, used by |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the source. |
do_update ¶
Advance the field by one time step.
With 'Implicit' and 'Crank-Nicolson', the theta scheme
c (u1 - u0)/dt = theta (L u1 + b1) + (1 - theta)(L u0 + b0), with
theta 1 or ½, is solved by preconditioned conjugate gradients,
with the source and boundary values taken at t + theta dt. Capacity and
conductivity functions are evaluated at u0, and the localized sources of
add_source() are averaged over the step. 'Explicit' takes forward
Euler substeps within get_stable_dtime(). 'Steady' solves L u + b = 0,
which is well posed only with a condition that fixes the level of the
field, so it requires at least one 'Dirichlet', 'Robin' or 'Radiation'
face or domain. 'Radiation' conditions are linearized at the surface
values, and the linear solve is repeated in Newton iterations until the
field no longer changes. 'Explicit' takes the exact radiation flux of
each substep, with the stability limit of the start of the step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtime
|
float
|
Time step, positive, or zero for a 'Steady' solve at the current time. |
required |
get_bc ¶
Get the boundary conditions of all faces.
Returns:
| Name | Type | Description |
|---|---|---|
bc |
dict
|
Face name to the tuple (kind, value, coefficient). |
get_domain_conditions ¶
Get the kinds of the conditions set on immobile domains.
Returns:
| Name | Type | Description |
|---|---|---|
conditions |
dict
|
Domain ID to 'Material', 'Dirichlet', 'Neumann', 'Robin' or 'Radiation'. |
get_name ¶
Get the name of the field.
Returns:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name given in |
get_solver_info ¶
Get the iterations and the relative residual of the last implicit update.
Returns:
| Name | Type | Description |
|---|---|---|
info |
dict
|
'iterations' (conjugate gradient iterations, summed over the Newton iterations), 'residual' (of the last solve) and 'newton_iterations' (linear solves for the 'Radiation' conditions, 1 without them). |
get_sources ¶
Get the names of the localized sources.
Returns:
| Name | Type | Description |
|---|---|---|
names |
list of str
|
Names of the sources added with |
get_stable_dtime ¶
Get the stability limit of the 'Explicit' scheme for the current properties.
Returns:
| Name | Type | Description |
|---|---|---|
dtime |
float
|
|
get_time ¶
Get the time up to which the field has been advanced.
Returns:
| Name | Type | Description |
|---|---|---|
time |
float
|
Time of the field. |
get_time_scheme ¶
Get the time integration scheme.
Returns:
| Name | Type | Description |
|---|---|---|
time_scheme |
str
|
'Implicit', 'Crank-Nicolson', 'Explicit' or 'Steady'. |
get_value ¶
Get the field values.
Returns:
| Name | Type | Description |
|---|---|---|
u |
ndarray of shape `ndiv`
|
Host copy of the field. |
get_value_device ¶
Get the field on the computing device (not a copy, do not change it in place).
Returns:
| Name | Type | Description |
|---|---|---|
u |
torch.Tensor of shape `ndiv`
|
Field on the device. |
remove_source ¶
Remove a localized source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name returned by |
required |
set_bc ¶
Set the boundary condition on one face of the domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
face
|
str
|
'x-', 'x+', 'y-', 'y+' and, in 3D, 'z-' or 'z+'. |
required |
kind
|
str
|
'Dirichlet' (the field |
required |
value
|
(float, ndarray or callable)
|
A number, an array of the shape of the face (the grid shape without
the normal axis) or a function of the time |
0.0
|
coefficient
|
(float, ndarray or callable)
|
Transfer coefficient of the 'Robin' condition or emissivity times the
Stefan-Boltzmann constant of the 'Radiation' condition, given like |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the face or the kind is not recognized, or if the face belongs to a periodic axis. |
set_capacity ¶
Set the capacity c.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
capacity
|
(float, ndarray or callable)
|
A positive number, an array of shape |
required |
set_conductivity ¶
Set the conductivity k.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conductivity
|
(float, ndarray or callable)
|
A nonnegative number, an array of shape |
required |
set_domain_condition ¶
set_domain_condition(domain_id: int, kind: Optional[str], value: Value = 0.0, coefficient: Optional[Value] = None, capacity: Optional[Value] = None, conductivity: Optional[Value] = None, source: Optional[Value] = None) -> None
Set the field condition of an immobile domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain_id
|
int
|
ID of an immobile domain (see |
required |
kind
|
str or None
|
'Material' (the domain is part of the problem with its own
|
required |
value
|
float or callable
|
Surface value or flux, a number or a function of the time |
0.0
|
coefficient
|
float or callable
|
Transfer coefficient of 'Robin' or emissivity times the Stefan-Boltzmann
constant of 'Radiation', given like |
None
|
capacity
|
float or callable
|
Properties of a 'Material' domain, numbers or functions of the field
|
None
|
conductivity
|
float or callable
|
Properties of a 'Material' domain, numbers or functions of the field
|
None
|
source
|
float or callable
|
Volumetric source in a 'Material' domain, a number or a function |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the domain is unknown or mobile, or the kind is not recognized. |
set_preconditioner ¶
Set the preconditioner of the conjugate gradient iterations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preconditioner
|
str
|
'Multigrid' or 'Jacobi'. The case is ignored. |
required |
set_source ¶
Set the volumetric source Q.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
(float, ndarray or callable)
|
A number, an array of shape |
required |
set_time_scheme ¶
Set the time integration scheme.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_scheme
|
str
|
'Implicit', 'Crank-Nicolson', 'Explicit' or 'Steady'. The case is ignored. |
required |
set_value ¶
Set the field values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
(float, ndarray or callable)
|
A number, an array of shape |
required |