def initialize(self): self.set_attribute('hor_friction_cosPower', np.random.randint(1, 5)) for a in ('dt_mom', 'r_bot', 'r_quad_bot', 'A_h', 'A_hbi', 'AB_eps', 'x_origin', 'y_origin'): self.set_attribute(a, np.random.rand()) for a in ('dxt', ): self.set_attribute( a, 0.1 * np.ones(self.nx + 4) + 0.01 * np.random.rand(self.nx + 4)) for a in ('dyt', ): self.set_attribute( a, 0.1 * np.ones(self.ny + 4) + 0.01 * np.random.rand(self.ny + 4)) for a in ('dzt', ): self.set_attribute(a, np.random.rand(self.nz)) for a in ('r_bot_var_u', 'r_bot_var_v', 'surface_taux', 'surface_tauy', 'coriolis_t', 'coriolis_h'): self.set_attribute(a, np.random.randn(self.nx + 4, self.ny + 4)) for a in ('K_diss_v', 'kappaM', 'flux_north', 'flux_east', 'flux_top', 'K_diss_bot', 'K_diss_h', 'du_mix', 'dv_mix', 'u_source', 'v_source', 'du_adv', 'dv_adv'): self.set_attribute( a, np.random.randn(self.nx + 4, self.ny + 4, self.nz)) for a in ('u', 'v', 'w', 'du', 'dv'): self.set_attribute( a, np.random.randn(self.nx + 4, self.ny + 4, self.nz, 3)) kbot = np.random.randint(1, self.nz, size=(self.nx + 4, self.ny + 4)) # add some islands, but avoid boundaries kbot[3:-3, 3:-3].flat[np.random.randint(0, (self.nx - 2) * (self.ny - 2), size=10)] = 0 self.set_attribute('kbot', kbot) numerics.calc_grid(self.veros_new.state) numerics.calc_topo(self.veros_new.state) self.veros_legacy.call_fortran_routine('calc_grid') self.veros_legacy.call_fortran_routine('calc_topo') if self.first: streamfunction.streamfunction_init(self.veros_new.state) self.veros_legacy.call_fortran_routine('streamfunction_init') self.first = False self.test_module = momentum veros_args = (self.veros_new.state, ) veros_legacy_args = dict() self.test_routines = OrderedDict() self.test_routines['momentum_advection'] = (veros_args, veros_legacy_args) self.test_routines['vertical_velocity'] = (veros_args, veros_legacy_args) self.test_routines['momentum'] = (veros_args, veros_legacy_args)
def initialize(self): self.set_attribute("hor_friction_cosPower", np.random.randint(1, 5)) for a in ("dt_mom", "r_bot", "r_quad_bot", "A_h", "A_hbi", "AB_eps", "x_origin", "y_origin"): self.set_attribute(a, np.random.rand()) for a in ("dxt", ): self.set_attribute( a, 0.1 * np.ones(self.nx + 4) + 0.01 * np.random.rand(self.nx + 4)) for a in ("dyt", ): self.set_attribute( a, 0.1 * np.ones(self.ny + 4) + 0.01 * np.random.rand(self.ny + 4)) for a in ("dzt", ): self.set_attribute(a, np.random.rand(self.nz)) for a in ("r_bot_var_u", "r_bot_var_v", "surface_taux", "surface_tauy", "coriolis_t", "coriolis_h"): self.set_attribute(a, np.random.randn(self.nx + 4, self.ny + 4)) for a in ("K_diss_v", "kappaM", "flux_north", "flux_east", "flux_top", "K_diss_bot", "K_diss_h", "du_mix", "dv_mix", "u_source", "v_source", "du_adv", "dv_adv"): self.set_attribute( a, np.random.randn(self.nx + 4, self.ny + 4, self.nz)) for a in ("u", "v", "w", "du", "dv"): self.set_attribute( a, np.random.randn(self.nx + 4, self.ny + 4, self.nz, 3)) kbot = np.random.randint(1, self.nz, size=(self.nx + 4, self.ny + 4)) # add some islands, but avoid boundaries kbot[3:-3, 3:-3].flat[np.random.randint(0, (self.nx - 2) * (self.ny - 2), size=10)] = 0 self.set_attribute("kbot", kbot) numerics.calc_grid(self.veros_new) numerics.calc_topo(self.veros_new) self.veros_legacy.call_fortran_routine("calc_grid") self.veros_legacy.call_fortran_routine("calc_topo") if self.first: external.streamfunction_init(self.veros_new) self.veros_legacy.call_fortran_routine("streamfunction_init") self.first = False self.test_module = momentum veros_args = (self.veros_new, ) veros_legacy_args = dict() self.test_routines = OrderedDict() self.test_routines["momentum_advection"] = (veros_args, veros_legacy_args) self.test_routines["vertical_velocity"] = (veros_args, veros_legacy_args) self.test_routines["momentum"] = (veros_args, veros_legacy_args)
def initialize(self): self.set_attribute('dt_tracer', 3600.) for a in ('dxt', ): self.set_attribute( a, np.random.randint(1, 100, size=self.nx + 4).astype(np.float)) for a in ('dyt', ): self.set_attribute( a, np.random.randint(1, 100, size=self.ny + 4).astype(np.float)) for a in ('cosu', 'cost'): self.set_attribute(a, 2 * np.random.rand(self.ny + 4) - 1.) for a in ('dzt', 'dzw'): self.set_attribute(a, 100 * np.random.rand(self.nz)) for a in ('flux_east', 'flux_north', 'flux_top', 'u_wgrid', 'v_wgrid', 'w_wgrid'): self.set_attribute( a, np.random.randn(self.nx + 4, self.ny + 4, self.nz)) for a in ('u', 'v', 'w', 'Hd'): self.set_attribute( a, np.random.randn(self.nx + 4, self.ny + 4, self.nz, 3)) self.set_attribute( 'kbot', np.random.randint(0, self.nz, size=(self.nx + 4, self.ny + 4)).astype(np.float)) numerics.calc_topo(self.veros_new.state) self.veros_legacy.call_fortran_routine('calc_topo') self.test_module = advection veros_args = (self.veros_new.state, self.veros_new.state.flux_east, self.veros_new.state.flux_north, self.veros_new.state.flux_top, self.veros_new.state.Hd[..., 1]) veros_legacy_args = dict( is_=-1, ie_=self.nx + 2, js_=-1, je_=self.ny + 2, nz_=self.nz, adv_fe=self.veros_legacy.get_fortran_attribute('flux_east'), adv_fn=self.veros_legacy.get_fortran_attribute('flux_north'), adv_ft=self.veros_legacy.get_fortran_attribute('flux_top'), var=self.veros_legacy.get_fortran_attribute('Hd')[..., 1]) self.test_routines = OrderedDict() self.test_routines['calculate_velocity_on_wgrid'] = (( self.veros_new.state, ), dict()) self.test_routines.update( adv_flux_2nd=(veros_args, veros_legacy_args), adv_flux_superbee=(veros_args, veros_legacy_args), adv_flux_upwind_wgrid=(veros_args, veros_legacy_args), adv_flux_superbee_wgrid=(veros_args, veros_legacy_args))
def initialize(self): m = self.veros_legacy.main_module #np.random.seed(123456) self.set_attribute("hor_friction_cosPower", np.random.randint(1, 5)) for a in ("dt_tracer", "K_hbi", "K_h"): self.set_attribute(a, np.random.rand()) for a in ("dxt", "dxu"): self.set_attribute( a, np.random.randint(1, 100, size=self.nx + 4).astype(np.float)) for a in ("dyt", "dyu"): self.set_attribute( a, np.random.randint(1, 100, size=self.ny + 4).astype(np.float)) for a in ("cosu", "cost"): self.set_attribute(a, 2 * np.random.rand(self.ny + 4) - 1.) for a in ("dzt", "dzw"): self.set_attribute(a, 100 * np.random.rand(self.nz)) for a in ("flux_east", "flux_north", "flux_top", "dtemp_hmix", "dsalt_hmix", "temp_source", "salt_source"): self.set_attribute( a, np.random.randn(self.nx + 4, self.ny + 4, self.nz)) for a in ("temp", "salt", "int_drhodS", "int_drhodT"): self.set_attribute( a, np.random.randn(self.nx + 4, self.ny + 4, self.nz, 3)) self.set_attribute( "kbot", np.random.randint(0, self.nz, size=(self.nx + 4, self.ny + 4))) numerics.calc_topo(self.veros_new) self.veros_legacy.fortran.calc_topo() self.set_attribute( "P_diss_hmix", np.random.randn(self.nx + 4, self.ny + 4, self.nz) * self.veros_new.maskT) self.test_module = diffusion veros_args = (self.veros_new, ) veros_legacy_args = dict() self.test_routines = OrderedDict() self.test_routines.update( tempsalt_biharmonic=(veros_args, veros_legacy_args), tempsalt_diffusion=(veros_args, veros_legacy_args), tempsalt_sources=(veros_args, veros_legacy_args), )
def initialize(self): m = self.veros_legacy.main_module np.random.seed(123456) self.set_attribute("hor_friction_cosPower", np.random.randint(1,5)) for a in ("dt_mom", "r_bot", "r_quad_bot", "A_h", "A_hbi", "x_origin", "y_origin"): self.set_attribute(a, np.random.rand()) for a in ("dxt","dxu"): self.set_attribute(a, np.random.randint(1,100,size=self.nx+4).astype(np.float)) for a in ("dyt","dyu"): self.set_attribute(a, np.random.randint(1,100,size=self.ny+4).astype(np.float)) for a in ("cosu","cost"): self.set_attribute(a, np.random.rand(self.ny+4) + 1) for a in ("dzt","dzw","zw"): self.set_attribute(a, 1 + np.random.rand(self.nz)) for a in ("r_bot_var_u","r_bot_var_v"): self.set_attribute(a, np.random.randn(self.nx+4,self.ny+4)) for a in ("area_u","area_v","area_t"): self.set_attribute(a, np.random.rand(self.nx+4,self.ny+4)) for a in ("K_diss_v", "kappaM", "flux_north", "flux_east", "flux_top", "K_diss_bot", "K_diss_h", "du_mix", "dv_mix", "u_source", "v_source"): self.set_attribute(a, np.random.randn(self.nx+4,self.ny+4,self.nz)) for a in ("u","v","w"): self.set_attribute(a, np.random.randn(self.nx+4,self.ny+4,self.nz,3)) for a in ("maskU", "maskV", "maskW", "maskT"): self.set_attribute(a, np.random.randint(0,2,size=(self.nx+4,self.ny+4,self.nz)).astype(np.float)) kbot = np.random.randint(1, self.nz, size=(self.nx+4,self.ny+4)) # add some islands, but avoid boundaries kbot[3:-3,3:-3].flat[np.random.randint(0, (self.nx-2) * (self.ny-2), size=10)] = 0 self.set_attribute("kbot",kbot) numerics.calc_grid(self.veros_new) numerics.calc_topo(self.veros_new) self.veros_legacy.fortran.calc_grid() self.veros_legacy.fortran.calc_topo() self.test_module = friction veros_args = (self.veros_new,) veros_legacy_args = dict() self.test_routines = {k: (veros_args, veros_legacy_args) for k in ("explicit_vert_friction","implicit_vert_friction","rayleigh_friction", "linear_bottom_friction","quadratic_bottom_friction","harmonic_friction", "biharmonic_friction","momentum_sources")}
def initialize(self): self.set_attribute('hor_friction_cosPower', np.random.randint(1, 5)) for a in ('dt_mom', 'r_bot', 'r_quad_bot', 'A_h', 'A_hbi', 'x_origin', 'y_origin'): self.set_attribute(a, np.random.rand()) for a in ('dxt', 'dxu'): self.set_attribute(a, np.ones(self.nx + 4) * np.random.rand()) for a in ('dyt', 'dyu'): self.set_attribute(a, np.ones(self.ny + 4) * np.random.rand()) for a in ('cosu', 'cost'): self.set_attribute(a, np.random.rand(self.ny + 4) + 1) for a in ('dzt', 'dzw', 'zw'): self.set_attribute(a, 1 + np.random.rand(self.nz)) for a in ('r_bot_var_u', 'r_bot_var_v'): self.set_attribute(a, np.random.randn(self.nx + 4, self.ny + 4)) for a in ('area_u', 'area_v', 'area_t'): self.set_attribute(a, np.random.rand(self.nx + 4, self.ny + 4)) for a in ('K_diss_v', 'kappaM', 'flux_north', 'flux_east', 'flux_top', 'K_diss_bot', 'K_diss_h', 'du_mix', 'dv_mix', 'u_source', 'v_source'): self.set_attribute(a, np.random.randn(self.nx + 4, self.ny + 4, self.nz)) for a in ('u', 'v', 'w'): self.set_attribute(a, np.random.randn(self.nx + 4, self.ny + 4, self.nz, 3)) for a in ('maskU', 'maskV', 'maskW', 'maskT'): self.set_attribute(a, np.random.randint(0, 2, size=(self.nx + 4, self.ny + 4, self.nz)).astype(np.float)) kbot = np.random.randint(1, self.nz, size=(self.nx + 4, self.ny + 4)) # add some islands, but avoid boundaries kbot[3:-3, 3:-3].flat[np.random.randint(0, (self.nx - 2) * (self.ny - 2), size=10)] = 0 self.set_attribute('kbot', kbot) numerics.calc_grid(self.veros_new.state) numerics.calc_topo(self.veros_new.state) self.veros_legacy.call_fortran_routine('calc_grid') self.veros_legacy.call_fortran_routine('calc_topo') self.test_module = friction veros_args = (self.veros_new.state, ) veros_legacy_args = dict() self.test_routines = {k: (veros_args, veros_legacy_args) for k in ( 'explicit_vert_friction', 'implicit_vert_friction', 'rayleigh_friction', 'linear_bottom_friction', 'quadratic_bottom_friction', 'harmonic_friction', 'biharmonic_friction', 'momentum_sources' )}
def initialize(self): self.set_attribute('hor_friction_cosPower', np.random.randint(1, 5)) for a in ('dt_tracer', 'K_hbi', 'K_h'): self.set_attribute(a, np.random.rand()) for a in ('dxt', 'dxu'): self.set_attribute( a, np.random.randint(1, 100, size=self.nx + 4).astype(np.float)) for a in ('dyt', 'dyu'): self.set_attribute( a, np.random.randint(1, 100, size=self.ny + 4).astype(np.float)) for a in ('cosu', 'cost'): self.set_attribute(a, 2 * np.random.rand(self.ny + 4) - 1.) for a in ('dzt', 'dzw'): self.set_attribute(a, 100 * np.random.rand(self.nz)) for a in ('flux_east', 'flux_north', 'flux_top', 'dtemp_hmix', 'dsalt_hmix', 'temp_source', 'salt_source'): self.set_attribute( a, np.random.randn(self.nx + 4, self.ny + 4, self.nz)) for a in ('temp', 'salt', 'int_drhodS', 'int_drhodT'): self.set_attribute( a, np.random.randn(self.nx + 4, self.ny + 4, self.nz, 3)) self.set_attribute( 'kbot', np.random.randint(0, self.nz, size=(self.nx + 4, self.ny + 4))) numerics.calc_topo(self.veros_new.state) self.veros_legacy.call_fortran_routine('calc_topo') self.set_attribute( 'P_diss_hmix', np.random.randn(self.nx + 4, self.ny + 4, self.nz) * self.veros_new.state.maskT) self.test_module = diffusion veros_args = (self.veros_new.state, ) veros_legacy_args = dict() self.test_routines = OrderedDict() self.test_routines.update( tempsalt_biharmonic=(veros_args, veros_legacy_args), tempsalt_diffusion=(veros_args, veros_legacy_args), tempsalt_sources=(veros_args, veros_legacy_args), )
def initialize(self): self.set_attribute("dt_tracer", 3600.) for a in ("dxt", ): self.set_attribute(a, np.random.randint(1, 100, size=self.nx + 4).astype(np.float)) for a in ("dyt", ): self.set_attribute(a, np.random.randint(1, 100, size=self.ny + 4).astype(np.float)) for a in ("cosu", "cost"): self.set_attribute(a, 2 * np.random.rand(self.ny + 4) - 1.) for a in ("dzt", "dzw"): self.set_attribute(a, 100 * np.random.rand(self.nz)) for a in ("flux_east", "flux_north", "flux_top", "u_wgrid", "v_wgrid", "w_wgrid"): self.set_attribute(a, np.random.randn(self.nx + 4, self.ny + 4, self.nz)) for a in ("u", "v", "w", "Hd"): self.set_attribute(a, np.random.randn(self.nx + 4, self.ny + 4, self.nz, 3)) self.set_attribute("kbot", np.random.randint(0, self.nz, size=(self.nx + 4, self.ny + 4)).astype(np.float)) numerics.calc_topo(self.veros_new) self.veros_legacy.call_fortran_routine("calc_topo") self.test_module = advection veros_args = (self.veros_new, self.veros_new.flux_east, self.veros_new.flux_north, self.veros_new.flux_top, self.veros_new.Hd[..., 1]) veros_legacy_args = dict( is_=-1, ie_=self.nx + 2, js_=-1, je_=self.ny + 2, nz_=self.nz, adv_fe=self.veros_legacy.get_fortran_attribute("flux_east"), adv_fn=self.veros_legacy.get_fortran_attribute("flux_north"), adv_ft=self.veros_legacy.get_fortran_attribute("flux_top"), var=self.veros_legacy.get_fortran_attribute("Hd")[..., 1] ) self.test_routines = OrderedDict() self.test_routines["calculate_velocity_on_wgrid"] = ((self.veros_new, ), dict()) self.test_routines.update( adv_flux_2nd=(veros_args, veros_legacy_args), adv_flux_superbee=(veros_args, veros_legacy_args), adv_flux_upwind_wgrid=(veros_args, veros_legacy_args), adv_flux_superbee_wgrid=(veros_args, veros_legacy_args) )
def setup(self): vs = self.state with vs.timers['setup']: logger.info('Setting up everything') self.set_parameter(vs) for setting, value in self.override_settings.items(): setattr(vs, setting, value) settings.check_setting_conflicts(vs) distributed.validate_decomposition(vs) vs.allocate_variables() self.set_grid(vs) numerics.calc_grid(vs) self.set_coriolis(vs) numerics.calc_beta(vs) self.set_topography(vs) numerics.calc_topo(vs) self.set_initial_conditions(vs) numerics.calc_initial_conditions(vs) streamfunction.streamfunction_init(vs) eke.init_eke(vs) for plugin in self._plugin_interfaces: plugin.setup_entrypoint(vs) vs.create_diagnostics() self.set_diagnostics(vs) diagnostics.initialize(vs) diagnostics.read_restart(vs) self.set_forcing(vs) isoneutral.check_isoneutral_slope_crit(vs)