[cig-commits] r6313 - in short/3D/PyLith/trunk: . libsrc/materials unittests/libtests/materials unittests/libtests/materials/data

brad at geodynamics.org brad at geodynamics.org
Mon Mar 19 22:52:20 PDT 2007


Author: brad
Date: 2007-03-19 22:52:19 -0700 (Mon, 19 Mar 2007)
New Revision: 6313

Added:
   short/3D/PyLith/trunk/unittests/libtests/materials/data/Makefile.am
   short/3D/PyLith/trunk/unittests/libtests/materials/data/matinitialize.spatialdb
Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/configure.ac
   short/3D/PyLith/trunk/libsrc/materials/Material.cc
   short/3D/PyLith/trunk/unittests/libtests/materials/Makefile.am
   short/3D/PyLith/trunk/unittests/libtests/materials/TestElasticMaterial.cc
   short/3D/PyLith/trunk/unittests/libtests/materials/TestMaterial.cc
Log:
Finished implementing C++ unit tests for Material, ElasticMaterial, and ElasticIsotropic3D.

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2007-03-20 05:49:59 UTC (rev 6312)
+++ short/3D/PyLith/trunk/TODO	2007-03-20 05:52:19 UTC (rev 6313)
@@ -5,18 +5,12 @@
 Unit tests:
   petsc module
   ParameterManager
-  Material
-  MaterialElastic
-  ElasticIsotropic3D
 
 0. Finish implementing materials with 3-D linear, isotropic elastic material
-   a. unit tests for C++ level
+   a. unit tests for C++ level [DONE]
    b. unit tests for Python level
 
-1. Create element families for materials.
-   a. Limit cells to cells with material label
-
-2. Finish implementing ExplicitElasticity
+1. Finish implementing ExplicitElasticity
    a. C++
    b. Python object
    c. bindings
@@ -26,12 +20,12 @@
    Status: Started on a.
     Only implement nonlumped and let PETSc "solver" do the lumping.
 
-3. Finish implementing Python Formulation
+2. Finish implementing Python Formulation
    (e.g., Explicit) with initialization of solid element families.
    a. Python object
    b. unit tests at Python level
 
-4. Implement unit tests for MeshIO at Python level.
+3. Implement unit tests for MeshIO at Python level.
    a. read()/write()
    b. checkFile()
 

Modified: short/3D/PyLith/trunk/configure.ac
===================================================================
--- short/3D/PyLith/trunk/configure.ac	2007-03-20 05:49:59 UTC (rev 6312)
+++ short/3D/PyLith/trunk/configure.ac	2007-03-20 05:52:19 UTC (rev 6313)
@@ -160,6 +160,7 @@
 		unittests/libtests/Makefile
 		unittests/libtests/feassemble/Makefile
 		unittests/libtests/materials/Makefile
+		unittests/libtests/materials/data/Makefile
 		unittests/libtests/meshio/Makefile
 		unittests/pytests/Makefile
 		unittests/pytests/feassemble/Makefile

Modified: short/3D/PyLith/trunk/libsrc/materials/Material.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/materials/Material.cc	2007-03-20 05:49:59 UTC (rev 6312)
+++ short/3D/PyLith/trunk/libsrc/materials/Material.cc	2007-03-20 05:52:19 UTC (rev 6313)
@@ -105,7 +105,7 @@
   double* queryData = (numValues > 0) ? new double[numValues] : 0;
   double* paramData = (numParams > 0) ? new double[numParams] : 0;
   double** cellData = (numParams > 0) ? new double*[numParams] : 0;
-  for (int iParam = 0; iParam < 0; ++iParam)
+  for (int iParam = 0; iParam < numParams; ++iParam)
     cellData[iParam] = (numQuadPts > 0) ? new double[numQuadPts] : 0;
   for (topology_type::label_sequence::iterator cellIter=cells->begin();
        cellIter != cellsEnd;
@@ -134,7 +134,7 @@
 	// Cleanup, then throw exception
 	for (int iParam=0; iParam < numParams; ++iParam) {
 	  delete[] cellData[iParam]; cellData[iParam] = 0;
-	} // fir
+	} // for
 	delete[] cellData; cellData = 0;
 	delete[] queryData; queryData = 0;
 	delete[] paramData; paramData = 0;
