modified: anasen_fem/paraview_plotter.py included code to make and save field plots modified: anasen_fem/run.py included changes for parapview plotter and also save all outputs for mesh and elmer in folders modified: anasen_fem/scalars.dat.names modified: anasen_fem/wires_gmsh2d_bc.py
120 lines
4.1 KiB
Python
Executable File
120 lines
4.1 KiB
Python
Executable File
#!/home/vsitaraman/ParaView-6.1.0-RC1-MPI-Linux-Python3.12-x86_64/bin/pvbatch
|
|
import numpy as np
|
|
import sys
|
|
from paraview.simple import *
|
|
|
|
reader = XMLUnstructuredGridReader(FileName=["wires2d/elfield_anasen_t0001.vtu"])
|
|
|
|
contour_filter = Contour(Input=reader,ContourBy = 'potential')
|
|
contour_filter.Isosurfaces = [i for i in np.arange(0,660,650/32.)]
|
|
|
|
renderView = GetActiveViewOrCreate('RenderView')
|
|
renderView.ViewSize = [2000,2000]
|
|
renderView.OrientationAxesVisibility = 0 # Hide axis
|
|
renderView.UseColorPaletteForBackground=0
|
|
renderView.Background = [0.1, 0.1, 0.1] # Set background to dark gray (RGB 0-1)
|
|
|
|
renderView.MultiSamples = 8 # 0 disables it, 4-8 is usually sufficient
|
|
|
|
ResetCamera()
|
|
|
|
contour_display = Show(contour_filter, renderView)
|
|
contour_display.LineWidth = 3.0 # Increase this for thicker lines
|
|
contour_display.RenderLinesAsTubes = 1 # Makes lines look smoother at high res
|
|
#colorbar
|
|
contour_display_potentialLUT = GetColorTransferFunction('potential', contour_display, separate=True)
|
|
contour_display_potentialLUT.ApplyPreset('Cool to Warm', True)
|
|
contour_display.SetScalarBarVisibility(renderView, True)
|
|
|
|
#axesGrid = renderView.AxesGridrfcxgdtv
|
|
#axesGrid.Visibility = 1
|
|
#axesGrid.XTitle = "x (mm)"
|
|
#axesGrid.YTitle = "y (mm)"
|
|
|
|
# 1. Get the active view
|
|
view = GetActiveView()
|
|
|
|
# 2. Define your desired coordinate ranges (x_min, x_max, y_min, y_max, z_min, z_max)
|
|
# Example: Look at a box from -10 to 10 in all dimensions
|
|
x_min, x_max = -50.0, 50.0
|
|
y_min, y_max = -50.0, 50.0
|
|
z_min, z_max = -50.0, 50.0
|
|
|
|
# 3. Calculate Center, Position, and Parallel Scale
|
|
center = [(x_min + x_max) / 2.0, (y_min + y_max) / 2.0, (z_min + z_max) / 2.0]
|
|
# Position the camera far away along Z to look at the center
|
|
position = [center[0], center[1], z_min - 30.0]
|
|
# Parallel scale defines how much of the scene is visible.
|
|
# It is usually half the height of the viewed area.
|
|
view.CameraParallelScale = max((x_max - x_min), (y_max - y_min))/1.6
|
|
|
|
# 4. Apply settings
|
|
view.CenterOfRotation = center
|
|
view.CameraPosition = position
|
|
view.CameraFocalPoint = center
|
|
view.CameraViewUp = [0.0, 1.0, 0.0] # Y-axis is up
|
|
|
|
# 5. Enable Parallel Projection (optional, often better for exact mapping)
|
|
view.CameraParallelProjection = 1
|
|
|
|
#ResetCamera()
|
|
Render()
|
|
|
|
SaveScreenshot("contour_output.png")
|
|
|
|
#make glyps for field lines
|
|
contour_display.LineWidth = 1.0 # Increase this for thicker lines
|
|
contour_display.RenderLinesAsTubes = 0 # Makes lines look smoother at high res
|
|
|
|
# 1. Get the active view
|
|
view = GetActiveView()
|
|
|
|
# 4. Apply settings
|
|
# 1. Set the Focal Point to the middle of the quadrant
|
|
zoom_center = [-25, 25, 0.0]
|
|
|
|
# 2. Tighten the Parallel Scale
|
|
view.CameraParallelScale = 15
|
|
|
|
# 3. Position the Camera
|
|
# Keep it 0.5m away looking "down" at the new center
|
|
view.CameraPosition = [zoom_center[0], zoom_center[1], 0.5]
|
|
view.CameraFocalPoint = zoom_center
|
|
view.CameraViewUp = [0.0, 1.0, 0.0]
|
|
# pot_threshold = Threshold(Input=reader)
|
|
# pot_threshold.Scalars = ['POINTS', 'potential']
|
|
# pot_threshold.ThresholdMethod = 'Above Upper Threshold'
|
|
# pot_threshold.UpperThreshold = 100.0
|
|
|
|
# --- 2. Create the Glyph Filter (The Arrows) ---
|
|
# IMPORTANT: Use 'pot_threshold' as the Input, not the 'reader'
|
|
glyph = Glyph(Input=reader, GlyphType='Arrow')
|
|
|
|
# Orientation Array: Use the 'electric field' vector from Elmer
|
|
glyph.OrientationArray = ['POINTS', 'electric field']
|
|
glyph.ScaleArray = ['POINTS', 'No scale array']
|
|
glyph.ScaleFactor = 1
|
|
|
|
# Sampling: Every nth point (Stride 16)
|
|
glyph.GlyphMode = 'Every Nth Point'
|
|
glyph.Stride = 96
|
|
|
|
# --- 3. Display the Glyphs ---
|
|
glyph_display = Show(glyph, renderView)
|
|
|
|
# Set the representation to Surface so we see the full arrow colors
|
|
glyph_display.Representation = 'Surface'
|
|
|
|
# This is the critical line: Color the arrows by the 'potential' scalar
|
|
ColorBy(glyph_display, ('POINTS', 'potential'))
|
|
contour_display_potentialLUT.RescaleTransferFunction(0.0, 660.0)
|
|
glyph_display.LookupTable = contour_display_potentialLUT
|
|
|
|
# Optional: Disable the scalar bar for the arrows to avoid cluttering
|
|
# the existing 'potential' scalar bar.
|
|
glyph_display.SetScalarBarVisibility(renderView, False)
|
|
|
|
# --- 4. Final Render ---
|
|
Render()
|
|
SaveScreenshot("Field_output.png")
|