[cig-commits] r17202 - in short/3D/PyLith/trunk: libsrc/meshio unittests/pytests/topology unittests/pytests/topology/data

brad at geodynamics.org brad at geodynamics.org
Mon Sep 20 11:46:24 PDT 2010


Author: brad
Date: 2010-09-20 11:46:24 -0700 (Mon, 20 Sep 2010)
New Revision: 17202

Added:
   short/3D/PyLith/trunk/unittests/pytests/topology/TestRefineUniform.py
   short/3D/PyLith/trunk/unittests/pytests/topology/data/twotet4.mesh
   short/3D/PyLith/trunk/unittests/pytests/topology/data/twotet4_nofault_refined2.mesh
Modified:
   short/3D/PyLith/trunk/libsrc/meshio/DataWriterHDF5.cc
   short/3D/PyLith/trunk/unittests/pytests/topology/Makefile.am
   short/3D/PyLith/trunk/unittests/pytests/topology/data/Makefile.am
   short/3D/PyLith/trunk/unittests/pytests/topology/testtopology.py
Log:
Worked on uniform refinement test.

Modified: short/3D/PyLith/trunk/libsrc/meshio/DataWriterHDF5.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/DataWriterHDF5.cc	2010-09-20 14:47:07 UTC (rev 17201)
+++ short/3D/PyLith/trunk/libsrc/meshio/DataWriterHDF5.cc	2010-09-20 18:46:24 UTC (rev 17202)
@@ -223,7 +223,7 @@
   const int indexExt = _filename.find(".h5");
   const int numTimeSteps = DataWriter<mesh_type, field_type>::_numTimeSteps;
   if (0 == numTimeSteps)
-    filename << std::string(_filename, 0, indexExt) << "_info.hdf5";
+    filename << std::string(_filename, 0, indexExt) << "_info.h5";
 
   return std::string(filename.str());
 } // _hdf5Filename

Modified: short/3D/PyLith/trunk/unittests/pytests/topology/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/Makefile.am	2010-09-20 14:47:07 UTC (rev 17201)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/Makefile.am	2010-09-20 18:46:24 UTC (rev 17202)
@@ -42,7 +42,8 @@
 	TestJacobian.py \
 	TestMeshGenerator.py \
 	TestMeshGenSimple.py \
-	TestMeshImporter.py
+	TestMeshImporter.py \
+	TestRefineUniform.py
 
 
 noinst_tmp = \

Added: short/3D/PyLith/trunk/unittests/pytests/topology/TestRefineUniform.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/TestRefineUniform.py	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/TestRefineUniform.py	2010-09-20 18:46:24 UTC (rev 17202)
@@ -0,0 +1,105 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard, U.S. Geological Survey
+# Charles A. Williams, GNS Science
+# Matthew G. Knepley, University of Chicago
+#
+# This code was developed as part of the Computational Infrastructure
+# for Geodynamics (http://geodynamics.org).
+#
+# Copyright (c) 2010 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/topology/TestRefineUniform.py
+
+## @brief Unit testing of Python RefineUniform object.
+
+import unittest
+
+from pylith.topology.RefineUniform import RefineUniform
+
+from pylith.topology.RefineUniform import RefineUniform
+
+# ----------------------------------------------------------------------
+class TestRefineUniform(unittest.TestCase):
+  """
+  Unit testing of Python RefineUniform object.
+  """
+
+  def test_constructor(self):
+    """
+    Test constructor.
+    """
+    io = RefineUniform()
+    return
+
+
+  def test_refineTet4NoFault(self):
+    """
+    Test refine().
+    """
+    filenameIn = "data/twotet4.mesh"
+    filenameOut = "data/twotet4_test.mesh"
+    filenameOutE = "data/twotet4_nofault_refined2.mesh"
+
+    self._runTest(filenameIn, filenameOut, filenameOutE)
+    return
+
+
+  def test_factory(self):
+    """
+    Test factory method.
+    """
+    from pylith.topology.RefineUniform import mesh_refiner
+    refiner = mesh_refiner()
+    return
+
+
+  def _runTest(self, filenameIn, filenameOut, filenameOutE):
+
+    from spatialdata.geocoords.CSCart import CSCart
+    cs = CSCart()
+    cs._configure()
+
+    from pylith.meshio.MeshIOAscii import MeshIOAscii
+    io = MeshIOAscii()
+    io.inventory.filename = filenameIn
+    io.inventory.coordsys = cs
+    io._configure()
+    
+    from spatialdata.units.Nondimensional import Nondimensional
+    normalizer = Nondimensional()
+
+    mesh = io.read(debug=True, interpolate=False)
+
+    from pylith.topology.RefineUniform import RefineUniform
+    refiner = RefineUniform()
+    meshRefined = refiner.refine(mesh)
+
+    meshRefined.view("MESH")
+    
+    io.filename(filenameOut)
+    io.write(meshRefined)
+
+    fileE = open(filenameOutE, "r")
+    linesE = fileE.readlines()
+    fileE.close()
+    fileT = open(filenameOut, "r")
+    linesT = fileT.readlines()
+    fileT.close()
+
+    self.assertEqual(len(linesE), len(linesT))
+    for (lineE, lineT) in zip(linesE, linesT):
+      self.assertEqual(lineE, lineT)
+    
+    return
+
+
+
+# End of file 

Modified: short/3D/PyLith/trunk/unittests/pytests/topology/data/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/data/Makefile.am	2010-09-20 14:47:07 UTC (rev 17201)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/data/Makefile.am	2010-09-20 18:46:24 UTC (rev 17202)
@@ -17,7 +17,9 @@
 #
 
 dist_noinst_DATA = \
-	tri3.mesh
+	tri3.mesh \
+	twotet4.mesh \
+	twotet4_nofault_refined2.mesh
 
 noinst_TMP =
 

Added: short/3D/PyLith/trunk/unittests/pytests/topology/data/twotet4.mesh
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/data/twotet4.mesh	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/data/twotet4.mesh	2010-09-20 18:46:24 UTC (rev 17202)
@@ -0,0 +1,110 @@
+// Global mesh object.
+// This defines a mesh composed of two tetrahedral elements.
+mesh = {
+
+  // This is a 3D mesh.
+  dimension = 3
+
+  // We are using zero-indexing (default) rather than one-indexing.
+  use-index-zero = true
+
+  // Describe the vertices (nodes) defining the mesh.
+  vertices = {
+
+    // The vertices are defined in a 3D coordinate system.
+    dimension = 3
+
+    // There are 5 vertices.
+    count = 5
+
+    // List the coordinates as:
+    // Vertex number (starting from zero), x-coord, y-coord, z-coord
+    // Use coordinate units that are consistent with the other units used.
+    coordinates = {
+             0     -1.0  0.0  0.0
+             1      0.0 -1.0  0.0
+             2      0.0  0.0  1.0
+             3      0.0  1.0  0.0
+             4      1.0  0.0  0.0
+    }
+  }
+
+  // Describe the cells (elements) composing the mesh.
+  cells = {
+
+    // There are 2 cells.
+    count = 2
+
+    // These are linear tetrahedral cells, so there are 4 corners per cell.
+    num-corners = 4
+
+    // List the vertices composing each cell (see manual for ordering).
+    // List the information as:
+    // Cell number (starting from zero), vertex 0, vertex 1, vertex 2, vertex 3
+    simplices = {
+             0       1  2  3  0
+             1       1  3  2  4
+    }
+
+    // List the material ID's associated with each cell.
+    // Different ID's may be used to specify a different material type, or
+    // to use a different spatial database for each material ID.
+    // In this example, cells 0 and 1 both are associated with material ID 1.
+    material-ids = {
+             0   1
+             1   1
+    }
+  }
+
+  // Here we list different groups (cells or vertices) that we want to associate
+  // with a particular name (ID).
+
+  // This group of vertices may be used to define a fault.
+  // There are 3 vertices corresponding to indices 1, 2 and 3.
+  group = {
+    name = fault
+    type = vertices
+    count = 3
+    indices = {
+      1
+      2
+      3
+    }
+  }
+
+  // This group of vertices may be used to specify boundary conditions.
+  // There are 2 vertices corresponding to indices 0 and 4.
+  group = {
+    name = end points
+    type = vertices
+    count = 2
+    indices = {
+      0
+      4
+    }
+  }
+
+  // This group of vertices may be used to specify boundary conditions.
+  // There are 2 vertices corresponding to indices 0, 1.
+  group = {
+    name = edge 1
+    type = vertices
+    count = 2
+    indices = {
+      0
+      1
+    }
+  }
+
+  // This group of vertices may be used to specify boundary conditions.
+  // There are 2 vertices corresponding to indices 2, 4.
+  group = {
+    name = edge 2
+    type = vertices
+    count = 2
+    indices = {
+      2
+      4
+    }
+  }
+}