@@ -155,6 +155,7 @@
   delete[] cellData; cellData = 0;
   delete[] queryData; queryData = 0;
   delete[] paramData; paramData = 0;
+  delete[] paramSections; paramSections = 0;
 
   // Close database
   _db->close();

Modified: short/3D/PyLith/trunk/unittests/libtests/materials/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/materials/Makefile.am	2007-03-20 05:49:59 UTC (rev 6312)
+++ short/3D/PyLith/trunk/unittests/libtests/materials/Makefile.am	2007-03-20 05:52:19 UTC (rev 6313)
@@ -13,6 +13,8 @@
 subpackage = materials
 include $(top_srcdir)/subpackage.am
 
+SUBDIRS = data
+
 TESTS = testmaterials
 
 check_PROGRAMS = testmaterials
@@ -36,7 +38,8 @@
 noinst_HEADERS += \
 	data/MaterialData.hh \
 	data/ElasticMaterialData.hh \
-	data/ElasticIsotropic3DData.hh
+	data/ElasticIsotropic3DData.hh \
+	data/header.hh
 
 testmaterials_LDFLAGS = $(PETSC_LIB)
 
@@ -47,8 +50,5 @@
 	$(top_builddir)/libsrc/libpylith.la \
 	-lspatialdata
 
-noinst_tmp =
 
-CLEANFILES = $(noinst_tmp)
-
 # End of file 

Modified: short/3D/PyLith/trunk/unittests/libtests/materials/TestElasticMaterial.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/materials/TestElasticMaterial.cc	2007-03-20 05:49:59 UTC (rev 6312)
+++ short/3D/PyLith/trunk/unittests/libtests/materials/TestElasticMaterial.cc	2007-03-20 05:52:19 UTC (rev 6313)
@@ -16,7 +16,10 @@
 
 #include "pylith/materials/ElasticIsotropic3D.hh" // USES ElasticIsotropic3D
 #include "data/ElasticMaterialData.hh" // USES ElasticMaterialData
+#include "data/ElasticIsotropic3DData.hh" // USES ElasticIsotropic3DData
 
+#include "pylith/feassemble/ParameterManager.hh" // USES ParameterManager
+
 // ----------------------------------------------------------------------
 CPPUNIT_TEST_SUITE_REGISTRATION( pylith::materials::TestElasticMaterial );
 
