[cig-commits] r20043 - in short/3D/PyLith/branches/v1.7-trunk: libsrc/pylith/problems modulesrc/problems pylith/problems

brad at geodynamics.org brad at geodynamics.org
Fri May 4 14:29:46 PDT 2012


Author: brad
Date: 2012-05-04 14:29:45 -0700 (Fri, 04 May 2012)
New Revision: 20043

Modified:
   short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/Formulation.cc
   short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/Formulation.hh
   short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/Solver.cc
   short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/SolverLinear.cc
   short/3D/PyLith/branches/v1.7-trunk/modulesrc/problems/Formulation.i
   short/3D/PyLith/branches/v1.7-trunk/pylith/problems/Formulation.py
Log:
Added switch to turn on/off separating split fields into components.

Modified: short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/Formulation.cc
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/Formulation.cc	2012-05-04 19:34:13 UTC (rev 20042)
+++ short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/Formulation.cc	2012-05-04 21:29:45 UTC (rev 20043)
@@ -39,7 +39,9 @@
   _jacobianLumped(0),
   _fields(0),
   _customConstraintPCMat(0),
-  _isJacobianSymmetric(false)
+  _isJacobianSymmetric(false),
+  _splitFields(false),
+  _splitFieldComponents(false)
 { // constructor
 } // constructor
 
@@ -87,6 +89,22 @@
 } // splitFields
 
 // ----------------------------------------------------------------------
+// Set flag for splitting field components.
+void
+pylith::problems::Formulation::splitFieldComponents(const bool flag)
+{ // splitFieldComponents
+  _splitFieldComponents = flag;
+} // splitFieldComponents
+
+// ----------------------------------------------------------------------
+// Get flag for splitting field components.
+bool
+pylith::problems::Formulation::splitFieldComponents(void) const
+{ // splitFieldComponents
+  return _splitFieldComponents;
+} // splitFieldComponents
+
+// ----------------------------------------------------------------------
 // Set flag for using custom preconditioner for Lagrange constraints.
 void
 pylith::problems::Formulation::useCustomConstraintPC(const bool flag)

Modified: short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/Formulation.hh
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/Formulation.hh	2012-05-04 19:34:13 UTC (rev 20042)
+++ short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/Formulation.hh	2012-05-04 21:29:45 UTC (rev 20043)
@@ -73,6 +73,18 @@
    */
   bool splitFields(void) const;
 
