[cig-commits] r12875 - short/3D/PyLith/trunk/libsrc/topology
brad at geodynamics.org
brad at geodynamics.org
Sat Sep 13 15:14:56 PDT 2008
Author: brad
Date: 2008-09-13 15:14:55 -0700 (Sat, 13 Sep 2008)
New Revision: 12875
Modified:
short/3D/PyLith/trunk/libsrc/topology/MeshOps.cc
Log:
Added check to make sure all materials are associated with at least 1 cell.
Modified: short/3D/PyLith/trunk/libsrc/topology/MeshOps.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/MeshOps.cc 2008-09-13 00:56:06 UTC (rev 12874)
+++ short/3D/PyLith/trunk/libsrc/topology/MeshOps.cc 2008-09-13 22:14:55 UTC (rev 12875)
@@ -14,12 +14,16 @@
#include "MeshOps.hh" // implementation of class methods
+#include "pylith/utils/array.hh" // USES int_array
+
#include <stdexcept> // USES std::runtime_error
#include <sstream> // USES std::ostringstream
#include <assert.h> // USES assert()
#include <algorithm> // USES std::sort, std::find
+#include <map> // USES std::map
+
// ----------------------------------------------------------------------
void
pylith::topology::MeshOps::checkMaterialIds(const ALE::Obj<Mesh>& mesh,
@@ -29,6 +33,14 @@
assert( (0 == numMaterials && 0 == materialIds) ||
(0 < numMaterials && 0 != materialIds) );
+ // Create map with indices for each material
+ std::map<int, int> materialIndex;
+ for (int i=0; i < numMaterials; ++i)
+ materialIndex[materialIds[i]] = i;
+
+ int_array matCellCounts(numMaterials);
+ matCellCounts = 0;
+
const ALE::Obj<Mesh::label_sequence>& cells = mesh->heightStratum(0);
assert(!cells.isNull());
const Mesh::label_sequence::iterator cellsEnd = cells->end();
@@ -49,7 +61,24 @@
<< "' does not match the id of any available materials or interfaces.";
throw std::runtime_error(msg.str());
} // if
+
+ const int matIndex = materialIndex[cellId];
+ assert(0 <= matIndex && matIndex < numMaterials);
+ ++matCellCounts[matIndex];
} // for
+
+ // Make sure each material has
+ int_array matCellCountsAll(matCellCounts.size());
+ MPI_Allreduce(&matCellCounts[0], &matCellCountsAll[0],
+ matCellCounts.size(), MPI_INT, MPI_SUM, mesh->comm());
+ for (int i=0; i < numMaterials; ++i)
+ if (matCellCountsAll[i] <= 0) {
+ std::ostringstream msg;
+ msg << "No cells associated with material with id '" << materialIds[i]
+ << "'.";
+ throw std::runtime_error(msg.str());
+ } // if
+
} // checkMaterialIds
More information about the cig-commits
mailing list