[cig-commits] r21831 - in short/3D/PyLith/trunk: libsrc/pylith/meshio unittests/libtests/meshio
brad at geodynamics.org
brad at geodynamics.org
Thu Apr 11 17:49:21 PDT 2013
Author: brad
Date: 2013-04-11 17:49:20 -0700 (Thu, 11 Apr 2013)
New Revision: 21831
Modified:
short/3D/PyLith/trunk/libsrc/pylith/meshio/CellFilterAvg.cc
short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputSolnPoints.cc
short/3D/PyLith/trunk/libsrc/pylith/meshio/VertexFilterVecNorm.cc
short/3D/PyLith/trunk/unittests/libtests/meshio/TestVertexFilterVecNorm.cc
Log:
Code cleanup.
Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/CellFilterAvg.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/CellFilterAvg.cc 2013-04-12 00:48:43 UTC (rev 21830)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/CellFilterAvg.cc 2013-04-12 00:49:20 UTC (rev 21831)
@@ -94,10 +94,6 @@
{ // filter
PYLITH_METHOD_BEGIN;
- typedef typename mesh_type::SieveMesh SieveMesh;
- typedef typename SieveMesh::label_sequence label_sequence;
- typedef typename field_type::Mesh::RealSection RealSection;
-
const feassemble::Quadrature<mesh_type>* quadrature = CellFilter<mesh_type, field_type>::_quadrature;assert(quadrature);
const int numQuadPts = quadrature->numQuadPts();
Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputSolnPoints.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputSolnPoints.cc 2013-04-12 00:48:43 UTC (rev 21830)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/OutputSolnPoints.cc 2013-04-12 00:49:20 UTC (rev 21831)
@@ -28,10 +28,6 @@
#include "spatialdata/geocoords/CoordSys.hh" // USES CoordSys
// ----------------------------------------------------------------------
-typedef pylith::topology::Mesh::SieveMesh SieveMesh;
-typedef pylith::topology::Mesh::RealSection RealSection;
-
-// ----------------------------------------------------------------------
// Constructor
pylith::meshio::OutputSolnPoints::OutputSolnPoints(void) :
_mesh(0),
Modified: short/3D/PyLith/trunk/libsrc/pylith/meshio/VertexFilterVecNorm.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/meshio/VertexFilterVecNorm.cc 2013-04-12 00:48:43 UTC (rev 21830)
+++ short/3D/PyLith/trunk/libsrc/pylith/meshio/VertexFilterVecNorm.cc 2013-04-12 00:49:20 UTC (rev 21831)
@@ -19,6 +19,8 @@
#include <portinfo>
#include "pylith/topology/Field.hh" // USES Field
+#include "pylith/topology/Stratum.hh" // USES Stratum
+#include "pylith/topology/VisitorMesh.hh" // USES VecVisitorMesh
// ----------------------------------------------------------------------
// Constructor
@@ -42,9 +44,13 @@
void
pylith::meshio::VertexFilterVecNorm<field_type>::deallocate(void)
{ // deallocate
+ PYLITH_METHOD_BEGIN;
+
VertexFilter<field_type>::deallocate();
delete _fieldVecNorm; _fieldVecNorm = 0;
+
+ PYLITH_METHOD_END;
} // deallocate
// ----------------------------------------------------------------------
@@ -69,29 +75,23 @@
// Filter field.
template<typename field_type>
field_type&
-pylith::meshio::VertexFilterVecNorm<field_type>::filter(
- const field_type& fieldIn)
+pylith::meshio::VertexFilterVecNorm<field_type>::filter(const field_type& fieldIn)
{ // filter
- typedef typename field_type::Mesh::RealSection RealSection;
- typedef typename field_type::Mesh::SieveMesh SieveMesh;
- typedef typename SieveMesh::label_sequence label_sequence;
+ PYLITH_METHOD_BEGIN;
- DM dmMesh = fieldIn.mesh().dmMesh();
- PetscInt vStart, vEnd;
- PetscErrorCode err;
+ PetscDM dmMesh = fieldIn.mesh().dmMesh();assert(dmMesh);
+ topology::Stratum verticesStratum(dmMesh, topology::Stratum::DEPTH, 0);
+ const PetscInt vStart = verticesStratum.begin();
+ const PetscInt vEnd = verticesStratum.end();
- assert(dmMesh);
- err = DMPlexGetDepthStratum(dmMesh, 0, &vStart, &vEnd);CHECK_PETSC_ERROR(err);
+ topology::VecVisitorMesh fieldInVisitor(fieldIn);
- PetscSection sectionIn = fieldIn.petscSection();
- Vec vecIn = fieldIn.localVector();
- PetscScalar *a, *an;
- PetscInt fiberDimIn, fiberDimNorm = 1;
- assert(sectionIn);assert(vecIn);
- err = PetscSectionGetDof(sectionIn, vStart, &fiberDimIn);CHECK_PETSC_ERROR(err);
+ // Only processors with cells for output get the correct fiber dimension.
+ PetscInt fiberDimIn = (verticesStratum.size() > 0) ? fieldInVisitor.sectionDof(vStart) : 0;
+ const int fiberDimNorm = 1;
- // Allocation field if necessary
- if (0 == _fieldVecNorm) {
+ // Allocate field if necessary
+ if (!_fieldVecNorm) {
_fieldVecNorm = new field_type(fieldIn.mesh());
_fieldVecNorm->label("vector norm");
_fieldVecNorm->newSection(fieldIn, fiberDimNorm);
@@ -119,30 +119,27 @@
} // switch
} // if
- PetscSection sectionNorm = _fieldVecNorm->petscSection();
- Vec vecNorm = _fieldVecNorm->localVector();
- assert(sectionNorm);assert(vecNorm);
+ const PetscScalar* fieldInArray = fieldInVisitor.localArray();
+ topology::VecVisitorMesh fieldNormVisitor(*_fieldVecNorm);
+ PetscScalar* fieldNormArray = fieldNormVisitor.localArray();
+
// Loop over vertices
- err = VecGetArray(vecIn, &a);CHECK_PETSC_ERROR(err);
- err = VecGetArray(vecNorm, &an);CHECK_PETSC_ERROR(err);
for(PetscInt v = vStart; v < vEnd; ++v) {
- PetscInt dof, off, offn;
- PylithScalar norm = 0.0;
+ const PetscInt ioff = fieldInVisitor.sectionOffset(v);
+ assert(fiberDimIn == fieldInVisitor.sectionDof(v));
- err = PetscSectionGetDof(sectionIn, v, &dof);CHECK_PETSC_ERROR(err);
- err = PetscSectionGetOffset(sectionIn, v, &off);CHECK_PETSC_ERROR(err);
- err = PetscSectionGetOffset(sectionNorm, v, &offn);CHECK_PETSC_ERROR(err);
- for(PetscInt d = 0; d < dof; ++d)
- norm += a[off+d]*a[off+d];
- norm = sqrt(norm);
- an[offn] = norm;
+ const PetscInt noff = fieldNormVisitor.sectionOffset(v);
+
+ PylithScalar norm = 0.0;
+ for(PetscInt d = 0; d < fiberDimIn; ++d) {
+ norm += fieldInArray[ioff+d]*fieldInArray[ioff+d];
+ } // for
+ fieldNormArray[noff] = sqrt(norm);
} // for
- err = VecRestoreArray(vecIn, &a);CHECK_PETSC_ERROR(err);
- err = VecRestoreArray(vecNorm, &an);CHECK_PETSC_ERROR(err);
PetscLogFlops((vEnd-vStart) * (1 + 2*fiberDimIn));
- return *_fieldVecNorm;
+ PYLITH_METHOD_RETURN(*_fieldVecNorm);
} // filter
Modified: short/3D/PyLith/trunk/unittests/libtests/meshio/TestVertexFilterVecNorm.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/meshio/TestVertexFilterVecNorm.cc 2013-04-12 00:48:43 UTC (rev 21830)
+++ short/3D/PyLith/trunk/unittests/libtests/meshio/TestVertexFilterVecNorm.cc 2013-04-12 00:49:20 UTC (rev 21831)
@@ -37,7 +37,11 @@
void
pylith::meshio::TestVertexFilterVecNorm::testConstructor(void)
{ // testConstructor
+ PYLITH_METHOD_BEGIN;
+
VertexFilterVecNorm<MeshField> filter;
+
+ PYLITH_METHOD_END;
} // testConstructor
// ----------------------------------------------------------------------
@@ -45,8 +49,7 @@
void
pylith::meshio::TestVertexFilterVecNorm::testFilter(void)
{ // testFilter
- typedef pylith::topology::Mesh::SieveMesh SieveMesh;
- typedef pylith::topology::Mesh::RealSection RealSection;
+ PYLITH_METHOD_BEGIN;
const char* filename = "data/tri3.mesh";
const int fiberDim = 2;
@@ -54,7 +57,7 @@
const std::string label = "field data";
const topology::FieldBase::VectorFieldEnum fieldType =
topology::FieldBase::VECTOR;
- const PylithScalar fieldValues[] = {
+ const PylithScalar fieldValues[nvertices*fiberDim] = {
1.1, 1.2,
2.1, 2.2,
3.1, 3.2,
@@ -75,59 +78,50 @@
iohandler.filename(filename);
iohandler.read(&mesh);
- // Set vertex field
+ PetscDM dmMesh = mesh.dmMesh();CPPUNIT_ASSERT(dmMesh);
+ topology::Stratum verticesStratum(dmMesh, topology::Stratum::DEPTH, 0);
+ const PetscInt vStart = verticesStratum.begin();
+ const PetscInt vEnd = verticesStratum.end();
+
MeshField field(mesh);
field.newSection(topology::FieldBase::VERTICES_FIELD, fiberDim);
field.allocate();
field.vectorFieldType(fieldType);
field.label(label.c_str());
- DM dmMesh = mesh.dmMesh();
- PetscInt vStart, vEnd;
- PetscErrorCode err;
+ { // Setup vertex field
+ topology::VecVisitorMesh fieldVisitor(field);
+ PetscScalar* fieldArray = fieldVisitor.localArray();
- CPPUNIT_ASSERT(dmMesh);
- err = DMPlexGetDepthStratum(dmMesh, 0, &vStart, &vEnd);CHECK_PETSC_ERROR(err);
+ CPPUNIT_ASSERT_EQUAL(nvertices, verticesStratum.size());
- PetscSection section = field.petscSection();
- Vec vec = field.localVector();
- PetscScalar *a;
- CPPUNIT_ASSERT(section);CPPUNIT_ASSERT(vec);
- CPPUNIT_ASSERT_EQUAL(nvertices, vEnd-vStart);
- err = VecGetArray(vec, &a);CHECK_PETSC_ERROR(err);
- for(PetscInt v = vStart; v < vEnd; ++v) {
- PetscInt dof, off;
+ for(PetscInt v = vStart, index = 0; v < vEnd; ++v) {
+ const PetscInt off = fieldVisitor.sectionOffset(v);
+ CPPUNIT_ASSERT_EQUAL(fiberDim, fieldVisitor.sectionDof(v));
- err = PetscSectionGetDof(section, v, &dof);CHECK_PETSC_ERROR(err);
- err = PetscSectionGetOffset(section, v, &off);CHECK_PETSC_ERROR(err);
- for(PetscInt d = 0; d < dof; ++d) {
- a[off+d] = fieldValues[(v-vStart)*dof+d];
- }
- } // for
- err = VecRestoreArray(vec, &a);CHECK_PETSC_ERROR(err);
+ for(PetscInt d = 0; d < fiberDim; ++d, ++index) {
+ fieldArray[off+d] = fieldValues[index];
+ } // for
+ } // for
+ } // Setup vertex field
VertexFilterVecNorm<MeshField> filter;
- const MeshField& fieldF = filter.filter(field);
- PetscSection sectionF = fieldF.petscSection();
- Vec vecF = fieldF.localVector();
- CPPUNIT_ASSERT(sectionF);CPPUNIT_ASSERT(vecF);
+ const MeshField& fieldNorm = filter.filter(field);
- CPPUNIT_ASSERT_EQUAL(fieldTypeE, fieldF.vectorFieldType());
- CPPUNIT_ASSERT_EQUAL(label, std::string(fieldF.label()));
+ CPPUNIT_ASSERT_EQUAL(fieldTypeE, fieldNorm.vectorFieldType());
+ CPPUNIT_ASSERT_EQUAL(label, std::string(fieldNorm.label()));
- const PylithScalar tolerance = 1.0e-06;
- err = VecGetArray(vecF, &a);CHECK_PETSC_ERROR(err);
- for(PetscInt v = vStart; v < vEnd; ++v) {
- PetscInt dof, off;
+ topology::VecVisitorMesh fieldNormVisitor(fieldNorm);
+ const PetscScalar* fieldNormArray = fieldNormVisitor.localArray();
- err = PetscSectionGetDof(sectionF, v, &dof);CHECK_PETSC_ERROR(err);
- err = PetscSectionGetOffset(sectionF, v, &off);CHECK_PETSC_ERROR(err);
- CPPUNIT_ASSERT_EQUAL(fiberDimE, dof);
- for(PetscInt d = 0; d < dof; ++d) {
- CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, a[off+d]/fieldValuesE[(v-vStart)*dof+d], tolerance);
- }
+ const PylithScalar tolerance = 1.0e-06;
+ for(PetscInt v = vStart, index = 0; v < vEnd; ++v) {
+ const PetscInt off = fieldNormVisitor.sectionOffset(v);
+ CPPUNIT_ASSERT_EQUAL(1, fieldNormVisitor.sectionDof(v));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, fieldNormArray[off]/fieldValuesE[index++], tolerance);
} // for
- err = VecRestoreArray(vecF, &a);CHECK_PETSC_ERROR(err);
+
+ PYLITH_METHOD_END;
} // testFilter
More information about the CIG-COMMITS
mailing list