[cig-commits] [commit] knepley/upgrade-petsc-interface: Minor cleanup of optimizeClosure(). (a0bd2c3)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Wed Nov 27 10:07:59 PST 2013


Repository : ssh://geoshell/pylith

On branch  : knepley/upgrade-petsc-interface
Link       : https://github.com/geodynamics/pylith/compare/5b37d1ea08e0a69bd51ffc02ad5050e32f819f3d...a0bd2c33efdb067cee19f14bac8d4aa4e31c8c8e

>---------------------------------------------------------------

commit a0bd2c33efdb067cee19f14bac8d4aa4e31c8c8e
Author: Brad Aagaard <baagaard at usgs.gov>
Date:   Wed Nov 27 10:10:55 2013 -0800

    Minor cleanup of optimizeClosure().
    
    Create static version of optimizeClosure() since index for closure
    depends only on section and dm.
    
    Removed non-static optimizeClosure method from CoordsVisitor, since it
    is easy to call static version. Keep non-static optimizeClosure method
    for VecVisitorMesh because it needs field, which is often not available
    in initialize() methods. We should fix this when we setup multiple
    fields for multi-physics.


>---------------------------------------------------------------

a0bd2c33efdb067cee19f14bac8d4aa4e31c8c8e
 libsrc/pylith/bc/AbsorbingDampers.cc               |  8 ++--
 libsrc/pylith/bc/Neumann.cc                        |  8 ++--
 libsrc/pylith/faults/FaultCohesiveDyn.cc           |  3 +-
 libsrc/pylith/faults/FaultCohesiveLagrange.cc      |  6 ++-
 libsrc/pylith/feassemble/ElasticityExplicit.cc     |  2 -
 .../feassemble/ElasticityExplicitLgDeform.cc       |  2 -
 libsrc/pylith/feassemble/ElasticityExplicitTet4.cc |  9 ++---
 libsrc/pylith/feassemble/ElasticityExplicitTri3.cc |  2 -
 libsrc/pylith/feassemble/ElasticityImplicit.cc     |  2 -
 .../feassemble/ElasticityImplicitLgDeform.cc       |  2 -
 libsrc/pylith/feassemble/IntegratorElasticity.cc   |  5 ++-
 .../feassemble/IntegratorElasticityLgDeform.cc     |  2 -
 libsrc/pylith/materials/ElasticMaterial.cc         |  3 --
 libsrc/pylith/materials/Material.cc                |  4 +-
 libsrc/pylith/topology/CoordsVisitor.hh            | 11 ++++--
 libsrc/pylith/topology/CoordsVisitor.icc           | 33 ++++++++++------
 libsrc/pylith/topology/VisitorMesh.hh              | 17 ++++++--
 libsrc/pylith/topology/VisitorMesh.icc             | 46 ++++++++++++++++------
 18 files changed, 95 insertions(+), 70 deletions(-)

diff --git a/libsrc/pylith/bc/AbsorbingDampers.cc b/libsrc/pylith/bc/AbsorbingDampers.cc
index 0f8ba26..1011de1 100644
--- a/libsrc/pylith/bc/AbsorbingDampers.cc
+++ b/libsrc/pylith/bc/AbsorbingDampers.cc
@@ -147,7 +147,6 @@ pylith::bc::AbsorbingDampers::initialize(const topology::Mesh& mesh,
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmSubMesh);
-  coordsVisitor.optimizeClosure();
 
   assert(_normalizer);
   const PylithScalar lengthScale = _normalizer->lengthScale();
