[cig-commits] r22011 - in short/3D/PyLith/trunk: libsrc/pylith/topology modulesrc/topology pylith/problems unittests/pytests/topology
brad at geodynamics.org
brad at geodynamics.org
Thu May 9 12:20:35 PDT 2013
Author: brad
Date: 2013-05-09 12:20:35 -0700 (Thu, 09 May 2013)
New Revision: 22011
Modified:
short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh
short/3D/PyLith/trunk/libsrc/pylith/topology/Field.icc
short/3D/PyLith/trunk/modulesrc/topology/Field.i
short/3D/PyLith/trunk/pylith/problems/Explicit.py
short/3D/PyLith/trunk/pylith/problems/Implicit.py
short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshField.py
short/3D/PyLith/trunk/unittests/pytests/topology/TestSolutionFields.py
Log:
Omit operator+= from SWIG interface (returning reference causes memory management problems). Added add() method for this functionality.
Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh 2013-05-09 15:49:10 UTC (rev 22010)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Field.hh 2013-05-09 19:20:35 UTC (rev 22011)
@@ -346,6 +346,12 @@
*/
Field& operator+=(const Field& field);
+ /** Add two fields, storing the result in one of the fields.
+ *
+ * @param field Field to add.
+ */
+ void add(const Field& field);
+
/** Dimensionalize field. Throws runtime_error if field is not
* allowed to be dimensionalized.
*/
Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Field.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Field.icc 2013-05-09 15:49:10 UTC (rev 22010)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Field.icc 2013-05-09 19:20:35 UTC (rev 22011)
@@ -138,6 +138,16 @@
return const_cast<Field*>(this)->_metadata["default"].dimsOkay;
}
+// Add two fields, storing the result in one of the fields.
+template<typename mesh_type>
+inline
+void
+pylith::topology::Field<mesh_type>::add(const Field& field) {
+ this->operator+=(field);
+}
+
+
+
#endif
Modified: short/3D/PyLith/trunk/modulesrc/topology/Field.i
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/Field.i 2013-05-09 15:49:10 UTC (rev 22010)
+++ short/3D/PyLith/trunk/modulesrc/topology/Field.i 2013-05-09 19:20:35 UTC (rev 22011)
@@ -22,20 +22,6 @@
* @brief Python interface to C++ Field object.
*/
-// Typemaps for returning reference in operator+=. The default
-// behavior is that the Python object will gain ownership. We want the
-// C++ object to retain ownership. This could be alleviated by using a
-// shared pointer.
-%typemap(out) pylith::topology::Field<pylith::topology::Mesh>& {
- $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), $descriptor(pylith::topology::Field<pylith::topology::Mesh>*), 0 | 0);
- return $result;
- }
-%typemap(out) pylith::topology::Field<pylith::topology::SubMesh>& {
- $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), $descriptor(pylith::topology::Field<pylith::topology::SubMesh>*), 0 | 0);
- return $result;
- }
-
-
namespace pylith {
namespace topology {
@@ -183,8 +169,8 @@
*
* @param field Field to add.
*/
- Field& operator+=(const Field& field);
-
+ void add(const Field& field);
+
/** Dimensionalize field. Throws runtime_error if field is not
* allowed to be dimensionalized.
*/
Modified: short/3D/PyLith/trunk/pylith/problems/Explicit.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Explicit.py 2013-05-09 15:49:10 UTC (rev 22010)
+++ short/3D/PyLith/trunk/pylith/problems/Explicit.py 2013-05-09 19:20:35 UTC (rev 22011)
@@ -241,7 +241,7 @@
dispTmdt = self.fields.get("disp(t-dt)")
dispTmdt.copy(dispT)
- dispT += dispIncr
+ dispT.add(dispIncr)
dispIncr.zero()
# Complete post-step processing.
Modified: short/3D/PyLith/trunk/pylith/problems/Implicit.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Implicit.py 2013-05-09 15:49:10 UTC (rev 22010)
+++ short/3D/PyLith/trunk/pylith/problems/Implicit.py 2013-05-09 19:20:35 UTC (rev 22011)
@@ -238,7 +238,7 @@
# Update displacement field from time t to time t+dt.
dispIncr = self.fields.get("dispIncr(t->t+dt)")
disp = self.fields.get("disp(t)")
- disp += dispIncr
+ disp.add(dispIncr)
dispIncr.zero()
# Complete post-step processing, then write data.
Modified: short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshField.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshField.py 2013-05-09 15:49:10 UTC (rev 22010)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshField.py 2013-05-09 19:20:35 UTC (rev 22011)
@@ -156,11 +156,11 @@
def test_operatorAdd(self):
"""
- Test operator+=.
+ Test add().
"""
fieldB = MeshField(self.mesh)
fieldB.allocate()
- self.field += fieldB
+ self.field.add(fieldB)
# No test of result
return
Modified: short/3D/PyLith/trunk/unittests/pytests/topology/TestSolutionFields.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/TestSolutionFields.py 2013-05-09 15:49:10 UTC (rev 22010)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/TestSolutionFields.py 2013-05-09 19:20:35 UTC (rev 22011)
@@ -111,7 +111,7 @@
fieldA.allocate()
fieldB.allocate()
- fieldA += fieldB
+ fieldA.add(fieldB)
return
More information about the CIG-COMMITS
mailing list