@@ -80,7 +83,110 @@
 void
 pylith::materials::TestElasticMaterial::testCalcProperties(void)
 { // testCalcProperties
-  CPPUNIT_ASSERT(false);
+  typedef ALE::Mesh::topology_type topology_type;
+  typedef topology_type::sieve_type sieve_type;
+  typedef ALE::Mesh::real_section_type real_section_type;
+
+  ALE::Obj<ALE::Mesh> mesh;
+  { // create mesh
+    const int cellDim = 1;
+    const int numCorners = 2;
+    const int spaceDim = 1;
+    const int numVertices = 2;
+    const int numCells = 1;
+    const double vertCoords[] = { -1.0, 1.0};
+    const int cells[] = { 0, 1};
+    CPPUNIT_ASSERT(0 != vertCoords);
+    CPPUNIT_ASSERT(0 != cells);
+
+    mesh = new ALE::Mesh(PETSC_COMM_WORLD, cellDim);
+    ALE::Obj<sieve_type> sieve = new sieve_type(mesh->comm());
+    ALE::Obj<topology_type> topology = new topology_type(mesh->comm());
+
+    const bool interpolate = false;
+    ALE::New::SieveBuilder<sieve_type>::buildTopology(sieve, cellDim, numCells,
+	       const_cast<int*>(cells), numVertices, interpolate, numCorners);
+    sieve->stratify();
+    topology->setPatch(0, sieve);
+    topology->stratify();
+    mesh->setTopology(topology);
+    ALE::New::SieveBuilder<sieve_type>::buildCoordinates(
+		   mesh->getRealSection("coordinates"), spaceDim, vertCoords);
+  } // create mesh
+
+  // Get cells associated with material
+  const ALE::Mesh::int_section_type::patch_type patch = 0;
+  const ALE::Obj<real_section_type>& coordinates = 
+    mesh->getRealSection("coordinates");
+  const ALE::Obj<topology_type>& topology = coordinates->getTopology();
+  const ALE::Obj<topology_type::label_sequence>& cells = 
+    topology->heightStratum(patch, 0);
+
+  ElasticIsotropic3D material;
+  ElasticIsotropic3DData data;
+  delete material._parameters; 
+  material._parameters = new feassemble::ParameterManager(mesh);
+  const int numQuadPts = 2;
+  const int fiberDim = numQuadPts; // number of values in field per cell
+
+  topology_type::label_sequence::iterator cellIter=cells->begin();
+
+  material._parameters->addReal("density");
+  const ALE::Obj<real_section_type>& parameterDensity = 
+    material._parameters->getReal("density");
+  parameterDensity->setFiberDimension(patch, cells, fiberDim);
+  parameterDensity->allocate();
+  double cellData[numQuadPts];
+  cellData[0] = data.parameterData[0];
+  cellData[1] = data.parameterData[3];
+  parameterDensity->updateAdd(patch, *cellIter, cellData);
+
+  material._parameters->addReal("mu");
+  const ALE::Obj<real_section_type>& parameterMu = 
+    material._parameters->getReal("mu");
+  parameterMu->setFiberDimension(patch, cells, fiberDim);
+  parameterMu->allocate();
+  cellData[0] = data.parameterData[1];
+  cellData[1] = data.parameterData[4];
+  parameterMu->updateAdd(patch, *cellIter, cellData);
+
+  material._parameters->addReal("lambda");
+  const ALE::Obj<real_section_type>& parameterLambda = 
+    material._parameters->getReal("lambda");
+  parameterLambda->setFiberDimension(patch, cells, fiberDim);
+  parameterLambda->allocate();
+  cellData[0] = data.parameterData[2];
+  cellData[1] = data.parameterData[5];
+  parameterLambda->updateAdd(patch, *cellIter, cellData);
+
+  material.calcProperties(*cellIter, patch, numQuadPts);
+
+  const double tolerance = 1.0e-06;
+
+  { // check density
+  const double* density = material.density();
+  const double* densityE = data.density;
+  CPPUNIT_ASSERT(0 != density);
+  CPPUNIT_ASSERT(0 != densityE);
+  const double size = numQuadPts;
+  for (int i=0; i < size; ++i)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, density[i]/densityE[i], tolerance);
+  } // check density
+  
+  { // check elasticConsts
+  const double* elasticConsts = material.elasticConsts();
+  const double* elasticConstsE = data.elasticConsts;
+  CPPUNIT_ASSERT(0 != elasticConsts);
+  CPPUNIT_ASSERT(0 != elasticConstsE);
+  const double size = numQuadPts * material.numElasticConsts();
+  for (int i=0; i < size; ++i)
+    if (fabs(elasticConstsE[i]) > tolerance)
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, elasticConsts[i]/elasticConstsE[i], 
+				   tolerance);
+    else
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(elasticConstsE[i], elasticConsts[i],
+				   tolerance);
+  } // check elasticConsts
 } // testCalcProperties
     
 // ----------------------------------------------------------------------

Modified: short/3D/PyLith/trunk/unittests/libtests/materials/TestMaterial.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/materials/TestMaterial.cc	2007-03-20 05:49:59 UTC (rev 6312)
+++ short/3D/PyLith/trunk/unittests/libtests/materials/TestMaterial.cc	2007-03-20 05:52:19 UTC (rev 6313)
@@ -18,7 +18,13 @@
 #include "data/MaterialData.hh" // USES MaterialData
 
 #include "spatialdata/spatialdb/SimpleDB.hh" // USES SimpleDB
