def viebahn2014_qgmodel(N=50, H=4000. | units.m, reynolds_number=1., dm=0.04, beta0=1.8616e-11 | (units.m * units.s)**-1, L=1.e6 | units.m): rho = 1000. | units.kg / units.m**3 dx = L / N A_H = beta0 * (dm * L)**3 tau = reynolds_number * A_H * rho * beta0 * H U = tau / beta0 / rho / H / L delta_m = (A_H / beta0)**(1. / 3) / L delta_i = (U / beta0)**0.5 / L timescale = 1. / (beta0 * L) print("Viebahn 2014 setup") print("N=%i, Reynolds_number=%f" % (N, reynolds_number)) print("dm (derived):", (A_H / beta0)**(1. / 3) / L) print("tau:", tau.value_in(units.Pa)) print("A:", A_H) print("timescale:", timescale.in_(units.s)) print("delta_m:", delta_m) print("delta_i:", delta_i) nodes, elements, elev_boundary, flow_boundary = unstructured_square_domain_sets( L=L, N=N) nodes.depth = H code = Adcirc(redirection="none") code.assign_grid_and_boundary(nodes, elements, elev_boundary, flow_boundary) code.parameters.Lx = L code.parameters.use_interface_parameters = True code.parameters.use_interface_grid = True code.parameters.A_H = A_H code.parameters.timestep = 100. | units.s code.parameters.use_predictor_corrector = True code.parameters.use_interface_met_forcing = True code.parameters.use_ramping = True print("parameters:") print(code.parameters) print() x = code.forcings.x y = code.forcings.y tau_x, tau_y = single_gyre_wind_model(x, y, L, tau) forcings = code.forcings.empty_copy() channel = forcings.new_channel_to(code.forcings) forcings.coriolis_f = (1.e-4 | units.s**-1) + (beta0 * (y - L / 2)) forcings.tau_x = tau_x forcings.tau_y = tau_y channel.copy_attributes(["tau_x", "tau_y", "coriolis_f"]) return code
def initialize_adcirc(self): adcirc = Adcirc(coordinates="spherical") adcirc.assign_grid_and_boundary(self.nodes, self.elements, self._elev_boundaries, self._flow_boundaries) adcirc.parameters.use_interface_elevation_boundary = False adcirc.parameters.use_interface_parameters = True adcirc.parameters.use_interface_grid = True adcirc.parameters.A_H = 50. | units.m**2 / units.s adcirc.parameters.timestep = 30 | units.s adcirc.parameters.bottom_friction_law = "quadratic" adcirc.parameters.quadratic_bottom_friction_coeff = 0.003 adcirc.parameters.use_predictor_corrector = True adcirc.parameters.use_interface_met_forcing = True adcirc.parameters.use_interface_wave_forcing = True adcirc.parameters.central_longitude = 265.5 | units.deg adcirc.parameters.central_latitude = 29.0 | units.deg adcirc.parameters.GWCE_weighting_factor = 0.001 adcirc.parameters.calculate_coriolis = True self.adcirc = adcirc
def run(tend=5. | units.day, state=None): param=adcirc_parameter_reader("data/test/2d/fort.15") param.read_parameters(NETA=9) param.parameters['NBFR']=-1 gr=adcirc_grid_reader("data/test/2d/fort.14") gr.read_grid() nodes,elements,elev_boundary,flow_boundary=gr.get_sets() code=Adcirc() code._parameters=param.parameters code.assign_grid_and_boundary(nodes,elements,elev_boundary, flow_boundary) code.parameters.use_interface_elevation_boundary=True code.parameters.use_interface_parameters=True code.parameters.use_interface_grid=True code.parameters.A_H=param.parameters["ESLM"] | units.m**2/units.s code.parameters.timestep=abs(param.parameters["DTDP"]) | units.s code.parameters.bottom_friction_law=["linear","quadratic","hybrid"][param.parameters["NOLIBF"]] try: code.parameters.linear_bottom_friction_coeff=param.parameters["TAU"]| units.s**-1 except: pass try: code.parameters.quadratic_bottom_friction_coeff=param.parameters["CF"] except: pass code.parameters.use_predictor_corrector=param.parameters["DTDP"]<0 code.parameters.use_interface_met_forcing=False if state: nodes,elements=state if state: code.parameters.begin_time=nodes.collection_attributes.time if state: channel=nodes.new_channel_to(code.nodes) channel.copy_attributes(["eta","deta_dt","status","vx","vy"]) channel=elements.new_channel_to(code.elements) channel.copy_attributes(["status"]) tnow=code.model_time dt=code.parameters.timestep elev_boundaries= list(code.elevation_boundaries()) eta61=[] time=[] forcing=[] while tnow<tend-dt/2: elev_boundaries[0].eta=tidal_force_function(tnow+dt/2) code.evolve_model(tnow+dt) tnow=code.get_model_time() eta=code.nodes[60].eta.number time.append(tnow.number) eta61.append(eta) forcing.append(elev_boundaries[0].eta[0].number) state=code.nodes.copy(),code.elements.copy() state[0].collection_attributes.time=code.model_time print("done at:", code.model_time.in_(units.day)) code.stop() return state,time,eta61,forcing
def initialize_adcirc(self): self.read_adcirc_grid("grid.input") param=adcirc_parameter_reader("param.input") param.read_parameters(NETA=self._neta, NFLUX=self._nflux) #~ param.parameters['NBFR']=-1 param.parameters['NWS']=0 adcirc=Adcirc(coordinates="spherical", redirection="file",redirect_stdout_file="adcirc.out") adcirc.set_rootdir(os.getcwd()) #~ adcirc._parameters=param.parameters adcirc._parameters=get_default_parameter_set() adcirc._parameters["NCOR"]=1 # set coriolis f internally adcirc.assign_grid_and_boundary(self.nodes, self.elements, self._elev_boundaries, self._flow_boundaries) adcirc.parameters.use_interface_parameters=True adcirc.parameters.use_interface_grid=True if self.boundary_forcing=="elevation": adcirc.parameters.use_interface_elevation_boundary=True elif self.boundary_forcing=="flow": adcirc.parameters.use_interface_flow_boundary=True adcirc.parameters.use_interface_met_forcing=True adcirc.parameters.A_H=1000. | units.m**2/units.s #~ adcirc.parameters.A_H=param.parameters["ESLM"] | units.m**2/units.s timestep=self.timestep n=1 #~ while timestep>abs(param.parameters["DTDP"]) | units.s: while timestep>300. | units.s: n+=1 timestep=timestep/n adcirc.parameters.timestep=timestep #~ adcirc.parameters.bottom_friction_law=["linear","quadratic","hybrid"][param.parameters["NOLIBF"]] #~ adcirc.parameters.linear_bottom_friction_coeff=param.parameters["TAU"]| units.s**-1 adcirc.parameters.bottom_friction_law="hybrid" adcirc.parameters.hybrid_bottom_friction_hbreak=50. | units.m #~ adcirc.parameters.bottom_friction_law="linear" #~ adcirc.parameters.linear_bottom_friction_coeff=0.00001| units.s**-1 adcirc.parameters.quadratic_bottom_friction_coeff=0.003#param.parameters["CF"] adcirc.parameters.use_predictor_corrector=True#param.parameters["DTDP"]<0 adcirc.parameters.central_longitude=param.parameters["SLAM0"] | units.deg adcirc.parameters.central_latitude=param.parameters["SFEA0"] | units.deg adcirc.parameters.GWCE_weighting_factor=-1.#param.parameters["TAU0"] #~ adcirc.parameters.GWCE_weighting_factor=0.005 #~ adcirc.parameters.spatial_derivative_advective_term_parameter=0 #~ adcirc.parameters.time_derivative_advective_term_parameter=0 #~ adcirc.parameters.finite_amplitude_term_parameter=0 adcirc.parameters.minimum_depth=5.| units.m if self.adcirc_ramp: adcirc.parameters.use_ramping=True adcirc.parameters.ramping_time=self.adcirc_ramp print(adcirc.parameters) self.adcirc=adcirc self.adcirc_grid=adcirc.get_grid() self.adcirc_forcings_grid=StaggeredGrid(self.adcirc_grid.elements, nodes=adcirc.forcings) elements=adcirc.elements.copy(filter_attributes=lambda x,y: y in ["lat","lon","n1","n2","n3"] ) nodes=adcirc.nodes.copy(filter_attributes=lambda x,y: y in ["lat","lon"] ) self.adcirc_memory_grid = StaggeredGrid( elements, nodes=nodes )
def test2(self): tend=5*86400. | units.s param=adcirc_parameter_reader("data/test/2d/fort.15") param.read_parameters(NETA=9) gr=adcirc_grid_reader("data/test/2d/fort.14") gr.read_grid() nodes,elements,elev_boundary,flow_boundary=gr.get_sets() code=Adcirc() code._parameters=param.parameters code.assign_grid_and_boundary(nodes,elements,elev_boundary, flow_boundary) code.parameters.use_interface_elevation_boundary=False code.parameters.use_interface_parameters=True code.parameters.use_interface_grid=True code.parameters.A_H=param.parameters["ESLM"] | units.m**2/units.s code.parameters.timestep=abs(param.parameters["DTDP"]) | units.s code.parameters.bottom_friction_law=["linear","quadratic","hybrid"][param.parameters["NOLIBF"]] try: code.parameters.linear_bottom_friction_coeff=param.parameters["TAU"]| units.s**-1 except: pass try: code.parameters.quadratic_bottom_friction_coeff=param.parameters["CF"] except: pass code.parameters.use_predictor_corrector=param.parameters["DTDP"]<0 code.parameters.use_interface_met_forcing=False print(code.parameters) tnow=code.model_time dt=code.parameters.timestep elev_boundaries= list(code.elevation_boundaries()) eta61=[] time=[] forcing=[] while tnow<tend-dt/2: code.evolve_model(tnow+dt) tnow=code.get_model_time() eta=code.nodes[60].eta.number time.append(tnow.number) eta61.append(eta) forcing.append(elev_boundaries[0].eta[0].number) code.stop() from matplotlib import pyplot pyplot.ion() f=pyplot.figure(figsize=(8,6)) pyplot.show() pyplot.clf() pyplot.plot(time,eta61,'r+') pyplot.plot(time,forcing,'g+') pyplot.plot(time,tidal_force_function((time| units.s)).number) pyplot.draw() sleep(3)