def test_point_source_1d(): """ Create a 1D water column, with a point source at the bed. Verifies that all cells with valid thickness (dzz>0.001m) have near unity salinity. """ g=unstructured_grid.UnstructuredGrid(max_sides=4) g.add_rectilinear([0,0],[10,10],2,2) g.add_cell_field('depth',-6*np.ones(g.Ncells())) model=sun_driver.SuntansModel() model.load_template('point_source_test.dat') model.set_grid(g) model.run_start=np.datetime64("2018-01-01 00:00") model.run_stop =np.datetime64("2018-01-01 10:00") source=sun_driver.SourceSinkBC(name='inflow',geom=np.array([5,5]), z=-10,Q=1.0) model.add_bcs(source) model.add_bcs( [sun_driver.ScalarBC(parent=source,scalar="S",value=1), sun_driver.ScalarBC(parent=source,scalar="T",value=1)] ) model.set_run_dir('rundata_point_1d', mode='pristine') model.projection='EPSG:26910' model.config['dt']=2.5 model.config['ntout']=1 model.config['Cmax']=30 model.config['Nkmax']=10 model.config['stairstep']=0 model.config['mergeArrays']=0 model.write() model.ic_ds.eta.values[:]=-5.999 model.ic_ds.salt.values[:]=1.0 model.ic_ds.temp.values[:]=1.0 model.write_ic_ds() model.partition() model.sun_verbose_flag='-v' model.run_simulation() ds=xr.open_dataset(model.map_outputs()[0]) dzz=ds.dzz.values dzz_thresh=0.001 salt=ds.salt.values salt_errors=salt[dzz>=dzz_thresh] - 1.0 assert np.max( np.abs(salt_errors) )<0.001
def base_model(): """ Channel """ g=unstructured_grid.UnstructuredGrid(max_sides=4) g.add_rectilinear([0,0],[1000,100],21,3) g.add_cell_field('depth',-6*np.ones(g.Ncells())) model=sun_driver.SuntansModel() model.load_template('point_source_test.dat') model.set_grid(g) model.run_start=np.datetime64("2018-01-01 00:00") model.run_stop =np.datetime64("2018-01-05 00:00") dt=np.timedelta64(600,'s') times=np.arange(model.run_start-dt,model.run_stop+2*dt,dt) secs=(times-times[0])/np.timedelta64(1,'s') eta0=-1 eta_bc=sun_driver.StageBC(name="eta_bc", geom=np.array([ [0,0], [0,100]]), z=eta0) model.add_bcs(eta_bc) model.add_bcs( [sun_driver.ScalarBC(parent=eta_bc,scalar="S",value=34), sun_driver.ScalarBC(parent=eta_bc,scalar="T",value=15)] ) model.set_run_dir('rundata_met_3d', mode='pristine') model.projection='EPSG:26910' model.num_procs=1 # test single first model.config['dt']=120 model.config['ntout']=5 model.config['Cmax']=30 model.config['Nkmax']=10 model.config['stairstep']=0 model.config['mergeArrays']=0 return model
def base_model_setup(L=100, dx=10): g = unstructured_grid.UnstructuredGrid(max_sides=4) g.add_rectilinear([0, 0], [L, 10], 1 + int(L / dx), 2) g.add_cell_field('depth', -6 * np.ones(g.Ncells())) model = sun_driver.SuntansModel() model.num_procs = 1 model.load_template('point_source_test.dat') model.set_grid(g) model.run_start = np.datetime64("2018-01-01 00:00") model.run_stop = np.datetime64("2018-01-02 00:00") # 50m2, 5.0 m3/s, 0.1m/s source = sun_driver.FlowBC(name='inflow', geom=np.array([[0, 0], [0, 10]]), Q=10.0) outlet = sun_driver.StageBC(name='outflow', geom=np.array([[100, 0], [100, 10]]), z=-1) model.add_bcs([source, outlet]) model.set_run_dir('rundata_2d_average', mode='pristine') model.projection = 'EPSG:26910' model.config['dt'] = 2.5 model.config['ntout'] = 100 model.config['ntaverage'] = 100 model.config['calcaverage'] = 1 model.config['averageNetcdfFile'] = "average.nc" model.config['thetaramptime'] = 100 model.config['Cmax'] = 2 model.config['Nkmax'] = 1 model.config['stairstep'] = 0 model.config['mergeArrays'] = 0 return model
import numpy as np import xarray as xr import pandas as pd from stompy import filters, utils from stompy.spatial import wkb2shp from stompy.grid import unstructured_grid from stompy.model.suntans import sun_driver as drv import stompy.model.delft.dflow_model as dfm six.moves.reload_module(utils) six.moves.reload_module(dfm) six.moves.reload_module(unstructured_grid) six.moves.reload_module(drv) model=drv.SuntansModel() model.projection="EPSG:26910" model.num_procs=1 model.sun_bin_dir="/home/rusty/src/suntans/main" model.mpi_bin_dir="/usr/bin" model.load_template("sun-template.dat") # backstep_00: initial... clobbered. # 01: nu_H 0.0 => 0.25 model.set_run_dir(os.path.join('runs',"backstep_01"), mode='pristine') model.run_start=np.datetime64('2017-03-01 00:00:00') model.run_stop=np.datetime64('2017-03-01 04:00:00')
cc = g.cells_center() cell_depth = -6 + np.cos(cc[:, 0] * np.pi / half_wave) * np.cos( cc[:, 1] * np.pi / half_wave) g.add_cell_field('depth', cell_depth) #plt.clf() #g.plot_cells(values=cell_depth,cmap='jet') #plt.axis('equal') ## n1 = g.select_nodes_nearest([300, 0]) n2 = g.select_nodes_nearest([300, 500]) model = sun_driver.SuntansModel() model.load_template('sun-template.dat') model.set_grid(g) model.run_start = np.datetime64("2018-01-01 00:00") model.run_stop = np.datetime64("2018-01-01 10:00") dt = np.timedelta64(600, 's') times = np.arange(model.run_start - dt, model.run_stop + 2 * dt, dt) secs = (times - times[0]) / np.timedelta64(1, 's') eta_values = -6 + 0.75 * np.cos(secs * np.pi / 7200) eta_da = xr.DataArray(eta_values, coords=[('time', times)]) eta_bc = sun_driver.StageBC(name="eta_bc", geom=np.array([[0, 0], [0, 500]]), z=eta_da) model.add_bcs(eta_bc)
def test_point_source_3d(): """ A square 3D grid with wetting and drying. the bathymetry is a wavy cos(x)*cos(y) function. two point sources and an oscillating freesurface. one point source at a saddle point, and the other on top of a bump which goes dry. This currently does pretty well, but it could be better -- see the test thresholds near the end which have been relaxed somewhat. """ g=unstructured_grid.UnstructuredGrid(max_sides=4) g.add_rectilinear([0,0],[500,500],50,50) # wavy bed half_wave=150 cc=g.cells_center() cell_depth=-6 + np.cos(cc[:,0]*np.pi/half_wave) * np.cos(cc[:,1]*np.pi/half_wave) g.add_cell_field('depth',cell_depth) model=sun_driver.SuntansModel() model.load_template('point_source_test.dat') model.set_grid(g) model.run_start=np.datetime64("2018-01-01 00:00") model.run_stop =np.datetime64("2018-01-01 10:00") dt=np.timedelta64(600,'s') times=np.arange(model.run_start-dt,model.run_stop+2*dt,dt) secs=(times-times[0])/np.timedelta64(1,'s') eta_values=-6 + 0.75*np.cos(secs*np.pi/7200) eta_da=xr.DataArray(eta_values,coords=[ ('time',times) ]) eta_bc=sun_driver.StageBC(name="eta_bc",geom=np.array([ [0,0], [0,500]]), z=eta_da) model.add_bcs(eta_bc) model.add_bcs( [sun_driver.ScalarBC(parent=eta_bc,scalar="S",value=1), sun_driver.ScalarBC(parent=eta_bc,scalar="T",value=1)] ) # point source that is typically dry hill_source=sun_driver.SourceSinkBC(name='inflow',geom=np.array([150,150]), z=-10,Q=1.0) # on a saddle saddle_source=sun_driver.SourceSinkBC(name='inflow',geom=np.array([220,225]), z=-10,Q=1.0) model.add_bcs(hill_source) model.add_bcs(saddle_source) model.add_bcs( [sun_driver.ScalarBC(parent=hill_source,scalar="S",value=1), sun_driver.ScalarBC(parent=hill_source,scalar="T",value=1)] ) model.add_bcs( [sun_driver.ScalarBC(parent=saddle_source,scalar="S",value=1), sun_driver.ScalarBC(parent=saddle_source,scalar="T",value=1)] ) model.set_run_dir('rundata_point_3d', mode='pristine') model.projection='EPSG:26910' model.num_procs=4 model.config['dt']=2.5 model.config['ntout']=5 model.config['Cmax']=30 model.config['Nkmax']=10 model.config['stairstep']=0 model.config['mergeArrays']=0 model.write() model.ic_ds.eta.values[:]=eta_da.values[1] model.ic_ds.salt.values[:]=1.0 model.ic_ds.temp.values[:]=1.0 model.write_ic_ds() model.partition() model.sun_verbose_flag='-v' model.run_simulation() for map_fn in model.map_outputs(): ds=xr.open_dataset(map_fn) dzz=ds.dzz.values # This is not as strict as it should be. # should be 0.001 or less. dzz_thresh=0.05 salt=ds.salt.values valid=np.isfinite(dzz) & (dzz>=dzz_thresh) salt_errors=salt[valid] - 1.0 # This is not as strict as it should be. # we should be able to get this down to 1e-4 or # better. assert np.max( np.abs(salt_errors) )<0.01 ds.close()
six.moves.reload_module(local_config) local_config.install() ## # fabricate grid: g = unstructured_grid.UnstructuredGrid(max_sides=4) L = 10000 W = 75 g.add_rectilinear([0, 0], [L, W], 101, 6) g.add_node_field('z_bed', -(10 - 8 * (2 * g.nodes['x'][:, 1] / W - 1)**2)) #model=dfm.DFlowModel() six.moves.reload_module(dfm) six.moves.reload_module(sun) local_config.install() model = sun.SuntansModel() model.set_grid(g) model.run_start = np.datetime64("2010-01-01 00:00") model.run_stop = np.datetime64("2010-01-05 00:00") ds = xr.Dataset() ds['time'] = ('time', ), np.arange(model.run_start, model.run_stop, np.timedelta64(15, 'm')) t_sec = (ds.time - ds.time[0]) / np.timedelta64(1, 's') ds['eta'] = ('time', ), np.cos(2 * np.pi * t_sec / (12 * 3600.)) model.add_bcs( dfm.StageBC(name='tide', z=ds.eta, geom=np.array([[0, 0], [0, W]]))) dt_secs = 30
def base_model(): """ A channel, uniform bathy. """ g=unstructured_grid.UnstructuredGrid(max_sides=4) g.add_rectilinear([0,0],[1000,100],21,3) g.add_cell_field('depth',-6*np.ones(g.Ncells())) model=sun_driver.SuntansModel() model.load_template('point_source_test.dat') model.set_grid(g) model.run_start=np.datetime64("2018-01-01 00:00") model.run_stop =np.datetime64("2018-01-01 10:00") dt=np.timedelta64(600,'s') times=np.arange(model.run_start-dt,model.run_stop+2*dt,dt) secs=(times-times[0])/np.timedelta64(1,'s') eta0=-2 eta_bc=sun_driver.StageBC(name="eta_bc", geom=np.array([ [0,0], [0,100]]), z=eta0) model.add_bcs(eta_bc) model.add_bcs( [sun_driver.ScalarBC(parent=eta_bc,scalar="S",value=1), sun_driver.ScalarBC(parent=eta_bc,scalar="T",value=1)] ) model.set_run_dir('rundata_sedi_3d', mode='pristine') model.projection='EPSG:26910' model.num_procs=1 # test single first model.config['dt']=30 model.config['ntout']=5 model.config['Cmax']=30 model.config['Nkmax']=10 model.config['stairstep']=0 model.config['mergeArrays']=0 # Sediment: model.config['computeSediments']=1 # whether include sediment model model.config['Nlayer']=0 # Number of bed layers (MAX = 5) model.config['Nsize']=3 # Number of sediment fractions (Max = 3) model.config['TBMAX']=1 # whether to output tb for each cell model.config['SETsediment']=0 # When Nlayer>5 or Nsize>3, SETsediment=1 to use SetSediment model.config['WSconstant']=1 # if 1, ws for sediment = ws0 model.config['readSediment']=0 # if 1, read sediment concentration data as IC. only work with Nsize==1 model.config['bedInterval']=150 # the interval steps to update bed change model.config['bedComplex']=0 # whether to consider the possibility to flush away a whole layer model.config['ParabolKappa']=0 # whether to use parabolic tubulent diffusivity model.config['Ds90']=0.000008 # ds90 for calculation of erosion taub model.config['Ds1']=0.00000057 # sediment diameter for fraction No.1 (m) model.config['Ds2']=0.0002 # sediment diameter for fraction No.2 model.config['Ds3']=0.0002 # sediment diameter for fraction No.3 model.config['Ws01']= 0.0001 # constant settling velocity for fraction No.1 (m/s) model.config['Ws02']= 0.01 # constant settling velocity for fraction No.2 model.config['Ws03']=-0.01 # constant settling velocity for fraction No.3 model.config['Gsedi1']=2.65 # relative density for fraction No.1 model.config['Gsedi2']=2.65 # relative density for fraction No.2 model.config['Gsedi3']=2.65 # relative density for fraction No.3 model.config['Prt1']=1 # Prandtl Number for fraction No.1 model.config['Prt2']=1 # Prandtl Number for fraction No.2 model.config['Prt3']=1 # Prandtl Number for fraction No.3 model.config['Consolid1']=0.00 # Consolidation rate (g/m^2/s) for layer No.1 model.config['E01']=0.1 # Basic Erosion Rate Constant (g/m^2/s) for layer No.1 model.config['Taue1']=0.0 # Erosion Critical Shear Stress (N/m^2) for layer No.1 # Taud1 isn't actually used in current code. Deposition always occurs at the rate # of w_s. model.config['Taud1']=0.0 # Deposition Critical Shear Stress (N/m^2) for layer No.1 model.config['Drydensity1']=530000 # Dry density (g/m^3) for layer No.1 model.config['Thickness1']=0.0 # Thickness (m) for layer No.1 model.config['softhard1']=1 # 0 soft or hard for layer No.1 to decide how to calculate erosion model.config['Bedmudratio1']=0.8 # Bed mud ratio for layer No.1 model.config['Chind']=1000000 # Concentration (in volumetric fraction) criterion for hindered settling velocity model.config['Cfloc']=500000 # Concentration (in volumetric fraction) criterion for flocculated settling velcoity model.config['k']=0.0002 # Constant coefficient for settling velocity as a function of conc. model.config['Sediment1File']='sedi1.dat' model.config['Sediment2File']='sedi2.dat' model.config['Sediment3File']='sedi3.dat' model.config['LayerFile']='sedilayer.dat' model.config['tbFile']='Seditb.dat' model.config['tbmaxFile']='Seditbmax.dat' return model