+#include "spatialdata/spatialdb/SimpleIOAscii.hh" // USES SimpleIOAscii
+#include "spatialdata/geocoords/CSCart.hh" // USES CSCart
+#include "pylith/feassemble/Quadrature1D.hh" // USES Quadrature1D
+#include "pylith/feassemble/ParameterManager.hh" // USES ParameterManager
 
+#include <petscmesh.h> // USES PETSc Mesh
+
 #include <math.h> // USES assert()
 
 // ----------------------------------------------------------------------
@@ -69,7 +75,128 @@
 void
 pylith::materials::TestMaterial::testInitialize(void)
 { // testInitialize
-  CPPUNIT_ASSERT(false);
+  typedef ALE::Mesh::topology_type topology_type;
+  typedef topology_type::sieve_type sieve_type;
+  typedef ALE::Mesh::real_section_type real_section_type;
+  typedef ALE::Sifter<int, sieve_type::point_type, int> patch_label_type;
+
+  ALE::Obj<ALE::Mesh> mesh;
+  const int materialID = 24;
+  { // create mesh
+    const int cellDim = 1;
+    const int numCorners = 3;
+    const int spaceDim = 1;
+    const int numVertices = 3;
+    const int numCells = 1;
+    const double vertCoords[] = { -1.0, 0.0, 1.0};
+    const int cells[] = { 0, 1, 2 };
+    CPPUNIT_ASSERT(0 != vertCoords);
+    CPPUNIT_ASSERT(0 != cells);
+
+    mesh = new ALE::Mesh(PETSC_COMM_WORLD, cellDim);
+    ALE::Obj<sieve_type> sieve = new sieve_type(mesh->comm());
+    ALE::Obj<topology_type> topology = new topology_type(mesh->comm());
+
+    const bool interpolate = false;
+    ALE::New::SieveBuilder<sieve_type>::buildTopology(sieve, cellDim, numCells,
+	       const_cast<int*>(cells), numVertices, interpolate, numCorners);
+    sieve->stratify();
+    topology->setPatch(0, sieve);
+    topology->stratify();
+    mesh->setTopology(topology);
+    ALE::New::SieveBuilder<sieve_type>::buildCoordinates(
+		   mesh->getRealSection("coordinates"), spaceDim, vertCoords);
+
+  } // create mesh
+
+  { // set material ids
+    const topology_type::patch_type patch = 0;
+    const ALE::Obj<topology_type>& topology = mesh->getTopology();
+    const ALE::Obj<ALE::Mesh::topology_type::label_sequence>& cells = 
+      topology->heightStratum(patch, 0);
+    const ALE::Obj<patch_label_type>& labelMaterials = 
+      topology->createLabel(patch, "material-id");
+    int i = 0;
+    for(ALE::Mesh::topology_type::label_sequence::iterator e_iter = cells->begin();
+	e_iter != cells->end();
+	++e_iter)
+      topology->setValue(labelMaterials, *e_iter, materialID);
+  } // set material ids
+
+  spatialdata::geocoords::CSCart cs;
+  cs.setSpaceDim(1);
+  cs.initialize();
+
+  feassemble::Quadrature1D quadrature;
+  const int cellDim = 1;
+  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 quadPtsRef[] = { -0.577350269, 0.577350269 };
+  const double quadWts[] = { 1.0, 1.0  };
+  quadrature.initialize(basis, basisDeriv, quadPtsRef, quadWts,
+	       cellDim, numCorners, numQuadPts, spaceDim);
+
+  spatialdata::spatialdb::SimpleDB db;
+  spatialdata::spatialdb::SimpleIOAscii iohandler;
+  iohandler.filename("data/matinitialize.spatialdb");
+  db.ioHandler(&iohandler);
+  db.queryType(spatialdata::spatialdb::SimpleDB::NEAREST);
+  
+  ElasticIsotropic3D material;
+  material.db(&db);
+  material.id(materialID);
+  material.label("my_material");
+  material.initialize(mesh, &cs, &quadrature);
+
+  const double densityA = 2000.0;
+  const double vsA = 100.0;
+  const double vpA = 180.0;
+  const double muA = vsA*vsA*densityA;
+  const double lambdaA = vpA*vpA*densityA - 2.0*muA;
+  const double densityB = 3000.0;
+  const double vsB = 200.0;
+  const double vpB = 400.0;
+  const double muB = vsB*vsB*densityB;
+  const double lambdaB = vpB*vpB*densityB - 2.0*muB;
+  const double densityE[] = { densityA, densityB };
+  const double muE[] = { muA, muB };
+  const double lambdaE[] = { lambdaA, lambdaB };
+
+  // Get cells associated with material
+  const ALE::Mesh::int_section_type::patch_type patch = 0;
+  const ALE::Obj<topology_type>& topology = mesh->getTopology();
+  const ALE::Obj<topology_type::label_sequence>& cells = 
+    topology->heightStratum(patch, 0);
+
+  topology_type::label_sequence::iterator cellIter=cells->begin();
+  const double tolerance = 1.0e-06;
+
+  const ALE::Obj<real_section_type>& parameterDensity = 
+    material._parameters->getReal("density");
+  const real_section_type::value_type* densityCell = 
+    parameterDensity->restrict(patch, *cellIter);
+  CPPUNIT_ASSERT(0 != densityCell);
+  for (int i=0; i < numQuadPts; ++i)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, densityCell[i]/densityE[i], tolerance);
+  
+  const ALE::Obj<real_section_type>& parameterMu = 
+    material._parameters->getReal("mu");
+  const real_section_type::value_type* muCell = 
+    parameterMu->restrict(patch, *cellIter);
+  CPPUNIT_ASSERT(0 != muCell);
+  for (int i=0; i < numQuadPts; ++i)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, muCell[i]/muE[i], tolerance);
+  
+  const ALE::Obj<real_section_type>& parameterLambda = 
+    material._parameters->getReal("lambda");
+  const real_section_type::value_type* lambdaCell = 
+    parameterLambda->restrict(patch, *cellIter);
+  CPPUNIT_ASSERT(0 != lambdaCell);
+  for (int i=0; i < numQuadPts; ++i)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, lambdaCell[i]/lambdaE[i], tolerance);
 } // testInitialize
 
 // ----------------------------------------------------------------------

