[cig-commits] r6063 - short/3D/PyLith/trunk/libsrc/meshio
brad at geodynamics.org
brad at geodynamics.org
Thu Feb 22 17:38:39 PST 2007
Author: brad
Date: 2007-02-22 17:38:39 -0800 (Thu, 22 Feb 2007)
New Revision: 6063
Modified:
short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc
short/3D/PyLith/trunk/libsrc/meshio/MeshIO.hh
Log:
Added routines to set material label.
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc 2007-02-22 21:44:49 UTC (rev 6062)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc 2007-02-23 01:38:39 UTC (rev 6063)
@@ -15,6 +15,8 @@
#include "MeshIO.hh" // implementation of class methods
#include <assert.h> // USES assert()
+#include <sstream> // USES std::ostringstream
+#include <stdexcept> // USES std::runtime_error
// ----------------------------------------------------------------------
// Constructor
@@ -84,8 +86,8 @@
topology->stratify();
mesh->setTopology(topology);
ALE::New::SieveBuilder<sieve_type>::buildCoordinates(
- mesh->getRealSection("coordinates"),
- spaceDim, coordinates);
+ mesh->getRealSection("coordinates"),
+ spaceDim, coordinates);
} // _buildMesh
// ----------------------------------------------------------------------
@@ -190,4 +192,75 @@
*pMeshDim = meshDim;
} // _getCells
+// ----------------------------------------------------------------------
+// Tag cells in mesh with material identifiers.
+void
+pylith::meshio::MeshIO::_setMaterials(const int* materialIds,
+ const int numCells)
+{ // _setMaterials
+ assert(0 != _mesh);
+ ALE::Obj<Mesh>& mesh = *_mesh;
+
+ const topology_type::patch_type patch = 0;
+ const ALE::Obj<topology_type>& topology = mesh->getTopology();
+ const ALE::Obj<Mesh::topology_type::label_sequence>& cells =
+ topology->heightStratum(patch, 0);
+
+ if (cells->size() != numCells) {
+ std::ostringstream msg;
+ msg << "Mismatch in size of materials identifier array ("
+ << numCells << ") and number of cells in mesh ("
+ << cells->size() << ").";
+ throw std::runtime_error(msg.str());
+ } // if
+
+ const ALE::Obj<patch_label_type>& labelMaterials =
+ topology->createLabel(patch, "material-id");
+
+ int i = 0;
+ for(Mesh::topology_type::label_sequence::iterator e_iter = cells->begin();
+ e_iter != cells->end();
+ ++e_iter)
+ topology->setValue(labelMaterials, *e_iter, materialIds[i++]);
+} // _setMaterials
+
+// ----------------------------------------------------------------------
+// Get material identifiers for cells.
+void
+pylith::meshio::MeshIO::_getMaterials(int** pMaterialIds,
+ int* pNumCells)
+{ // _getMaterials
+ assert(0 != _mesh);
+ ALE::Obj<Mesh>& mesh = *_mesh;
+
+ const topology_type::patch_type patch = 0;
+ const ALE::Obj<topology_type>& topology = mesh->getTopology();
+ const ALE::Obj<Mesh::topology_type::label_sequence>& cells =
+ topology->heightStratum(patch, 0);
+ const int numCells = cells->size();
+
+ int* materialsArray = 0;
+ const int size = numCells;
+ if (0 != pMaterialIds && size > 0) {
+ materialsArray = new int[size];
+
+ const ALE::Obj<patch_label_type>& labelMaterials =
+ topology->getLabel(patch, "material-id");
+ const int idDefault = 0;
+
+ int i = 0;
+ for(Mesh::topology_type::label_sequence::iterator e_iter = cells->begin();
+ e_iter != cells->end();
+ ++e_iter)
+ materialsArray[i++] =
+ topology->getValue(labelMaterials, *e_iter, idDefault);
+ } // if
+
+ if (0 != pMaterialIds)
+ *pMaterialIds = materialsArray;
+ if (0 != pNumCells)
+ *pNumCells = numCells;
+} // _getMaterials
+
+
// End of file
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIO.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIO.hh 2007-02-22 21:44:49 UTC (rev 6062)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIO.hh 2007-02-23 01:38:39 UTC (rev 6063)
@@ -28,6 +28,7 @@
typedef ALE::Mesh Mesh;
typedef ALE::Mesh::sieve_type sieve_type;
typedef ALE::Mesh::topology_type topology_type;
+ typedef ALE::Sifter<int, sieve_type::point_type, int> patch_label_type;
// PUBLIC MEMBERS ///////////////////////////////////////////////////////
public :
@@ -131,6 +132,22 @@
int* pNumCorners,
int* pMeshDim) const;
+ /** Tag cells in mesh with material identifiers.
+ *
+ * @param materialIds Material identifiers [numCells]
+ * @param numCells Number of cells
+ */
+ void _setMaterials(const int* materialIds,
+ const int numCells);
+
+ /** Get material identifiers for cells.
+ *
+ * @param materialIds Material identifiers [numCells]
+ * @param numCells Number of cells
+ */
+ void _getMaterials(int** pMaterialIds,
+ int* pNumCells);
+
// PRIVATE MEMBERS //////////////////////////////////////////////////////
private :
More information about the cig-commits
mailing list