-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisit_isocontour_rate.py
More file actions
153 lines (137 loc) · 5.34 KB
/
Copy pathvisit_isocontour_rate.py
File metadata and controls
153 lines (137 loc) · 5.34 KB
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
153
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 14 09:45:28 2022
@author: mmeierdo
"""
import visit
import os, shutil
import sys
path = "/mmfs1/home/mmeierdo/homogeneous"
save_folder = "curve"
extended_file = "celloutput.visit" #"nodeoutput.visit"
remove_existing_folder = 1 # 0 doesnt remove and cancel process, 1 removes the folder
var = os.listdir(path)
#var = ["output-2d"] # Overwrite list of directories
print(var)
def savepic(path):
SaveWindowAtts = SaveWindowAttributes()
SaveWindowAtts.outputToCurrentDirectory = 0
SaveWindowAtts.outputDirectory = path
SaveWindowAtts.fileName = "lasframe"
SaveWindowAtts.family = 1
SaveWindowAtts.format = SaveWindowAtts.PNG # BMP, CURVE, JPEG, OBJ, PNG, POSTSCRIPT, POVRAY, PPM, RGB, STL, TIFF, ULTRA, VTK, PLY, EXR
SaveWindowAtts.width = 1024
SaveWindowAtts.height = 1024
SaveWindowAtts.screenCapture = 0
SaveWindowAtts.saveTiled = 0
SaveWindowAtts.quality = 80
SaveWindowAtts.progressive = 0
SaveWindowAtts.binary = 0
SaveWindowAtts.stereo = 0
SaveWindowAtts.compression = SaveWindowAtts.NONE # NONE, PackBits, Jpeg, Deflate, LZW
SaveWindowAtts.forceMerge = 0
SaveWindowAtts.resConstraint = SaveWindowAtts.ScreenProportions # NoConstraint, EqualWidthHeight, ScreenProportions
SaveWindowAtts.pixelData = 1
SaveWindowAtts.advancedMultiWindowSave = 0
SaveWindowAtts.opts.types = ()
SaveWindowAtts.opts.help = ""
SetSaveWindowAttributes(SaveWindowAtts)
SaveWindow()
def read_metadata(path):
a={}
with open(path + "/metadata") as f:
for line in f:
if line[0] != "#" and line[0] != "\n" and line[0] != " ":
k,v = line.split(" = ")
v = v.split(" #")[0]
a[k] = v
special = ["geometry.prob_lo", "geometry.prob_hi", "amr.n_cell", "phi.ic.laminate.center"]
for i in a.keys():
a[i] = a[i].replace("\n", "")
if " " in a[i]:
if i not in special:
a[i] = a[i].replace(" ", '')
steps = 50
if "amr.plot_dt" in a.keys():
plot_dt = float(a["amr.plot_dt"])
else:
plot_dt = float(a["timestep"]) * float(a["amr.plot_int"])
if a["Status"][0] == "C":
try:
steps = float(a["stop_time"]) / plot_dt
except:
steps = float(a["stop_time"]) / float(a["plot_int"])
else:
g = ""
for i in a["Status"]:
if i <= '9' and i >= '0':
g += i
steps = float(g) / 100 * float(a["stop_time"]) / plot_dt
return steps
def isocontour_loop(path, steps, folder = "curves", nodecell = "celloutput.visit", save_lastframe = False):
OpenDatabase("localhost:"+path+"/"+nodecell, 0)
AddPlot("Contour", "eta", 1, 1)
ContourAtts = ContourAttributes()
ContourAtts.contourNLevels = 1
ContourAtts.contourValue = ()
ContourAtts.contourPercent = ()
ContourAtts.contourMethod = ContourAtts.Level
ContourAtts.minFlag = 0
ContourAtts.maxFlag = 0
ContourAtts.min = 0.5
ContourAtts.max = 0.5
ContourAtts.scaling = ContourAtts.Linear # Linear, Log
ContourAtts.wireframe = 0
SetPlotOptions(ContourAtts)
DrawPlots()
for i in range(int(steps)):
SaveWindowAtts = SaveWindowAttributes()
SaveWindowAtts.format = SaveWindowAtts.CURVE # BMP, CURVE, JPEG, OBJ, PNG, POA, VTK, PLY, EXR
SaveWindowAtts.outputToCurrentDirectory = 0
SaveWindowAtts.outputDirectory = path+"/"+folder
SaveWindowAtts.fileName = "visit"
SaveWindowAtts.family = 1
SaveWindowAtts.width = 1024
SaveWindowAtts.height = 1024
SaveWindowAtts.screenCapture = 0
SaveWindowAtts.saveTiled = 0
SaveWindowAtts.quality = 80
SaveWindowAtts.progressive = 0
SaveWindowAtts.binary = 0
SaveWindowAtts.stereo = 0
SaveWindowAtts.compression = SaveWindowAtts.NONE
SaveWindowAtts.forceMerge = 0
SaveWindowAtts.resConstraint = SaveWindowAtts.ScreenProportions # NoConstraint, EqualWidthHeight, ScreenProportions
SaveWindowAtts.pixelData = 1
SaveWindowAtts.advancedMultiWindowSave = 0
SaveWindowAtts.opts.types = (5)
SaveWindowAtts.opts.help = ""
SetSaveWindowAttributes(SaveWindowAtts)
SaveWindow()
if i == steps-1 and save_lastframe == True:
savepic(path)
TimeSliderNextState()
DeleteActivePlots()
OpenDatabase("localhost:"+path+"/"+nodecell)
counter = 0
total = len(var)
for record in var:
record_path = os.path.join(path,record)
if not os.path.isdir(record_path):
raise ValueError("This record does not exist")
if not os.path.isfile(record_path+"/"+extended_file):
raise ValueError(f"{extended_file} does not exist")
try:
os.mkdir(record_path+"/"+save_folder)
except:
if remove_existing_folder == 1:
shutil.rmtree(record_path+"/"+save_folder)
os.mkdir(record_path+"/"+save_folder)
else:
raise ValueError("Trying to create folder that already exists")
steps = read_metadata(record_path)
isocontour_loop(record_path, steps, folder = save_folder, nodecell=extended_file)
counter += 1
print(f"Processed {counter}/{total}"
print(f"{counter} total records were sucessfully processed")