[cig-commits] r14151 - in short/3D/PyLith/branches/pylith-swig: libsrc/feassemble libsrc/materials unittests/libtests/materials unittests/libtests/materials/data

brad at geodynamics.org brad at geodynamics.org
Wed Feb 25 11:54:53 PST 2009


Author: brad
Date: 2009-02-25 11:54:52 -0800 (Wed, 25 Feb 2009)
New Revision: 14151

Modified:
   short/3D/PyLith/branches/pylith-swig/libsrc/feassemble/Quadrature.cc
   short/3D/PyLith/branches/pylith-swig/libsrc/materials/ElasticMaterial.hh
   short/3D/PyLith/branches/pylith-swig/libsrc/materials/Material.hh
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestMaterial.cc
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestMaterial.hh
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/data/Makefile.am
Log:
Fixed bug in Quadrature (numBasis vs numCorners). Updated unit test for Material::initialize().

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/feassemble/Quadrature.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/feassemble/Quadrature.cc	2009-02-25 19:39:19 UTC (rev 14150)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/feassemble/Quadrature.cc	2009-02-25 19:54:52 UTC (rev 14151)
@@ -143,12 +143,12 @@
 
   const typename label_sequence::iterator cellsEnd = cells->end();
   assert(0 != _geometry);
-  const int numCorners = _geometry->numCorners();
+  const int numBasis = _numBasis;
   const ALE::Obj<typename mesh_type::SieveMesh>& sieveMesh = mesh.sieveMesh();
   assert(!sieveMesh.isNull());
   const ALE::Obj<RealSection>& coordinates = 
     sieveMesh->getRealSection("coordinates");
-  RestrictVisitor coordsVisitor(*coordinates, numCorners*_spaceDim);
+  RestrictVisitor coordsVisitor(*coordinates, numBasis*_spaceDim);
 
   const ALE::Obj<RealSection>& quadPtsSection = _quadPtsField->section();
   const ALE::Obj<RealSection>& jacobianSection = _jacobianField->section();

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/materials/ElasticMaterial.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/materials/ElasticMaterial.hh	2009-02-25 19:39:19 UTC (rev 14150)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/materials/ElasticMaterial.hh	2009-02-25 19:54:52 UTC (rev 14151)
@@ -65,7 +65,6 @@
    * @param mesh Finite-element mesh.
    * @param quadrature Quadrature for finite-element integration
    */
-  virtual
   void initialize(const topology::Mesh& mesh,
 		  feassemble::Quadrature<topology::Mesh>* quadrature);
   

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/materials/Material.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/materials/Material.hh	2009-02-25 19:39:19 UTC (rev 14150)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/materials/Material.hh	2009-02-25 19:54:52 UTC (rev 14151)
@@ -120,6 +120,9 @@
   /** Initialize material by getting physical property parameters from
    * database.
    *
+   * @pre Must call Quadrature::computeGeometry() before calling
+   * initialize().
+   *
    * @param mesh Finite-element mesh.
    * @param quadrature Quadrature for finite-element integration
    */
@@ -243,7 +246,7 @@
   int _id; ///< Material identifier.
   std::string _label; ///< Label of material.
 
-  const Metadata& _metadata; ///< Property and state variable metadata.
+  const Metadata _metadata; ///< Property and state variable metadata.
 
   // NOT IMPLEMENTED ////////////////////////////////////////////////////
 private :

Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestMaterial.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestMaterial.cc	2009-02-25 19:39:19 UTC (rev 14150)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestMaterial.cc	2009-02-25 19:54:52 UTC (rev 14151)
@@ -16,11 +16,15 @@
 
 #include "data/MaterialData.hh" // USES MaterialData
 
+#include "pylith/utils/array.hh" // USES double_array
+
+#include "pylith/topology/Mesh.hh" // USES Mesh
+#include "pylith/topology/Field.hh" // USES Field
+#include "pylith/meshio/MeshIOAscii.hh" // USES MeshIOAscii
 #include "pylith/materials/ElasticIsotropic3D.hh" // USES ElasticIsotropic3D
