PySDM.environments.box
Bare zero-dimensional framework
1""" 2Bare zero-dimensional framework 3""" 4 5import numpy as np 6 7from PySDM.impl.mesh import Mesh 8from PySDM.environments.impl import register_environment 9 10 11@register_environment() 12class Box: 13 def __init__(self, dt, dv): 14 self.dt = dt 15 self.mesh = Mesh.mesh_0d(dv) 16 self.particulator = None 17 self._ambient_air = {} 18 19 def __getitem__(self, item): 20 return self._ambient_air[item] 21 22 def __setitem__(self, key, value): 23 if key not in self._ambient_air: 24 self._ambient_air[key] = self.particulator.backend.Storage.from_ndarray( 25 np.array([value]) 26 ) 27 else: 28 self._ambient_air[key][:] = value 29 30 def register(self, builder): 31 self.particulator = builder.particulator 32 33 def init_attributes(self, *, spectral_discretisation): 34 attributes = {} 35 ( 36 attributes["volume"], 37 attributes["multiplicity"], 38 ) = spectral_discretisation.sample( 39 backend=self.particulator.backend, n_sd=self.particulator.n_sd 40 ) 41 return attributes
@register_environment()
class
Box:
12@register_environment() 13class Box: 14 def __init__(self, dt, dv): 15 self.dt = dt 16 self.mesh = Mesh.mesh_0d(dv) 17 self.particulator = None 18 self._ambient_air = {} 19 20 def __getitem__(self, item): 21 return self._ambient_air[item] 22 23 def __setitem__(self, key, value): 24 if key not in self._ambient_air: 25 self._ambient_air[key] = self.particulator.backend.Storage.from_ndarray( 26 np.array([value]) 27 ) 28 else: 29 self._ambient_air[key][:] = value 30 31 def register(self, builder): 32 self.particulator = builder.particulator 33 34 def init_attributes(self, *, spectral_discretisation): 35 attributes = {} 36 ( 37 attributes["volume"], 38 attributes["multiplicity"], 39 ) = spectral_discretisation.sample( 40 backend=self.particulator.backend, n_sd=self.particulator.n_sd 41 ) 42 return attributes