@@ -160,6 +159,9 @@ pylith::bc::AbsorbingDampers::initialize(const topology::Mesh& mesh,
   // Compute quadrature information
   _quadrature->initializeGeometry();
 
+  // Optimize coordinate retrieval in closure
+  topology::CoordsVisitor::optimizeClosure(dmSubMesh);
+
   PetscScalar* dampingConstsArray = dampingConstsVisitor.localArray();
 
   for(PetscInt c = cStart; c < cEnd; ++c) {
@@ -276,7 +278,6 @@ pylith::bc::AbsorbingDampers::integrateResidual(const topology::Field& residual,
   
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmSubMesh);
-  coordsVisitor.optimizeClosure();
 
   // Get 'surface' cells (1 dimension lower than top-level cells)
   topology::Stratum cellsStratum(dmSubMesh, topology::Stratum::HEIGHT, 1);
@@ -413,7 +414,6 @@ pylith::bc::AbsorbingDampers::integrateResidualLumped(const topology::Field& res
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmSubMesh);
-  coordsVisitor.optimizeClosure();
 
   _logger->eventEnd(setupEvent);
 #if !defined(DETAILED_EVENT_LOGGING)
@@ -547,7 +547,6 @@ pylith::bc::AbsorbingDampers::integrateJacobian(topology::Jacobian* jacobian,
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmSubMesh);
-  coordsVisitor.optimizeClosure();
 
   _logger->eventEnd(setupEvent);
 #if !defined(DETAILED_EVENT_LOGGING)
@@ -679,7 +678,6 @@ pylith::bc::AbsorbingDampers::integrateJacobian(topology::Field* jacobian,
   
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmSubMesh);
-  coordsVisitor.optimizeClosure();
 
   _logger->eventEnd(setupEvent);
 #if !defined(DETAILED_EVENT_LOGGING)
diff --git a/libsrc/pylith/bc/Neumann.cc b/libsrc/pylith/bc/Neumann.cc
index 87afdfe..3db9aa6 100644
--- a/libsrc/pylith/bc/Neumann.cc
+++ b/libsrc/pylith/bc/Neumann.cc
@@ -79,6 +79,11 @@ pylith::bc::Neumann::initialize(const topology::Mesh& mesh,
   _queryDatabases();
   _paramsLocalToGlobal(upDir);
 
+  // Optimize coordinate retrieval in closure
+  assert(_boundaryMesh);
+  const PetscDM dmSubMesh = _boundaryMesh->dmMesh();assert(dmSubMesh);
+  topology::CoordsVisitor::optimizeClosure(dmSubMesh);
+
   PYLITH_METHOD_END;
 } // initialize
 
@@ -125,7 +130,6 @@ pylith::bc::Neumann::integrateResidual(const topology::Field& residual,
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmSubMesh);
-  coordsVisitor.optimizeClosure();
 
   // Loop over faces and integrate contribution from each face
   for(PetscInt c = cStart; c < cEnd; ++c) {
@@ -419,7 +423,6 @@ pylith::bc::Neumann::_queryDB(const char* name,
   // Get coordinates
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmSubMesh);
-  coordsVisitor.optimizeClosure();
 
   const spatialdata::geocoords::CoordSys* cs = _boundaryMesh->coordsys();
   assert(cs);
@@ -508,7 +511,6 @@ void
   // Get coordinates.
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmSubMesh);
-  coordsVisitor.optimizeClosure();
 
   // Get sections
   scalar_array tmpLocal(spaceDim);
diff --git a/libsrc/pylith/faults/FaultCohesiveDyn.cc b/libsrc/pylith/faults/FaultCohesiveDyn.cc
index bd1a385..05f6a71 100644
--- a/libsrc/pylith/faults/FaultCohesiveDyn.cc
+++ b/libsrc/pylith/faults/FaultCohesiveDyn.cc
@@ -549,7 +549,6 @@ pylith::faults::FaultCohesiveDyn::constrainSolnSpace(topology::SolutionFields* c
   scalar_array dLagrangeTpdtVertex(spaceDim);
   topology::VecVisitorMesh dLagrangeVisitor(_fields->get("sensitivity dLagrange"));
   PetscScalar* dLagrangeArray = dLagrangeVisitor.localArray();
-  dLagrangeVisitor.optimizeClosure();
 
   constrainSolnSpace_fn_type constrainSolnSpaceFn;
   switch (spaceDim) { // switch
@@ -1609,6 +1608,7 @@ pylith::faults::FaultCohesiveDyn::_sensitivitySetup(const topology::Jacobian& ja
     _fields->add("sensitivity dLagrange", "sensitivity_dlagrange");
     topology::Field& dLagrange = _fields->get("sensitivity dLagrange");
     dLagrange.cloneSection(solution);
+    topology::VecVisitorMesh::optimizeClosure(dLagrange);
   } // if
   topology::Field& dLagrange = _fields->get("sensitivity dLagrange");
   dLagrange.zeroAll();
@@ -1819,7 +1819,6 @@ pylith::faults::FaultCohesiveDyn::_sensitivityReformResidual(const bool negative
   // Get sections
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(faultDMMesh);
-  coordsVisitor.optimizeClosure();
 
   scalar_array dLagrangeCell(numBasis*spaceDim);
   topology::VecVisitorMesh dLagrangeVisitor(_fields->get("sensitivity dLagrange"));
diff --git a/libsrc/pylith/faults/FaultCohesiveLagrange.cc b/libsrc/pylith/faults/FaultCohesiveLagrange.cc
index d1f895c..72761ee 100644
--- a/libsrc/pylith/faults/FaultCohesiveLagrange.cc
+++ b/libsrc/pylith/faults/FaultCohesiveLagrange.cc
@@ -104,6 +104,10 @@ pylith::faults::FaultCohesiveLagrange::initialize(const topology::Mesh& mesh,
   
   topology::MeshOps::checkTopology(*_faultMesh);
 
+  // Optimize coordinate retrieval in closure
+  PetscDM faultDMMesh = _faultMesh->dmMesh();assert(faultDMMesh);
+  topology::CoordsVisitor::optimizeClosure(faultDMMesh);
+
   _initializeCohesiveInfo(mesh);
 
   delete _fields; _fields = new topology::Fields(*_faultMesh);assert(_fields);
@@ -1356,7 +1360,6 @@ pylith::faults::FaultCohesiveLagrange::_calcOrientation(const PylithScalar upDir
   // Get section containing coordinates of vertices
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(faultDMMesh);
-  coordsVisitor.optimizeClosure();
 
   // Loop over cohesive cells, computing orientation weighted by
   // jacobian at constraint vertices
@@ -1621,7 +1624,6 @@ pylith::faults::FaultCohesiveLagrange::_calcArea(void)
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(faultDMMesh);
-  coordsVisitor.optimizeClosure();
 
   // Loop over cells in fault mesh, compute area
   for(PetscInt c = cStart; c < cEnd; ++c) {
diff --git a/libsrc/pylith/feassemble/ElasticityExplicit.cc b/libsrc/pylith/feassemble/ElasticityExplicit.cc
index c5bbd93..5f9a400 100644
--- a/libsrc/pylith/feassemble/ElasticityExplicit.cc
+++ b/libsrc/pylith/feassemble/ElasticityExplicit.cc
@@ -225,7 +225,6 @@ pylith::feassemble::ElasticityExplicit::integrateResidual(const topology::Field&
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   assert(_normalizer);
   const PylithScalar lengthScale = _normalizer->lengthScale();
@@ -448,7 +447,6 @@ pylith::feassemble::ElasticityExplicit::integrateJacobian(topology::Field* jacob
 
   scalar_array coordsCell(numBasis*spaceDim); // :KLUDGE: numBasis to numCorners after switching to higher order
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   _logger->eventEnd(setupEvent);
 #if !defined(DETAILED_EVENT_LOGGING)
diff --git a/libsrc/pylith/feassemble/ElasticityExplicitLgDeform.cc b/libsrc/pylith/feassemble/ElasticityExplicitLgDeform.cc
index 1e69d99..8116c9d 100644
--- a/libsrc/pylith/feassemble/ElasticityExplicitLgDeform.cc
+++ b/libsrc/pylith/feassemble/ElasticityExplicitLgDeform.cc
@@ -220,7 +220,6 @@ pylith::feassemble::ElasticityExplicitLgDeform::integrateResidual(const topology
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   assert(_normalizer);
   const PylithScalar lengthScale = _normalizer->lengthScale();
@@ -401,7 +400,6 @@ pylith::feassemble::ElasticityExplicitLgDeform::integrateJacobian(topology::Fiel
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   _logger->eventEnd(setupEvent);
   _logger->eventBegin(computeEvent);
diff --git a/libsrc/pylith/feassemble/ElasticityExplicitTet4.cc b/libsrc/pylith/feassemble/ElasticityExplicitTet4.cc
index 694316b..63052d9 100644
--- a/libsrc/pylith/feassemble/ElasticityExplicitTet4.cc
+++ b/libsrc/pylith/feassemble/ElasticityExplicitTet4.cc
@@ -135,10 +135,9 @@ pylith::feassemble::ElasticityExplicitTet4::normViscosity(const PylithScalar vis
 // ----------------------------------------------------------------------
 // Integrate constributions to residual term (r) for operator.
 void
-pylith::feassemble::ElasticityExplicitTet4::integrateResidual(
-        const topology::Field& residual,
-        const PylithScalar t,
-        topology::SolutionFields* const fields)
+pylith::feassemble::ElasticityExplicitTet4::integrateResidual(const topology::Field& residual,
+							      const PylithScalar t,
+							      topology::SolutionFields* const fields)
 { // integrateResidual
   PYLITH_METHOD_BEGIN;
   
@@ -217,7 +216,6 @@ pylith::feassemble::ElasticityExplicitTet4::integrateResidual(
 
   scalar_array coordsCell(numCorners*spaceDim);
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   assert(_normalizer);
   const PylithScalar lengthScale = _normalizer->lengthScale();
@@ -495,7 +493,6 @@ pylith::feassemble::ElasticityExplicitTet4::integrateJacobian(topology::Field* j
 
   scalar_array coordsCell(numCorners*spaceDim);
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   _logger->eventEnd(setupEvent);
 #if !defined(DETAILED_EVENT_LOGGING)
diff --git a/libsrc/pylith/feassemble/ElasticityExplicitTri3.cc b/libsrc/pylith/feassemble/ElasticityExplicitTri3.cc
index 71a8bb2..12c759d 100644
--- a/libsrc/pylith/feassemble/ElasticityExplicitTri3.cc
+++ b/libsrc/pylith/feassemble/ElasticityExplicitTri3.cc
@@ -216,7 +216,6 @@ pylith::feassemble::ElasticityExplicitTri3::integrateResidual(const topology::Fi
 
   scalar_array coordsCell(numCorners*spaceDim);
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   assert(_normalizer);
   const PylithScalar lengthScale = _normalizer->lengthScale();
@@ -457,7 +456,6 @@ pylith::feassemble::ElasticityExplicitTri3::integrateJacobian(
 
   scalar_array coordsCell(numCorners*spaceDim);
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   _logger->eventEnd(setupEvent);
 #if !defined(DETAILED_EVENT_LOGGING)
diff --git a/libsrc/pylith/feassemble/ElasticityImplicit.cc b/libsrc/pylith/feassemble/ElasticityImplicit.cc
index 031262a..20a9936 100644
--- a/libsrc/pylith/feassemble/ElasticityImplicit.cc
+++ b/libsrc/pylith/feassemble/ElasticityImplicit.cc
@@ -184,7 +184,6 @@ pylith::feassemble::ElasticityImplicit::integrateResidual(const topology::Field&
 
   scalar_array coordsCell(numBasis*spaceDim); // :KLUDGE: numBasis to numCorners after switching to higher order
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   assert(_normalizer);
   const PylithScalar lengthScale = _normalizer->lengthScale();
@@ -354,7 +353,6 @@ pylith::feassemble::ElasticityImplicit::integrateJacobian(topology::Jacobian* ja
 
   scalar_array coordsCell(numBasis*spaceDim); // :KLUDGE: numBasis to numCorners after switching to higher order
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   // Get sparse matrix
   const PetscMat jacobianMat = jacobian->matrix();assert(jacobianMat);
diff --git a/libsrc/pylith/feassemble/ElasticityImplicitLgDeform.cc b/libsrc/pylith/feassemble/ElasticityImplicitLgDeform.cc
index bd0a6f8..8ef5fcd 100644
--- a/libsrc/pylith/feassemble/ElasticityImplicitLgDeform.cc
+++ b/libsrc/pylith/feassemble/ElasticityImplicitLgDeform.cc
@@ -190,7 +190,6 @@ pylith::feassemble::ElasticityImplicitLgDeform::integrateResidual(
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   assert(_normalizer);
   const PylithScalar lengthScale = _normalizer->lengthScale();
@@ -367,7 +366,6 @@ pylith::feassemble::ElasticityImplicitLgDeform::integrateJacobian(topology::Jaco
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   // Get sparse matrix
   const PetscMat jacobianMat = jacobian->matrix();assert(jacobianMat);
diff --git a/libsrc/pylith/feassemble/IntegratorElasticity.cc b/libsrc/pylith/feassemble/IntegratorElasticity.cc
index 04dac40..aca4ae9 100644
--- a/libsrc/pylith/feassemble/IntegratorElasticity.cc
+++ b/libsrc/pylith/feassemble/IntegratorElasticity.cc
@@ -121,6 +121,9 @@ pylith::feassemble::IntegratorElasticity::initialize(const topology::Mesh& mesh)
   // Compute geometry for quadrature operations.
   _quadrature->initializeGeometry();
 
+  // Optimize coordinate retrieval in closure
+  topology::CoordsVisitor::optimizeClosure(dmMesh);
+
   // Initialize material.
   _material->initialize(mesh, _quadrature);
   _isJacobianSymmetric = _material->isJacobianSymmetric();
@@ -203,7 +206,6 @@ pylith::feassemble::IntegratorElasticity::updateStateVars(const PylithScalar t,
 
   scalar_array coordsCell(numCorners*spaceDim);
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   // Loop over cells
   for(PetscInt c = 0; c < numCells; ++c) {
@@ -540,7 +542,6 @@ pylith::feassemble::IntegratorElasticity::_calcStrainStressField(topology::Field
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   // Loop over cells
   for(PetscInt c = 0; c < numCells; ++c) {
diff --git a/libsrc/pylith/feassemble/IntegratorElasticityLgDeform.cc b/libsrc/pylith/feassemble/IntegratorElasticityLgDeform.cc
index 313c432..c0198a0 100644
--- a/libsrc/pylith/feassemble/IntegratorElasticityLgDeform.cc
+++ b/libsrc/pylith/feassemble/IntegratorElasticityLgDeform.cc
@@ -114,7 +114,6 @@ pylith::feassemble::IntegratorElasticityLgDeform::updateStateVars(const PylithSc
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   // Loop over cells
   for (PetscInt c = 0; c < numCells; ++c) {
@@ -197,7 +196,6 @@ pylith::feassemble::IntegratorElasticityLgDeform::_calcStrainStressField(topolog
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   // Loop over cells
   for (PetscInt c = 0; c < numCells; ++c) {
diff --git a/libsrc/pylith/materials/ElasticMaterial.cc b/libsrc/pylith/materials/ElasticMaterial.cc
index e35d3b2..bc374c8 100644
--- a/libsrc/pylith/materials/ElasticMaterial.cc
+++ b/libsrc/pylith/materials/ElasticMaterial.cc
@@ -417,7 +417,6 @@ pylith::materials::ElasticMaterial::stableTimeStepExplicit(const topology::Mesh&
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   PylithScalar dtStable = pylith::PYLITH_MAXSCALAR;
   scalar_array dtStableCell(numQuadPts);
@@ -577,7 +576,6 @@ pylith::materials::ElasticMaterial::_initializeInitialStress(const topology::Mes
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   // Create arrays for querying
   const int tensorSize = _tensorSize;
@@ -707,7 +705,6 @@ pylith::materials::ElasticMaterial::_initializeInitialStrain(const topology::Mes
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
 
   // Create arrays for querying
   const int tensorSize = _tensorSize;
diff --git a/libsrc/pylith/materials/Material.cc b/libsrc/pylith/materials/Material.cc
index fe0bcd6..443f2ba 100644
--- a/libsrc/pylith/materials/Material.cc
+++ b/libsrc/pylith/materials/Material.cc
@@ -149,7 +149,9 @@ pylith::materials::Material::initialize(const topology::Mesh& mesh,
 
   scalar_array coordsCell(numBasis*spaceDim); // :KULDGE: Update numBasis to numCorners after implementing higher order
   topology::CoordsVisitor coordsVisitor(dmMesh);
-  coordsVisitor.optimizeClosure();
+
+  // Optimize coordinate retrieval in closure  
+  topology::CoordsVisitor::optimizeClosure(dmMesh);
 
   // Create arrays for querying.
   const int numDBProperties = _metadata.numDBProperties();
diff --git a/libsrc/pylith/topology/CoordsVisitor.hh b/libsrc/pylith/topology/CoordsVisitor.hh
index 7136dd7..84da354 100644
--- a/libsrc/pylith/topology/CoordsVisitor.hh
+++ b/libsrc/pylith/topology/CoordsVisitor.hh
@@ -76,10 +76,6 @@ public :
    */
   PetscInt sectionOffset(const PetscInt point) const;
 
-  /** Optimize the closure operator by using extra storage.
-   */
-  void optimizeClosure();
-
   /** Get coordinates array associated with closure.
    *
    * @pre Must be followed by call to restoreClosure().
@@ -112,6 +108,13 @@ public :
 		      PetscInt* coordsSize,
 		      const PetscInt cell) const;
 
+  /** Optimize the closure operator by creating index for closures.
+   *
+   * @param dmMesh PETSc DM to optimize closure on coordinates field.
+   */
+  static
+  void optimizeClosure(PetscDM dmMesh);
+
 // PRIVATE MEMBERS //////////////////////////////////////////////////////
 private :
 
diff --git a/libsrc/pylith/topology/CoordsVisitor.icc b/libsrc/pylith/topology/CoordsVisitor.icc
index 3f9b13d..46a06b8 100644
--- a/libsrc/pylith/topology/CoordsVisitor.icc
+++ b/libsrc/pylith/topology/CoordsVisitor.icc
@@ -107,19 +107,6 @@ pylith::topology::CoordsVisitor::sectionOffset(const PetscInt point) const
 } // sectionOffset
 
 // ----------------------------------------------------------------------
-// Optimize the closure operation.
-inline
-void
-pylith::topology::CoordsVisitor::optimizeClosure()
-{ // optimizeClosure
-  PetscSection   clSection;
-  PetscErrorCode err;
-
-  err = PetscSectionGetClosureIndex(_section, (PetscObject) _dm, &clSection, NULL);PYLITH_CHECK_ERROR(err);
-  if (!clSection) {err = DMPlexCreateClosureIndex(_dm, _section);PYLITH_CHECK_ERROR(err);}
-} // optimizeClosure
-
-// ----------------------------------------------------------------------
 // Get coordinates array associated with closure.
 inline
 void
@@ -163,6 +150,26 @@ pylith::topology::CoordsVisitor::restoreClosure(PetscScalar** coordsCell,
   PetscErrorCode err = DMPlexVecRestoreClosure(_dm, _section, _localVec, cell, coordsSize, coordsCell);PYLITH_CHECK_ERROR(err);
 } // restoreClosure
 
+// ----------------------------------------------------------------------
+// Optimize the closure operation.
+inline
+void
+pylith::topology::CoordsVisitor::optimizeClosure(PetscDM dmMesh)
+{ // optimizeClosure
+  assert(dmMesh);
+
+  PetscErrorCode err;
+  PetscSection fieldSection = NULL;
+  err = DMPlexGetCoordinateSection(dmMesh, &fieldSection);PYLITH_CHECK_ERROR(err);assert(fieldSection);
+
+  PetscSection indexSection = NULL;
+  err = PetscSectionGetClosureIndex(fieldSection, (PetscObject) dmMesh, &indexSection, NULL);PYLITH_CHECK_ERROR(err);
+  if (!indexSection) {
+    err = DMPlexCreateClosureIndex(dmMesh, fieldSection);PYLITH_CHECK_ERROR(err);
+  } // if
+
+} // optimizeClosure
+
 #endif
 
 
diff --git a/libsrc/pylith/topology/VisitorMesh.hh b/libsrc/pylith/topology/VisitorMesh.hh
index c71c776..06da6e8 100644
--- a/libsrc/pylith/topology/VisitorMesh.hh
+++ b/libsrc/pylith/topology/VisitorMesh.hh
@@ -100,10 +100,6 @@ public :
    */
   PetscInt sectionOffset(const PetscInt point) const;
 
-  /** Optimize the closure operator by using extra storage.
-   */
-  void optimizeClosure();
-
   /** Get array of values associated with closure.
    *
    * @pre Must be followed by call to restoreClosure().
@@ -148,6 +144,19 @@ public :
 		  const PetscInt cell,
 		  const InsertMode mode) const;
 
+  /** Optimize the closure operator by creating index for closures.
+   *
+   * :TODO: Remove this method. Call static version when setting up fields.
+   */
+  void optimizeClosure(void);
+
+  /** Optimize the closure operator by creating index for closures.
+   *
+   * @param field Field to optimize closure for.
+   */
+  static
+  void optimizeClosure(const Field& field);
+
 // PRIVATE MEMBERS //////////////////////////////////////////////////////
 private :
 
diff --git a/libsrc/pylith/topology/VisitorMesh.icc b/libsrc/pylith/topology/VisitorMesh.icc
index 429c319..9024563 100644
--- a/libsrc/pylith/topology/VisitorMesh.icc
+++ b/libsrc/pylith/topology/VisitorMesh.icc
@@ -139,19 +139,6 @@ pylith::topology::VecVisitorMesh::sectionOffset(const PetscInt point) const
 } // sectionOffset
 
 // ----------------------------------------------------------------------
-// Optimize the closure operation.
-inline
-void
-pylith::topology::VecVisitorMesh::optimizeClosure()
-{ // optimizeClosure
-  PetscSection   clSection;
-  PetscErrorCode err;
-
-  err = PetscSectionGetClosureIndex(_section, (PetscObject) _dm, &clSection, NULL);PYLITH_CHECK_ERROR(err);
-  if (!clSection) {err = DMPlexCreateClosureIndex(_dm, _section);PYLITH_CHECK_ERROR(err);}
-} // optimizeClosure
-
-// ----------------------------------------------------------------------
 // Get coordinates array associated with closure.
 inline
 void
@@ -211,6 +198,39 @@ pylith::topology::VecVisitorMesh::setClosure(const PetscScalar* valuesCell,
 } // setClosure
 
 // ----------------------------------------------------------------------
+// Optimize the closure operation.
+inline
+void
+pylith::topology::VecVisitorMesh::optimizeClosure(void)
+{ // optimizeClosure
+  PetscErrorCode err;
+
+  PetscSection indexSection = NULL;
+  err = PetscSectionGetClosureIndex(_section, (PetscObject) _dm, &indexSection, NULL);PYLITH_CHECK_ERROR(err);
+  if (!indexSection) {
+    err = DMPlexCreateClosureIndex(_dm, _section);PYLITH_CHECK_ERROR(err);
+  } // if
+} // optimizeClosure
+
+// ----------------------------------------------------------------------
+// Optimize the closure operation.
+inline
+void
+pylith::topology::VecVisitorMesh::optimizeClosure(const Field& field)
+{ // optimizeClosure
+  PetscErrorCode err;
+
+  PetscSection fieldSection = field.petscSection();assert(fieldSection);
+  PetscDM dmMesh = field.mesh().dmMesh();assert(dmMesh);
+  PetscSection indexSection = NULL;
+  err = PetscSectionGetClosureIndex(fieldSection, (PetscObject) dmMesh, &indexSection, NULL);PYLITH_CHECK_ERROR(err);
+  if (!indexSection) {
+    err = DMPlexCreateClosureIndex(dmMesh, fieldSection);PYLITH_CHECK_ERROR(err);
+  } // if
+} // optimizeClosure
+
+
+// ----------------------------------------------------------------------
 // Default constructor.
 inline
 pylith::topology::MatVisitorMesh::MatVisitorMesh(const PetscMat mat,



More information about the CIG-COMMITS mailing list