Skip to content

Special Linear Scenarios in physical Mode¤

apebench.scenarios.physical.UnbalancedAdvection ¤

Bases: BaseScenario

Source code in apebench/scenarios/physical/_special_linear.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class UnbalancedAdvection(BaseScenario):
    domain_extent: float = 1.0
    dt: float = 0.1

    advection_coef_vector: tuple[float, ...] = (
        0.01,
        -0.04,
        0.005,
    )  # Needs to be as long as num_spatial_dims

    coarse_proportion: float = 0.5

    def __post_init__(self):
        if self.num_spatial_dims == 1:
            raise ValueError("Unbalanced advection is only supported for 2D and 3D")
        if len(self.advection_coef_vector) != self.num_spatial_dims:
            raise ValueError(
                "Advection coefficient vector needs to be as long as the number of spatial dimensions"
            )

    def get_ref_stepper(self) -> ex.BaseStepper:
        return ex.stepper.Advection(
            num_spatial_dims=self.num_spatial_dims,
            domain_extent=self.domain_extent,
            num_points=self.num_points,
            dt=self.dt,
            velocity=jnp.array(self.advection_coef_vector),
        )

    def get_coarse_stepper(self) -> ex.BaseStepper:
        return ex.stepper.Advection(
            num_spatial_dims=self.num_spatial_dims,
            domain_extent=self.domain_extent,
            num_points=self.num_points,
            dt=self.dt * self.coarse_proportion,
            velocity=jnp.array(self.advection_coef_vector),
        )

    def get_scenario_name(self) -> str:
        return f"{self.num_spatial_dims}d_phy_unbal_adv"
domain_extent class-attribute instance-attribute ¤
domain_extent: float = 1.0
dt class-attribute instance-attribute ¤
dt: float = 0.1
advection_coef_vector class-attribute instance-attribute ¤
advection_coef_vector: tuple[float, ...] = (
    0.01,
    -0.04,
    0.005,
)
coarse_proportion class-attribute instance-attribute ¤
coarse_proportion: float = 0.5
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/physical/_special_linear.py
48
49
def get_scenario_name(self) -> str:
    return f"{self.num_spatial_dims}d_phy_unbal_adv"
__post_init__ ¤
__post_init__()
Source code in apebench/scenarios/physical/_special_linear.py
22
23
24
25
26
27
28
def __post_init__(self):
    if self.num_spatial_dims == 1:
        raise ValueError("Unbalanced advection is only supported for 2D and 3D")
    if len(self.advection_coef_vector) != self.num_spatial_dims:
        raise ValueError(
            "Advection coefficient vector needs to be as long as the number of spatial dimensions"
        )

apebench.scenarios.physical.DiagonalDiffusion ¤

Bases: BaseScenario

Source code in apebench/scenarios/physical/_special_linear.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
class DiagonalDiffusion(BaseScenario):
    domain_extent: float = 1.0
    dt: float = 0.1

    diffusion_coef_vector: tuple[float, ...] = (
        0.001,
        0.002,
    )  # Needs to be as long as num_spatial_dims

    coarse_proportion: float = 0.5

    def __post_init__(self):
        if self.num_spatial_dims == 1:
            raise ValueError("Diagonal diffusion is only supported for 2D and 3D")
        if len(self.diffusion_coef_vector) != self.num_spatial_dims:
            raise ValueError(
                "Diffusion coefficient vector needs to be as long as the number of spatial dimensions"
            )

    def get_ref_stepper(self) -> ex.BaseStepper:
        return ex.stepper.Diffusion(
            num_spatial_dims=self.num_spatial_dims,
            domain_extent=self.domain_extent,
            num_points=self.num_points,
            dt=self.dt,
            diffusivity=jnp.array(self.diffusion_coef_vector),
        )

    def get_coarse_stepper(self) -> ex.BaseStepper:
        return ex.stepper.Diffusion(
            num_spatial_dims=self.num_spatial_dims,
            domain_extent=self.domain_extent,
            num_points=self.num_points,
            dt=self.dt * self.coarse_proportion,
            diffusivity=jnp.array(self.diffusion_coef_vector),
        )

    def get_scenario_name(self) -> str:
        return f"{self.num_spatial_dims}d_phy_diag_diff"
