[cig-commits] r8407 - short/3D/PyLith/benchmarks/trunk/quasistatic/strikeslipnog/figs

brad at geodynamics.org brad at geodynamics.org
Fri Dec 7 14:28:04 PST 2007


Author: brad
Date: 2007-12-07 14:28:04 -0800 (Fri, 07 Dec 2007)
New Revision: 8407

Added:
   short/3D/PyLith/benchmarks/trunk/quasistatic/strikeslipnog/figs/plot_error.py
   short/3D/PyLith/benchmarks/trunk/quasistatic/strikeslipnog/figs/plot_soln.py
Modified:
   short/3D/PyLith/benchmarks/trunk/quasistatic/strikeslipnog/figs/plot_geometry.py
Log:
Improved plotting geometry. Added scripts to plot solution and error.

Added: short/3D/PyLith/benchmarks/trunk/quasistatic/strikeslipnog/figs/plot_error.py
===================================================================
--- short/3D/PyLith/benchmarks/trunk/quasistatic/strikeslipnog/figs/plot_error.py	2007-12-07 17:43:56 UTC (rev 8406)
+++ short/3D/PyLith/benchmarks/trunk/quasistatic/strikeslipnog/figs/plot_error.py	2007-12-07 22:28:04 UTC (rev 8407)
@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+from plot_geometry import PlotScene
+
+shape = "tet4"
+res = 500
+
+class PlotError(PlotScene):
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def run(self):    
+    from enthought.mayavi.sources.vtk_data_source import VTKDataSource
+    from enthought.mayavi.modules.iso_surface import IsoSurface
+
+    self._setupScene()
+    data = self._readData()
+
+    script = self.script
+    script.add_source(VTKDataSource(data=data))
+    script.engine.current_object.name = "Error"
+    surf = IsoSurface()
+    script.add_module(surf)
+    
+    return
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _readData(self):
+    from enthought.tvtk.api import tvtk
+    import tables
+    import numpy
+
+    filename = "../projection/pylith_%s_%04dm.h5" % (shape, res)
+    h5 = tables.openFile(filename, 'r')
+
+    cells = h5.root.topology.cells[:]
+    (ncells, ncorners) = cells.shape
+    vertices = h5.root.geometry.vertices[:] / 1e+3
+    (nvertices, spaceDim) = vertices.shape
+    error = h5.root.difference.pylith_1_0_analytic.snapshot0.displacements[:]
+    h5.close()
+    
+    if shape == "tet4":
+        assert(spaceDim == 3)
+        assert(ncorners == 4)
+        cellType = tvtk.Tetra().cell_type
+    else:
+        raise ValueError("Unknown shape '%s'." % shape)
+
+    errorLog10 = numpy.log10(error)
+
+    data = tvtk.UnstructuredGrid()
+    data.points = vertices
+    data.set_cells(cellType, cells)
+    data.point_data.scalars = errorLog10
+    data.point_data.scalars.name = "log10(Error [m])"
+    return data
+
+
+# ----------------------------------------------------------------------
+if __name__ == "__main__":
+  app = PlotError()
+  app.main()
+
+
+# End of file
+


Property changes on: short/3D/PyLith/benchmarks/trunk/quasistatic/strikeslipnog/figs/plot_error.py
___________________________________________________________________
Name: svn:executable
   + *

Modified: short/3D/PyLith/benchmarks/trunk/quasistatic/strikeslipnog/figs/plot_geometry.py
===================================================================
--- short/3D/PyLith/benchmarks/trunk/quasistatic/strikeslipnog/figs/plot_geometry.py	2007-12-07 17:43:56 UTC (rev 8406)
+++ short/3D/PyLith/benchmarks/trunk/quasistatic/strikeslipnog/figs/plot_geometry.py	2007-12-07 22:28:04 UTC (rev 8407)
@@ -14,16 +14,31 @@
 import vtk_geometry
 from enthought.mayavi.sources.vtk_data_source import VTKDataSource
 
-class PlotGeometry(Mayavi):
+class PlotScene(Mayavi):
 
-  def run(self):
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def run(self):    
+    self._setupScene(showFaultTaper=True)
+    return
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _setupScene(self,
+                  showFault=True,
+                  showMaterials=True,
+                  showFaultTaper=False):
+    """
+    Plot axes, fault surface, and materials.
+    """
+
     from enthought.mayavi.modules.outline import Outline
     from enthought.mayavi.modules.axes import Axes
     from enthought.mayavi.modules.surface import Surface
-    
+
+    # Create rendering scene
     script = self.script
-    
-    # Create rendering scene
     script.new_scene()
     script.engine.current_scene.scene.background = (1,1,1)
     script.engine.current_scene.scene.foreground = (0,0,0)
@@ -43,37 +58,40 @@
     script.add_module(axes)
 
     # Fault surface
