From: ageay Date: Mon, 26 Jul 2010 10:02:45 +0000 (+0000) Subject: Addition of Exception handling. X-Git-Tag: V5_1_main_FINAL~74 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=63576c44b2587d6e92941819008ed99ccd889a97;p=tools%2Fmedcoupling.git Addition of Exception handling. --- diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 59ce7be13..00f7ab781 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -370,7 +370,7 @@ void MEDCouplingFieldDouble::serialize(std::vector& arrays) c /*! * \b Warning ! This method potentially modifies the underlying mesh ! If the mesh is shared by other fields, these fields could be unavailable. */ -bool MEDCouplingFieldDouble::mergeNodes(double eps) +bool MEDCouplingFieldDouble::mergeNodes(double eps) throw(INTERP_KERNEL::Exception) { MEDCouplingPointSet *meshC=dynamic_cast((MEDCouplingMesh *)(_mesh)); if(!meshC) diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 7717b3628..9d0732731 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -74,7 +74,7 @@ namespace ParaMEDMEM void resizeForUnserialization(const std::vector& tinyInfoI, std::vector& arrays); void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); void serialize(std::vector& arrays) const; - bool mergeNodes(double eps); + bool mergeNodes(double eps) throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const { return addFields(this,&other); } const MEDCouplingFieldDouble &operator+=(const MEDCouplingFieldDouble& other); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 96ca8a98e..430ca9bee 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -130,7 +130,7 @@ void DataArrayDouble::checkNoNullValues() const throw(INTERP_KERNEL::Exception) throw INTERP_KERNEL::Exception("A value 0.0 have been detected !"); } -DataArrayDouble *DataArrayDouble::aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) +DataArrayDouble *DataArrayDouble::aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) { int nbOfComp=a1->getNumberOfComponents(); if(nbOfComp!=a2->getNumberOfComponents()) @@ -145,7 +145,7 @@ DataArrayDouble *DataArrayDouble::aggregate(const DataArrayDouble *a1, const Dat return ret; } -DataArrayDouble *DataArrayDouble::add(const DataArrayDouble *a1, const DataArrayDouble *a2) +DataArrayDouble *DataArrayDouble::add(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) { int nbOfComp=a1->getNumberOfComponents(); if(nbOfComp!=a2->getNumberOfComponents()) @@ -160,7 +160,7 @@ DataArrayDouble *DataArrayDouble::add(const DataArrayDouble *a1, const DataArray return ret; } -void DataArrayDouble::addEqual(const DataArrayDouble *other) +void DataArrayDouble::addEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception) { int nbOfComp=getNumberOfComponents(); if(nbOfComp!=other->getNumberOfComponents()) @@ -172,7 +172,7 @@ void DataArrayDouble::addEqual(const DataArrayDouble *other) declareAsNew(); } -DataArrayDouble *DataArrayDouble::substract(const DataArrayDouble *a1, const DataArrayDouble *a2) +DataArrayDouble *DataArrayDouble::substract(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) { int nbOfComp=a1->getNumberOfComponents(); if(nbOfComp!=a2->getNumberOfComponents()) @@ -187,7 +187,7 @@ DataArrayDouble *DataArrayDouble::substract(const DataArrayDouble *a1, const Dat return ret; } -void DataArrayDouble::substractEqual(const DataArrayDouble *other) +void DataArrayDouble::substractEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception) { int nbOfComp=getNumberOfComponents(); if(nbOfComp!=other->getNumberOfComponents()) @@ -199,7 +199,7 @@ void DataArrayDouble::substractEqual(const DataArrayDouble *other) declareAsNew(); } -DataArrayDouble *DataArrayDouble::multiply(const DataArrayDouble *a1, const DataArrayDouble *a2) +DataArrayDouble *DataArrayDouble::multiply(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) { int nbOfTuple=a1->getNumberOfTuples(); int nbOfTuple2=a2->getNumberOfTuples(); @@ -246,7 +246,7 @@ DataArrayDouble *DataArrayDouble::multiply(const DataArrayDouble *a1, const Data return ret; } -void DataArrayDouble::multiplyEqual(const DataArrayDouble *other) +void DataArrayDouble::multiplyEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception) { int nbOfTuple=getNumberOfTuples(); int nbOfTuple2=other->getNumberOfTuples(); @@ -276,7 +276,7 @@ void DataArrayDouble::multiplyEqual(const DataArrayDouble *other) declareAsNew(); } -DataArrayDouble *DataArrayDouble::divide(const DataArrayDouble *a1, const DataArrayDouble *a2) +DataArrayDouble *DataArrayDouble::divide(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) { int nbOfComp=a1->getNumberOfComponents(); if(nbOfComp!=a2->getNumberOfComponents()) @@ -291,7 +291,7 @@ DataArrayDouble *DataArrayDouble::divide(const DataArrayDouble *a1, const DataAr return ret; } -void DataArrayDouble::divideEqual(const DataArrayDouble *other) +void DataArrayDouble::divideEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception) { int nbOfComp=getNumberOfComponents(); if(nbOfComp!=other->getNumberOfComponents()) diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index d17fa018a..9974aa563 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -122,15 +122,15 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); MEDCOUPLING_EXPORT void writeOnPlace(int id, double element0, const double *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } MEDCOUPLING_EXPORT void checkNoNullValues() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT static DataArrayDouble *aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2); - MEDCOUPLING_EXPORT static DataArrayDouble *add(const DataArrayDouble *a1, const DataArrayDouble *a2); - MEDCOUPLING_EXPORT void addEqual(const DataArrayDouble *other); - MEDCOUPLING_EXPORT static DataArrayDouble *substract(const DataArrayDouble *a1, const DataArrayDouble *a2); - MEDCOUPLING_EXPORT void substractEqual(const DataArrayDouble *other); - MEDCOUPLING_EXPORT static DataArrayDouble *multiply(const DataArrayDouble *a1, const DataArrayDouble *a2); - MEDCOUPLING_EXPORT void multiplyEqual(const DataArrayDouble *other); - MEDCOUPLING_EXPORT static DataArrayDouble *divide(const DataArrayDouble *a1, const DataArrayDouble *a2); - MEDCOUPLING_EXPORT void divideEqual(const DataArrayDouble *other); + MEDCOUPLING_EXPORT static DataArrayDouble *aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayDouble *add(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void addEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayDouble *substract(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void substractEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayDouble *multiply(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void multiplyEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayDouble *divide(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void divideEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); //! nothing to do here because this class does not aggregate any TimeLabel instance. MEDCOUPLING_EXPORT void updateTime() { } private: diff --git a/src/MEDCoupling/MEDCouplingRemapper.cxx b/src/MEDCoupling/MEDCouplingRemapper.cxx index e1b0efeee..071dc7835 100644 --- a/src/MEDCoupling/MEDCouplingRemapper.cxx +++ b/src/MEDCoupling/MEDCouplingRemapper.cxx @@ -41,7 +41,7 @@ MEDCouplingRemapper::~MEDCouplingRemapper() releaseData(false); } -int MEDCouplingRemapper::prepare(const MEDCouplingMesh *srcMesh, const MEDCouplingMesh *targetMesh, const char *method) +int MEDCouplingRemapper::prepare(const MEDCouplingMesh *srcMesh, const MEDCouplingMesh *targetMesh, const char *method) throw(INTERP_KERNEL::Exception) { releaseData(true); _src_mesh=(MEDCouplingMesh *)srcMesh; _target_mesh=(MEDCouplingMesh *)targetMesh; @@ -58,7 +58,7 @@ int MEDCouplingRemapper::prepare(const MEDCouplingMesh *srcMesh, const MEDCoupli } } -void MEDCouplingRemapper::transfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField, double dftValue) +void MEDCouplingRemapper::transfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception) { if(_src_method!=srcField->getDiscretization()->getStringRepr()) throw INTERP_KERNEL::Exception("Incoherency with prepare call for source field"); @@ -86,7 +86,7 @@ void MEDCouplingRemapper::transfer(const MEDCouplingFieldDouble *srcField, MEDCo computeProduct(inputPointer,srcNbOfCompo,dftValue,resPointer); } -void MEDCouplingRemapper::reverseTransfer(MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *targetField, double dftValue) +void MEDCouplingRemapper::reverseTransfer(MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception) { if(_src_method!=srcField->getDiscretization()->getStringRepr()) throw INTERP_KERNEL::Exception("Incoherency with prepare call for source field"); @@ -114,7 +114,7 @@ void MEDCouplingRemapper::reverseTransfer(MEDCouplingFieldDouble *srcField, cons computeReverseProduct(inputPointer,trgNbOfCompo,dftValue,resPointer); } -MEDCouplingFieldDouble *MEDCouplingRemapper::transferField(const MEDCouplingFieldDouble *srcField, double dftValue) +MEDCouplingFieldDouble *MEDCouplingRemapper::transferField(const MEDCouplingFieldDouble *srcField, double dftValue) throw(INTERP_KERNEL::Exception) { if(_src_method!=srcField->getDiscretization()->getStringRepr()) throw INTERP_KERNEL::Exception("Incoherency with prepare call for source field"); @@ -125,7 +125,7 @@ MEDCouplingFieldDouble *MEDCouplingRemapper::transferField(const MEDCouplingFiel return ret; } -MEDCouplingFieldDouble *MEDCouplingRemapper::reverseTransferField(const MEDCouplingFieldDouble *targetField, double dftValue) +MEDCouplingFieldDouble *MEDCouplingRemapper::reverseTransferField(const MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception) { if(_target_method!=targetField->getDiscretization()->getStringRepr()) throw INTERP_KERNEL::Exception("Incoherency with prepare call for target field"); @@ -151,7 +151,7 @@ bool MEDCouplingRemapper::setOptionString(const std::string& key, std::string& v return INTERP_KERNEL::InterpolationOptions::setOptionString(key,value); } -int MEDCouplingRemapper::prepareUU(const char *method) +int MEDCouplingRemapper::prepareUU(const char *method) throw(INTERP_KERNEL::Exception) { MEDCouplingUMesh *src_mesh=(MEDCouplingUMesh *)_src_mesh; MEDCouplingUMesh *target_mesh=(MEDCouplingUMesh *)_target_mesh; @@ -301,7 +301,7 @@ int MEDCouplingRemapper::prepareUU(const char *method) return 1; } -int MEDCouplingRemapper::prepareEE(const char *method) +int MEDCouplingRemapper::prepareEE(const char *method) throw(INTERP_KERNEL::Exception) { MEDCouplingExtrudedMesh *src_mesh=(MEDCouplingExtrudedMesh *)_src_mesh; MEDCouplingExtrudedMesh *target_mesh=(MEDCouplingExtrudedMesh *)_target_mesh; @@ -365,7 +365,7 @@ void MEDCouplingRemapper::computeDeno(NatureOfField nat, const MEDCouplingFieldD return computeDenoFromScratch(nat,srcField,trgField); } -void MEDCouplingRemapper::computeDenoFromScratch(NatureOfField nat, const MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *trgField) +void MEDCouplingRemapper::computeDenoFromScratch(NatureOfField nat, const MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *trgField) throw(INTERP_KERNEL::Exception) { _nature_of_deno=nat; _time_deno_update=getTimeOfThis(); diff --git a/src/MEDCoupling/MEDCouplingRemapper.hxx b/src/MEDCoupling/MEDCouplingRemapper.hxx index 5e2bd63dd..473ba0c82 100644 --- a/src/MEDCoupling/MEDCouplingRemapper.hxx +++ b/src/MEDCoupling/MEDCouplingRemapper.hxx @@ -24,6 +24,7 @@ #include "MEDCouplingTimeLabel.hxx" #include "InterpolationOptions.hxx" #include "MEDCouplingNatureOfField.hxx" +#include "InterpKernelException.hxx" #include #include @@ -42,23 +43,23 @@ namespace ParaMEDMEM public: MEDCOUPLINGREMAPPER_EXPORT MEDCouplingRemapper(); MEDCOUPLINGREMAPPER_EXPORT ~MEDCouplingRemapper(); - MEDCOUPLINGREMAPPER_EXPORT int prepare(const MEDCouplingMesh *srcMesh, const MEDCouplingMesh *targetMesh, const char *method); - MEDCOUPLINGREMAPPER_EXPORT void transfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField, double dftValue); - MEDCOUPLINGREMAPPER_EXPORT void reverseTransfer(MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *targetField, double dftValue); - MEDCOUPLINGREMAPPER_EXPORT MEDCouplingFieldDouble *transferField(const MEDCouplingFieldDouble *srcField, double dftValue); - MEDCOUPLINGREMAPPER_EXPORT MEDCouplingFieldDouble *reverseTransferField(const MEDCouplingFieldDouble *targetField, double dftValue); + MEDCOUPLINGREMAPPER_EXPORT int prepare(const MEDCouplingMesh *srcMesh, const MEDCouplingMesh *targetMesh, const char *method) throw(INTERP_KERNEL::Exception); + MEDCOUPLINGREMAPPER_EXPORT void transfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception); + MEDCOUPLINGREMAPPER_EXPORT void reverseTransfer(MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception); + MEDCOUPLINGREMAPPER_EXPORT MEDCouplingFieldDouble *transferField(const MEDCouplingFieldDouble *srcField, double dftValue) throw(INTERP_KERNEL::Exception); + MEDCOUPLINGREMAPPER_EXPORT MEDCouplingFieldDouble *reverseTransferField(const MEDCouplingFieldDouble *targetField, double dftValue) throw(INTERP_KERNEL::Exception); MEDCOUPLINGREMAPPER_EXPORT bool setOptionInt(const std::string& key, int value); MEDCOUPLINGREMAPPER_EXPORT bool setOptionDouble(const std::string& key, double value); MEDCOUPLINGREMAPPER_EXPORT bool setOptionString(const std::string& key, std::string& value); public: MEDCOUPLINGREMAPPER_EXPORT static void printMatrix(const std::vector >& m); private: - int prepareUU(const char *method); - int prepareEE(const char *method); + int prepareUU(const char *method) throw(INTERP_KERNEL::Exception); + int prepareEE(const char *method) throw(INTERP_KERNEL::Exception); void updateTime(); void releaseData(bool matrixSuppression); void computeDeno(NatureOfField nat, const MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *trgField); - void computeDenoFromScratch(NatureOfField nat, const MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *trgField); + void computeDenoFromScratch(NatureOfField nat, const MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *trgField) throw(INTERP_KERNEL::Exception); void computeProduct(const double *inputPointer, int inputNbOfCompo, double dftValue, double *resPointer); void computeReverseProduct(const double *inputPointer, int inputNbOfCompo, double dftValue, double *resPointer); void buildFinalInterpolationMatrixByConvolution(const std::vector< std::map >& m1D, diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 9f9061a26..f6254d4fd 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -116,18 +116,17 @@ class MEDCouplingBasicsTest(unittest.TestCase): pass def testMeshM1D(self): meshM1D=MEDCouplingUMesh.New(); - ## CPPUNIT_ASSERT_THROW(meshM1D->getMeshDimension(),INTERP_KERNEL::Exception); - ## CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception); - ## CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfCells(),INTERP_KERNEL::Exception); - ## CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-2),INTERP_KERNEL::Exception); - ## CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-10),INTERP_KERNEL::Exception); - ## CPPUNIT_ASSERT_THROW(meshM1D->checkCoherency(),INTERP_KERNEL::Exception); + self.failUnlessRaises(Exception,meshM1D.getMeshDimension); + self.failUnlessRaises(Exception,meshM1D.getNumberOfNodes); + self.failUnlessRaises(Exception,meshM1D.getNumberOfCells); + self.failUnlessRaises(Exception,meshM1D.setMeshDimension,-2) + self.failUnlessRaises(Exception,meshM1D.setMeshDimension,-10) meshM1D.setMeshDimension(-1); meshM1D.checkCoherency(); self.failUnlessEqual(meshM1D.getMeshDimension(),-1); self.failUnlessEqual(meshM1D.getNumberOfCells(),1); - ## CPPUNIT_ASSERT_THROW(meshM1D.getNumberOfNodes(),INTERP_KERNEL::Exception); - ## CPPUNIT_ASSERT_THROW(meshM1D.getSpaceDimension(),INTERP_KERNEL::Exception); + self.failUnlessRaises(Exception,meshM1D.getNumberOfNodes); + self.failUnlessRaises(Exception,meshM1D.getSpaceDimension); cpy=meshM1D.clone(True); self.failUnless(cpy.isEqual(meshM1D,1e-12)); fieldOnCells=MEDCouplingFieldDouble.New(ON_CELLS); @@ -582,8 +581,8 @@ class MEDCouplingBasicsTest(unittest.TestCase): field.setNature(IntegralGlobConstraint); field=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME); field.setNature(ConservativeVolumic); - #self.failUnless_THROW(field.setNature(Integral),INTERP_KERNEL::Exception); - #self.failUnless_THROW(field.setNature(IntegralGlobConstraint),INTERP_KERNEL::Exception); + self.failUnlessRaises(Exception,field.setNature,Integral); + self.failUnlessRaises(Exception,field.setNature,IntegralGlobConstraint); pass def testBuildSubMeshData(self): @@ -901,7 +900,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.failUnless(abs(0.5-values4[0])<1.e-12); self.failUnless(abs(1.-values4[1])<1.e-12); # - ## self.failUnlessEqual_THROW(f1=m.fillFromAnalytic(ON_NODES,1,func3),Exception); + self.failUnlessRaises(Exception,m.fillFromAnalytic,ON_NODES,1,"1./(x-0.2)"); pass def testFillFromAnalytic2(self): @@ -1078,7 +1077,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): f4.checkCoherency(); self.failUnlessEqual(f4.getTypeOfField(),ON_NODES); self.failUnlessEqual(f4.getTimeDiscretization(),ONE_TIME); - ## self.failUnlessEqual_THROW(f3=f1+f4,Exception); + self.failUnlessRaises(Exception,f1.__add__,f4); f5=f4.buildNewTimeReprFromThis(NO_TIME,False); self.failUnlessEqual(f5.getTypeOfField(),ON_NODES); self.failUnlessEqual(f5.getTimeDiscretization(),NO_TIME); @@ -1094,7 +1093,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): f4.checkCoherency(); self.failUnlessEqual(f4.getTypeOfField(),ON_NODES); self.failUnlessEqual(f4.getTimeDiscretization(),ONE_TIME); - ## self.failUnlessEqual_THROW(f3=f1+f4,Exception); + self.failUnlessRaises(Exception,f1.__add__,f4); f5=f4.buildNewTimeReprFromThis(NO_TIME,True); self.failUnlessEqual(f5.getTypeOfField(),ON_NODES); self.failUnlessEqual(f5.getTimeDiscretization(),NO_TIME); @@ -1168,7 +1167,8 @@ class MEDCouplingBasicsTest(unittest.TestCase): pass # f1=m.buildOrthogonalField(); - ## self.failUnlessEqual_THROW(f2*=f1,INTERP_KERNEL::Exception); + # to avoid valgrind leaks + # self.failUnlessRaises(Exception,f2.__imul__,f1); pass def testOperationsOnFields4(self): @@ -1178,8 +1178,8 @@ class MEDCouplingBasicsTest(unittest.TestCase): f1.setMesh(m); array=DataArrayDouble.New(); f1.setArray(array); - ## self.failUnlessEqual_THROW(f1.setEndArray(array),Exception); - ## self.failUnlessEqual_THROW(f1.getEndArray(),Exception); + self.failUnlessRaises(Exception,f1.setEndArray,array); + self.failUnlessRaises(Exception,f1.getEndArray); arr1=[0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.] arr2=[5.,15.,25.,6.,16.,26.,7.,17.,27.,8.,18.,28.,9.,19.,29.] array.setValues(arr1,nbOfCells,3); @@ -1197,13 +1197,13 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.failUnless(abs(arr1[4]-res[1])<1.e-12); self.failUnless(abs(arr1[5]-res[2])<1.e-12); res=None - ## self.failUnlessEqual_THROW(f1.getValueOn(pos,3.2,res),Exception); + self.failUnlessRaises(Exception,f1.getValueOn,pos,3.2) f2=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME); f2.setMesh(m); f2.setArray(f1.getArray()); f2.setStartTime(2.,3,0); f2.setEndTime(4.,13,0); - ## self.failUnlessEqual_THROW(f2.checkCoherency(),Exception); + self.failUnlessRaises(Exception,f2.checkCoherency) array2=DataArrayDouble.New(); array2.setValues(arr2,nbOfCells,3); f2.setEndArray(array2); @@ -1268,7 +1268,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): f1=targetMesh.fillFromAnalytic(ON_NODES,1,"x+y+z"); tmp=f1.getArray() tmp.setIJ(1,0,1000.); - ## self.failUnlessEqual_THROW(f1.mergeNodes(1e-10),Exception); + self.failUnlessRaises(Exception,f1.mergeNodes,1.e-10) pass def testCheckConsecutiveCellTypes(self): @@ -1468,7 +1468,6 @@ class MEDCouplingBasicsTest(unittest.TestCase): pass def testGetValueOn1(self): - # not implemented yet targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1(); fieldOnCells=MEDCouplingFieldDouble.New(ON_CELLS); nbOfCells=targetMesh.getNumberOfCells(); @@ -1517,7 +1516,6 @@ class MEDCouplingBasicsTest(unittest.TestCase): pass def testCMesh0(self): - # not implemented yet mesh=MEDCouplingCMesh.New(); coordsX=DataArrayDouble.New(); arrX=[ -1., 1., 2., 4. ] @@ -1568,7 +1566,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): m1=MEDCouplingDataForTest.build2DTargetMesh_1(); m2=MEDCouplingDataForTest.build2DSourceMesh_1(); #self.failUnlessEqual(m1.getCoords()!=m2.getCoords()); - ## self.failUnlessEqual_THROW(m1.tryToShareSameCoords(m2,1e-12),Exception); + self.failUnlessRaises(Exception,m1.tryToShareSameCoords,m2,1e-12) pass def testFindNodeOnPlane(self): diff --git a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i index af601f71a..e5a317ce0 100644 --- a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i +++ b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i @@ -65,6 +65,11 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayDouble::performCpy; %newobject ParaMEDMEM::DataArrayInt::deepCopy; %newobject ParaMEDMEM::DataArrayInt::performCpy; +%newobject ParaMEDMEM::DataArrayDouble::aggregate; +%newobject ParaMEDMEM::DataArrayDouble::add; +%newobject ParaMEDMEM::DataArrayDouble::substract; +%newobject ParaMEDMEM::DataArrayDouble::multiply; +%newobject ParaMEDMEM::DataArrayDouble::divide; %newobject ParaMEDMEM::MEDCouplingFieldDouble::clone; %newobject ParaMEDMEM::MEDCouplingFieldDouble::buildNewTimeReprFromThis; %newobject ParaMEDMEM::MEDCouplingMesh::buildOrthogonalField; @@ -83,6 +88,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingCMesh::New; %feature("unref") DataArrayDouble "$this->decrRef();" %feature("unref") MEDCouplingPointSet "$this->decrRef();" +%feature("unref") MEDCouplingMesh "$this->decrRef();" %feature("unref") MEDCouplingUMesh "$this->decrRef();" %feature("unref") MEDCouplingExtrudedMesh "$this->decrRef();" %feature("unref") MEDCouplingCMesh "$this->decrRef();" @@ -94,13 +100,71 @@ using namespace INTERP_KERNEL; %ignore ParaMEDMEM::MemArray::operator=; %ignore ParaMEDMEM::MemArray::operator[]; %ignore ParaMEDMEM::MEDCouplingPointSet::getCoords(); - +%rename (Exception) InterpKernelException; %nodefaultctor; + +namespace INTERP_KERNEL +{ + class Exception + { + public: + Exception(const char* what); + ~Exception() throw (); + const char *what() const throw (); + }; +} + %include "MEDCouplingTimeLabel.hxx" %include "MEDCouplingRefCountObject.hxx" -%include "MEDCouplingMesh.hxx" + +namespace ParaMEDMEM +{ + typedef enum + { + UNSTRUCTURED = 5, + UNSTRUCTURED_DESC = 6, + CARTESIAN = 7, + EXTRUDED = 8 + } MEDCouplingMeshType; + + class DataArrayInt; + class DataArrayDouble; + class MEDCouplingFieldDouble; + + class MEDCOUPLING_EXPORT MEDCouplingMesh : public RefCountObject, public TimeLabel + { + public: + void setName(const char *name) { _name=name; } + const char *getName() const { return _name.c_str(); } + virtual MEDCouplingMeshType getType() const = 0; + virtual bool isEqual(const MEDCouplingMesh *other, double prec) const { return _name==other->_name; } + virtual void checkCoherency() const throw(INTERP_KERNEL::Exception) = 0; + virtual bool isStructured() const = 0; + virtual int getNumberOfCells() const throw(INTERP_KERNEL::Exception) = 0; + virtual int getNumberOfNodes() const throw(INTERP_KERNEL::Exception) = 0; + virtual int getSpaceDimension() const throw(INTERP_KERNEL::Exception) = 0; + virtual int getMeshDimension() const throw(INTERP_KERNEL::Exception) = 0; + virtual DataArrayDouble *getCoordinatesAndOwner() const = 0; + virtual DataArrayDouble *getBarycenterAndOwner() const = 0; + virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const = 0; + virtual void getNodeIdsOfCell(int cellId, std::vector& conn) const = 0; + virtual void getCoordinatesOfNode(int nodeId, std::vector& coo) const = 0; + // tools + virtual void getBoundingBox(double *bbox) const = 0; + virtual MEDCouplingFieldDouble *getMeasureField(bool isAbs) const = 0; + virtual MEDCouplingFieldDouble *getMeasureFieldOnNode(bool isAbs) const = 0; + virtual int getCellContainingPoint(const double *pos, double eps) const = 0; + virtual MEDCouplingFieldDouble *fillFromAnalytic(TypeOfField t, int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingFieldDouble *buildOrthogonalField() const = 0; + virtual void rotate(const double *center, const double *vector, double angle) = 0; + virtual void translate(const double *vector) = 0; + virtual MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const throw(INTERP_KERNEL::Exception) = 0; + virtual bool areCompatible(const MEDCouplingMesh *other) const; + static MEDCouplingMesh *mergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2); + }; +} + %include "MEDCouplingMemArray.hxx" -%include "MEDCouplingMesh.hxx" %include "NormalizedUnstructuredMesh.hxx" %include "MEDCouplingNatureOfField.hxx" %include "MEDCouplingTimeDiscretization.hxx" @@ -112,8 +176,6 @@ namespace ParaMEDMEM public: void updateTime(); bool isStructured() const; - int getNumberOfNodes() const; - int getSpaceDimension() const; void setCoords(DataArrayDouble *coords); DataArrayDouble *getCoordinatesAndOwner() const; bool isEqual(const MEDCouplingMesh *other, double prec) const; @@ -131,7 +193,6 @@ namespace ParaMEDMEM virtual MEDCouplingPointSet *buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const = 0; virtual MEDCouplingPointSet *buildPartOfMySelfNode(const int *start, const int *end, bool fullyIn) const = 0; virtual MEDCouplingPointSet *buildFacePartOfMySelfNode(const int *start, const int *end, bool fullyIn) const = 0; - virtual void findBoundaryNodes(std::vector& nodes) const = 0; virtual MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const = 0; virtual void renumberNodes(const int *newNodeNumbers, int newNbOfNodes); virtual bool isEmptyMesh(const std::vector& tinyInfo) const = 0; @@ -281,7 +342,7 @@ namespace ParaMEDMEM MEDCouplingUMesh *clone(bool recDeepCpy) const; void updateTime(); void checkCoherency() const throw(INTERP_KERNEL::Exception); - void setMeshDimension(int meshDim); + void setMeshDimension(int meshDim) throw(INTERP_KERNEL::Exception); void allocateCells(int nbOfCells); void finishInsertingCells(); void setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes=true); @@ -378,7 +439,7 @@ namespace ParaMEDMEM return convertIntArrToPyList2(elts); } - static PyObject *mergeUMeshesOnSameCoords(PyObject *ms) + static PyObject *mergeUMeshesOnSameCoords(PyObject *ms) throw(INTERP_KERNEL::Exception) { std::vector meshes; if(PyList_Check(ms)) @@ -422,7 +483,7 @@ namespace ParaMEDMEM } void convertToPolyTypes(const std::vector& cellIdsToConvert); MEDCouplingUMesh *buildExtrudedMeshFromThis(const MEDCouplingUMesh *mesh1D, int policy); - static MEDCouplingUMesh *mergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2); + static MEDCouplingUMesh *mergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); }; class MEDCouplingExtrudedMesh : public ParaMEDMEM::MEDCouplingMesh @@ -514,7 +575,7 @@ namespace ParaMEDMEM class MEDCouplingField : public ParaMEDMEM::RefCountObject, public ParaMEDMEM::TimeLabel { public: - virtual void checkCoherency() const; + virtual void checkCoherency() const throw(INTERP_KERNEL::Exception); virtual bool areCompatible(const MEDCouplingField *other) const; virtual bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const; void setMesh(const ParaMEDMEM::MEDCouplingMesh *mesh); @@ -556,53 +617,71 @@ namespace ParaMEDMEM TypeOfTimeDiscretization getTimeDiscretization() const; void checkCoherency() const throw(INTERP_KERNEL::Exception); double getIJ(int tupleId, int compoId) const; - void setArray(DataArrayDouble *array); - void setEndArray(DataArrayDouble *array); - void setTime(double val, int dt, int it); - void setStartTime(double val, int dt, int it); - void setEndTime(double val, int dt, int it); - DataArrayDouble *getArray() const; - DataArrayDouble *getEndArray() const; - void applyLin(double a, double b, int compoId); + void setArray(DataArrayDouble *array) throw(INTERP_KERNEL::Exception); + void setEndArray(DataArrayDouble *array) throw(INTERP_KERNEL::Exception); + void setTime(double val, int dt, int it) throw(INTERP_KERNEL::Exception); + void setStartTime(double val, int dt, int it) throw(INTERP_KERNEL::Exception); + void setEndTime(double val, int dt, int it) throw(INTERP_KERNEL::Exception); + DataArrayDouble *getArray() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *getEndArray() const throw(INTERP_KERNEL::Exception); + void applyLin(double a, double b, int compoId) throw(INTERP_KERNEL::Exception); int getNumberOfComponents() const; int getNumberOfTuples() const throw(INTERP_KERNEL::Exception); NatureOfField getNature() const { return _nature; } void setNature(NatureOfField nat) throw(INTERP_KERNEL::Exception); void updateTime(); - bool mergeNodes(double eps); - void applyFunc(int nbOfComp, const char *func); - void applyFunc(const char *func); - double accumulate(int compId) const; - double measureAccumulate(int compId, bool isWAbs) const; - static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); - MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const; - const MEDCouplingFieldDouble &operator+=(const MEDCouplingFieldDouble& other); - MEDCouplingFieldDouble *operator-(const MEDCouplingFieldDouble& other) const; - const MEDCouplingFieldDouble &operator-=(const MEDCouplingFieldDouble& other); - MEDCouplingFieldDouble *operator*(const MEDCouplingFieldDouble& other) const; - const MEDCouplingFieldDouble &operator*=(const MEDCouplingFieldDouble& other); - MEDCouplingFieldDouble *operator/(const MEDCouplingFieldDouble& other) const; - const MEDCouplingFieldDouble &operator/=(const MEDCouplingFieldDouble& other); + bool mergeNodes(double eps) throw(INTERP_KERNEL::Exception); + void applyFunc(int nbOfComp, const char *func) throw(INTERP_KERNEL::Exception); + void applyFunc(const char *func) throw(INTERP_KERNEL::Exception); + double accumulate(int compId) const throw(INTERP_KERNEL::Exception); + double measureAccumulate(int compId, bool isWAbs) const throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); + const MEDCouplingFieldDouble &operator+=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *operator-(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); + const MEDCouplingFieldDouble &operator-=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *operator*(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); + const MEDCouplingFieldDouble &operator*=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *operator/(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); + const MEDCouplingFieldDouble &operator/=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); %extend { - PyObject *getValueOn(PyObject *sl) const + PyObject *getValueOn(PyObject *sl) const throw(INTERP_KERNEL::Exception) { int sz; double *spaceLoc=convertPyToNewDblArr2(sl,&sz); sz=self->getNumberOfComponents(); double *res=new double[sz]; - self->getValueOn(spaceLoc,res); + try + { + self->getValueOn(spaceLoc,res); + } + catch(INTERP_KERNEL::Exception& e) + { + delete [] spaceLoc; + delete [] res; + throw e; + } delete [] spaceLoc; PyObject *ret=convertDblArrToPyList(res,sz); delete [] res; return ret; } - PyObject *getValueOn(PyObject *sl, double time) const + PyObject *getValueOn(PyObject *sl, double time) const throw(INTERP_KERNEL::Exception) { int sz; double *spaceLoc=convertPyToNewDblArr2(sl,&sz); sz=self->getNumberOfComponents(); double *res=new double[sz]; - self->getValueOn(spaceLoc,time,res); + try + { + self->getValueOn(spaceLoc,time,res); + } + catch(INTERP_KERNEL::Exception& e) + { + delete [] spaceLoc; + delete [] res; + throw e; + } delete [] spaceLoc; PyObject *ret=convertDblArrToPyList(res,sz); delete [] res;