+  /** Set flag for splitting field components.
+   *
+   * @param flag True if splitting fields comonents, false otherwise.
+   */
+  void splitFieldComponents(const bool flag);
+
+  /** Get flag for splitting field components.
+   *
+   * @returns flag True if splitting field components, false otherwise.
+   */
+  bool splitFieldComponents(void) const;
+
   /** Set flag for using custom preconditioner for Lagrange constraints.
    *
    * @param flag True if using custom fault preconditioner, false otherwise.
@@ -210,6 +222,7 @@
 
   bool _isJacobianSymmetric; ///< Is system Jacobian symmetric?
   bool _splitFields; ///< True if splitting fields.
+  bool _splitFieldComponents; ///< True if splitting field components
 
   /// True if using custom preconditioner for Lagrange constraints.
   bool _useCustomConstraintPC;

Modified: short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/Solver.cc
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/Solver.cc	2012-05-04 19:34:13 UTC (rev 20042)
+++ short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/Solver.cc	2012-05-04 21:29:45 UTC (rev 20043)
@@ -158,17 +158,32 @@
   const topology::Field<topology::Mesh>& solution = fields.solution();
   const ALE::Obj<RealSection>& solutionSection = solution.section();
   assert(!solutionSection.isNull());
+  const int spaceDim = sieveMesh->getDimension();
+  const int numSpaces = solutionSection->getNumSpaces();
 
   err = PCSetType(*pc, PCFIELDSPLIT); CHECK_PETSC_ERROR(err);
   err = PCSetOptionsPrefix(*pc, "fs_"); CHECK_PETSC_ERROR(err);
   err = PCSetFromOptions(*pc); CHECK_PETSC_ERROR(err);
 
-  constructFieldSplit(solutionSection, 
-		      sieveMesh->getFactory()->getGlobalOrder(sieveMesh, "default", 
-							      solutionSection), 
-		      solution.vector(), *pc);
+  bool separateComponents = formulation->splitFieldComponents();
+  if (separateComponents) {
+    constructFieldSplit(solutionSection, PETSC_DETERMINE, PETSC_NULL, PETSC_NULL, 
+			sieveMesh->getFactory()->getGlobalOrder(sieveMesh, "default", 
+								solutionSection), 
+			solution.vector(), *pc);
+  } else {
+    int numFields[2] = {spaceDim, (numSpaces > spaceDim) ? 1 : 0};
+    int* fields = new int[numSpaces];
+    for(PetscInt f=0; f < numSpaces; ++f) {
+      fields[f] = f;
+    } // for
+    constructFieldSplit(solutionSection, 2, numFields, fields,
+			sieveMesh->getFactory()->getGlobalOrder(sieveMesh,
+"default", solutionSection),
+			solution.vector(), *pc);
+    delete[] fields;
+  } // if/else
 
-  const int spaceDim = sieveMesh->getDimension();
   if (formulation->splitFields() && 
       formulation->useCustomConstraintPC() &&
       solutionSection->getNumSpaces() > sieveMesh->getDimension()) {
@@ -208,10 +223,10 @@
       _ctx.faultFieldName = "1";
       break;
     case 2 :
-      _ctx.faultFieldName = "2";
+      _ctx.faultFieldName = (separateComponents) ? "2" : "1";
       break;
     case 3 :
-      _ctx.faultFieldName = "3";
+      _ctx.faultFieldName = (separateComponents) ? "3" : "1";
       break;
     default:
       assert(0);

Modified: short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/SolverLinear.cc
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/SolverLinear.cc	2012-05-04 19:34:13 UTC (rev 20042)
+++ short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/problems/SolverLinear.cc	2012-05-04 21:29:45 UTC (rev 20043)
@@ -137,7 +137,7 @@
     err = KSPSetUp(_ksp); CHECK_PETSC_ERROR(err);
     err = KSPGetPC(_ksp, &pc); CHECK_PETSC_ERROR(err);
     err = PCFieldSplitGetSubKSP(pc, &num, &ksps); CHECK_PETSC_ERROR(err);
-    assert(solutionSection->getNumSpaces() == num);
+    // Now only true if splitting components assert(solutionSection->getNumSpaces() == num);
 
     MatStructure flag;
     err = KSPGetOperators(ksps[num-1], &A, PETSC_NULL, &flag);CHECK_PETSC_ERROR(err);

Modified: short/3D/PyLith/branches/v1.7-trunk/modulesrc/problems/Formulation.i
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/modulesrc/problems/Formulation.i	2012-05-04 19:34:13 UTC (rev 20042)
+++ short/3D/PyLith/branches/v1.7-trunk/modulesrc/problems/Formulation.i	2012-05-04 21:29:45 UTC (rev 20043)
@@ -52,6 +52,18 @@
        */
       bool splitFields(void) const;
 
+      /** Set flag for splitting field components.
+       *
+       * @param flag True if splitting fields comonents, false otherwise.
+       */
+      void splitFieldComponents(const bool flag);
+      
+      /** Get flag for splitting field components.
+       *
+       * @returns flag True if splitting field components, false otherwise.
+       */
+      bool splitFieldComponents(void) const;
+
       /** Set flag for using custom Lagrange constraint preconditioner.
        *
        * @param flag True if using custom constraint precondition,

Modified: short/3D/PyLith/branches/v1.7-trunk/pylith/problems/Formulation.py
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/pylith/problems/Formulation.py	2012-05-04 19:34:13 UTC (rev 20042)
+++ short/3D/PyLith/branches/v1.7-trunk/pylith/problems/Formulation.py	2012-05-04 21:29:45 UTC (rev 20043)
@@ -75,6 +75,8 @@
     ## @li \b use_cuda Enable use of CUDA for finite-element integrations.
     ## @li \b matrix_type Type of PETSc sparse matrix.
     ## @li \b split_fields Split solution fields into displacements
+    ## and Lagrange constraints.
+    ## @li \b split_field_components Split fields into components.
     ## @li \b use_custom_constraint_pc Use custom preconditioner for
     ##   Lagrange constraints.
     ## @li \b view_jacobian Flag to output Jacobian matrix when it is
@@ -99,6 +101,9 @@
     useSplitFields.meta['tip'] = "Split solution fields into displacements "\
         "and Lagrange multipliers for separate preconditioning."
 
+    useSplitFieldComponents = pyre.inventory.bool("split_field_components", default=False)
+    useSplitFieldComponents.meta['tip'] = "Split solution fields into components for separate preconditioning."
+
     useCustomConstraintPC = pyre.inventory.bool("use_custom_constraint_pc",
                                                 default=False)
     useCustomConstraintPC.meta['tip'] = "Use custom preconditioner for " \
@@ -333,6 +338,7 @@
       self.inventory.useSplitFields = True
 
     ModuleFormulation.splitFields(self, self.inventory.useSplitFields)
+    ModuleFormulation.splitFieldComponents(self, self.inventory.useSplitFieldComponents)
     ModuleFormulation.useCustomConstraintPC(self,
                                             self.inventory.useCustomConstraintPC)
 



More information about the CIG-COMMITS mailing list