Skip to content

Commit e68ac61

Browse files
committed
Update README
1 parent 391f930 commit e68ac61

File tree

4 files changed

+492
-2
lines changed

4 files changed

+492
-2
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ Note that the results displayed here are re-generated every time a push is made
1414
## Install dependencies
1515
To run the code in this repo you need FEniCS and gmsh with OpenCascade installed. The easiest way to do this is to either use the provided docker image, i.e
1616
```
17-
docker pull ghcr.io/computationalphysiology/ciucci-2024:v1.0.0
17+
docker pull ghcr.io/computationalphysiology/ciucci-2024:latest
1818
```
1919
You can create a new container using the command
2020
```
21-
docker run --name ciucci -w /home/shared -v $PWD:/home/shared -it ghcr.io/computationalphysiology/ciucci-2024:v1.0.0
21+
docker run --name ciucci -w /home/shared -v $PWD:/home/shared -it ghcr.io/computationalphysiology/ciucci-2024:latest
2222
```
2323
which will also share your current directory with the container. If you are interested you can also check out the [Dockerfile](Dockerfile) if you want to know how the image was created.
2424

code/create_paraview_figure.py

+379
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,379 @@
1+
# trace generated using paraview version 5.11.0
2+
# import paraview
3+
# paraview.compatibility.major = 5
4+
# paraview.compatibility.minor = 11
5+
6+
#### import the simple module from the paraview
7+
from paraview.simple import *
8+
9+
10+
def main(filename, min_value, max_value, name, label, blocknr, figure_folder):
11+
#### disable automatic camera reset on 'Show'
12+
paraview.simple._DisableFirstRenderCameraReset()
13+
14+
# create a new 'Xdmf3ReaderT'
15+
resultsxdmf = Xdmf3ReaderT(
16+
registrationName="results.xdmf",
17+
FileName=[
18+
filename,
19+
],
20+
)
21+
22+
# get animation scene
23+
animationScene1 = GetAnimationScene()
24+
25+
# get the time-keeper
26+
timeKeeper1 = GetTimeKeeper()
27+
28+
# update animation scene based on data timesteps
29+
animationScene1.UpdateAnimationUsingDataTimeSteps()
30+
31+
# get active view
32+
renderView1 = GetActiveViewOrCreate("RenderView")
33+
34+
# # create a new 'Extract Block'
35+
extractBlock = ExtractBlock(registrationName="ExtractBlock", Input=resultsxdmf)
36+
37+
# # Properties modified on extractBlock
38+
extractBlock.Selectors = [f"/Root/Block{blocknr}"]
39+
40+
# show data in view
41+
extractBlockDisplay = Show(extractBlock, renderView1, "UnstructuredGridRepresentation")
42+
43+
# get color transfer function/color map for 'sigma_xx'
44+
sigma_xxLUT = GetColorTransferFunction(name)
45+
46+
# get opacity transfer function/opacity map for 'sigma_xx'
47+
sigma_xxPWF = GetOpacityTransferFunction(name)
48+
49+
# trace defaults for the display properties.
50+
extractBlockDisplay.Representation = "Surface"
51+
extractBlockDisplay.ColorArrayName = ["POINTS", name]
52+
extractBlockDisplay.LookupTable = sigma_xxLUT
53+
extractBlockDisplay.SelectTCoordArray = "None"
54+
extractBlockDisplay.SelectNormalArray = "None"
55+
extractBlockDisplay.SelectTangentArray = "None"
56+
extractBlockDisplay.OSPRayScaleArray = name
57+
extractBlockDisplay.OSPRayScaleFunction = "PiecewiseFunction"
58+
extractBlockDisplay.SelectOrientationVectors = "None"
59+
extractBlockDisplay.ScaleFactor = 400.0
60+
extractBlockDisplay.SelectScaleArray = name
61+
extractBlockDisplay.GlyphType = "Arrow"
62+
extractBlockDisplay.GlyphTableIndexArray = name
63+
extractBlockDisplay.GaussianRadius = 20.0
64+
extractBlockDisplay.SetScaleArray = ["POINTS", name]
65+
extractBlockDisplay.ScaleTransferFunction = "PiecewiseFunction"
66+
extractBlockDisplay.OpacityArray = ["POINTS", name]
67+
extractBlockDisplay.OpacityTransferFunction = "PiecewiseFunction"
68+
extractBlockDisplay.DataAxesGrid = "GridAxesRepresentation"
69+
extractBlockDisplay.PolarAxes = "PolarAxesRepresentation"
70+
extractBlockDisplay.ScalarOpacityFunction = sigma_xxPWF
71+
extractBlockDisplay.ScalarOpacityUnitDistance = 120.50872400061667
72+
extractBlockDisplay.OpacityArrayName = ["POINTS", name]
73+
extractBlockDisplay.SelectInputVectors = [None, ""]
74+
extractBlockDisplay.WriteLog = ""
75+
76+
# init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
77+
extractBlockDisplay.ScaleTransferFunction.Points = [
78+
2.5313084643816214e-16,
79+
0.0,
80+
0.5,
81+
0.0,
82+
2.531850565467864e-16,
83+
1.0,
84+
0.5,
85+
0.0,
86+
]
87+
88+
# init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
89+
extractBlockDisplay.OpacityTransferFunction.Points = [
90+
2.5313084643816214e-16,
91+
0.0,
92+
0.5,
93+
0.0,
94+
2.531850565467864e-16,
95+
1.0,
96+
0.5,
97+
0.0,
98+
]
99+
100+
# hide data in view
101+
Hide(resultsxdmf, renderView1)
102+
103+
# show color bar/color legend
104+
extractBlockDisplay.SetScalarBarVisibility(renderView1, True)
105+
106+
# update the view to ensure updated data information
107+
renderView1.Update()
108+
109+
# get 2D transfer function for 'sigma_xx'
110+
sigma_xxTF2D = GetTransferFunction2D(name)
111+
112+
animationScene1.GoToNext()
113+
114+
# Rescale transfer function
115+
sigma_xxLUT.RescaleTransferFunction(-2.8939850330352783, 7.81556510925293)
116+
117+
# Rescale transfer function
118+
sigma_xxPWF.RescaleTransferFunction(-2.8939850330352783, 7.81556510925293)
119+
120+
# create a new 'Clip'
121+
clip1 = Clip(registrationName="Clip1", Input=extractBlock)
122+
clip1.ClipType = "Plane"
123+
clip1.HyperTreeGridClipper = "Plane"
124+
clip1.Scalars = ["POINTS", name]
125+
clip1.Value = 2.4607900381088257
126+
127+
# show data in view
128+
clip1Display = Show(clip1, renderView1, "UnstructuredGridRepresentation")
129+
130+
# trace defaults for the display properties.
131+
clip1Display.Representation = "Surface"
132+
clip1Display.ColorArrayName = ["POINTS", name]
133+
clip1Display.LookupTable = sigma_xxLUT
134+
clip1Display.SelectTCoordArray = "None"
135+
clip1Display.SelectNormalArray = "None"
136+
clip1Display.SelectTangentArray = "None"
137+
clip1Display.OSPRayScaleArray = name
138+
clip1Display.OSPRayScaleFunction = "PiecewiseFunction"
139+
clip1Display.SelectOrientationVectors = "None"
140+
clip1Display.ScaleFactor = 200.0
141+
clip1Display.SelectScaleArray = name
142+
clip1Display.GlyphType = "Arrow"
143+
clip1Display.GlyphTableIndexArray = name
144+
clip1Display.GaussianRadius = 10.0
145+
clip1Display.SetScaleArray = ["POINTS", name]
146+
clip1Display.ScaleTransferFunction = "PiecewiseFunction"
147+
clip1Display.OpacityArray = ["POINTS", name]
148+
clip1Display.OpacityTransferFunction = "PiecewiseFunction"
149+
clip1Display.DataAxesGrid = "GridAxesRepresentation"
150+
clip1Display.PolarAxes = "PolarAxesRepresentation"
151+
clip1Display.ScalarOpacityFunction = sigma_xxPWF
152+
clip1Display.ScalarOpacityUnitDistance = 80.35903137837035
153+
clip1Display.OpacityArrayName = ["POINTS", name]
154+
clip1Display.SelectInputVectors = [None, ""]
155+
clip1Display.WriteLog = ""
156+
157+
# init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
158+
clip1Display.ScaleTransferFunction.Points = [
159+
-2.8062829971313477,
160+
0.0,
161+
0.5,
162+
0.0,
163+
7.81556510925293,
164+
1.0,
165+
0.5,
166+
0.0,
167+
]
168+
169+
# init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
170+
clip1Display.OpacityTransferFunction.Points = [
171+
-2.8062829971313477,
172+
0.0,
173+
0.5,
174+
0.0,
175+
7.81556510925293,
176+
1.0,
177+
0.5,
178+
0.0,
179+
]
180+
181+
# hide data in view
182+
Hide(extractBlock, renderView1)
183+
184+
# show color bar/color legend
185+
clip1Display.SetScalarBarVisibility(renderView1, True)
186+
187+
# update the view to ensure updated data information
188+
renderView1.Update()
189+
190+
# set active source
191+
SetActiveSource(extractBlock)
192+
193+
# toggle interactive widget visibility (only when running from the GUI)
194+
HideInteractiveWidgets(proxy=clip1.ClipType)
195+
196+
# create a new 'Clip'
197+
clip2 = Clip(registrationName="Clip2", Input=extractBlock)
198+
clip2.ClipType = "Plane"
199+
clip2.HyperTreeGridClipper = "Plane"
200+
clip2.Scalars = ["POINTS", name]
201+
clip2.Value = 2.4607900381088257
202+
203+
# Properties modified on clip2.ClipType
204+
clip2.ClipType.Normal = [0.0, 1.0, 0.0]
205+
206+
# show data in view
207+
clip2Display = Show(clip2, renderView1, "UnstructuredGridRepresentation")
208+
209+
# trace defaults for the display properties.
210+
clip2Display.Representation = "Surface"
211+
clip2Display.ColorArrayName = ["POINTS", name]
212+
clip2Display.LookupTable = sigma_xxLUT
213+
clip2Display.SelectTCoordArray = "None"
214+
clip2Display.SelectNormalArray = "None"
215+
clip2Display.SelectTangentArray = "None"
216+
clip2Display.OSPRayScaleArray = name
217+
clip2Display.OSPRayScaleFunction = "PiecewiseFunction"
218+
clip2Display.SelectOrientationVectors = "None"
219+
clip2Display.ScaleFactor = 400.0
220+
clip2Display.SelectScaleArray = name
221+
clip2Display.GlyphType = "Arrow"
222+
clip2Display.GlyphTableIndexArray = name
223+
clip2Display.GaussianRadius = 20.0
224+
clip2Display.SetScaleArray = ["POINTS", name]
225+
clip2Display.ScaleTransferFunction = "PiecewiseFunction"
226+
clip2Display.OpacityArray = ["POINTS", name]
227+
clip2Display.OpacityTransferFunction = "PiecewiseFunction"
228+
clip2Display.DataAxesGrid = "GridAxesRepresentation"
229+
clip2Display.PolarAxes = "PolarAxesRepresentation"
230+
clip2Display.ScalarOpacityFunction = sigma_xxPWF
231+
clip2Display.ScalarOpacityUnitDistance = 145.3794450275547
232+
clip2Display.OpacityArrayName = ["POINTS", name]
233+
clip2Display.SelectInputVectors = [None, ""]
234+
clip2Display.WriteLog = ""
235+
236+
# init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
237+
clip2Display.ScaleTransferFunction.Points = [
238+
-2.363538980484009,
239+
0.0,
240+
0.5,
241+
0.0,
242+
6.50651741027832,
243+
1.0,
244+
0.5,
245+
0.0,
246+
]
247+
248+
# init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
249+
clip2Display.OpacityTransferFunction.Points = [
250+
-2.363538980484009,
251+
0.0,
252+
0.5,
253+
0.0,
254+
6.50651741027832,
255+
1.0,
256+
0.5,
257+
0.0,
258+
]
259+
260+
# hide data in view
261+
Hide(extractBlock, renderView1)
262+
263+
# show color bar/color legend
264+
clip2Display.SetScalarBarVisibility(renderView1, True)
265+
266+
# update the view to ensure updated data information
267+
renderView1.Update()
268+
269+
# get color legend/bar for sigma_xxLUT in view renderView1
270+
sigma_xxLUTColorBar = GetScalarBar(sigma_xxLUT, renderView1)
271+
272+
# Properties modified on sigma_xxLUTColorBar
273+
sigma_xxLUTColorBar.Title = label
274+
sigma_xxLUTColorBar.RangeLabelFormat = "%-#6.1f"
275+
276+
# Apply a preset using its name. Note this may not work as expected when presets have duplicate names.
277+
sigma_xxLUT.ApplyPreset("Viridis (matplotlib)", True)
278+
279+
# change scalar bar placement
280+
sigma_xxLUTColorBar.Orientation = "Horizontal"
281+
sigma_xxLUTColorBar.WindowLocation = "Any Location"
282+
sigma_xxLUTColorBar.Position = [0.3250956464379949, 0.7651456310679611]
283+
sigma_xxLUTColorBar.ScalarBarLength = 0.33
284+
285+
# Rescale transfer function
286+
sigma_xxLUT.RescaleTransferFunction(min_value, max_value)
287+
288+
# Rescale transfer function
289+
sigma_xxPWF.RescaleTransferFunction(min_value, max_value)
290+
291+
# Rescale 2D transfer function
292+
sigma_xxTF2D.RescaleTransferFunction(min_value, max_value, 0.0, 1.0)
293+
294+
# toggle interactive widget visibility (only when running from the GUI)
295+
HideInteractiveWidgets(proxy=clip2.ClipType)
296+
297+
# get layout
298+
layout1 = GetLayout()
299+
300+
# --------------------------------
301+
# saving layout sizes for layouts
302+
303+
# layout/tab size in pixels
304+
layout1.SetSize(1516, 1030)
305+
306+
# -----------------------------------
307+
# saving camera placements for views
308+
309+
# current camera placement for renderView1
310+
renderView1.CameraPosition = [
311+
4527.975828521292,
312+
1143.9996458085711,
313+
1335.8353866420669,
314+
]
315+
renderView1.CameraFocalPoint = [
316+
-501.3331417934615,
317+
-126.6625437863954,
318+
-147.90241305746002,
319+
]
320+
renderView1.CameraViewUp = [
321+
-0.21900790347787114,
322+
0.9715903578242485,
323+
-0.08970905638326834,
324+
]
325+
renderView1.CameraParallelScale = 2044.5048300260873
326+
327+
# export view
328+
ExportView(f"{figure_folder}/{name}.svg", view=renderView1)
329+
330+
# ================================================================
331+
# addendum: following script captures some of the application
332+
# state to faithfully reproduce the visualization during playback
333+
# ================================================================
334+
335+
# --------------------------------------------
336+
# uncomment the following to render all views
337+
# RenderAllViews()
338+
# alternatively, if you want to write images, you can use SaveScreenshot(...).
339+
340+
341+
if __name__ == "__main__":
342+
import argparse
343+
344+
parser = argparse.ArgumentParser()
345+
parser.add_argument("--filename", type=str)
346+
parser.add_argument("--min_value", type=float)
347+
parser.add_argument("--max_value", type=float)
348+
parser.add_argument("--name", type=str)
349+
parser.add_argument("--label", type=str)
350+
parser.add_argument("--blocknr", type=int)
351+
parser.add_argument("--figure_folder", type=str)
352+
args = parser.parse_args()
353+
354+
main(
355+
filename=args.filename,
356+
min_value=float(args.min_value),
357+
max_value=float(args.max_value),
358+
name=args.name,
359+
label=args.label,
360+
blocknr=int(args.blocknr),
361+
figure_folder=args.figure_folder,
362+
)
363+
364+
# main(
365+
# filename="/Users/finsberg/local/src/cardiac-cancer/code/results4/cylinder_fine_varying_incomp/spring3000.0/results.xdmf",
366+
# min_value=0.0,
367+
# max_value=3.0,
368+
# name=name,
369+
# label="$\\sigma_{xx}$",
370+
# )
371+
372+
# main(
373+
# filename="/Users/finsberg/local/src/cardiac-cancer/code/results4/cylinder_fine_incomp/spring3000.0/results.xdmf",
374+
# min_value=0.0,
375+
# max_value=3.0,
376+
# name="sigma_r",
377+
# label="$\\sigma_{xx}$",
378+
# blocknr=1,
379+
# )

0 commit comments

Comments
 (0)