Skip to content

Conversion Utilties for Normalized and Difficulty Steppers¤

exponax.normalized.normalize_coefficients ¤

normalize_coefficients(
    coefficients: tuple[float, ...],
    *,
    domain_extent: float,
    dt: float
) -> tuple[float, ...]

Normalize the coefficients to a linear time stepper to be used with the normalized linear stepper.

Arguments: - coefficients: coefficients for the linear operator, coefficients[i] is the coefficient for the i-th derivative - domain_extent: extent of the domain - dt: time step

Source code in exponax/normalized/_utils.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def normalize_coefficients(
    coefficients: tuple[float, ...],
    *,
    domain_extent: float,
    dt: float,
) -> tuple[float, ...]:
    """
    Normalize the coefficients to a linear time stepper to be used with the
    normalized linear stepper.

    **Arguments:**
    - `coefficients`: coefficients for the linear operator, `coefficients[i]` is
        the coefficient for the `i`-th derivative
    - `domain_extent`: extent of the domain
    - `dt`: time step
    """
    normalized_coefficients = tuple(
        c * dt / (domain_extent**i) for i, c in enumerate(coefficients)
    )
    return normalized_coefficients

exponax.normalized.denormalize_coefficients ¤

denormalize_coefficients(
    normalized_coefficients: tuple[float, ...],
    *,
    domain_extent: float,
    dt: float
) -> tuple[float, ...]

Denormalize the coefficients as they were used in the normalized linear to then be used again in a regular linear stepper.

Arguments: - normalized_coefficients: coefficients for the linear operator, normalized_coefficients[i] is the coefficient for the i-th derivative - domain_extent: extent of the domain - dt: time step

Source code in exponax/normalized/_utils.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def denormalize_coefficients(
    normalized_coefficients: tuple[float, ...],
    *,
    domain_extent: float,
    dt: float,
) -> tuple[float, ...]:
    """
    Denormalize the coefficients as they were used in the normalized linear to
    then be used again in a regular linear stepper.

    **Arguments:**
    - `normalized_coefficients`: coefficients for the linear operator,
        `normalized_coefficients[i]` is the coefficient for the `i`-th
        derivative
    - `domain_extent`: extent of the domain
    - `dt`: time step
    """
    coefficients = tuple(
        c_n / dt * domain_extent**i for i, c_n in enumerate(normalized_coefficients)
    )
    return coefficients

exponax.normalized.normalize_convection_scale ¤

normalize_convection_scale(
    convection_scale: float,
    *,
    domain_extent: float,
    dt: float
) -> float
Source code in exponax/normalized/_utils.py
49
50
51
52
53
54
55
56
def normalize_convection_scale(
    convection_scale: float,
    *,
    domain_extent: float,
    dt: float,
) -> float:
    normalized_convection_scale = convection_scale * dt / domain_extent
    return normalized_convection_scale

exponax.normalized.denormalize_convection_scale ¤

denormalize_convection_scale(
    normalized_convection_scale: float,
    *,
    domain_extent: float,
    dt: float
) -> float
Source code in exponax/normalized/_utils.py
59
60
61
62
63
64
65
66
def denormalize_convection_scale(
    normalized_convection_scale: float,
    *,
    domain_extent: float,
    dt: float,
) -> float:
    convection_scale = normalized_convection_scale / dt * domain_extent
    return convection_scale

exponax.normalized.normalize_gradient_norm_scale ¤

normalize_gradient_norm_scale(
    gradient_norm_scale: float,
    *,
    domain_extent: float,
    dt: float
)
Source code in exponax/normalized/_utils.py
69
70
71
72
73
74
75
76
77
78
def normalize_gradient_norm_scale(
    gradient_norm_scale: float,
    *,
    domain_extent: float,
    dt: float,
):
    normalized_gradient_norm_scale = (
        gradient_norm_scale * dt / jnp.square(domain_extent)
    )
    return normalized_gradient_norm_scale

