[cig-commits] r16442 - in short/3D/PyLith/trunk: libsrc/topology modulesrc/topology pylith/topology unittests/libtests/topology
brad at geodynamics.org
brad at geodynamics.org
Tue Mar 23 15:50:47 PDT 2010
Author: brad
Date: 2010-03-23 15:50:46 -0700 (Tue, 23 Mar 2010)
New Revision: 16442
Modified:
short/3D/PyLith/trunk/libsrc/topology/Jacobian.cc
short/3D/PyLith/trunk/libsrc/topology/Jacobian.hh
short/3D/PyLith/trunk/modulesrc/topology/Jacobian.i
short/3D/PyLith/trunk/pylith/topology/Jacobian.py
short/3D/PyLith/trunk/pylith/topology/JacobianViewer.py
short/3D/PyLith/trunk/unittests/libtests/topology/TestJacobian.cc
short/3D/PyLith/trunk/unittests/libtests/topology/TestJacobian.hh
Log:
Cleaned up interface to Jacobian. Use single field for flexibility instead of requiring a SolutionFields object as arg in constructor.
Modified: short/3D/PyLith/trunk/libsrc/topology/Jacobian.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Jacobian.cc 2010-03-23 21:28:16 UTC (rev 16441)
+++ short/3D/PyLith/trunk/libsrc/topology/Jacobian.cc 2010-03-23 22:50:46 UTC (rev 16442)
@@ -15,22 +15,21 @@
#include "Jacobian.hh" // implementation of class methods
#include "Mesh.hh" // USES Mesh
-#include "SolutionFields.hh" // USES SolutionFields
+#include "SubMesh.hh" // USES SubMesh
#include "Field.hh" // USES Field
#include "pylith/utils/petscerror.h" // USES CHECK_PETSC_ERROR
// ----------------------------------------------------------------------
// Default constructor.
-pylith::topology::Jacobian::Jacobian(const SolutionFields& fields,
- const char* matrixType,
- const bool blockOkay) :
- _fields(fields),
+pylith::topology::Jacobian::Jacobian(const Field<Mesh>& field,
+ const char* matrixType,
+ const bool blockOkay) :
_matrix(0),
_valuesChanged(true)
{ // constructor
- const ALE::Obj<Mesh::SieveMesh>& sieveMesh = fields.mesh().sieveMesh();
- const ALE::Obj<Mesh::RealSection>& solnSection = fields.solution().section();
+ const ALE::Obj<Mesh::SieveMesh>& sieveMesh = field.mesh().sieveMesh();
+ const ALE::Obj<Mesh::RealSection>& fieldSection = field.section();
ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
logger.stagePush("Jacobian");
@@ -38,14 +37,42 @@
// dimension, otherwise use a block size of 1.
const int blockFlag = (blockOkay) ? -1 : 1;
- PetscErrorCode err = MeshCreateMatrix(sieveMesh, solnSection,
+ PetscErrorCode err = MeshCreateMatrix(sieveMesh, fieldSection,
matrixType, &_matrix, blockFlag);
CHECK_PETSC_ERROR_MSG(err, "Could not create PETSc sparse matrix "
"associated with system Jacobian.");
logger.stagePop();
+
+ _type = matrixType;
} // constructor
// ----------------------------------------------------------------------
+// Default constructor.
+pylith::topology::Jacobian::Jacobian(const Field<SubMesh>& field,
+ const char* matrixType,
+ const bool blockOkay) :
+ _matrix(0),
+ _valuesChanged(true)
+{ // constructor
+ const ALE::Obj<SubMesh::SieveMesh>& sieveMesh = field.mesh().sieveMesh();
+ const ALE::Obj<SubMesh::RealSection>& fieldSection = field.section();
+ ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
+ logger.stagePush("Jacobian");
+
+ // Set blockFlag to -1 if okay to set block size equal to fiber
+ // dimension, otherwise use a block size of 1.
+ const int blockFlag = (blockOkay) ? -1 : 1;
+
+ PetscErrorCode err = MeshCreateMatrix(sieveMesh, fieldSection,
+ matrixType, &_matrix, blockFlag);
+ CHECK_PETSC_ERROR_MSG(err, "Could not create PETSc sparse matrix "
+ "associated with subsystem Jacobian.");
+ logger.stagePop();
+
+ _type = matrixType;
+} // constructor
+
+// ----------------------------------------------------------------------
// Destructor.
pylith::topology::Jacobian::~Jacobian(void)
{ // destructor
@@ -80,6 +107,14 @@
} // matrix
// ----------------------------------------------------------------------
+// Get matrix type.
+const char*
+pylith::topology::Jacobian::matrixType(void) const
+{ // matrixType
+ return _type.c_str();
+} // matrixType
+
+// ----------------------------------------------------------------------
// Assemble matrix.
void
pylith::topology::Jacobian::assemble(const char* mode)
@@ -124,12 +159,11 @@
// ----------------------------------------------------------------------
// Write matrix to binary file.
void
-pylith::topology::Jacobian::write(const char* filename)
+pylith::topology::Jacobian::write(const char* filename,
+ const MPI_Comm comm)
{ // write
PetscViewer viewer;
- const MPI_Comm comm = _fields.mesh().comm();
-
PetscErrorCode err =
PetscViewerBinaryOpen(comm, filename, FILE_MODE_WRITE, &viewer);
CHECK_PETSC_ERROR(err);
Modified: short/3D/PyLith/trunk/libsrc/topology/Jacobian.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Jacobian.hh 2010-03-23 21:28:16 UTC (rev 16441)
+++ short/3D/PyLith/trunk/libsrc/topology/Jacobian.hh 2010-03-23 22:50:46 UTC (rev 16442)
@@ -19,11 +19,14 @@
#if !defined(pylith_topology_jacobian_hh)
#define pylith_topology_jacobian_hh
+
// Include directives ---------------------------------------------------
#include "topologyfwd.hh" // forward declarations
#include "pylith/utils/petscfwd.h" // HOLDSA PetscMat
+#include <mpi.h> // USES MPI_Comm
+
// Jacobian -------------------------------------------------------------
/// Jacobian of the system as a PETSc sparse matrix.
class pylith::topology::Jacobian
@@ -35,15 +38,26 @@
/** Default constructor.
*
- * @param fields Fields associated with mesh and solution of the problem.
+ * @param field Field associated with mesh and solution of the problem.
* @param matrixType Type of PETSc sparse matrix.
* @param blockOkay True if okay to use block size equal to fiberDim
* (all or none of the DOF at each point are constrained).
*/
- Jacobian(const SolutionFields& fields,
- const char* matrixType ="aij",
- const bool blockOkay =false);
+ Jacobian(const Field<Mesh>& field,
+ const char* matrixType ="aij",
+ const bool blockOkay =false);
+ /** Constructor with field for submesh.
+ *
+ * @param field Fields associated with submesh and solution of the problem.
+ * @param matrixType Type of PETSc sparse matrix.
+ * @param blockOkay True if okay to use block size equal to fiberDim
+ * (all or none of the DOF at each point are constrained).
+ */
+ Jacobian(const Field<SubMesh>& field,
+ const char* matrixType ="aij",
+ const bool blockOkay =true);
+
/// Destructor.
~Jacobian(void);
@@ -62,6 +76,12 @@
*/
PetscMat matrix(void);
+ /** Get matrix type.
+ *
+ * @returns Matrix type.
+ */
+ const char* matrixType(void) const;
+
/** Assemble matrix.
*
* @param mode Assembly mode.
@@ -77,8 +97,10 @@
/** Write matrix to binary file.
*
* @param filename Name of file.
+ * @param comm MPI communicator.
*/
- void write(const char* filename);
+ void write(const char* filename,
+ const MPI_Comm comm);
/// Verify symmetry of matrix. For debugger purposes only.
void verifySymmetry(void) const;
@@ -97,11 +119,12 @@
// PRIVATE MEMBERS //////////////////////////////////////////////////////
private :
- const SolutionFields& _fields; ///< Solution fields associated with problem.
PetscMat _matrix; ///< Sparse matrix for Jacobian of problem.
bool _valuesChanged; ///< Sparse matrix values have been updated.
+ std::string _type; ///< String associated with matrix type.
+
// NOT IMPLEMENTED //////////////////////////////////////////////////////
private :
Modified: short/3D/PyLith/trunk/modulesrc/topology/Jacobian.i
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/Jacobian.i 2010-03-23 21:28:16 UTC (rev 16441)
+++ short/3D/PyLith/trunk/modulesrc/topology/Jacobian.i 2010-03-23 22:50:46 UTC (rev 16442)
@@ -27,15 +27,26 @@
/** Default constructor.
*
- * @param fields Fields associated with mesh and solution of the problem.
+ * @param field Field associated with mesh and solution of the problem.
* @param matrixType Type of PETSc sparse matrix.
* @param blockOkay True if okay to use block size equal to fiberDim
* (all or none of the DOF at each point are constrained).
*/
- Jacobian(const SolutionFields& fields,
+ Jacobian(const Field<Mesh>& field,
const char* matrixType ="aij",
const bool blockOkay =false);
-
+
+ /** Constructor with field for submesh.
+ *
+ * @param field Fields associated with submesh and solution of the problem.
+ * @param matrixType Type of PETSc sparse matrix.
+ * @param blockOkay True if okay to use block size equal to fiberDim
+ * (all or none of the DOF at each point are constrained).
+ */
+ Jacobian(const Field<SubMesh>& field,
+ const char* matrixType ="aij",
+ const bool blockOkay =true);
+
/// Destructor.
~Jacobian(void);
@@ -54,6 +65,12 @@
*/
PetscMat* matrix(void);
+ /** Get matrix type.
+ *
+ * @returns Matrix type.
+ */
+ const char* matrixType(void) const;
+
/** Assemble matrix.
*
* @param mode Assembly mode.
@@ -69,8 +86,10 @@
/** Write matrix to binary file.
*
* @param filename Name of file.
+ * @param comm MPI communicator.
*/
- void write(const char* filename);
+ void write(const char* filename,
+ const MPI_Comm comm);
/// Verify symmetry of matrix. For debugger purposes only.
void verifySymmetry(void) const;
Modified: short/3D/PyLith/trunk/pylith/topology/Jacobian.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/Jacobian.py 2010-03-23 21:28:16 UTC (rev 16441)
+++ short/3D/PyLith/trunk/pylith/topology/Jacobian.py 2010-03-23 22:50:46 UTC (rev 16442)
@@ -25,7 +25,7 @@
# PUBLIC METHODS /////////////////////////////////////////////////////
- def __init__(self, fields, matrixType="unknown"):
+ def __init__(self, field, matrixType="unknown"):
"""
Constructor.
@@ -35,7 +35,7 @@
if matrixType == "unknown":
matrixType = "sbaij"
- ModuleJacobian.__init__(self, fields, matrixType)
+ ModuleJacobian.__init__(self, field, matrixType)
return
Modified: short/3D/PyLith/trunk/pylith/topology/JacobianViewer.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/JacobianViewer.py 2010-03-23 21:28:16 UTC (rev 16441)
+++ short/3D/PyLith/trunk/pylith/topology/JacobianViewer.py 2010-03-23 22:50:46 UTC (rev 16442)
@@ -74,11 +74,11 @@
return
- def view(self, jacobian, t):
+ def view(self, jacobian, t, comm):
"""
Write Jacobian to binary file.
"""
- jacobian.write(self._filenameStamp(t))
+ jacobian.write(self._filenameStamp(t), comm)
return
Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestJacobian.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestJacobian.cc 2010-03-23 21:28:16 UTC (rev 16441)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestJacobian.cc 2010-03-23 22:50:46 UTC (rev 16442)
@@ -17,6 +17,7 @@
#include "pylith/topology/Jacobian.hh" // USES Jacobian
#include "pylith/topology/Mesh.hh" // USES Mesh
+#include "pylith/topology/SubMesh.hh" // USES SubMesh
#include "pylith/topology/Field.hh" // USES Field
#include "pylith/topology/SolutionFields.hh" // USES SolutionFields
@@ -31,25 +32,43 @@
pylith::topology::TestJacobian::testConstructor(void)
{ // testConstructor
Mesh mesh;
- SolutionFields fields(mesh);
- _initialize(&mesh, &fields);
- Jacobian jacobian(fields);
+ Field<Mesh> field(mesh);
+ _initialize(&mesh, &field);
+ Jacobian jacobian(field);
- Jacobian jacobianB(fields, "baij");
- Jacobian jacobianC(fields, "baij", true);
- Jacobian jacobianD(fields, "sbaij");
- Jacobian jacobianE(fields, "sbaij", true);
+ Jacobian jacobianB(field, "baij");
+ Jacobian jacobianC(field, "baij", true);
+ Jacobian jacobianD(field, "sbaij");
+ Jacobian jacobianE(field, "sbaij", true);
} // testConstructor
-
+
// ----------------------------------------------------------------------
+// Test constructor with subdomain field
+void
+pylith::topology::TestJacobian::testConstructorSubDomain(void)
+{ // testConstructorSubDomain
+ Mesh mesh;
+ Field<Mesh> field(mesh);
+ _initialize(&mesh, &field);
+
+ SubMesh submesh(mesh, "bc");
+ Field<SubMesh> subfield(submesh);
+ subfield.newSection(FieldBase::VERTICES_FIELD, submesh.dimension());
+ subfield.allocate();
+ subfield.zero();
+
+ Jacobian jacobian(subfield);
+} // testConstructorSubDomain
+
+// ----------------------------------------------------------------------
// Test matrix().
void
pylith::topology::TestJacobian::testMatrix(void)
{ // testMatrix
Mesh mesh;
- SolutionFields fields(mesh);
- _initialize(&mesh, &fields);
- Jacobian jacobian(fields);
+ Field<Mesh> field(mesh);
+ _initialize(&mesh, &field);
+ Jacobian jacobian(field);
const PetscMat matrix = jacobian.matrix();
CPPUNIT_ASSERT(0 != matrix);
@@ -61,9 +80,9 @@
pylith::topology::TestJacobian::testAssemble(void)
{ // testAssemble
Mesh mesh;
- SolutionFields fields(mesh);
- _initialize(&mesh, &fields);
- Jacobian jacobian(fields);
+ Field<Mesh> field(mesh);
+ _initialize(&mesh, &field);
+ Jacobian jacobian(field);
jacobian.assemble("flush_assembly");
jacobian.assemble("final_assembly");
@@ -75,9 +94,9 @@
pylith::topology::TestJacobian::testZero(void)
{ // testZero
Mesh mesh;
- SolutionFields fields(mesh);
- _initialize(&mesh, &fields);
- Jacobian jacobian(fields);
+ Field<Mesh> field(mesh);
+ _initialize(&mesh, &field);
+ Jacobian jacobian(field);
jacobian.zero();
} // testZero
@@ -88,9 +107,9 @@
pylith::topology::TestJacobian::testView(void)
{ // testView
Mesh mesh;
- SolutionFields fields(mesh);
- _initialize(&mesh, &fields);
- Jacobian jacobian(fields);
+ Field<Mesh> field(mesh);
+ _initialize(&mesh, &field);
+ Jacobian jacobian(field);
jacobian.assemble("final_assembly");
@@ -103,32 +122,30 @@
pylith::topology::TestJacobian::testWrite(void)
{ // testWrite
Mesh mesh;
- SolutionFields fields(mesh);
- _initialize(&mesh, &fields);
- Jacobian jacobian(fields);
+ Field<Mesh> field(mesh);
+ _initialize(&mesh, &field);
+ Jacobian jacobian(field);
jacobian.assemble("final_assembly");
- jacobian.write("jacobian.mat");
+ jacobian.write("jacobian.mat", mesh.comm());
} // testWrite
// ----------------------------------------------------------------------
void
pylith::topology::TestJacobian::_initialize(Mesh* mesh,
- SolutionFields* fields) const
+ Field<Mesh>* field) const
{ // _initialize
CPPUNIT_ASSERT(0 != mesh);
+ CPPUNIT_ASSERT(0 != field);
meshio::MeshIOAscii iohandler;
iohandler.filename("data/tri3.mesh");
iohandler.read(mesh);
- fields->add("disp t+dt", "displacement");
- fields->solutionName("disp t+dt");
- Field<Mesh>& solution = fields->solution();
- solution.newSection(FieldBase::VERTICES_FIELD, mesh->dimension());
- solution.allocate();
- solution.zero();
+ field->newSection(FieldBase::VERTICES_FIELD, mesh->dimension());
+ field->allocate();
+ field->zero();
} // _initialize
Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestJacobian.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestJacobian.hh 2010-03-23 21:28:16 UTC (rev 16441)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestJacobian.hh 2010-03-23 22:50:46 UTC (rev 16442)
@@ -40,6 +40,7 @@
CPPUNIT_TEST_SUITE( TestJacobian );
CPPUNIT_TEST( testConstructor );
+ CPPUNIT_TEST( testConstructorSubDomain );
CPPUNIT_TEST( testMatrix );
CPPUNIT_TEST( testAssemble );
CPPUNIT_TEST( testZero );
@@ -54,6 +55,9 @@
/// Test constructor.
void testConstructor(void);
+ /// Test constructor with subdomain.
+ void testConstructorSubDomain(void);
+
/// Test matrix().
void testMatrix(void);
@@ -75,10 +79,10 @@
/** Initialize mesh for Jacobian.
*
* @param mesh Finite-element mesh.
- * @param fields Solution fields.
+ * @param field Solution field.
*/
void _initialize(Mesh* mesh,
- SolutionFields* fields) const;
+ Field<Mesh>* field) const;
}; // class TestJacobian
More information about the CIG-COMMITS
mailing list