Introduction
Introduction Statistics Contact Development Disclaimer Help
tAdded VTK output function - ns2dfd - 2D finite difference Navier Stokes solver…
git clone git://src.adamsgaard.dk/ns2dfd
Log
Files
Refs
LICENSE
---
commit a9c5e210c85110662bd2c31c3fd5d3c3c8c12291
parent 502702ca8b1d45e5023f4e1f5fa5b5408a614ed4
Author: Anders Damsgaard <[email protected]>
Date: Tue, 4 Mar 2014 13:38:07 +0100
Added VTK output function
Diffstat:
M ns2dfd.py | 77 +++++++++++++++++++++++++++++…
M pressure_anomaly.py | 1 +
2 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/ns2dfd.py b/ns2dfd.py
t@@ -2,6 +2,7 @@
import numpy
import subprocess
+import vtk
class fluid:
t@@ -264,3 +265,79 @@ class fluid:
'''
self.write()
subprocess.call('./ns2dfd ' + self.sim_id + '.dat', shell=True)
+
+ def writeVTK(self, folder = './', verbose = True):
+ '''
+ Writes a VTK file for the fluid grid to the current folder by default.
+ The file name will be in the format ``<self.sid>.vti``. The vti files
+ can be used for visualizing the fluid in ParaView.
+
+ The fluid grid is visualized by opening the vti files, and pressing
+ "Apply" to import all fluid field properties. To visualize the scalar
+ fields, such as the pressure, the porosity, the porosity change or the
+ velocity magnitude, choose "Surface" or "Surface With Edges" as the
+ "Representation". Choose the desired property as the "Coloring" field.
+ It may be desirable to show the color bar by pressing the "Show" butto…
+ and "Rescale" to fit the color range limits to the current file. The
+ coordinate system can be displayed by checking the "Show Axis" field.
+ All adjustments by default require the "Apply" button to be pressed
+ before regenerating the view.
+
+ The fluid vector fields (e.g. the fluid velocity) can be visualizing by
+ e.g. arrows. To do this, select the fluid data in the "Pipeline
+ Browser". Press "Glyph" from the "Common" toolbar, or go to the
+ "Filters" mennu, and press "Glyph" from the "Common" list. Make sure
+ that "Arrow" is selected as the "Glyph type", and "Velocity" as the
+ "Vectors" value. Adjust the "Maximum Number of Points" to be at least …
+ big as the number of fluid cells in the grid. Press "Apply" to visuali…
+ the arrows.
+
+ If several data files are generated for the same simulation (e.g. using
+ the :func:`writeVTKall()` function), it is able to step the
+ visualization through time by using the ParaView controls.
+
+ :param folder: The folder where to place the output binary file (defau…
+ (default = './')
+ :type folder: str
+ :param verbose: Show diagnostic information (default = True)
+ :type verbose: bool
+ '''
+ filename = folder + '/' + self.sim_id + '.vti' # image grid
+
+ # initalize VTK data structure
+ grid = vtk.vtkImageData()
+ grid.SetOrigin([0.0, 0.0, 0.0])
+ grid.SetSpacing([self.dx, self.dy, 1])
+ grid.SetDimensions([self.nx+2, self.ny+2, 1])
+
+ # array of scalars: hydraulic pressures
+ pres = vtk.vtkDoubleArray()
+ pres.SetName("Pressure")
+ pres.SetNumberOfComponents(1)
+ pres.SetNumberOfTuples(grid.GetNumberOfPoints())
+
+ # array of vectors: hydraulic velocities
+ vel = vtk.vtkDoubleArray()
+ vel.SetName("Velocity")
+ vel.SetNumberOfComponents(2)
+ vel.SetNumberOfTuples(grid.GetNumberOfPoints())
+
+ # insert values
+ for y in range(self.ny+2):
+ for x in range(self.nx+2):
+ idx = x + (self.nx+2)*y
+ pres.SetValue(idx, self.P[x,y])
+ vel.SetTuple(idx, [self.U[x,y], self.V[x,y]])
+
+ # add pres array to grid
+ grid.GetPointData().AddArray(pres)
+ grid.GetPointData().AddArray(vel)
+
+ # write VTK XML image data file
+ writer = vtk.vtkXMLImageDataWriter()
+ writer.SetFileName(filename)
+ writer.SetInput(grid)
+ writer.Update()
+ if (verbose == True):
+ print('Output file: {0}'.format(filename))
+
diff --git a/pressure_anomaly.py b/pressure_anomaly.py
t@@ -6,3 +6,4 @@ sim.P[5,3] = 1.0
sim.run()
sim.read(sim.sim_id + '00004.dat')
print(sim.P)
+sim.writeVTK()
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.