-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdriven_cavity_noslip.shml
224 lines (206 loc) · 8.02 KB
/
driven_cavity_noslip.shml
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?xml version='1.0' encoding='utf-8'?>
<harness_options>
<length>
<string_value lines="1">short</string_value>
</length>
<owner>
<string_value lines="1">cwilson</string_value>
</owner>
<description>
<string_value lines="1">A driven cavity example for stokes</string_value>
</description>
<simulations>
<simulation name="DrivenCavity">
<input_file>
<string_value lines="1" type="filename">driven_cavity/noslip/driven_cavity.tfml</string_value>
</input_file>
<run_when name="input_changed_or_output_missing"/>
<parameter_sweep>
<parameter name="dmu">
<values>
<string_value lines="1">1.0</string_value>
</values>
<update>
<string_value lines="20" type="code" language="python">import libspud
if float(dmu) <= 0.0:
import sys
print "ERROR: dmu must be greater than 0!"
sys.exit(1)
libspud.set_option("/system::Stokes/coefficient::ViscosityJumpFactor/type/rank/value/constant", float(dmu))</string_value>
<single_build/>
</update>
</parameter>
<parameter name="ncells">
<values>
<string_value lines="1">32</string_value>
</values>
</parameter>
</parameter_sweep>
<dependencies>
<run name="Mesh">
<input_file>
<string_value lines="1" type="filename">driven_cavity/unitsquare.geo</string_value>
</input_file>
<run_when name="input_changed_or_output_missing"/>
<parameter_sweep>
<parameter name="ncells">
<update>
<string_value lines="20" type="code" language="python">from string import Template as template
if int(ncells) <= 0:
import sys
print "ERROR: ncells must be greater than 0!"
sys.exit(1)
input_file = template(input_file).safe_substitute({'ncells':ncells})</string_value>
</update>
</parameter>
</parameter_sweep>
<required_output>
<filenames name="Mesh">
<string>
<string_value lines="1" type="filename">unitsquare.xml.gz</string_value>
</string>
</filenames>
</required_output>
<commands>
<command name="GMsh">
<string_value lines="1">gmsh -2 unitsquare.geo</string_value>
</command>
<command name="Convert">
<string_value lines="1">dolfin-convert unitsquare.msh unitsquare.xml</string_value>
</command>
<command name="GZip">
<string_value lines="1">gzip unitsquare.xml</string_value>
</command>
</commands>
</run>
</dependencies>
<variables>
<variable name="vtudata">
<string_value lines="20" type="code" language="python">import buckettools.vtktools as vtktools
import os
from lxml import etree
from buckettools.threadlibspud import *
from matplotlib.tri import Triangulation
def lastvtuinpvd(filename):
assert(filename[-4:]==".pvd")
dirname = os.path.dirname(filename)
tree = etree.parse(filename)
vtunames = [[element.attrib['timestep'], os.path.join(dirname, element.attrib['file'])] for element in tree.getroot().iterdescendants(tag="DataSet")]
sortedvtunames = sorted(vtunames, key=lambda entry: float(entry[0]))
return sortedvtunames[-1][-1]
filename = os.path.split(input_filename)[-1]
threadlibspud.load_options(filename)
basename = libspud.get_option("/io/output_base_name")
threadlibspud.clear_options()
vtufilename = lastvtuinpvd(basename+".pvd")
vtu = vtktools.vtu(vtufilename)
vtulocations = vtu.GetLocations()
triangles = []
for c in xrange(vtu.ugrid.GetNumberOfCells()):
points = vtu.GetCellPoints(c)
triangles.append(points)
triang = Triangulation(vtulocations[:,0], vtulocations[:,1], triangles)
v = vtu.GetField("Stokes::Velocity")
p = vtu.GetField("Stokes::Pressure")
vtudata = [triang, vtulocations, v, p]</string_value>
</variable>
<variable name="rmsvelocities">
<string_value lines="20" type="code" language="python">from buckettools.statfile import parser
from buckettools.threadlibspud import *
import os
filename = os.path.split(input_filename)[-1]
threadlibspud.load_options(filename)
basename = libspud.get_option("/io/output_base_name")
threadlibspud.clear_options()
stat = parser(basename+".stat")
vrms = stat["Stokes"]["VelocityL2NormSquared"]["functional_value"][-1]**0.5
vrmsu = stat["Stokes"]["VelocityL2NormSquaredUpper"]["functional_value"][-1]**0.5
vrmsl = stat["Stokes"]["VelocityL2NormSquaredLower"]["functional_value"][-1]**0.5
rmsvelocities = [vrms, vrmsu, vrmsl]</string_value>
</variable>
<variable name="errfile">
<string_value lines="20" type="code" language="python">err = file("terraferma.err-0", 'r')
errfile = [line for line in err.readlines() if not line.startswith("WARNING:")]</string_value>
</variable>
<variable name="havedisplay">
<string_value lines="20" type="code" language="python">import os
exitval = os.system('python -c "import matplotlib.pyplot as plt; plt.figure()"')
havedisplay = (exitval == 0) and "DISPLAY" in os.environ</string_value>
</variable>
</variables>
</simulation>
</simulations>
<tests>
<test name="errors">
<string_value lines="20" type="code" language="python">noerrors = True
for dmu in errfile.parameters['dmu']:
for ncells in errfile.parameters['ncells']:
if len(errfile[{'dmu':dmu, 'ncells':ncells}]) > 0:
print "ERROR: dmu = {}, ncells produced an unexpected error!".format(dmu, ncells)
noerrors = False
assert(noerrors)</string_value>
</test>
<test name="rmsvelocities">
<string_value lines="20" type="code" language="python">for dmu in rmsvelocities.parameters['dmu']:
for ncells in rmsvelocities.parameters['ncells']:
index = {'dmu':dmu, 'ncells':ncells}
print "dmu = {}, ncells = {}:".format(dmu, ncells)
print " rms velocity = {}".format(rmsvelocities[index][0])
print " rms velocity upper = {}".format(rmsvelocities[index][1])
print " rms velocity lower = {}".format(rmsvelocities[index][2])</string_value>
</test>
<test name="plot">
<string_value lines="20" type="code" language="python">import matplotlib
if havedisplay[0][0]:
matplotlib.use('GTKAgg')
else:
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import os
for dmu in vtudata.parameters['dmu']:
for ncells in vtudata.parameters['ncells']:
index = {'dmu':dmu, 'ncells':ncells}
x = vtudata[index][1]
v = vtudata[index][2]
fig = plt.figure()
stride = 1
q = plt.quiver(x[:,0][::stride], x[:,1][::stride], v[:,0][::stride], v[:,1][::stride], width=0.005, units='x', scale_units='x', scale=10, color='k')
plt.quiverkey(q, 0.9, 0.9, 1, "1", labelpos='S', coordinates='figure', color='k')
plt.gca().set_aspect('equal')
plt.xlabel('x')
plt.ylabel('y')
plt.title('velocity (dmu = {}, ncells = {})'.format(dmu, ncells), y=1.05)
fig.savefig("driven_cavity_freeslip_dmu_{}_ncells_{}.png".format(dmu, ncells))</string_value>
</test>
<test name="convergence">
<string_value lines="20" type="code" language="python">import matplotlib
if havedisplay[0][0]:
matplotlib.use('GTKAgg')
else:
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import os
if len(rmsvelocities.parameters["ncells"]) > 1:
for dmu in rmsvelocities.parameters["dmu"]:
index = {'dmu':dmu}
ncells = [int(nc) for nc in rmsvelocities.parameters["ncells"]]
fig1 = plt.figure()
plt.plot(ncells, np.asarray(rmsvelocities[index])[:,0])
plt.xlabel('ncells')
plt.ylabel('RMS velocity')
plt.title('RMS velocity (dmu = {})'.format(dmu,), y=1.05)</string_value>
</test>
<test name="display">
<string_value lines="20" type="code" language="python">import matplotlib
if havedisplay[0][0]:
matplotlib.use('GTKAgg')
else:
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import os
if havedisplay[0][0]: plt.show()</string_value>
</test>
</tests>
</harness_options>