-#include "pylith/utils/array.hh" // USES double_array
-#include "pylith/feassemble/Quadrature1D.hh" // USES Quadrature1D
+#include "pylith/materials/ElasticStrain1D.hh" // USES ElasticStrain1D
+#include "pylith/feassemble/Quadrature.hh" // USES Quadrature
 #include "pylith/feassemble/GeometryLine1D.hh" // USES GeometryLine1D
-#include "pylith/topology/FieldsManager.hh" // USES FieldsManager
 
 #include "spatialdata/spatialdb/SimpleDB.hh" // USES SimpleDB
 #include "spatialdata/spatialdb/SimpleIOAscii.hh" // USES SimpleIOAscii
@@ -34,6 +38,10 @@
 CPPUNIT_TEST_SUITE_REGISTRATION( pylith::materials::TestMaterial );
 
 // ----------------------------------------------------------------------
+typedef pylith::topology::Mesh::SieveMesh SieveMesh;
+typedef pylith::topology::Mesh::RealSection RealSection;
+
+// ----------------------------------------------------------------------
 // Test id()
 void
 pylith::materials::TestMaterial::testID(void)
@@ -133,7 +141,6 @@
   CPPUNIT_ASSERT_EQUAL(flag, material.needNewJacobian());
 } // testNeedNewJacobian
 
-#if 0
 // ----------------------------------------------------------------------
 // Test initialize()
 void
@@ -142,7 +149,7 @@
   // Setup mesh
   topology::Mesh mesh;
   meshio::MeshIOAscii iohandler;
-  iohandler.filename("");
+  iohandler.filename("data/line3.mesh");
   iohandler.read(&mesh);
 
   // Set up coordinates
@@ -159,26 +166,42 @@
   const int numCorners = 3;
   const int numQuadPts = 2;
   const int spaceDim = 1;
-  const double basis[] = { 0.455, 0.667, -0.122, -0.122, 0.667, 0.455 };
-  const double basisDeriv[] = { -1.077, 1.155, -0.077, 0.077, -1.155, 1.077 };
+  const double basis[] = { 0.455, -0.122, 0.667, -0.122, 0.455, 0.667 };
+  const double basisDeriv[] = { 
+    -1.07735027e+00,
+    -7.73502692e-02,
+    1.15470054e+00,
+    7.73502692e-02,
+    1.07735027e+00,
+    -1.15470054e+00,
+  };
   const double quadPtsRef[] = { -0.577350269, 0.577350269 };
   const double quadWts[] = { 1.0, 1.0  };
   quadrature.initialize(basis, basisDeriv, quadPtsRef, quadWts,
 			cellDim, numCorners, numQuadPts, spaceDim);
 
 
+  // Get cells associated with material
+  const int materialId = 24;
+  const ALE::Obj<SieveMesh>& sieveMesh = mesh.sieveMesh();
+  assert(!sieveMesh.isNull());
+  const ALE::Obj<SieveMesh::label_sequence>& cells = 
+    sieveMesh->getLabelStratum("material-id", materialId);
+
+  // Compute geometry for cells
+  quadrature.computeGeometry(mesh, cells);
+
   spatialdata::spatialdb::SimpleDB db;
-  spatialdata::spatialdb::SimpleIOAscii iohandler;
-  iohandler.filename("data/matinitialize.spatialdb");
-  db.ioHandler(&iohandler);
+  spatialdata::spatialdb::SimpleIOAscii dbIO;
+  dbIO.filename("data/matinitialize.spatialdb");
+  db.ioHandler(&dbIO);
   db.queryType(spatialdata::spatialdb::SimpleDB::NEAREST);
   
   spatialdata::units::Nondimensional normalizer;
 
