Skip to content

Generic Scenarios in physical Mode¤

apebench.scenarios.physical.Linear ¤

Bases: BaseScenario

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

    a_coefs: tuple[float, ...] = (0.0, -0.25, 0.0, 0.0, 0.0)
    coarse_proportion: float = 0.5

    def get_ref_stepper(self):
        return ex.stepper.generic.GeneralLinearStepper(
            num_spatial_dims=self.num_spatial_dims,
            domain_extent=self.domain_extent,
            num_points=self.num_points,
            dt=self.dt,
            linear_coefficients=self.a_coefs,
        )

    def get_coarse_stepper(self) -> ex.BaseStepper:
        return ex.stepper.generic.GeneralLinearStepper(
            num_spatial_dims=self.num_spatial_dims,
            domain_extent=self.domain_extent,
            num_points=self.num_points,
            dt=self.dt * self.coarse_proportion,
            linear_coefficients=self.a_coefs,
        )

    def get_scenario_name(self) -> str:
        active_indices = []
        for i, a in enumerate(self.a_coefs):
            if a != 0.0:
                active_indices.append(i)
        return f"{self.num_spatial_dims}d_phy_lin_{'_'.join(str(i) for i in active_indices)}"
a_coefs class-attribute instance-attribute ¤
a_coefs: tuple[float, ...] = (0.0, -0.25, 0.0, 0.0, 0.0)
coarse_proportion class-attribute instance-attribute ¤
coarse_proportion: float = 0.5
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/physical/_linear.py
31
32
33
34
35
36
def get_scenario_name(self) -> str:
    active_indices = []
    for i, a in enumerate(self.a_coefs):
        if a != 0.0:
            active_indices.append(i)
    return f"{self.num_spatial_dims}d_phy_lin_{'_'.join(str(i) for i in active_indices)}"

apebench.scenarios.physical.LinearSimple ¤

Bases: Linear

Source code in apebench/scenarios/physical/_linear.py
39
40
41
42
43
44
class LinearSimple(Linear):
    linear_coef: float = -0.25
    linear_term_order: int = 1

    def __post_init__(self):
        self.a_coefs = (0.0,) * self.linear_term_order + (self.linear_coef,)
linear_coef class-attribute instance-attribute ¤
linear_coef: float = -0.25
linear_term_order class-attribute instance-attribute ¤
linear_term_order: int = 1
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/physical/_linear.py
31
32
33
34
35
36
def get_scenario_name(self) -> str:
    active_indices = []
    for i, a in enumerate(self.a_coefs):
        if a != 0.0:
            active_indices.append(i)
    return f"{self.num_spatial_dims}d_phy_lin_{'_'.join(str(i) for i in active_indices)}"

apebench.scenarios.physical.FirstFour ¤

Bases: Linear

Source code in apebench/scenarios/physical/_linear.py
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
class FirstFour(Linear):
    advection_coef: float = -2500.0
    diffusion_coef: float = 80.0
    dispersion_coef: float = 0.025
    hyp_diffusion_coef: float = -0.000075
    dt: float = 0.00001  # Overwrite

    def __post_init__(self):
        self.a_coefs = (
            0.0,
            self.advection_coef,
            self.diffusion_coef,
            self.dispersion_coef,
            self.hyp_diffusion_coef,
        )

    def get_scenario_name(self) -> str:
        return f"{self.num_spatial_dims}d_phy_four"
advection_coef class-attribute instance-attribute ¤
advection_coef: float = -2500.0
diffusion_coef class-attribute instance-attribute ¤
diffusion_coef: float = 80.0
dispersion_coef class-attribute instance-attribute ¤
dispersion_coef: float = 0.025
hyp_diffusion_coef class-attribute instance-attribute ¤
hyp_diffusion_coef: float = -7.5e-05
__post_init__ ¤
__post_init__()
Source code in apebench/scenarios/physical/_linear.py
107
108
109
110
111
112
113
114
def __post_init__(self):
    self.a_coefs = (
        0.0,
        self.advection_coef,
        self.diffusion_coef,
        self.dispersion_coef,
        self.hyp_diffusion_coef,
    )
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/physical/_linear.py
116
117
def get_scenario_name(self) -> str:
    return f"{self.num_spatial_dims}d_phy_four"

apebench.scenarios.physical.Nonlinear ¤

Bases: BaseScenario

Uses the single channel convection mode to not have channels grow with spatial dimensions.

