PyMPDATA_examples.Smolarkiewicz_2006_Figs_3_4_10_11_12.simulation
1import numpy as np 2from PyMPDATA_examples.Smolarkiewicz_2006_Figs_3_4_10_11_12.settings import Settings 3from PyMPDATA_examples.utils.discretisation import from_cdf_1d 4 5from PyMPDATA import Options, ScalarField, Solver, Stepper, VectorField 6from PyMPDATA.boundary_conditions import Periodic 7 8 9class Simulation: 10 def __init__(self, settings: Settings, options: Options): 11 _, state = from_cdf_1d( 12 settings.cdf, settings.x_min, settings.x_max, settings.nx 13 ) 14 15 self.stepper = Solver( 16 stepper=Stepper( 17 options=options, n_dims=len(state.shape), non_unit_g_factor=False 18 ), 19 advectee=ScalarField( 20 state.astype(options.dtype), 21 halo=options.n_halo, 22 boundary_conditions=(Periodic(),), 23 ), 24 advector=VectorField( 25 (np.full(state.shape[0] + 1, settings.C, dtype=options.dtype),), 26 halo=options.n_halo, 27 boundary_conditions=(Periodic(),), 28 ), 29 ) 30 self.nt = settings.nt 31 32 @property 33 def state(self): 34 return self.stepper.advectee.get().copy() 35 36 def run(self): 37 self.stepper.advance(self.nt)
class
Simulation:
10class Simulation: 11 def __init__(self, settings: Settings, options: Options): 12 _, state = from_cdf_1d( 13 settings.cdf, settings.x_min, settings.x_max, settings.nx 14 ) 15 16 self.stepper = Solver( 17 stepper=Stepper( 18 options=options, n_dims=len(state.shape), non_unit_g_factor=False 19 ), 20 advectee=ScalarField( 21 state.astype(options.dtype), 22 halo=options.n_halo, 23 boundary_conditions=(Periodic(),), 24 ), 25 advector=VectorField( 26 (np.full(state.shape[0] + 1, settings.C, dtype=options.dtype),), 27 halo=options.n_halo, 28 boundary_conditions=(Periodic(),), 29 ), 30 ) 31 self.nt = settings.nt 32 33 @property 34 def state(self): 35 return self.stepper.advectee.get().copy() 36 37 def run(self): 38 self.stepper.advance(self.nt)
Simulation( settings: PyMPDATA_examples.Smolarkiewicz_2006_Figs_3_4_10_11_12.settings.Settings, options: PyMPDATA.options.Options)
11 def __init__(self, settings: Settings, options: Options): 12 _, state = from_cdf_1d( 13 settings.cdf, settings.x_min, settings.x_max, settings.nx 14 ) 15 16 self.stepper = Solver( 17 stepper=Stepper( 18 options=options, n_dims=len(state.shape), non_unit_g_factor=False 19 ), 20 advectee=ScalarField( 21 state.astype(options.dtype), 22 halo=options.n_halo, 23 boundary_conditions=(Periodic(),), 24 ), 25 advector=VectorField( 26 (np.full(state.shape[0] + 1, settings.C, dtype=options.dtype),), 27 halo=options.n_halo, 28 boundary_conditions=(Periodic(),), 29 ), 30 ) 31 self.nt = settings.nt