PyMPDATA_examples.Molenkamp_test_as_in_Jaruga_et_al_2015_Fig_12.simulation

 1from PyMPDATA_examples.Molenkamp_test_as_in_Jaruga_et_al_2015_Fig_12.settings import (
 2    Settings,
 3)
 4from PyMPDATA_examples.utils import nondivergent_vector_field_2d
 5from PyMPDATA_examples.utils.discretisation import from_pdf_2d
 6
 7from PyMPDATA import Options, ScalarField, Solver, Stepper
 8from PyMPDATA.boundary_conditions import Periodic
 9
10
11class Simulation:
12    def __init__(self, settings: Settings, options: Options):
13        _, __, z = from_pdf_2d(
14            settings.pdf,
15            xrange=settings.xrange,
16            yrange=settings.yrange,
17            gridsize=settings.grid,
18        )
19        stepper = Stepper(options=options, grid=settings.grid, non_unit_g_factor=False)
20        advector = nondivergent_vector_field_2d(
21            settings.grid,
22            settings.size,
23            settings.dt,
24            settings.stream_function,
25            options.n_halo,
26        )
27        advectee = ScalarField(
28            z.astype(dtype=options.dtype),
29            halo=options.n_halo,
30            boundary_conditions=(Periodic(), Periodic()),
31        )
32        self.mpdata = Solver(stepper=stepper, advectee=advectee, advector=advector)
33        self.nt = settings.nt
34
35    @property
36    def state(self):
37        return self.mpdata.advectee.get().copy()
38
39    def run(self):
40        self.mpdata.advance(self.nt)
class Simulation:
12class Simulation:
13    def __init__(self, settings: Settings, options: Options):
14        _, __, z = from_pdf_2d(
15            settings.pdf,
16            xrange=settings.xrange,
17            yrange=settings.yrange,
18            gridsize=settings.grid,
19        )
20        stepper = Stepper(options=options, grid=settings.grid, non_unit_g_factor=False)
21        advector = nondivergent_vector_field_2d(
22            settings.grid,
23            settings.size,
24            settings.dt,
25            settings.stream_function,
26            options.n_halo,
27        )
28        advectee = ScalarField(
29            z.astype(dtype=options.dtype),
30            halo=options.n_halo,
31            boundary_conditions=(Periodic(), Periodic()),
32        )
33        self.mpdata = Solver(stepper=stepper, advectee=advectee, advector=advector)
34        self.nt = settings.nt
35
36    @property
37    def state(self):
38        return self.mpdata.advectee.get().copy()
39
40    def run(self):
41        self.mpdata.advance(self.nt)
13    def __init__(self, settings: Settings, options: Options):
14        _, __, z = from_pdf_2d(
15            settings.pdf,
16            xrange=settings.xrange,
17            yrange=settings.yrange,
18            gridsize=settings.grid,
19        )
20        stepper = Stepper(options=options, grid=settings.grid, non_unit_g_factor=False)
21        advector = nondivergent_vector_field_2d(
22            settings.grid,
23            settings.size,
24            settings.dt,
25            settings.stream_function,
26            options.n_halo,
27        )
28        advectee = ScalarField(
29            z.astype(dtype=options.dtype),
30            halo=options.n_halo,
31            boundary_conditions=(Periodic(), Periodic()),
32        )
33        self.mpdata = Solver(stepper=stepper, advectee=advectee, advector=advector)
34        self.nt = settings.nt
mpdata
nt
state
36    @property
37    def state(self):
38        return self.mpdata.advectee.get().copy()
def run(self):
40    def run(self):
41        self.mpdata.advance(self.nt)