Skip to content

Gaussian Blob¤

exponax.ic.RandomGaussianBlobs ¤

Bases: BaseRandomICGenerator

Source code in exponax/ic/_gaussian_blob.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
class RandomGaussianBlobs(BaseRandomICGenerator):
    num_spatial_dims: int
    domain_extent: float
    num_blobs: int

    position_range: tuple[float, float]
    variance_range: tuple[float, float]

    one_complement: bool

    def __init__(
        self,
        num_spatial_dims: int,
        *,
        domain_extent: float = 1.0,
        num_blobs: int = 1,
        position_range: tuple[float, float] = (0.4, 0.6),
        variance_range: tuple[float, float] = (0.005, 0.01),
        one_complement: bool = False,
    ):
        """
        A random Gaussian blob initial condition generator.

        **Arguments**:
            - `num_spatial_dims`: The number of spatial dimensions.
            - `domain_extent`: The extent of the domain.
            - `num_blobs`: The number of blobs.
            - `position_range`: The range of the position of the blobs. This
                will be scaled by the domain extent. Hence, this acts as if the
                domain_extent was 1
            - `variance_range`: The range of the variance of the blobs. This will
                be scaled by the domain extent. Hence, this acts as if the
                domain_extent was 1
            - `one_complement`: Whether to return one minus the Gaussian blob.
        """
        self.num_spatial_dims = num_spatial_dims
        self.domain_extent = domain_extent
        self.num_blobs = num_blobs
        self.position_range = position_range
        self.variance_range = variance_range
        self.one_complement = one_complement

    def gen_blob(self, *, key) -> GaussianBlob:
        position_key, variance_key = jr.split(key)

        position = jr.uniform(
            position_key,
            shape=(self.num_spatial_dims,),
            minval=self.position_range[0] * self.domain_extent,
            maxval=self.position_range[1] * self.domain_extent,
        )
        variances = jr.uniform(
            variance_key,
            shape=(self.num_spatial_dims,),
            minval=self.variance_range[0] * self.domain_extent,
            maxval=self.variance_range[1] * self.domain_extent,
        )
        covariance = jnp.diag(variances)

        return GaussianBlob(position, covariance, one_complement=self.one_complement)

    def gen_ic_fun(self, *, key: PRNGKeyArray) -> GaussianBlobs:
        blob_list = []
        for _ in range(self.num_blobs):
            key, subkey = jr.split(key)
            blob_list.append(self.gen_blob(key=subkey))
        return GaussianBlobs(tuple(blob_list))
__init__ ¤
__init__(
    num_spatial_dims: int,
    *,
    domain_extent: float = 1.0,
    num_blobs: int = 1,
    position_range: tuple[float, float] = (0.4, 0.6),
    variance_range: tuple[float, float] = (0.005, 0.01),
    one_complement: bool = False
)

A random Gaussian blob initial condition generator.

Arguments: - num_spatial_dims: The number of spatial dimensions. - domain_extent: The extent of the domain. - num_blobs: The number of blobs. - position_range: The range of the position of the blobs. This will be scaled by the domain extent. Hence, this acts as if the domain_extent was 1 - variance_range: The range of the variance of the blobs. This will be scaled by the domain extent. Hence, this acts as if the domain_extent was 1 - one_complement: Whether to return one minus the Gaussian blob.

Source code in exponax/ic/_gaussian_blob.py
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def __init__(
    self,
    num_spatial_dims: int,
    *,
    domain_extent: float = 1.0,
    num_blobs: int = 1,
    position_range: tuple[float, float] = (0.4, 0.6),
    variance_range: tuple[float, float] = (0.005, 0.01),
    one_complement: bool = False,
):
    """
    A random Gaussian blob initial condition generator.

    **Arguments**:
        - `num_spatial_dims`: The number of spatial dimensions.
        - `domain_extent`: The extent of the domain.
        - `num_blobs`: The number of blobs.
        - `position_range`: The range of the position of the blobs. This
            will be scaled by the domain extent. Hence, this acts as if the
            domain_extent was 1
        - `variance_range`: The range of the variance of the blobs. This will
            be scaled by the domain extent. Hence, this acts as if the
            domain_extent was 1
        - `one_complement`: Whether to return one minus the Gaussian blob.
    """
    self.num_spatial_dims = num_spatial_dims
    self.domain_extent = domain_extent
    self.num_blobs = num_blobs
    self.position_range = position_range
    self.variance_range = variance_range
    self.one_complement = one_complement
__call__ ¤
__call__(
    num_points: int, *, key: PRNGKeyArray
) -> Float[Array, "1 ... N"]

Generate a random initial condition.

Arguments: - num_points: The number of grid points in each dimension. - key: A jax random key. - indexing: The indexing convention for the grid.

Returns: - u: The initial condition evaluated at the grid points.

Source code in exponax/ic/_base_ic.py
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
def __call__(
    self,
    num_points: int,
    *,
    key: PRNGKeyArray,
) -> Float[Array, "1 ... N"]:
    """
    Generate a random initial condition.

    **Arguments**:
        - `num_points`: The number of grid points in each dimension.
        - `key`: A jax random key.
        - `indexing`: The indexing convention for the grid.

    **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.GaussianBlobs ¤

Bases: BaseIC

Source code in exponax/ic/_gaussian_blob.py
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
class GaussianBlobs(BaseIC):
    blob_list: tuple[GaussianBlob, ...]

    def __init__(
        self,
        blob_list: tuple[GaussianBlob, ...],
    ):
        """
        A state described by a collection of Gaussian blobs.

        **Arguments**:
            - `blob_list`: A tuple of Gaussian blobs.
        """
        self.blob_list = blob_list

    def __call__(self, x: Array) -> Array:
        summation = sum(blob(x) for blob in self.blob_list)
        return summation / len(self.blob_list)
blob_list instance-attribute ¤
blob_list: tuple[GaussianBlob, ...] = blob_list
__init__ ¤
__init__(blob_list: tuple[GaussianBlob, ...])

A state described by a collection of Gaussian blobs.

Arguments: - blob_list: A tuple of Gaussian blobs.

Source code in exponax/ic/_gaussian_blob.py
73
74
75
76
77
78
79
80
81
82
83
def __init__(
    self,
    blob_list: tuple[GaussianBlob, ...],
):
    """
    A state described by a collection of Gaussian blobs.

    **Arguments**:
        - `blob_list`: A tuple of Gaussian blobs.
    """
    self.blob_list = blob_list
__call__ ¤
__call__(x: Array) -> Array
Source code in exponax/ic/_gaussian_blob.py
85
86
87
def __call__(self, x: Array) -> Array:
    summation = sum(blob(x) for blob in self.blob_list)
    return summation / len(self.blob_list)