[cig-commits] r22153 - in short/3D/PyLith/trunk: libsrc/pylith/materials libsrc/pylith/topology unittests/libtests/topology
brad at geodynamics.org
brad at geodynamics.org
Tue May 28 12:38:13 PDT 2013
Author: brad
Date: 2013-05-28 12:38:13 -0700 (Tue, 28 May 2013)
New Revision: 22153
Modified:
short/3D/PyLith/trunk/libsrc/pylith/materials/Material.cc
short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc
short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh
short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.cc
short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.hh
Log:
Fixed some bugs in creating section using an index set. Chart starting point was incorrect. Added Field::hasSection() convenience function. Added some missing unit tests for Field methods (chartSize(), sectionSize(), hasSection()).
Modified: short/3D/PyLith/trunk/libsrc/pylith/materials/Material.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/materials/Material.cc 2013-05-28 16:38:14 UTC (rev 22152)
+++ short/3D/PyLith/trunk/libsrc/pylith/materials/Material.cc 2013-05-28 19:38:13 UTC (rev 22153)
@@ -366,30 +366,22 @@
// Allocate buffer for property field if necessary.
bool useCurrentField = false;
- PetscSection fieldSection = field->petscSection();
- PetscInt pStart, pEnd;
- PetscErrorCode err;
- err = PetscSectionGetChart(fieldSection, &pStart, &pEnd);PYLITH_CHECK_ERROR(err);
- if (pEnd < 0) {
- err = DMPlexGetHeightStratum(dmMesh, 0, &pStart, &pEnd);PYLITH_CHECK_ERROR(err);
- err = PetscSectionSetChart(fieldSection, pStart, pEnd);PYLITH_CHECK_ERROR(err);
- } else {
+ if (field->hasSection()) {
// check fiber dimension
PetscInt totalFiberDimCurrentLocal = 0;
PetscInt totalFiberDimCurrent = 0;
if (numCells > 0) {
- err = PetscSectionGetDof(fieldSection, cells[0], &totalFiberDimCurrentLocal);PYLITH_CHECK_ERROR(err);
+ PetscSection fieldSection = field->petscSection();
+ PetscErrorCode err = PetscSectionGetDof(fieldSection, cells[0], &totalFiberDimCurrentLocal);PYLITH_CHECK_ERROR(err);
} // if
MPI_Allreduce((void *) &totalFiberDimCurrentLocal, (void *) &totalFiberDimCurrent, 1, MPIU_INT, MPI_MAX, field->mesh().comm());
assert(totalFiberDimCurrent > 0);
useCurrentField = totalFiberDim == totalFiberDimCurrent;
} // if
if (!useCurrentField) {
- int_array cellsTmp(cells, numCells);
- field->newSection(cellsTmp, totalFiberDim);
+ field->newSection(cells, numCells, totalFiberDim);
field->allocate();
} // if
- assert(fieldSection);
field->label(name);
field->scale(1.0);
fieldType = _metadata.getProperty(propertyIndex).fieldType;
@@ -439,13 +431,13 @@
const int totalFiberDim = numQuadPts * fiberDim;
// Allocate buffer for state variable field if necessary.
- PetscSection fieldSection = field->petscSection();
- bool useCurrentField = fieldSection != NULL;
- if (fieldSection) {
+ bool useCurrentField = false;
+ if (field->hasSection()) {
// check fiber dimension
PetscInt totalFiberDimCurrentLocal = 0;
PetscInt totalFiberDimCurrent = 0;
if (numCells > 0) {
+ PetscSection fieldSection = field->petscSection();
PetscErrorCode err = PetscSectionGetDof(fieldSection, cells[0], &totalFiberDimCurrentLocal);PYLITH_CHECK_ERROR(err);
} // if
MPI_Allreduce((void*) &totalFiberDimCurrentLocal, (void*) &totalFiberDimCurrent, 1, MPIU_INT, MPI_MAX, field->mesh().comm());
@@ -453,11 +445,9 @@
useCurrentField = totalFiberDim == totalFiberDimCurrent;
} // if
if (!useCurrentField) {
- int_array cellsTmp(cells, numCells);
- field->newSection(cellsTmp, totalFiberDim);
+ field->newSection(cells, numCells, totalFiberDim);
field->allocate();
} // if
- assert(fieldSection);
fieldType = _metadata.getStateVar(stateVarIndex).fieldType;
field->label(name);
field->scale(1.0);
@@ -484,8 +474,7 @@
} // for
} // if/else
- topology::FieldBase::VectorFieldEnum multiType =
- topology::FieldBase::MULTI_OTHER;
+ topology::FieldBase::VectorFieldEnum multiType = topology::FieldBase::MULTI_OTHER;
switch (fieldType)
{ // switch
case topology::FieldBase::SCALAR:
Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc 2013-05-28 16:38:14 UTC (rev 22152)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc 2013-05-28 19:38:13 UTC (rev 22153)
@@ -184,6 +184,25 @@
} // spaceDim
// ----------------------------------------------------------------------
+// Has section been setup?
+bool
+pylith::topology::Field::hasSection(void) const
+{ // hasSection
+ PYLITH_METHOD_BEGIN;
+
+ PetscErrorCode err;
+ PetscSection s = NULL;
+ err = DMGetDefaultSection(_dm, &s);PYLITH_CHECK_ERROR(err);
+
+ PetscInt pStart = 0, pEnd = 0;
+ err = PetscSectionGetChart(s, &pStart, &pEnd);PYLITH_CHECK_ERROR(err);
+
+ bool result = (pEnd < 0) ? false : true;
+
+ PYLITH_METHOD_RETURN(result);
+} // hasSection
+
+// ----------------------------------------------------------------------
// Get the chart size.
int
pylith::topology::Field::chartSize(void) const
@@ -255,9 +274,9 @@
const PetscInt npts = points.size();
if (npts > 0) {
PetscSection s = NULL;
- PetscInt pointMin = 0, pointMax = 0;
+ PetscInt pointMin = points[0], pointMax = points[0];
- for (PetscInt i = 0; i < npts; ++i) {
+ for (PetscInt i = 1; i < npts; ++i) {
pointMin = std::min(pointMin, points[i]);
pointMax = std::max(pointMax, points[i]);
} // for
@@ -302,9 +321,9 @@
if (num > 0) {
PetscSection s = NULL;
- PetscInt pointMin = 0, pointMax = 0;
+ PetscInt pointMin = points[0], pointMax = points[0];
- for (PetscInt i = 0; i < num; ++i) {
+ for (PetscInt i = 1; i < num; ++i) {
pointMin = std::min(pointMin, points[i]);
pointMax = std::max(pointMax, points[i]);
} // for
@@ -1062,18 +1081,6 @@
/* assert(order->getLocalSize() == localSize); This does not work because the local vector includes the lagrange cell variables */
/* assert(order->getGlobalSize() == globalSize); */
err = PetscSectionDestroy(&subSection);PYLITH_CHECK_ERROR(err);
-#if 0
- std::cout << "["<<mesh.commRank()<<"] CONTEXT: " << context
- << ", orderLabel: " << orderLabel
- << ", section size w/BC: " << _section->sizeWithBC()
- << ", section size: " << _section->size()
- << ", section storage size: " << _section->getStorageSize()
- << ", global numbering size: " << numbering->getGlobalSize()
- << ", global order size: " << order->getGlobalSize()
- << ", local numbering size: " << numbering->getLocalSize()
- << ", local order size: " << order->getLocalSize()
- << std::endl;
-#endif
PYLITH_METHOD_END;
} // createScatterWithBC
Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh 2013-05-28 16:38:14 UTC (rev 22152)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh 2013-05-28 19:38:13 UTC (rev 22153)
@@ -164,6 +164,24 @@
*/
int spaceDim(void) const;
+ /** Get the number of points in the chart.
+ *
+ * @returns the chart size.
+ */
+ int chartSize(void) const;
+
+ /** Get the number of degrees of freedom.
+ *
+ * @returns the number of degrees of freedom.
+ */
+ int sectionSize(void) const;
+
+ /** Has section been setup?
+ *
+ * @returns True if section has been setup.
+ */
+ bool hasSection(void) const;
+
/** Get PetscSection.
*
* @returns PETSc section.
@@ -182,18 +200,6 @@
*/
PetscVec globalVector(void) const;
- /** Get the number of points in the chart.
- *
- * @returns the chart size.
- */
- int chartSize(void) const;
-
- /** Get the number of degrees of freedom.
- *
- * @returns the number of degrees of freedom.
- */
- int sectionSize(void) const;
-
/** Create PETSc section.
*
* @note Don't forget to call label().
Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.cc 2013-05-28 16:38:14 UTC (rev 22152)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.cc 2013-05-28 19:38:13 UTC (rev 22153)
@@ -194,6 +194,81 @@
} // testSpaceDim
// ----------------------------------------------------------------------
+// Test chartSize().
+void
+pylith::topology::TestFieldMesh::testChartSize(void)
+{ // testChartSize
+ PYLITH_METHOD_BEGIN;
+
+ const int fiberDim = 2;
+ const std::string& label = "field A";
+
+ Mesh mesh;
+ _buildMesh(&mesh);
+
+ Field field(mesh);
+ field.label(label.c_str());
+
+ CPPUNIT_ASSERT_EQUAL(0, field.chartSize());
+
+ field.newSection(topology::FieldBase::VERTICES_FIELD, fiberDim);
+ field.allocate();
+
+ CPPUNIT_ASSERT_EQUAL(_TestFieldMesh::nvertices, field.chartSize());
+
+ PYLITH_METHOD_END;
+} // testChartSize
+
+// ----------------------------------------------------------------------
+// Test sectionSize().
+void
+pylith::topology::TestFieldMesh::testSectionSize(void)
+{ // testSectionSize
+ PYLITH_METHOD_BEGIN;
+
+ const int fiberDim = 2;
+ const std::string& label = "field A";
+
+ Mesh mesh;
+ _buildMesh(&mesh);
+
+ Field field(mesh);
+ field.label(label.c_str());
+
+ CPPUNIT_ASSERT_EQUAL(0, field.sectionSize());
+
+ field.newSection(topology::FieldBase::VERTICES_FIELD, fiberDim);
+ field.allocate();
+
+ CPPUNIT_ASSERT_EQUAL(_TestFieldMesh::nvertices*fiberDim, field.sectionSize());
+
+ PYLITH_METHOD_END;
+} // testSectionSize
+
+// ----------------------------------------------------------------------
+// Test hasSection().
+void
+pylith::topology::TestFieldMesh::testHasSection(void)
+{ // testHasSection
+ PYLITH_METHOD_BEGIN;
+
+ const int fiberDim = 2;
+ const std::string& label = "field A";
+
+ Mesh mesh;
+ _buildMesh(&mesh);
+ Field field(mesh);
+ field.label(label.c_str());
+
+ CPPUNIT_ASSERT(!field.hasSection());
+ field.newSection(topology::FieldBase::VERTICES_FIELD, fiberDim);
+
+ CPPUNIT_ASSERT(field.hasSection());
+
+ PYLITH_METHOD_END;
+} // testHasSection
+
+// ----------------------------------------------------------------------
// Test newSection().
void
pylith::topology::TestFieldMesh::testNewSection(void)
Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.hh 2013-05-28 16:38:14 UTC (rev 22152)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldMesh.hh 2013-05-28 19:38:13 UTC (rev 22153)
@@ -53,6 +53,9 @@
CPPUNIT_TEST( testScale );
CPPUNIT_TEST( testAddDimensionOkay );
CPPUNIT_TEST( testSpaceDim );
+ CPPUNIT_TEST( testChartSize );
+ CPPUNIT_TEST( testSectionSize );
+ CPPUNIT_TEST( testHasSection );
CPPUNIT_TEST( testNewSection );
CPPUNIT_TEST( testNewSectionPoints );
CPPUNIT_TEST( testNewSectionPointsArray );
@@ -105,6 +108,15 @@
/// Test spaceDim().
void testSpaceDim(void);
+ /// Test chartSize().
+ void testChartSize(void);
+
+ /// Test sectionSize().
+ void testSectionSize(void);
+
+ /// Test hasSection().
+ void testHasSection(void);
+
/// Test newSection().
void testNewSection(void);
More information about the CIG-COMMITS
mailing list