-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_basemesh.py
executable file
·95 lines (80 loc) · 2.13 KB
/
make_basemesh.py
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
34
35
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import pyvista as pv
import numpy as np
import os
import sys
import json
basedir = os.getcwd()
#################################################################################
# Inputs
#################################################################################
# Fine
xbox = [-0.2,1.2]
ybox = [-0.15,0.15]
boxdx = [0.005,0.005]
# growth rate outside of box
xgr = 1.2
ygr = 1.2
## Coarse
## Fine box limits
#xbox = [-0.15,1.15]
#ybox = [-0.15,0.15]
#boxdx = [0.02,0.015]
#
## growth rate outside of box
#xgr = 1.5
#ygr = 1.5
#
xdist = 0.8
ydist = 0.4
inputfile = sys.argv[1]
with open(inputfile) as json_file:
json_dat = json.load(json_file)
casename = json_dat['casename']
datadir = json_dat['datadir']
testfile = None #os.path.join(datadir,'CFD_DATA',casename,'design_0000','flow.vtk')
#################################################################################
# Create box
x = np.arange(xbox[0],xbox[1],boxdx[0])
y = np.arange(ybox[0],ybox[1],boxdx[1])
z = 0
# Grow outside of box
def grow_mesh(startcell,gr,dist):
dx = (startcell[1]-startcell[0])*gr
start = startcell[1]
xnew = []
temp = start
if dx > 0:
dist = start + dist
while temp <= dist:
temp += dx
xnew.append(temp)
dx *= xgr
return np.asarray(xnew)
elif dx < 0:
dist = start - dist
while temp >= dist:
temp += dx
xnew.append(temp)
dx *= xgr
xnew.reverse()
return np.asarray(xnew)
xrhs = grow_mesh(x[-2:] ,xgr,xdist)
xlhs = grow_mesh(x[1::-1] ,xgr,xdist)
yupp = grow_mesh(y[-2:] ,ygr,ydist)
ydwn = grow_mesh(y[1::-1] ,ygr,ydist)
x = np.append(np.append(xlhs,x),xrhs)
y = np.append(np.append(ydwn,y),yupp)
# Create vtk structured grid
nx = len(x)
ny = len(y)
print('nx = ', nx)
print('ny = ', ny)
print('n = ', nx*ny)
xx,yy,zz = np.meshgrid(x,y,z)
grid = pv.StructuredGrid(xx,yy,zz)
# Resample flow onto base mesh to test
if testfile is not None:
testgrid = pv.read(testfile)
grid = grid.sample(testgrid,mark_blank=False)
savefile = os.path.join(datadir,'CFD_DATA',casename,'basegrid.vtk')
grid.save(savefile)