Source code in apebench/scenarios/physical/_nonlinear.py
 6
 7
 8
 9
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
50
51
52
53
54
55
56
57
58
class Nonlinear(BaseScenario):
    """
    Uses the single channel convection mode to not have channels grow with
    spatial dimensions.
    """

    domain_extent: float = 1.0
    dt: float = 0.1

    a_coefs: tuple[float, ...] = (0.0, 0.0, 0.0003, 0.0, 0.0)
    b_coefs: tuple[float, float, float] = (0.0, -0.125, 0.0)

    num_substeps: int = 1

    coarse_proportion: float = 0.5

    order: int = 2
    dealiasing_fraction: float = 2 / 3
    num_circle_points: int = 16
    circle_radius: float = 1.0

    def __post_init__(self):
        pass

    def _build_stepper(self, dt):
        substepped_stepper = ex.stepper.generic.GeneralNonlinearStepper(
            num_spatial_dims=self.num_spatial_dims,
            domain_extent=self.domain_extent,
            num_points=self.num_points,
            dt=dt / self.num_substeps,
            linear_coefficients=self.a_coefs,
            nonlinear_coefficients=self.b_coefs,
            order=self.order,
            dealiasing_fraction=self.dealiasing_fraction,
            num_circle_points=self.num_circle_points,
            circle_radius=self.circle_radius,
        )

        if self.num_substeps == 1:
            stepper = substepped_stepper
        else:
            stepper = ex.RepeatedStepper(substepped_stepper, self.num_substeps)

        return stepper

    def get_ref_stepper(self):
        return self._build_stepper(self.dt)

    def get_coarse_stepper(self):
        return self._build_stepper(self.dt * self.coarse_proportion)

    def get_scenario_name(self) -> str:
        return f"{self.num_spatial_dims}d_phy_nonlin"
a_coefs class-attribute instance-attribute ¤
a_coefs: tuple[float, ...] = (0.0, 0.0, 0.0003, 0.0, 0.0)
b_coefs class-attribute instance-attribute ¤
b_coefs: tuple[float, float, float] = (0.0, -0.125, 0.0)
num_substeps class-attribute instance-attribute ¤
num_substeps: int = 1
coarse_proportion class-attribute instance-attribute ¤
coarse_proportion: float = 0.5
order class-attribute instance-attribute ¤
order: int = 2
dealiasing_fraction class-attribute instance-attribute ¤
dealiasing_fraction: float = 2 / 3
num_circle_points class-attribute instance-attribute ¤
num_circle_points: int = 16
circle_radius class-attribute instance-attribute ¤
circle_radius: float = 1.0
_build_stepper ¤
_build_stepper(dt)
Source code in apebench/scenarios/physical/_nonlinear.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def _build_stepper(self, dt):
    substepped_stepper = ex.stepper.generic.GeneralNonlinearStepper(
        num_spatial_dims=self.num_spatial_dims,
        domain_extent=self.domain_extent,
        num_points=self.num_points,
        dt=dt / self.num_substeps,
        linear_coefficients=self.a_coefs,
        nonlinear_coefficients=self.b_coefs,
        order=self.order,
        dealiasing_fraction=self.dealiasing_fraction,
        num_circle_points=self.num_circle_points,
        circle_radius=self.circle_radius,
    )

    if self.num_substeps == 1:
        stepper = substepped_stepper
    else:
        stepper = ex.RepeatedStepper(substepped_stepper, self.num_substeps)

    return stepper
get_ref_stepper ¤
get_ref_stepper()
Source code in apebench/scenarios/physical/_nonlinear.py
51
52
def get_ref_stepper(self):
    return self._build_stepper(self.dt)
get_coarse_stepper ¤
get_coarse_stepper()
Source code in apebench/scenarios/physical/_nonlinear.py
54
55
def get_coarse_stepper(self):
    return self._build_stepper(self.dt * self.coarse_proportion)
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/physical/_nonlinear.py
57
58
def get_scenario_name(self) -> str:
    return f"{self.num_spatial_dims}d_phy_nonlin"

apebench.scenarios.physical.Convection ¤

Bases: BaseScenario

