-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwriteIce1rr_SS_Restarts.py
153 lines (134 loc) · 4.87 KB
/
writeIce1rr_SS_Restarts.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import netCDF4
import sys
import os
import glob
import numpy as np
sys.path.append('/usr/local/lib/python2.7/site-packages/')
import vtk
from vtk.util.numpy_support import vtk_to_numpy
rhow=1.028
rhoi=0.918
caseFirst='Test500m_Schoof_SSAStar_Repeated'
cases=['Test500m_Schoof_SSAStar_Repeated']
runs=['Ice1r9','Ice1r10','Ice1r11','Ice1r12','Ice1r13','Ice1r14','Ice1r15','Ice1r16','Ice1r17','Ice1r18','Ice1r19',
'Ice1r20','Ice1r21','Ice1r22','Ice1r23','Ice1r24','Ice1r25','Ice1r26','Ice1r27']
indexCases=0
#Integrales
Voldata=[]
VolSubdata=[]
AreaGdata=[]
time=[100.0,110.0,120.0,130.0,140.0,150.0,160.0,170.0,180.0,190.0,200.0,
300.0,400.0,500.0,600.0,700.0,800.0,900.0,1000.0]
for case in cases:
for run in runs:
indexFile=0
if run==runs[0]: #First data comes from previous Run
path='/home/users/merino4i/MISMIP+/'+caseFirst+'/'+run+'/'
filesIce=glob.glob(path+'*.pvtu')
filesIce.sort()
for file1 in filesIce:
file1=file1
else:
path='/home/users/merino4i/MISMIP+/'+case+'/'+run+'/'
filesIce=glob.glob(path+'*.pvtu')
filesIce.sort()
for file1 in filesIce:
file1=file1
reader = vtk.vtkXMLPUnstructuredGridReader()
print file1
reader.SetFileName(file1)
reader.Update()
output=reader.GetOutput()
Coords=vtk_to_numpy(output.GetPoints().GetData())
PointData=output.GetPointData()
numArrays=PointData.GetNumberOfArrays()
for i in np.arange(numArrays):
if PointData.GetArrayName(i)=='ssavelocity':
VarIndex=i
break
Vel=vtk_to_numpy(PointData.GetArray(VarIndex))
for i in np.arange(numArrays):
if PointData.GetArrayName(i)=='groundedmask':
VarIndex=i
break
Gl=vtk_to_numpy(PointData.GetArray(VarIndex))
for i in np.arange(numArrays):
if PointData.GetArrayName(i)=='zb':
VarIndex=i
break
Zb=vtk_to_numpy(PointData.GetArray(VarIndex))
for i in np.arange(numArrays):
if PointData.GetArrayName(i)=='zs':
VarIndex=i
break
Zs=vtk_to_numpy(PointData.GetArray(VarIndex))
for i in np.arange(numArrays):
if PointData.GetArrayName(i)=='h':
VarIndex=i
break
H=vtk_to_numpy(PointData.GetArray(VarIndex))
cellData=output.GetCellData()
pointData=output.GetPointData()
GeometryIDS=vtk_to_numpy(cellData.GetArray(0))
indexGEO=np.where(GeometryIDS==1)
#Integrales
#Volume
listPoints=set()
VolInteg=0
for i in indexGEO[0]:
#La primera celda de todas
celda1=output.GetCell(i)
ids=celda1.GetPointIds()
if ids.GetNumberOfIds()==3:
mean=0
for j in np.arange(3):
mean=mean+H[ids.GetId(j)]/3
VolLocal=mean*celda1.ComputeArea()
VolInteg=VolInteg+VolLocal
Voldata.append(VolInteg)
#Volume_Submerged
listPoints=set()
VolInteg=0
for i in indexGEO[0]:
#La primera celda de todas
celda1=output.GetCell(i)
ids=celda1.GetPointIds()
if ids.GetNumberOfIds()==3:
mean=0
for j in np.arange(3):
mean=mean+Zb[ids.GetId(j)]/3
VolLocal=mean*celda1.ComputeArea()
if VolLocal>0:
VolLocal=0
else:
VolLocal=-VolLocal
VolInteg=VolInteg+VolLocal
VolSubdata.append(VolInteg)
#Grounded Area
listPoints=set()
AreaInteg=0
for i in indexGEO[0]:
#La primera celda de todas
celda1=output.GetCell(i)
ids=celda1.GetPointIds()
if ids.GetNumberOfIds()==3:
mean=0
for j in np.arange(3):
mean=mean+Gl[ids.GetId(j)]/3
if mean>0:
AreaLocal=celda1.ComputeArea()
else:
AreaLocal=0.
AreaInteg=AreaInteg+AreaLocal
AreaGdata.append(AreaInteg)
indexFile=indexFile+1
ncfile = netCDF4.Dataset('/home/users/merino4i/output_files_MISMIP/output_files_MISMIP-/Ice1rr.nc','a')
iceVolume= ncfile.variables['iceVolume']
iceVAF= ncfile.variables['iceVAF']
groundedArea = ncfile.variables['groundedArea']
timeVar = ncfile.variables['time']
iceVolume[:]=np.array(Voldata)
groundedArea[:]=np.array(AreaGdata)
iceVAF[:]=np.array(Voldata)-np.array(VolSubdata)*(rhow/rhoi)
timeVar[:]=np.array(time)
ncfile.close()