[cig-commits] r6560 - in short/3D/PyLith/trunk/libsrc: feassemble
materials meshio utils
brad at geodynamics.org
brad at geodynamics.org
Thu Apr 12 18:19:45 PDT 2007
Author: brad
Date: 2007-04-12 18:19:44 -0700 (Thu, 12 Apr 2007)
New Revision: 6560
Added:
short/3D/PyLith/trunk/libsrc/utils/sievefwd.hh
short/3D/PyLith/trunk/libsrc/utils/sievetypes.hh
Modified:
short/3D/PyLith/trunk/libsrc/feassemble/Integrator.hh
short/3D/PyLith/trunk/libsrc/feassemble/ParameterManager.cc
short/3D/PyLith/trunk/libsrc/feassemble/ParameterManager.hh
short/3D/PyLith/trunk/libsrc/feassemble/Quadrature.hh
short/3D/PyLith/trunk/libsrc/materials/ElasticMaterial.hh
short/3D/PyLith/trunk/libsrc/materials/Material.cc
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
short/3D/PyLith/trunk/libsrc/utils/Makefile.am
short/3D/PyLith/trunk/libsrc/utils/arrayfwd.hh
Log:
Cleaned up MeshIO and MeshIOAscii interfaces (insulate MeshIO implementations from ALL Sieve stuff). Create helper header file to create aliases for Sieve types (readability and eliminate putting typedefs in a bunch of header files) and another helper header file for forward declaration of Petsc Mesh (insulate code from needless inclusion of header files where possible).
Modified: short/3D/PyLith/trunk/libsrc/feassemble/Integrator.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/feassemble/Integrator.hh 2007-04-12 21:11:36 UTC (rev 6559)
+++ short/3D/PyLith/trunk/libsrc/feassemble/Integrator.hh 2007-04-13 01:19:44 UTC (rev 6560)
@@ -24,7 +24,7 @@
#if !defined(pylith_feassemble_integrator_hh)
#define pylith_feassemble_integrator_hh
-#include <petscmesh.h> // USES Mesh
+#include "pylith/utils/sievetypes.hh" // USES PETSc Mesh
namespace pylith {
namespace feassemble {
@@ -40,13 +40,6 @@
{ // Integrator
friend class TestIntegrator; // unit testing
-// PUBLIC TYPEDEFS //////////////////////////////////////////////////////
-public :
-
- typedef ALE::Mesh Mesh;
- typedef Mesh::point_type point_type;
- typedef Mesh::real_section_type real_section_type;
-
// PUBLIC MEMBERS ///////////////////////////////////////////////////////
public :
Modified: short/3D/PyLith/trunk/libsrc/feassemble/ParameterManager.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/feassemble/ParameterManager.cc 2007-04-12 21:11:36 UTC (rev 6559)
+++ short/3D/PyLith/trunk/libsrc/feassemble/ParameterManager.cc 2007-04-13 01:19:44 UTC (rev 6560)
@@ -21,7 +21,7 @@
// ----------------------------------------------------------------------
// Constructor
pylith::feassemble::ParameterManager::ParameterManager(
- const ALE::Obj<Mesh>& mesh) :
+ const ALE::Obj<Mesh>& mesh) :
_mesh(mesh)
{ // constructor
} // constructor
@@ -54,7 +54,7 @@
// ----------------------------------------------------------------------
// Get parameter.
-const ALE::Obj<pylith::feassemble::ParameterManager::Mesh::real_section_type>&
+const ALE::Obj<pylith::real_section_type>&
pylith::feassemble::ParameterManager::getReal(const char* name)
{ // getReal
map_real_type::const_iterator iter = _real.find(name);
Modified: short/3D/PyLith/trunk/libsrc/feassemble/ParameterManager.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/feassemble/ParameterManager.hh 2007-04-12 21:11:36 UTC (rev 6559)
+++ short/3D/PyLith/trunk/libsrc/feassemble/ParameterManager.hh 2007-04-13 01:19:44 UTC (rev 6560)
@@ -26,7 +26,7 @@
#include <map> // HASA std::map
#include <string> // USES std::string
-#include <petscmesh.h> // USES Mesh
+#include "pylith/utils/sievetypes.hh" // USES PETSc Mesh
namespace pylith {
namespace feassemble {
@@ -39,13 +39,6 @@
{ // ParameterManager
friend class TestParameterManager; // unit testing
-// PUBLIC TYPEDEFS //////////////////////////////////////////////////////
-public :
-
- typedef ALE::Mesh Mesh;
- typedef Mesh::point_type point_type;
- typedef Mesh::real_section_type real_section_type;
-
// PUBLIC MEMBERS ///////////////////////////////////////////////////////
public :
@@ -81,7 +74,6 @@
typedef std::map< std::string, ALE::Obj<real_section_type> > map_real_type;
-
// PRIVATE MEMBERS //////////////////////////////////////////////////////
private :
Modified: short/3D/PyLith/trunk/libsrc/feassemble/Quadrature.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/feassemble/Quadrature.hh 2007-04-12 21:11:36 UTC (rev 6559)
+++ short/3D/PyLith/trunk/libsrc/feassemble/Quadrature.hh 2007-04-13 01:19:44 UTC (rev 6560)
@@ -31,9 +31,8 @@
#if !defined(pylith_feassemble_quadrature_hh)
#define pylith_feassemble_quadrature_hh
-#include <petscmesh.h>
-
#include "pylith/utils/array.hh" // HASA double_array
+#include "pylith/utils/sievetypes.hh" // USES PETSc Mesh
namespace pylith {
namespace feassemble {
@@ -45,12 +44,6 @@
{ // Quadrature
friend class TestQuadrature; // unit testing
-// PUBLIC TYPEDEFS //////////////////////////////////////////////////////
-public :
-
- typedef ALE::Mesh Mesh;
- typedef Mesh::real_section_type real_section_type;
-
// PUBLIC METHODS ///////////////////////////////////////////////////////
public :
Modified: short/3D/PyLith/trunk/libsrc/materials/ElasticMaterial.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/materials/ElasticMaterial.hh 2007-04-12 21:11:36 UTC (rev 6559)
+++ short/3D/PyLith/trunk/libsrc/materials/ElasticMaterial.hh 2007-04-13 01:19:44 UTC (rev 6560)
@@ -22,8 +22,8 @@
#include "Material.hh" // ISA Material
-#include <petscmesh.h> // USES Mesh
#include "pylith/utils/arrayfwd.hh" // USES double_array
+#include "pylith/utils/sievetypes.hh" // USES PETSc Mesh
#include <vector> // USES std::vector
/// Namespace for pylith package
@@ -40,12 +40,6 @@
{ // class ElasticMaterial
friend class TestElasticMaterial; ///< unit testing
- // PUBLIC TYPEDEFS ////////////////////////////////////////////////////
-public :
-
- typedef ALE::Mesh Mesh;
- typedef Mesh::real_section_type real_section_type;
-
// PUBLIC METHODS /////////////////////////////////////////////////////
public :
Modified: short/3D/PyLith/trunk/libsrc/materials/Material.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/materials/Material.cc 2007-04-12 21:11:36 UTC (rev 6559)
+++ short/3D/PyLith/trunk/libsrc/materials/Material.cc 2007-04-13 01:19:44 UTC (rev 6560)
@@ -70,8 +70,6 @@
assert(0 != quadrature);
assert(!mesh.isNull());
- typedef ALE::Mesh::real_section_type real_section_type;
-
// Get cells associated with material
const ALE::Obj<real_section_type>& coordinates =
mesh->getRealSection("coordinates");
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc 2007-04-12 21:11:36 UTC (rev 6559)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc 2007-04-13 01:19:44 UTC (rev 6560)
@@ -14,6 +14,10 @@
#include "MeshIO.hh" // implementation of class methods
+#include "pylith/utils/array.hh" // USES double_array, int_array
+
+#include "pylith/utils/sievetypes.hh" // USES PETSc Mesh
+
#include <assert.h> // USES assert()
#include <sstream> // USES std::ostringstream
#include <stdexcept> // USES std::runtime_error
@@ -72,15 +76,17 @@
// ----------------------------------------------------------------------
// Set vertices in mesh.
void
-pylith::meshio::MeshIO::_buildMesh(const double* coordinates,
+pylith::meshio::MeshIO::_buildMesh(const double_array& coordinates,
const int numVertices,
const int spaceDim,
- const int* cells,
+ const int_array& cells,
const int numCells,
const int numCorners,
const int meshDim)
{ // _buildMesh
assert(0 != _mesh);
+ assert(coordinates.size() == numVertices*spaceDim);
+ assert(cells.size() == numCells*numCorners);
*_mesh = new Mesh(PETSC_COMM_WORLD, meshDim);
_mesh->addRef();
@@ -91,116 +97,97 @@
ALE::SieveBuilder<Mesh>::buildTopology(sieve, meshDim,
numCells,
- const_cast<int*>(cells),
+ const_cast<int*>(&cells[0]),
numVertices,
_interpolate, numCorners);
(*_mesh)->setSieve(sieve);
(*_mesh)->stratify();
- ALE::SieveBuilder<Mesh>::buildCoordinates(*_mesh, spaceDim, coordinates);
+ ALE::SieveBuilder<Mesh>::buildCoordinates(*_mesh, spaceDim, &coordinates[0]);
} // _buildMesh
// ----------------------------------------------------------------------
// Get coordinates of vertices in mesh.
void
-pylith::meshio::MeshIO::_getVertices(double** pCoordinates,
- int* pNumVertices,
- int* pSpaceDim) const
+pylith::meshio::MeshIO::_getVertices(double_array* coordinates,
+ int* numVertices,
+ int* spaceDim) const
{ // _getVertices
+ assert(0 != coordinates);
+ assert(0 != numVertices);
+ assert(0 != spaceDim);
assert(0 != _mesh);
assert(!_mesh->isNull());
const ALE::Obj<Mesh::label_sequence>& vertices = (*_mesh)->depthStratum(0);
assert(!vertices.isNull());
- const ALE::Obj<Mesh::real_section_type>& coordsField =
+ const ALE::Obj<real_section_type>& coordsField =
(*_mesh)->getRealSection("coordinates");
assert(!coordsField.isNull());
- const int numVertices = vertices->size();
- const int spaceDim =
- coordsField->getFiberDimension(*vertices->begin());
+ *numVertices = vertices->size();
+ *spaceDim = coordsField->getFiberDimension(*vertices->begin());
- double* coordinates = 0;
- const int size = numVertices * spaceDim;
- if (0 != pCoordinates && size > 0) {
- coordinates = new double[size];
+ const int size = (*numVertices) * (*spaceDim);
+ coordinates->resize(size);
- int i = 0;
- for(Mesh::label_sequence::iterator v_iter = vertices->begin();
- v_iter != vertices->end();
- ++v_iter) {
- const Mesh::real_section_type::value_type *vertexCoords =
- coordsField->restrictPoint(*v_iter);
- for (int iDim=0; iDim < spaceDim; ++iDim)
- coordinates[i++] = vertexCoords[iDim];
- } // for
- } // if
-
- if (0 != pCoordinates)
- *pCoordinates = coordinates;
- if (0 != pNumVertices)
- *pNumVertices = numVertices;
- if (0 != pSpaceDim)
- *pSpaceDim = spaceDim;
+ int i = 0;
+ for(Mesh::label_sequence::iterator v_iter = vertices->begin();
+ v_iter != vertices->end();
+ ++v_iter) {
+ const real_section_type::value_type *vertexCoords =
+ coordsField->restrictPoint(*v_iter);
+ for (int iDim=0; iDim < *spaceDim; ++iDim)
+ (*coordinates)[i++] = vertexCoords[iDim];
+ } // for
} // _getVertices
// ----------------------------------------------------------------------
// Get cells in mesh.
void
-pylith::meshio::MeshIO::_getCells(int** pCells,
- int* pNumCells,
- int* pNumCorners,
- int* pMeshDim) const
+pylith::meshio::MeshIO::_getCells(int_array* cells,
+ int* numCells,
+ int* numCorners,
+ int* meshDim) const
{ // _getCells
+ assert(0 != cells);
+ assert(0 != numCells);
+ assert(0 != meshDim);
assert(0 != _mesh);
assert(!_mesh->isNull());
const ALE::Obj<sieve_type>& sieve = (*_mesh)->getSieve();
assert(!sieve.isNull());
- const ALE::Obj<Mesh::label_sequence>& cells = (*_mesh)->heightStratum(0);
- assert(!cells.isNull());
+ const ALE::Obj<Mesh::label_sequence>& meshCells = (*_mesh)->heightStratum(0);
+ assert(!meshCells.isNull());
- const int meshDim = (*_mesh)->getDimension();
- const int numCells = cells->size();
- const int numCorners = sieve->nCone(*cells->begin(),
- (*_mesh)->depth())->size();
-
+ *meshDim = (*_mesh)->getDimension();
+ *numCells = meshCells->size();
+ *numCorners = sieve->nCone(*meshCells->begin(), (*_mesh)->depth())->size();
+
const ALE::Obj<Mesh::numbering_type>& vNumbering =
(*_mesh)->getFactory()->getLocalNumbering(*_mesh, 0);
- int* cellsArray = 0;
- const int size = numCells * numCorners;
- if (0 != pCells && size > 0) {
- cellsArray = new int[size];
+ const int size = (*numCells) * (*numCorners);
+ cells->resize(size);
- const int offset = (useIndexZero()) ? 0 : 1;
- int i = 0;
- for(Mesh::label_sequence::iterator e_iter = cells->begin();
- e_iter != cells->end();
- ++e_iter) {
- const ALE::Obj<sieve_type::traits::coneSequence>& cone =
- sieve->cone(*e_iter);
- for(sieve_type::traits::coneSequence::iterator c_iter = cone->begin();
- c_iter != cone->end();
- ++c_iter)
- cellsArray[i++] = vNumbering->getIndex(*c_iter) + offset;
- } // for
- } // if
-
- if (0 != pCells)
- *pCells = cellsArray;
- if (0 != pNumCells)
- *pNumCells = numCells;
- if (0 != pNumCorners)
- *pNumCorners = numCorners;
- if (0 != pMeshDim)
- *pMeshDim = meshDim;
+ const int offset = (useIndexZero()) ? 0 : 1;
+ int i = 0;
+ for(Mesh::label_sequence::iterator e_iter = meshCells->begin();
+ e_iter != meshCells->end();
+ ++e_iter) {
+ const ALE::Obj<sieve_type::traits::coneSequence>& cone =
+ sieve->cone(*e_iter);
+ for(sieve_type::traits::coneSequence::iterator c_iter = cone->begin();
+ c_iter != cone->end();
+ ++c_iter)
+ (*cells)[i++] = vNumbering->getIndex(*c_iter) + offset;
+ } // for
} // _getCells
// ----------------------------------------------------------------------
// Tag cells in mesh with material identifiers.
void
-pylith::meshio::MeshIO::_setMaterials(const int* materialIds,
- const int numCells)
+pylith::meshio::MeshIO::_setMaterials(const int_array& materialIds)
{ // _setMaterials
assert(0 != _mesh);
assert(!_mesh->isNull());
@@ -208,6 +195,7 @@
const ALE::Obj<Mesh::label_sequence>& cells = (*_mesh)->heightStratum(0);
assert(!cells.isNull());
+ const int numCells = materialIds.size();
if (cells->size() != numCells) {
std::ostringstream msg;
msg << "Mismatch in size of materials identifier array ("
@@ -216,7 +204,8 @@
throw std::runtime_error(msg.str());
} // if
- const ALE::Obj<label_type>& labelMaterials = (*_mesh)->createLabel("material-id");
+ const ALE::Obj<Mesh::label_type>& labelMaterials =
+ (*_mesh)->createLabel("material-id");
int i = 0;
for(Mesh::label_sequence::iterator e_iter = cells->begin();
@@ -228,9 +217,9 @@
// ----------------------------------------------------------------------
// Get material identifiers for cells.
void
-pylith::meshio::MeshIO::_getMaterials(int** pMaterialIds,
- int* pNumCells) const
+pylith::meshio::MeshIO::_getMaterials(int_array* materialIds) const
{ // _getMaterials
+ assert(0 != materialIds);
assert(0 != _mesh);
assert(!_mesh->isNull());
@@ -238,104 +227,103 @@
assert(!cells.isNull());
const int numCells = cells->size();
- int* materialsArray = 0;
const int size = numCells;
- if (0 != pMaterialIds && size > 0) {
- materialsArray = new int[size];
+ materialIds->resize(size);
- const ALE::Obj<label_type>& labelMaterials =
- (*_mesh)->getLabel("material-id");
- const int idDefault = 0;
+ const ALE::Obj<Mesh::label_type>& labelMaterials =
+ (*_mesh)->getLabel("material-id");
+ const int idDefault = 0;
- int i = 0;
- for(Mesh::label_sequence::iterator e_iter = cells->begin();
- e_iter != cells->end();
- ++e_iter)
- materialsArray[i++] =
- (*_mesh)->getValue(labelMaterials, *e_iter, idDefault);
- } // if
-
- if (0 != pMaterialIds)
- *pMaterialIds = materialsArray;
- if (0 != pNumCells)
- *pNumCells = numCells;
+ int i = 0;
+ for(Mesh::label_sequence::iterator e_iter = cells->begin();
+ e_iter != cells->end();
+ ++e_iter)
+ (*materialIds)[i++] =
+ (*_mesh)->getValue(labelMaterials, *e_iter, idDefault);
} // _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
+pylith::meshio::MeshIO::_setGroup(const std::string& name,
+ const GroupPtType type,
+ const int_array& points)
+{ // _setGroup
assert(0 != _mesh);
assert(!_mesh->isNull());
- const ALE::Obj<Mesh::int_section_type>& groupField =
- (*_mesh)->getIntSection(name);
+ const ALE::Obj<int_section_type>& groupField = (*_mesh)->getIntSection(name);
assert(!groupField.isNull());
- if (CELL == type) {
- for(int i = 0; i < numPoints; ++i) {
+ const int numPoints = points.size();
+ if (CELL == type)
+ for(int i=0; i < numPoints; ++i)
groupField->setFiberDimension(points[i], 1);
- }
- } else if (VERTEX == type) {
+ else if (VERTEX == type) {
const int numCells = (*_mesh)->heightStratum(0)->size();
- for(int i = 0; i < numPoints; ++i) {
+ for(int i=0; i < numPoints; ++i)
groupField->setFiberDimension(points[i]+numCells, 1);
- }
- } // if
+ } // if/else
(*_mesh)->allocate(groupField);
-} // _buildMesh
+} // _setGroup
// ----------------------------------------------------------------------
-// Get group names
-ALE::Obj<std::set<std::string> >
-pylith::meshio::MeshIO::_getGroups() const
-{
- return (*_mesh)->getIntSections();
-}
+// Get names of all groups in mesh.
+void
+pylith::meshio::MeshIO::_getGroupNames(string_vector* names) const
+{ // _getGroups
+ assert(0 != names);
+ assert(0 != _mesh);
+ assert(!_mesh->isNull());
+
+ const ALE::Obj<std::set<std::string> >& sectionNames =
+ (*_mesh)->getIntSections();
+
+ const int numGroups = sectionNames->size();
+ names->resize(numGroups);
+ int i=0;
+ for (std::set<std::string>::const_iterator name=sectionNames->begin();
+ name != sectionNames->end();
+ ++name)
+ (*names)[i++] = *name;
+} // _getGroups
// ----------------------------------------------------------------------
// Get group entities
void
-pylith::meshio::MeshIO::_getGroup(const char *name,
- PointType& type,
- int& numPoints,
- int *points[]) const
+pylith::meshio::MeshIO::_getGroup(int_array* points,
+ GroupPtType* type,
+ const char *name) const
{ // _getMaterials
+ assert(0 != points);
+ assert(0 != type);
assert(0 != _mesh);
assert(!_mesh->isNull());
- assert(0 != points);
- const ALE::Obj<Mesh::int_section_type>& groupField =
- (*_mesh)->getIntSection(name);
+ const ALE::Obj<int_section_type>& groupField = (*_mesh)->getIntSection(name);
assert(!groupField.isNull());
- const Mesh::int_section_type::chart_type& chart =
- groupField->getChart();
+ const 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;
+ *type = CELL;
numbering = (*_mesh)->getFactory()->getNumbering(*_mesh,
(*_mesh)->depth());
} else {
- type = VERTEX;
+ *type = VERTEX;
numbering = (*_mesh)->getFactory()->getNumbering(*_mesh, 0);
} // if/else
- numPoints = chart.size();
- int *indices = new int[numPoints];
+ const int numPoints = chart.size();
+ points->resize(numPoints);
int i = 0;
- for(Mesh::int_section_type::chart_type::iterator c_iter = chart.begin();
+ for(int_section_type::chart_type::iterator c_iter = chart.begin();
c_iter != chart.end();
++c_iter) {
assert(!numbering.isNull());
- indices[i++] = numbering->getIndex(*c_iter);
- }
- *points = indices;
+ (*points)[i++] = numbering->getIndex(*c_iter);
+ } // for
} // _getMaterials
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIO.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIO.hh 2007-04-12 21:11:36 UTC (rev 6559)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIO.hh 2007-04-13 01:19:44 UTC (rev 6560)
@@ -13,8 +13,11 @@
#if !defined(pylith_meshio_meshio_hh)
#define pylith_meshio_meshio_hh
-#include <Mesh.hh> // PETSc Mesh
+#include "pylith/utils/arrayfwd.hh" // USES double_array, int_array,
+ // string_vector
+#include "pylith/utils/sievefwd.hh" // USES ALE::Obj, ALE::Mesh
+
namespace pylith {
namespace meshio {
class MeshIO;
@@ -23,16 +26,15 @@
class pylith::meshio::MeshIO
{ // MeshIO
+
// PUBLIC TYPEDEFS //////////////////////////////////////////////////////
public :
- typedef ALE::Mesh Mesh;
- typedef Mesh::sieve_type sieve_type;
- typedef Mesh::label_type label_type;
-
+
+ /// Type of points in a group.
+ typedef enum { VERTEX, CELL } GroupPtType;
+
// PUBLIC MEMBERS ///////////////////////////////////////////////////////
public :
- typedef enum {VERTEX, CELL} PointType;
-
/// Constructor
MeshIO(void);
@@ -69,13 +71,13 @@
*
* @param mesh Pointer to PETSc mesh object
*/
- void read(ALE::Obj<Mesh>* mesh);
+ void read(ALE::Obj<ALE::Mesh>* mesh);
/** Write mesh to file.
*
* @param mesh Pointer to PETSc mesh object
*/
- void write(ALE::Obj<Mesh>* mesh);
+ void write(ALE::Obj<ALE::Mesh>* mesh);
// PROTECTED MEMBERS ////////////////////////////////////////////////////
protected :
@@ -116,10 +118,10 @@
* @param numCorners Number of vertices per cell
* @param meshDim Dimension of cells in mesh
*/
- void _buildMesh(const double* coordinates,
+ void _buildMesh(const double_array& coordinates,
const int numVertices,
const int spaceDim,
- const int* cells,
+ const int_array& cells,
const int numCells,
const int numCorners,
const int meshDim);
@@ -128,72 +130,65 @@
*
* Method caller is responsible for memory management.
*
- * @param pCoordinates Pointer to array of vertex coordinates
- * @param pNumVertices Pointer to number of vertices
- * @param pSpaceDim Poiner to dimension of vector space for coordinates
+ * @param coordinates Pointer to array of vertex coordinates
+ * @param numVertices Pointer to number of vertices
+ * @param spaceDim Poiner to dimension of vector space for coordinates
*/
- void _getVertices(double** pCoordinates,
- int* pNumVertices,
- int* pSpaceDim) const;
+ void _getVertices(double_array* coordinates,
+ int* numVertices,
+ int* spaceDim) const;
/** Get information about cells in mesh.
*
* Method caller is responsible for memory management.
*
- * @param pCells Pointer to array of indicates of vertices in each cell
- * @param pNumCells Pointer to number of cells in mesh
- * @param pNumCorners Pointer to number of vertices in each cell
- * @param pMeshDim Pointer to number of dimensions associated with cell
+ * @param cells Pointer to array of indicates of vertices in each cell
+ * @param numCells Pointer to number of cells in mesh
+ * @param numCorners Pointer to number of vertices in each cell
+ * @param meshDim Pointer to number of dimensions associated with cell
*/
- void _getCells(int** pCells,
- int* pNumCells,
- int* pNumCorners,
- int* pMeshDim) const;
+ void _getCells(int_array* cells,
+ int* numCells,
+ int* numCorners,
+ int* meshDim) 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);
+ void _setMaterials(const int_array& materialIds);
/** Get material identifiers for cells.
*
* @param materialIds Material identifiers [numCells]
- * @param numCells Number of cells
*/
- void _getMaterials(int** pMaterialIds,
- int* pNumCells) const;
+ void _getMaterials(int_array* pMaterialIds) 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
+ * @param points An array of the points in the group.
*/
- void _buildGroup(const std::string& name,
- const PointType type,
- const int numPoints,
- const int* points);
+ void _setGroup(const std::string& name,
+ const GroupPtType type,
+ const int_array& points);
- /** Return all group names
+ /** Get names of all groups in mesh.
*
+ * @returns Array of group names.
*/
- ALE::Obj<std::set<std::string> > _getGroups() const;
+ void _getGroupNames(string_vector* names) const;
/** Return a point group
*
- * @param name The group name
+ * @param points An array of the points in the group
* @param type The point type, e.g. VERTEX, CELL
- * @param numPoints The number of points
- * @param points An array of the points
+ * @param name The group name
*/
- void _getGroup(const char *name,
- PointType& type,
- int& numPoints,
- int *points[]) const;
+ void _getGroup(int_array* points,
+ GroupPtType* type,
+ const char *name) const;
// PRIVATE MEMBERS //////////////////////////////////////////////////////
private :
@@ -202,7 +197,7 @@
bool _debug; ///< True to turn of mesh debugging output
bool _interpolate; ///< True if building intermediate topology elements
- ALE::Obj<Mesh>* _mesh; ///< Pointer to PETSc mesh object
+ ALE::Obj<ALE::Mesh>* _mesh; ///< Pointer to PETSc mesh object
}; // MeshIO
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc 2007-04-12 21:11:36 UTC (rev 6559)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.cc 2007-04-13 01:19:44 UTC (rev 6560)
@@ -14,12 +14,16 @@
#include "MeshIOAscii.hh" // implementation of class methods
+#include "pylith/utils/array.hh" // USES double_array, int_array, string_vector
+#include "pylith/utils/sievetypes.hh" // USES PETSc mesh
+
#include <fstream> // USES std::ifstream, std::ofstream
#include <stdexcept> // USES std::runtime_error
#include <sstream> // USES std::ostringstream
#include <assert.h> // USES assert()
#include <iomanip> // USES setw(), setiosflags(), resetiosflags()
+// ----------------------------------------------------------------------
const char* pylith::meshio::MeshIOAscii::groupTypeNames[] =
{"vertices", "cells"};
@@ -46,9 +50,9 @@
int numVertices = 0;
int numCells = 0;
int numCorners = 0;
- double* coordinates = 0;
- int* cells = 0;
- int* materialIds = 0;
+ double_array coordinates;
+ int_array cells;
+ int_array materialIds;
std::ifstream filein(_filename.c_str());
if (!filein.is_open() || !filein.good()) {
@@ -97,17 +101,16 @@
readCells = true;
} else if (0 == strcasecmp(token.c_str(), "group")) {
std::string name;
- pylith::meshio::MeshIO::PointType type;
- int numPoints;
- int *points;
+ GroupPtType type;
+ int numPoints = 0;
+ int_array points;
if (!builtMesh)
throw std::runtime_error("Both 'vertices' and 'cells' must "
"precede any groups in mesh file.");
filein.ignore(maxIgnore, '{');
- _readGroup(filein, name, type, numPoints, &points);
- _buildGroup(name, type, numPoints, points);
- delete [] points;
+ _readGroup(filein, &points, &type, &name);
+ _setGroup(name, type, points);
} else {
std::ostringstream msg;
msg << "Could not parse '" << token << "' into a mesh setting.";
@@ -118,10 +121,7 @@
// Can now build mesh
_buildMesh(coordinates, numVertices, spaceDim,
cells, numCells, numCorners, meshDim);
- _setMaterials(materialIds, numCells);
- delete[] coordinates; coordinates = 0;
- delete[] cells; cells = 0;
- delete[] materialIds; materialIds = 0;
+ _setMaterials(materialIds);
builtMesh = true;
} // if
@@ -150,11 +150,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());
- }
+ string_vector groups;
+ _getGroupNames(&groups);
+ const int numGroups = groups.size();
+ for (int i=0; i < numGroups; ++i)
+ _writeGroup(fileout, groups[i].c_str());
fileout << "}\n";
fileout.close();
@@ -164,13 +165,13 @@
// Read mesh vertices.
void
pylith::meshio::MeshIOAscii::_readVertices(std::istream& filein,
- double** pCoordinates,
- int* pNumVertices,
- int* pNumDims) const
+ double_array* coordinates,
+ int* numVertices,
+ int* numDims) const
{ // _readVertices
- double* coordinates = 0;
- int numDims = 0;
- int numVertices = 0;
+ assert(0 != coordinates);
+ assert(0 != numVertices);
+ assert(0 != numDims);
std::string token;
const int maxIgnore = 1024;
@@ -178,12 +179,12 @@
while (filein.good() && token != "}") {
if (0 == strcasecmp(token.c_str(), "dimension")) {
filein.ignore(maxIgnore, '=');
- filein >> numDims;
+ filein >> *numDims;
} else if (0 == strcasecmp(token.c_str(), "count")) {
filein.ignore(maxIgnore, '=');
- filein >> numVertices;
+ filein >> *numVertices;
} else if (0 == strcasecmp(token.c_str(), "coordinates")) {
- const int size = numVertices*numDims;
+ const int size = (*numVertices) * (*numDims);
if (0 == size) {
const char* msg =
"Tokens 'dimension' and 'count' must precede 'coordinates'.";
@@ -191,13 +192,12 @@
} // if
filein.ignore(maxIgnore, '{');
- delete[] coordinates; coordinates = new double[size];
- assert(0 != coordinates);
+ coordinates->resize(size);
int label;
- for (int iVertex=0, i=0; iVertex < numVertices; ++iVertex) {
+ for (int iVertex=0, i=0; iVertex < *numVertices; ++iVertex) {
filein >> label;
- for (int iDim=0; iDim < numDims; ++iDim)
- filein >> coordinates[i++];
+ for (int iDim=0; iDim < *numDims; ++iDim)
+ filein >> (*coordinates)[i++];
} // for
filein.ignore(maxIgnore, '}');
} else {
@@ -209,13 +209,6 @@
} // while
if (!filein.good())
throw std::runtime_error("I/O error while parsing vertices settings.");
-
- if (0 != pCoordinates)
- *pCoordinates = coordinates;
- if (0 != pNumVertices)
- *pNumVertices = numVertices;
- if (0 != pNumDims)
- *pNumDims = numDims;
} // _readVertices
// ----------------------------------------------------------------------
@@ -225,7 +218,7 @@
{ // _writeVertices
int spaceDim = 0;
int numVertices = 0;
- double* coordinates = 0;
+ double_array coordinates;
_getVertices(&coordinates, &numVertices, &spaceDim);
fileout
@@ -246,23 +239,22 @@
fileout
<< " }\n"
<< " }\n";
-
- delete[] coordinates; coordinates = 0;
} // _writeVertices
// ----------------------------------------------------------------------
// Read mesh cells.
void
pylith::meshio::MeshIOAscii::_readCells(std::istream& filein,
- int** pCells,
- int** pMaterialIds,
- int* pNumCells,
- int* pNumCorners) const
+ int_array* cells,
+ int_array* materialIds,
+ int* numCells,
+ int* numCorners) const
{ // _readCells
- int* cells = 0;
- int* materialIds = 0;
- int numCells = 0;
- int numCorners = 0;
+ assert(0 != cells);
+ assert(0 != materialIds);
+ assert(0 != numCells);
+ assert(0 != numCorners);
+
int dimension = 0;
std::string token;
@@ -271,12 +263,12 @@
while (filein.good() && token != "}") {
if (0 == strcasecmp(token.c_str(), "num-corners")) {
filein.ignore(maxIgnore, '=');
- filein >> numCorners;
+ filein >> *numCorners;
} else if (0 == strcasecmp(token.c_str(), "count")) {
filein.ignore(maxIgnore, '=');
- filein >> numCells;
+ filein >> *numCells;
} else if (0 == strcasecmp(token.c_str(), "simplices")) {
- const int size = numCells*numCorners;
+ const int size = (*numCells) * (*numCorners);
if (0 == size) {
const char* msg =
"Tokens 'num-corners' and 'count' must precede 'cells'.";
@@ -284,36 +276,34 @@
} // if
filein.ignore(maxIgnore, '{');
- delete[] cells; cells = new int[size];
- assert(0 != cells);
+ cells->resize(size);
int label;
- for (int iCell=0, i=0; iCell < numCells; ++iCell) {
+ for (int iCell=0, i=0; iCell < *numCells; ++iCell) {
filein >> label;
- for (int iCorner=0; iCorner < numCorners; ++iCorner)
- filein >> cells[i++];
+ for (int iCorner=0; iCorner < *numCorners; ++iCorner)
+ filein >> (*cells)[i++];
} // for
if (!useIndexZero()) {
// if files begins with index 1, then decrement to index 0
// for compatibility with Sieve
for (int i=0; i < size; ++i)
- --cells[i];
+ --(*cells)[i];
} // if
filein.ignore(maxIgnore, '}');
} else if (0 == strcasecmp(token.c_str(), "material-ids")) {
- if (0 == numCells) {
+ if (0 == *numCells) {
const char* msg =
"Token 'count' must precede 'material-ids'.";
throw std::runtime_error(msg);
} // if
- const int size = numCells;
+ const int size = *numCells;
filein.ignore(maxIgnore, '{');
- delete[] materialIds; materialIds = new int[size];
- assert(0 != materialIds);
+ materialIds->resize(size);
int label = 0;
- for (int iCell=0; iCell < numCells; ++iCell) {
+ for (int iCell=0; iCell < *numCells; ++iCell) {
filein >> label;
- filein >> materialIds[iCell];
+ filein >> (*materialIds)[iCell];
} // for
filein.ignore(maxIgnore, '}');
} else {
@@ -327,21 +317,11 @@
throw std::runtime_error("I/O error while parsing cells settings.");
// If no materials given, assign each cell material identifier of 0
- if (0 == materialIds && numCells > 0) {
- const int size = numCells;
- materialIds = new int[size];
- for (int i=0; i < size; ++i)
- materialIds[i] = 0;
+ if (0 == materialIds->size() && *numCells > 0) {
+ const int size = *numCells;
+ materialIds->resize(size);
+ (*materialIds) = 0;
} // if
-
- if (0 != pCells)
- *pCells = cells;
- if (0 != pNumCells)
- *pNumCells = numCells;
- if (0 != pNumCorners)
- *pNumCorners = numCorners;
- if (0 != pMaterialIds)
- *pMaterialIds = materialIds;
} // _readCells
// ----------------------------------------------------------------------
@@ -352,7 +332,7 @@
int meshDim = 0;
int numCells = 0;
int numCorners = 0;
- int* cells = 0;
+ int_array cells;
_getCells(&cells, &numCells, &numCorners, &meshDim);
fileout
@@ -367,45 +347,37 @@
fileout << std::setw(8) << cells[i++];
fileout << "\n";
} // for
- fileout
- << " }\n";
- delete[] cells; cells = 0;
+ fileout << " }\n";
// Write material identifiers
- int* materialIds = 0;
- _getMaterials(&materialIds, &numCells);
- assert( (0 != materialIds && 0 < numCells) ||
- (0 == materialIds && 0 == numCells) );
- fileout
- << " material-ids = {\n";
+ int_array materialIds;
+ _getMaterials(&materialIds);
+ assert(numCells == materialIds.size());
+ fileout << " material-ids = {\n";
for(int iCell=0, i=0; iCell < numCells; ++iCell) {
fileout << " " << std::setw(8) << iCell;
fileout << std::setw(4) << materialIds[iCell] << "\n";
} // for
- fileout
- << " }\n";
- delete[] materialIds; materialIds = 0;
+ fileout << " }\n";
- fileout
- << " }\n";
+ fileout << " }\n";
} // _writeCells
// ----------------------------------------------------------------------
// Read mesh group.
void
pylith::meshio::MeshIOAscii::_readGroup(std::istream& filein,
- std::string& name,
- pylith::meshio::MeshIO::PointType& type,
- int& numPoints,
- int *points[]) const
+ int_array* points,
+ GroupPtType* type,
+ std::string* name) const
{ // _readGroup
assert(0 != points);
+ assert(0 != type);
+ assert(0 != name);
- int* indices = 0; // Indices of entities in group
-
std::string token;
const int maxIgnore = 1024;
- numPoints = -1;
+ int numPoints = -1;
filein >> token;
while (filein.good() && token != "}") {
if (0 == strcasecmp(token.c_str(), "name")) {
@@ -413,20 +385,20 @@
filein >> std::ws;
char buffer[maxIgnore];
filein.get(buffer, maxIgnore, '\n');
- name = buffer;
+ *name = buffer;
} else if (0 == strcasecmp(token.c_str(), "type")) {
std::string typeName;
filein.ignore(maxIgnore, '=');
filein >> typeName;
- if (typeName == groupTypeNames[VERTEX]) {
- type = VERTEX;
- } else if (typeName == groupTypeNames[CELL]) {
- type = CELL;
- } else {
+ 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
} else if (0 == strcasecmp(token.c_str(), "count")) {
filein.ignore(maxIgnore, '=');
filein >> numPoints;
@@ -436,11 +408,10 @@
msg << "Tokens 'count' must precede 'indices'.";
throw std::runtime_error(msg.str());
} // if
-
filein.ignore(maxIgnore, '{');
- delete[] indices; indices = (numPoints > 0) ? new int[numPoints] : 0;
+ points->resize(numPoints);
for (int i=0; i < numPoints; ++i)
- filein >> indices[i];
+ filein >> (*points)[i];
filein.ignore(maxIgnore, '}');
} else {
std::ostringstream msg;
@@ -451,7 +422,6 @@
} // while
if (!filein.good())
throw std::runtime_error("I/O error while parsing group settings.");
- *points = indices;
} // _readGroup
// ----------------------------------------------------------------------
@@ -460,20 +430,20 @@
pylith::meshio::MeshIOAscii::_writeGroup(std::ostream& fileout,
const char* name) const
{ // _writeGroup
- pylith::meshio::MeshIO::PointType type;
- int numPoints;
- int *points;
+ int_array points;
+ GroupPtType type;
+ _getGroup(&points, &type, name);
- _getGroup(name, type, numPoints, &points);
+ const int numPoints = points.size();
fileout
<< " group = {\n"
<< " name = " << name << "\n"
<< " type = " << groupTypeNames[type] << "\n"
<< " count = " << numPoints << "\n"
<< " indices = {\n";
- for(int i = 0; i < numPoints; ++i) {
+ for(int i=0; i < numPoints; ++i)
fileout << " " << points[i] << "\n";
- }
+
fileout
<< " }\n"
<< " }\n";
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.hh 2007-04-12 21:11:36 UTC (rev 6559)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIOAscii.hh 2007-04-13 01:19:44 UTC (rev 6560)
@@ -63,14 +63,14 @@
/** Read mesh vertices.
*
* @param filein Input stream
- * @param pCoordinates Pointer to array of vertex coordinates
- * @param pNumVertices Pointer to number of vertices
- * @param pSpaceDim Pointer to dimension of coordinates vector space
+ * @param coordinates Pointer to array of vertex coordinates
+ * @param numVertices Pointer to number of vertices
+ * @param spaceDim Pointer to dimension of coordinates vector space
*/
void _readVertices(std::istream& filein,
- double** pCoordinates,
- int* pNumVertices,
- int* pSpaceDim) const;
+ double_array* coordinates,
+ int* numVertices,
+ int* spaceDim) const;
/** Write mesh vertices.
*
@@ -87,10 +87,10 @@
* @param pNumCorners Pointer to number of corners
*/
void _readCells(std::istream& filein,
- int** pCells,
- int** pMaterialIds,
- int* pNumCells,
- int* pNumCorners) const;
+ int_array* pCells,
+ int_array* pMaterialIds,
+ int* numCells,
+ int* numCorners) const;
/** Write mesh cells.
*
@@ -107,18 +107,17 @@
* @param mesh The mesh
*/
void _readGroup(std::istream& filein,
- std::string& name,
- pylith::meshio::MeshIO::PointType& type,
- int& numPoints, int *points[]) const;
+ int_array* points,
+ GroupPtType* type,
+ std::string* name) 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;
+ const char* name) const;
// PRIVATE MEMBERS ----------------------------------------------------
private :
Modified: short/3D/PyLith/trunk/libsrc/utils/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/utils/Makefile.am 2007-04-12 21:11:36 UTC (rev 6559)
+++ short/3D/PyLith/trunk/libsrc/utils/Makefile.am 2007-04-13 01:19:44 UTC (rev 6560)
@@ -16,7 +16,9 @@
subpkginclude_HEADERS = \
array.hh \
arrayfwd.hh \
- petscfwd.h
+ petscfwd.h \
+ sievefwd.hh \
+ sievetypes.hh
noinst_HEADERS =
Modified: short/3D/PyLith/trunk/libsrc/utils/arrayfwd.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/utils/arrayfwd.hh 2007-04-12 21:11:36 UTC (rev 6559)
+++ short/3D/PyLith/trunk/libsrc/utils/arrayfwd.hh 2007-04-13 01:19:44 UTC (rev 6560)
@@ -25,6 +25,8 @@
#if !defined(pylith_utils_arrayfwd_hh)
#define pylith_utils_arrayfwd_hh
+#include <string> // USES std::string
+
/// Forward declaration of STL vector
namespace std {
// std::vector
@@ -43,6 +45,9 @@
/// Alias for std::vector<double>
typedef std::vector<double, std::allocator<double> > double_vector;
+ /// Alias for std::vector<std::string>
+ typedef std::vector<std::string, std::allocator<std::string> > string_vector;
+
/// Alias for std::valarray<int>
typedef std::valarray<int> int_array;
Added: short/3D/PyLith/trunk/libsrc/utils/sievefwd.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/utils/sievefwd.hh 2007-04-12 21:11:36 UTC (rev 6559)
+++ short/3D/PyLith/trunk/libsrc/utils/sievefwd.hh 2007-04-13 01:19:44 UTC (rev 6560)
@@ -0,0 +1,34 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file pylith/utils/sievefwd.hh
+ *
+ * @brief Forward declarations for PETSc Sieve objects.
+ */
+
+#if !defined(pylith_utils_sievefwd_hh)
+#define pylith_utils_sievefwd_hh
+
+namespace ALE {
+
+ /// ALE::Obj
+ template<class T> class Obj;
+
+ /// PETSc mesh
+ class Mesh;
+} // ALE
+
+#endif // pylith_utils_sievefwd_hh
+
+
+// End of file
Added: short/3D/PyLith/trunk/libsrc/utils/sievetypes.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/utils/sievetypes.hh 2007-04-12 21:11:36 UTC (rev 6559)
+++ short/3D/PyLith/trunk/libsrc/utils/sievetypes.hh 2007-04-13 01:19:44 UTC (rev 6560)
@@ -0,0 +1,35 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file pylith/utils/sievetypes.hh
+ *
+ * @brief Aliases for Sieve types.
+ */
+
+#if !defined(pylith_utils_sievetypes_hh)
+#define pylith_utils_sievefwd_hh
+
+#include <petscmesh.h> // PETSc Mesh
+
+namespace pylith {
+
+ typedef ALE::Mesh Mesh;
+ typedef Mesh::sieve_type sieve_type;
+ typedef Mesh::real_section_type real_section_type;
+ typedef Mesh::int_section_type int_section_type;
+} // pylith
+
+#endif // pylith_utils_sievetypes_hh
+
+
+// End of file
More information about the cig-commits
mailing list