From 88635b6cb5ce37a952fba3537718dafb53a43950 Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 10 Jan 2013 13:11:39 +0000 Subject: [PATCH] Clean-up --- src/MEDCoupling/MEDCouplingMemArray.cxx | 56 +++++++++++++----------- src/MEDCoupling/MEDCouplingMemArray.hxx | 2 +- src/MEDCoupling/MEDCouplingRemapper.cxx | 8 ++-- src/MEDCoupling_Swig/MEDCouplingCommon.i | 9 ++-- src/MEDLoader/MEDFileMesh.cxx | 38 ++++++++++++---- 5 files changed, 69 insertions(+), 44 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index c4d29ef95..08105454b 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -5600,32 +5600,6 @@ DataArrayInt *DataArrayInt::BuildIntersection(const std::vectorcheckAllocated(); - if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception(MSG); - if(other->getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception(MSG); - const int *pt1Bg(begin()),*pt1End(end()),*pt2Bg(other->begin()),*pt2End(other->end()),*work2(pt2Bg); - MEDCouplingAutoRefCountObjectPtr ret0(DataArrayInt::New()),ret1(DataArrayInt::New()); ret0->alloc(0,1); ret1->alloc(0,1); - for(const int *work1=pt1Bg;work1!=pt1End;work1++) - { - if(work2!=pt2End && *work1==*work2) - { ret1->pushBackSilent(*work1); work2++; } - else - { ret0->pushBackSilent(*work1); } - } - idsInThisNotInOther=ret0.retn(); idsInThisAndInOther=ret1.retn(); -} - DataArrayInt *DataArrayInt::buildComplement(int nbOfElement) const throw(INTERP_KERNEL::Exception) { checkAllocated(); @@ -5650,6 +5624,9 @@ DataArrayInt *DataArrayInt::buildComplement(int nbOfElement) const throw(INTERP_ return ret; } +/*! + * \sa DataArrayInt::buildSubstractionOptimized + */ DataArrayInt *DataArrayInt::buildSubstraction(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception) { if(!other) @@ -5674,6 +5651,33 @@ DataArrayInt *DataArrayInt::buildSubstraction(const DataArrayInt *other) const t return ret; } +/*! + * \a this is expected to have one component and to be sorted ascendingly (as for \a other). + * \a other is expected to be a part of \a this. If not DataArrayInt::buildSubstraction should be called instead. + * + * \param [in] other an array with one component and expected to be sorted ascendingly. + * \ret list of ids in \a this but not in \a other. + * \sa DataArrayInt::buildSubstraction + */ +DataArrayInt *DataArrayInt::buildSubstractionOptimized(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception) +{ + static const char *MSG="DataArrayInt::buildSubstractionOptimized : only single component allowed !"; + if(!other) throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstractionOptimized : NULL input array !"); + checkAllocated(); other->checkAllocated(); + if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception(MSG); + if(other->getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception(MSG); + const int *pt1Bg(begin()),*pt1End(end()),*pt2Bg(other->begin()),*pt2End(other->end()),*work1(pt1Bg),*work2(pt2Bg); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); ret->alloc(0,1); + for(;work1!=pt1End;work1++) + { + if(work2!=pt2End && *work1==*work2) + work2++; + else + ret->pushBackSilent(*work1); + } + return ret.retn(); +} + DataArrayInt *DataArrayInt::buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception) { std::vectorarrs(2); diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index dc3778b26..73b2215d7 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -483,9 +483,9 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static DataArrayInt *MakePartition(const std::vector& groups, int newNb, std::vector< std::vector >& fidsOfGroups) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayInt *BuildUnion(const std::vector& arr) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayInt *BuildIntersection(const std::vector& arr) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void splitInTwoPartsWith(const DataArrayInt *other, DataArrayInt *&idsInThisNotInOther, DataArrayInt *&idsInThisAndInOther) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *buildComplement(int nbOfElement) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *buildSubstraction(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *buildSubstractionOptimized(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *buildUnique() const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingRemapper.cxx b/src/MEDCoupling/MEDCouplingRemapper.cxx index 8a489b139..0e120ce10 100644 --- a/src/MEDCoupling/MEDCouplingRemapper.cxx +++ b/src/MEDCoupling/MEDCouplingRemapper.cxx @@ -666,8 +666,8 @@ void MEDCouplingRemapper::computeDenoFromScratch(NatureOfField nat, const MEDCou } case Integral: { - MEDCouplingFieldDouble *deno=srcField->getDiscretization()->getMeasureField(srcField->getMesh(),true); - MEDCouplingFieldDouble *denoR=trgField->getDiscretization()->getMeasureField(trgField->getMesh(),true); + MEDCouplingFieldDouble *deno=srcField->getDiscretization()->getMeasureField(srcField->getMesh(),getMeasureAbsStatus()); + MEDCouplingFieldDouble *denoR=trgField->getDiscretization()->getMeasureField(trgField->getMesh(),getMeasureAbsStatus()); const double *denoPtr=deno->getArray()->getConstPointer(); const double *denoRPtr=denoR->getArray()->getConstPointer(); if(trgField->getMesh()->getMeshDimension()==-1) @@ -698,8 +698,8 @@ void MEDCouplingRemapper::computeDenoFromScratch(NatureOfField nat, const MEDCou } case RevIntegral: { - MEDCouplingFieldDouble *deno=trgField->getDiscretization()->getMeasureField(trgField->getMesh(),true); - MEDCouplingFieldDouble *denoR=srcField->getDiscretization()->getMeasureField(srcField->getMesh(),true); + MEDCouplingFieldDouble *deno=trgField->getDiscretization()->getMeasureField(trgField->getMesh(),getMeasureAbsStatus()); + MEDCouplingFieldDouble *denoR=srcField->getDiscretization()->getMeasureField(srcField->getMesh(),getMeasureAbsStatus()); const double *denoPtr=deno->getArray()->getConstPointer(); const double *denoRPtr=denoR->getArray()->getConstPointer(); if(trgField->getMesh()->getMeshDimension()==-1) diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 005e5c3d8..9a30b57f6 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -164,6 +164,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::buildComplement; %newobject ParaMEDMEM::DataArrayInt::buildUnion; %newobject ParaMEDMEM::DataArrayInt::buildSubstraction; +%newobject ParaMEDMEM::DataArrayInt::buildSubstractionOptimized; %newobject ParaMEDMEM::DataArrayInt::buildIntersection; %newobject ParaMEDMEM::DataArrayInt::buildUnique; %newobject ParaMEDMEM::DataArrayInt::deltaShiftIndex; @@ -848,10 +849,10 @@ namespace ParaMEDMEM %extend ParaMEDMEM::DataArrayInt { PyObject *getDifferentValues() const throw(INTERP_KERNEL::Exception) - { - std::set ret=self->getDifferentValues(); - return convertIntArrToPyList3(ret); - } + { + std::set ret=self->getDifferentValues(); + return convertIntArrToPyList3(ret); + } PyObject *partitionByDifferentValues() const throw(INTERP_KERNEL::Exception) { diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index a94699ce7..8b6c4251b 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -2420,19 +2420,17 @@ void MEDFileUMesh::addGroupUnderground(const DataArrayInt *ids, DataArrayInt *fa MEDCouplingAutoRefCountObjectPtr ids2Tmp=famIds->getIdsEqual(*famId); MEDCouplingAutoRefCountObjectPtr ids2=ids->selectByTupleId(ids2Tmp->begin(),ids2Tmp->end()); MEDCouplingAutoRefCountObjectPtr ids1=famArr->getIdsEqual(*famId); - DataArrayInt *ret0=0,*ret1=0; - ids1->splitInTwoPartsWith(ids2,ret0,ret1); - MEDCouplingAutoRefCountObjectPtr ret00(ret0),ret11(ret1); + MEDCouplingAutoRefCountObjectPtr ret0(ids1->buildSubstractionOptimized(ids2)); if(ret0->empty()) { bool isFamPresent=false; for(std::list< MEDCouplingAutoRefCountObjectPtr >::const_iterator itl=allFamIds.begin();itl!=allFamIds.end() && !isFamPresent;itl++) isFamPresent=(*itl)->presenceOfValue(*famId); if(!isFamPresent) - { familyIds.push_back(*famId); idsPerfamiliyIds.push_back(ret00); fams.push_back(FindOrCreateAndGiveFamilyWithId(families,*famId,created)); } // adding *famId in grp + { familyIds.push_back(*famId); idsPerfamiliyIds.push_back(ret0); fams.push_back(FindOrCreateAndGiveFamilyWithId(families,*famId,created)); } // adding *famId in grp else { - familyIds.push_back(maxVal); idsPerfamiliyIds.push_back(ret11); std::string locFamName=FindOrCreateAndGiveFamilyWithId(families,maxVal,created); + familyIds.push_back(maxVal); idsPerfamiliyIds.push_back(ids2); std::string locFamName=FindOrCreateAndGiveFamilyWithId(families,maxVal,created); fams.push_back(locFamName); if(existsFamily(*famId)) { @@ -2444,8 +2442,8 @@ void MEDFileUMesh::addGroupUnderground(const DataArrayInt *ids, DataArrayInt *fa } else { - familyIds.push_back(maxVal); idsPerfamiliyIds.push_back(ret00); // modifying all other groups on *famId to lie on maxVal and on maxVal+1 - familyIds.push_back(maxVal+1); idsPerfamiliyIds.push_back(ret11);//grp lie only on maxVal+1 + familyIds.push_back(maxVal); idsPerfamiliyIds.push_back(ret0); // modifying all other groups on *famId to lie on maxVal and on maxVal+1 + familyIds.push_back(maxVal+1); idsPerfamiliyIds.push_back(ids2);//grp lie only on maxVal+1 std::string n2(FindOrCreateAndGiveFamilyWithId(families,maxVal+1,created)); fams.push_back(n2); if(existsFamily(*famId)) { @@ -2728,12 +2726,34 @@ MEDFileCMesh *MEDFileCMesh::New(const char *fileName, const char *mName, int dt, int MEDFileCMesh::getMaxFamilyIdInArrays() const throw(INTERP_KERNEL::Exception) { - throw INTERP_KERNEL::Exception("Tony"); + int ret=-std::numeric_limits::max(),tmp=-1; + if((const DataArrayInt *)_fam_nodes) + { + int val=_fam_nodes->getMaxValue(tmp); + ret=std::max(ret,val); + } + if((const DataArrayInt *)_fam_cells) + { + int val=_fam_cells->getMaxValue(tmp); + ret=std::max(ret,val); + } + return ret; } int MEDFileCMesh::getMinFamilyIdInArrays() const throw(INTERP_KERNEL::Exception) { - throw INTERP_KERNEL::Exception("Tony"); + int ret=std::numeric_limits::max(),tmp=-1; + if((const DataArrayInt *)_fam_nodes) + { + int val=_fam_nodes->getMinValue(tmp); + ret=std::min(ret,val); + } + if((const DataArrayInt *)_fam_cells) + { + int val=_fam_cells->getMinValue(tmp); + ret=std::min(ret,val); + } + return ret; } int MEDFileCMesh::getMeshDimension() const throw(INTERP_KERNEL::Exception) -- 2.39.2