[cig-commits] r13016 - in mc/2D/ConMan/trunk/visual: . cover
luis at geodynamics.org
luis at geodynamics.org
Thu Oct 9 13:22:27 PDT 2008
Author: luis
Date: 2008-10-09 13:22:27 -0700 (Thu, 09 Oct 2008)
New Revision: 13016
Added:
mc/2D/ConMan/trunk/visual/README
mc/2D/ConMan/trunk/visual/conman_vtk.py
mc/2D/ConMan/trunk/visual/cover/
mc/2D/ConMan/trunk/visual/cover/Makefile
mc/2D/ConMan/trunk/visual/cover/README
mc/2D/ConMan/trunk/visual/cover/conman_vtk.py
mc/2D/ConMan/trunk/visual/cover/generate_cover.py
mc/2D/ConMan/trunk/visual/cover/geom
mc/2D/ConMan/trunk/visual/cover/input
mc/2D/ConMan/trunk/visual/cover/runfile
mc/2D/ConMan/trunk/visual/cover/tempi
Log:
Use the example used for the cover image to show how to convert conman output into vtk format
Added: mc/2D/ConMan/trunk/visual/README
===================================================================
--- mc/2D/ConMan/trunk/visual/README (rev 0)
+++ mc/2D/ConMan/trunk/visual/README 2008-10-09 20:22:27 UTC (rev 13016)
@@ -0,0 +1,25 @@
+Converting ConMan Output to VTK Visualization Files
+===================================================
+
+In this directory you will find a python file that can help you convert
+the output from ConMan into VTK files you can visualize with programs like
+Paraview or Mayavi2.
+
+In order to use this, you will need the numpy and pyvtk python modules,
+which are available from the following websites:
+
+ * http://numpy.scipy.org/
+ * http://cens.ioc.ee/projects/pyvtk/
+
+The file conman_vtk.py is meant to be imported as a python module from
+another script. It defines a number of functions for splitting
+and parsing the temperature file output from ConMan, and for writing
+the resulting data into VTK files.
+
+For an example of how to use the conman_vtk module, we show how the
+cover image seen in the ConMan manual was generated. In particular,
+note how the conman_vtk python module is used in the generate_cover.py
+script.
+
+See the README file in the cover/ subdirectory for further instructions.
+
Added: mc/2D/ConMan/trunk/visual/conman_vtk.py
===================================================================
--- mc/2D/ConMan/trunk/visual/conman_vtk.py (rev 0)
+++ mc/2D/ConMan/trunk/visual/conman_vtk.py 2008-10-09 20:22:27 UTC (rev 13016)
@@ -0,0 +1,154 @@
+#!/usr/bin/env python
+
+from __future__ import with_statement
+
+import numpy
+import pyvtk
+
+
+def splitfile(infile, numsteps, numlines):
+ with open(infile, 'r') as fp:
+ for i in xrange(numsteps):
+ out = open('%s_%03d' % (infile, i), 'w')
+ for j in xrange(numlines):
+ line = fp.readline()
+ out.write(line)
+ out.close()
+ return
+
+def parse_header(line):
+ params = line.split()
+ (nsd, nex, ney, nno, t) = [int(p) for p in params[0:5]]
+ num = float(params[5])
+ return (nsd, nex, ney, nno, t, num)
+
+def read_temp(filename):
+
+ with open(filename, 'r') as fp:
+
+ line = fp.readline()
+ nsd,nex,ney,nno,t,num = parse_header(line)
+
+ var_names = fp.readline()
+
+ coords = numpy.zeros((nno,3))
+ connect = (nex,ney)
+ nodemap = numpy.zeros((nno,1), dtype=int)
+ velocity = numpy.zeros((nno,3))
+ temperature = numpy.zeros((nno,1))
+
+ for i in xrange(nno):
+ line = fp.readline()
+ params = line.split()
+ n = int(params[0])
+ x1 = float(params[1])
+ x2 = float(params[2])
+ v1 = float(params[3])
+ v2 = float(params[4])
+ T = float(params[5])
+ nodemap[i] = n
+ coords[i] = (x1,x2,0)
+ velocity[i] = (v1,v2,0)
+ temperature[i] = T
+
+ return {'step': (t, num),
+ 'coords': coords,
+ 'connect': connect,
+ 'velocity': velocity,
+ 'temperature': temperature,
+ 'nodemap': nodemap}
+
+def read_stress(filename):
+
+ with open(filename,'r') as fp:
+
+ line = fp.readline()
+ nsd, nex, ney, nno, t, num = parse_header(line)
+
+ var_names = fp.readline()
+
+ coords = numpy.zeros((nno,3))
+ connect = (nex,ney)
+ stress = numpy.zeros((nno,5))
+ pressure = numpy.zeros((nno,1))
+
+ for i in xrange(nno):
+ line = fp.readline()
+ params = line.split()
+ n = int(params[0])
+ x1 = float(params[1])
+ x2 = float(params[2])
+ t1 = float(params[3])
+ t2 = float(params[4])
+ t3 = float(params[5])
+ t4 = float(params[6])
+ t5 = float(params[7])
+ p = float(params[8])
+ coords[i] = (x1,x2,0)
+ stress[i] = (t1,t2,t3,t4,t5)
+ pressure[i] = p
+
+ return {'coords': coords,
+ 'connect': connect,
+ 'stress': stress,
+ 'pressure': pressure}
+
+def make_grid(coords, connect, **kw):
+ grid = None
+ gridtype = kw.get('gridtype', 'unstructured')
+ if gridtype == 'unstructured':
+ (nex, ney) = connect
+ (nx, ny) = (nex+1, ney+1)
+ conn = numpy.zeros((nex*ney,4), dtype=int)
+ def node(i,j):
+ return ny * i + j
+ for i in xrange(nex):
+ for j in xrange(ney):
+ e = (ney)*i + j
+ n1 = node(i,j)
+ n2 = node(i+1, j)
+ n3 = node(i+1, j+1)
+ n4 = node(i, j+1)
+ conn[e] = (n1,n2,n3,n4)
+ grid = pyvtk.UnstructuredGrid(coords, quad=conn)
+ else:
+ raise Exception('Unknown grid type')
+ return grid
+
+def make_scalar(array, name=None):
+ return pyvtk.Scalars(array, name, lookup_table='default')
+
+def make_vector(array, name=None):
+ return pyvtk.Vectors(array, name)
+
+def make_tensor(array, name=None):
+ return pyvtk.Tensors(array, name)
+
+def make_vtk(**kwargs):
+ args = []
+ if 'grid' in kwargs:
+ args.append(kwargs.get('grid'))
+ if 'point_data' in kwargs:
+ data = kwargs['point_data']
+ args.append(pyvtk.PointData(*data))
+ if 'cell_data' in kwargs:
+ data = kwargs['cell_data']
+ args.append(pyvtk.CellData(*data))
+ if 'header' in kwargs:
+ args.append(kwargs.get('header'))
+ return pyvtk.VtkData(*args)
+
+def write_vtk(infile, outfile='foo.vtk'):
+ info = read_temp(infile)
+ coords = info['coords']
+ connect = info['connect']
+ velocity = info['velocity']
+ temperature = info['temperature']
+ vtk = make_vtk(header='vtk header',
+ grid=make_grid(coords, connect, gridtype='unstructured'),
+ point_data=[make_scalar(temperature, 'temperature'),
+ make_vector(velocity, 'velocity')
+ ],
+ )
+ vtk.tofile(outfile)
+
Added: mc/2D/ConMan/trunk/visual/cover/Makefile
===================================================================
--- mc/2D/ConMan/trunk/visual/cover/Makefile (rev 0)
+++ mc/2D/ConMan/trunk/visual/cover/Makefile 2008-10-09 20:22:27 UTC (rev 13016)
@@ -0,0 +1,8 @@
+
+run:
+ ./conman.exp < runfile
+
+clean:
+ rm -f temp_???
+
+.PHONY: clean
Added: mc/2D/ConMan/trunk/visual/cover/README
===================================================================
--- mc/2D/ConMan/trunk/visual/cover/README (rev 0)
+++ mc/2D/ConMan/trunk/visual/cover/README 2008-10-09 20:22:27 UTC (rev 13016)
@@ -0,0 +1,17 @@
+This example consists of a thermal convection model with fully
+developed downwellings and upwellings. The computation is performed
+on a 4x1 rectangular domain with 256x64 uniform square elements.
+This convection model uses a Rayleigh number of 10^{6} and constant
+viscosity, with free slip velocity boundary conditions applied on all
+sides and constant temperature boundary conditions on the bottom and top
+layer.
+
+To run this example, you will need compile ConMan without
+the -DIMPLICIT and -DPICARD flags, so you will need to modify
+FFLAGS in either Makefile-gfort or Makefile-ifort.
+
+Now, run the command 'make explicit', and copy the resulting
+conman.exp executable into this directory.
+
+Finally, run the example with './conman.exp < runfile'
+
Added: mc/2D/ConMan/trunk/visual/cover/conman_vtk.py
===================================================================
--- mc/2D/ConMan/trunk/visual/cover/conman_vtk.py (rev 0)
+++ mc/2D/ConMan/trunk/visual/cover/conman_vtk.py 2008-10-09 20:22:27 UTC (rev 13016)
@@ -0,0 +1,154 @@
+#!/usr/bin/env python
+
+from __future__ import with_statement
+
+import numpy
+import pyvtk
+
+
+def splitfile(infile, numsteps, numlines):
+ with open(infile, 'r') as fp:
+ for i in xrange(numsteps):
+ out = open('%s_%03d' % (infile, i), 'w')
+ for j in xrange(numlines):
+ line = fp.readline()
+ out.write(line)
+ out.close()
+ return
+
+def parse_header(line):
+ params = line.split()
+ (nsd, nex, ney, nno, t) = [int(p) for p in params[0:5]]
+ num = float(params[5])
+ return (nsd, nex, ney, nno, t, num)
+
+def read_temp(filename):
+
+ with open(filename, 'r') as fp:
+
+ line = fp.readline()
+ nsd,nex,ney,nno,t,num = parse_header(line)
+
+ var_names = fp.readline()
+
+ coords = numpy.zeros((nno,3))
+ connect = (nex,ney)
+ nodemap = numpy.zeros((nno,1), dtype=int)
+ velocity = numpy.zeros((nno,3))
+ temperature = numpy.zeros((nno,1))
+
+ for i in xrange(nno):
+ line = fp.readline()
+ params = line.split()
+ n = int(params[0])
+ x1 = float(params[1])
+ x2 = float(params[2])
+ v1 = float(params[3])
+ v2 = float(params[4])
+ T = float(params[5])
+ nodemap[i] = n
+ coords[i] = (x1,x2,0)
+ velocity[i] = (v1,v2,0)
+ temperature[i] = T
+
+ return {'step': (t, num),
+ 'coords': coords,
+ 'connect': connect,
+ 'velocity': velocity,
+ 'temperature': temperature,
+ 'nodemap': nodemap}
+
+def read_stress(filename):
+
+ with open(filename,'r') as fp:
+
+ line = fp.readline()
+ nsd, nex, ney, nno, t, num = parse_header(line)
+
+ var_names = fp.readline()
+
+ coords = numpy.zeros((nno,3))
+ connect = (nex,ney)
+ stress = numpy.zeros((nno,5))
+ pressure = numpy.zeros((nno,1))
+
+ for i in xrange(nno):
+ line = fp.readline()
+ params = line.split()
+ n = int(params[0])
+ x1 = float(params[1])
+ x2 = float(params[2])
+ t1 = float(params[3])
+ t2 = float(params[4])
+ t3 = float(params[5])
+ t4 = float(params[6])
+ t5 = float(params[7])
+ p = float(params[8])
+ coords[i] = (x1,x2,0)
+ stress[i] = (t1,t2,t3,t4,t5)
+ pressure[i] = p
+
+ return {'coords': coords,
+ 'connect': connect,
+ 'stress': stress,
+ 'pressure': pressure}
+
+def make_grid(coords, connect, **kw):
+ grid = None
+ gridtype = kw.get('gridtype', 'unstructured')
+ if gridtype == 'unstructured':
+ (nex, ney) = connect
+ (nx, ny) = (nex+1, ney+1)
+ conn = numpy.zeros((nex*ney,4), dtype=int)
+ def node(i,j):
+ return ny * i + j
+ for i in xrange(nex):
+ for j in xrange(ney):
+ e = (ney)*i + j
+ n1 = node(i,j)
+ n2 = node(i+1, j)
+ n3 = node(i+1, j+1)
+ n4 = node(i, j+1)
+ conn[e] = (n1,n2,n3,n4)
+ grid = pyvtk.UnstructuredGrid(coords, quad=conn)
+ else:
+ raise Exception('Unknown grid type')
+ return grid
+
+def make_scalar(array, name=None):
+ return pyvtk.Scalars(array, name, lookup_table='default')
+
+def make_vector(array, name=None):
+ return pyvtk.Vectors(array, name)
+
+def make_tensor(array, name=None):
+ return pyvtk.Tensors(array, name)
+
+def make_vtk(**kwargs):
+ args = []
+ if 'grid' in kwargs:
+ args.append(kwargs.get('grid'))
+ if 'point_data' in kwargs:
+ data = kwargs['point_data']
+ args.append(pyvtk.PointData(*data))
+ if 'cell_data' in kwargs:
+ data = kwargs['cell_data']
+ args.append(pyvtk.CellData(*data))
+ if 'header' in kwargs:
+ args.append(kwargs.get('header'))
+ return pyvtk.VtkData(*args)
+
+def write_vtk(infile, outfile='foo.vtk'):
+ info = read_temp(infile)
+ coords = info['coords']
+ connect = info['connect']
+ velocity = info['velocity']
+ temperature = info['temperature']
+ vtk = make_vtk(header='vtk header',
+ grid=make_grid(coords, connect, gridtype='unstructured'),
+ point_data=[make_scalar(temperature, 'temperature'),
+ make_vector(velocity, 'velocity')
+ ],
+ )
+ vtk.tofile(outfile)
+
Added: mc/2D/ConMan/trunk/visual/cover/generate_cover.py
===================================================================
--- mc/2D/ConMan/trunk/visual/cover/generate_cover.py (rev 0)
+++ mc/2D/ConMan/trunk/visual/cover/generate_cover.py 2008-10-09 20:22:27 UTC (rev 13016)
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+
+import conman_vtk as conman
+
+
+def main():
+
+ numsteps = 100
+ nelx = 256
+ nelz = 64
+
+ nx = nelx + 1
+ nz = nelz + 1
+ numlines = nx*nz + 2
+
+ filename = 'temp'
+ conman.splitfile(filename, numsteps, numlines)
+ for i in xrange(numsteps):
+ print 'Writing %d-th file' % i
+ conman.write_vtk(infile='temp_%03d' % i, outfile='cover_%03d.vtk' % i)
+ return 0
+
+if __name__ == '__main__':
+ main()
+
Property changes on: mc/2D/ConMan/trunk/visual/cover/generate_cover.py
___________________________________________________________________
Name: svn:executable
+ *
Added: mc/2D/ConMan/trunk/visual/cover/geom
===================================================================
--- mc/2D/ConMan/trunk/visual/cover/geom (rev 0)
+++ mc/2D/ConMan/trunk/visual/cover/geom 2008-10-09 20:22:27 UTC (rev 13016)
@@ -0,0 +1,18 @@
+ coordinates
+ 1 4 0.0 0.0
+ 16640 1 4.0 0.0
+ 16705 1 4.0 1.0
+ 65 1 0.0 1.0
+ 256 65 64 1
+ 0 0 0.0 0.0
+ velocity boundary conditions (non-zero)
+ 0 0 0.0 0.0
+ temperature boundary conditions (non-zero)
+ 1 2 1.0
+ 16640 0 1.0
+ 256 65
+ 0 0 0.0
+ element connectivity and material groups
+ 1 1 1 1 66 67 2
+ 256 64 65 64 1 1
+ 0 0 0 0 0 0 0
Added: mc/2D/ConMan/trunk/visual/cover/input
===================================================================
--- mc/2D/ConMan/trunk/visual/cover/input (rev 0)
+++ mc/2D/ConMan/trunk/visual/cover/input 2008-10-09 20:22:27 UTC (rev 13016)
@@ -0,0 +1,47 @@
+ 256 x 64 el. plate problem from Blankenbach et al., 1989 (for cover image)
+ #Nds sdm dof X Z prc ck echo rrst wrst nus tdvf tseq nelg sky wr
+ 16705 2 2 256 64 2 1 0 0 1 514 0 1 1 1 0
+ time step information
+ 10000 1 1.0 1.0 0.50000
+ output information
+ 100 100 100 100
+ velocity boundary condition flags: IFCMT,DELNXTLN
+ bnode enode incr bcf1 bcf2
+ 1 16640 65 0 1
+ 16640 16705 1 1 0
+ 1 65 1 1 0
+ 65 16705 65 0 1
+ 1 1 1 1 1
+ 65 65 1 1 1
+ 16640 16640 1 1 1
+ 16705 16705 1 1 1
+ 0 0 0 0 0
+ temperature boundary condition flags
+ 1 16640 65 1
+ 65 16705 65 1
+ 0 0 0 0
+ bndy info (top - bottom rows)
+ 1 16640 65
+ 65 16705 65
+ 0 0 0
+ bndy info (2nd from top - 2nd from bottom rows)
+ 2 16641 65
+ 64 16704 65
+ 0 0 0
+ initial condition information
+ 0.1 1.0 1.0 1.0
+ element information
+ 2 16384 4 4 1 2 0 5 0 0
+ viscosity
+ 1.0e0
+ penalty number
+ 0.1E+08
+ diffusivity (always one)
+ 1.0
+ Rayleigh number
+ 1.0e+06
+ internal heating parameter
+ 0.0
+ 0.0
+ 0.0
+ 1.0e7
Added: mc/2D/ConMan/trunk/visual/cover/runfile
===================================================================
--- mc/2D/ConMan/trunk/visual/cover/runfile (rev 0)
+++ mc/2D/ConMan/trunk/visual/cover/runfile 2008-10-09 20:22:27 UTC (rev 13016)
@@ -0,0 +1,9 @@
+input
+geom
+output
+tempi
+tempo
+tseries
+temp
+stress
+geoid
Added: mc/2D/ConMan/trunk/visual/cover/tempi
===================================================================
More information about the cig-commits
mailing list