-  const int materialID = 24;
   ElasticStrain1D material;
   material.dbProperties(&db);
-  material.id(materialID);
+  material.id(materialId);
   material.label("my_material");
   material.normalizer(normalizer);
   material.initialize(mesh, &quadrature);
@@ -197,39 +220,39 @@
   const double muE[] = { muA, muB };
   const double lambdaE[] = { lambdaA, lambdaB };
 
-  // Get cells associated with material
-  const ALE::Obj<Mesh::label_sequence>& cells = mesh->heightStratum(0);
-
-  Mesh::label_sequence::iterator c_iter = cells->begin();
+  SieveMesh::label_sequence::iterator c_iter = cells->begin();
   const double tolerance = 1.0e-06;
 
-  const real_section_type::value_type* paramsCell =
-    material._properties->restrictPoint(*c_iter);
-  CPPUNIT_ASSERT(0 != paramsCell);
+  CPPUNIT_ASSERT(0 != material._properties);
+  const Obj<RealSection>& propertiesSection = material._properties->section();
+  CPPUNIT_ASSERT(!propertiesSection.isNull());
+  const double* propertiesCell = propertiesSection->restrictPoint(*c_iter);
+  CPPUNIT_ASSERT(0 != propertiesCell);
 
-  const int pidDensity = 0;
-  const int pidMu = 1;
-  const int pidLambda = 2;
+  const int p_density = 0;
+  const int p_mu = 1;
+  const int p_lambda = 2;
 
   // density
   for (int i=0; i < numQuadPts; ++i) {
-    const int index = i*material._totalPropsQuadPt + pidDensity;
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, paramsCell[index]/densityE[i], tolerance);
+    const int index = i*material._numPropsQuadPt + p_density;
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, propertiesCell[index]/densityE[i],
+				 tolerance);
   } // for
   
   // mu
   for (int i=0; i < numQuadPts; ++i) {
-    const int index = i*material._totalPropsQuadPt + pidMu;
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, paramsCell[index]/muE[i], tolerance);
+    const int index = i*material._numPropsQuadPt + p_mu;
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, propertiesCell[index]/muE[i], tolerance);
   } // for
   
   // lambda
   for (int i=0; i < numQuadPts; ++i) {
-    const int index = i*material._totalPropsQuadPt + pidLambda;
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, paramsCell[index]/lambdaE[i], tolerance);
+    const int index = i*material._numPropsQuadPt + p_lambda;
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, propertiesCell[index]/lambdaE[i], 
+				 tolerance);
   } // for
 } // testInitialize
-#endif
 
 // ----------------------------------------------------------------------
 // Setup testing data.

Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestMaterial.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestMaterial.hh	2009-02-25 19:39:19 UTC (rev 14150)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/TestMaterial.hh	2009-02-25 19:54:52 UTC (rev 14151)
@@ -47,9 +47,7 @@
   CPPUNIT_TEST( testDBStateVars );
   CPPUNIT_TEST( testNormalizer );
   CPPUNIT_TEST( testNeedNewJacobian );
-#if 0
   CPPUNIT_TEST( testInitialize );
-#endif
 
   CPPUNIT_TEST_SUITE_END();
 
@@ -77,10 +75,8 @@
   /// Test needNewJacobian()
   void testNeedNewJacobian(void);
 
-#if 0
   /// Test initialize()
   void testInitialize(void);
-#endif
 
   // PUBLIC METHODS /////////////////////////////////////////////////////
 public :

Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/data/Makefile.am
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/data/Makefile.am	2009-02-25 19:39:19 UTC (rev 14150)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/materials/data/Makefile.am	2009-02-25 19:54:52 UTC (rev 14151)
@@ -11,7 +11,8 @@
 #
 
 dist_noinst_DATA = \
-	matinitialize.spatialdb
+	matinitialize.spatialdb \
+	line3.mesh
 
 noinst_TMP =
 



More information about the CIG-COMMITS mailing list