[cig-commits] r6489 - in short/3D/PyLith/trunk: examples/twotri3
libsrc/meshio
knepley at geodynamics.org
knepley at geodynamics.org
Sat Mar 31 12:54:13 PDT 2007
Author: knepley
Date: 2007-03-31 12:54:13 -0700 (Sat, 31 Mar 2007)
New Revision: 6489
Modified:
short/3D/PyLith/trunk/examples/twotri3/twotri3.mesh
short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc
short/3D/PyLith/trunk/libsrc/meshio/MeshIO.hh
short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc
short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.hh
Log:
Added groups to Mesh file
Modified: short/3D/PyLith/trunk/examples/twotri3/twotri3.mesh
===================================================================
--- short/3D/PyLith/trunk/examples/twotri3/twotri3.mesh 2007-03-31 19:43:45 UTC (rev 6488)
+++ short/3D/PyLith/trunk/examples/twotri3/twotri3.mesh 2007-03-31 19:54:13 UTC (rev 6489)
@@ -22,4 +22,13 @@
1 1
}
}
+ group = {
+ type = vertices
+ name = fault
+ count = 2
+ indices = {
+ 1
+ 2
+ }
+ }
}
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc 2007-03-31 19:43:45 UTC (rev 6488)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc 2007-03-31 19:54:13 UTC (rev 6489)
@@ -255,5 +255,75 @@
*pNumCells = numCells;
} // _getMaterials
+// ----------------------------------------------------------------------
+// Build a point group as an int sectio
+void
+pylith::meshio::MeshIO::_buildGroup(const std::string& name,
+ const PointType type,
+ const int numPoints,
+ const int* points)
+{ // _buildMesh
+ assert(0 != _mesh);
+ ALE::Obj<Mesh>& mesh = *_mesh;
+ mesh.addRef();
+
+ const ALE::Obj<Mesh::int_section_type>& groupField = mesh->getIntSection(name);
+
+ if (CELL == type) {
+ for(int i = 0; i < numPoints; ++i) {
+ groupField->setFiberDimension(points[i], 1);
+ }
+ } else if (VERTEX == type) {
+ const int numCells = mesh->heightStratum(0)->size();
+ for(int i = 0; i < numPoints; ++i) {
+ groupField->setFiberDimension(points[i]+numCells, 1);
+ }
+ } // if
+ mesh->allocate(groupField);
+ groupField->view("Group Field");
+} // _buildMesh
+
+// ----------------------------------------------------------------------
+// Get group names
+ALE::Obj<std::set<std::string> >
+pylith::meshio::MeshIO::_getGroups() const
+{
+ return (*_mesh)->getIntSections();
+}
+
+// ----------------------------------------------------------------------
+// Get group entities
+void
+pylith::meshio::MeshIO::_getGroup(const char *name,
+ PointType& type,
+ int& numPoints,
+ int *points[]) const
+{ // _getMaterials
+ assert(0 != _mesh);
+ ALE::Obj<Mesh>& mesh = *_mesh;
+ mesh.addRef();
+
+ const ALE::Obj<Mesh::int_section_type>& groupField = mesh->getIntSection(name);
+ const Mesh::int_section_type::chart_type& chart = groupField->getChart();
+ const Mesh::point_type firstPoint = *chart.begin();
+ ALE::Obj<Mesh::numbering_type> numbering;
+
+ if (mesh->height(firstPoint) == 0) {
+ type = CELL;
+ numbering = mesh->getFactory()->getNumbering(mesh, mesh->depth());
+ } else {
+ type = VERTEX;
+ numbering = mesh->getFactory()->getNumbering(mesh, 0);
+ }
+ numPoints = chart.size();
+ int *indices = new int[numPoints];
+ int i = 0;
+
+ for(Mesh::int_section_type::chart_type::iterator c_iter = chart.begin(); c_iter != chart.end(); ++c_iter) {
+ indices[i++] = numbering->getIndex(*c_iter);
+ }
+ *points = indices;
+} // _getMaterials
+
// End of file
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIO.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIO.hh 2007-03-31 19:43:45 UTC (rev 6488)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIO.hh 2007-03-31 19:54:13 UTC (rev 6489)
@@ -31,6 +31,7 @@
// PUBLIC MEMBERS ///////////////////////////////////////////////////////
public :
+ typedef enum {VERTEX, CELL} PointType;
/// Constructor
MeshIO(void);
@@ -153,6 +154,35 @@
void _getMaterials(int** pMaterialIds,
int* pNumCells) const;
+ /** Build a point group
+ *
+ * @param name The group name
+ * @param type The point type, e.g. VERTEX, CELL
+ * @param numPoints The number of points
+ * @param points An array of the points
+ */
+ void _buildGroup(const std::string& name,
+ const PointType type,
+ const int numPoints,
+ const int* points);
+
+ /** Return all group names
+ *
+ */
+ ALE::Obj<std::set<std::string> > _getGroups() const;
+
+ /** Return a point group
+ *
+ * @param name The group name
+ * @param type The point type, e.g. VERTEX, CELL
+ * @param numPoints The number of points
+ * @param points An array of the points
+ */
+ void _getGroup(const char *name,
+ PointType& type,
+ int& numPoints,
+ int *points[]) const;
+
// PRIVATE MEMBERS //////////////////////////////////////////////////////
private :
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc 2007-03-31 19:43:45 UTC (rev 6488)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc 2007-03-31 19:54:13 UTC (rev 6489)
@@ -20,6 +20,8 @@
#include <assert.h> // USES assert()
#include <iomanip> // USES setw(), setiosflags(), resetiosflags()
+const char *pylith::meshio::MeshIOAscii::groupTypeNames[] = {"vertices", "cells"};
+
// ----------------------------------------------------------------------
// Constructor
pylith::meshio::MeshIOAscii::MeshIOAscii(void) :
@@ -93,11 +95,18 @@
_readCells(filein, &cells, &materialIds, &numCells, &numCorners);
readCells = true;
} else if (0 == strcasecmp(token.c_str(), "group")) {
+ std::string name;
+ pylith::meshio::MeshIO::PointType type;
+ int numPoints;
+ int *points;
+
if (!builtMesh)
- throw std::runtime_error("Both 'vertices' and 'cells' must "
+ throw std::runtime_error("Both 'vertices' and 'cells' must "
"precede any groups in mesh file.");
filein.ignore(maxIgnore, '{');
- //_readGroup(filein, mesh);
+ _readGroup(filein, name, type, numPoints, &points);
+ _buildGroup(name, type, numPoints, points);
+ delete [] points;
} else {
std::ostringstream msg;
msg << "Could not parse '" << token << "' into a mesh setting.";
@@ -140,7 +149,12 @@
_writeVertices(fileout);
_writeCells(fileout);
+ ALE::Obj<std::set<std::string> > groups = _getGroups();
+ for(std::set<std::string>::const_iterator name = groups->begin(); name != groups->end(); ++name) {
+ _writeGroup(fileout, name->c_str());
+ }
+
// LOOP OVER GROUPS
// _writeGroup(fileout, mesh, nameIter->c_str());
@@ -378,43 +392,53 @@
<< " }\n";
} // _writeCells
-#if 0
// ----------------------------------------------------------------------
// Read mesh group.
void
pylith::meshio::MeshIOAscii::_readGroup(std::istream& filein,
- const ALE::Obj<Mesh>& mesh) const
+ std::string& name,
+ pylith::meshio::MeshIO::PointType& type,
+ int& numPoints,
+ int *points[]) const
{ // _readGroup
- std::string name = ""; // Name of group
- int dimension = 0; // Topology dimension associated with group
- int count = 0; // Number of entities in group
int* indices = 0; // Indices of entities in group
std::string token;
const int maxIgnore = 1024;
+ numPoints = -1;
filein >> token;
while (filein.good() && token != "}") {
if (0 == strcasecmp(token.c_str(), "name")) {
filein.ignore(maxIgnore, '=');
filein >> name;
- } else if (0 == strcasecmp(token.c_str(), "dimension")) {
+ } else if (0 == strcasecmp(token.c_str(), "type")) {
+ std::string typeName;
filein.ignore(maxIgnore, '=');
- filein >> dimension;
+ filein >> typeName;
+ if (typeName == groupTypeNames[VERTEX]) {
+ type = VERTEX;
+ } else if (typeName == groupTypeNames[CELL]) {
+ type = CELL;
+ } else {
+ std::ostringstream msg;
+ msg << "Invalid point type " << typeName << ".";
+ throw std::runtime_error(msg.str());
+ }
} else if (0 == strcasecmp(token.c_str(), "count")) {
filein.ignore(maxIgnore, '=');
- filein >> count;
+ filein >> numPoints;
} else if (0 == strcasecmp(token.c_str(), "indices")) {
- if (0 == count) {
- std::ostringstream msg;
- msg << "Tokens 'count' must precede 'indices'.";
- throw std::runtime_error(msg.str());
+ if (-1 == numPoints) {
+ std::ostringstream msg;
+ msg << "Tokens 'count' must precede 'indices'.";
+ throw std::runtime_error(msg.str());
} // if
filein.ignore(maxIgnore, '{');
- delete[] indices; indices = new int[count];
+ delete[] indices; indices = new int[numPoints];
assert(0 != indices);
- for (int i = 0; i < count; ++i)
- filein >> indices[i];
+ for (int i = 0; i < numPoints; ++i)
+ filein >> indices[i];
filein.ignore(maxIgnore, '}');
} else {
std::ostringstream msg;
@@ -425,51 +449,32 @@
} // while
if (!filein.good())
throw std::runtime_error("I/O error while parsing group settings.");
-
- assert(!mesh.isNull());
- ALE::Obj<Mesh::field_type> groupField = mesh->getField(name);
- const int meshDim = mesh->getDimension();
- ALE::Obj<std::list<Mesh::point_type> > patchPoints =
- std::list<Mesh::point_type>();
- Mesh::field_type::patch_type patch;
-
- patchPoints->clear();
- if (meshDim == dimension) {
- for (int i=0; i < count; ++i)
- patchPoints->push_back(Mesh::point_type(0, indices[i]));
- groupField->setPatch(patchPoints, patch);
- } else if (0 == dimension) {
- } // if
- groupField->setFiberDimensionByHeight(patch, 0, 1);
- groupField->orderPatches();
- const double zero = 0;
- for (int i=0; i < count; ++i)
- groupField->update(patch, Mesh::point_type(0, i), &zero);
+ *points = indices;
} // _readGroup
// ----------------------------------------------------------------------
// Write mesh group.
void
pylith::meshio::MeshIOAscii::_writeGroup(std::ostream& fileout,
- const ALE::Obj<Mesh>& mesh,
const char* name) const
{ // _writeGroup
- //_writeGroup(fileout, mesh);
- // ADD STUFF HERE
- int count = 0; // TEMPORARY
- int dimension = 0; // TEMPORARY
+ pylith::meshio::MeshIO::PointType type;
+ int numPoints;
+ int *points;
+ _getGroup(name, type, numPoints, &points);
fileout
<< " group = {\n"
<< " name = " << name << "\n"
- << " dimension = " << dimension << "\n"
- << " count = " << count << "\n"
+ << " type = " << groupTypeNames[type] << "\n"
+ << " count = " << numPoints << "\n"
<< " indices = {\n";
-
+ for(int i = 0; i < numPoints; ++i) {
+ fileout << " " << points[i] << "\n";
+ }
fileout
<< " }\n"
<< " }\n";
} // _writeGroup
-#endif
// End of file
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.hh 2007-03-31 19:43:45 UTC (rev 6488)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.hh 2007-03-31 19:54:13 UTC (rev 6489)
@@ -28,6 +28,7 @@
{ // MeshIOAscii
// PUBLIC METHODS -------------------------------------------------------
public :
+ static const char *groupTypeNames[];
/// Constructor
MeshIOAscii(void);
@@ -99,6 +100,25 @@
* @param numCorners Number of corners
*/
void _writeCells(std::ostream& fileout) const;
+
+ /** Read a point group.
+ *
+ * @param filein Input stream
+ * @param mesh The mesh
+ */
+ void _readGroup(std::istream& filein,
+ std::string& name,
+ pylith::meshio::MeshIO::PointType& type,
+ int& numPoints, int *points[]) const;
+
+ /** Write a point group.
+ *
+ * @param fileout Output stream
+ * @param mesh The mesh
+ * @param name The group name
+ */
+ void _writeGroup(std::ostream& fileout,
+ const char *name) const;
// PRIVATE MEMBERS ----------------------------------------------------
private :
More information about the cig-commits
mailing list