prepro.py 2.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import slimPre
import numpy as np
import math

data_dir = 'data/'
slimPre.make_directory(data_dir)

### Generate Mesh ###
from dgpy.scripts import Common
Common.genMesh("box.geo", 2)

mesh_file = 'box.msh'

print('Extruding mesh')
def shiftOperation(node, iPerBound) :
  n = [node[0], node[1] - 250, node[2]]
  return n
cutTags = ["cut"]
pasteTags = ["paste"]
mapFilename = data_dir+"periodicMesh.txt"
periodicity = (shiftOperation, cutTags, pasteTags, mapFilename)

nPart = 2
if nPart > 1:
    slimPre.dgpy.dgMeshPartition(mesh_file, nPart)
    mesh_file = mesh_file[:-4] + '_' + str(nPart) + '.msh'

mesh2d = slimPre.Mesh(mesh_file)
region_global = slimPre.Region(mesh2d)
xyz = region_global.coordinates
bath = 40 - 35 * xyz[:,0] * xyz[:,0] / 1e8
slimPre.write_file(data_dir+'bath_2d.nc', region=region_global, time=None, data=[('bath',bath)])

34
35
#slimPre.extrude(mesh_file, (data_dir+'bath_2d.nc','bath'), nb_layers=int(50), mesh_file_name_out=data_dir+'mesh3d.msh', factor_show=200, periodicity=periodicity)
slimPre.extrude(mesh_file, (data_dir+'bath_2d.nc','bath'), nb_layers=int(10), mesh_file_name_out=data_dir+'mesh3d.msh', factor_show=200, periodicity=periodicity)
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
##zLayers  = [0, .25, .5, .75, 1, 1.5, 2, 3, 4, 6, 8, 10]
##zLayers += [12 + 2*i for i in range(15)]
#zLayers = [.5 * i for i in range(1000)]
#slimPre.extrude(mesh_file, (data_dir+'bath_2d.nc','bath'), z_layers=zLayers, mesh_file_name_out=data_dir+'mesh3d.msh', factor_show=200, periodicity=periodicity)

print('Loading 3D mesh')
mesh_file = data_dir + "mesh3d.msh"
mesh = slimPre.Mesh(mesh_file)
region_global = slimPre.Region(mesh)

print('Preprocessing coriolis')
Tday = 0.99726968*24*60*60; # sidereal time of Earth revolution
OmegaEarth = 2*math.pi/Tday
latDeg = 55.
phi = (math.pi/180)*latDeg # latitude in radians
corio = 2*OmegaEarth*math.sin(phi) # // [rad/s] Coriolis parameter
slimPre.write_file(data_dir+'coriolis.nc',None,None,[('coriolis',corio)])

print('Preprocessing wind')
uwind = 0
vwind = .2
slimPre.write_file(data_dir+'wind.nc',None,None,[('u',uwind), ('v',vwind)])

print('preprocessing done')
slimPre.exit(0)