[cig-commits] r14434 - in short/3D/PyLith/branches/pylith-swig: . libsrc/problems modulesrc modulesrc/problems modulesrc/topology pylith pylith/problems pylith/topology
brad at geodynamics.org
brad at geodynamics.org
Tue Mar 24 15:08:01 PDT 2009
Author: brad
Date: 2009-03-24 15:08:00 -0700 (Tue, 24 Mar 2009)
New Revision: 14434
Added:
short/3D/PyLith/branches/pylith-swig/modulesrc/problems/
short/3D/PyLith/branches/pylith-swig/modulesrc/problems/Formulation.i
short/3D/PyLith/branches/pylith-swig/modulesrc/problems/Makefile.am
short/3D/PyLith/branches/pylith-swig/modulesrc/problems/Solver.i
short/3D/PyLith/branches/pylith-swig/modulesrc/problems/SolverLinear.i
short/3D/PyLith/branches/pylith-swig/modulesrc/problems/SolverNonlinear.i
short/3D/PyLith/branches/pylith-swig/modulesrc/problems/problems.i
short/3D/PyLith/branches/pylith-swig/pylith/problems/Solver.py
short/3D/PyLith/branches/pylith-swig/pylith/problems/SolverLinear.py
short/3D/PyLith/branches/pylith-swig/pylith/problems/SolverNonlinear.py
short/3D/PyLith/branches/pylith-swig/pylith/topology/JacobianViewer.py
Removed:
short/3D/PyLith/branches/pylith-swig/modulesrc/solver/
short/3D/PyLith/branches/pylith-swig/pylith/solver/
Modified:
short/3D/PyLith/branches/pylith-swig/configure.ac
short/3D/PyLith/branches/pylith-swig/libsrc/problems/Formulation.hh
short/3D/PyLith/branches/pylith-swig/libsrc/problems/Solver.hh
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/problems/SolverNonlinear.hh
short/3D/PyLith/branches/pylith-swig/modulesrc/Makefile.am
short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Field.i
short/3D/PyLith/branches/pylith-swig/pylith/Makefile.am
short/3D/PyLith/branches/pylith-swig/pylith/problems/Formulation.py
short/3D/PyLith/branches/pylith-swig/pylith/problems/__init__.py
Log:
Added module and updated Python code for formulation and solvers.
Modified: short/3D/PyLith/branches/pylith-swig/configure.ac
===================================================================
--- short/3D/PyLith/branches/pylith-swig/configure.ac 2009-03-24 21:21:31 UTC (rev 14433)
+++ short/3D/PyLith/branches/pylith-swig/configure.ac 2009-03-24 22:08:00 UTC (rev 14434)
@@ -227,7 +227,7 @@
modulesrc/materials/Makefile
modulesrc/meshio/Makefile
modulesrc/mpi/Makefile
- modulesrc/solver/Makefile
+ modulesrc/problems/Makefile
modulesrc/topology/Makefile
modulesrc/utils/Makefile
applications/Makefile
Modified: short/3D/PyLith/branches/pylith-swig/libsrc/problems/Formulation.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/problems/Formulation.hh 2009-03-24 21:21:31 UTC (rev 14433)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/problems/Formulation.hh 2009-03-24 22:08:00 UTC (rev 14434)
@@ -11,7 +11,7 @@
//
/**
- * @file pylith/problems/Formulation.hh
+ * @file libsrc/problems/Formulation.hh
*
* @brief C++ Object that manages reforming the Jacobian and residual for
* the problem.
@@ -33,7 +33,7 @@
// Formulation ----------------------------------------------------------
class pylith::problems::Formulation
-{ // Integrator
+{ // Formulation
friend class TestFormulation; // unit testing
// PRIVATE TYPEDEFS /////////////////////////////////////////////////////
Modified: short/3D/PyLith/branches/pylith-swig/libsrc/problems/Solver.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/problems/Solver.hh 2009-03-24 21:21:31 UTC (rev 14433)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/problems/Solver.hh 2009-03-24 22:08:00 UTC (rev 14434)
@@ -11,7 +11,7 @@
//
/**
- * @file pylith/problems/Solver.hh
+ * @file libsrc/problems/Solver.hh
*
* @brief Abstract C++ base class for using PETSc linear and nonlinear
* solvers.
@@ -28,7 +28,7 @@
// Solver ---------------------------------------------------------
class pylith::problems::Solver
-{ // Integrator
+{ // Solver
friend class TestSolver; // unit testing
// PUBLIC MEMBERS ///////////////////////////////////////////////////////
Modified: short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.cc 2009-03-24 21:21:31 UTC (rev 14433)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.cc 2009-03-24 22:08:00 UTC (rev 14434)
@@ -39,16 +39,16 @@
} // destructor
// ----------------------------------------------------------------------
-// Set initial guess nonzero flag.
+// Set initial guess zero flag.
void
-pylith::problems::SolverLinear::initialGuessNonzero(const bool value)
-{ // initialGuessNonzero
+pylith::problems::SolverLinear::initialGuessZero(const bool value)
+{ // initialGuessZero
assert(0 != _ksp);
- PetscTruth flag = (value) ? PETSC_TRUE : PETSC_FALSE;
+ PetscTruth flag = (value) ? PETSC_FALSE : PETSC_TRUE;
PetscErrorCode err = KSPSetInitialGuessNonzero(_ksp, flag);
CHECK_PETSC_ERROR(err);
-} // initialGuessNonzero
+} // initialGuessZero
// ----------------------------------------------------------------------
// Initialize solver.
Modified: short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.hh 2009-03-24 21:21:31 UTC (rev 14433)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.hh 2009-03-24 22:08:00 UTC (rev 14434)
@@ -11,7 +11,7 @@
//
/**
- * @file pylith/problems/SolverLinear.hh
+ * @file libsrc/problems/SolverLinear.hh
*
* @brief Object for using PETSc scalable linear equation solvers (KSP).
*
@@ -29,7 +29,7 @@
// SolverLinear ---------------------------------------------------------
class pylith::problems::SolverLinear : Solver
-{ // Integrator
+{ // SolverLinear
friend class TestSolverLinear; // unit testing
// PUBLIC MEMBERS ///////////////////////////////////////////////////////
@@ -41,12 +41,12 @@
/// Destructor
~SolverLinear(void);
- /** Set initial guess nonzero flag.
+ /** Set initial guess zero flag.
*
- * @param value true means use previous solution as initial guess, false
- * means use zero as initial guess.
+ * @param value True means use zero as initial guess, false means
+ * use previous solution as initial guess.
*/
- void initialGuessNonzero(const bool value);
+ void initialGuessZero(const bool value);
/** Initialize solver.
*
Modified: short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverNonlinear.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverNonlinear.hh 2009-03-24 21:21:31 UTC (rev 14433)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverNonlinear.hh 2009-03-24 22:08:00 UTC (rev 14434)
@@ -11,7 +11,7 @@
//
/**
- * @file pylith/problems/SolverNonlinear.hh
+ * @file libsrc/problems/SolverNonlinear.hh
*
* @brief Object for using PETSc scalable nonlinear equation solvers
* (SNES).
@@ -31,7 +31,7 @@
// SolverNonlinear ---------------------------------------------------------
class pylith::problems::SolverNonlinear : public Solver
-{ // Integrator
+{ // SolverNonlinear
friend class TestSolverNonlinear; // unit testing
// PUBLIC MEMBERS ///////////////////////////////////////////////////////
Modified: short/3D/PyLith/branches/pylith-swig/modulesrc/Makefile.am
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/Makefile.am 2009-03-24 21:21:31 UTC (rev 14433)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/Makefile.am 2009-03-24 22:08:00 UTC (rev 14434)
@@ -17,7 +17,7 @@
materials \
meshio \
mpi \
- solver \
+ problems \
topology \
utils
Added: short/3D/PyLith/branches/pylith-swig/modulesrc/problems/Formulation.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/problems/Formulation.i (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/problems/Formulation.i 2009-03-24 22:08:00 UTC (rev 14434)
@@ -0,0 +1,75 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file modulesrc/problems/Formulation.hh
+ *
+ * @brief Python interface to C++ Formulation.
+ */
+
+namespace pylith {
+ namespace problems {
+
+ class Formulation
+ { // Formulation
+
+ // PUBLIC MEMBERS /////////////////////////////////////////////////
+ public :
+
+ /// Constructor
+ Formulation(void);
+
+ /// Destructor
+ ~Formulation(void);
+
+ /** Set handles to integrators over the mesh.
+ *
+ * @param integrators Integrators over the mesh.
+ * @param numIntegrators Number of integrators.
+ */
+ void meshIntegrators(pylith::feassemble::Integrator<pylith::feassemble::Quadrature<pylith::topology::Mesh> >** integrators,
+ const int numIntegrators);
+
+ /** Set handles to integrators over lower-dimension meshes.
+ *
+ * @param integrators Integrators over lower-dimension meshes.
+ * @param numIntegrators Number of integrators.
+ */
+ void submeshIntegrators(pylith::feassemble::Integrator<pylith::feassemble::Quadrature<pylith::topology::SubMesh> >** integrators,
+ const int numIntegrators);
+
+ /** Update handles and parameters for reforming the Jacobian and
+ * residual.
+ *
+ * @param jacobian Handle to sparse matrix for Jacobian of system.
+ * @param fields Handle to solution fields.
+ * @param t Current time (nondimensional).
+ * @param dt Time step (nondimension).
+ */
+ void updateSettings(pylith::topology::Jacobian* jacobian,
+ pylith::topology::SolutionFields* fields,
+ const double t,
+ const double dt);
+
+ /// Reform system residual.
+ void reformResidual(void);
+
+ /// Reform system Jacobian.
+ void reformJacobian(void);
+
+ }; // Formulation
+
+ } // problems
+} // pylith
+
+
+// End of file
Added: short/3D/PyLith/branches/pylith-swig/modulesrc/problems/Makefile.am
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/problems/Makefile.am (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/problems/Makefile.am 2009-03-24 22:08:00 UTC (rev 14434)
@@ -0,0 +1,60 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+subpackage = problems
+include $(top_srcdir)/subpackage.am
+
+subpkgpyexec_LTLIBRARIES = _problemsmodule.la
+
+subpkgpyexec_PYTHON = problems.py
+
+swig_sources = \
+ problems.i \
+ Formulation.i \
+ Solver.i \
+ SolverLinear.i \
+ SolverNonlinear.i
+
+
+swig_generated = \
+ problems_wrap.cxx \
+ problems.py
+
+_problemsmodule_la_LDFLAGS = -module -avoid-version \
+ $(AM_LDFLAGS) $(PYTHON_LA_LDFLAGS)
+
+dist__problemsmodule_la_SOURCES = $(swig_sources) $(swig_generated)
+
+_problemsmodule_la_LIBADD = \
+ $(top_builddir)/libsrc/libpylith.la \
+ -lspatialdata \
+ $(PETSC_LIBS)
+if ENABLE_CUBIT
+ _problemsmodule_la_LIBADD += -lnetcdf_c++ -lnetcdf
+endif
+if NO_UNDEFINED
+_problemsmodule_la_LIBADD += \
+ $(PYTHON_BLDLIBRARY) $(PYTHON_LIBS) $(PYTHON_SYSLIBS)
+endif
+
+INCLUDES += $(PYTHON_EGG_CPPFLAGS) -I$(NUMPY_INCDIR) -I$(PYTHON_INCDIR) $(PETSC_INCLUDE)
+
+$(srcdir)/problems_wrap.cxx $(srcdir)/problems.py: $(swig_sources)
+ $(SWIG) -Wall -c++ -python $<
+
+
+MAINTAINERCLEANFILES = \
+ $(srcdir)/problems_wrap.cxx \
+ $(srcdir)/problems.py
+
+
+# End of file
Added: short/3D/PyLith/branches/pylith-swig/modulesrc/problems/Solver.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/problems/Solver.i (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/problems/Solver.i 2009-03-24 22:08:00 UTC (rev 14434)
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file modulesrc/problems/Solver.hh
+ *
+ * @brief Python interface to abstract base class Solver.
+ */
+
+namespace pylith {
+ namespace problems {
+
+ class Solver
+ { // Solver
+
+ // PUBLIC MEMBERS /////////////////////////////////////////////////
+ public :
+
+ /// Constructor.
+ Solver(void);
+
+ /// Destructor
+ ~Solver(void);
+
+ /** Initialize solver.
+ *
+ * @param fields Solution fields.
+ * @param jacobian Jacobian of system.
+ * @param formulation Formulation of system of equations.
+ */
+ virtual
+ void
+ initialize(const pylith::topology::SolutionFields& fields,
+ const pylith::topology::Jacobian& jacobian,
+ Formulation* const formulation);
+
+ }; // Solver
+
+ } // problems
+} // pylith
+
+
+// End of file
Added: short/3D/PyLith/branches/pylith-swig/modulesrc/problems/SolverLinear.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/problems/SolverLinear.i (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/problems/SolverLinear.i 2009-03-24 22:08:00 UTC (rev 14434)
@@ -0,0 +1,68 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file modulesrc/problems/SolverLinear.hh
+ *
+ * @brief Python interface to abstract base class SolverLinear.
+ */
+
+namespace pylith {
+ namespace problems {
+
+ class SolverLinear
+ { // SolverLinear
+
+ // PUBLIC MEMBERS /////////////////////////////////////////////////
+ public :
+
+ /// Constructor.
+ SolverLinear(void);
+
+ /// Destructor
+ ~SolverLinear(void);
+
+ /** Set initial guess zero flag.
+ *
+ * @param value True means use zero as initial guess, false means
+ * use previous solution as initial guess.
+ */
+ void initialGuessZero(const bool value);
+
+ /** Initialize solver.
+ *
+ * @param fields Solution fields.
+ * @param jacobian Jacobian of system.
+ * @param formulation Formulation of system of equations.
+ */
+ void
+ initialize(const pylith::topology::SolutionFields& fields,
+ const pylith::topology::Jacobian& jacobian,
+ Formulation* const formulation);
+
+ /** Solve the system.
+ *
+ * @param solution Solution field.
+ * @param jacobian Jacobian of the system.
+ * @param residual Residual field.
+ */
+ void solve(pylith::topology::Field<pylith::topology::Mesh>* solution,
+ const pylith::topology::Jacobian& jacobian,
+ const pylith::topology::Field<pylith::topology::Mesh>& residual);
+
+ }; // SolverLinear
+
+ } // problems
+} // pylith
+
+
+// End of file
Added: short/3D/PyLith/branches/pylith-swig/modulesrc/problems/SolverNonlinear.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/problems/SolverNonlinear.i (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/problems/SolverNonlinear.i 2009-03-24 22:08:00 UTC (rev 14434)
@@ -0,0 +1,61 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file modulesrc/problems/SolverNonlinear.hh
+ *
+ * @brief Python interface to abstract base class SolverNonlinear.
+ */
+
+namespace pylith {
+ namespace problems {
+
+ class SolverNonlinear
+ { // SolverNonlinear
+
+ // PUBLIC MEMBERS /////////////////////////////////////////////////
+ public :
+
+ /// Constructor.
+ SolverNonlinear(void);
+
+ /// Destructor
+ ~SolverNonlinear(void);
+
+ /** Initialize solver.
+ *
+ * @param fields Solution fields.
+ * @param jacobian Jacobian of system.
+ * @param formulation Formulation of system of equations.
+ */
+ void
+ initialize(const pylith::topology::SolutionFields& fields,
+ const pylith::topology::Jacobian& jacobian,
+ Formulation* const formulation);
+
+ /** Solve the system.
+ *
+ * @param solution Solution field.
+ * @param jacobian Jacobian of the system.
+ * @param residual Residual field.
+ */
+ void solve(pylith::topology::Field<pylith::topology::Mesh>* solution,
+ const pylith::topology::Jacobian& jacobian,
+ const pylith::topology::Field<pylith::topology::Mesh>& residual);
+
+ }; // SolverNonlinear
+
+ } // problems
+} // pylith
+
+
+// End of file
Added: short/3D/PyLith/branches/pylith-swig/modulesrc/problems/problems.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/problems/problems.i (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/problems/problems.i 2009-03-24 22:08:00 UTC (rev 14434)
@@ -0,0 +1,48 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+// SWIG interface
+%module problems
+
+// Header files for module C++ code
+%{
+#include "pylith/problems/problemsfwd.hh" // forward declarations
+
+#include "pylith/topology/topologyfwd.hh" // USES Mesh
+#include "pylith/feassemble/feassemblefwd.hh" // USES Integrator
+
+#include "pylith/problems/Formulation.hh"
+#include "pylith/problems/Solver.hh"
+#include "pylith/problems/SolverLinear.hh"
+#include "pylith/problems/SolverNonlinear.hh"
+
+%}
+
+%include "exception.i"
+%exception {
+ try {
+ $action
+ } catch (const std::exception& err) {
+ SWIG_exception(SWIG_RuntimeError, err.what());
+ } // try/catch
+ } // exception
+
+
+// Interfaces
+%include "Formulation.i"
+%include "Solver.i"
+%include "SolverLinear.i"
+%include "SolverNonlinear.i"
+
+
+// End of file
+
Modified: short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Field.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Field.i 2009-03-24 21:21:31 UTC (rev 14433)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Field.i 2009-03-24 22:08:00 UTC (rev 14434)
@@ -159,6 +159,34 @@
*/
void view(const char* label);
+ /// Create PETSc vector for field.
+ void createVector(void);
+
+ /** Get PETSc vector associated with field.
+ *
+ * @returns PETSc vector.
+ */
+ PetscVec vector(void);
+
+ /** Get PETSc vector associated with field.
+ *
+ * @returns PETSc vector.
+ */
+ 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) const;
+
+ /// Scatter PETSc vector information across processors to update the
+ /// Sieve section view of the field.
+ void scatterVectorToSection(void) const;
+
}; // Field
} // topology
Modified: short/3D/PyLith/branches/pylith-swig/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/Makefile.am 2009-03-24 21:21:31 UTC (rev 14433)
+++ short/3D/PyLith/branches/pylith-swig/pylith/Makefile.am 2009-03-24 22:08:00 UTC (rev 14434)
@@ -79,15 +79,14 @@
problems/Formulation.py \
problems/Implicit.py \
problems/Problem.py \
+ problems/Solver.py \
+ problems/SolverLinear.py \
+ problems/SolverNonlinear.py \
problems/TimeDependent.py \
problems/TimeStep.py \
problems/TimeStepAdapt.py \
problems/TimeStepUniform.py \
problems/TimeStepUser.py \
- solver/__init__.py \
- solver/Solver.py \
- solver/SolverLinear.py \
- solver/SolverNonlinear.py \
topology/__init__.py \
topology/Distributor.py \
topology/Mesh.py \
Modified: short/3D/PyLith/branches/pylith-swig/pylith/problems/Formulation.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/problems/Formulation.py 2009-03-24 21:21:31 UTC (rev 14433)
+++ short/3D/PyLith/branches/pylith-swig/pylith/problems/Formulation.py 2009-03-24 22:08:00 UTC (rev 14434)
@@ -10,6 +10,7 @@
# ----------------------------------------------------------------------
#
+
## @file pylith/problems/Formulation.py
##
## @brief Python abstract base class for formulations of solving equations.
@@ -17,6 +18,7 @@
## Factory: pde_formulation
from pyre.components.Component import Component
+from problems import Formulation as ModuleFormulation
from pylith.utils.profiling import resourceUsageString
from pyre.units.time import second
@@ -55,33 +57,18 @@
##
## \b Properties
## @li \b view_jacobian Flag to output Jacobian matrix when it is reformed.
- ## @li \b jacobian_filename Filename for Jacobian matrix.
- ## @li \b jacobian_time_width String length of time stamp in Jacobian filename.
- ## @li \b jacobian_time_constant Value used to normalize time stamp in filename.
-
##
## \b Facilities
## @li \b time_step Time step size manager.
## @li \b solver Algebraic solver.
## @li \b output Output manager associated with solution.
+ ## @li \b jacobian_viewer Writer for Jacobian sparse matrix.
import pyre.inventory
viewJacobian = pyre.inventory.bool("view_jacobian", default=False)
viewJacobian.meta['tip'] = "Write Jacobian matrix to binary file."
- jacobianFilename = pyre.inventory.str("jacobian_filename",
- default="jacobian.mat")
- jacobianFilename.meta['tip'] = "Filename for Jacobian matrix."
-
- jacobianTimeWidth = pyre.inventory.int("jacobian_time_width", default=5)
- jacobianTimeWidth.meta['tip'] = "String length of time stamp in Jacobian filename."
-
- jacobianTimeConstant = pyre.inventory.dimensional("jacobian_time_constant",
- default=1.0*second,
- validator=pyre.inventory.greater(0.0*second))
- jacobianTimeConstant.meta['tip'] = "Values used to normalize time stamp in Jacobian filename."
-
from TimeStepUniform import TimeStepUniform
timeStep = pyre.inventory.facility("time_step", family="time_step",
factory=TimeStepUniform)
@@ -98,6 +85,12 @@
factory=SingleOutput)
output.meta['tip'] = "Output managers associated with solution."
+ from pylith.topology.JacobianViewer import JacobianViewer
+ jacobianViewer = pyre.inventory.facility("jacobian_viewer",
+ family="jacobian_viewer",
+ factory=JacobianViewer)
+ jacobianViewer.meta['tip'] = "Writer for Jacobian sparse matrix."
+
# PUBLIC METHODS /////////////////////////////////////////////////////
def __init__(self, name="formulation"):
@@ -105,10 +98,11 @@
Constructor.
"""
Component.__init__(self, name, facility="pde_formulation")
+ ModuleFormulation.__init__(self)
self.integrators = None
self.constraints = None
self.fields = None
- self.solnField = None
+ self.solnName = None
return
@@ -132,9 +126,9 @@
self._setupBC(boundaryConditions)
self._setupInterfaces(interfaceConditions)
- self._info.log("Pre-initializing output.")
- for output in self.output.components():
- output.preinitialize()
+ #self._info.log("Pre-initializing output.")
+ #for output in self.output.components():
+ # output.preinitialize()
self._logger.eventEnd(logEvent)
return
@@ -153,8 +147,8 @@
integrator.verifyConfiguration()
for constraint in self.constraints:
constraint.verifyConfiguration()
- for output in self.output.components():
- output.verifyConfiguration(self.mesh)
+ #for output in self.output.components():
+ # output.verifyConfiguration(self.mesh)
self._logger.eventEnd(logEvent)
return
@@ -172,8 +166,8 @@
numTimeSteps = self.timeStep.numTimeSteps()
totalTime = self.timeStep.totalTime
- from pylith.topology.FieldsManager import FieldsManager
- self.fields = FieldsManager(self.mesh)
+ from pylith.topology.SolutionFields import SolutionFields
+ self.fields = SolutionFields(self.mesh)
self._debug.log(resourceUsageString())
if self.gravityField != None:
@@ -191,17 +185,17 @@
constraint.initialize(totalTime, numTimeSteps, normalizer)
self._debug.log(resourceUsageString())
- self._info.log("Setting up solution output.")
- for output in self.output.components():
- output.initialize(self.mesh, normalizer)
- output.writeInfo()
- output.open(totalTime, numTimeSteps)
- self._debug.log(resourceUsageString())
+ #self._info.log("Setting up solution output.")
+ #for output in self.output.components():
+ # output.initialize(self.mesh, normalizer)
+ # output.writeInfo()
+ # output.open(totalTime, numTimeSteps)
+ #self._debug.log(resourceUsageString())
self._info.log("Creating solution field.")
solnName = self.solnField['name']
self.fields.addReal(solnName)
- self.fields.solutionField(solnName)
+ self.fields.solutionName(solnName)
self.fields.setFiberDimension(solnName, dimension)
for constraint in self.constraints:
constraint.setConstraintSizes(self.fields.getSolution())
@@ -273,8 +267,8 @@
totalTime = self.timeStep.totalTime
self._info.log("Writing solution fields.")
- for output in self.output.components():
- output.writeData(t+dt, self.fields)
+ #for output in self.output.components():
+ # output.writeData(t+dt, self.fields)
for integrator in self.integrators:
integrator.poststep(t, dt, totalTime, self.fields)
for constraint in self.constraints:
@@ -297,8 +291,8 @@
integrator.finalize()
for constraint in self.constraints:
constraint.finalize()
- for output in self.output.components():
- output.close()
+ #for output in self.output.components():
+ # output.close()
self._debug.log(resourceUsageString())
self._logger.eventEnd(logEvent)
@@ -316,9 +310,7 @@
self.solver = self.inventory.solver
self.output = self.inventory.output
self.viewJacobian = self.inventory.viewJacobian
- self.jacobianFilename = self.inventory.jacobianFilename
- self.jacobianTimeWidth = self.inventory.jacobianTimeWidth
- self.jacobianTimeConstant = self.inventory.jacobianTimeConstant
+ self.jacobianViewer = self.inventory.jacobianViewer
import journal
self._debug = journal.debug(self.name)
@@ -413,76 +405,31 @@
"""
self._debug.log(resourceUsageString())
self._logger.stagePush("Reform Jacobian")
- import pylith.utils.petsc as petsc
- petsc.mat_setzero(self.jacobian)
- # Add in contributions that do not require assembly
- self._info.log("Reforming assembled portion of Jacobian of operator.")
- for integrator in self.integrators:
- integrator.timeStep(dt)
- integrator.integrateJacobianAssembled(self.jacobian, t+dt,
- self.fields)
- self._debug.log(resourceUsageString()) # TEMPORARY
- self._info.log("Flushing assembly of Jacobian of operator.")
- petsc.mat_assemble(self.jacobian, "flush_assembly")
+ self.updateSettings(fields, jacobian, t, dt)
+ self.reformJacobian()
- # Add in contributions that require assembly
- self._info.log("Reforming unassembled portion of Jacobian of operator.")
- for integrator in self.integrators:
- integrator.timeStep(dt)
- integrator.integrateJacobian(self.jacobian, t+dt, self.fields)
- self._debug.log(resourceUsageString()) # TEMPORARY
- self._info.log("Doing final assembly of Jacobian of operator.")
- petsc.mat_assemble(self.jacobian, "final_assembly")
self._logger.stagePop()
if self.viewJacobian:
- filename = self._createJacobianFilename(t+dt)
- petsc.mat_view_binary(self.jacobian, filename)
+ self.jacobianViewer.write(self.jacobian, t)
+
self._debug.log(resourceUsageString())
return
- def _createJacobianFilename(self, t):
- """
- Create filename by extracting basename and adding a time stamp.
- """
- base = self.jacobianFilename.lstrip().rstrip()
- baseLen = len(base)
- if base.endswith(".mat"):
- basename = base[0:baseLen-4]
- else:
- basename = base
- time = int(t.value/self.jacobianTimeConstant.value)
- timeStamp = repr(time).rjust(self.jacobianTimeWidth, '0')
- filename = basename + "_t" + timeStamp + ".mat"
- return filename
-
-
def _reformResidual(self, t, dt):
"""
Reform residual vector for operator.
"""
self._info.log("Integrating residual term in operator.")
self._logger.stagePush("Reform Residual")
- residual = self.fields.getReal("residual")
- import pylith.topology.topology as bindings
- bindings.zeroRealSection(residual)
- # Add in contributions that require assembly
- for integrator in self.integrators:
- integrator.timeStep(dt)
- integrator.integrateResidual(residual, t, self.fields)
- self._info.log("Completing residual.")
- bindings.completeSection(self.mesh.cppHandle, residual)
+ self.updateSettings(fields, jacobian, t, dt)
+ self.reformResidual()
- # Add in contributions that do not require assembly
- self._info.log("Integrating assembled residual term in operator.")
- for integrator in self.integrators:
- integrator.timeStep(dt)
- integrator.integrateResidualAssembled(residual, t, self.fields)
-
self._logger.stagePop()
+ self._debug.log(resourceUsageString())
return
Copied: short/3D/PyLith/branches/pylith-swig/pylith/problems/Solver.py (from rev 14425, short/3D/PyLith/branches/pylith-swig/pylith/solver/Solver.py)
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/problems/Solver.py (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/pylith/problems/Solver.py 2009-03-24 22:08:00 UTC (rev 14434)
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/solver/Solver.py
+##
+## @brief Python PyLith abstract base class for solver.
+##
+## Factory: solver
+
+from pyre.components.Component import Component
+
+# Solver class
+class Solver(Component):
+ """
+ Python abstract base class for solver.
+
+ Factory: solver.
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(Component.Inventory):
+ """
+ Python object for managing Solver facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing Solver facilities and properties.
+ ##
+ ## \b Properties
+ ## @li None
+ ##
+ ## \b Facilities
+ ## @li None
+
+ import pyre.inventory
+
+ guessZero = pyre.inventory.bool("initial_guess_zero", default=True)
+ guessZero.meta['tip'] = "Use zero for initial guess."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="solver"):
+ """
+ Constructor.
+ """
+ Component.__init__(self, name, facility="solver")
+ return
+
+
+ # PRIVATE METHODS /////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based using inventory.
+ """
+ Component._configure(self)
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def solver():
+ """
+ Factory associated with Solver.
+ """
+ return Solver()
+
+
+# End of file
Copied: short/3D/PyLith/branches/pylith-swig/pylith/problems/SolverLinear.py (from rev 14425, short/3D/PyLith/branches/pylith-swig/pylith/solver/SolverLinear.py)
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/problems/SolverLinear.py (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/pylith/problems/SolverLinear.py 2009-03-24 22:08:00 UTC (rev 14434)
@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/solver/SolverLinear.py
+
+## @brief Python PyLith linear algebraic solver.
+
+from Solver import Solver
+from problems import SolverLinear as ModuleSolverLinear
+
+# SolverLinear class
+class SolverLinear(Solver, ModuleSolverLinear):
+ """
+ Python PyLith linear algebraic solver.
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(Solver.Inventory):
+ """
+ Python object for managing SolverLinear facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing SolverLinear facilities and properties.
+ ##
+ ## \b Properties
+ ## @li \b initial_guess_zero Use zero for initial guess.
+ ##
+ ## \b Facilities
+ ## @li None
+
+ import pyre.inventory
+
+ guessZero = pyre.inventory.bool("initial_guess_zero", default=True)
+ guessZero.meta['tip'] = "Use zero for initial guess."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="solverlinear"):
+ """
+ Constructor.
+ """
+ Solver.__init__(self, name)
+ ModuleSolverLinear.__init__(self)
+ return
+
+
+ # PRIVATE METHODS /////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based using inventory.
+ """
+ Solver._configure(self)
+ self.initialGuessZero(self.inventory.guessZero)
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def solver():
+ """
+ Factory associated with Solver.
+ """
+ return SolverLinear()
+
+
+# End of file
Copied: short/3D/PyLith/branches/pylith-swig/pylith/problems/SolverNonlinear.py (from rev 14425, short/3D/PyLith/branches/pylith-swig/pylith/solver/SolverNonlinear.py)
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/problems/SolverNonlinear.py (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/pylith/problems/SolverNonlinear.py 2009-03-24 22:08:00 UTC (rev 14434)
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/solver/SolverNonlinear.py
+
+## @brief Python PyLith nonlinear algebraic solver.
+
+from Solver import Solver
+from problems import SolverNonlinear as ModuleSolverNonlinear
+
+# SolverNonlinear class
+class SolverNonlinear(Solver):
+ """
+ Python PyLith nonlinear algebraic solver.
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(Solver.Inventory):
+ """
+ Python object for managing SolverNonlinear facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing SolverNonlinear facilities and properties.
+ ##
+ ## \b Properties
+ ## @li None
+ ##
+ ## \b Facilities
+ ## @li None
+
+ import pyre.inventory
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="solvernonlinear"):
+ """
+ Constructor.
+ """
+ Solver.__init__(self, name)
+ ModuleSolverNonlinear.__init__(self)
+ return
+
+
+ # PRIVATE METHODS /////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based using inventory.
+ """
+ Solver._configure(self)
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def solver():
+ """
+ Factory associated with Solver.
+ """
+ return SolverNonlinear()
+
+
+# End of file
Modified: short/3D/PyLith/branches/pylith-swig/pylith/problems/__init__.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/problems/__init__.py 2009-03-24 21:21:31 UTC (rev 14433)
+++ short/3D/PyLith/branches/pylith-swig/pylith/problems/__init__.py 2009-03-24 22:08:00 UTC (rev 14434)
@@ -18,6 +18,9 @@
'Explicit',
'Implicit',
'Problem',
+ 'Solver',
+ 'SolverLinear',
+ 'SolverNonlinear',
'TimeDependent',
'TimeStep',
'TimeStepUniform',
Added: short/3D/PyLith/branches/pylith-swig/pylith/topology/JacobianViewer.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/topology/JacobianViewer.py (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/pylith/topology/JacobianViewer.py 2009-03-24 22:08:00 UTC (rev 14434)
@@ -0,0 +1,119 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+
+## @file pylith/topology/JacobianViewer.py
+##
+## @brief Python object for writing system Jacobian to file.
+##
+## Factory: jacobian_viewer
+
+from pyre.components.Component import Component
+
+# JacobianViewer class
+class JacobianViewer(Component):
+ """
+ Python abstract base class for formulations of solving equations.
+
+ In general, we use some explicit or implicit formulation of the PDEs
+ to create a linear form, [A]{u}={b} that we can solve.
+
+ Factory: pde_formulation.
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(Component.Inventory):
+ """
+ Python object for managing JacobianViewer facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing JacobianViewer facilities and properties.
+ ##
+ ## \b Properties
+ ## @li \b filename Filename for Jacobian matrix.
+ ## @li \b time_format C style format string for time stamp in filename.
+ ## @li \b time_constant Value used to normalize time stamp in filename.
+ ##
+ ## \b Facilities
+ ## @li None
+
+ import pyre.inventory
+
+ filename = pyre.inventory.str("filename", default="jacobian.mat")
+ filename.meta['tip'] = "Filename for Jacobian matrix."
+
+ timeFormat = pyre.inventory.str("time_format", default="%f")
+ timeFormat.meta['tip'] = "C style format string for time stamp in filename."
+
+ from pyre.units.time import second
+ timeConstant = pyre.inventory.dimensional("time_constant",
+ default=1.0*second,
+ validator=pyre.inventory.greater(0.0*second))
+ timeConstant.meta['tip'] = \
+ "Values used to normalize time stamp in filename."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="formulation"):
+ """
+ Constructor.
+ """
+ Component.__init__(self, name, facility="jacobian_viewer")
+ return
+
+
+ def view(self, jacobian, t):
+ """
+ Write Jacobian to binary file.
+ """
+ jacobian.write(self._filenameStamp(t))
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based using inventory.
+ """
+ Component._configure(self)
+ self.filename = self.inventory.filename
+ self.timeFormat = self.inventory.timeFormat
+ self.timeConstant = self.inventory.timeConstant
+ return
+
+
+ def _filenameStamped(self, t):
+ """
+ Create filename by extracting basename and adding a time stamp.
+ """
+ timeStamp = self.timeFormat % (t.value/self.jacobianTimeConstant.value)
+ basename = self.filename
+ if basename.endswith(".mat"):
+ basename = base[0:len(base)-4]
+ filename = basename + "_t" + timeStamp + ".mat"
+ return filename
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def jacobian_viewer():
+ """
+ Factory associated with JacobianViewer.
+ """
+ return JacobianViewer()
+
+
+# End of file
More information about the CIG-COMMITS
mailing list