Commit 912c03d8 authored by Philippe Delandmeter's avatar Philippe Delandmeter
Browse files

burdekin application in slim3d interface

parent 9d0a36ce
Pipeline #1239 failed with stage
in 27 minutes and 55 seconds
import slim3d
import slimPre
import shutil
output_dir = 'output/'
pre_data_dir_base = 'data_'+slimPre.partition_nb()+'/'
pre_data_dir = pre_data_dir_base+slimPre.partition_id()+'/'
slimPre.make_directory(output_dir)
shutil.copyfile(pre_data_dir_base+'mesh3d.msh', output_dir+'mesh3d.msh')
shutil.copyfile(pre_data_dir_base+'mesh3d_show.msh', output_dir+'mesh3d_show.msh')
domain = slim3d.Domain(pre_data_dir_base+'mesh3d.msh')
equations = slim3d.Slim3d_equations(domain, salinity=True)
equations.set_implicit_vertical_diffusion(True)
equations.set_vertical_viscosity('gotm')
equations.set_vertical_diffusivity('gotm')
equations.set_horizontal_viscosity('smagorinsky')
equations.set_horizontal_diffusivity('okubo')
equations.set_bottom_friction(True, z0B=0.005, z0S=0.02)
equations.set_limiter(True)
equations.set_initial_temperature('netcdf', (pre_data_dir+'initial_condition.nc', 'temperature'))
equations.set_initial_salinity('netcdf', (pre_data_dir+'initial_condition.nc', 'salinity'))
equations.set_coriolis((pre_data_dir+'coriolis.nc', 'coriolis'))
equations.set_boundary_coast('coast')
equations.set_boundary_open(['openSeaNorth', 'openSeaCentral', 'openSeaSouth'],
eta=(pre_data_dir+'open_sea.nc', 'h'),
u=(pre_data_dir+'open_sea.nc', 'u'),
v=(pre_data_dir+'open_sea.nc', 'v'),
temperature=(pre_data_dir+'initial_condition.nc', 'temperature'),
salinity=(pre_data_dir+'initial_condition.nc', 'salinity'),
transport=True)
equations.set_boundary_open('burdekinMouth',
flux=(pre_data_dir+'river_discharge.nc', 'river_discharge'),
temperature=(pre_data_dir+'initial_condition.nc', 'temperature'),
salinity=(pre_data_dir+'river_salinity.nc', 'river_salinity'))
time_loop = slim3d.Loop(equations,
maximum_2d_time_step=1,
ratio_3dvs2d_time_step=20,
export_time_step=1800,
initial_time='2007-01-01 00:00:00',
final_time='2007-02-01 00:00:00',
output_directory=output_dir)
time_loop.export_elevation()
time_loop.export_salinity()
time_loop.export_uv()
time_loop.export_uv2d()
time_loop.export_w()
time_loop.loop()
import slimPre
import numpy as np
pre_data_dir_base = 'data_'+slimPre.partition_nb()+'/'
pre_data_dir = pre_data_dir_base+slimPre.partition_id()+'/'
slimPre.make_directory(pre_data_dir)
mesh_file_name = slimPre.fetch_ftp('slim_data/burdekin/meshes/burdekin_v1.msh')
mesh_file_name = slimPre.partition_mesh(mesh_file_name, pre_data_dir+"mesh2d.msh")
initial_time = '2007-01-01 00:00:00'
final_time = '2007-02-01 00:00:00'
### Bathymetry Process ###
bath_file_name = slimPre.fetch_ftp('slim_data/burdekin/bath/bath_smooth_v1/bath_smooth_v1.idx', pre_data_dir_base)
bath_file = slimPre.fetch_ftp('slim_data/burdekin/bath/bath_smooth_v1/bath_smooth_v1_COMP_0.msh', pre_data_dir_base)
## This is only used where prepro is sequential for run in parallel ##
#### Partitioning Process ###
#nPart = 1
#if nPart > 1:
# slimPre.dgpy.dgMeshPartition(mesh_file_name, nPart)
# mesh_file_name = mesh_file_name[:-4] + '_' + str(nPart) + '.msh'
### Extrusion Process ###
nb_layers = 8
def layers_func(x, y, h):
h = max(h, 5.)
layers = [0, 0.75, 1.5, 2.25]
for z in range(nb_layers + 1 - 4) :
layers.append(3 + z * (h-3)/(nb_layers-4))
return layers
slimPre.extrude(mesh_file_name, bath_file_name, layers_function=layers_func, mesh_file_name_out=pre_data_dir_base+'mesh3d.msh', factor_show=500)
mesh_file_name = pre_data_dir_base + 'mesh3d.msh'
mesh = slimPre.Mesh(mesh_file_name, mesh_proj='+proj=utm +ellps=WGS84 +zone=55 +south')
### Coriolis Process ###
Tday = 0.99726968*24*60*60
OmegaEarth = 2*np.pi/Tday
latDeg = -19.2
corio = 2*OmegaEarth*np.sin(latDeg*(np.pi/180))
slimPre.write_file(pre_data_dir+'coriolis.nc', region=None, time=None, data=[('coriolis', corio)])
### Temperature and Salinity Process ###
slimPre.write_file(pre_data_dir+'initial_condition.nc', region=None, time=None, data=[('temperature', 15), ('salinity', 35)])
### Open Sea Process ###
print('Preprocessing Open Sea Boundary')
time = slimPre.Time(initial_time=initial_time, final_time=final_time, time_step=900.)
region = slimPre.Region(mesh, physical_tags=['openSeaNorth', 'openSeaCentral', 'openSeaSouth'])
slimPre.tpxo_tide(region, time, pre_data_dir+'open_sea.nc')
### River Discharge Process ###
print('Preprocessing River Discharge')
river_flow_file_name = slimPre.fetch_ftp('slim_data/burdekin/forcings/burdekinDischarge2007.txt', pre_data_dir)
f_flux = open(river_flow_file_name, 'r')
f_flux.readline()
year = int(f_flux.readline().split()[1])
month = int(f_flux.readline().split()[1])
day = int(f_flux.readline().split()[1])
hour = int(f_flux.readline().split()[1])
minute = int(f_flux.readline().split()[1])
second = int(f_flux.readline().split()[1])
f_flux.readline()
flux_init_time = ('%04d-%02d-%02d %02d:%02d:%02d' % (year, month, day, hour, minute, second) )
f_flux.readline()
l = f_flux.readline().split()
if l[0] != 'day':
print('Format of the file is wrong')
slimPre.exit(-1)
dt = float(l[1]) * 86400
f_flux.readline()
num_lines = sum(1 for line in open(river_flow_file_name)) - 11
t_flux = np.array([dt*j for j in range(num_lines)])
flux = np.zeros((num_lines))
for i in range(num_lines):
flux[i] = float(f_flux.readline())
time_flux = slimPre.Time(time_vector=t_flux, initial_time=flux_init_time)
slimPre.write_file(pre_data_dir+'river_discharge.nc', region=None, time=time_flux, data=[('river_discharge', flux)])
river_salinity_file_name = slimPre.fetch_ftp('slim_data/burdekin/forcings/salinityBurdekin2007.txt', pre_data_dir)
f_sal = open(river_salinity_file_name, 'r')
f_sal.readline()
year = int(f_sal.readline().split()[1])
month = int(f_sal.readline().split()[1])
day = int(f_sal.readline().split()[1])
hour = int(f_sal.readline().split()[1])
minute = int(f_sal.readline().split()[1])
second = int(f_sal.readline().split()[1])
f_sal.readline()
sal_init_time = ('%04d-%02d-%02d %02d:%02d:%02d' % (year, month, day, hour, minute, second) )
f_sal.readline()
l = f_sal.readline().split()
if l[0] != 'day':
print('Format of the file is wrong')
slimPre.exit(-1)
dt = float(l[1]) * 86400
l = f_sal.readline().split()
if l[0] != 'hour':
print('Format of the file is wrong')
slimPre.exit(-1)
dt = dt + float(l[1]) * 3600
l = f_sal.readline().split()
if l[0] != 'minute':
print('Format of the file is wrong')
slimPre.exit(-1)
dt = dt + float(l[1]) * 60
l = f_sal.readline().split()
if l[0] != 'second':
print('Format of the file is wrong')
slimPre.exit(-1)
dt = dt + float(l[1])
f_sal.readline()
num_lines = sum(1 for line in open(river_salinity_file_name)) - 14
t_sal = np.array([dt*j for j in range(num_lines)])
sal = np.zeros((num_lines))
for i in range(num_lines):
sal[i] = float(f_sal.readline())
time_sal = slimPre.Time(time_vector=t_sal, initial_time=sal_init_time)
slimPre.write_file(pre_data_dir+'river_salinity.nc', region=None, time=time_sal, data=[('river_salinity', sal)])
print( 'Preprocessing done ' )
slimPre.exit(0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment