[cig-commits] [commit] knepley/upgrade-petsc-interface: Updated Python unit tests for interpolated meshes. (f706511)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Thu Nov 7 14:20:07 PST 2013


Repository : ssh://geoshell/pylith

On branch  : knepley/upgrade-petsc-interface
Link       : https://github.com/geodynamics/pylith/compare/7dc1717efea97bf36be5cf1ee76fac0388cf6dc1...f706511525a18a3ed18db1757934ca6142c943c4

>---------------------------------------------------------------

commit f706511525a18a3ed18db1757934ca6142c943c4
Author: Brad Aagaard <baagaard at usgs.gov>
Date:   Thu Nov 7 14:20:53 2013 -0800

    Updated Python unit tests for interpolated meshes.
    
    Filter out faces and edges when writing groups.


>---------------------------------------------------------------

f706511525a18a3ed18db1757934ca6142c943c4
 libsrc/pylith/meshio/MeshIO.cc               | 52 ++++++++++++++++++----------
 unittests/pytests/bc/TestNeumann.py          |  4 +--
 unittests/pytests/meshio/TestMeshIOAscii.py  |  2 +-
 unittests/pytests/meshio/TestMeshIOCubit.py  |  2 +-
 unittests/pytests/meshio/TestMeshIOLagrit.py |  2 +-
 5 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/libsrc/pylith/meshio/MeshIO.cc b/libsrc/pylith/meshio/MeshIO.cc