exponax.normalized.denormalize_gradient_norm_scale ¤

denormalize_gradient_norm_scale(
    normalized_gradient_norm_scale: float,
    *,
    domain_extent: float,
    dt: float
)
Source code in exponax/normalized/_utils.py
81
82
83
84
85
86
87
88
89
90
def denormalize_gradient_norm_scale(
    normalized_gradient_norm_scale: float,
    *,
    domain_extent: float,
    dt: float,
):
    gradient_norm_scale = (
        normalized_gradient_norm_scale / dt * jnp.square(domain_extent)
    )
    return gradient_norm_scale

exponax.normalized.normalize_polynomial_scales ¤

normalize_polynomial_scales(
    polynomial_scales: tuple[float],
    *,
    domain_extent: float = None,
    dt: float
) -> tuple[float]

Normalize the polynomial scales to be used with the normalized polynomial stepper.

Arguments: - polynomial_scales: scales for the polynomial operator, polynomial_scales[i] is the scale for the i-th derivative - domain_extent: extent of the domain (not needed, kept for compatibility with other normalization APIs) - dt: time step

Source code in exponax/normalized/_utils.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
def normalize_polynomial_scales(
    polynomial_scales: tuple[float],
    *,
    domain_extent: float = None,
    dt: float,
) -> tuple[float]:
    """
    Normalize the polynomial scales to be used with the normalized polynomial
    stepper.

    **Arguments:**
        - `polynomial_scales`: scales for the polynomial operator,
            `polynomial_scales[i]` is the scale for the `i`-th derivative
        - `domain_extent`: extent of the domain (not needed, kept for
            compatibility with other normalization APIs)
        - `dt`: time step
    """
    normalized_polynomial_scales = tuple(c * dt for c in polynomial_scales)
    return normalized_polynomial_scales

exponax.normalized.denormalize_polynomial_scales ¤

denormalize_polynomial_scales(
    normalized_polynomial_scales: tuple[float, ...],
    *,
    domain_extent: float = None,
    dt: float
) -> tuple[float, ...]

Denormalize the polynomial scales as they were used in the normalized polynomial to then be used again in a regular polynomial stepper.

Arguments: - normalized_polynomial_scales: scales for the polynomial operator, normalized_polynomial_scales[i] is the scale for the i-th derivative - domain_extent: extent of the domain (not needed, kept for compatibility with other normalization APIs) - dt: time step

Source code in exponax/normalized/_utils.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
def denormalize_polynomial_scales(
    normalized_polynomial_scales: tuple[float, ...],
    *,
    domain_extent: float = None,
    dt: float,
) -> tuple[float, ...]:
    """
    Denormalize the polynomial scales as they were used in the normalized
    polynomial to then be used again in a regular polynomial stepper.

    **Arguments:**
        - `normalized_polynomial_scales`: scales for the polynomial operator,
            `normalized_polynomial_scales[i]` is the scale for the `i`-th
            derivative
        - `domain_extent`: extent of the domain (not needed, kept for
            compatibility with other normalization APIs)
        - `dt`: time step
    """
    polynomial_scales = tuple(c_n / dt for c_n in normalized_polynomial_scales)
    return polynomial_scales

exponax.normalized.reduce_normalized_coefficients_to_difficulty ¤

reduce_normalized_coefficients_to_difficulty(
    normalized_coefficients: tuple[float, ...],
    *,
    num_spatial_dims: int,
    num_points: int
)
Source code in exponax/normalized/_utils.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
def reduce_normalized_coefficients_to_difficulty(
    normalized_coefficients: tuple[float, ...],
    *,
    num_spatial_dims: int,
    num_points: int,
):
    difficulty_coefficients = list(
        alpha * num_points**j * 2 ** (j - 1) * num_spatial_dims
        for j, alpha in enumerate(normalized_coefficients)
    )
    difficulty_coefficients[0] = normalized_coefficients[0]

    difficulty_coefficients = tuple(difficulty_coefficients)
    return difficulty_coefficients

