[cig-commits] r16417 - in short/3D/PyLith/trunk/playpen: . closure

brad at geodynamics.org brad at geodynamics.org
Sun Mar 14 19:13:41 PDT 2010


Author: brad
Date: 2010-03-14 19:13:41 -0700 (Sun, 14 Mar 2010)
New Revision: 16417

Added:
   short/3D/PyLith/trunk/playpen/closure/
   short/3D/PyLith/trunk/playpen/closure/Makefile.am
   short/3D/PyLith/trunk/playpen/closure/TestClosure.cc
   short/3D/PyLith/trunk/playpen/closure/TestClosure.hh
   short/3D/PyLith/trunk/playpen/closure/test_cubit.cc
   short/3D/PyLith/trunk/playpen/closure/test_lagrit.cc
Log:
Added closure test.

Added: short/3D/PyLith/trunk/playpen/closure/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/playpen/closure/Makefile.am	                        (rev 0)
+++ short/3D/PyLith/trunk/playpen/closure/Makefile.am	2010-03-15 02:13:41 UTC (rev 16417)
@@ -0,0 +1,51 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+bin_PROGRAMS = testlagrit testcubit
+
+testlagrit_SOURCES = \
+	TestClosure.cc \
+	test_lagrit.cc
+
+testcubit_SOURCES = \
+	TestClosure.cc \
+	test_cubit.cc
+
+noinst_HEADERS = \
+	TestClosure.hh
+
+
+AM_CPPFLAGS = \
+	$(PYTHON_EGG_CPPFLAGS) -I$(PYTHON_INCDIR) \
+	$(PETSC_SIEVE_FLAGS) $(PETSC_INCLUDE)
+
+testlagrit_LDFLAGS = \
+	$(AM_LDFLAGS) $(PYTHON_LA_LDFLAGS)
+
+testlagrit_LDADD = \
+	-ldl \
+	$(top_builddir)/libsrc/libpylith.la \
+	-lspatialdata \
+	$(PETSC_LIB) $(PYTHON_BLDLIBRARY) $(PYTHON_LIBS) $(PYTHON_SYSLIBS)
+
+testcubit_LDFLAGS = \
+	$(AM_LDFLAGS) $(PYTHON_LA_LDFLAGS)
+
+testcubit_LDADD = \
+	-ldl \
+	$(top_builddir)/libsrc/libpylith.la \
+	-lspatialdata \
+	$(PETSC_LIB) $(PYTHON_BLDLIBRARY) $(PYTHON_LIBS) $(PYTHON_SYSLIBS) \
+	-lnetcdf_c++ -lnetcdf
+
+
+# End of file 

