Skip to content

discretization

Continuous

Bases: Field

A continuous discretization. This discretization assumes that the field is a function of the parameters contained in Continuous.params and a point in the domain. The function that computes the field from the parameters and the point in the domain is contained in Continuous.get_fun. This function has the signature get_fun(params, x), where params is the parameter vector and x is the point in the domain.

is_complex property

Checks if a field is complex.

Returns:

Name Type Description
bool bool

Whether the field is complex.

on_grid property

Returns the field on the grid points of the domain.

__call__(x)

An object of this class can be called as a function, returning the field at a desired point.

Example

...
a = Continuous.from_function(init_params, domain, get_field)
field_at_x = a(1.0)

from_function(domain, init_fun, get_field, seed) classmethod

Creates a continuous discretization from an init_fun function.

Parameters:

Name Type Description Default
domain Domain

The domain of the discretization.

required
init_fun Callable

A function that initializes the parameters of the discretization. The signature of this function is init_fun(rng, domain).

required
get_field Callable

A function that takes a parameter vector and a point in the domain and returns the field at that point. The signature of this function is get_field(params, x).

required
seed int

The seed for the random number generator.

required

Returns:

Name Type Description
Continuous

A continuous discretization.

replace_params(new_params)

Replaces the parameters of the discretization with new ones. The domain and get_field function are not changed.

Parameters:

Name Type Description Default
new_params PyTree

The new parameters of the discretization.

required

Returns:

Name Type Description
Continuous Continuous

A continuous discretization with the new parameters.

update_fun_and_params(params, get_field)

Updates the parameters and the function of the discretization.

Parameters:

Name Type Description Default
params PyTree

The new parameters of the discretization.

required
get_field Callable

A function that takes a parameter vector and a point in the domain and returns the field at that point. The signature of this function is get_field(params, x).

required

Returns:

Name Type Description
Continuous Continuous

A continuous discretization with the new parameters and function.

FiniteDifferences

Bases: OnGrid

A Finite Differences field defined on a collocation grid.

replace_params(new_params)

Replaces the parameters of the discretization with new ones, preserving the accuracy setting.

Parameters:

Name Type Description Default
new_params PyTree

The new parameters of the discretization.

required

Returns:

Name Type Description
FiniteDifferences

A new field with the new parameters.

FourierSeries

Bases: OnGrid

A Fourier series field defined on a collocation grid.

__call__(x)

Uses the Fourier shift theorem to compute the value of the field at an arbitrary point. Requires N*2 one dimensional FFTs.

Parameters:

Name Type Description Default
x float

The point at which to evaluate the field.

required

Returns:

Type Description

float, jnp.ndarray: The value of the field at the point.

Linear

Bases: Field

This discretization assumes that the field is a linear function of the parameters contained in Linear.params.

is_complex property

Checks if a field is complex.

Returns:

Name Type Description
bool bool

Whether the field is complex.

OnGrid

Bases: Linear

on_grid property

The field on the grid points of the domain.

__getitem__(idx)

Allow indexing when leading batch / time dimensions are present in the parameters

Example

...
domain = Domain((16, (1.0,))

# 10 fields
params = random.uniform(key, (10, 16, 1))
a = OnGrid(params, domain)

# Field at the 5th index
field = a[5]

Returns:

Name Type Description
OnGrid

A linear discretization on the grid points of the domain.

Raises:

Type Description
IndexError

If the field is not indexable (single field).

add_dim()

Adds a dimension at the end of the params array.

empty(domain, dims=1) classmethod

Creates an empty OnGrid field (zero field). Equivalent to OnGrid(jnp.zeros(domain.N), domain).

from_grid(grid_values, domain) classmethod

Creates an OnGrid field from a grid of values.

Parameters:

Name Type Description Default
grid_values ndarray

The grid of values.

required
domain Domain

The domain of the discretization.

required

replace_params(new_params)

Replaces the parameters of the discretization with new ones. The domain is not changed.

Parameters:

Name Type Description Default
new_params PyTree

The new parameters of the discretization.

required

Returns:

Name Type Description
OnGrid

A linear discretization with the new parameters.