def init_attributes(self, *, spatial_discretisation, spectral_discretisation, kappa, enable_temperatures=False, rtol=default_rtol): # TODO move to one method super().sync() self.notify() attributes = {} with np.errstate(all='raise'): positions = spatial_discretisation.sample(self.mesh.grid, self.core.n_sd) attributes['cell id'], attributes['cell origin'], attributes['position in cell'] = \ self.mesh.cellular_attributes(positions) r_dry, n_per_kg = spectral_discretisation.sample(self.core.n_sd) r_wet = r_wet_init(r_dry, self, attributes['cell id'], kappa, rtol) rhod = self['rhod'].to_ndarray() cell_id = attributes['cell id'] domain_volume = np.prod(np.array(self.mesh.size)) if enable_temperatures: attributes['temperature'] = temperature_init( self, attributes['cell id']) attributes['n'] = discretise_n(n_per_kg * rhod[cell_id] * domain_volume) attributes['volume'] = phys.volume(radius=r_wet) attributes['dry volume'] = phys.volume(radius=r_dry) return attributes
def init_attributes(self, *, n_in_dv: [float, np.ndarray], kappa: float, r_dry: [float, np.ndarray], rtol=default_rtol): if not isinstance(n_in_dv, np.ndarray): r_dry = np.array([r_dry]) n_in_dv = np.array([n_in_dv]) attributes = {} attributes['dry volume'] = self.formulae.trivia.volume(radius=r_dry) attributes['n'] = discretise_n(n_in_dv) r_wet = r_wet_init(r_dry, self, kappa, rtol=rtol) attributes['volume'] = self.formulae.trivia.volume(radius=r_wet) return attributes
def __init__(self, settings, backend=CPU): t_half = settings.z_half / settings.w_avg dt_output = (2 * t_half) / settings.n_output self.n_substeps = 1 while dt_output / self.n_substeps >= settings.dt_max: # TODO #334 dt_max self.n_substeps += 1 builder = Builder(backend=backend, n_sd=1, formulae=settings.formulae) builder.set_environment(Parcel( dt=dt_output / self.n_substeps, mass_of_dry_air=settings.mass_of_dry_air, p0=settings.p0, q0=settings.q0, T0=settings.T0, w=settings.w )) builder.add_dynamic(AmbientThermodynamics()) builder.add_dynamic(Condensation( kappa=settings.kappa, rtol_x=settings.rtol_x, rtol_thd=settings.rtol_thd, dt_cond_range=settings.dt_cond_range )) attributes = {} r_dry = np.array([settings.r_dry]) attributes['dry volume'] = settings.formulae.trivia.volume(radius=r_dry) attributes['n'] = np.array([settings.n_in_dv], dtype=np.int64) environment = builder.core.environment r_wet = r_wet_init(r_dry, environment, kappa=settings.kappa) attributes['volume'] = settings.formulae.trivia.volume(radius=r_wet) products = [ PySDM_products.ParticleMeanRadius(), PySDM_products.CondensationTimestepMin(), PySDM_products.ParcelDisplacement(), PySDM_products.RelativeHumidity(), PySDM_products.Time(), PySDM_products.ActivatingRate(), PySDM_products.DeactivatingRate(), PySDM_products.RipeningRate(), PySDM_products.PeakSupersaturation() ] self.core = builder.build(attributes, products) self.n_output = settings.n_output
def __init__(self, setup): dt_output = setup.total_time / setup.n_steps # TODO: overwritten in jupyter example self.n_substeps = 1 # TODO: while (dt_output / self.n_substeps >= setup.dt_max): self.n_substeps += 1 self.bins_edges = phys.volume(setup.r_bins_edges) particles_builder = ParticlesBuilder(backend=setup.backend, n_sd=setup.n_sd) particles_builder.set_environment( MoistLagrangianParcelAdiabatic, { "dt": dt_output / self.n_substeps, "mass_of_dry_air": setup.mass_of_dry_air, "p0": setup.p0, "q0": setup.q0, "T0": setup.T0, "w": setup.w, "z0": setup.z0 }) environment = particles_builder.particles.environment r_wet = r_wet_init(setup.r_dry, environment, np.zeros_like(setup.n), setup.kappa) particles_builder.register_dynamic( Condensation, { "kappa": setup.kappa, "coord": setup.coord, "adaptive": setup.adaptive, "rtol_x": setup.rtol_x, "rtol_thd": setup.rtol_thd, }) attributes = { 'n': setup.n, 'dry volume': phys.volume(radius=setup.r_dry), 'volume': phys.volume(radius=r_wet) } products = { ParticlesSizeSpectrum: { 'v_bins': phys.volume(setup.r_bins_edges) }, CondensationTimestep: {}, RipeningRate: {} } self.particles = particles_builder.get_particles(attributes, products) self.n_steps = setup.n_steps
def __init__(self, setup): dt_output = setup.total_time / setup.n_steps # TODO: overwritten in jupyter example self.n_substeps = 1 # TODO while (dt_output / self.n_substeps >= setup.dt_max): self.n_substeps += 1 self.bins_edges = phys.volume(setup.r_bins_edges) particles_builder = Builder(backend=setup.backend, n_sd=setup.n_sd) particles_builder.set_environment( MoistLagrangianParcelAdiabatic( dt=dt_output / self.n_substeps, mass_of_dry_air=setup.mass_of_dry_air, p0=setup.p0, q0=setup.q0, T0=setup.T0, w=setup.w, z0=setup.z0)) environment = particles_builder.core.environment r_wet = r_wet_init(setup.r_dry, environment, np.zeros_like(setup.n), setup.kappa) condensation = Condensation(kappa=setup.kappa, coord=setup.coord, adaptive=setup.adaptive, rtol_x=setup.rtol_x, rtol_thd=setup.rtol_thd) particles_builder.add_dynamic(condensation) attributes = { 'n': setup.n, 'dry volume': phys.volume(radius=setup.r_dry), 'volume': phys.volume(radius=r_wet) } products = [ ParticlesWetSizeSpectrum(v_bins=phys.volume(setup.r_bins_edges)), CondensationTimestep(), RipeningRate() ] self.particles = particles_builder.build(attributes, products) self.n_steps = setup.n_steps
def init_attributes(self, *, spatial_discretisation, kappa, spectral_discretisation = None, spectro_glacial_discretisation = None, rtol=default_rtol ): super().sync() self.notify() assert spectro_glacial_discretisation is None or spectral_discretisation is None attributes = {} with np.errstate(all='raise'): positions = spatial_discretisation.sample(self.mesh.grid, self.particulator.n_sd) attributes['cell id'], attributes['cell origin'], attributes['position in cell'] = \ self.mesh.cellular_attributes(positions) if spectral_discretisation: r_dry, n_per_kg = spectral_discretisation.sample(self.particulator.n_sd) elif spectro_glacial_discretisation: r_dry, T_fz, n_per_kg = spectro_glacial_discretisation.sample(self.particulator.n_sd) attributes['freezing temperature'] = T_fz else: raise NotImplementedError() attributes['dry volume'] = self.formulae.trivia.volume(radius=r_dry) attributes['kappa times dry volume'] = kappa * attributes['dry volume'] if kappa == 0: r_wet = r_dry else: r_wet = r_wet_init(r_dry, self, kappa_times_dry_volume=attributes['kappa times dry volume'], rtol=rtol, cell_id=attributes['cell id']) rhod = self['rhod'].to_ndarray() cell_id = attributes['cell id'] domain_volume = np.prod(np.array(self.mesh.size)) attributes['n'] = discretise_n(n_per_kg * rhod[cell_id] * domain_volume) attributes['volume'] = self.formulae.trivia.volume(radius=r_wet) return attributes
def __init__(self, setup): t_half = setup.z_half / setup.w_avg dt_output = (2 * t_half) / setup.n_output self.n_substeps = 1 while dt_output / self.n_substeps >= setup.dt_max: # TODO dt_max self.n_substeps += 1 particles_builder = ParticlesBuilder(backend=setup.backend, n_sd=1) particles_builder.set_environment( MoistLagrangianParcelAdiabatic, { "dt": dt_output / self.n_substeps, "mass_of_dry_air": setup.mass_of_dry_air, "p0": setup.p0, "q0": setup.q0, "T0": setup.T0, "w": setup.w }) particles_builder.register_dynamic( Condensation, { "kappa": setup.kappa, "rtol_x": setup.rtol_x, "rtol_thd": setup.rtol_thd, }) attributes = {} r_dry = np.array([setup.r_dry]) attributes['dry volume'] = phys.volume(radius=r_dry) attributes['n'] = np.array([setup.n_in_dv], dtype=np.int64) environment = particles_builder.particles.environment r_wet = r_wet_init(r_dry, environment, np.zeros_like(attributes['n']), setup.kappa) attributes['volume'] = phys.volume(radius=r_wet) products = {ParticleMeanRadius: {}} self.particles = particles_builder.get_particles(attributes, products) self.n_output = setup.n_output
def __init__(self, setup): t_half = setup.z_half / setup.w_avg dt_output = (2 * t_half) / setup.n_output self.n_substeps = 1 while dt_output / self.n_substeps >= setup.dt_max: # TODO dt_max self.n_substeps += 1 builder = Builder(backend=setup.backend, n_sd=1) builder.set_environment( MoistLagrangianParcelAdiabatic( dt=dt_output / self.n_substeps, mass_of_dry_air=setup.mass_of_dry_air, p0=setup.p0, q0=setup.q0, T0=setup.T0, w=setup.w)) builder.add_dynamic( Condensation( kappa=setup.kappa, rtol_x=setup.rtol_x, rtol_thd=setup.rtol_thd, )) attributes = {} r_dry = np.array([setup.r_dry]) attributes['dry volume'] = phys.volume(radius=r_dry) attributes['n'] = np.array([setup.n_in_dv], dtype=np.int64) environment = builder.core.environment r_wet = r_wet_init(r_dry, environment, np.zeros_like(attributes['n']), setup.kappa) attributes['volume'] = phys.volume(radius=r_wet) products = [ParticleMeanRadius(), CondensationTimestep()] self.core = builder.build(attributes, products) self.n_output = setup.n_output