Added: short/3D/PyLith/trunk/playpen/closure/TestClosure.cc
===================================================================
--- short/3D/PyLith/trunk/playpen/closure/TestClosure.cc	                        (rev 0)
+++ short/3D/PyLith/trunk/playpen/closure/TestClosure.cc	2010-03-15 02:13:41 UTC (rev 16417)
@@ -0,0 +1,177 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "TestClosure.hh" // implementation of class methods
+
+#include "pylith/topology/Field.hh" // USES Field
+#include "pylith/topology/SolutionFields.hh" // USES SolutionFields
+
+#include "pylith/utils/array.hh" // USES double_array
+#include "pylith/utils/EventLogger.hh" // USES EventLogger
+
+#include "pylith/utils/petscerror.h" // USES CHECK_PETSC_ERROR
+#include <cassert> // USES assert()
+#include <stdexcept> // USES std::runtime_error
+
+#define SEPARATE_FIELDS
+
+// ----------------------------------------------------------------------
+typedef pylith::topology::Mesh::SieveMesh SieveMesh;
+typedef pylith::topology::Mesh::RealSection RealSection;
+
+// ----------------------------------------------------------------------
+const int pylith::playpen::TestClosure::_spaceDim = 3;
+
+// ----------------------------------------------------------------------
+// Constructor
+pylith::playpen::TestClosure::TestClosure(void) :
+  _niterations(1000)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor
+pylith::playpen::TestClosure::~TestClosure(void)
+{ // destructor
+} // destructor
+  
+// ----------------------------------------------------------------------
+// Set number of iterations.
+void
+pylith::playpen::TestClosure::iterations(const long value) {
+  _niterations = value;
+}
+
+// ----------------------------------------------------------------------
+// Test restrictClosure().
+void
+pylith::playpen::TestClosure::testRestrictClosure(const pylith::topology::Mesh& mesh)
+{ // testRestrictClosure
+
+  const int spaceDim = _spaceDim;
+
+  // Create fields
+  pylith::topology::SolutionFields fields(mesh);
+  fields.add("field A", "field_A");
+  fields.add("field B", "field_B");
+  topology::Field<topology::Mesh>& fieldA = fields.get("field A");
+  fieldA.newSection(topology::FieldBase::VERTICES_FIELD, spaceDim);
+  fieldA.allocate();
+  fieldA.zero();
+  fields.copyLayout("field A");
+
+  // Setup timing
+  utils::EventLogger logger;
+  logger.className("TestClosure");
+  logger.initialize();
+  const int stage = logger.registerStage("Test Closure");
+  const int closureEvent = logger.registerEvent("closure");
+  
+  // Setup stuff for doing closure
+  const ALE::Obj<SieveMesh>& sieveMesh = mesh.sieveMesh();
+  assert(!sieveMesh.isNull());
+  const ALE::Obj<SieveMesh::label_sequence>& cells =
+    sieveMesh->heightStratum(0);
+  assert(!cells.isNull());
+  const SieveMesh::label_sequence::iterator cellsBegin = cells->begin();
+  const SieveMesh::label_sequence::iterator cellsEnd = cells->end();
+
+  const ALE::Obj<SieveMesh::sieve_type>& sieve = sieveMesh->getSieve();
+  assert(!sieve.isNull());
+  typedef ALE::SieveAlg<SieveMesh> SieveAlg;
+  ALE::ISieveVisitor::NConeRetriever<SieveMesh::sieve_type> ncV(*sieve,
+      (size_t) pow(sieve->getMaxConeSize(), std::max(0, sieveMesh->depth())));
+  ncV.clear();
+  ALE::ISieveTraversal<SieveMesh::sieve_type>::orientedClosure(*sieve,
+							       *cellsBegin, ncV);
+  const int coneSize = ncV.getSize();
+
+  // Setup visitors
+  double_array coordsCell(coneSize*spaceDim);
+  const ALE::Obj<RealSection>& coordsSection = 
+    sieveMesh->getRealSection("coordinates");
+  assert(!coordsSection.isNull());
+  topology::Mesh::RestrictVisitor coordsVisitor(*coordsSection,
+						coordsCell.size(),
+						&coordsCell[0]);
+  double_array fieldACell(coneSize*spaceDim);
+  const ALE::Obj<RealSection>& fieldASection = fields.get("field A").section();
+  assert(!fieldASection.isNull());
+  topology::Mesh::RestrictVisitor fieldAVisitor(*fieldASection,
+						fieldACell.size(),
+						&fieldACell[0]);
+  double_array fieldBCell(coneSize*spaceDim);
+  const ALE::Obj<RealSection>& fieldBSection = fields.get("field B").section();
+  assert(!fieldBSection.isNull());
+  topology::Mesh::RestrictVisitor fieldBVisitor(*fieldBSection,
+						fieldBCell.size(),
+						&fieldBCell[0]);
+  
+  double_array tmpCell(coneSize*spaceDim);
+
+  ALE::LogStagePush(stage);
+  logger.eventBegin(closureEvent);
+
+  long i = 0;
+  const long niterations = _niterations;
+  for (long iter=0; iter < niterations; ++iter)
+    for (SieveMesh::label_sequence::iterator c_iter=cellsBegin;
+	 c_iter != cellsEnd;
+	 ++c_iter) {
+#if defined(SEPARATE_FIELDS)
+      coordsVisitor.clear();
+      sieveMesh->restrictClosure(*c_iter, coordsVisitor);
+      
+      fieldAVisitor.clear();
+      sieveMesh->restrictClosure(*c_iter, fieldAVisitor);
+      
+      fieldBVisitor.clear();
+      sieveMesh->restrictClosure(*c_iter, fieldBVisitor);
+      
+      ++i;
+#else
+#endif
+      
+      // Perform trivial operation on fields
+      tmpCell = fieldACell + fieldBCell + coordsCell;
+    } // for
+
+  logger.eventEnd(closureEvent);
+  ALE::LogStagePop(stage);
+
+  // Print stats
+  PetscErrorCode ierr = 0;
+  StageLog stageLog = 0;
+  EventPerfLog eventLog = 0;
+  ierr = PetscLogGetStageLog(&stageLog); CHECK_PETSC_ERROR(ierr);
+  ierr = StageLogGetEventPerfLog(stageLog, stage, &eventLog); CHECK_PETSC_ERROR(ierr);
+  EventPerfInfo eventInfo = eventLog->eventInfo[closureEvent];
+  assert(1 == eventInfo.count);
+  assert(i == cells->size() * _niterations);
+
+#if defined(SEPARATE_FIELDS)
+  const long nclosures = (1 + 2) * cells->size() * _niterations;
+#else
+  const long nclosures = (1 + 1) * cells->size() * _niterations;
+#endif
+  std::cout << "Number of cells: " << cells->size() << std::endl;
+  std::cout << "Number of loops: " << _niterations << std::endl;
+  std::cout << "Total time: " << eventInfo.time << std::endl;
+  std::cout << "Average time per closure (" << nclosures << ") : "
+	    << eventInfo.time/nclosures << std::endl;
+
+} // testRestrictClosure
+
+
+// End of file 