Added: short/3D/PyLith/trunk/unittests/pytests/topology/data/twotet4_nofault_refined2.mesh
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/data/twotet4_nofault_refined2.mesh	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/data/twotet4_nofault_refined2.mesh	2010-09-20 18:46:24 UTC (rev 17202)
@@ -0,0 +1,110 @@
+// Global mesh object.
+// This defines a mesh composed of two tetrahedral elements.
+mesh = {
+
+  // This is a 3D mesh.
+  dimension = 3
+
+  // We are using zero-indexing (default) rather than one-indexing.
+  use-index-zero = true
+
+  // Describe the vertices (nodes) defining the mesh.
+  vertices = {
+
+    // The vertices are defined in a 3D coordinate system.
+    dimension = 3
+
+    // There are 5 vertices.
+    count = 5
+
+    // List the coordinates as:
+    // Vertex number (starting from zero), x-coord, y-coord, z-coord
+    // Use coordinate units that are consistent with the other units used.
+    coordinates = {
+             0     -1.0  0.0  0.0
+             1      0.0 -1.0  0.0
+             2      0.0  0.0  1.0
+             3      0.0  1.0  0.0
+             4      1.0  0.0  0.0
+    }
+  }
+
+  // Describe the cells (elements) composing the mesh.
+  cells = {
+
+    // There are 2 cells.
+    count = 2
+
+    // These are linear tetrahedral cells, so there are 4 corners per cell.
+    num-corners = 4
+
+    // List the vertices composing each cell (see manual for ordering).
+    // List the information as:
+    // Cell number (starting from zero), vertex 0, vertex 1, vertex 2, vertex 3
+    simplices = {
+             0       1  2  3  0
+             1       1  3  2  4
+    }
+
+    // List the material ID's associated with each cell.
+    // Different ID's may be used to specify a different material type, or
+    // to use a different spatial database for each material ID.
+    // In this example, cells 0 and 1 both are associated with material ID 1.
+    material-ids = {
+             0   1
+             1   1
+    }
+  }
+
+  // Here we list different groups (cells or vertices) that we want to associate
+  // with a particular name (ID).
+
+  // This group of vertices may be used to define a fault.
+  // There are 3 vertices corresponding to indices 1, 2 and 3.
+  group = {
+    name = fault
+    type = vertices
+    count = 3
+    indices = {
+      1
+      2
+      3
+    }
+  }
+
+  // This group of vertices may be used to specify boundary conditions.
+  // There are 2 vertices corresponding to indices 0 and 4.
+  group = {
+    name = end points
+    type = vertices
+    count = 2
+    indices = {
+      0
+      4
+    }
+  }
+
+  // This group of vertices may be used to specify boundary conditions.
+  // There are 2 vertices corresponding to indices 0, 1.
+  group = {
+    name = edge 1
+    type = vertices
+    count = 2
+    indices = {
+      0
+      1
+    }
+  }
+
+  // This group of vertices may be used to specify boundary conditions.
+  // There are 2 vertices corresponding to indices 2, 4.
+  group = {
+    name = edge 2
+    type = vertices
+    count = 2
+    indices = {
+      2
+      4
+    }
+  }
+}

Modified: short/3D/PyLith/trunk/unittests/pytests/topology/testtopology.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/testtopology.py	2010-09-20 14:47:07 UTC (rev 17201)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/testtopology.py	2010-09-20 18:46:24 UTC (rev 17202)
@@ -87,6 +87,9 @@
     from TestMeshImporter import TestMeshImporter
     suite.addTest(unittest.makeSuite(TestMeshImporter))
 
+    from TestRefineUniform import TestRefineUniform
+    suite.addTest(unittest.makeSuite(TestRefineUniform))
+
     return suite
 
 



More information about the CIG-COMMITS mailing list