Source code in apebench/scenarios/physical/_convection.py
 6
 7
 8
 9
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
50
51
52
53
54
55
56
57
58
59
60
class Convection(BaseScenario):
    domain_extent: float = 1.0
    dt: float = 0.1

    a_coefs: tuple[float, ...] = (0.0, 0.0, 0.0003, 0.0, 0.0)
    convection_coef: float = -0.125
    conservative: bool = True

    num_substeps: int = 1

    coarse_proportion: float = 0.5

    order: int = 2
    dealiasing_fraction: float = 2 / 3
    num_circle_points: int = 16
    circle_radius: float = 1.0

    def __post_init__(self):
        self.num_channels = self.num_spatial_dims  # Overwrite

    def _build_stepper(self, dt):
        substepped_stepper = ex.stepper.generic.GeneralConvectionStepper(
            num_spatial_dims=self.num_spatial_dims,
            domain_extent=self.domain_extent,
            num_points=self.num_points,
            dt=dt / self.num_substeps,
            linear_coefficients=self.a_coefs,
            # Need minus to move the convection to the right hand side
            convection_scale=-self.convection_coef,
            conservative=self.conservative,
            order=self.order,
            dealiasing_fraction=self.dealiasing_fraction,
            num_circle_points=self.num_circle_points,
            circle_radius=self.circle_radius,
        )

        if self.num_substeps == 1:
            stepper = substepped_stepper
        else:
            stepper = ex.RepeatedStepper(substepped_stepper, self.num_substeps)

        return stepper

    def get_ref_stepper(self):
        return self._build_stepper(self.dt)

    def get_coarse_stepper(self) -> ex.BaseStepper:
        return self._build_stepper(self.dt * self.coarse_proportion)

    def get_scenario_name(self) -> str:
        active_indices = []
        for i, a in enumerate(self.a_coefs):
            if a != 0.0:
                active_indices.append(i)
        return f"{self.num_spatial_dims}d_phy_conv_{'_'.join(str(i) for i in active_indices)}"
domain_extent class-attribute instance-attribute ¤
domain_extent: float = 1.0
dt class-attribute instance-attribute ¤
dt: float = 0.1
a_coefs class-attribute instance-attribute ¤
a_coefs: tuple[float, ...] = (0.0, 0.0, 0.0003, 0.0, 0.0)
convection_coef class-attribute instance-attribute ¤
convection_coef: float = -0.125
conservative class-attribute instance-attribute ¤
conservative: bool = True
num_substeps class-attribute instance-attribute ¤
num_substeps: int = 1
coarse_proportion class-attribute instance-attribute ¤
coarse_proportion: float = 0.5
order class-attribute instance-attribute ¤
order: int = 2
dealiasing_fraction class-attribute instance-attribute ¤
dealiasing_fraction: float = 2 / 3
num_circle_points class-attribute instance-attribute ¤
num_circle_points: int = 16
circle_radius class-attribute instance-attribute ¤
circle_radius: float = 1.0
__post_init__ ¤
__post_init__()
Source code in apebench/scenarios/physical/_convection.py
23
24
def __post_init__(self):
    self.num_channels = self.num_spatial_dims  # Overwrite
_build_stepper ¤
_build_stepper(dt)
Source code in apebench/scenarios/physical/_convection.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def _build_stepper(self, dt):
    substepped_stepper = ex.stepper.generic.GeneralConvectionStepper(
        num_spatial_dims=self.num_spatial_dims,
        domain_extent=self.domain_extent,
        num_points=self.num_points,
        dt=dt / self.num_substeps,
        linear_coefficients=self.a_coefs,
        # Need minus to move the convection to the right hand side
        convection_scale=-self.convection_coef,
        conservative=self.conservative,
        order=self.order,
        dealiasing_fraction=self.dealiasing_fraction,
        num_circle_points=self.num_circle_points,
        circle_radius=self.circle_radius,
    )

    if self.num_substeps == 1:
        stepper = substepped_stepper
    else:
        stepper = ex.RepeatedStepper(substepped_stepper, self.num_substeps)

    return stepper
get_ref_stepper ¤
get_ref_stepper()
Source code in apebench/scenarios/physical/_convection.py
49
50
def get_ref_stepper(self):
    return self._build_stepper(self.dt)
get_coarse_stepper ¤
get_coarse_stepper() -> ex.BaseStepper
Source code in apebench/scenarios/physical/_convection.py
52
53
def get_coarse_stepper(self) -> ex.BaseStepper:
    return self._build_stepper(self.dt * self.coarse_proportion)
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/physical/_convection.py
55
56
57
58
59
60
def get_scenario_name(self) -> str:
    active_indices = []
    for i, a in enumerate(self.a_coefs):
        if a != 0.0:
            active_indices.append(i)
    return f"{self.num_spatial_dims}d_phy_conv_{'_'.join(str(i) for i in active_indices)}"