domain_extent class-attribute instance-attribute ¤
domain_extent: float = 1.0
dt class-attribute instance-attribute ¤
dt: float = 0.1
diffusion_coef_vector class-attribute instance-attribute ¤
diffusion_coef_vector: tuple[float, ...] = (0.001, 0.002)
coarse_proportion class-attribute instance-attribute ¤
coarse_proportion: float = 0.5
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/physical/_special_linear.py
89
90
def get_scenario_name(self) -> str:
    return f"{self.num_spatial_dims}d_phy_diag_diff"
__post_init__ ¤
__post_init__()
Source code in apebench/scenarios/physical/_special_linear.py
63
64
65
66
67
68
69
def __post_init__(self):
    if self.num_spatial_dims == 1:
        raise ValueError("Diagonal diffusion is only supported for 2D and 3D")
    if len(self.diffusion_coef_vector) != self.num_spatial_dims:
        raise ValueError(
            "Diffusion coefficient vector needs to be as long as the number of spatial dimensions"
        )

apebench.scenarios.physical.AnisotropicDiffusion ¤

Bases: BaseScenario

Source code in apebench/scenarios/physical/_special_linear.py
 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
class AnisotropicDiffusion(BaseScenario):
    domain_extent: float = 1.0
    dt: float = 0.1

    diffusion_coef_matrix: tuple[tuple[float, ...], ...] = (
        (0.001, 0.0005),
        (0.0005, 0.002),
    )
    """
    Needs to be a square matrix with the same size as the number of spatial
    dimensions, given as a tuple of tuples.

    Also has to be symmetric and positive definite.
    """

    coarse_proportion: float = 0.5

    def __post_init__(self):
        if self.num_spatial_dims == 1:
            raise ValueError("Anisotropic diffusion is only supported for 2D and 3D")
        if len(self.diffusion_coef_matrix) != self.num_spatial_dims:
            raise ValueError(
                "Diffusion coefficient matrix needs to be as long as the number of spatial dimensions"
            )
        for row in self.diffusion_coef_matrix:
            if len(row) != self.num_spatial_dims:
                raise ValueError("Diffusion coefficient matrix needs to be square")

        # No check for SPD for now

    def get_ref_stepper(self) -> ex.BaseStepper:
        return ex.stepper.Diffusion(
            num_spatial_dims=self.num_spatial_dims,
            domain_extent=self.domain_extent,
            num_points=self.num_points,
            dt=self.dt,
            diffusivity=jnp.array(self.diffusion_coef_matrix),
        )

    def get_coarse_stepper(self) -> ex.BaseStepper:
        return ex.stepper.Diffusion(
            num_spatial_dims=self.num_spatial_dims,
            domain_extent=self.domain_extent,
            num_points=self.num_points,
            dt=self.dt * self.coarse_proportion,
            diffusivity=jnp.array(self.diffusion_coef_matrix),
        )

    def get_scenario_name(self) -> str:
        return f"{self.num_spatial_dims}d_phy_aniso_diff"
domain_extent class-attribute instance-attribute ¤
domain_extent: float = 1.0
dt class-attribute instance-attribute ¤
dt: float = 0.1
diffusion_coef_matrix class-attribute instance-attribute ¤
diffusion_coef_matrix: tuple[tuple[float, ...], ...] = (
    (0.001, 0.0005),
    (0.0005, 0.002),
)

Needs to be a square matrix with the same size as the number of spatial dimensions, given as a tuple of tuples.

Also has to be symmetric and positive definite.

coarse_proportion class-attribute instance-attribute ¤
coarse_proportion: float = 0.5
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/physical/_special_linear.py
141
142
def get_scenario_name(self) -> str:
    return f"{self.num_spatial_dims}d_phy_aniso_diff"
__post_init__ ¤
__post_init__()
Source code in apebench/scenarios/physical/_special_linear.py
110
111
112
113
114
115
116
117
118
119
def __post_init__(self):
    if self.num_spatial_dims == 1:
        raise ValueError("Anisotropic diffusion is only supported for 2D and 3D")
    if len(self.diffusion_coef_matrix) != self.num_spatial_dims:
        raise ValueError(
            "Diffusion coefficient matrix needs to be as long as the number of spatial dimensions"
        )
    for row in self.diffusion_coef_matrix:
        if len(row) != self.num_spatial_dims:
            raise ValueError("Diffusion coefficient matrix needs to be square")

apebench.scenarios.physical.SpatiallyMixedDispersion ¤

Bases: BaseScenario

