Skip to content

Base Initial Condition

exponax.ic.BaseRandomICGenerator ¤

Bases: Module

Source code in exponax/ic/_base_ic.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class BaseRandomICGenerator(eqx.Module):
    num_spatial_dims: int
    indexing: str = "ij"

    def gen_ic_fun(self, *, key: PRNGKeyArray) -> BaseIC:
        """
        Generate an initial condition function.

        **Arguments**:

        - `key`: A jax random key.

        **Returns**:

        - `ic`: An initial condition function that can be evaluated at
            degree of freedom locations.
        """
        raise NotImplementedError(
            "This random ic generator cannot represent its initial condition as a function. Directly evaluate it."
        )

    def __call__(
        self,
        num_points: int,
        *,
        key: PRNGKeyArray,
    ) -> Float[Array, "1 ... N"]:
        """
        Generate a random initial condition on a grid with `num_points` points.

        **Arguments**:

        - `num_points`: The number of grid points in each dimension.
        - `key`: A jax random key.

        **Returns**:

        - `u`: The initial condition evaluated at the grid points.
        """
        ic_fun = self.gen_ic_fun(key=key)
        grid = make_grid(
            self.num_spatial_dims,
            self.domain_extent,
            num_points,
            indexing=self.indexing,
        )
        return ic_fun(grid)
num_spatial_dims instance-attribute ¤
num_spatial_dims: int
indexing class-attribute instance-attribute ¤
indexing: str = 'ij'
gen_ic_fun ¤
gen_ic_fun(*, key: PRNGKeyArray) -> BaseIC

Generate an initial condition function.

Arguments:

  • key: A jax random key.

Returns:

  • ic: An initial condition function that can be evaluated at degree of freedom locations.
Source code in exponax/ic/_base_ic.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def gen_ic_fun(self, *, key: PRNGKeyArray) -> BaseIC:
    """
    Generate an initial condition function.

    **Arguments**:

    - `key`: A jax random key.

    **Returns**:

    - `ic`: An initial condition function that can be evaluated at
        degree of freedom locations.
    """
    raise NotImplementedError(
        "This random ic generator cannot represent its initial condition as a function. Directly evaluate it."
    )
__call__ ¤
__call__(
    num_points: int, *, key: PRNGKeyArray
) -> Float[Array, "1 ... N"]

Generate a random initial condition on a grid with num_points points.

Arguments:

  • num_points: The number of grid points in each dimension.
  • key: A jax random key.

Returns:

  • u: The initial condition evaluated at the grid points.
Source code in exponax/ic/_base_ic.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def __call__(
    self,
    num_points: int,
    *,
    key: PRNGKeyArray,
) -> Float[Array, "1 ... N"]:
    """
    Generate a random initial condition on a grid with `num_points` points.

    **Arguments**:

    - `num_points`: The number of grid points in each dimension.
    - `key`: A jax random key.

    **Returns**:

    - `u`: The initial condition evaluated at the grid points.
    """
    ic_fun = self.gen_ic_fun(key=key)
    grid = make_grid(
        self.num_spatial_dims,
        self.domain_extent,
        num_points,
        indexing=self.indexing,
    )
    return ic_fun(grid)

exponax.ic.BaseIC ¤

Bases: Module, ABC

Source code in exponax/ic/_base_ic.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class BaseIC(eqx.Module, ABC):
    @abstractmethod
    def __call__(self, x: Float[Array, "D ... N"]) -> Float[Array, "1 ... N"]:
        """
        Evaluate the initial condition.

        **Arguments**:

        - `x`: The grid points.

        **Returns**:

        - `u`: The initial condition evaluated at the grid points.
        """
        pass
__call__ abstractmethod ¤
__call__(
    x: Float[Array, "D ... N"]
) -> Float[Array, "1 ... N"]

Evaluate the initial condition.

Arguments:

  • x: The grid points.

Returns:

  • u: The initial condition evaluated at the grid points.
Source code in exponax/ic/_base_ic.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@abstractmethod
def __call__(self, x: Float[Array, "D ... N"]) -> Float[Array, "1 ... N"]:
    """
    Evaluate the initial condition.

    **Arguments**:

    - `x`: The grid points.

    **Returns**:

    - `u`: The initial condition evaluated at the grid points.
    """
    pass