Added: short/3D/PyLith/trunk/playpen/closure/TestClosure.hh
===================================================================
--- short/3D/PyLith/trunk/playpen/closure/TestClosure.hh	                        (rev 0)
+++ short/3D/PyLith/trunk/playpen/closure/TestClosure.hh	2010-03-15 02:13:41 UTC (rev 16417)
@@ -0,0 +1,73 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file playpen/closure/TestClosure.hh
+ *
+ */
+
+#if !defined(pylith_playpen_testclosure_hh)
+#define pylith_playpen_testclosure_hh
+
+// Include directives ---------------------------------------------------
+namespace pylith {
+  namespace playpen {
+    class TestClosure;
+  } // playpen
+} // pylith
+
+#include "pylith/topology/topologyfwd.hh"
+
+// ElasticityExplicitTet4 ---------------------------------------------------
+class pylith::playpen::TestClosure
+{ // TestClosure
+
+// PUBLIC MEMBERS ///////////////////////////////////////////////////////
+public :
+
+  /// Constructor
+  TestClosure(void);
+
+  /// Destructor
+  ~TestClosure(void);
+
+  /** Set number of iterations.
+   *
+   * @param value Number of iterations.
+   */
+  void iterations(const long value);
+
+  /** Test restrictClosure().
+   *
+   * @param mesh Finite-element mesh.
+   */
+  void testRestrictClosure(const pylith::topology::Mesh& mesh);
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+  long _niterations; ///< Number of iterations.
+
+  static const int _spaceDim; ///< Space dimension.
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+  TestClosure(const TestClosure&); ///< Not implemented
+  const TestClosure& operator=(const TestClosure&); ///< Not implemented.
+
+}; // TestClosure
+
+#endif // pylith_playpen_testclosure_hh
+
+
+// End of file 

