1 | #!/usr/bin/env python |
---|
2 | import os |
---|
3 | |
---|
4 | class EnsPythonCut(object): |
---|
5 | def __init__(self, filename): |
---|
6 | self.filename = filename |
---|
7 | |
---|
8 | self.fileid = open(filename,"w") |
---|
9 | |
---|
10 | self.ppdir = os.path.dirname(filename) |
---|
11 | |
---|
12 | def writeHeader(self): |
---|
13 | """Header Of all ensight python scripts""" |
---|
14 | self.fileid.write(""" |
---|
15 | |
---|
16 | #image resolution and filename |
---|
17 | XRESOLUTION=800 |
---|
18 | YRESOLUTION=600 |
---|
19 | COLORMIN=0 |
---|
20 | COLORMAX=1 |
---|
21 | OUTPATHFILE='./' # trailing / needed ! |
---|
22 | CASEFILE='{0}' |
---|
23 | |
---|
24 | ensight.part.select_default() |
---|
25 | ensight.part.modify_begin() |
---|
26 | ensight.part.elt_representation("3D_feature_2D_full") |
---|
27 | ensight.part.modify_end() |
---|
28 | ensight.data.binary_files_are("native") |
---|
29 | ensight.data.format("Xdmf2") |
---|
30 | ensight.data.shift_time(1.000000,0.000000,0.000000) |
---|
31 | ensight.data.replace(CASEFILE) |
---|
32 | """.format(os.path.join(self.ppdir,'c3sm_xdmfgroup.xmf'))) |
---|
33 | self.fileid.flush() |
---|
34 | |
---|
35 | def writeBody(self,cuttype,direction,pos,var,list_ids): |
---|
36 | """Make cuts and save images""" |
---|
37 | |
---|
38 | self.fileid.write(""" |
---|
39 | print "Defining functions ...", |
---|
40 | |
---|
41 | def print_image(file): |
---|
42 | |
---|
43 | ensight.file.image_format("gif") |
---|
44 | ensight.file.image_format_options("Compression Default") |
---|
45 | ensight.anim_recorders.render_offscreen("ON") |
---|
46 | ensight.file.image_numpasses(4) |
---|
47 | ensight.file.image_stereo("current") |
---|
48 | ensight.file.image_screen_tiling(1,1) |
---|
49 | ensight.file.image_file(OUTPATHFILE+file) |
---|
50 | ensight.file.image_window_size("user_defined") |
---|
51 | ensight.file.image_window_xy(XRESOLUTION,YRESOLUTION) |
---|
52 | ensight.file.save_image() |
---|
53 | |
---|
54 | return |
---|
55 | |
---|
56 | def cut(axis,value,part): |
---|
57 | ensight.part.select_begin(part) |
---|
58 | ensight.clip.begin() |
---|
59 | ensight.clip.mesh_plane(axis) |
---|
60 | ensight.clip.value(value) |
---|
61 | ensight.clip.tool("xyz") |
---|
62 | ensight.clip.end() |
---|
63 | ensight.clip.create() |
---|
64 | ensight.clip.domain("crinkly") |
---|
65 | ensight.part.select_end(part) |
---|
66 | |
---|
67 | return |
---|
68 | |
---|
69 | def cylinder(Origin,axis,radius,part): |
---|
70 | ensight.part.select_begin(part) |
---|
71 | ensight.clip.begin() |
---|
72 | ensight.clip.extents("infinite") |
---|
73 | ensight.clip.tool("cylinder") |
---|
74 | ensight.clip.origin(Origin[0],Origin[1],Origin[2]) |
---|
75 | ensight.clip.axis(axis[0],axis[1],axis[2]) |
---|
76 | ensight.clip.radius(radius) |
---|
77 | ensight.clip.end() |
---|
78 | ensight.clip.create() |
---|
79 | ensight.part.select_end(part) |
---|
80 | |
---|
81 | def color(variable,part): |
---|
82 | ensight.part.select_begin(part) |
---|
83 | ensight.part.modify_begin() |
---|
84 | ensight.part.colorby_palette(variable) |
---|
85 | ensight.function.palette("abspress") |
---|
86 | ensight.function.range(COLORMIN,COLORMAX) |
---|
87 | ensight.part.modify_end() |
---|
88 | ensight.part.select_end(part) |
---|
89 | |
---|
90 | return |
---|
91 | |
---|
92 | def hide(part): |
---|
93 | ensight.part.select_begin(part) |
---|
94 | ensight.part.modify_begin() |
---|
95 | ensight.part.visible("OFF") |
---|
96 | ensight.part.modify_end() |
---|
97 | ensight.part.select_end(part) |
---|
98 | |
---|
99 | def hide_legend(variable): |
---|
100 | ensight.legend.select_palette_begin(variable) |
---|
101 | ensight.legend.visible("OFF") |
---|
102 | |
---|
103 | |
---|
104 | def legend(variable,VARTITLE,var_range_min,var_range_max): |
---|
105 | ensight.function.palette(variable) |
---|
106 | ensight.function.modify_begin() |
---|
107 | ensight.function.range(float(var_range_min),float(var_range_max)) |
---|
108 | ensight.legend.select_palette_begin(variable) |
---|
109 | ensight.legend.title_name(VARTITLE) |
---|
110 | ensight.legend.format("%.2f") |
---|
111 | |
---|
112 | print "Done" |
---|
113 | |
---|
114 | #ensight.sendmesgoptions(exception=1,display=1) |
---|
115 | ensight.viewport.select_begin(0) |
---|
116 | ensight.viewport.background_type("constant") |
---|
117 | ensight.viewport.select_end(0) |
---|
118 | |
---|
119 | |
---|
120 | """) |
---|
121 | |
---|
122 | self.fileid.write(cuttype+"('"+direction+"','"+pos+"',1)\n") |
---|
123 | self.fileid.write("hide(1)\n") |
---|
124 | self.fileid.write("color('"+var+"',2)\n") |
---|
125 | self.fileid.write("legend('"+var+"','"+var+"',0,1)\n") |
---|
126 | |
---|
127 | self.fileid.write("ensight.part.select_begin(2)\n") |
---|
128 | self.fileid.write("ensight.view_transf.view_recall('+"+direction+"')\n") |
---|
129 | self.fileid.write("ensight.view_transf.fit(2)\n") |
---|
130 | self.fileid.write("ensight.part.select_end(2)\n") |
---|
131 | |
---|
132 | |
---|
133 | self.fileid.write(""" |
---|
134 | ensight.text.new_text('Simulation') |
---|
135 | ensight.text.location_x(5.000000e-01) |
---|
136 | ensight.text.location_y(1.50000e-01) |
---|
137 | ensight.text.size(40) |
---|
138 | """) |
---|
139 | |
---|
140 | |
---|
141 | for current_step in range(0,len(list_ids)): |
---|
142 | |
---|
143 | self.fileid.write("ensight.solution_time.current_step("+str(current_step)+")\n") |
---|
144 | self.fileid.write("ensight.solution_time.update_to_current()\n") |
---|
145 | self.fileid.write("ensight.text.select_begin(0)\n") |
---|
146 | self.fileid.write("ensight.text.change_text('"+list_ids[current_step].replace("#","<cr>")+"')\n") |
---|
147 | self.fileid.write("ensight.text.select_end(0)\n") |
---|
148 | #fileid.write('ensight.file.image_convert("ON")\n') |
---|
149 | self.fileid.write("print_image('./"+var+"_"+str(current_step)+"_"+list_ids[current_step].replace("#","_")+"')\n") |
---|
150 | #fileid.write('ensight.file.image_convert("OFF")\n') |
---|
151 | |
---|
152 | self.fileid.flush() |
---|
153 | |
---|
154 | def close(self): |
---|
155 | self.fileid.close() |
---|
156 | |
---|
157 | |
---|
158 | if __name__ == '__main__': |
---|
159 | pass # Do tests |
---|