Source code in apebench/scenarios/physical/_special_linear.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
class SpatiallyMixedDispersion(BaseScenario):
    domain_extent: float = 1.0
    dt: float = 0.001
    dispersion_coef: float = 0.00025

    coarse_proportion: float = 0.5

    def __post_init__(self):
        if self.num_spatial_dims == 1:
            raise ValueError(
                "Spatially mixed dispersion is only supported for 2D and 3D"
            )

    def get_ref_stepper(self) -> ex.BaseStepper:
        return ex.stepper.Dispersion(
            num_spatial_dims=self.num_spatial_dims,
            domain_extent=self.domain_extent,
            num_points=self.num_points,
            dt=self.dt,
            dispersivity=self.dispersion_coef,
            advect_on_diffusion=True,
        )

    def get_coarse_stepper(self) -> ex.BaseStepper:
        return ex.stepper.Dispersion(
            num_spatial_dims=self.num_spatial_dims,
            domain_extent=self.domain_extent,
            num_points=self.num_points,
            dt=self.dt * self.coarse_proportion,
            dispersivity=self.dispersion_coef,
            advect_on_diffusion=True,
        )

    def get_scenario_name(self) -> str:
        return f"{self.num_spatial_dims}d_phy_mix_disp"
domain_extent class-attribute instance-attribute ¤
domain_extent: float = 1.0
dt class-attribute instance-attribute ¤
dt: float = 0.001
dispersion_coef class-attribute instance-attribute ¤
dispersion_coef: float = 0.00025
coarse_proportion class-attribute instance-attribute ¤
coarse_proportion: float = 0.5
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/physical/_special_linear.py
178
179
def get_scenario_name(self) -> str:
    return f"{self.num_spatial_dims}d_phy_mix_disp"
__post_init__ ¤
__post_init__()
Source code in apebench/scenarios/physical/_special_linear.py
152
153
154
155
156
def __post_init__(self):
    if self.num_spatial_dims == 1:
        raise ValueError(
            "Spatially mixed dispersion is only supported for 2D and 3D"
        )

apebench.scenarios.physical.SpatiallyMixedHyperDiffusion ¤

Bases: BaseScenario

Source code in apebench/scenarios/physical/_special_linear.py
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
class SpatiallyMixedHyperDiffusion(BaseScenario):
    domain_extent: float = 1.0
    dt: float = 0.00001
    hyp_diffusion_coef: float = -0.000075

    coarse_proportion: float = 0.5

    def __post_init__(self):
        if self.num_spatial_dims == 1:
            raise ValueError(
                "Spatially mixed hyperdiffusion is only supported for 2D and 3D"
            )

    def get_ref_stepper(self) -> ex.BaseStepper:
        return ex.stepper.HyperDiffusion(
            num_spatial_dims=self.num_spatial_dims,
            domain_extent=self.domain_extent,
            num_points=self.num_points,
            dt=self.dt,
            # Need minus to match the sign of the diffusion coefficient
            hyper_diffusivity=-self.hyp_diffusion_coef,
            diffuse_on_diffuse=True,
        )

    def get_coarse_stepper(self) -> ex.BaseStepper:
        return ex.stepper.HyperDiffusion(
            num_spatial_dims=self.num_spatial_dims,
            domain_extent=self.domain_extent,
            num_points=self.num_points,
            dt=self.dt * self.coarse_proportion,
            # Need minus to match the sign of the diffusion coefficient
            hyper_diffusivity=-self.hyp_diffusion_coef,
            diffuse_on_diffuse=True,
        )

    def get_scenario_name(self) -> str:
        return f"{self.num_spatial_dims}d_phy_mix_hyp"
domain_extent class-attribute instance-attribute ¤
domain_extent: float = 1.0
dt class-attribute instance-attribute ¤
dt: float = 1e-05
hyp_diffusion_coef class-attribute instance-attribute ¤
hyp_diffusion_coef: float = -7.5e-05
coarse_proportion class-attribute instance-attribute ¤
coarse_proportion: float = 0.5
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/physical/_special_linear.py
217
218
def get_scenario_name(self) -> str:
    return f"{self.num_spatial_dims}d_phy_mix_hyp"
__post_init__ ¤
__post_init__()
Source code in apebench/scenarios/physical/_special_linear.py
189
190
191
192
193
def __post_init__(self):
    if self.num_spatial_dims == 1:
        raise ValueError(
            "Spatially mixed hyperdiffusion is only supported for 2D and 3D"
        )