Added: short/3D/PyLith/trunk/playpen/closure/test_cubit.cc
===================================================================
--- short/3D/PyLith/trunk/playpen/closure/test_cubit.cc	                        (rev 0)
+++ short/3D/PyLith/trunk/playpen/closure/test_cubit.cc	2010-03-15 02:13:41 UTC (rev 16417)
@@ -0,0 +1,69 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include "petsc.h"
+#include <Python.h>
+
+#include "TestClosure.hh"
+
+#include "pylith/meshio/MeshIOCubit.hh"
+#include "pylith/topology/Mesh.hh"
+
+#include "spatialdata/geocoords/CSCart.hh"
+
+#include <stdlib.h> // USES abort()
+
+int
+main(int argc,
+     char* argv[])
+{ // main
+  if (2 != argc) {
+    std::cerr << "Usage: test_cubit filename" << std::endl;
+    return 1;
+  } // if
+
+  const char* filenameCubit = argv[1];
+
+  try {
+    // Initialize PETSc
+    PetscErrorCode err = PetscInitialize(&argc, &argv,
+					 PETSC_NULL, PETSC_NULL);
+    CHKERRQ(err);
+    err = PetscLogBegin(); CHKERRQ(err);
+
+    // Initialize Python.
+    Py_Initialize();
+
+    pylith::meshio::MeshIOCubit reader;
+    reader.filename(filenameCubit);
+    
+    pylith::topology::Mesh mesh;
+    spatialdata::geocoords::CSCart cs;
+    mesh.coordsys(&cs);
+    reader.read(&mesh);
+
+    pylith::playpen::TestClosure test;
+    test.testRestrictClosure(mesh);
+
+    // Finalize Python
+    Py_Finalize();
+
+    // Finalize PETSc
+    err = PetscFinalize(); CHKERRQ(err);
+  } catch (...) {
+    abort();
+  } // catch
+
+  return 0;
+} // main
+
+// End of file

Added: short/3D/PyLith/trunk/playpen/closure/test_lagrit.cc
===================================================================
--- short/3D/PyLith/trunk/playpen/closure/test_lagrit.cc	                        (rev 0)
+++ short/3D/PyLith/trunk/playpen/closure/test_lagrit.cc	2010-03-15 02:13:41 UTC (rev 16417)
@@ -0,0 +1,71 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include "petsc.h"
+#include <Python.h>
+
+#include "TestClosure.hh"
+
+#include "pylith/meshio/MeshIOLagrit.hh"
+#include "pylith/topology/Mesh.hh"
+
+#include "spatialdata/geocoords/CSCart.hh"
+
+#include <stdlib.h> // USES abort()
+
+int
+main(int argc,
+     char* argv[])
+{ // main
+  if (3 != argc) {
+    std::cerr << "Usage: test_lagrit filenameGMV filenamePset" << std::endl;
+    return 1;
+  } // if
+
+  const char* filenameGmv = argv[1];
+  const char* filenamePset = argv[2];
+
+  try {
+    // Initialize PETSc
+    PetscErrorCode err = PetscInitialize(&argc, &argv,
+					 PETSC_NULL, PETSC_NULL);
+    CHKERRQ(err);
+    err = PetscLogBegin(); CHKERRQ(err);
+
+    // Initialize Python.
+    Py_Initialize();
+
+    pylith::meshio::MeshIOLagrit reader;
+    reader.filenameGmv(filenameGmv);
+    reader.filenamePset(filenamePset);
+    
+    pylith::topology::Mesh mesh;
+    spatialdata::geocoords::CSCart cs;
+    mesh.coordsys(&cs);
+    reader.read(&mesh);
+
+    pylith::playpen::TestClosure test;
+    test.testRestrictClosure(mesh);
+
+    // Finalize Python
+    Py_Finalize();
+
+    // Finalize PETSc
+    err = PetscFinalize(); CHKERRQ(err);
+  } catch (...) {
+    abort();
+  } // catch
+
+  return 0;
+} // main
+
+// End of file



More information about the CIG-COMMITS mailing list