From 1f367c7d14c318df170785e3ddbacc02b2599793 Mon Sep 17 00:00:00 2001 From: ageay Date: Wed, 15 Dec 2010 10:42:04 +0000 Subject: [PATCH] *** empty log message *** --- src/MEDCoupling/MEDCouplingFieldDouble.cxx | 22 +++++- src/MEDCoupling/MEDCouplingFieldDouble.hxx | 1 + src/MEDCoupling/MEDCouplingMemArray.cxx | 61 ++++++++++++---- .../MEDCouplingTimeDiscretization.cxx | 69 ++++++++++++++++++- .../MEDCouplingTimeDiscretization.hxx | 5 ++ .../Test/MEDCouplingBasicsTest.hxx | 2 + .../Test/MEDCouplingBasicsTest2.cxx | 41 +++++++++++ src/MEDCoupling_Swig/MEDCoupling.i | 24 ++++++- src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 32 +++++++++ 9 files changed, 239 insertions(+), 18 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index f530f2141..d24f36c12 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -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(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; diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index c319fae10..719bc41c8 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -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); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 6ba17ac7f..8c94de8b4 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -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()); - 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()); + 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(),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()); + if(nbOfComp==nbOfComp2) + { + std::transform(getConstPointer(),getConstPointer()+nbOfTuple*nbOfComp,other->getConstPointer(),getPointer(),std::divides()); + } + else + { + if(nbOfComp2==1) + { + const double *ptr=other->getConstPointer(); + double *myPtr=getPointer(); + for(int i=0;i(),ptr[i])); + } + else + throw INTERP_KERNEL::Exception("Nb of components mismatch for array divideEqual !"); + } declareAsNew(); } diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index 8e43c0e60..8757e8c10 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -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(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(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(other); + return otherC!=0; +} + +bool MEDCouplingConstOnTimeInterval::areStrictlyCompatibleForDiv(const MEDCouplingTimeDiscretization *other) const +{ + if(!MEDCouplingTimeDiscretization::areStrictlyCompatibleForDiv(other)) return false; const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(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(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(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)) diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index 45f8518ba..88b020eb1 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -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& tinyInfo) const; void getTinySerializationDbleInformation(std::vector& 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& vals, double *res) const; void getValueOnTime(int eltId, double time, double *value) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index ccd971ffd..076a59565 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -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(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx index 9091e64b2..7b2b12146 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx @@ -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(); +} diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 238129cb8..94c2613d4 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -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 d0=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d2=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr 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& 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 ); } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 4ef4a8f7c..31e6ba1b3 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -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 -- 2.39.2