[cig-commits] r14391 - in short/3D/PyLith/branches/pylith-swig: . libsrc/meshio libsrc/topology unittests/libtests/topology
brad at geodynamics.org
brad at geodynamics.org
Thu Mar 19 09:43:29 PDT 2009
Author: brad
Date: 2009-03-19 09:43:28 -0700 (Thu, 19 Mar 2009)
New Revision: 14391
Modified:
short/3D/PyLith/branches/pylith-swig/TODO
short/3D/PyLith/branches/pylith-swig/libsrc/meshio/MeshBuilder.cc
short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.icc
short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldMesh.cc
short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldSubMesh.cc
short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldSubMesh.hh
Log:
Fixed memory leak. Added vector/scatter unit tests to TestFieldSubMesh.
Modified: short/3D/PyLith/branches/pylith-swig/TODO
===================================================================
--- short/3D/PyLith/branches/pylith-swig/TODO 2009-03-19 10:12:05 UTC (rev 14390)
+++ short/3D/PyLith/branches/pylith-swig/TODO 2009-03-19 16:43:28 UTC (rev 14391)
@@ -8,13 +8,6 @@
createScatter()
When copying layout, copy VecScatter. [Fields]
- libtests/topology/Field
- createVector()
- vector()
- createScatter()
- scatterVectorToSection()
- scatterSectionToVector()
-
Cleanup logging. Constraints and Integrators should log at the C++
level using the C++ EventLogger. Add finer grain logging at C++
level as in ElasticityImplicit.
Modified: short/3D/PyLith/branches/pylith-swig/libsrc/meshio/MeshBuilder.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/meshio/MeshBuilder.cc 2009-03-19 10:12:05 UTC (rev 14390)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/meshio/MeshBuilder.cc 2009-03-19 16:43:28 UTC (rev 14391)
@@ -107,7 +107,8 @@
sieve->setCone(cone, c);
sieve->setConeOrientation(coneO, c);
} // for
- delete [] cone; cone = 0;
+ delete[] cone; cone = 0;
+ delete[] coneO; coneO = 0;
// Symmetrize to fill up supports
sieve->symmetrize();
} else {
Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.icc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.icc 2009-03-19 10:12:05 UTC (rev 14390)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.icc 2009-03-19 16:43:28 UTC (rev 14391)
@@ -30,6 +30,11 @@
template<typename field_type>
pylith::topology::Fields<field_type>::~Fields(void)
{ // destructor
+ const typename map_type::iterator begin = _fields.begin();
+ const typename map_type::iterator end = _fields.end();
+ for (typename map_type::iterator iter=begin; iter != end; ++iter) {
+ delete iter->second; iter->second = 0;
+ } // for
} // destructor
// ----------------------------------------------------------------------
Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldMesh.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldMesh.cc 2009-03-19 10:12:05 UTC (rev 14390)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldMesh.cc 2009-03-19 16:43:28 UTC (rev 14391)
@@ -226,16 +226,14 @@
const ALE::Obj<Mesh::RealSection>& section = fieldSrc.section();
CPPUNIT_ASSERT(!section.isNull());
int iV=0;
-
- CPPUNIT_ASSERT(!vertices.isNull());
for (Mesh::SieveMesh::label_sequence::iterator v_iter=vertices->begin();
v_iter != vertices->end();
++v_iter)
section->addConstraintDimension(*v_iter, nconstraints[iV++]);
fieldSrc.allocate();
+ fieldSrc.createScatter();
} // Setup source field
-
Field<Mesh> field(mesh);
field.newSection(fieldSrc);
const ALE::Obj<Mesh::RealSection>& section = field.section();
@@ -248,6 +246,9 @@
CPPUNIT_ASSERT_EQUAL(nconstraints[iV++],
section->getConstraintDimension(*v_iter));
} // for
+
+ // Verify vector scatter was also copied.
+ CPPUNIT_ASSERT_EQUAL(fieldSrc._scatter, field._scatter);
} // testNewSectionField
// ----------------------------------------------------------------------
@@ -732,6 +733,10 @@
// Make sure we can do multiple calls to createScatter().
field.createScatter();
CPPUNIT_ASSERT(0 != field._scatter);
+
+ Field<Mesh> fieldB(mesh);
+ fieldB.newSection(field);
+ CPPUNIT_ASSERT_EQUAL(fieldB._scatter, field._scatter);
} // testCreateScatter
// ----------------------------------------------------------------------
Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldSubMesh.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldSubMesh.cc 2009-03-19 10:12:05 UTC (rev 14390)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldSubMesh.cc 2009-03-19 16:43:28 UTC (rev 14391)
@@ -135,15 +135,16 @@
SubMesh submesh;
_buildMesh(&mesh, &submesh);
const ALE::Obj<SubMesh::SieveMesh>& sieveMesh = submesh.sieveMesh();
+ CPPUNIT_ASSERT(!sieveMesh.isNull());
Field<SubMesh> field(submesh);
const ALE::Obj<SieveMesh::label_sequence>& vertices =
sieveMesh->depthStratum(0);
+ CPPUNIT_ASSERT(!vertices.isNull());
field.newSection(vertices, fiberDim);
const ALE::Obj<SubMesh::RealSection>& section = field.section();
CPPUNIT_ASSERT(!section.isNull());
- CPPUNIT_ASSERT(!vertices.isNull());
for (SieveMesh::label_sequence::iterator v_iter=vertices->begin();
v_iter != vertices->end();
++v_iter)
@@ -161,6 +162,7 @@
SubMesh submesh;
_buildMesh(&mesh, &submesh);
const ALE::Obj<SieveMesh>& sieveMesh = submesh.sieveMesh();
+ CPPUNIT_ASSERT(!sieveMesh.isNull());
Field<SubMesh> field(submesh);
field.newSection(Field<SubMesh>::VERTICES_FIELD, fiberDim);
@@ -194,6 +196,7 @@
SubMesh submesh;
_buildMesh(&mesh, &submesh);
const ALE::Obj<SieveMesh>& sieveMesh = submesh.sieveMesh();
+ CPPUNIT_ASSERT(!sieveMesh.isNull());
// Create field with atlas to use to create new field
Field<SubMesh> fieldSrc(submesh);
@@ -205,6 +208,7 @@
Field<SubMesh> field(submesh);
field.newSection(chart, fiberDim);
const ALE::Obj<SubMesh::RealSection>& section = field.section();
+ CPPUNIT_ASSERT(!section.isNull());
const ALE::Obj<SieveMesh::label_sequence>& vertices =
sieveMesh->depthStratum(0);
CPPUNIT_ASSERT(!vertices.isNull());
@@ -232,6 +236,7 @@
SubMesh submesh;
_buildMesh(&mesh, &submesh);
const ALE::Obj<SieveMesh>& sieveMesh = submesh.sieveMesh();
+ CPPUNIT_ASSERT(!sieveMesh.isNull());
const ALE::Obj<SieveMesh::label_sequence>& vertices =
sieveMesh->depthStratum(0);
@@ -242,6 +247,7 @@
{ // Setup source field
fieldSrc.newSection(Field<SubMesh>::VERTICES_FIELD, fiberDim);
const ALE::Obj<SubMesh::RealSection>& section = fieldSrc.section();
+ CPPUNIT_ASSERT(!section.isNull());
int iV=0;
CPPUNIT_ASSERT(!vertices.isNull());
@@ -256,6 +262,7 @@
Field<SubMesh> field(submesh);
field.newSection(fieldSrc);
const ALE::Obj<SubMesh::RealSection>& section = field.section();
+ CPPUNIT_ASSERT(!section.isNull());
int iV = 0;
for (SieveMesh::label_sequence::iterator v_iter=vertices->begin();
v_iter != vertices->end();
@@ -304,13 +311,16 @@
SubMesh submesh;
_buildMesh(&mesh, &submesh);
const ALE::Obj<SieveMesh>& sieveMesh = submesh.sieveMesh();
+ CPPUNIT_ASSERT(!sieveMesh.isNull());
const ALE::Obj<SieveMesh::label_sequence>& vertices =
sieveMesh->depthStratum(0);
+ CPPUNIT_ASSERT(!vertices.isNull());
Field<SubMesh> field(submesh);
field.newSection(Field<SubMesh>::VERTICES_FIELD, fiberDim);
field.allocate();
const ALE::Obj<SubMesh::RealSection>& section = field.section();
+ CPPUNIT_ASSERT(!section.isNull());
double_array values(fiberDim);
int i = 0;
@@ -351,13 +361,16 @@
SubMesh submesh;
_buildMesh(&mesh, &submesh);
const ALE::Obj<SieveMesh>& sieveMesh = submesh.sieveMesh();
+ CPPUNIT_ASSERT(!sieveMesh.isNull());
const ALE::Obj<SieveMesh::label_sequence>& vertices =
sieveMesh->depthStratum(0);
+ CPPUNIT_ASSERT(!vertices.isNull());
Field<SubMesh> field(submesh);
field.newSection(Field<SubMesh>::VERTICES_FIELD, fiberDim);
field.allocate();
const ALE::Obj<SubMesh::RealSection>& section = field.section();
+ CPPUNIT_ASSERT(!section.isNull());
double_array values(fiberDim);
int i = 0;
@@ -399,13 +412,16 @@
SubMesh submesh;
_buildMesh(&mesh, &submesh);
const ALE::Obj<SieveMesh>& sieveMesh = submesh.sieveMesh();
+ CPPUNIT_ASSERT(!sieveMesh.isNull());
const ALE::Obj<SieveMesh::label_sequence>& vertices =
sieveMesh->depthStratum(0);
+ CPPUNIT_ASSERT(!vertices.isNull());
Field<SubMesh> field(submesh);
field.newSection(Field<SubMesh>::VERTICES_FIELD, fiberDim);
field.allocate();
const ALE::Obj<SubMesh::RealSection>& section = field.section();
+ CPPUNIT_ASSERT(!section.isNull());
double_array values(fiberDim);
int i = 0;
@@ -449,14 +465,17 @@
SubMesh submesh;
_buildMesh(&mesh, &submesh);
const ALE::Obj<SieveMesh>& sieveMesh = submesh.sieveMesh();
+ CPPUNIT_ASSERT(!sieveMesh.isNull());
const ALE::Obj<SieveMesh::label_sequence>& vertices =
sieveMesh->depthStratum(0);
+ CPPUNIT_ASSERT(!vertices.isNull());
Field<SubMesh> fieldSrc(submesh);
{ // Setup source field
fieldSrc.newSection(Field<SubMesh>::VERTICES_FIELD, fiberDim);
fieldSrc.allocate();
const ALE::Obj<SubMesh::RealSection>& section = fieldSrc.section();
+ CPPUNIT_ASSERT(!section.isNull());
double_array values(fiberDim);
int i = 0;
@@ -473,6 +492,7 @@
field.newSection(Field<SubMesh>::VERTICES_FIELD, fiberDim);
field.allocate();
const ALE::Obj<SubMesh::RealSection>& section = field.section();
+ CPPUNIT_ASSERT(!section.isNull());
field.copy(fieldSrc);
@@ -511,14 +531,17 @@
SubMesh submesh;
_buildMesh(&mesh, &submesh);
const ALE::Obj<SieveMesh>& sieveMesh = submesh.sieveMesh();
+ CPPUNIT_ASSERT(!sieveMesh.isNull());
const ALE::Obj<SieveMesh::label_sequence>& vertices =
sieveMesh->depthStratum(0);
+ CPPUNIT_ASSERT(!vertices.isNull());
Field<SubMesh> fieldSrc(submesh);
{ // Setup source field
fieldSrc.newSection(Field<SubMesh>::VERTICES_FIELD, fiberDim);
fieldSrc.allocate();
const ALE::Obj<SubMesh::RealSection>& section = fieldSrc.section();
+ CPPUNIT_ASSERT(!section.isNull());
double_array values(fiberDim);
int i = 0;
@@ -535,6 +558,7 @@
field.newSection(Field<SubMesh>::VERTICES_FIELD, fiberDim);
field.allocate();
const ALE::Obj<SubMesh::RealSection>& section = field.section();
+ CPPUNIT_ASSERT(!section.isNull());
{ // Setup destination field
double_array values(fiberDim);
@@ -582,13 +606,16 @@
SubMesh submesh;
_buildMesh(&mesh, &submesh);
const ALE::Obj<SieveMesh>& sieveMesh = submesh.sieveMesh();
+ CPPUNIT_ASSERT(!sieveMesh.isNull());
Field<SubMesh> field(submesh);
field.newSection(Field<SubMesh>::VERTICES_FIELD, fiberDim);
field.allocate();
const ALE::Obj<SubMesh::RealSection>& section = field.section();
+ CPPUNIT_ASSERT(!section.isNull());
const ALE::Obj<SieveMesh::label_sequence>& vertices =
sieveMesh->depthStratum(0);
+ CPPUNIT_ASSERT(!vertices.isNull());
double_array values(fiberDim);
int i = 0;
@@ -635,12 +662,15 @@
SubMesh submesh;
_buildMesh(&mesh, &submesh);
const ALE::Obj<SieveMesh>& sieveMesh = submesh.sieveMesh();
+ CPPUNIT_ASSERT(!sieveMesh.isNull());
Field<SubMesh> field(submesh);
field.newSection(Field<SubMesh>::VERTICES_FIELD, fiberDim);
field.allocate();
const ALE::Obj<SubMesh::RealSection>& section = field.section();
+ CPPUNIT_ASSERT(!section.isNull());
const ALE::Obj<SieveMesh::label_sequence>& vertices =
sieveMesh->depthStratum(0);
+ CPPUNIT_ASSERT(!vertices.isNull());
double_array values(fiberDim);
int i = 0;
@@ -656,7 +686,187 @@
} // testView
// ----------------------------------------------------------------------
+// Test createVector().
void
+pylith::topology::TestFieldSubMesh::testCreateVector(void)
+{ // testCreateVector
+ const int fiberDim = 3;
+
+ Mesh mesh;
+ SubMesh submesh;
+ _buildMesh(&mesh, &submesh);
+ const ALE::Obj<SubMesh::SieveMesh>& sieveMesh = submesh.sieveMesh();
+ CPPUNIT_ASSERT(!sieveMesh.isNull());
+ Field<SubMesh> field(submesh);
+ field.newSection(FieldBase::VERTICES_FIELD, fiberDim);
+ field.allocate();
+
+ const ALE::Obj<SubMesh::SieveMesh::label_sequence>& vertices =
+ sieveMesh->depthStratum(0);
+ CPPUNIT_ASSERT(!vertices.isNull());
+ const int sizeE = vertices->size() * fiberDim;
+
+ field.createVector();
+
+ CPPUNIT_ASSERT(0 != field._vector);
+ int size = 0;
+ VecGetSize(field._vector, &size);
+ CPPUNIT_ASSERT_EQUAL(sizeE, size);
+
+ // Make sure we can do multiple calls to createVector().
+ field.createVector();
+ CPPUNIT_ASSERT(0 != field._vector);
+} // testCreateVector
+
+// ----------------------------------------------------------------------
+// Test vector().
+void
+pylith::topology::TestFieldSubMesh::testVector(void)
+{ // testVector
+ const int fiberDim = 3;
+
+ Mesh mesh;
+ SubMesh submesh;
+ _buildMesh(&mesh, &submesh);
+ Field<SubMesh> field(submesh);
+ field.newSection(FieldBase::VERTICES_FIELD, fiberDim);
+ field.allocate();
+
+ CPPUNIT_ASSERT(0 == field._vector);
+ field.createVector();
+ CPPUNIT_ASSERT(0 != field._vector);
+ const PetscVec vector = field.vector();
+ CPPUNIT_ASSERT_EQUAL(field._vector, vector);
+} // testVector
+
+// ----------------------------------------------------------------------
+// Test createScatter().
+void
+pylith::topology::TestFieldSubMesh::testCreateScatter(void)
+{ // testCreateScatter
+ const int fiberDim = 3;
+
+ Mesh mesh;
+ SubMesh submesh;
+ _buildMesh(&mesh, &submesh);
+ Field<SubMesh> field(submesh);
+ field.newSection(FieldBase::VERTICES_FIELD, fiberDim);
+ field.allocate();
+
+ CPPUNIT_ASSERT(0 == field._scatter);
+ field.createScatter();
+ CPPUNIT_ASSERT(0 != field._scatter);
+
+ // Make sure we can do multiple calls to createScatter().
+ field.createScatter();
+ CPPUNIT_ASSERT(0 != field._scatter);
+} // testCreateScatter
+
+// ----------------------------------------------------------------------
+// Test scatterSectionToVector().
+void
+pylith::topology::TestFieldSubMesh::testScatterSectionToVector(void)
+{ // testScatterSectionToVector
+ const int fiberDim = 3;
+ const double valuesE[] = {
+ 1.1, 2.2, 3.3,
+ 1.2, 2.3, 3.4,
+ 1.3, 2.4, 3.5,
+ };
+
+ Mesh mesh;
+ SubMesh submesh;
+ _buildMesh(&mesh, &submesh);
+ Field<SubMesh> field(submesh);
+ const ALE::Obj<SubMesh::SieveMesh>& sieveMesh = submesh.sieveMesh();
+ field.newSection(FieldBase::VERTICES_FIELD, fiberDim);
+ field.allocate();
+ const ALE::Obj<SubMesh::RealSection>& section = field.section();
+ const ALE::Obj<SubMesh::SieveMesh::label_sequence>& vertices =
+ sieveMesh->depthStratum(0);
+
+ double_array values(fiberDim);
+ int i = 0;
+ for (SubMesh::SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+ v_iter != vertices->end();
+ ++v_iter) {
+ for (int iDim=0; iDim < fiberDim; ++iDim)
+ values[iDim] = valuesE[i++];
+ section->updatePoint(*v_iter, &values[0]);
+ } // for
+
+ field.scatterSectionToVector();
+ CPPUNIT_ASSERT(0 != field._scatter);
+ const PetscVec vec = field.vector();
+ CPPUNIT_ASSERT(0 != vec);
+ int size = 0;
+ VecGetSize(vec, &size);
+ double* valuesVec = 0;
+ VecGetArray(vec, &valuesVec);
+
+ const double tolerance = 1.0e-06;
+ const int sizeE = vertices->size() * fiberDim;
+ CPPUNIT_ASSERT_EQUAL(sizeE, size);
+ for (int i=0; i < sizeE; ++i)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesE[i], valuesVec[i], tolerance);
+ VecRestoreArray(vec, &valuesVec);
+} // testScatterSectionToVector
+
+// ----------------------------------------------------------------------
+// Test scatterVectorToSection().
+void
+pylith::topology::TestFieldSubMesh::testScatterVectorToSection(void)
+{ // testScatterVectorToSection
+ const int fiberDim = 3;
+ const double valuesE[] = {
+ 1.1, 2.2, 3.3,
+ 1.2, 2.3, 3.4,
+ 1.3, 2.4, 3.5,
+ };
+
+ Mesh mesh;
+ SubMesh submesh;
+ _buildMesh(&mesh, &submesh);
+ Field<SubMesh> field(submesh);
+ const ALE::Obj<SubMesh::SieveMesh>& sieveMesh = submesh.sieveMesh();
+ field.newSection(FieldBase::VERTICES_FIELD, fiberDim);
+ field.allocate();
+ const ALE::Obj<SubMesh::RealSection>& section = field.section();
+ const ALE::Obj<SubMesh::SieveMesh::label_sequence>& vertices =
+ sieveMesh->depthStratum(0);
+
+ field.createVector();
+ const PetscVec vec = field.vector();
+ CPPUNIT_ASSERT(0 != vec);
+ int size = 0;
+ VecGetSize(vec, &size);
+ double* valuesVec = 0;
+ VecGetArray(vec, &valuesVec);
+
+ const double tolerance = 1.0e-06;
+ const int sizeE = vertices->size() * fiberDim;
+ CPPUNIT_ASSERT_EQUAL(sizeE, size);
+ for (int i=0; i < sizeE; ++i)
+ valuesVec[i] = valuesE[i];
+ VecRestoreArray(vec, &valuesVec);
+
+ field.scatterVectorToSection();
+ CPPUNIT_ASSERT(0 != field._scatter);
+
+ double_array values(fiberDim);
+ int i = 0;
+ for (SubMesh::SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+ v_iter != vertices->end();
+ ++v_iter) {
+ section->restrictPoint(*v_iter, &values[0], fiberDim);
+ for (int iDim=0; iDim < fiberDim; ++iDim)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesE[i++], values[iDim], tolerance);
+ } // for
+
+} // testScatterVectorToSection
+
+// ----------------------------------------------------------------------
+void
pylith::topology::TestFieldSubMesh::_buildMesh(Mesh* mesh,
SubMesh* submesh)
{ // _buildMesh
@@ -665,6 +875,7 @@
mesh->createSieveMesh(_TestFieldSubMesh::cellDim);
const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh->sieveMesh();
+ CPPUNIT_ASSERT(!sieveMesh.isNull());
ALE::Obj<Mesh::SieveMesh::sieve_type> sieve =
new Mesh::SieveMesh::sieve_type(sieveMesh->comm());
@@ -672,6 +883,7 @@
ALE::Obj<ALE::Mesh::sieve_type> s =
new ALE::Mesh::sieve_type(sieve->comm(), sieve->debug());
+ CPPUNIT_ASSERT(!s.isNull());
const int cellDim = _TestFieldSubMesh::cellDim;
const int ncells = _TestFieldSubMesh::ncells;
Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldSubMesh.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldSubMesh.hh 2009-03-19 10:12:05 UTC (rev 14390)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldSubMesh.hh 2009-03-19 16:43:28 UTC (rev 14391)
@@ -57,6 +57,11 @@
CPPUNIT_TEST( testOperatorAdd );
CPPUNIT_TEST( testDimensionalize );
CPPUNIT_TEST( testView );
+ CPPUNIT_TEST( testCreateVector );
+ CPPUNIT_TEST( testVector );
+ CPPUNIT_TEST( testCreateScatter );
+ CPPUNIT_TEST( testScatterSectionToVector );
+ CPPUNIT_TEST( testScatterVectorToSection );
CPPUNIT_TEST_SUITE_END();
@@ -114,6 +119,21 @@
/// Test view().
void testView(void);
+ /// Test createVector().
+ void testCreateVector(void);
+
+ /// Test vector().
+ void testVector(void);
+
+ /// Test createScatter().
+ void testCreateScatter(void);
+
+ /// Test scatterSectionToVector().
+ void testScatterSectionToVector(void);
+
+ /// Test scatterVectorToSection().
+ void testScatterVectorToSection(void);
+
// PRIVATE METHODS /////////////////////////////////////////////////////
private :
More information about the CIG-COMMITS
mailing list