]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
*** empty log message ***
authorageay <ageay>
Wed, 15 Dec 2010 10:42:04 +0000 (10:42 +0000)
committerageay <ageay>
Wed, 15 Dec 2010 10:42:04 +0000 (10:42 +0000)
src/MEDCoupling/MEDCouplingFieldDouble.cxx
src/MEDCoupling/MEDCouplingFieldDouble.hxx
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingTimeDiscretization.cxx
src/MEDCoupling/MEDCouplingTimeDiscretization.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx
src/MEDCoupling_Swig/MEDCoupling.i
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index f530f2141c36ee73a0ba4ba89928cc848661c4b4..d24f36c1208399b05d85dc5fe75d1c9d3db76ecf 100644 (file)
@@ -226,6 +226,24 @@ bool MEDCouplingFieldDouble::areCompatibleForMul(const MEDCouplingField *other)
   return true;
 }
 
+/*!
+ * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatible method except that
+ * number of components between 'this' and 'other' can be different here (for operator/).
+ */
+bool MEDCouplingFieldDouble::areCompatibleForDiv(const MEDCouplingField *other) const
+{
+  if(!MEDCouplingField::areStrictlyCompatible(other))
+    return false;
+  const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
+  if(!otherC)
+    return false;
+  if(_nature!=otherC->_nature)
+    return false;
+  if(!_time_discr->areStrictlyCompatibleForDiv(otherC->_time_discr))
+    return false;
+  return true;
+}
+
 /*!
  * This method is invocated before any attempt of melding. This method is very close to areStrictlyCompatible,
  * except that 'this' and other can have different number of components.
@@ -1425,7 +1443,7 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCoupli
 
 MEDCouplingFieldDouble *MEDCouplingFieldDouble::divideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception)
 {
-  if(!f1->areStrictlyCompatible(f2))
+  if(!f1->areCompatibleForDiv(f2))
     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply divideFields on them !");
   MEDCouplingTimeDiscretization *td=f1->_time_discr->divide(f2->_time_discr);
   td->copyTinyAttrFrom(*f1->_time_discr);
@@ -1436,7 +1454,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::divideFields(const MEDCouplingFi
 
 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator/=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception)
 {
-  if(!areStrictlyCompatible(&other))
+  if(!areCompatibleForDiv(&other))
     throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply /= on them !");
   _time_discr->divideEqual(other._time_discr);
   return *this;
index c319fae10585242cb8570a81892af9267746ca6d..719bc41c80b6b253cc1b469ed161f73e9d39cb4c 100644 (file)
@@ -41,6 +41,7 @@ namespace ParaMEDMEM
     bool areCompatibleForMerge(const MEDCouplingField *other) const;
     bool areStrictlyCompatible(const MEDCouplingField *other) const;
     bool areCompatibleForMul(const MEDCouplingField *other) const;
+    bool areCompatibleForDiv(const MEDCouplingField *other) const;
     bool areCompatibleForMeld(const MEDCouplingFieldDouble *other) const;
     void renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception);
     void renumberCellsWithoutMesh(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception);
index 6ba17ac7f6b3ff852883eb502c73514d2c9d1a3b..8c94de8b45a6710f27c19a5a16f5f715ab51c21f 100644 (file)
@@ -1382,28 +1382,63 @@ void DataArrayDouble::multiplyEqual(const DataArrayDouble *other) throw(INTERP_K
 
 DataArrayDouble *DataArrayDouble::divide(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
 {
-  int nbOfComp=a1->getNumberOfComponents();
-  if(nbOfComp!=a2->getNumberOfComponents())
-    throw INTERP_KERNEL::Exception("Nb of components mismatch for array divide !");
   int nbOfTuple=a1->getNumberOfTuples();
-  if(nbOfTuple!=a2->getNumberOfTuples())
+  int nbOfTuple2=a2->getNumberOfTuples();
+  int nbOfComp=a1->getNumberOfComponents();
+  int nbOfComp2=a2->getNumberOfComponents();
+  if(nbOfTuple!=nbOfTuple2)
     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array divide !");
-  DataArrayDouble *ret=DataArrayDouble::New();
-  ret->alloc(nbOfTuple,nbOfComp);
-  std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::divides<double>());
-  ret->copyStringInfoFrom(*a1);
+  DataArrayDouble *ret=0;
+  if(nbOfComp==nbOfComp2)
+    {
+      ret=DataArrayDouble::New();
+      ret->alloc(nbOfTuple,nbOfComp);
+      std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::divides<double>());
+      ret->copyStringInfoFrom(*a1);
+    }
+  else
+    {
+      if(nbOfComp2==1)
+        {
+          ret=DataArrayDouble::New();
+          ret->alloc(nbOfTuple,nbOfComp);
+          const double *a2Ptr=a2->getConstPointer();
+          const double *a1Ptr=a1->getConstPointer();
+          double *res=ret->getPointer();
+          for(int i=0;i<nbOfTuple;i++)
+            res=std::transform(a1Ptr+i*nbOfComp,a1Ptr+(i+1)*nbOfComp,res,std::bind2nd(std::divides<double>(),a2Ptr[i]));
+          ret->copyStringInfoFrom(*a1);
+        }
+      else
+        throw INTERP_KERNEL::Exception("Nb of components mismatch for array divide !");
+    }
   return ret;
 }
 
 void DataArrayDouble::divideEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
 {
-  int nbOfComp=getNumberOfComponents();
-  if(nbOfComp!=other->getNumberOfComponents())
-    throw INTERP_KERNEL::Exception("Nb of components mismatch for array divideEqual !");
   int nbOfTuple=getNumberOfTuples();
-  if(nbOfTuple!=other->getNumberOfTuples())
+  int nbOfTuple2=other->getNumberOfTuples();
+  int nbOfComp=getNumberOfComponents();
+  int nbOfComp2=other->getNumberOfComponents();
+  if(nbOfTuple!=nbOfTuple2)
     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array divideEqual !");
-  std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::divides<double>());
+  if(nbOfComp==nbOfComp2)
+    {
+      std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::divides<double>());
+    }
+  else
+    {
+      if(nbOfComp2==1)
+        {
+          const double *ptr=other->getConstPointer();
+          double *myPtr=getPointer();
+          for(int i=0;i<nbOfTuple;i++)
+            myPtr=std::transform(myPtr,myPtr+nbOfComp,myPtr,std::bind2nd(std::divides<double>(),ptr[i]));
+        }
+      else
+        throw INTERP_KERNEL::Exception("Nb of components mismatch for array divideEqual !");
+    }
   declareAsNew();
 }
 
index 8e43c0e60e4492f2443fabc2e05be1c769a75033..8757e8c1092291a5bf95e84dec851c9483716cb1 100644 (file)
@@ -144,6 +144,21 @@ bool MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(const MEDCouplin
   return true;
 }
 
+bool MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const
+{
+  if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
+    return false;
+  if(_array==0 && other->_array==0)
+    return true;
+  if(_array==0 || other->_array==0)
+    return false;
+  int nbC1=_array->getNumberOfComponents();
+  int nbC2=other->_array->getNumberOfComponents();
+  if(nbC1!=nbC2 && nbC2!=1)
+    return false;
+  return true;
+}
+
 bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const
 {
   if(!areStrictlyCompatible(other))
@@ -721,6 +736,14 @@ bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForMul(const MEDCouplingTimeDi
   return otherC!=0;
 }
 
+bool MEDCouplingNoTimeLabel::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const
+{
+  if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
+    return false;
+  const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
+  return otherC!=0;
+}
+
 bool MEDCouplingNoTimeLabel::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
 {
   if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
@@ -1037,6 +1060,14 @@ bool MEDCouplingWithTimeStep::areStrictlyCompatibleForMul(const MEDCouplingTimeD
   return otherC!=0;
 }
 
+bool MEDCouplingWithTimeStep::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const
+{
+  if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
+    return false;
+  const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
+  return otherC!=0;
+}
+
 bool MEDCouplingWithTimeStep::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
 {
   if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
@@ -1420,7 +1451,15 @@ bool MEDCouplingConstOnTimeInterval::areStrictlyCompatible(const MEDCouplingTime
 
 bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const
 {
-  if(!MEDCouplingTimeDiscretization::areStrictlyCompatible(other))
+  if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForMul(other))
+    return false;
+  const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
+  return otherC!=0;
+}
+
+bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const
+{
+  if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
     return false;
   const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
   return otherC!=0;
@@ -1977,7 +2016,15 @@ bool MEDCouplingLinearTime::areCompatible(const MEDCouplingTimeDiscretization *o
   if(!MEDCouplingTimeDiscretization::areCompatible(other))
     return false;
   const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
-  return otherC!=0;
+  if(otherC==0)
+    return false;
+  if(_end_array==0 && otherC->_end_array==0)
+    return true;
+  if(_end_array==0 || otherC->_end_array==0)
+    return false;
+  if(_end_array->getNumberOfComponents()!=otherC->_end_array->getNumberOfComponents())
+    return false;
+  return true;
 }
 
 bool MEDCouplingLinearTime::areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const
@@ -1996,6 +2043,24 @@ bool MEDCouplingLinearTime::areStrictlyCompatibleForMul(const MEDCouplingTimeDis
   return otherC!=0;
 }
 
+bool MEDCouplingLinearTime::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const
+{
+  if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other))
+    return false;
+  const MEDCouplingLinearTime *otherC=dynamic_cast<const MEDCouplingLinearTime *>(other);
+  if(otherC==0)
+    return false;
+  if(_end_array==0 && otherC->_end_array==0)
+    return true;
+  if(_end_array==0 || otherC->_end_array==0)
+    return false;
+  int nbC1=_end_array->getNumberOfComponents();
+  int nbC2=otherC->_end_array->getNumberOfComponents();
+  if(nbC1!=nbC2 && nbC2!=1)
+    return false;
+  return true;
+}
+
 bool MEDCouplingLinearTime::areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const
 {
   if(!MEDCouplingTimeDiscretization::areCompatibleForMeld(other))
index 45f8518ba083278f8f3e2d76c95fae7caa1a90b4..88b020eb1db2b8fb047c1a8e34ac5e36d752321d 100644 (file)
@@ -46,6 +46,7 @@ namespace ParaMEDMEM
     virtual bool areCompatible(const MEDCouplingTimeDiscretization *other) const;
     virtual bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const;
     virtual bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const;
+    virtual bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const;
     virtual bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const;
     virtual bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const;
     virtual bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const;
@@ -155,6 +156,7 @@ namespace ParaMEDMEM
     bool areCompatible(const MEDCouplingTimeDiscretization *other) const;
     bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const;
     bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const;
+    bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const;
     bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const;
     MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const;
     void checkNoTimePresence() const throw(INTERP_KERNEL::Exception) { }
@@ -205,6 +207,7 @@ namespace ParaMEDMEM
     bool areCompatible(const MEDCouplingTimeDiscretization *other) const;
     bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const;
     bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const;
+    bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const;
     bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const;
     void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
     void getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const;
@@ -245,6 +248,7 @@ namespace ParaMEDMEM
     bool areCompatible(const MEDCouplingTimeDiscretization *other) const;
     bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const;
     bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const;
+    bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const;
     bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const;
     bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const;
     bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const;
@@ -343,6 +347,7 @@ namespace ParaMEDMEM
     bool areCompatible(const MEDCouplingTimeDiscretization *other) const;
     bool areStrictlyCompatible(const MEDCouplingTimeDiscretization *other) const;
     bool areStrictlyCompatibleForMul(const MEDCouplingTimeDiscretization *other) const;
+    bool areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const;
     bool areCompatibleForMeld(const MEDCouplingTimeDiscretization *other) const;
     void getValueForTime(double time, const std::vector<double>& vals, double *res) const;
     void getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception);
index ccd971ffdfbb298fdfbe5db328707331cbb35e58..076a5956566859a902c85284476a13c0484085d8 100644 (file)
@@ -173,6 +173,7 @@ namespace ParaMEDMEM
     CPPUNIT_TEST( testDAIBuildSubstraction1 );
     CPPUNIT_TEST( testBuildOrthogonalField2 );
     CPPUNIT_TEST( testUMInsertNextCell1 );
+    CPPUNIT_TEST( testFieldOperatorDivDiffComp1 );
     //MEDCouplingBasicsTestInterp.cxx
     CPPUNIT_TEST( test2DInterpP0P0_1 );
     CPPUNIT_TEST( test2DInterpP0P0PL_1 );
@@ -374,6 +375,7 @@ namespace ParaMEDMEM
     void testDAIBuildSubstraction1();
     void testBuildOrthogonalField2();
     void testUMInsertNextCell1();
+    void testFieldOperatorDivDiffComp1();
     //MEDCouplingBasicsTestInterp.cxx
     void test2DInterpP0P0_1();
     void test2DInterpP0P0PL_1();
index 9091e64b2c410edb688acdc67f99f73484e96fc6..7b2b12146384fcc22d6e93538a16a2a8854bf16e 100644 (file)
@@ -4034,3 +4034,44 @@ void MEDCouplingBasicsTest::testUMInsertNextCell1()
   targetMesh->checkCoherency();
   targetMesh->decrRef();
 }
+
+void MEDCouplingBasicsTest::testFieldOperatorDivDiffComp1()
+{
+  MEDCouplingUMesh *m=build2DTargetMesh_1();
+  DataArrayInt *d1=DataArrayInt::New();
+  DataArrayInt *d2=DataArrayInt::New();
+  DataArrayInt *d3=DataArrayInt::New();
+  DataArrayInt *d4=DataArrayInt::New();
+  MEDCouplingUMesh *m1=m->buildDescendingConnectivity(d1,d2,d3,d4);
+  //
+  MEDCouplingFieldDouble *f1=m1->buildOrthogonalField();
+  const double arr1[13]={2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.};
+  DataArrayDouble *arr=DataArrayDouble::New();
+  arr->alloc(13,1);
+  std::copy(arr1,arr1+13,arr->getPointer());
+  MEDCouplingFieldDouble *f2=MEDCouplingFieldDouble::New(ON_CELLS);
+  f2->setArray(arr);
+  f2->setMesh(m1);
+  f2->checkCoherency();
+  //
+  MEDCouplingFieldDouble *f3=(*f1)/(*f2);
+  CPPUNIT_ASSERT_THROW((*f2)/(*f1),INTERP_KERNEL::Exception);
+  f3->checkCoherency();
+  (*f1)/=(*f2);
+  CPPUNIT_ASSERT(f1->isEqual(f3,1e-10,1e-10));
+  CPPUNIT_ASSERT_THROW((*f2)/=(*f1),INTERP_KERNEL::Exception);
+  const double expected1[26]={-0.5, 0.0, 0.0, 0.33333333333333331, 0.25, 0.0, 0.0, -0.20000000000000001, 0.117851130197758, 0.117851130197758, 0.0, -0.14285714285714285, 0.0, 0.125, 0.1111111111111111, 0.0, 0.0, 0.10000000000000001, 0.090909090909090912, 0.0, -0.083333333333333329, 0.0, 0.0, 0.076923076923076927, 0.071428571428571425, 0.0};
+  for(int i=0;i<26;i++)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f3->getIJ(0,i),1e-10);
+  //
+  f3->decrRef();
+  f2->decrRef();
+  arr->decrRef();
+  f1->decrRef();
+  m1->decrRef();
+  d1->decrRef();
+  d2->decrRef();
+  d3->decrRef();
+  d4->decrRef();
+  m->decrRef();
+}
index 238129cb83750a6b0c01c6460c934ec192e83b41..94c2613d4edf7bb3c45afcb9c14b0759aa7fe868 100644 (file)
@@ -32,6 +32,7 @@
 #include "MEDCouplingField.hxx"
 #include "MEDCouplingFieldDouble.hxx"
 #include "MEDCouplingGaussLocalization.hxx"
+#include "MEDCouplingAutoRefCountObjectPtr.hxx"
 #include "MEDCouplingTypemaps.i"
 
 #include "InterpKernelAutoPtr.hxx"
@@ -857,6 +858,26 @@ namespace ParaMEDMEM
         PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
         return ret;
       }
+
+      PyObject *buildDescendingConnectivity() const throw(INTERP_KERNEL::Exception)
+      {
+        MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d0=DataArrayInt::New();
+        MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d1=DataArrayInt::New();
+        MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d2=DataArrayInt::New();
+        MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d3=DataArrayInt::New();
+        MEDCouplingUMesh *m=self->buildDescendingConnectivity(d0,d1,d2,d3);
+        PyObject *ret=PyTuple_New(5);
+        PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(m),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 ));
+        PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+        PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+        PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(d2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+        PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(d3),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+        d0->incrRef();
+        d1->incrRef();
+        d2->incrRef();
+        d3->incrRef();
+        return ret;
+      }
     }
     void convertToPolyTypes(const std::vector<int>& cellIdsToConvert) throw(INTERP_KERNEL::Exception);
     void unPolyze() throw(INTERP_KERNEL::Exception);
@@ -1328,7 +1349,8 @@ namespace ParaMEDMEM
       PyObject *getMesh() const throw(INTERP_KERNEL::Exception)
       {
         MEDCouplingMesh *ret1=(MEDCouplingMesh *)self->getMesh();
-        ret1->incrRef();
+        if(ret1)
+          ret1->incrRef();
         return convertMesh(ret1, SWIG_POINTER_OWN | 0 );
       }
 
index 4ef4a8f7cd79eb56835b391d1394d58f5ccf3780..31e6ba1b3f8e3eb9eda9009488e2ce15862bc593 100644 (file)
@@ -5525,6 +5525,13 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         xx=m.getCoordsAt(0)
         del m
         self.assertEqual(3,xx.getNumberOfTuples());
+        #
+        m=MEDCouplingDataForTest.build2DTargetMesh_1();
+        f=m.getMeasureField(True)
+        m2=f.getMesh()
+        del m
+        del f
+        self.assertEqual(5,m2.getNumberOfCells());
         pass
 
     def testUMInsertNextCell1(self):
@@ -5548,6 +5555,31 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         targetMesh.setCoords(myCoords);
         targetMesh.checkCoherency();
         pass
+
+    def testFieldOperatorDivDiffComp1(self):
+        m=MEDCouplingDataForTest.build2DTargetMesh_1();
+        m1,d0,d1,d2,d3=m.buildDescendingConnectivity();
+        #
+        f1=m1.buildOrthogonalField();
+        arr1=[2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.]
+        arr=DataArrayDouble.New();
+        arr.setValues(arr1,13,1);
+        f2=MEDCouplingFieldDouble.New(ON_CELLS);
+        f2.setArray(arr);
+        f2.setMesh(m1);
+        f2.checkCoherency();
+        #
+        f3=f1/f2;
+        self.assertRaises(Exception,f2.__div__,f1)
+        f3.checkCoherency();
+        f1/=f2;
+        self.assertRaises(Exception,f2.__idiv__,f1)
+        self.assertTrue(f1.isEqual(f3,1e-10,1e-10));
+        expected1=[-0.5, 0.0, 0.0, 0.33333333333333331, 0.25, 0.0, 0.0, -0.20000000000000001, 0.117851130197758, 0.117851130197758, 0.0, -0.14285714285714285, 0.0, 0.125, 0.1111111111111111, 0.0, 0.0, 0.10000000000000001, 0.090909090909090912, 0.0, -0.083333333333333329, 0.0, 0.0, 0.076923076923076927, 0.071428571428571425, 0.0]
+        for i in xrange(26):
+            self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),10);
+            pass
+        pass
     
     def setUp(self):
         pass