-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathgenerate_viz.py
More file actions
98 lines (76 loc) · 2.99 KB
/
generate_viz.py
File metadata and controls
98 lines (76 loc) · 2.99 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
#!/usr/bin/env python3
import sys
import os
sys.path.insert(0, "/usr/lib/python3/dist-packages")
# Set up offscreen rendering
import paraview
paraview.compatibility.major = 5
paraview.compatibility.minor = 11
import paraview.simple as pvs
# Configure for headless/offscreen rendering
# OSPRay plugin not available in this installation
# Disable first render camera reset
pvs._DisableFirstRenderCameraReset()
# Change to cavity directory
os.chdir("/workspaces/openfoam-mcp-server/results/cavity")
print("Starting visualization generation...")
print("Current directory:", os.getcwd())
try:
# Load OpenFOAM case
print("Loading OpenFOAM case...")
reader = pvs.OpenFOAMReader(FileName="cavity.foam")
reader.MeshRegions = ["internalMesh"]
reader.CellArrays = ["U", "p"]
print("Setting up view...")
# Create view
view = pvs.GetActiveViewOrCreate('RenderView')
view.ViewSize = [800, 600]
view.Background = [1, 1, 1] # White background
print("Creating representation...")
# Show the data
rep = pvs.Show(reader, view)
print("Setting up velocity visualization...")
# Color by velocity magnitude
pvs.ColorBy(rep, ("POINTS", "U", "Magnitude"))
# Get color transfer function
lut = pvs.GetColorTransferFunction("U")
lut.RescaleTransferFunction(0.0, 1.0)
# Reset camera and render
pvs.ResetCamera(view)
pvs.Render(view)
print("Saving velocity magnitude image...")
# Save velocity visualization
pvs.SaveScreenshot("/workspaces/openfoam-mcp-server/results/velocity_magnitude.png", view)
print("✅ Velocity magnitude visualization saved")
print("Setting up pressure visualization...")
# Color by pressure
pvs.ColorBy(rep, ("CELLS", "p"))
lut_p = pvs.GetColorTransferFunction("p")
lut_p.RescaleTransferFunction(-0.5, 0.2)
pvs.Render(view)
pvs.SaveScreenshot("/workspaces/openfoam-mcp-server/results/pressure.png", view)
print("✅ Pressure visualization saved")
print("Creating streamlines...")
# Create streamlines
pvs.ColorBy(rep, ("POINTS", "U", "Magnitude"))
# Create stream tracer
stream = pvs.StreamTracer(Input=reader, SeedType="Line")
stream.SeedType.Point1 = [0.01, 0.01, 0.005]
stream.SeedType.Point2 = [0.01, 0.09, 0.005]
stream.SeedType.Resolution = 10
# Show streamlines
stream_rep = pvs.Show(stream, view)
pvs.ColorBy(stream_rep, ("POINTS", "U", "Magnitude"))
stream_rep.LineWidth = 3.0
# Note: TubeRadius may not be available in this ParaView version
# Hide the mesh and show only streamlines
pvs.Hide(reader, view)
pvs.ResetCamera(view)
pvs.Render(view)
pvs.SaveScreenshot("/workspaces/openfoam-mcp-server/results/streamlines.png", view)
print("✅ Streamlines visualization saved")
print("🎉 All visualizations generated successfully!")
except Exception as e:
print(f"❌ Error generating visualization: {e}")
import traceback
traceback.print_exc()