From: ageay Date: Thu, 4 Apr 2013 07:49:06 +0000 (+0000) Subject: Protections on Fields against null pointers X-Git-Tag: V6_main_FINAL~211 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6178737095518f83b5125a610e091a841d4a5a11;p=tools%2Fmedcoupling.git Protections on Fields against null pointers --- diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index 12c7138fd..4f3fc3e56 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -77,6 +77,10 @@ bool MEDCouplingField::isEqual(const MEDCouplingField *other, double meshPrec, d bool MEDCouplingField::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const { + if(!other) + throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualWithoutConsideringStr : input field is NULL !"); + if(!_type) + throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualWithoutConsideringStr : spatial discretization of this is NULL !"); if(!_type->isEqualWithoutConsideringStr(other->_type,valsPrec)) return false; if(_nature!=other->_nature) @@ -97,6 +101,8 @@ bool MEDCouplingField::isEqualWithoutConsideringStr(const MEDCouplingField *othe */ bool MEDCouplingField::areCompatibleForMerge(const MEDCouplingField *other) const { + if(!other) + throw INTERP_KERNEL::Exception("MEDCouplingField::areCompatibleForMerge : input field is NULL !"); if(!_type->isEqual(other->_type,1.)) return false; if(_nature!=other->_nature) @@ -112,6 +118,8 @@ bool MEDCouplingField::areCompatibleForMerge(const MEDCouplingField *other) cons */ bool MEDCouplingField::areStrictlyCompatible(const MEDCouplingField *other) const { + if(!other) + throw INTERP_KERNEL::Exception("MEDCouplingField::areStrictlyCompatible : input field is NULL !"); if(!_type->isEqual(other->_type,1.e-12)) return false; if(_nature!=other->_nature) @@ -161,6 +169,7 @@ NatureOfField MEDCouplingField::getNature() const */ void MEDCouplingField::setNature(NatureOfField nat) throw(INTERP_KERNEL::Exception) { + MEDCouplingNatureOfField::GetRepr(nat);//generate a throw if nat not recognized _nature=nat; } @@ -174,6 +183,8 @@ DataArrayDouble *MEDCouplingField::getLocalizationOfDiscr() const throw(INTERP_K { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingField::getLocalizationOfDiscr : No mesh set !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("MEDCouplingField::getLocalizationOfDiscr : No spatial discretization set !"); return _type->getLocalizationOfDiscValues(_mesh); } @@ -183,8 +194,10 @@ DataArrayDouble *MEDCouplingField::getLocalizationOfDiscr() const throw(INTERP_K */ MEDCouplingFieldDouble *MEDCouplingField::buildMeasureField(bool isAbs) const throw(INTERP_KERNEL::Exception) { - if(_mesh==0) - throw INTERP_KERNEL::Exception("MEDCouplingField::getMeasureField : no mesh defined !!!"); + if(!_mesh) + throw INTERP_KERNEL::Exception("MEDCouplingField::buildMeasureField : no mesh defined !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("MEDCouplingField::buildMeasureField : No spatial discretization set !"); return _type->getMeasureField(_mesh,isAbs); } @@ -217,6 +230,8 @@ void MEDCouplingField::setGaussLocalizationOnType(INTERP_KERNEL::NormalizedCellT { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling setGaussLocalizationOnType method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call setGaussLocalizationOnType method !"); _type->setGaussLocalizationOnType(_mesh,type,refCoo,gsCoo,wg); } @@ -235,6 +250,8 @@ void MEDCouplingField::setGaussLocalizationOnCells(const int *begin, const int * { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling setGaussLocalizationOnCells method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call setGaussLocalizationOnCells method !"); _type->setGaussLocalizationOnCells(_mesh,begin,end,refCoo,gsCoo,wg); } @@ -245,6 +262,8 @@ void MEDCouplingField::clearGaussLocalizations() { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling clearGaussLocalizations method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call clearGaussLocalizations method !"); _type->clearGaussLocalizations(); } @@ -258,6 +277,8 @@ MEDCouplingGaussLocalization& MEDCouplingField::getGaussLocalization(int locId) { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalization method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalization method !"); return _type->getGaussLocalization(locId); } @@ -270,6 +291,8 @@ int MEDCouplingField::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedC { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdOfOneType method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalizationIdOfOneType method !"); return _type->getGaussLocalizationIdOfOneType(type); } @@ -277,6 +300,8 @@ std::set MEDCouplingField::getGaussLocalizationIdsOfOneType(INTERP_KERNEL:: { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdsOfOneType method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalizationIdsOfOneType method !"); return _type->getGaussLocalizationIdsOfOneType(type); } @@ -288,6 +313,8 @@ int MEDCouplingField::getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exce { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling getNbOfGaussLocalization method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getNbOfGaussLocalization method !"); return _type->getNbOfGaussLocalization(); } @@ -300,6 +327,8 @@ int MEDCouplingField::getGaussLocalizationIdOfOneCell(int cellId) const throw(IN { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdOfOneCell method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalizationIdOfOneCell method !"); return _type->getGaussLocalizationIdOfOneCell(cellId); } @@ -315,6 +344,8 @@ void MEDCouplingField::getCellIdsHavingGaussLocalization(int locId, std::vector< cellIds.clear(); if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdOfOneCell method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getCellIdsHavingGaussLocalization method !"); _type->getCellIdsHavingGaussLocalization(locId,cellIds); } @@ -328,6 +359,8 @@ const MEDCouplingGaussLocalization& MEDCouplingField::getGaussLocalization(int l { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalization method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalization method !"); return _type->getGaussLocalization(locId); } @@ -365,6 +398,8 @@ MEDCouplingField::MEDCouplingField(const MEDCouplingField& other, bool deepCopy) */ MEDCouplingMesh *MEDCouplingField::buildSubMeshData(const int *start, const int *end, DataArrayInt *&di) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call buildSubMeshData method !"); return _type->buildSubMeshData(_mesh,start,end,di); } @@ -374,6 +409,8 @@ MEDCouplingMesh *MEDCouplingField::buildSubMeshData(const int *start, const int */ DataArrayInt *MEDCouplingField::computeTupleIdsToSelectFromCellIds(const int *startCellIds, const int *endCellIds) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call computeTupleIdsToSelectFromCellIds method !"); return _type->computeTupleIdsToSelectFromCellIds(_mesh,startCellIds,endCellIds); } @@ -383,6 +420,8 @@ DataArrayInt *MEDCouplingField::computeTupleIdsToSelectFromCellIds(const int *st */ int MEDCouplingField::getNumberOfTuplesExpected() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getNumberOfTuplesExpected method !"); if(_mesh) return _type->getNumberOfTuples(_mesh); else @@ -391,9 +430,12 @@ int MEDCouplingField::getNumberOfTuplesExpected() const throw(INTERP_KERNEL::Exc void MEDCouplingField::setDiscretization(MEDCouplingFieldDiscretization *newDisc) { + bool needUpdate=(const MEDCouplingFieldDiscretization *)_type!=newDisc; _type=newDisc; if(newDisc) newDisc->incrRef(); + if(needUpdate) + declareAsNew(); } /*! @@ -402,6 +444,8 @@ void MEDCouplingField::setDiscretization(MEDCouplingFieldDiscretization *newDisc */ int MEDCouplingField::getNumberOfMeshPlacesExpected() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getNumberOfMeshPlacesExpected method !"); if(_mesh) return _type->getNumberOfMeshPlaces(_mesh); else diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 297a8de77..1180cf43c 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -434,6 +434,11 @@ const char *MEDCouplingFieldDiscretizationP0::getRepr() const bool MEDCouplingFieldDiscretizationP0::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (P0) is defined."; + return false; + } const MEDCouplingFieldDiscretizationP0 *otherC=dynamic_cast(other); bool ret=otherC!=0; if(!ret) @@ -443,16 +448,22 @@ bool MEDCouplingFieldDiscretizationP0::isEqualIfNotWhy(const MEDCouplingFieldDis int MEDCouplingFieldDiscretizationP0::getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfTuples : NULL input mesh !"); return mesh->getNumberOfCells(); } int MEDCouplingFieldDiscretizationP0::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfMeshPlaces : NULL input mesh !"); return mesh->getNumberOfCells(); } DataArrayInt *MEDCouplingFieldDiscretizationP0::getOffsetArr(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getOffsetArr : NULL input mesh !"); int nbOfTuples=mesh->getNumberOfCells(); DataArrayInt *ret=DataArrayInt::New(); ret->alloc(nbOfTuples+1,1); @@ -463,6 +474,8 @@ DataArrayInt *MEDCouplingFieldDiscretizationP0::getOffsetArr(const MEDCouplingMe void MEDCouplingFieldDiscretizationP0::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::renumberArraysForCell : NULL input mesh !"); const int *array=old2NewBg; if(check) array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells()); @@ -477,6 +490,8 @@ void MEDCouplingFieldDiscretizationP0::renumberArraysForCell(const MEDCouplingMe DataArrayDouble *MEDCouplingFieldDiscretizationP0::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getLocalizationOfDiscValues : NULL input mesh !"); return mesh->getBarycenterAndOwner(); } @@ -504,6 +519,8 @@ void MEDCouplingFieldDiscretizationP0::checkCompatibilityWithNature(NatureOfFiel void MEDCouplingFieldDiscretizationP0::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::checkCoherencyBetween : NULL input mesh !"); if(mesh->getNumberOfCells()!=da->getNumberOfTuples()) { std::ostringstream message; @@ -522,6 +539,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationP0::getMeasureField(const void MEDCouplingFieldDiscretizationP0::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getValueOn : NULL input mesh !"); int id=mesh->getCellContainingPoint(loc,_precision); if(id==-1) throw INTERP_KERNEL::Exception("Specified point is detected outside of mesh : unable to apply P0::getValueOn !"); @@ -539,6 +558,8 @@ void MEDCouplingFieldDiscretizationP0::getValueOnPos(const DataArrayDouble *arr, DataArrayDouble *MEDCouplingFieldDiscretizationP0::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getValueOnMulti : NULL input mesh !"); std::vector elts,eltsIndex; mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,elts,eltsIndex); int spaceDim=mesh->getSpaceDimension(); @@ -599,6 +620,8 @@ DataArrayInt *MEDCouplingFieldDiscretizationP0::computeTupleIdsToSelectFromCellI */ MEDCouplingMesh *MEDCouplingFieldDiscretizationP0::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::buildSubMeshData : NULL input mesh !"); MEDCouplingMesh *ret=mesh->buildPart(start,end); di=DataArrayInt::New(); di->alloc((int)std::distance(start,end),1); @@ -609,11 +632,15 @@ MEDCouplingMesh *MEDCouplingFieldDiscretizationP0::buildSubMeshData(const MEDCou int MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getNumberOfTuples : NULL input mesh !"); return mesh->getNumberOfNodes(); } int MEDCouplingFieldDiscretizationOnNodes::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getNumberOfMeshPlaces : NULL input mesh !"); return mesh->getNumberOfNodes(); } @@ -627,6 +654,8 @@ void MEDCouplingFieldDiscretizationOnNodes::renumberArraysForCell(const MEDCoupl DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::getOffsetArr(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getOffsetArr : NULL input mesh !"); int nbOfTuples=mesh->getNumberOfNodes(); DataArrayInt *ret=DataArrayInt::New(); ret->alloc(nbOfTuples+1,1); @@ -636,6 +665,8 @@ DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::getOffsetArr(const MEDCoupl DataArrayDouble *MEDCouplingFieldDiscretizationOnNodes::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getLocalizationOfDiscValues : NULL input mesh !"); return mesh->getCoordinatesAndOwner(); } @@ -656,6 +687,8 @@ void MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds(c void MEDCouplingFieldDiscretizationOnNodes::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::checkCoherencyBetween : NULL input mesh !"); if(mesh->getNumberOfNodes()!=da->getNumberOfTuples()) { std::ostringstream message; @@ -672,6 +705,8 @@ void MEDCouplingFieldDiscretizationOnNodes::checkCoherencyBetween(const MEDCoupl */ MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::buildSubMeshData : NULL input mesh !"); MEDCouplingMesh *ret=mesh->buildPartAndReduceNodes(start,end,di); DataArrayInt *di2=di->invertArrayO2N2N2O(ret->getNumberOfNodes()); di->decrRef(); @@ -690,7 +725,7 @@ MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData(const M DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const { if(!mesh) - throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::computeTupleIdsToSelectFromCellIds : null mesh !"); + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::computeTupleIdsToSelectFromCellIds : NULL input mesh !"); const MEDCouplingAutoRefCountObjectPtr umesh=mesh->buildUnstructured(); MEDCouplingAutoRefCountObjectPtr umesh2=static_cast(umesh->buildPartOfMySelf(startCellIds,endCellIds,true)); return umesh2->computeFetchedNodeIds(); @@ -751,6 +786,11 @@ const char *MEDCouplingFieldDiscretizationP1::getRepr() const bool MEDCouplingFieldDiscretizationP1::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (P1) is defined."; + return false; + } const MEDCouplingFieldDiscretizationP1 *otherC=dynamic_cast(other); bool ret=otherC!=0; if(!ret) @@ -773,6 +813,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationP1::getMeasureField(const void MEDCouplingFieldDiscretizationP1::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueOn : NULL input mesh !"); int id=mesh->getCellContainingPoint(loc,_precision); if(id==-1) throw INTERP_KERNEL::Exception("Specified point is detected outside of mesh : unable to apply P1::getValueOn !"); @@ -788,6 +830,8 @@ void MEDCouplingFieldDiscretizationP1::getValueOn(const DataArrayDouble *arr, co */ void MEDCouplingFieldDiscretizationP1::getValueInCell(const MEDCouplingMesh *mesh, int cellId, const DataArrayDouble *arr, const double *loc, double *res) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueInCell : NULL input mesh !"); std::vector conn; std::vector coo; mesh->getNodeIdsOfCell(cellId,conn); @@ -813,6 +857,8 @@ void MEDCouplingFieldDiscretizationP1::getValueInCell(const MEDCouplingMesh *mes DataArrayDouble *MEDCouplingFieldDiscretizationP1::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueOnMulti : NULL input mesh !"); std::vector elts,eltsIndex; mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,elts,eltsIndex); int spaceDim=mesh->getSpaceDimension(); @@ -881,6 +927,8 @@ void MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(const MEDCoupl { if(!_discr_per_cell) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell has no discretization per cell !"); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween : NULL input mesh !"); int nbOfTuples=_discr_per_cell->getNumberOfTuples(); if(nbOfTuples!=mesh->getNumberOfCells()) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell has a discretization per cell but it's not matching the underlying mesh !"); @@ -888,10 +936,15 @@ void MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(const MEDCoupl bool MEDCouplingFieldDiscretizationPerCell::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (PerCell) is defined."; + return false; + } const MEDCouplingFieldDiscretizationPerCell *otherC=dynamic_cast(other); if(!otherC) { - reason="Spatial discrtization of this is ON_GAUSS, which is not the case of other."; + reason="Spatial discretization of this is ON_GAUSS, which is not the case of other."; return false; } if(_discr_per_cell==0) @@ -935,12 +988,14 @@ void MEDCouplingFieldDiscretizationPerCell::renumberCells(const int *old2NewBg, delete [] const_cast(array); } -void MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary(const MEDCouplingMesh *m) +void MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary(const MEDCouplingMesh *mesh) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary : NULL input mesh !"); if(!_discr_per_cell) { _discr_per_cell=DataArrayInt::New(); - int nbTuples=m->getNumberOfCells(); + int nbTuples=mesh->getNumberOfCells(); _discr_per_cell->alloc(nbTuples,1); int *ptr=_discr_per_cell->getPointer(); std::fill(ptr,ptr+nbTuples,DFT_INVALID_LOCID_VALUE); @@ -1006,6 +1061,11 @@ TypeOfField MEDCouplingFieldDiscretizationGauss::getEnum() const bool MEDCouplingFieldDiscretizationGauss::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (Gauss) is defined."; + return false; + } const MEDCouplingFieldDiscretizationGauss *otherC=dynamic_cast(other); if(!otherC) { @@ -1111,11 +1171,15 @@ int MEDCouplingFieldDiscretizationGauss::getNumberOfTuples(const MEDCouplingMesh int MEDCouplingFieldDiscretizationGauss::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfMeshPlaces : NULL input mesh !"); return mesh->getNumberOfCells(); } DataArrayInt *MEDCouplingFieldDiscretizationGauss::getOffsetArr(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getOffsetArr : NULL input mesh !"); int nbOfTuples=mesh->getNumberOfCells(); MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(nbOfTuples+1,1); @@ -1141,6 +1205,8 @@ DataArrayInt *MEDCouplingFieldDiscretizationGauss::getOffsetArr(const MEDCouplin void MEDCouplingFieldDiscretizationGauss::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::renumberArraysForCell : NULL input mesh !"); const int *array=old2NewBg; if(check) array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells()); @@ -1170,6 +1236,8 @@ void MEDCouplingFieldDiscretizationGauss::renumberArraysForCell(const MEDCouplin DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getLocalizationOfDiscValues : NULL input mesh !"); checkNoOrphanCells(); MEDCouplingAutoRefCountObjectPtr umesh=mesh->buildUnstructured();//in general do nothing int nbOfTuples=getNumberOfTuples(mesh); @@ -1299,6 +1367,8 @@ double MEDCouplingFieldDiscretizationGauss::getIJK(const MEDCouplingMesh *mesh, void MEDCouplingFieldDiscretizationGauss::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::checkCoherencyBetween : NULL input mesh !"); MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(mesh,da); for(std::vector::const_iterator iter=_loc.begin();iter!=_loc.end();iter++) (*iter).checkCoherency(); @@ -1398,6 +1468,8 @@ DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getValueOnMulti(const Data MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshData : NULL input mesh !"); di=computeTupleIdsToSelectFromCellIds(mesh,start,end); return mesh->buildPart(start,end); } @@ -1449,41 +1521,45 @@ void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCellsR(const MEDCoupli throw INTERP_KERNEL::Exception("Number of cells has changed and becomes higher with some cells that have been split ! Unable to conserve the Gauss field !"); } -void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, +void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType(const MEDCouplingMesh *mesh, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType : NULL input mesh !"); const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type); - if((int)cm.getDimension()!=m->getMeshDimension()) + if((int)cm.getDimension()!=mesh->getMeshDimension()) { - std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType : mismatch of dimensions ! MeshDim==" << m->getMeshDimension(); + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType : mismatch of dimensions ! MeshDim==" << mesh->getMeshDimension(); oss << " whereas Type '" << cm.getRepr() << "' has dimension " << cm.getDimension() << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - buildDiscrPerCellIfNecessary(m); + buildDiscrPerCellIfNecessary(mesh); int id=(int)_loc.size(); MEDCouplingGaussLocalization elt(type,refCoo,gsCoo,wg); _loc.push_back(elt); int *ptr=_discr_per_cell->getPointer(); - int nbCells=m->getNumberOfCells(); + int nbCells=mesh->getNumberOfCells(); for(int i=0;igetTypeOfCell(i)==type) + if(mesh->getTypeOfCell(i)==type) ptr[i]=id; zipGaussLocalizations(); } -void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector& refCoo, +void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells(const MEDCouplingMesh *mesh, const int *begin, const int *end, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) { - buildDiscrPerCellIfNecessary(m); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells : NULL input mesh !"); + buildDiscrPerCellIfNecessary(mesh); if(std::distance(begin,end)<1) throw INTERP_KERNEL::Exception("Size of [begin,end) must be equal or greater than 1 !"); - INTERP_KERNEL::NormalizedCellType type=m->getTypeOfCell(*begin); + INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(*begin); MEDCouplingGaussLocalization elt(type,refCoo,gsCoo,wg); int id=(int)_loc.size(); int *ptr=_discr_per_cell->getPointer(); for(const int *w=begin+1;w!=end;w++) { - if(m->getTypeOfCell(*w)!=type) + if(mesh->getTypeOfCell(*w)!=type) { std::ostringstream oss; oss << "The cell with id " << *w << " has been detected to be incompatible in the [begin,end) array specified !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); @@ -1692,6 +1768,11 @@ const char *MEDCouplingFieldDiscretizationGaussNE::getRepr() const bool MEDCouplingFieldDiscretizationGaussNE::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (GaussNE) is defined."; + return false; + } const MEDCouplingFieldDiscretizationGaussNE *otherC=dynamic_cast(other); bool ret=otherC!=0; if(!ret) @@ -1701,6 +1782,8 @@ bool MEDCouplingFieldDiscretizationGaussNE::isEqualIfNotWhy(const MEDCouplingFie int MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples : NULL input mesh !"); int ret=0; int nbOfCells=mesh->getNumberOfCells(); for(int i=0;igetNumberOfCells(); } DataArrayInt *MEDCouplingFieldDiscretizationGaussNE::getOffsetArr(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getOffsetArr : NULL input mesh !"); int nbOfTuples=mesh->getNumberOfCells(); DataArrayInt *ret=DataArrayInt::New(); ret->alloc(nbOfTuples+1,1); @@ -1740,6 +1827,8 @@ DataArrayInt *MEDCouplingFieldDiscretizationGaussNE::getOffsetArr(const MEDCoupl void MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell : NULL input mesh !"); const int *array=old2NewBg; if(check) array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells()); @@ -1773,6 +1862,8 @@ void MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell(const MEDCoupl DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscValues : NULL input mesh !"); MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); MEDCouplingAutoRefCountObjectPtr umesh=mesh->buildUnstructured();//in general do nothing int nbOfTuples=getNumberOfTuples(umesh); @@ -1961,6 +2052,8 @@ void MEDCouplingFieldDiscretizationGaussNE::checkCompatibilityWithNature(NatureO double MEDCouplingFieldDiscretizationGaussNE::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, int cellId, int nodeIdInCell, int compoId) const throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getIJK : NULL input mesh !"); int offset=0; for(int i=0;ibuildPart(start,end); } @@ -2113,6 +2208,11 @@ void MEDCouplingFieldDiscretizationKriging::checkCompatibilityWithNature(NatureO bool MEDCouplingFieldDiscretizationKriging::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (Kriginig) is defined."; + return false; + } const MEDCouplingFieldDiscretizationKriging *otherC=dynamic_cast(other); bool ret=otherC!=0; if(!ret) @@ -2135,6 +2235,8 @@ void MEDCouplingFieldDiscretizationKriging::getValueOn(const DataArrayDouble *ar DataArrayDouble *MEDCouplingFieldDiscretizationKriging::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfTargetPoints) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::getValueOnMulti : NULL input mesh !"); MEDCouplingAutoRefCountObjectPtr coords=getLocalizationOfDiscValues(mesh); int nbOfPts=coords->getNumberOfTuples(); int dimension=coords->getNumberOfComponents(); @@ -2184,6 +2286,8 @@ void MEDCouplingFieldDiscretizationKriging::reprQuickOverview(std::ostream& stre */ DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeVectorOfCoefficients(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, int& isDrift) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::computeVectorOfCoefficients : NULL input mesh !"); MEDCouplingAutoRefCountObjectPtr coords=getLocalizationOfDiscValues(mesh); int nbOfPts=coords->getNumberOfTuples(); //int dimension=coords->getNumberOfComponents(); diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index 5363e458c..96da042d0 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -205,7 +205,7 @@ namespace ParaMEDMEM bool isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const; void renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception); protected: - void buildDiscrPerCellIfNecessary(const MEDCouplingMesh *m); + void buildDiscrPerCellIfNecessary(const MEDCouplingMesh *mesh); protected: DataArrayInt *_discr_per_cell; static const int DFT_INVALID_LOCID_VALUE; @@ -248,9 +248,9 @@ namespace ParaMEDMEM void renumberValuesOnNodes(double epsOnVals, const int *old2New, int newNbOfNodes, DataArrayDouble *arr) const; void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const; void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const; - void setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, + void setGaussLocalizationOnType(const MEDCouplingMesh *mesh, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception); - void setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector& refCoo, + void setGaussLocalizationOnCells(const MEDCouplingMesh *mesh, const int *begin, const int *end, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception); void clearGaussLocalizations() throw(INTERP_KERNEL::Exception); void setGaussLocalization(int locId, const MEDCouplingGaussLocalization& loc) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 27377d972..7d303c54e 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -169,7 +169,10 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::deepCpy() const MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCopy) const { MEDCouplingTimeDiscretization *tdo=_time_discr->buildNewTimeReprFromThis(td,deepCopy); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),tdo,_type->clone()); + MEDCouplingAutoRefCountObjectPtr disc; + if(_type) + disc=_type->clone(); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),tdo,disc.retn()); ret->setMesh(getMesh()); ret->setName(getName()); ret->setDescription(getDescription()); @@ -250,8 +253,14 @@ std::string MEDCouplingFieldDouble::advancedRepr() const std::ostringstream ret; ret << "FieldDouble with name : \"" << getName() << "\"\n"; ret << "Description of field is : \"" << getDescription() << "\"\n"; - ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; - ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; + if(_type) + { ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; } + else + { ret << "FieldDouble has no space discretization set !\n"; } + if(_time_discr) + { ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; } + else + { ret << "FieldDouble has no time discretization set !\n"; } if(getArray()) ret << "FieldDouble default array has " << getArray()->getNumberOfComponents() << " components and " << getArray()->getNumberOfTuples() << " tuples.\n"; if(_mesh) @@ -412,7 +421,9 @@ void MEDCouplingFieldDouble::renumberCells(const int *old2NewBg, bool check) thr void MEDCouplingFieldDouble::renumberCellsWithoutMesh(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { if(!_mesh) - throw INTERP_KERNEL::Exception("Expecting a defined mesh to be able to operate a renumbering !"); + throw INTERP_KERNEL::Exception("Expecting a defined mesh to be able to operate a renumbering !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !"); // _type->renumberCells(old2NewBg,check); std::vector arrays; @@ -446,6 +457,8 @@ void MEDCouplingFieldDouble::renumberNodes(const int *old2NewBg) throw(INTERP_KE */ void MEDCouplingFieldDouble::renumberNodesWithoutMesh(const int *old2NewBg, int newNbOfNodes, double eps) throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !"); std::vector arrays; _time_discr->getArrays(arrays); for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) @@ -523,6 +536,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const DataArrayInt */ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const int *partBg, const int *partEnd) const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !"); DataArrayInt *arrSelect; MEDCouplingAutoRefCountObjectPtr m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect); MEDCouplingAutoRefCountObjectPtr arrSelect2(arrSelect); @@ -586,6 +601,8 @@ void MEDCouplingFieldDouble::checkCoherency() const throw(INTERP_KERNEL::Excepti { if(!_mesh) throw INTERP_KERNEL::Exception("Field invalid because no mesh specified !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::checkCoherency : no spatial discretization !"); _time_discr->checkCoherency(); _type->checkCoherencyBetween(_mesh,getArray()); } @@ -820,7 +837,9 @@ double MEDCouplingFieldDouble::getWeightedAverageValue(int compId, bool isWAbs) double MEDCouplingFieldDouble::normL1(int compId) const throw(INTERP_KERNEL::Exception) { if(!_mesh) - throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1"); + throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1 !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL1 !"); int nbComps=getArray()->getNumberOfComponents(); if(compId<0 || compId>=nbComps) { @@ -843,6 +862,8 @@ void MEDCouplingFieldDouble::normL1(double *res) const throw(INTERP_KERNEL::Exce { if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL1 !"); _type->normL1(_mesh,getArray(),res); } @@ -857,6 +878,8 @@ double MEDCouplingFieldDouble::normL2(int compId) const throw(INTERP_KERNEL::Exc { if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL2"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL2 !"); int nbComps=getArray()->getNumberOfComponents(); if(compId<0 || compId>=nbComps) { @@ -879,6 +902,8 @@ void MEDCouplingFieldDouble::normL2(double *res) const throw(INTERP_KERNEL::Exce { if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL2"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL2 !"); _type->normL2(_mesh,getArray(),res); } @@ -891,6 +916,8 @@ double MEDCouplingFieldDouble::integral(int compId, bool isWAbs) const throw(INT { if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform integral"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform integral !"); int nbComps=getArray()->getNumberOfComponents(); if(compId<0 || compId>=nbComps) { @@ -911,6 +938,8 @@ void MEDCouplingFieldDouble::integral(bool isWAbs, double *res) const throw(INTE { if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform integral2"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform integral2 !"); _type->integral(_mesh,getArray(),isWAbs,res); } @@ -924,6 +953,8 @@ void MEDCouplingFieldDouble::getValueOnPos(int i, int j, int k, double *res) con const DataArrayDouble *arr=_time_discr->getArray(); if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnPos"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnPos !"); _type->getValueOnPos(arr,_mesh,i,j,k,res); } @@ -936,6 +967,8 @@ void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double *res) con const DataArrayDouble *arr=_time_discr->getArray(); if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnPos !"); _type->getValueOn(arr,_mesh,spaceLoc,res); } @@ -947,6 +980,8 @@ DataArrayDouble *MEDCouplingFieldDouble::getValueOnMulti(const double *spaceLoc, const DataArrayDouble *arr=_time_discr->getArray(); if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnMulti"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnMulti !"); return _type->getValueOnMulti(arr,_mesh,spaceLoc,nbOfPoints); } @@ -960,6 +995,8 @@ void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double time, dou std::vector< const DataArrayDouble *> arrs=_time_discr->getArraysForTime(time); if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOn !"); std::vector res2; for(std::vector< const DataArrayDouble *>::const_iterator iter=arrs.begin();iter!=arrs.end();iter++) { @@ -987,6 +1024,8 @@ MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator=(double value) throw(IN { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::operator= : no mesh defined !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform operator = !"); int nbOfTuple=_type->getNumberOfTuples(_mesh); _time_discr->setUniformValue(nbOfTuple,1,value); return *this; @@ -1002,6 +1041,8 @@ void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, FunctionToEvaluate f { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !"); MEDCouplingAutoRefCountObjectPtr loc=_type->getLocalizationOfDiscValues(_mesh); _time_discr->fillFromAnalytic(loc,nbOfComp,func); } @@ -1016,6 +1057,8 @@ void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const char *func) th { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !"); MEDCouplingAutoRefCountObjectPtr loc=_type->getLocalizationOfDiscValues(_mesh); _time_discr->fillFromAnalytic(loc,nbOfComp,func); } @@ -1030,6 +1073,8 @@ void MEDCouplingFieldDouble::fillFromAnalytic2(int nbOfComp, const char *func) t { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic2 : no mesh defined !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic2 !"); MEDCouplingAutoRefCountObjectPtr loc=_type->getLocalizationOfDiscValues(_mesh); _time_discr->fillFromAnalytic2(loc,nbOfComp,func); } @@ -1044,6 +1089,8 @@ void MEDCouplingFieldDouble::fillFromAnalytic3(int nbOfComp, const std::vector loc=_type->getLocalizationOfDiscValues(_mesh); _time_discr->fillFromAnalytic3(loc,nbOfComp,varsOrder,func); } @@ -1065,6 +1112,8 @@ void MEDCouplingFieldDouble::applyFunc(int nbOfComp, double val) { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::applyFunc : no mesh defined !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform applyFunc !"); int nbOfTuple=_type->getNumberOfTuples(_mesh); _time_discr->setUniformValue(nbOfTuple,nbOfComp,val); } @@ -1150,6 +1199,8 @@ int MEDCouplingFieldDouble::getNumberOfTuples() const throw(INTERP_KERNEL::Excep { if(!_mesh) throw INTERP_KERNEL::Exception("Impossible to retrieve number of tuples because no mesh specified !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getNumberOfTuples !"); return _type->getNumberOfTuples(_mesh); } @@ -1182,7 +1233,8 @@ std::size_t MEDCouplingFieldDouble::getHeapMemorySize() const void MEDCouplingFieldDouble::setNature(NatureOfField nat) throw(INTERP_KERNEL::Exception) { MEDCouplingField::setNature(nat); - _type->checkCompatibilityWithNature(nat); + if(_type) + _type->checkCompatibilityWithNature(nat); } /*! @@ -1202,6 +1254,8 @@ void MEDCouplingFieldDouble::synchronizeTimeWithMesh() throw(INTERP_KERNEL::Exce double MEDCouplingFieldDouble::getIJK(int cellId, int nodeIdInCell, int compoId) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getIJK !"); return _type->getIJK(_mesh,getArray(),cellId,nodeIdInCell,compoId); } @@ -1236,6 +1290,8 @@ void MEDCouplingFieldDouble::getTinySerializationStrInformation(std::vector& tinyInfo) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !"); tinyInfo.clear(); tinyInfo.push_back((int)_type->getEnum()); tinyInfo.push_back((int)_time_discr->getEnum()); @@ -1253,6 +1309,8 @@ void MEDCouplingFieldDouble::getTinySerializationIntInformation(std::vector */ void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vector& tinyInfo) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !"); tinyInfo.clear(); _time_discr->getTinySerializationDbleInformation(tinyInfo); std::vector tinyInfo2; @@ -1270,6 +1328,8 @@ void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vector& tinyInfoI, DataArrayInt *&dataInt, std::vector& arrays) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !"); dataInt=0; std::vector tinyInfoITmp(tinyInfoI); int sz=tinyInfoITmp.back(); @@ -1283,6 +1343,8 @@ void MEDCouplingFieldDouble::resizeForUnserialization(const std::vector& ti void MEDCouplingFieldDouble::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !"); std::vector tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end()); // std::vector tmp(tinyInfoD); @@ -1306,6 +1368,8 @@ void MEDCouplingFieldDouble::finishUnserialization(const std::vector& tinyI */ void MEDCouplingFieldDouble::serialize(DataArrayInt *&dataInt, std::vector& arrays) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !"); _time_discr->getArrays(arrays); _type->getSerializationIntArray(dataInt); } @@ -1355,6 +1419,8 @@ bool MEDCouplingFieldDouble::mergeNodes(double eps, double epsOnVals) throw(INTE const MEDCouplingPointSet *meshC=dynamic_cast(_mesh); if(!meshC) throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform mergeNodes !"); MEDCouplingAutoRefCountObjectPtr meshC2((MEDCouplingPointSet *)meshC->deepCpy()); bool ret; int ret2; @@ -1380,6 +1446,8 @@ bool MEDCouplingFieldDouble::mergeNodes2(double eps, double epsOnVals) throw(INT const MEDCouplingPointSet *meshC=dynamic_cast(_mesh); if(!meshC) throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform mergeNodes2 !"); MEDCouplingAutoRefCountObjectPtr meshC2((MEDCouplingPointSet *)meshC->deepCpy()); bool ret; int ret2; @@ -1405,6 +1473,8 @@ bool MEDCouplingFieldDouble::zipCoords(double epsOnVals) throw(INTERP_KERNEL::Ex const MEDCouplingPointSet *meshC=dynamic_cast(_mesh); if(!meshC) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipCoords : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipCoords !"); MEDCouplingAutoRefCountObjectPtr meshC2((MEDCouplingPointSet *)meshC->deepCpy()); int oldNbOfNodes=meshC2->getNumberOfNodes(); MEDCouplingAutoRefCountObjectPtr arr=meshC2->zipCoordsTraducer(); @@ -1431,6 +1501,8 @@ bool MEDCouplingFieldDouble::zipConnectivity(int compType, double epsOnVals) thr const MEDCouplingUMesh *meshC=dynamic_cast(_mesh); if(!meshC) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipCoords : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipConnectivity !"); MEDCouplingAutoRefCountObjectPtr meshC2((MEDCouplingUMesh *)meshC->deepCpy()); int oldNbOfCells=meshC2->getNumberOfCells(); MEDCouplingAutoRefCountObjectPtr arr=meshC2->zipConnectivityTraducer(compType); @@ -1491,6 +1563,10 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::extractSlice3D(const double *ori */ bool MEDCouplingFieldDouble::simplexize(int policy) throw(INTERP_KERNEL::Exception) { + if(!_mesh) + throw INTERP_KERNEL::Exception("No underlying mesh on this field to perform simplexize !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform simplexize !"); int oldNbOfCells=_mesh->getNumberOfCells(); MEDCouplingAutoRefCountObjectPtr meshC2(_mesh->deepCpy()); MEDCouplingAutoRefCountObjectPtr arr=meshC2->simplexize(policy); @@ -1508,6 +1584,8 @@ bool MEDCouplingFieldDouble::simplexize(int policy) throw(INTERP_KERNEL::Excepti MEDCouplingFieldDouble *MEDCouplingFieldDouble::doublyContractedProduct() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform doublyContractedProduct !"); MEDCouplingTimeDiscretization *td=_time_discr->doublyContractedProduct(); td->copyTinyAttrFrom(*_time_discr); MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); @@ -1518,6 +1596,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::doublyContractedProduct() const MEDCouplingFieldDouble *MEDCouplingFieldDouble::determinant() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform determinant !"); MEDCouplingTimeDiscretization *td=_time_discr->determinant(); td->copyTinyAttrFrom(*_time_discr); MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); @@ -1528,6 +1608,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::determinant() const throw(INTERP MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenValues() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenValues !"); MEDCouplingTimeDiscretization *td=_time_discr->eigenValues(); td->copyTinyAttrFrom(*_time_discr); MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); @@ -1538,6 +1620,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenValues() const throw(INTERP MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenVectors() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenVectors !"); MEDCouplingTimeDiscretization *td=_time_discr->eigenVectors(); td->copyTinyAttrFrom(*_time_discr); MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); @@ -1548,6 +1632,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenVectors() const throw(INTER MEDCouplingFieldDouble *MEDCouplingFieldDouble::inverse() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform inverse !"); MEDCouplingTimeDiscretization *td=_time_discr->inverse(); td->copyTinyAttrFrom(*_time_discr); MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); @@ -1558,6 +1644,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::inverse() const throw(INTERP_KER MEDCouplingFieldDouble *MEDCouplingFieldDouble::trace() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform trace !"); MEDCouplingTimeDiscretization *td=_time_discr->trace(); td->copyTinyAttrFrom(*_time_discr); MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); @@ -1568,6 +1656,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::trace() const throw(INTERP_KERNE MEDCouplingFieldDouble *MEDCouplingFieldDouble::deviator() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform deviator !"); MEDCouplingTimeDiscretization *td=_time_discr->deviator(); td->copyTinyAttrFrom(*_time_discr); MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); @@ -1578,6 +1668,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::deviator() const throw(INTERP_KE MEDCouplingFieldDouble *MEDCouplingFieldDouble::magnitude() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform magnitude !"); MEDCouplingTimeDiscretization *td=_time_discr->magnitude(); td->copyTinyAttrFrom(*_time_discr); MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); @@ -1588,6 +1680,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::magnitude() const throw(INTERP_K MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxPerTuple() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform maxPerTuple !"); MEDCouplingTimeDiscretization *td=_time_discr->maxPerTuple(); td->copyTinyAttrFrom(*_time_discr); MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); @@ -1605,6 +1699,8 @@ void MEDCouplingFieldDouble::changeNbOfComponents(int newNbOfComp, double dftVal MEDCouplingFieldDouble *MEDCouplingFieldDouble::keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform keepSelectedComponents !"); MEDCouplingTimeDiscretization *td=_time_discr->keepSelectedComponents(compoIds); td->copyTinyAttrFrom(*_time_discr); MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); @@ -1629,6 +1725,12 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const MEDCouplingFie throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MergeFields on them !"); const MEDCouplingMesh *m1=f1->getMesh(); const MEDCouplingMesh *m2=f2->getMesh(); + if(!m1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no underlying mesh of f1 !"); + if(!f1->_time_discr) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no time discr of f1 !"); + if(!f1->_type) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no spatial discr of f1 !"); MEDCouplingMesh *m=m1->mergeMyselfWith(m2); MEDCouplingTimeDiscretization *td=f1->_time_discr->aggregate(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); @@ -1655,6 +1757,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const std::vector tds(a.size()); std::vector::const_iterator it=a.begin(); const MEDCouplingFieldDouble *ref=(*it++); + if(!ref) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : presence of NULL instance in first place of input vector !"); for(;it!=a.end();it++) if(!ref->areCompatibleForMerge(*it)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MergeFields on them !"); @@ -1690,6 +1794,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MeldFields(const MEDCouplingFiel MEDCouplingFieldDouble *MEDCouplingFieldDouble::DotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DotFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply DotFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->dot(f2->_time_discr); @@ -1701,6 +1807,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::DotFields(const MEDCouplingField MEDCouplingFieldDouble *MEDCouplingFieldDouble::CrossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::CrossProductFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply CrossProductFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->crossProduct(f2->_time_discr); @@ -1712,6 +1820,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::CrossProductFields(const MEDCoup MEDCouplingFieldDouble *MEDCouplingFieldDouble::MaxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MaxFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MaxFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->max(f2->_time_discr); @@ -1723,6 +1833,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MaxFields(const MEDCouplingField MEDCouplingFieldDouble *MEDCouplingFieldDouble::MinFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MinFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MinFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->min(f2->_time_discr); @@ -1734,6 +1846,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MinFields(const MEDCouplingField MEDCouplingFieldDouble *MEDCouplingFieldDouble::AddFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::AddFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply AddFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->add(f2->_time_discr); @@ -1753,6 +1867,8 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator+=(const MEDCoupli MEDCouplingFieldDouble *MEDCouplingFieldDouble::SubstractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::SubstractFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply SubstractFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->substract(f2->_time_discr); @@ -1772,6 +1888,8 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator-=(const MEDCoupli MEDCouplingFieldDouble *MEDCouplingFieldDouble::MultiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MultiplyFields : input field is NULL !"); if(!f1->areCompatibleForMul(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MultiplyFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->multiply(f2->_time_discr); @@ -1791,6 +1909,8 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCoupli MEDCouplingFieldDouble *MEDCouplingFieldDouble::DivideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DivideFields : input field is NULL !"); 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); @@ -1819,7 +1939,11 @@ void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vectorgetMesh(); + if(!m) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : 1st instance of field lies on NULL mesh !"); for(std::size_t i=1;igetMesh()!=m) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : Fields are not lying on a same mesh ! Expected by VTK ! MEDCouplingFieldDouble::setMesh or MEDCouplingFieldDouble::changeUnderlyingMesh can help to that."); diff --git a/src/MEDCoupling/MEDCouplingFieldTemplate.cxx b/src/MEDCoupling/MEDCouplingFieldTemplate.cxx index 225fa2896..70202d069 100644 --- a/src/MEDCoupling/MEDCouplingFieldTemplate.cxx +++ b/src/MEDCoupling/MEDCouplingFieldTemplate.cxx @@ -80,6 +80,8 @@ std::string MEDCouplingFieldTemplate::advancedRepr() const void MEDCouplingFieldTemplate::getTinySerializationIntInformation(std::vector& tinyInfo) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !"); tinyInfo.clear(); tinyInfo.push_back((int)_type->getEnum()); tinyInfo.push_back((int)_nature); @@ -91,6 +93,8 @@ void MEDCouplingFieldTemplate::getTinySerializationIntInformation(std::vector& tinyInfo) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !"); tinyInfo.clear(); _type->getTinySerializationDbleInformation(tinyInfo); } @@ -104,6 +108,8 @@ void MEDCouplingFieldTemplate::getTinySerializationStrInformation(std::vector& tinyInfoI, DataArrayInt *&dataInt) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !"); dataInt=0; std::vector tinyInfoITmp(tinyInfoI.begin()+2,tinyInfoI.end()); _type->resizeForUnserialization(tinyInfoITmp,dataInt); @@ -111,6 +117,8 @@ void MEDCouplingFieldTemplate::resizeForUnserialization(const std::vector& void MEDCouplingFieldTemplate::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !"); _nature=(NatureOfField)tinyInfoI[1]; _type->finishUnserialization(tinyInfoD); _name=tinyInfoS[0];