[cig-commits] r14379 - in short/3D/PyLith/branches/pylith-swig: . libsrc/problems libsrc/topology
brad at geodynamics.org
brad at geodynamics.org
Tue Mar 17 22:05:24 PDT 2009
Author: brad
Date: 2009-03-17 22:05:24 -0700 (Tue, 17 Mar 2009)
New Revision: 14379
Modified:
short/3D/PyLith/branches/pylith-swig/TODO
short/3D/PyLith/branches/pylith-swig/libsrc/problems/Formulation.cc
short/3D/PyLith/branches/pylith-swig/libsrc/problems/Solver.cc
short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.cc
short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.hh
short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.cc
short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.hh
short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.cc
short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.hh
Log:
More work on solvers. Initial use of VecScatter within Field.
Modified: short/3D/PyLith/branches/pylith-swig/TODO
===================================================================
--- short/3D/PyLith/branches/pylith-swig/TODO 2009-03-18 02:27:34 UTC (rev 14378)
+++ short/3D/PyLith/branches/pylith-swig/TODO 2009-03-18 05:05:24 UTC (rev 14379)
@@ -4,13 +4,16 @@
0. SWIG conversion
- libtests/topology/Field
- createVector()
- vector()
- libtests/topology/SolutionFields
- createScatter()
- scatter()
+ libsrc/topology/Field
+ createScatter() [use ALE::Obj<PetscVecScatter> to share scatter]
+ When copying layout, copy VecScatter. [Fields]
+ scatterSectionToVector()
+ scatterVectorToSection()
+ libtests/topology/Field
+ createVector()
+ vector()
+
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/problems/Formulation.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/problems/Formulation.cc 2009-03-18 02:27:34 UTC (rev 14378)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/problems/Formulation.cc 2009-03-18 05:05:24 UTC (rev 14379)
@@ -50,41 +50,17 @@
assert(0 != args);
assert(0 != args->object);
assert(0 != args->fields);
+ assert(0 != args->residual);
- PetscVec localVec;
- PetscErrorCode err = 0;
-
- PetscVecScatter scatter = args->fields->scatter();
-
// Copy solution information from PETSc vector into field
- const ALE::Obj<topology::Mesh::RealSection>& solutionSection =
- args->fields->solution().section();
- err = VecCreateSeqWithArray(PETSC_COMM_SELF,
- solutionSection->sizeWithBC(),
- solutionSection->restrictSpace(),
- &localVec); CHECK_PETSC_ERROR(err);
- err = VecScatterBegin(scatter, solutionVec, localVec, INSERT_VALUES,
- SCATTER_REVERSE); CHECK_PETSC_ERROR(err);
- err = VecScatterEnd(scatter, solutionVec, localVec, INSERT_VALUES,
- SCATTER_REVERSE); CHECK_PETSC_ERROR(err);
- err = VecDestroy(localVec); CHECK_PETSC_ERROR(err);
+ args->fields->solution().scatterVectorToSection();
// Reform residual
args->object->reformResidual(args->residual, args->fields,
args->t, args->dt);
// Copy residual information from field into PETSc vector
- const ALE::Obj<topology::Mesh::RealSection>& residualSection =
- args->fields->get("residual").section();
- err = VecCreateSeqWithArray(PETSC_COMM_SELF,
- residualSection->sizeWithBC(),
- residualSection->restrictSpace(),
- &localVec); CHECK_PETSC_ERROR(err);
- err = VecScatterBegin(scatter, localVec, residualVec, INSERT_VALUES,
- SCATTER_FORWARD); CHECK_PETSC_ERROR(err);
- err = VecScatterEnd(scatter, localVec, residualVec, INSERT_VALUES,
- SCATTER_FORWARD); CHECK_PETSC_ERROR(err);
- err = VecDestroy(localVec); CHECK_PETSC_ERROR(err);
+ args->residual->scatterSectionToVector();
} // reformResidual
// ----------------------------------------------------------------------
Modified: short/3D/PyLith/branches/pylith-swig/libsrc/problems/Solver.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/problems/Solver.cc 2009-03-18 02:27:34 UTC (rev 14378)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/problems/Solver.cc 2009-03-18 05:05:24 UTC (rev 14379)
@@ -35,13 +35,13 @@
{ // initialize
assert(0 != fields);
- fields->createScatter();
-
topology::Field<topology::Mesh>& solution = fields->solution();
- solution.createVector();
+ solution.createVector(); // Move this to use of SolutionFields and copyLayout?
+ solution.createScatter();
topology::Field<topology::Mesh>& residual = fields->get("residual");
residual.createVector();
+ solution.createScatter(); // :TODO: eliminate duplication
} // initialize
Modified: short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.cc 2009-03-18 02:27:34 UTC (rev 14378)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.cc 2009-03-18 05:05:24 UTC (rev 14379)
@@ -38,9 +38,12 @@
// ----------------------------------------------------------------------
// Set initial guess nonzero flag.
void
-pylith::problems::SolverLinear::initialGuessNonzero(bool flag)
+pylith::problems::SolverLinear::initialGuessNonzero(const bool value)
{ // initialGuessNonzero
-
+ assert(0 != _ksp);
+
+ PetscTruth flag = (value) ? PETSC_TRUE : PETSC_FALSE;
+ KSPSetInitialGuessNonzero(_ksp, flag);
} // initialGuessNonzero
// ----------------------------------------------------------------------
@@ -68,6 +71,22 @@
const topology::Jacobian& jacobian,
const topology::Field<topology::Mesh>& residual)
{ // solve
+ assert(0 != solution);
+
+ PetscErrorCode err = 0;
+
+ // Update PetscVector view of field.
+ residual->scatterSectionToVector();
+
+ err = KSPSetOperators(_ksp, jacobianMat, jacobianMat,
+ DIFFERENT_NONZERO_PATTERN); CHECK_PETSC_ERROR(err);
+
+ const PetscVec residualVec = residual.vector();
+ const PetscVec solutionVec = solution->vector();
+ err = KSPSolve(_ksp, residualVec, solutionVec); CHECK_PETSC_ERROR(err);
+
+ // Update section view of field.
+ solution->scatterVectorToSection();
} // solve
Modified: short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.hh 2009-03-18 02:27:34 UTC (rev 14378)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.hh 2009-03-18 05:05:24 UTC (rev 14379)
@@ -44,10 +44,10 @@
/** Set initial guess nonzero flag.
*
- * True = use previous solution as initial guess, False = use zero
- * as initial guess.
+ * @param value true means use previous solution as initial guess, false
+ * means use zero as initial guess.
*/
- void initialGuessNonzero(bool flag);
+ void initialGuessNonzero(const bool value);
/** Initialize solver.
*
Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.cc 2009-03-18 02:27:34 UTC (rev 14378)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.cc 2009-03-18 05:05:24 UTC (rev 14379)
@@ -419,5 +419,69 @@
err = VecSetFromOptions(_vector); CHECK_PETSC_ERROR(err);
} // createVector
+// ----------------------------------------------------------------------
+// Create PETSc vector scatter for field. This is used to transfer
+// information from the "global" PETSc vector view to the "local"
+// Sieve section view.
+template<typename mesh_type>
+void
+pylith::topology::Field<mesh_type>::createScatter(void)
+{ // createScatter
+ PetscErrorCode err = 0;
+ if (0 != _scatter) {
+ err = VecScatterDestroy(_scatter); _scatter = 0;
+ CHECK_PETSC_ERROR(err);
+ } // if
+
+ err = MeshCreateGlobalScatter(_mesh.sieveMesh(), _section, &_scatter);
+ CHECK_PETSC_ERROR(err);
+} // createScatter
+// ----------------------------------------------------------------------
+// Scatter section information across processors to update the
+// PETSc vector view of the field.
+template<typename mesh_type>
+void
+pylith::topology::Field<mesh_type>::scatterSectionToVector(void)
+{ // scatterSectionToVector
+ assert(0 != _scatter);
+ assert(!_section.isNull());
+ assert(0 != _vector);
+
+ PetscErrorCode err = 0;
+ PetscVec localVec = 0;
+ err = VecCreateSeqWithArray(PETSC_COMM_SELF,
+ _section->sizeWithBC(), _section->restrictSpace(),
+ &localVec); CHECK_PETSC_ERROR(err);
+ err = VecScatterBegin(_scatter, _vector, localVec,
+ INSERT_VALUES, SCATTER_REVERSE); CHECK_PETSC_ERROR(err);
+ err = VecScatterEnd(_scatter, _vector, localVec,
+ INSERT_VALUES, SCATTER_REVERSE); CHECK_PETSC_ERROR(err);
+ err = VecDestroy(localVec); CHECK_PETSC_ERROR(err);
+} // scatterSectionToVector
+
+// ----------------------------------------------------------------------
+// Scatter PETSc vector information across processors to update the
+// section view of the field.
+template<typename mesh_type>
+void
+pylith::topology::Field<mesh_type>::scatterVectorToSection(void)
+{ // scatterVectorToSection
+ assert(0 != _scatter);
+ assert(!_section.isNull());
+ assert(0 != _vector);
+
+ PetscErrorCode err = 0;
+ PetscVec localVec = 0;
+ err = VecCreateSeqWithArray(PETSC_COMM_SELF,
+ _section->sizeWithBC(), _section->restrictSpace(),
+ &localVec); CHECK_PETSC_ERROR(err);
+ err = VecScatterBegin(_scatter, localVec, _vector,
+ INSERT_VALUES, SCATTER_FORWARD); CHECK_PETSC_ERROR(err);
+ err = VecScatterEnd(_scatter, localVec, _vector,
+ INSERT_VALUES, SCATTER_FORWARD); CHECK_PETSC_ERROR(err);
+ err = VecDestroy(localVec); CHECK_PETSC_ERROR(err);
+} // scatterVectorToSection
+
+
// End of file
Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.hh 2009-03-18 02:27:34 UTC (rev 14378)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.hh 2009-03-18 05:05:24 UTC (rev 14379)
@@ -216,6 +216,19 @@
*/
const PetscVec vector(void) const;
+ /// Create PETSc vector scatter for field. This is used to transfer
+ /// information from the "global" PETSc vector view to the "local"
+ /// Sieve section view.
+ void createScatter(void);
+
+ /// Scatter section information across processors to update the
+ /// PETSc vector view of the field.
+ void scatterSectionToVector(void);
+
+ /// Scatter PETSc vector information across processors to update the
+ /// section view of the field.
+ void scatterVectorToSection(void);
+
// PRIVATE MEMBERS //////////////////////////////////////////////////////
private :
@@ -223,7 +236,8 @@
std::string _name; ///< Name of field
const mesh_type& _mesh; ///< Mesh associated with section
ALE::Obj<RealSection> _section; ///< Real section with data
- PetscVec _vector;
+ PetscVec _vector; ///< PETSc vector associated with field.
+ PetscVecScatter _scatter; ///< PETSc scatter associated with field.
VectorFieldEnum _vecFieldType; ///< Type of vector field
bool _dimensionsOkay; ///< Flag indicating it is okay to dimensionalize
Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.cc 2009-03-18 02:27:34 UTC (rev 14378)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.cc 2009-03-18 05:05:24 UTC (rev 14379)
@@ -101,37 +101,5 @@
_fields[_history[0]] = tmp;
} // shiftHistory
-// ----------------------------------------------------------------------
-// Create vector scatter associated with solution fields.
-void
-pylith::topology::SolutionFields::createScatter(void)
-{ // createScatter
- PetscErrorCode err = 0;
- if (0 != _scatter) {
- err = VecScatterDestroy(_scatter); _scatter = 0;
- CHECK_PETSC_ERROR(err);
- } // if
-
- err = MeshCreateGlobalScatter(_mesh.sieveMesh(),
- solution().section(), &_scatter);
- CHECK_PETSC_ERROR(err);
-} // createScatter
-// ----------------------------------------------------------------------
-// Get vector scatter associated with solution fields.
-const PetscVecScatter
-pylith::topology::SolutionFields::scatter(void) const
-{ // scatter
- return _scatter;
-} // scatter
-
-// ----------------------------------------------------------------------
-// Get vector scatter associated with solution fields.
-PetscVecScatter
-pylith::topology::SolutionFields::scatter(void)
-{ // scatter
- return _scatter;
-} // scatter
-
-
// End of file
Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.hh 2009-03-18 02:27:34 UTC (rev 14378)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/SolutionFields.hh 2009-03-18 05:05:24 UTC (rev 14379)
@@ -78,21 +78,6 @@
*/
void shiftHistory(void);
- /// Create vector scatter associated with solution fields.
- void createScatter(void);
-
- /** Get vector scatter associated with solution fields.
- *
- * @returns PETSc vector scatter.
- */
- const PetscVecScatter scatter(void) const;
-
- /** Get vector scatter associated with solution fields.
- *
- * @returns PETSc vector scatter.
- */
- PetscVecScatter scatter(void);
-
// PRIVATE MEMBERS //////////////////////////////////////////////////////
private :
More information about the CIG-COMMITS
mailing list