index 7f0f92e..857c60e 100644
--- a/libsrc/pylith/meshio/MeshIO.cc
+++ b/libsrc/pylith/meshio/MeshIO.cc
@@ -375,30 +375,46 @@ pylith::meshio::MeshIO::_getGroup(int_array* points,
   const PetscInt cEnd = cellsStratum.end();
   const PetscInt numCells = cellsStratum.size();
 
-  PetscInt pStart, pEnd, firstPoint = 0;
-  PetscErrorCode err = 0;
-  err = DMPlexGetChart(dmMesh, &pStart, &pEnd);PYLITH_CHECK_ERROR(err);
-  for(PetscInt p = pStart; p < pEnd; ++p) {
-    PetscInt val;
-    err = DMPlexGetLabelValue(dmMesh, name, p, &val);PYLITH_CHECK_ERROR(err);
-    if (val >= 0) {
-      firstPoint = p;
-      break;
-    } // if
-  } // for
-  *groupType = (firstPoint >= cStart && firstPoint < cEnd) ? CELL : VERTEX;
-
-  PetscInt groupSize;
-  err = DMPlexGetStratumSize(dmMesh, name, 1, &groupSize);PYLITH_CHECK_ERROR(err);
-  points->resize(groupSize);
+  topology::Stratum verticesStratum(dmMesh, topology::Stratum::DEPTH, 0);
+  const PetscInt vStart = verticesStratum.begin();
+  const PetscInt vEnd = verticesStratum.end();
 
-  const PetscInt offset = (VERTEX == *groupType) ? numCells : 0;
   PetscIS groupIS = NULL;
   const PetscInt* groupIndices = NULL;
+  PetscErrorCode err;
   err = DMPlexGetStratumIS(dmMesh, name, 1, &groupIS);PYLITH_CHECK_ERROR(err);
   err = ISGetIndices(groupIS, &groupIndices);PYLITH_CHECK_ERROR(err);
+
+  PetscInt totalSize;
+  err = DMPlexGetStratumSize(dmMesh, name, 1, &totalSize);PYLITH_CHECK_ERROR(err);
+
+  *groupType = VERTEX;
+  if (totalSize > 0 && (groupIndices[0] >= cStart && groupIndices[0] < cEnd)) {
+    *groupType = CELL;
+  } // if
+    
+  PetscInt offset = 0;
+  PetscInt pStart = cStart;
+  PetscInt pEnd = cEnd;
+  if (VERTEX == *groupType) {
+    offset = numCells;
+    pStart = vStart;
+    pEnd = vEnd;
+  } // if
+
+  // Count number of cells/vertices, filtering out edges and faces
+  PetscInt groupSize = 0;
+  for (PetscInt p = 0; p < totalSize; ++p) {
+    if (groupIndices[p] >= pStart && groupIndices[p] < pEnd) {
+      ++groupSize;
+    } // if
+  } // for
+
+  points->resize(groupSize);
   for(PetscInt p = 0; p < groupSize; ++p) {
-    (*points)[p] = groupIndices[p]-offset;
+    if (groupIndices[p] >= pStart && groupIndices[p] < pEnd) {
+      (*points)[p] = groupIndices[p]-offset;
+    } // if
   } // for
   err = ISRestoreIndices(groupIS, &groupIndices);PYLITH_CHECK_ERROR(err);
   err = ISDestroy(&groupIS);PYLITH_CHECK_ERROR(err);
diff --git a/unittests/pytests/bc/TestNeumann.py b/unittests/pytests/bc/TestNeumann.py
index 12da141..c96d579 100644
--- a/unittests/pytests/bc/TestNeumann.py
+++ b/unittests/pytests/bc/TestNeumann.py
@@ -220,7 +220,7 @@ class TestNeumann(unittest.TestCase):
     importer.inventory.filename = "data/tri3.mesh"
     importer.inventory.coordsys = cs
     importer._configure()
-    mesh = importer.read(debug=False, interpolate=False)
+    mesh = importer.read(debug=False, interpolate=True)
     
     bc.preinitialize(mesh)
     bc.initialize(totalTime=0.0, numTimeSteps=1, normalizer=normalizer)
@@ -230,7 +230,7 @@ class TestNeumann(unittest.TestCase):
     from pylith.topology.SolutionFields import SolutionFields
     fields = SolutionFields(mesh)
     fields.add("residual", "residual")
-    fields.add("disp(t), bc(t+dt)", "displacement")
+    fields.add("disp(t)", "displacement")
     fields.add("dispIncr(t->t+dt)", "displacement")
     fields.solutionName("dispIncr(t->t+dt)")
 
diff --git a/unittests/pytests/meshio/TestMeshIOAscii.py b/unittests/pytests/meshio/TestMeshIOAscii.py
index 1308300..b566787 100644
--- a/unittests/pytests/meshio/TestMeshIOAscii.py
+++ b/unittests/pytests/meshio/TestMeshIOAscii.py
@@ -69,7 +69,7 @@ class TestMeshIOAscii(unittest.TestCase):
     from spatialdata.units.Nondimensional import Nondimensional
     normalizer = Nondimensional()
 
-    mesh = io.read(debug=False, interpolate=False)
+    mesh = io.read(debug=False, interpolate=True)
 
     io.filename(filenameOut)
     io.write(mesh)
diff --git a/unittests/pytests/meshio/TestMeshIOCubit.py b/unittests/pytests/meshio/TestMeshIOCubit.py
index fc7bddd..c17c4b0 100644
--- a/unittests/pytests/meshio/TestMeshIOCubit.py
+++ b/unittests/pytests/meshio/TestMeshIOCubit.py
@@ -72,7 +72,7 @@ class TestMeshIOCubit(unittest.TestCase):
     from spatialdata.units.Nondimensional import Nondimensional
     normalizer = Nondimensional()
 
-    mesh = io.read(debug=False, interpolate=False)
+    mesh = io.read(debug=False, interpolate=True)
 
     testhandler = MeshIOAscii()
     testhandler.filename(filenameOut)
diff --git a/unittests/pytests/meshio/TestMeshIOLagrit.py b/unittests/pytests/meshio/TestMeshIOLagrit.py
index 8e3df97..031e671 100644
--- a/unittests/pytests/meshio/TestMeshIOLagrit.py
+++ b/unittests/pytests/meshio/TestMeshIOLagrit.py
@@ -77,7 +77,7 @@ class TestMeshIOLagrit(unittest.TestCase):
     from spatialdata.units.Nondimensional import Nondimensional
     normalizer = Nondimensional()
 
-    mesh = io.read(debug=False, interpolate=False)
+    mesh = io.read(debug=False, interpolate=True)
 
     testhandler = MeshIOAscii()
     testhandler.filename(filenameOut)



More information about the CIG-COMMITS mailing list