-    srcs = vtk_geometry.fault(showTaper=True)
-    for src in srcs:
-      script.add_source(VTKDataSource(data=src['object']))
-      script.engine.current_object.name = "Fault %s" % src['name']
-      surf = Surface()
-      script.add_module(surf)
-      surf.actor.property.color = (1,0,0)
-      if src['name'] == "taper":
-        surf.actor.property.opacity = 0.1
-      else:
-        surf.actor.property.opacity = 0.3
+    if showFault:
+      srcs = vtk_geometry.fault(showTaper=showFaultTaper)
+      for src in srcs:
+        script.add_source(VTKDataSource(data=src['object']))
+        script.engine.current_object.name = "Fault %s" % src['name']
+        surf = Surface()
+        script.add_module(surf)
+        surf.actor.property.color = (1,0,0)
+        if src['name'] == "taper":
+          surf.actor.property.opacity = 0.1
+        else:
+          surf.actor.property.opacity = 0.3
 
     # Materials
-    srcs = vtk_geometry.materials()
-    for src in srcs:
-      script.add_source(VTKDataSource(data=src['object']))
-      script.engine.current_object.name = "Material %s" % src['name']
-      surf = Surface()
-      script.add_module(surf)
-      surf.actor.property.opacity = 0.1
-      if src['name'] == "elastic":
-        surf.actor.property.color = (1,1,0)
-      elif src['name'] == "viscoelastic":
-        surf.actor.property.color = (0,1,1)
+    if showMaterials:
+      srcs = vtk_geometry.materials()
+      for src in srcs:
+        script.add_source(VTKDataSource(data=src['object']))
+        script.engine.current_object.name = "Material %s" % src['name']
+        surf = Surface()
+        script.add_module(surf)
+        surf.actor.property.opacity = 0.1
+        if src['name'] == "elastic":
+          surf.actor.property.color = (1,1,0)
+        elif src['name'] == "viscoelastic":
+          surf.actor.property.color = (0,1,1)
 
     return
 
 
+
 # ----------------------------------------------------------------------
 if __name__ == "__main__":
-  app = PlotGeometry()
+  app = PlotScene()
   app.main()
 
 

Added: short/3D/PyLith/benchmarks/trunk/quasistatic/strikeslipnog/figs/plot_soln.py
===================================================================
--- short/3D/PyLith/benchmarks/trunk/quasistatic/strikeslipnog/figs/plot_soln.py	2007-12-07 17:43:56 UTC (rev 8406)
+++ short/3D/PyLith/benchmarks/trunk/quasistatic/strikeslipnog/figs/plot_soln.py	2007-12-07 22:28:04 UTC (rev 8407)
@@ -0,0 +1,98 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+from plot_geometry import PlotScene
+
+shape = "tet4"
+res = 1000
+
+class PlotSoln(PlotScene):
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def run(self):    
+    from enthought.mayavi.sources.vtk_data_source import VTKDataSource
+    from enthought.mayavi.filters.warp_vector import WarpVector
+    from enthought.mayavi.filters.extract_vector_norm import ExtractVectorNorm
+    from enthought.mayavi.modules.surface import Surface
+    from enthought.mayavi.modules.glyph import Glyph
+
+    self._setupScene(showFault=False, showMaterials=False)
+    data = self._readData()
+
+    script = self.script
+    script.add_source(VTKDataSource(data=data))
+    script.engine.current_object.name = "Solution"
+
+    warp = WarpVector()
+    script.add_filter(warp)
+
+    norm = ExtractVectorNorm()
+    script.add_filter(norm)
+    
+    surf = Surface()
+    script.add_module(surf)
+    glyph = Glyph()
+    script.add_module(glyph)
+    glyph.actor.property.color = (1,1,1)
+    glyph.actor.mapper.scalar_visibility = False
+    glyph.glyph.glyph_position = 'tail'
+    glyph.glyph.glyph_source = glyph.glyph.glyph_list[1]
+    
+    return
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _readData(self):
+    from enthought.tvtk.api import tvtk
+    import tables
+    import numpy
+
+    filename = "../results/strikeslip_%s_%04dm.h5" % (shape, res)
+    h5 = tables.openFile(filename, 'r')
+
+    cells = h5.root.topology.cells[:]
+    (ncells, ncorners) = cells.shape
+    vertices = h5.root.geometry.vertices[:] / 1e+3
+    (nvertices, spaceDim) = vertices.shape
+    disp = h5.root.solution.snapshot0.displacements[:]
+    h5.close()
+    
+    if shape == "tet4":
+        assert(spaceDim == 3)
+        assert(ncorners == 4)
+        cellType = tvtk.Tetra().cell_type
+    else:
+        raise ValueError("Unknown shape '%s'." % shape)
+
+    # Zero out values for Lagrange multipliers
+    mask = numpy.ones( (nvertices,), dtype=numpy.bool)
+    mask[cells.flatten()] = False
+    disp[mask,:] = 0.0
+
+    data = tvtk.UnstructuredGrid()
+    data.points = vertices
+    data.set_cells(cellType, cells)
+    data.point_data.vectors = disp
+    data.point_data.vectors.name = "Displacement [m]"
+    return data
+
+
+# ----------------------------------------------------------------------
+if __name__ == "__main__":
+  app = PlotSoln()
+  app.main()
+
+
+# End of file
+


Property changes on: short/3D/PyLith/benchmarks/trunk/quasistatic/strikeslipnog/figs/plot_soln.py
___________________________________________________________________
Name: svn:executable
   + *



More information about the cig-commits mailing list