[cig-commits] [commit] knepley/upgrade-petsc-interface: Copy field and subfield metadata when cloning fields. (e85362d)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Wed Nov 13 17:53:31 PST 2013


Repository : ssh://geoshell/pylith

On branch  : knepley/upgrade-petsc-interface
Link       : https://github.com/geodynamics/pylith/compare/38af70f852f88e09db031dc32da2bb69b8636846...cc6d236d1d32991191bebf4738dac67befb5fead

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

commit e85362dada7f46a342614c429559e5557e61bb71
Author: Brad Aagaard <baagaard at usgs.gov>
Date:   Wed Nov 13 17:52:39 2013 -0800

    Copy field and subfield metadata when cloning fields.
    
    Was not copying subfield metadata. Also fixed setting index of fields in
    section (use index in metadata).


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

e85362dada7f46a342614c429559e5557e61bb71
 libsrc/pylith/topology/Field.cc | 20 ++++++++------------
 modulesrc/topology/Field.i      |  8 ++++++++
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/libsrc/pylith/topology/Field.cc b/libsrc/pylith/topology/Field.cc
index 828cdf0..aa400a1 100644
--- a/libsrc/pylith/topology/Field.cc
+++ b/libsrc/pylith/topology/Field.cc
@@ -524,7 +524,7 @@ pylith::topology::Field::cloneSection(const Field& src)
   // Clear memory
   clear();
 
-  _metadata["default"] = const_cast<Field&>(src)._metadata["default"];
+  _metadata = src._metadata;
   label(origLabel.c_str());
 
   PetscSection section = src.petscSection();
@@ -1266,12 +1266,12 @@ pylith::topology::Field::subfieldsSetup(void)
 
   // Setup section now that we know the total number of sub-fields and components.
   PetscSection section = NULL;
-  PetscInt iField = 0;
   PetscErrorCode err = DMGetDefaultSection(_dm, &section);PYLITH_CHECK_ERROR(err);assert(section);
   err = PetscSectionSetNumFields(section, _subfieldComps.size());PYLITH_CHECK_ERROR(err);
-  for(std::map<std::string, int>::const_iterator f_iter = _subfieldComps.begin(); f_iter != _subfieldComps.end(); ++f_iter, ++iField) {
-    err = PetscSectionSetFieldName(section, iField, f_iter->first.c_str());PYLITH_CHECK_ERROR(err);
-    err = PetscSectionSetFieldComponents(section, iField, f_iter->second);PYLITH_CHECK_ERROR(err);
+  for(std::map<std::string, int>::const_iterator f_iter = _subfieldComps.begin(); f_iter != _subfieldComps.end(); ++f_iter) {
+    const PetscInt index = subfieldMetadata(f_iter->first.c_str()).index;
+    err = PetscSectionSetFieldName(section, index, f_iter->first.c_str());PYLITH_CHECK_ERROR(err);
+    err = PetscSectionSetFieldComponents(section, index, f_iter->second);PYLITH_CHECK_ERROR(err);
   } // for
 
   PYLITH_METHOD_END;
@@ -1325,17 +1325,13 @@ pylith::topology::Field::subfieldMetadata(const char* name)
 { // subfieldMetadata
   PYLITH_METHOD_BEGIN;
 
-  try {
-    const Metadata& metadata = _metadata[name];
-    PYLITH_METHOD_RETURN(metadata);
-  } catch (std::exception& err) {
+  if (!_metadata.count(name)) {
     std::ostringstream msg;
     msg << "Could not find subfield '" << name << "' in field '" << label() << "'." << std::endl;
     throw std::runtime_error(msg.str());
-  } // try/catch
+  } // if
 
-  // Satisfy return value
-  PYLITH_METHOD_RETURN(_metadata["default"]);
+  PYLITH_METHOD_RETURN(_metadata[name]);
 } // subfieldmetadata
 
 
diff --git a/modulesrc/topology/Field.i b/modulesrc/topology/Field.i
index c2212b9..e55728e 100644
--- a/modulesrc/topology/Field.i
+++ b/modulesrc/topology/Field.i
@@ -198,6 +198,14 @@ namespace pylith {
        */
       void copy(const Field& field);
       
+      /** Copy subfield values and its metadata to field;
+       *
+       * @param field Field to copy from.
+       * @param name Name of subfield to copy.
+       */
+      void copySubfield(const Field& field,
+			const char* name);
+
       /** Add two fields, storing the result in one of the fields.
        *
        * @param field Field to add.



More information about the CIG-COMMITS mailing list