exponax.normalized.extract_normalized_coefficients_from_difficulty ¤

extract_normalized_coefficients_from_difficulty(
    difficulty_coefficients: tuple[float, ...],
    *,
    num_spatial_dims: int,
    num_points: int
)
Source code in exponax/normalized/_utils.py
152
153
154
155
156
157
158
159
160
161
162
163
164
165
def extract_normalized_coefficients_from_difficulty(
    difficulty_coefficients: tuple[float, ...],
    *,
    num_spatial_dims: int,
    num_points: int,
):
    normalized_coefficients = list(
        gamma / (num_points**j * 2 ** (j - 1) * num_spatial_dims)
        for j, gamma in enumerate(difficulty_coefficients)
    )
    normalized_coefficients[0] = difficulty_coefficients[0]

    normalized_coefficients = tuple(normalized_coefficients)
    return normalized_coefficients

exponax.normalized.reduce_normalized_convection_scale_to_difficulty ¤

reduce_normalized_convection_scale_to_difficulty(
    normalized_convection_scale: float,
    *,
    num_spatial_dims: int,
    num_points: int,
    maximum_absolute: float
)
Source code in exponax/normalized/_utils.py
168
169
170
171
172
173
174
175
176
177
178
def reduce_normalized_convection_scale_to_difficulty(
    normalized_convection_scale: float,
    *,
    num_spatial_dims: int,
    num_points: int,
    maximum_absolute: float,
):
    difficulty_convection_scale = (
        normalized_convection_scale * maximum_absolute * num_points * num_spatial_dims
    )
    return difficulty_convection_scale

exponax.normalized.extract_normalized_convection_scale_from_difficulty ¤

extract_normalized_convection_scale_from_difficulty(
    difficulty_convection_scale: float,
    *,
    num_spatial_dims: int,
    num_points: int,
    maximum_absolute: float
)
Source code in exponax/normalized/_utils.py
181
182
183
184
185
186
187
188
189
190
191
def extract_normalized_convection_scale_from_difficulty(
    difficulty_convection_scale: float,
    *,
    num_spatial_dims: int,
    num_points: int,
    maximum_absolute: float,
):
    normalized_convection_scale = difficulty_convection_scale / (
        maximum_absolute * num_points * num_spatial_dims
    )
    return normalized_convection_scale

exponax.normalized.reduce_normalized_gradient_norm_scale_to_difficulty ¤

reduce_normalized_gradient_norm_scale_to_difficulty(
    normalized_gradient_norm_scale: float,
    *,
    num_spatial_dims: int,
    num_points: int,
    maximum_absolute: float
)
Source code in exponax/normalized/_utils.py
194
195
196
197
198
199
200
201
202
203
204
205
206
207
def reduce_normalized_gradient_norm_scale_to_difficulty(
    normalized_gradient_norm_scale: float,
    *,
    num_spatial_dims: int,
    num_points: int,
    maximum_absolute: float,
):
    difficulty_gradient_norm_scale = (
        normalized_gradient_norm_scale
        * maximum_absolute
        * jnp.square(num_points)
        * num_spatial_dims
    )
    return difficulty_gradient_norm_scale

exponax.normalized.extract_normalized_gradient_norm_scale_from_difficulty ¤

extract_normalized_gradient_norm_scale_from_difficulty(
    difficulty_gradient_norm_scale: float,
    *,
    num_spatial_dims: int,
    num_points: int,
    maximum_absolute: float
)
Source code in exponax/normalized/_utils.py
210
211
212
213
214
215
216
217
218
219
220
def extract_normalized_gradient_norm_scale_from_difficulty(
    difficulty_gradient_norm_scale: float,
    *,
    num_spatial_dims: int,
    num_points: int,
    maximum_absolute: float,
):
    normalized_gradient_norm_scale = difficulty_gradient_norm_scale / (
        maximum_absolute * jnp.square(num_points) * num_spatial_dims
    )
    return normalized_gradient_norm_scale