PyMPDATA_examples.Smolarkiewicz_1984.simulation
1import numpy as np 2 3from PyMPDATA import ScalarField, Solver, Stepper, VectorField 4from PyMPDATA.boundary_conditions import Constant 5 6 7class Simulation: 8 def __init__(self, settings, options, static=True, n_threads=None): 9 bcs = tuple(Constant(0) for _ in settings.grid) 10 11 advector = VectorField( 12 data=tuple(comp.astype(options.dtype) for comp in settings.advector), 13 halo=options.n_halo, 14 boundary_conditions=bcs, 15 ) 16 17 advectee = ScalarField( 18 data=np.asarray(settings.advectee, dtype=options.dtype), 19 halo=options.n_halo, 20 boundary_conditions=bcs, 21 ) 22 23 args = {"grid": settings.grid} if static else {"n_dims": len(settings.grid)} 24 if n_threads is not None: 25 args["n_threads"] = n_threads 26 stepper = Stepper(options=options, **args) 27 self.solver = Solver(stepper=stepper, advectee=advectee, advector=advector) 28 29 def run(self, nt): 30 return self.solver.advance(nt) 31 32 @property 33 def advectee(self): 34 return self.solver.advectee
class
Simulation:
8class Simulation: 9 def __init__(self, settings, options, static=True, n_threads=None): 10 bcs = tuple(Constant(0) for _ in settings.grid) 11 12 advector = VectorField( 13 data=tuple(comp.astype(options.dtype) for comp in settings.advector), 14 halo=options.n_halo, 15 boundary_conditions=bcs, 16 ) 17 18 advectee = ScalarField( 19 data=np.asarray(settings.advectee, dtype=options.dtype), 20 halo=options.n_halo, 21 boundary_conditions=bcs, 22 ) 23 24 args = {"grid": settings.grid} if static else {"n_dims": len(settings.grid)} 25 if n_threads is not None: 26 args["n_threads"] = n_threads 27 stepper = Stepper(options=options, **args) 28 self.solver = Solver(stepper=stepper, advectee=advectee, advector=advector) 29 30 def run(self, nt): 31 return self.solver.advance(nt) 32 33 @property 34 def advectee(self): 35 return self.solver.advectee
Simulation(settings, options, static=True, n_threads=None)
9 def __init__(self, settings, options, static=True, n_threads=None): 10 bcs = tuple(Constant(0) for _ in settings.grid) 11 12 advector = VectorField( 13 data=tuple(comp.astype(options.dtype) for comp in settings.advector), 14 halo=options.n_halo, 15 boundary_conditions=bcs, 16 ) 17 18 advectee = ScalarField( 19 data=np.asarray(settings.advectee, dtype=options.dtype), 20 halo=options.n_halo, 21 boundary_conditions=bcs, 22 ) 23 24 args = {"grid": settings.grid} if static else {"n_dims": len(settings.grid)} 25 if n_threads is not None: 26 args["n_threads"] = n_threads 27 stepper = Stepper(options=options, **args) 28 self.solver = Solver(stepper=stepper, advectee=advectee, advector=advector)