def test11(self): instance = Adcirc(**default_options) instance.set_rootdir("data/test/2d") instance.evolve_model( 1 | units.hour) self.assertEqual(instance.model_time, 21*174.656| units.s) self.assertEqual(instance.nodes.status, 'wet') self.assertEqual(instance.elements.status, 'wet') instance.nodes[12].eta=0.21 | units.m self.assertEqual(instance.nodes[12].eta,0.21 | units.m) instance.nodes[12].status='dry' self.assertEqual(instance.nodes[12].status,'dry') self.assertEqual(instance.nodes[12].eta,-instance.nodes[12].depth) instance.nodes[11].deta_dt=0.1 | units.m/units.s self.assertEqual(instance.nodes[11].deta_dt,0.1 | units.m/units.s) instance.nodes[11].eta=0.21 | units.m self.assertEqual(instance.nodes[11].eta,0.21 | units.m) instance.nodes[21].vx=0.21 | units.m/units.s self.assertEqual(instance.nodes[21].vx,0.21 | units.m/units.s) instance.nodes[21].vy=0.21 | units.m/units.s self.assertEqual(instance.nodes[21].vy,0.21 | units.m/units.s) instance.stop()
def test10(self): instance = Adcirc(**default_options) instance.set_rootdir("data/test/2d") print(instance.parameters) instance.evolve_model( 1 | units.hour) self.assertEqual(instance.model_time, 21*174.656| units.s) self.assertEqual(instance.nodes.status, 'wet') self.assertEqual(instance.elements.status, 'wet') instance.stop()
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 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)