Added: short/3D/PyLith/trunk/unittests/libtests/materials/data/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/materials/data/Makefile.am	2007-03-20 05:49:59 UTC (rev 6312)
+++ short/3D/PyLith/trunk/unittests/libtests/materials/data/Makefile.am	2007-03-20 05:52:19 UTC (rev 6313)
@@ -0,0 +1,30 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+noinst_DATA = \
+	matinitialize.spatialdb
+
+noinst_TMP =
+
+# 'export' the input files by performing a mock install
+export_datadir = $(top_builddir)/unittests/libtests/materials/data
+export-data: $(noinst_DATA)
+	for f in $(noinst_DATA); do $(install_sh_DATA) $(srcdir)/$$f $(export_datadir); done
+
+BUILT_SOURCES = export-data
+
+CLEANFILES = \
+	$(export_datadir)/$(noinst_DATA) \
+	$(export_datadir)/$(noinst_TMP)
+
+
+# End of file 

Added: short/3D/PyLith/trunk/unittests/libtests/materials/data/matinitialize.spatialdb
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/materials/data/matinitialize.spatialdb	2007-03-20 05:49:59 UTC (rev 6312)
+++ short/3D/PyLith/trunk/unittests/libtests/materials/data/matinitialize.spatialdb	2007-03-20 05:52:19 UTC (rev 6313)
@@ -0,0 +1,15 @@
+#SPATIAL.ascii 1
+SimpleDB {
+  num-values = 3
+  value-names =  density vs vp
+  value-units =  kg/m^3  m/s  m/s
+  num-locs = 2
+  data-dim = 1
+  space-dim = 1
+  cs-data = cartesian {
+    to-meters = 1.0
+    space-dim = 1
+  }
+}
+-0.5  2000.0  100.0 180.0
++0.5  3000.0  200.0 400.0



More information about the cig-commits mailing list