apebench.scenarios.physical.Polynomial ¤

Bases: BaseScenario

Source code in apebench/scenarios/physical/_polynomial.py
 6
 7
 8
 9
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
50
51
52
53
class Polynomial(BaseScenario):
    domain_extent: float = 1.0
    dt: float = 0.001

    a_coefs: tuple[float, ...] = (0.02, 0.0, 4e-6, 0.0, 0.0)
    poly_coefs: tuple[float, ...] = (0.0, 0.0, -0.02)

    num_substeps: int = 1

    coarse_proportion: float = 0.5

    order: int = 2
    dealiasing_fraction: float = 2 / 3
    num_circle_points: int = 16
    circle_radius: float = 1.0

    def __post_init__(self):
        pass

    def _build_stepper(self, dt):
        substepped_stepper = ex.stepper.generic.GeneralPolynomialStepper(
            num_spatial_dims=self.num_spatial_dims,
            domain_extent=self.domain_extent,
            num_points=self.num_points,
            dt=dt / self.num_substeps,
            linear_coefficients=self.a_coefs,
            polynomial_coefficients=self.poly_coefs,
            order=self.order,
            dealiasing_fraction=self.dealiasing_fraction,
            num_circle_points=self.num_circle_points,
            circle_radius=self.circle_radius,
        )

        if self.num_substeps == 1:
            stepper = substepped_stepper
        else:
            stepper = ex.RepeatedStepper(substepped_stepper, self.num_substeps)

        return stepper

    def get_ref_stepper(self):
        return self._build_stepper(self.dt)

    def get_coarse_stepper(self):
        return self._build_stepper(self.dt * self.coarse_proportion)

    def get_scenario_name(self) -> str:
        return f"{self.num_spatial_dims}d_phy_poly"
domain_extent class-attribute instance-attribute ¤
domain_extent: float = 1.0
dt class-attribute instance-attribute ¤
dt: float = 0.001
a_coefs class-attribute instance-attribute ¤
a_coefs: tuple[float, ...] = (0.02, 0.0, 4e-06, 0.0, 0.0)
poly_coefs class-attribute instance-attribute ¤
poly_coefs: tuple[float, ...] = (0.0, 0.0, -0.02)
num_substeps class-attribute instance-attribute ¤
num_substeps: int = 1
coarse_proportion class-attribute instance-attribute ¤
coarse_proportion: float = 0.5
order class-attribute instance-attribute ¤
order: int = 2
dealiasing_fraction class-attribute instance-attribute ¤
dealiasing_fraction: float = 2 / 3
num_circle_points class-attribute instance-attribute ¤
num_circle_points: int = 16
circle_radius class-attribute instance-attribute ¤
circle_radius: float = 1.0
__post_init__ ¤
__post_init__()
Source code in apebench/scenarios/physical/_polynomial.py
22
23
def __post_init__(self):
    pass
_build_stepper ¤
_build_stepper(dt)
Source code in apebench/scenarios/physical/_polynomial.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def _build_stepper(self, dt):
    substepped_stepper = ex.stepper.generic.GeneralPolynomialStepper(
        num_spatial_dims=self.num_spatial_dims,
        domain_extent=self.domain_extent,
        num_points=self.num_points,
        dt=dt / self.num_substeps,
        linear_coefficients=self.a_coefs,
        polynomial_coefficients=self.poly_coefs,
        order=self.order,
        dealiasing_fraction=self.dealiasing_fraction,
        num_circle_points=self.num_circle_points,
        circle_radius=self.circle_radius,
    )

    if self.num_substeps == 1:
        stepper = substepped_stepper
    else:
        stepper = ex.RepeatedStepper(substepped_stepper, self.num_substeps)

    return stepper
get_ref_stepper ¤
get_ref_stepper()
Source code in apebench/scenarios/physical/_polynomial.py
46
47
def get_ref_stepper(self):
    return self._build_stepper(self.dt)
get_coarse_stepper ¤
get_coarse_stepper()
Source code in apebench/scenarios/physical/_polynomial.py
49
50
def get_coarse_stepper(self):
    return self._build_stepper(self.dt * self.coarse_proportion)
get_scenario_name ¤
get_scenario_name() -> str
Source code in apebench/scenarios/physical/_polynomial.py
52
53
def get_scenario_name(self) -> str:
    return f"{self.num_spatial_dims}d_phy_poly"