From: vsr Date: Fri, 15 Jul 2011 11:04:26 +0000 (+0000) Subject: Merge from V6_3_BR 15/07/2011 X-Git-Tag: V6_main_FINAL~1006 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ce8bf65b5f6c9d8e5ea66c5c9027a92a0c26a144;p=tools%2Fmedcoupling.git Merge from V6_3_BR 15/07/2011 --- diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx b/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx index ff6edfb21..4bc2354c8 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx @@ -821,6 +821,8 @@ void ExprParser::fillValuesInExpr(std::vector& valuesInExpr) throw(INTER for(std::size_t pos=0;pos!=std::string::npos;id++) { std::size_t pos2=_expr.find_first_of(FIGURES,pos,10); + if(pos2==std::string::npos) + break; if(pos2>0) {//treat case of "x*log10(x)" -> "10" should NOT be intercepted by this if(other.find_first_of(_expr[pos2-1])==std::string::npos) @@ -837,8 +839,6 @@ void ExprParser::fillValuesInExpr(std::vector& valuesInExpr) throw(INTER throw INTERP_KERNEL::Exception(oss.str().c_str()); } } - if(pos2==std::string::npos) - break; std::size_t pos3=_expr.find_first_not_of(FIGURES,pos2,10); if(pos3==std::string::npos) {//"x+1223442320" diff --git a/src/INTERP_KERNEL/InterpKernelCellSimplify.hxx b/src/INTERP_KERNEL/InterpKernelCellSimplify.hxx index 9b295e536..6b2434e19 100644 --- a/src/INTERP_KERNEL/InterpKernelCellSimplify.hxx +++ b/src/INTERP_KERNEL/InterpKernelCellSimplify.hxx @@ -20,12 +20,13 @@ #ifndef __INTERPKERNELCELLSIMPLIFY_HXX__ #define __INTERPKERNELCELLSIMPLIFY_HXX__ +#include "INTERPKERNELDefines.hxx" #include "NormalizedUnstructuredMesh.hxx" #include "InterpKernelException.hxx" namespace INTERP_KERNEL { - class CellSimplify + class INTERPKERNEL_EXPORT CellSimplify { public: static INTERP_KERNEL::NormalizedCellType simplifyDegeneratedCell(INTERP_KERNEL::NormalizedCellType type, const int *conn, int lgth, diff --git a/src/INTERP_KERNEL/Interpolation3D.hxx b/src/INTERP_KERNEL/Interpolation3D.hxx index d9950547f..31579ceaa 100644 --- a/src/INTERP_KERNEL/Interpolation3D.hxx +++ b/src/INTERP_KERNEL/Interpolation3D.hxx @@ -20,13 +20,14 @@ #ifndef __INTERPOLATION3D_HXX__ #define __INTERPOLATION3D_HXX__ +#include "INTERPKERNELDefines.hxx" #include "Interpolation.hxx" #include "NormalizedUnstructuredMesh.hxx" #include "InterpolationOptions.hxx" namespace INTERP_KERNEL { - class Interpolation3D : public Interpolation + class INTERPKERNEL_EXPORT Interpolation3D : public Interpolation { public: Interpolation3D(); diff --git a/src/INTERP_KERNEL/Interpolation3DSurf.hxx b/src/INTERP_KERNEL/Interpolation3DSurf.hxx index 2e52f0f3e..3ad619279 100644 --- a/src/INTERP_KERNEL/Interpolation3DSurf.hxx +++ b/src/INTERP_KERNEL/Interpolation3DSurf.hxx @@ -20,12 +20,13 @@ #ifndef __INTERPOLATION3DSURF_HXX__ #define __INTERPOLATION3DSURF_HXX__ -#include "InterpolationPlanar.hxx" +#include "InterpolationPlanar.txx" +#include "INTERPKERNELDefines.hxx" #include "InterpolationOptions.hxx" namespace INTERP_KERNEL { - class Interpolation3DSurf : public InterpolationPlanar + class INTERPKERNEL_EXPORT Interpolation3DSurf : public InterpolationPlanar { public: Interpolation3DSurf(); diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx index 14791e509..a219f5631 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -534,6 +534,20 @@ DataArrayInt *MEDCouplingCMesh::checkTypeConsistencyAndContig(const std::vector< return 0; } +/*! + * See MEDCouplingUMesh::splitProfilePerType for more information + */ +void MEDCouplingCMesh::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsInPflPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) +{ + int nbCells=getNumberOfCells(); + code.resize(3); + code[0]=(int)getTypeOfCell(0); + code[1]=nbCells; + code[2]=0; + idsInPflPerType.push_back(profile->deepCpy()); + idsPerType.push_back(profile->deepCpy()); +} + MEDCouplingUMesh *MEDCouplingCMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception) { int spaceDim=getSpaceDimension(); diff --git a/src/MEDCoupling/MEDCouplingCMesh.hxx b/src/MEDCoupling/MEDCouplingCMesh.hxx index 1864a9fb2..c5883d5e2 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.hxx +++ b/src/MEDCoupling/MEDCouplingCMesh.hxx @@ -68,6 +68,7 @@ namespace ParaMEDMEM const DataArrayDouble *coordsZ=0); // tools DataArrayInt *checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); + void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsInPflPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *buildUnstructured() const throw(INTERP_KERNEL::Exception); MEDCouplingMesh *buildPart(const int *start, const int *end) const; MEDCouplingMesh *buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const; diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx index 1615957cc..48d160bc0 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx @@ -606,6 +606,11 @@ DataArrayInt *MEDCouplingExtrudedMesh::checkTypeConsistencyAndContig(const std:: throw INTERP_KERNEL::Exception("Not implemented yet !"); } +void MEDCouplingExtrudedMesh::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsInPflPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + MEDCouplingMesh *MEDCouplingExtrudedMesh::buildPart(const int *start, const int *end) const { // not implemented yet ! diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx index 926ded6b4..64eb7ede1 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx @@ -81,6 +81,7 @@ namespace ParaMEDMEM void translate(const double *vector); void scale(const double *point, double factor); DataArrayInt *checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); + void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsInPflPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); MEDCouplingMesh *buildPart(const int *start, const int *end) const; MEDCouplingMesh *buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const; DataArrayInt *simplexize(int policy) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index e9d9b6d8f..5bda7bc2b 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -2165,6 +2165,72 @@ void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd declareAsNew(); } +/*! + * 'this' should be allocated and with numberOfComponents set to one. If not an exception will be thrown. + * This method takes as input an array defined by ['arrBg','arrEnd'). The size of the array (std::distance(arrBg,arrEnd)) is equal to the number of cast + 1. + * The values contained in ['arrBg','arrEnd') should be sorted ascendently. No check of this will be done. If not the result is not waranted. + * For each cast j the value range that defines the cast is equal to [arrBg[j],arrBg[j+1]). + * This method returns three arrays (to be managed by the caller). + * This method is typically usefull for entity number spliting by types for example. + * Example : If 'this' contains [6,5,0,3,2,7,8,1,4] and if ['arrBg','arrEnd') contains [0,4,9] then the output of this method will be : + * - 'castArr' : [1,1,0,0,0,1,1,0,1] + * - 'rankInsideCast' : [2,1,0,3,2,3,4,1,0] + * - 'return' : [0,1] + * + * @param castArr is a returned param has the same number of tuples than 'this' and number of components set to one. In case of sucess, this param contains for each tuple in 'this' in which cast it holds. + * @param rankInsideCast is an another returned param has the same number of tuples than 'this' and number of components set to one too. In case of sucess, this param contains for each tuple its rank inside its cast. + * @param castsPresent the casts that 'this' contains. + * @throw if a value in 'this' is greater or equal to the last value of ['arrBg','arrEnd') + */ +void DataArrayInt::splitByValueRange(const int *arrBg, const int *arrEnd, + DataArrayInt *& castArr, DataArrayInt *& rankInsideCast, DataArrayInt *& castsPresent) const throw(INTERP_KERNEL::Exception) +{ + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("Call splitByValueRange method on DataArrayInt with only one component, you can call 'rearrange' method before !"); + int nbOfTuples=getNumberOfTuples(); + std::size_t nbOfCast=std::distance(arrBg,arrEnd); + if(nbOfCast<2) + throw INTERP_KERNEL::Exception("DataArrayInt::splitByValueRange : The input array giving the cast range values should be of size >=2 !"); + nbOfCast--; + const int *work=getConstPointer(); + typedef std::reverse_iterator rintstart; + rintstart bg(arrEnd);//OK no problem because size of 'arr' is greater of equal 2 + rintstart end(arrBg); + MEDCouplingAutoRefCountObjectPtr ret1=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr ret2=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr ret3=DataArrayInt::New(); + ret1->alloc(nbOfTuples,1); + ret2->alloc(nbOfTuples,1); + int *ret1Ptr=ret1->getPointer(); + int *ret2Ptr=ret2->getPointer(); + std::set castsDetected; + for(int i=0;i(), work[i])); + std::size_t pos=std::distance(bg,res); + std::size_t pos2=nbOfCast-pos; + if(pos2alloc((int)castsDetected.size(),1); + std::copy(castsDetected.begin(),castsDetected.end(),ret3->getPointer()); + ret1->incrRef(); + castArr=ret1; + ret2->incrRef(); + rankInsideCast=ret2; + ret3->incrRef(); + castsPresent=ret3; +} + DataArrayInt *DataArrayInt::transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()!=1) @@ -3445,6 +3511,85 @@ void DataArrayInt::computeOffsets() throw(INTERP_KERNEL::Exception) declareAsNew(); } +/*! + * Idem DataArrayInt::computeOffsets method execpt that 'this' changes its number of tuples. + * After the call in case of success new number of tuples is equal to old number of tuples +1. + * The content in 'this' for the first old number of tuples is exactly the same than those given by + * DataArrayInt::computeOffsets method. + * For an array [3,5,1,2,0,8] it becomes [0,3,8,9,11,11,19]. + */ +void DataArrayInt::computeOffsets2() throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsets2 : only single component allowed !"); + int nbOfTuples=getNumberOfTuples(); + int *ret=new int[nbOfTuples+1]; + if(nbOfTuples==0) + return ; + const int *work=getConstPointer(); + ret[0]=0; + for(int i=0;igetNumberOfTuples()-1 tuples. + * If 'this' contains [0,2,3] and 'offsets' [0,3,6,10,14,20] the returned array will contain [0,1,2,6,7,8,9,10,11,12,13] + */ +DataArrayInt *DataArrayInt::buildExplicitArrByRanges(const DataArrayInt *offsets) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : only single component allowed !"); + offsets->checkAllocated(); + if(offsets->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : input array should have only single component !"); + int othNbTuples=offsets->getNumberOfTuples()-1; + int nbOfTuples=getNumberOfTuples(); + int retNbOftuples=0; + const int *work=getConstPointer(); + const int *offPtr=offsets->getConstPointer(); + for(int i=0;i=0 && val=0) + retNbOftuples+=delta; + else + { + std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << val << " of offset array has a delta < 0 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + else + { + std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << i << " in this contains " << val; + oss << " whereas offsets array is of size " << othNbTuples+1 << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + ret->alloc(retNbOftuples,1); + int *retPtr=ret->getPointer(); + for(int i=0;iincrRef(); + return ret; +} + /*! * This method returns all different values found in 'this'. */ diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index b2439f1c2..64890dcec 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -273,6 +273,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void transformWithIndArr(const int *indArrBg, const int *indArrEnd) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void splitByValueRange(const int *arrBg, const int *arrEnd, + DataArrayInt *& castArr, DataArrayInt *& rankInsideCast, DataArrayInt *& castsPresent) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *invertArrayO2N2N2O(int newNbOfElem) const; MEDCOUPLING_EXPORT DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const; //!alloc or useArray should have been called before. @@ -338,6 +340,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *deltaShiftIndex() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void computeOffsets() throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void computeOffsets2() throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *buildExplicitArrByRanges(const DataArrayInt *offsets) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::set getDifferentValues() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); MEDCOUPLING_EXPORT void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index 182dce853..4f40a2d86 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -90,6 +90,7 @@ namespace ParaMEDMEM virtual std::string advancedRepr() const = 0; // tools virtual DataArrayInt *checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) = 0; + virtual void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsInPflPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) = 0; virtual void getBoundingBox(double *bbox) const = 0; virtual MEDCouplingFieldDouble *getMeasureField(bool isAbs) const = 0; virtual MEDCouplingFieldDouble *getMeasureFieldOnNode(bool isAbs) const = 0; diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 61c6f4627..d2818e797 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -3415,6 +3415,81 @@ DataArrayInt *MEDCouplingUMesh::checkTypeConsistencyAndContig(const std::vector< return ret; } +/*! + * This method makes the hypothesis that 'this' is sorted by type. If not an exception will be thrown. + * This method is the opposite of MEDCouplingUMesh::checkTypeConsistencyAndContig method. Given a list of cells in 'profile' it returns a list of profiles sorted by geo type. + * This method has 1 input 'profile' and 2 outputs 'code' and 'idsPerType'. + * @throw if 'profile' has not exactly one component. It throws too, if 'profile' contains some values not in [0,getNumberOfCells()) or if 'this' is not fully defined + */ +void MEDCouplingUMesh::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsInPflPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) +{ + if(profile->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::splitProfilePerType : input profile should have exactly one component !"); + checkConnectivityFullyDefined(); + const int *conn=_nodal_connec->getConstPointer(); + const int *connI=_nodal_connec_index->getConstPointer(); + int nbOfCells=getNumberOfCells(); + std::vector types; + std::vector typeRangeVals(1); + for(const int *i=connI;i!=connI+nbOfCells;) + { + INTERP_KERNEL::NormalizedCellType curType=(INTERP_KERNEL::NormalizedCellType)conn[*i]; + if(std::find(types.begin(),types.end(),curType)!=types.end()) + { + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::splitProfilePerType : current mesh is not sorted by type !"); + } + types.push_back(curType); + i=std::find_if(i+1,connI+nbOfCells,ParaMEDMEMImpl::ConnReader(conn,(int)curType)); + typeRangeVals.push_back(std::distance(connI,i)); + } + // + DataArrayInt *castArr=0,*rankInsideCast=0,*castsPresent=0; + profile->splitByValueRange(&typeRangeVals[0],&typeRangeVals[0]+typeRangeVals.size(),castArr,rankInsideCast,castsPresent); + MEDCouplingAutoRefCountObjectPtr tmp0=castArr; + MEDCouplingAutoRefCountObjectPtr tmp1=rankInsideCast; + MEDCouplingAutoRefCountObjectPtr tmp2=castsPresent; + // + int nbOfCastsFinal=castsPresent->getNumberOfTuples(); + code.resize(3*nbOfCastsFinal); + std::vector< MEDCouplingAutoRefCountObjectPtr > idsInPflPerType2; + std::vector< MEDCouplingAutoRefCountObjectPtr > idsPerType2; + for(int i=0;igetIJ(i,0); + MEDCouplingAutoRefCountObjectPtr tmp3=castArr->getIdsEqual(castId); + idsInPflPerType2.push_back(tmp3); + code[3*i]=(int)types[castId]; + code[3*i+1]=tmp3->getNumberOfTuples(); + MEDCouplingAutoRefCountObjectPtr tmp4=rankInsideCast->selectByTupleId(tmp3->getConstPointer(),tmp3->getConstPointer()+tmp3->getNumberOfTuples()); + if(tmp4->getNumberOfTuples()!=typeRangeVals[castId+1]-typeRangeVals[castId] || !tmp4->isIdentity()) + { + tmp4->copyStringInfoFrom(*profile); + idsPerType2.push_back(tmp4); + code[3*i+2]=(int)idsPerType2.size()-1; + } + else + { + code[3*i+2]=-1; + } + } + int sz2=idsInPflPerType2.size(); + idsInPflPerType.resize(sz2); + for(int i=0;iincrRef(); + idsInPflPerType[i]=locDa; + } + int sz=idsPerType2.size(); + idsPerType.resize(sz); + for(int i=0;iincrRef(); + idsPerType[i]=locDa; + } +} + /*! * This method is here too emulate the MEDMEM behaviour on BDC (buildDescendingConnectivity). Hoping this method becomes deprecated very soon. * This method make the assumption that 'this' and 'nM1LevMesh' mesh lyies on same coords (same pointer) as MED and MEDMEM does. @@ -3490,7 +3565,7 @@ bool MEDCouplingUMesh::checkConsecutiveCellTypes() const { INTERP_KERNEL::NormalizedCellType curType=(INTERP_KERNEL::NormalizedCellType)conn[*i]; if(types.find(curType)!=types.end()) - return false; + return false; types.insert(curType); i=std::find_if(i+1,connI+nbOfCells,ParaMEDMEMImpl::ConnReader(conn,(int)curType)); } diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 96fc0a6fd..9a20b68ad 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -140,6 +140,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT MEDCouplingFieldDouble *getSkewField() const throw(INTERP_KERNEL::Exception); //utilities for MED File RW MEDCOUPLING_EXPORT DataArrayInt *checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsInPflPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT MEDCouplingUMesh *emulateMEDMEMBDC(const MEDCouplingUMesh *nM1LevMesh, DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *&revDesc, DataArrayInt *&revDescIndx, DataArrayInt *& nM1LevMeshIds, DataArrayInt *&meshnM1Old2New) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *sortCellsInMEDFileFrmt() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool checkConsecutiveCellTypes() const; diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx index 9406b0766..19f75c2c1 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx @@ -194,6 +194,11 @@ DataArrayInt *MEDCouplingUMeshDesc::checkTypeConsistencyAndContig(const std::vec throw INTERP_KERNEL::Exception("Not implemented yet !"); } +void MEDCouplingUMeshDesc::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsInPflPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Not implemented yet !"); +} + void MEDCouplingUMeshDesc::getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const { MEDCouplingPointSet::getTinySerializationInformation(tinyInfoD,tinyInfo,littleStrings); diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx index 98867717b..71a88bcec 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx @@ -58,6 +58,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void setConnectivity(DataArrayInt *descConn, DataArrayInt *descConnIndex, DataArrayInt *nodalFaceConn, DataArrayInt *nodalFaceConnIndx); //tools to overload MEDCOUPLING_EXPORT DataArrayInt *checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsInPflPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const; MEDCOUPLING_EXPORT bool isEmptyMesh(const std::vector& tinyInfo) const; MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const; diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index 6fbe69a54..23c43559e 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -223,6 +223,10 @@ namespace ParaMEDMEM CPPUNIT_TEST( testSortCellsInMEDFileFrmt1 ); CPPUNIT_TEST( testBuildPartAndReduceNodes1 ); CPPUNIT_TEST( testDAITransformWithIndArrR1 ); + CPPUNIT_TEST( testDAISplitByValueRange1 ); + CPPUNIT_TEST( testUMeshSplitProfilePerType1 ); + CPPUNIT_TEST( testDAIBuildExplicitArrByRanges1 ); + CPPUNIT_TEST( testDAIComputeOffsets2 ); //MEDCouplingBasicsTestInterp.cxx CPPUNIT_TEST( test2DInterpP0P0_1 ); CPPUNIT_TEST( test2DInterpP0P0PL_1 ); @@ -472,6 +476,10 @@ namespace ParaMEDMEM void testSortCellsInMEDFileFrmt1(); void testBuildPartAndReduceNodes1(); void testDAITransformWithIndArrR1(); + void testDAISplitByValueRange1(); + void testUMeshSplitProfilePerType1(); + void testDAIBuildExplicitArrByRanges1(); + void testDAIComputeOffsets2(); //MEDCouplingBasicsTestInterp.cxx void test2DInterpP0P0_1(); void test2DInterpP0P0PL_1(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index cdd00270e..37aabd78a 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -1270,3 +1270,202 @@ void MEDCouplingBasicsTest::testDAITransformWithIndArrR1() d->decrRef(); d1->decrRef(); } + +void MEDCouplingBasicsTest::testDAISplitByValueRange1() +{ + const int val1[9]={6,5,0,3,2,7,8,1,4}; + const int val2[3]={0,4,9}; + DataArrayInt *d=DataArrayInt::New(); + d->alloc(9,1); + std::copy(val1,val1+9,d->getPointer()); + DataArrayInt *e=0,*f=0,*g=0; + d->splitByValueRange(val2,val2+3,e,f,g); + CPPUNIT_ASSERT_EQUAL(9,e->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,e->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(9,f->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(2,g->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,g->getNumberOfComponents()); + // + const int expected1[9]={1,1,0,0,0,1,1,0,1}; + const int expected2[9]={2,1,0,3,2,3,4,1,0}; + for(int i=0;i<9;i++) + { + CPPUNIT_ASSERT_EQUAL(expected1[i],e->getIJ(i,0)); + CPPUNIT_ASSERT_EQUAL(expected2[i],f->getIJ(i,0)); + } + CPPUNIT_ASSERT_EQUAL(0,g->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(1,g->getIJ(1,0)); + // + e->decrRef(); + f->decrRef(); + g->decrRef(); + // + d->setIJ(6,0,9); + CPPUNIT_ASSERT_THROW(d->splitByValueRange(val2,val2+3,e,f,g),INTERP_KERNEL::Exception); + // + d->decrRef(); +} + +void MEDCouplingBasicsTest::testUMeshSplitProfilePerType1() +{ + const int val0[5]={2,0,1,3,4}; + MEDCouplingUMesh *m=build2DTargetMesh_1(); + m->renumberCells(val0,false); + std::vector code; + std::vector idsInPflPerType; + std::vector pfls; + // + const int val1[3]={0,2,3}; + DataArrayInt *d=DataArrayInt::New(); + d->alloc(3,1); + d->setName("sup"); + std::copy(val1,val1+3,d->getPointer()); + m->splitProfilePerType(d,code,idsInPflPerType,pfls); + CPPUNIT_ASSERT_EQUAL(6,(int)code.size()); + CPPUNIT_ASSERT_EQUAL(2,(int)idsInPflPerType.size()); + const int expected1[6]={3,1,0, 4,2,1}; + for(int i=0;i<6;i++) + CPPUNIT_ASSERT_EQUAL(expected1[i],code[i]); + CPPUNIT_ASSERT_EQUAL(1,idsInPflPerType[0]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(0,idsInPflPerType[0]->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(2,idsInPflPerType[1]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,idsInPflPerType[1]->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(2,idsInPflPerType[1]->getIJ(1,0)); + idsInPflPerType[0]->decrRef(); + idsInPflPerType[1]->decrRef(); + CPPUNIT_ASSERT_EQUAL(2,(int)pfls.size()); + CPPUNIT_ASSERT(std::string("sup")==pfls[0]->getName()); + CPPUNIT_ASSERT_EQUAL(1,pfls[0]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(0,pfls[0]->getIJ(0,0)); + CPPUNIT_ASSERT(std::string("sup")==pfls[1]->getName()); + CPPUNIT_ASSERT_EQUAL(2,pfls[1]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(0,pfls[1]->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(1,pfls[1]->getIJ(1,0)); + pfls[0]->decrRef(); + pfls[1]->decrRef(); + d->decrRef(); + idsInPflPerType.clear(); + pfls.clear(); + code.clear(); + // + const int val2[4]={0,2,3,4};// all quad4 are selected here ! So no profile for Quads + d=DataArrayInt::New(); + d->alloc(4,1); + std::copy(val2,val2+4,d->getPointer()); + m->splitProfilePerType(d,code,idsInPflPerType,pfls); + CPPUNIT_ASSERT_EQUAL(6,(int)code.size()); + CPPUNIT_ASSERT_EQUAL(2,(int)idsInPflPerType.size()); + const int expected2[6]={3,1,0, 4,3,-1}; + for(int i=0;i<6;i++) + CPPUNIT_ASSERT_EQUAL(expected2[i],code[i]); + CPPUNIT_ASSERT_EQUAL(1,idsInPflPerType[0]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(0,idsInPflPerType[0]->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(3,idsInPflPerType[1]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,idsInPflPerType[1]->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(2,idsInPflPerType[1]->getIJ(1,0)); + CPPUNIT_ASSERT_EQUAL(3,idsInPflPerType[1]->getIJ(2,0)); + idsInPflPerType[0]->decrRef(); + idsInPflPerType[1]->decrRef(); + CPPUNIT_ASSERT_EQUAL(1,(int)pfls.size()); + CPPUNIT_ASSERT_EQUAL(1,pfls[0]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(0,pfls[0]->getIJ(0,0)); + pfls[0]->decrRef(); + d->decrRef(); + idsInPflPerType.clear(); + pfls.clear(); + code.clear(); + // + const int val3[3]={1,0,2};// all tri3 are selected here but not in the same order ! Profile requested for Tri3 + d=DataArrayInt::New(); + d->alloc(3,1); + std::copy(val3,val3+3,d->getPointer()); + m->splitProfilePerType(d,code,idsInPflPerType,pfls); + CPPUNIT_ASSERT_EQUAL(6,(int)code.size()); + CPPUNIT_ASSERT_EQUAL(2,(int)idsInPflPerType.size()); + const int expected3[6]={3,2,0, 4,1,1}; + for(int i=0;i<6;i++) + CPPUNIT_ASSERT_EQUAL(expected3[i],code[i]); + CPPUNIT_ASSERT_EQUAL(2,idsInPflPerType[0]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(0,idsInPflPerType[0]->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(1,idsInPflPerType[0]->getIJ(1,0)); + CPPUNIT_ASSERT_EQUAL(1,idsInPflPerType[1]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(2,idsInPflPerType[1]->getIJ(0,0)); + idsInPflPerType[0]->decrRef(); + idsInPflPerType[1]->decrRef(); + CPPUNIT_ASSERT_EQUAL(2,(int)pfls.size()); + CPPUNIT_ASSERT_EQUAL(2,pfls[0]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,pfls[0]->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(0,pfls[0]->getIJ(1,0)); + CPPUNIT_ASSERT_EQUAL(0,pfls[1]->getIJ(0,0)); + pfls[0]->decrRef(); + pfls[1]->decrRef(); + d->decrRef(); + idsInPflPerType.clear(); + pfls.clear(); + code.clear(); + // + const int val4[2]={3,4};// all tri3 are selected here but not in the same order ! Profile requested for Tri3 + d=DataArrayInt::New(); + d->alloc(2,1); + std::copy(val4,val4+2,d->getPointer()); + m->splitProfilePerType(d,code,idsInPflPerType,pfls); + CPPUNIT_ASSERT_EQUAL(3,(int)code.size()); + CPPUNIT_ASSERT_EQUAL(1,(int)idsInPflPerType.size()); + const int expected4[3]={4,2,0}; + for(int i=0;i<3;i++) + CPPUNIT_ASSERT_EQUAL(expected4[i],code[i]); + CPPUNIT_ASSERT_EQUAL(2,idsInPflPerType[0]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(0,idsInPflPerType[0]->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(1,idsInPflPerType[0]->getIJ(1,0)); + idsInPflPerType[0]->decrRef(); + CPPUNIT_ASSERT_EQUAL(1,(int)pfls.size()); + CPPUNIT_ASSERT_EQUAL(2,pfls[0]->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,pfls[0]->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(2,pfls[0]->getIJ(1,0)); + pfls[0]->decrRef(); + d->decrRef(); + idsInPflPerType.clear(); + pfls.clear(); + code.clear(); + // + m->decrRef(); +} + +void MEDCouplingBasicsTest::testDAIBuildExplicitArrByRanges1() +{ + DataArrayInt *d=DataArrayInt::New(); + d->alloc(3,1); + const int vals1[3]={0,2,3}; + std::copy(vals1,vals1+3,d->getPointer()); + DataArrayInt *e=DataArrayInt::New(); + e->alloc(6,1); + const int vals2[6]={0,3,6,10,14,20}; + std::copy(vals2,vals2+6,e->getPointer()); + // + DataArrayInt *f=d->buildExplicitArrByRanges(e); + CPPUNIT_ASSERT_EQUAL(11,f->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,f->getNumberOfComponents()); + const int expected1[11]={0,1,2,6,7,8,9,10,11,12,13}; + for(int i=0;i<11;i++) + CPPUNIT_ASSERT_EQUAL(expected1[i],f->getIJ(i,0)); + // + f->decrRef(); + e->decrRef(); + d->decrRef(); +} + +void MEDCouplingBasicsTest::testDAIComputeOffsets2() +{ + DataArrayInt *d=DataArrayInt::New(); + const int vals1[6]={3,5,1,2,0,8}; + const int expected1[7]={0,3,8,9,11,11,19}; + d->alloc(6,1); + std::copy(vals1,vals1+6,d->getPointer()); + d->computeOffsets2(); + CPPUNIT_ASSERT_EQUAL(7,d->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,d->getNumberOfComponents()); + for(int i=0;i<7;i++) + CPPUNIT_ASSERT_EQUAL(expected1[i],d->getIJ(0,i)); + d->decrRef(); +} diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index eea5b04e0..07734296e 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -149,6 +149,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::buildSubstraction; %newobject ParaMEDMEM::DataArrayInt::buildIntersection; %newobject ParaMEDMEM::DataArrayInt::deltaShiftIndex; +%newobject ParaMEDMEM::DataArrayInt::buildExplicitArrByRanges; %newobject ParaMEDMEM::DataArrayInt::buildPermutationArr; %newobject ParaMEDMEM::DataArrayInt::buildPermArrPerLevel; %newobject ParaMEDMEM::DataArrayInt::__getitem__; @@ -272,8 +273,11 @@ using namespace INTERP_KERNEL; %feature("unref") MEDCouplingField "$this->decrRef();" %feature("unref") MEDCouplingFieldDouble "$this->decrRef();" %feature("unref") MEDCouplingMultiFields "$this->decrRef();" +%feature("unref") MEDCouplingFieldTemplate "$this->decrRef();" +%feature("unref") MEDCouplingMultiFields "$this->decrRef();" %rename(assign) *::operator=; +%ignore ParaMEDMEM::RefCountObject::decrRef; %ignore ParaMEDMEM::MemArray::operator=; %ignore ParaMEDMEM::MemArray::operator[]; %ignore ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationIntInfo; @@ -562,6 +566,26 @@ namespace ParaMEDMEM return self->checkTypeConsistencyAndContig(code,idsPerType); } + PyObject *splitProfilePerType(const DataArrayInt *profile) const throw(INTERP_KERNEL::Exception) + { + std::vector code; + std::vector idsInPflPerType; + std::vector idsPerType; + self->splitProfilePerType(profile,code,idsInPflPerType,idsPerType); + PyObject *ret=PyTuple_New(3); + PyTuple_SetItem(ret,0,convertIntArrToPyList2(code)); + PyObject *ret1=PyList_New(idsInPflPerType.size()); + for(std::size_t j=0;j tmp=convertPyToNewIntArr2(li,&size); + self->splitByValueRange(tmp,(int *)tmp+size,ret0,ret1,ret2); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + self->splitByValueRange(da2->getConstPointer(),da2->getConstPointer()+size,ret0,ret1,ret2); + } + PyObject *ret = PyList_New(3); + PyList_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(ret2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + DataArrayInt *transformWithIndArrR(PyObject *li) const { void *da=0; diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 391a5036d..61f3f1694 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -7402,6 +7402,160 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(expected[i],d3.getIJ(i,0)); pass pass + + def testDAISplitByValueRange1(self): + val1=[6,5,0,3,2,7,8,1,4] + val2=[0,4,9] + d=DataArrayInt.New(); + d.setValues(val1,9,1); + e,f,g=d.splitByValueRange(val2); + self.assertEqual(9,e.getNumberOfTuples()); + self.assertEqual(1,e.getNumberOfComponents()); + self.assertEqual(9,f.getNumberOfTuples()); + self.assertEqual(1,f.getNumberOfComponents()); + self.assertEqual(2,g.getNumberOfTuples()); + self.assertEqual(1,g.getNumberOfComponents()); + # + expected1=[1,1,0,0,0,1,1,0,1] + expected2=[2,1,0,3,2,3,4,1,0] + for i in xrange(9): + self.assertEqual(expected1[i],e.getIJ(i,0)); + self.assertEqual(expected2[i],f.getIJ(i,0)); + pass + self.assertEqual(0,g.getIJ(0,0)); + self.assertEqual(1,g.getIJ(1,0)); + # + d.setIJ(6,0,9); + self.assertRaises(InterpKernelException,d.splitByValueRange,val2); + pass + + def testUMeshSplitProfilePerType1(self): + val0=[2,0,1,3,4] + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + m.renumberCells(val0,False); + # + val1=[0,2,3] + d=DataArrayInt.New(); + d.setValues(val1,3,1); + d.setName("sup") + code,idsInPflPerType,pfls=m.splitProfilePerType(d); + self.assertEqual(6,len(code)); + self.assertEqual(2,len(idsInPflPerType)); + expected1=[3,1,0, 4,2,1] + for i in xrange(6): + self.assertEqual(expected1[i],code[i]); + pass + self.assertEqual(2,len(idsInPflPerType)); + self.assertEqual(1,idsInPflPerType[0].getNumberOfTuples()); + self.assertEqual(0,idsInPflPerType[0].getIJ(0,0)); + self.assertEqual(2,idsInPflPerType[1].getNumberOfTuples()); + self.assertEqual(1,idsInPflPerType[1].getIJ(0,0)); + self.assertEqual(2,idsInPflPerType[1].getIJ(1,0)); + # + self.assertEqual(2,len(pfls)); + self.assertEqual("sup",pfls[0].getName()) + self.assertEqual(1,pfls[0].getNumberOfTuples()); + self.assertEqual(0,pfls[0].getIJ(0,0)); + self.assertEqual("sup",pfls[1].getName()) + self.assertEqual(2,pfls[1].getNumberOfTuples()); + self.assertEqual(0,pfls[1].getIJ(0,0)); + self.assertEqual(1,pfls[1].getIJ(1,0)); + # + val2=[0,2,3,4] + d=DataArrayInt.New(); + d.setValues(val2,4,1); + code,idsInPflPerType,pfls=m.splitProfilePerType(d); + self.assertEqual(6,len(code)); + self.assertEqual(2,len(idsInPflPerType)); + expected2=[3,1,0, 4,3,-1] + for i in xrange(6): + self.assertEqual(expected2[i],code[i]); + pass + self.assertEqual(2,len(idsInPflPerType)); + self.assertEqual(1,idsInPflPerType[0].getNumberOfTuples()); + self.assertEqual(0,idsInPflPerType[0].getIJ(0,0)); + self.assertEqual(3,idsInPflPerType[1].getNumberOfTuples()); + self.assertEqual(1,idsInPflPerType[1].getIJ(0,0)); + self.assertEqual(2,idsInPflPerType[1].getIJ(1,0)); + self.assertEqual(3,idsInPflPerType[1].getIJ(2,0)); + # + self.assertEqual(1,len(pfls)); + self.assertEqual(1,pfls[0].getNumberOfTuples()); + self.assertEqual(0,pfls[0].getIJ(0,0)); + # + val3=[1,0,2] + d=DataArrayInt.New(); + d.setValues(val3,3,1); + code,idsInPflPerType,pfls=m.splitProfilePerType(d); + self.assertEqual(6,len(code)); + self.assertEqual(2,len(idsInPflPerType)); + expected3=[3,2,0, 4,1,1] + for i in xrange(6): + self.assertEqual(expected3[i],code[i]); + pass + self.assertEqual(2,len(idsInPflPerType)); + self.assertEqual(2,idsInPflPerType[0].getNumberOfTuples()); + self.assertEqual(0,idsInPflPerType[0].getIJ(0,0)); + self.assertEqual(1,idsInPflPerType[0].getIJ(1,0)); + self.assertEqual(1,idsInPflPerType[1].getNumberOfTuples()); + self.assertEqual(2,idsInPflPerType[1].getIJ(0,0)); + # + self.assertEqual(2,len(pfls)); + self.assertEqual(2,pfls[0].getNumberOfTuples()); + self.assertEqual(1,pfls[0].getIJ(0,0)); + self.assertEqual(0,pfls[0].getIJ(1,0)); + self.assertEqual(0,pfls[1].getIJ(0,0)); + # + val4=[3,4] + d=DataArrayInt.New(); + d.setValues(val4,2,1); + code,idsInPflPerType,pfls=m.splitProfilePerType(d); + self.assertEqual(3,len(code)); + self.assertEqual(1,len(idsInPflPerType)); + expected4=[4,2,0] + for i in xrange(3): + self.assertEqual(expected4[i],code[i]); + pass + self.assertEqual(1,len(idsInPflPerType)); + self.assertEqual(2,idsInPflPerType[0].getNumberOfTuples()); + self.assertEqual(0,idsInPflPerType[0].getIJ(0,0)); + self.assertEqual(1,idsInPflPerType[0].getIJ(1,0)); + # + self.assertEqual(1,len(pfls)); + self.assertEqual(2,pfls[0].getNumberOfTuples()); + self.assertEqual(1,pfls[0].getIJ(0,0)); + self.assertEqual(2,pfls[0].getIJ(1,0)); + pass + + def testDAIBuildExplicitArrByRanges1(self): + d=DataArrayInt.New(); + vals1=[0,2,3] + d.setValues(vals1,3,1); + e=DataArrayInt.New(); + vals2=[0,3,6,10,14,20] + e.setValues(vals2,6,1); + # + f=d.buildExplicitArrByRanges(e); + self.assertEqual(11,f.getNumberOfTuples()); + self.assertEqual(1,f.getNumberOfComponents()); + expected1=[0,1,2,6,7,8,9,10,11,12,13] + for i in xrange(11): + self.assertEqual(expected1[i],f.getIJ(i,0)); + pass + pass + + def testDAIComputeOffsets2(self): + d=DataArrayInt.New(); + vals1=[3,5,1,2,0,8] + expected1=[0,3,8,9,11,11,19] + d.setValues(vals1,6,1); + d.computeOffsets2(); + self.assertEqual(7,d.getNumberOfTuples()); + self.assertEqual(1,d.getNumberOfComponents()); + for i in xrange(7): + self.assertEqual(expected1[i],d.getIJ(0,i)); + pass + pass def setUp(self): pass diff --git a/src/MEDLoader/MEDFileData.cxx b/src/MEDLoader/MEDFileData.cxx new file mode 100644 index 000000000..7f9d1804a --- /dev/null +++ b/src/MEDLoader/MEDFileData.cxx @@ -0,0 +1,99 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDFileData.hxx" + +using namespace ParaMEDMEM; + +MEDFileData *MEDFileData::New(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileData(fileName); +} + +MEDFileData *MEDFileData::New() +{ + return new MEDFileData; +} + +MEDFileFields *MEDFileData::getFields() const +{ + return const_cast(static_cast(_fields)); +} + +MEDFileMeshes *MEDFileData::getMeshes() const +{ + return const_cast(static_cast(_meshes)); +} + +void MEDFileData::setFields(MEDFileFields *fields) throw(INTERP_KERNEL::Exception) +{ + if(!fields) + throw INTERP_KERNEL::Exception("MEDFileData::setFields : input pointer is null !"); + fields->incrRef(); + _fields=fields; +} + +void MEDFileData::setMeshes(MEDFileMeshes *meshes) throw(INTERP_KERNEL::Exception) +{ + if(!meshes) + throw INTERP_KERNEL::Exception("MEDFileData::setMeshes : input pointer is null !"); + meshes->incrRef(); + _meshes=meshes; +} + +int MEDFileData::getNumberOfFields() const throw(INTERP_KERNEL::Exception) +{ + const MEDFileFields *f=_fields; + if(!f) + throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfFields : no fields set !"); + return f->getNumberOfFields(); +} + +int MEDFileData::getNumberOfMeshes() const throw(INTERP_KERNEL::Exception) +{ + const MEDFileMeshes *m=_meshes; + if(!m) + throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfMeshes : no meshes set !"); + return m->getNumberOfMeshes(); +} + +MEDFileData::MEDFileData() +{ +} + +MEDFileData::MEDFileData(const char *fileName) throw(INTERP_KERNEL::Exception) +try + { + _fields=MEDFileFields::New(fileName); + _meshes=MEDFileMeshes::New(fileName); + } +catch(INTERP_KERNEL::Exception& e) + { + throw e; + } + +void MEDFileData::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +{ + const MEDFileMeshes *ms=_meshes; + if(ms) + ms->write(fileName,mode); + const MEDFileFields *fs=_fields; + if(fs) + fs->write(fileName,mode); +} diff --git a/src/MEDLoader/MEDFileData.hxx b/src/MEDLoader/MEDFileData.hxx new file mode 100644 index 000000000..2fb00eaf2 --- /dev/null +++ b/src/MEDLoader/MEDFileData.hxx @@ -0,0 +1,54 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDFILEDATA_HXX__ +#define __MEDFILEDATA_HXX__ + +#include "MEDCouplingAutoRefCountObjectPtr.hxx" +#include "MEDFileField.hxx" +#include "MEDFileMesh.hxx" + +namespace ParaMEDMEM +{ + /*! + * User class. + */ + class MEDFileData : public RefCountObject, public MEDFileWritable + { + public: + static MEDFileData *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileData *New(); + MEDFileFields *getFields() const; + MEDFileMeshes *getMeshes() const; + void setFields(MEDFileFields *fields) throw(INTERP_KERNEL::Exception); + void setMeshes(MEDFileMeshes *meshes) throw(INTERP_KERNEL::Exception); + int getNumberOfFields() const throw(INTERP_KERNEL::Exception); + int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception); + // + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + private: + MEDFileData(); + MEDFileData(const char *fileName) throw(INTERP_KERNEL::Exception); + private: + MEDCouplingAutoRefCountObjectPtr _fields; + MEDCouplingAutoRefCountObjectPtr _meshes; + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 1c79e25a4..7b958119c 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -101,7 +101,7 @@ void MEDFileFieldLoc::writeLL(med_idt fid) const MEDlocalizationWr(fid,_name.c_str(),typmai3[(int)_geo_type],_dim,&_ref_coo[0],MED_FULL_INTERLACE,_nb_gauss_pt,&_gs_coo[0],&_w[0],MED_NO_INTERPOLATION,MED_NO_MESH_SUPPORT); } -void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { _type=field->getTypeOfField(); const DataArrayDouble *da=field->getArray(); @@ -163,7 +163,56 @@ void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int offset, int nbO } } -void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +/*! + * Leaf method of field with profile assignement. + * @param pflName input containing name of profile if any. 0 if no profile. + * @param multiTypePfl input containing the profile array \b including \b all \b types. This array is usefull only for GAUSS_NE. + * @param idsInPfl input containing the ids in the profile 'multiTypePfl' concerning the current geo type. + */ +void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(const char *pflName, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) +{ + if(pflName) + _profile=pflName; + else + _profile.clear(); + _type=field->getTypeOfField(); + const DataArrayDouble *da=field->getArray(); + switch(_type) + { + case ON_NODES: + { + _nval=idsInPfl->getNumberOfTuples(); + _arr=da->deepCpy(); + break; + } + case ON_CELLS: + { + _nval=idsInPfl->getNumberOfTuples(); + _arr=da->selectByTupleId(idsInPfl->getConstPointer(),idsInPfl->getConstPointer()+_nval); + break; + } + case ON_GAUSS_NE: + { + MEDCouplingAutoRefCountObjectPtr arr=field->getDiscretization()->getOffsetArr(mesh); + MEDCouplingAutoRefCountObjectPtr arr2=arr->deltaShiftIndex(); + MEDCouplingAutoRefCountObjectPtr arr3=arr2->selectByTupleId(multiTypePfl->getConstPointer(),multiTypePfl->getConstPointer()+multiTypePfl->getNumberOfTuples()); + arr3->computeOffsets2(); + MEDCouplingAutoRefCountObjectPtr tmp=idsInPfl->buildExplicitArrByRanges(arr3); + int trueNval=tmp->getNumberOfTuples(); + _nval=idsInPfl->getNumberOfTuples(); + _arr=da->selectByTupleIdSafe(tmp->getConstPointer(),tmp->getConstPointer()+trueNval); + break; + } + case ON_GAUSS_PT: + { + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for profiles on gauss points !"); + } + default: + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !"); + } +} + +void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { _arr=field->getArray()->deepCpy(); _nval=field->getArray()->getNumberOfTuples(); @@ -203,7 +252,15 @@ try:_type(atype),_father(fath),_profile_it(profileIt) _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE); _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE); if(type==ON_CELLS && !_localization.empty()) - setType(ON_GAUSS_PT); + { + if(_localization!="MED_GAUSS_ELNO") + setType(ON_GAUSS_PT); + else + { + setType(ON_GAUSS_NE); + _localization.clear(); + } + } } catch(INTERP_KERNEL::Exception& e) { @@ -284,7 +341,7 @@ std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const return _localization; } -void MEDFileFieldPerMeshPerTypePerDisc::getFieldAtLevel(TypeOfField type, const MEDFieldFieldGlobs *glob, std::vector& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const +void MEDFileFieldPerMeshPerTypePerDisc::getFieldAtLevel(TypeOfField type, const MEDFieldFieldGlobsReal *glob, std::vector& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const { if(type!=_type) return ; @@ -335,20 +392,59 @@ MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh return new MEDFileFieldPerMeshPerType(fath,geoType); } -void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { std::vector pos=addNewEntryIfNecessary(field,offset,nbOfCells); for(std::vector::const_iterator it=pos.begin();it!=pos.end();it++) _field_pm_pt_pd[*it]->assignFieldNoProfile(offset,nbOfCells,field,glob); } -void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +void MEDFileFieldPerMeshPerType::assignFieldProfile(const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) +{ + std::vector pos=addNewEntryIfNecessary(field,idsInPfl); + if(locIds) + { + // + std::string pflName(locIds->getName()); + if(pflName.empty()) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignFieldProfile : existing profile with empty name !"); + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); + std::ostringstream oss; oss << pflName << "_" << cm.getRepr(); + locIds->setName(oss.str().c_str()); + glob.appendProfile(locIds); + // + for(std::vector::const_iterator it=pos.begin();it!=pos.end();it++) + _field_pm_pt_pd[*it]->assignFieldProfile(oss.str().c_str(),multiTypePfl,idsInPfl,field,mesh,glob); + } + else + { + for(std::vector::const_iterator it=pos.begin();it!=pos.end();it++) + _field_pm_pt_pd[*it]->assignFieldProfile(0,multiTypePfl,idsInPfl,field,mesh,glob); + } +} + +void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { _field_pm_pt_pd.resize(1); _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3); _field_pm_pt_pd[0]->assignNodeFieldNoProfile(field,glob); } +void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) +{ + std::string pflName(pfl->getName()); + if(pflName.empty()) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : existing profile with empty name !"); + std::ostringstream oss; oss << pflName << "_NODE"; + MEDCouplingAutoRefCountObjectPtr pfl2=pfl->deepCpy(); + pfl2->setName(oss.str().c_str()); + glob.appendProfile(pfl2); + // + _field_pm_pt_pd.resize(1); + _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3); + _field_pm_pt_pd[0]->assignFieldProfile(oss.str().c_str(),pfl,pfl2,field,0,glob);//mesh is not requested so 0 is send. +} + std::vector MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception) { TypeOfField type=field->getTypeOfField(); @@ -419,6 +515,76 @@ std::vector MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const M return ret; } +std::vector MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception) +{ + TypeOfField type=field->getTypeOfField(); + if(type!=ON_GAUSS_PT) + { + int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0); + int sz=_field_pm_pt_pd.size(); + bool found=false; + for(int j=0;jgetLocId()==locIdToFind) + { + _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind); + found=true; + } + } + if(!found) + { + _field_pm_pt_pd.resize(sz+1); + _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind); + } + std::vector ret(1,0); + return ret; + } + else + { + std::vector ret2=addNewEntryIfNecessaryGauss(field,subCells); + int sz2=ret2.size(); + std::vector ret3(sz2); + int k=0; + for(int i=0;igetLocId()==locIdToFind) + { + _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind); + ret3[k++]=j; + found=true; + } + } + if(!found) + { + _field_pm_pt_pd.resize(sz+1); + _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind); + ret3[k++]=sz; + } + } + return ret3; + } +} + +std::vector MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception) +{ + const MEDCouplingFieldDiscretization *disc=field->getDiscretization(); + const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast(disc); + if(!disc2) + throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !"); + const DataArrayInt *da=disc2->getArrayOfDiscIds(); + MEDCouplingAutoRefCountObjectPtr da2=da->selectByTupleId(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples()); + std::set retTmp=da2->getDifferentValues(); + if(retTmp.find(-1)!=retTmp.end()) + throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !"); + std::vector ret(retTmp.begin(),retTmp.end()); + return ret; +} + const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const { return _father; @@ -496,7 +662,7 @@ std::vector MEDFileFieldPerMeshPerType::getLocsReallyUsed() const return ret; } -void MEDFileFieldPerMeshPerType::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFieldFieldGlobs *glob, std::vector& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const +void MEDFileFieldPerMeshPerType::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFieldFieldGlobsReal *glob, std::vector& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const { if(_geo_type!=INTERP_KERNEL::NORM_ERROR) { @@ -529,7 +695,11 @@ void MEDFileFieldPerMeshPerType::finishLoading(med_idt fid, TypeOfField type) th void MEDFileFieldPerMeshPerType::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) { - _field_pm_pt_pd[0]->writeLL(fid); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++) + { + (*it)->copyOptionsFrom(*this); + (*it)->writeLL(fid); + } } med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType) @@ -570,7 +740,25 @@ void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh) throw(IN mesh->getTime(_mesh_iteration,_mesh_order); } -void MEDFileFieldPerMesh::assignFieldNoProfile(const std::vector& code, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +void MEDFileFieldPerMesh::assignFieldProfile(const DataArrayInt *multiTypePfl, const std::vector& code, const std::vector& idsInPflPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) +{ + int nbOfTypes=code.size()/3; + bool isProfile=false; + for(int i=0;i& code, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { int nbOfTypes=code.size()/3; int offset=0; @@ -584,12 +772,35 @@ void MEDFileFieldPerMesh::assignFieldNoProfile(const std::vector& code, con } } -void MEDFileFieldPerMesh::assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +/*! + * This method is the most general one. No optimization is done here. + */ +void MEDFileFieldPerMesh::assignFieldProfileGeneral(const DataArrayInt *multiTypePfl, const std::vector& code, const std::vector& idsInPflPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) +{ + int nbOfTypes=code.size()/3; + for(int i=0;iassignFieldProfile(multiTypePfl,idsInPflPerType[i],pfl,field,mesh,glob); + } +} + +void MEDFileFieldPerMesh::assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR); _field_pm_pt[pos]->assignNodeFieldNoProfile(field,glob); } +void MEDFileFieldPerMesh::assignNodeFieldProfile(const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) +{ + int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR); + _field_pm_pt[pos]->assignNodeFieldProfile(pfl,field,glob); +} + void MEDFileFieldPerMesh::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception) { INTERP_KERNEL::AutoPtr meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); @@ -629,7 +840,10 @@ void MEDFileFieldPerMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Except { int nbOfTypes=_field_pm_pt.size(); for(int i=0;iwriteLL(fid); + { + _field_pm_pt[i]->copyOptionsFrom(*this); + _field_pm_pt[i]->writeLL(fid); + } } void MEDFileFieldPerMesh::getDimension(int& dim) const @@ -674,14 +888,14 @@ const std::vector& MEDFileFieldPerMesh::getInfo() const } /*! - * geoTypes,dads,pfls,locs are input parameters. They should have the same size. + * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size. * Before the call of this method 'geoTypes','dads','pfls','locs' must be reorganized so that types in geoTypes are contiguous and ordered following typmai2 array. * It returns 2 output vectors : * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes' * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed. * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format. */ -void MEDFileFieldPerMesh::SortArraysPerType(const MEDFieldFieldGlobs *glob, const std::vector& geoTypes, const std::vector& dads, const std::vector& pfls, const std::vector& locs, std::vector& code, std::vector& notNullPfls) +void MEDFileFieldPerMesh::SortArraysPerType(const MEDFieldFieldGlobsReal *glob, TypeOfField type, const std::vector& geoTypes, const std::vector& dads, const std::vector& pfls, const std::vector& locs, std::vector& code, std::vector& notNullPfls) { int notNullPflsSz=0; int nbOfArrs=geoTypes.size(); @@ -714,7 +928,7 @@ void MEDFileFieldPerMesh::SortArraysPerType(const MEDFieldFieldGlobs *glob, cons std::vector tmpPfls(pfls.begin()+startZone,pfls.begin()+j); std::vector tmpLocs(locs.begin()+startZone,locs.begin()+j); code[3*i]=(int)refType; - code[3*i+1]=ComputeNbOfElems(glob,tmpDads,tmpLocs); + code[3*i+1]=ComputeNbOfElems(glob,type,refType,tmpDads,tmpLocs); if(notNullTmp.empty()) code[3*i+2]=-1; else @@ -728,14 +942,22 @@ void MEDFileFieldPerMesh::SortArraysPerType(const MEDFieldFieldGlobs *glob, cons /*! * 'dads' and 'locs' are input parameters that should have same size sz. sz should be >=1. */ -int MEDFileFieldPerMesh::ComputeNbOfElems(const MEDFieldFieldGlobs *glob, const std::vector& dads, const std::vector& locs) throw(INTERP_KERNEL::Exception) +int MEDFileFieldPerMesh::ComputeNbOfElems(const MEDFieldFieldGlobsReal *glob, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const std::vector& dads, const std::vector& locs) throw(INTERP_KERNEL::Exception) { int sz=dads.size(); int ret=0; for(int i=0;igetNumberOfTuples(); + { + if(type!=ON_GAUSS_NE) + ret+=dads[i]->getNumberOfTuples(); + else + { + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoType); + ret+=dads[i]->getNumberOfTuples()/cm.getNumberOfNodes(); + } + } else { int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]); @@ -779,7 +1001,7 @@ std::vector MEDFileFieldPerMesh::getLocsReallyUsed() const return ret; } -MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, int meshDim, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception) +MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFieldFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception) { if(_field_pm_pt.empty()) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !"); @@ -790,9 +1012,9 @@ MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField t std::vector locs,code; std::vector geoTypes; for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) - (*it)->getFieldAtLevel(meshDim,type,glob,dads,pfls,locs,geoTypes); + (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes); // Sort by types - SortArraysPerType(glob,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType); + SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType); if(code.empty()) { std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << getName() << "\" exists but not with such spatial discretization or such dimension specified !"; @@ -832,6 +1054,52 @@ MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField t } } +DataArrayDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFieldFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception) +{ + if(_field_pm_pt.empty()) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !"); + // + std::vector dads; + std::vector pfls; + std::vector notNullPflsPerGeoType; + std::vector locs,code; + std::vector geoTypes; + for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes); + // Sort by types + SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType); + if(code.empty()) + { + std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << getName() << "\" exists but not with such spatial discretization or such dimension specified !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + std::vector< MEDCouplingAutoRefCountObjectPtr > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end()); + std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end()); + if(type!=ON_NODES) + { + MEDCouplingAutoRefCountObjectPtr arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3); + return finishField4(dads,arr,mesh->getNumberOfCells(),pfl); + } + else + { + if(code.size()!=3) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !"); + int nb=code[1]; + if(code[2]==-1) + { + if(nb!=mesh->getNumberOfNodes()) + { + std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes(); + oss << " nodes in mesh !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl); + } + // + return 0; +} + int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type) { int i=0; @@ -854,7 +1122,7 @@ int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellTyp return ret; } -MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFieldFieldGlobs *glob, +MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFieldFieldGlobsReal *glob, const std::vector& dads, const std::vector& locs, const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception) { @@ -874,7 +1142,7 @@ MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const for(int i=0;i dads2(1,dads[i]); const std::vector locs2(1,locs[i]); - int nbOfElems=ComputeNbOfElems(glob,dads2,locs2); + int nbOfElems=ComputeNbOfElems(glob,type,INTERP_KERNEL::NORM_ERROR,dads2,locs2); MEDCouplingAutoRefCountObjectPtr di=DataArrayInt::New(); di->alloc(nbOfElems,1); di->iota(offset); @@ -893,14 +1161,14 @@ MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support. * The order of cells in the returned field is those imposed by the profile. */ -MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFieldFieldGlobs *glob, +MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFieldFieldGlobsReal *glob, const std::vector& dads, const std::vector& locs, const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl) const throw(INTERP_KERNEL::Exception) { if(da->isIdentity()) { int nbOfTuples=da->getNumberOfTuples(); - if(nbOfTuples==ComputeNbOfElems(glob,dads,locs)) + if(nbOfTuples==ComputeNbOfElems(glob,type,INTERP_KERNEL::NORM_ERROR,dads,locs))//No problem for NORM_ERROR because it is in context of node return finishField(type,glob,dads,locs,mesh,isPfl); } MEDCouplingAutoRefCountObjectPtr ret=finishField(type,glob,dads,locs,mesh,isPfl); @@ -915,14 +1183,14 @@ MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, cons /*! * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles. */ -MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField3(const MEDFieldFieldGlobs *glob, +MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField3(const MEDFieldFieldGlobsReal *glob, const std::vector& dads, const std::vector& locs, const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl) const throw(INTERP_KERNEL::Exception) { if(da->isIdentity()) { int nbOfTuples=da->getNumberOfTuples(); - if(nbOfTuples==ComputeNbOfElems(glob,dads,locs)) + if(nbOfTuples==ComputeNbOfElems(glob,ON_NODES,INTERP_KERNEL::NORM_ERROR,dads,locs))//No problem for NORM_ERROR because it is in context of node return finishField(ON_NODES,glob,dads,locs,mesh,isPfl); } MEDCouplingAutoRefCountObjectPtr ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl); @@ -946,6 +1214,33 @@ MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField3(const MEDFieldFieldGlo return 0; } +/*! + * This method is the most light method of field retrieving. + */ +DataArrayDouble *MEDFileFieldPerMesh::finishField4(const std::vector& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const throw(INTERP_KERNEL::Exception) +{ + if(!pflIn) + { + pflOut=DataArrayInt::New(); + pflOut->alloc(nbOfElems,1); + pflOut->iota(0); + } + else + { + pflOut=const_cast(pflIn); + pflOut->incrRef(); + } + MEDCouplingAutoRefCountObjectPtr safePfl(pflOut); + MEDCouplingAutoRefCountObjectPtr da=DataArrayDouble::Aggregate(dads); + const std::vector& infos=getInfo(); + int nbOfComp=infos.size(); + for(int i=0;isetInfoOnComponent(i,infos[i].c_str()); + safePfl->incrRef(); + da->incrRef(); + return da; +} + MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, int meshCsit, int meshIteration, int meshOrder):_mesh_iteration(meshIteration),_mesh_order(meshOrder), _mesh_csit(meshCsit),_father(fath) { @@ -958,6 +1253,8 @@ MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, const void MEDFieldFieldGlobs::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception) { + if(id>=(int)_pfls.size()) + _pfls.resize(id+1); _pfls[id]=DataArrayInt::New(); int lgth=MEDprofileSizeByName(fid,pflName); _pfls[id]->setName(pflName); @@ -972,6 +1269,8 @@ void MEDFieldFieldGlobs::loadProfileInFile(med_idt fid, int i) int sz; MEDprofileInfo(fid,i+1,pflName,&sz); std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE); + if(i>=(int)_pfls.size()) + _pfls.resize(i+1); _pfls[i]=DataArrayInt::New(); _pfls[i]->alloc(sz,1); _pfls[i]->setName(pflCpp.c_str()); @@ -995,21 +1294,31 @@ void MEDFieldFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) c _locs[i]->writeLL(fid); } -void MEDFieldFieldGlobs::loadGlobals(med_idt fid) throw(INTERP_KERNEL::Exception) +void MEDFieldFieldGlobs::loadGlobals(med_idt fid, const MEDFieldFieldGlobsReal& real) throw(INTERP_KERNEL::Exception) { - std::vector profiles=getPflsReallyUsed(); + std::vector profiles=real.getPflsReallyUsed(); int sz=profiles.size(); _pfls.resize(sz); for(int i=0;i locs=getLocsReallyUsed(); + std::vector locs=real.getLocsReallyUsed(); sz=locs.size(); _locs.resize(sz); for(int i=0;i=_locs.size()) + if(locId<0 || locId>=(int)_locs.size()) throw INTERP_KERNEL::Exception("MEDFieldFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !"); return _locs[locId]->getNbOfGaussPtPerCell(); } const MEDFileFieldLoc& MEDFieldFieldGlobs::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception) { - if(locId<0 || locId>=_locs.size()) + if(locId<0 || locId>=(int)_locs.size()) throw INTERP_KERNEL::Exception("MEDFieldFieldGlobs::getLocalizationFromId : Invalid localization id !"); return *_locs[locId]; } @@ -1138,6 +1451,94 @@ void MEDFieldFieldGlobs::appendLoc(const char *locName, INTERP_KERNEL::Normalize _locs.push_back(obj); } +MEDFieldFieldGlobsReal::MEDFieldFieldGlobsReal(const char *fname):_globals(MEDFieldFieldGlobs::New(fname)) +{ +} + +MEDFieldFieldGlobsReal::MEDFieldFieldGlobsReal():_globals(MEDFieldFieldGlobs::New()) +{ +} + +void MEDFieldFieldGlobsReal::shallowCpyGlobs(const MEDFieldFieldGlobsReal& other) +{ + _globals=other._globals; +} + +void MEDFieldFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception) +{ + _globals->loadProfileInFile(fid,id,pflName); +} + +void MEDFieldFieldGlobsReal::loadProfileInFile(med_idt fid, int id) +{ + _globals->loadProfileInFile(fid,id); +} + +void MEDFieldFieldGlobsReal::loadGlobals(med_idt fid) throw(INTERP_KERNEL::Exception) +{ + _globals->loadGlobals(fid,*this); +} + +void MEDFieldFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception) +{ + _globals->writeGlobals(fid,opt); +} + +std::vector MEDFieldFieldGlobsReal::getPfls() const +{ + return _globals->getPfls(); +} + +std::vector MEDFieldFieldGlobsReal::getLocs() const +{ + return _globals->getLocs(); +} + +void MEDFieldFieldGlobsReal::setFileName(const char *fileName) +{ + _globals->setFileName(fileName); +} + +int MEDFieldFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception) +{ + return _globals->getNbOfGaussPtPerCell(locId); +} + +int MEDFieldFieldGlobsReal::getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception) +{ + return _globals->getLocalizationId(loc); +} + +const char *MEDFieldFieldGlobsReal::getFileName() const +{ + return _globals->getFileName(); +} + +std::string MEDFieldFieldGlobsReal::getFileName2() const +{ + return _globals->getFileName2(); +} + +const MEDFileFieldLoc& MEDFieldFieldGlobsReal::getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception) +{ + return _globals->getLocalizationFromId(locId); +} + +const DataArrayInt *MEDFieldFieldGlobsReal::getProfile(const std::string& pflName) const throw(INTERP_KERNEL::Exception) +{ + return _globals->getProfile(pflName); +} + +void MEDFieldFieldGlobsReal::appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception) +{ + _globals->appendProfile(pfl); +} + +void MEDFieldFieldGlobsReal::appendLoc(const char *locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& w) throw(INTERP_KERNEL::Exception) +{ + _globals->appendLoc(locName,geoType,refCoo,gsCoo,w); +} + /*! * This method returns the max dimension of 'this'. * This method returns -2 if 'this' is empty, -1 if only nodes are defined. @@ -1177,7 +1578,7 @@ std::vector MEDFileField1TSWithoutDAS::CheckSBTMesh(const MEDCouplingMesh * int nbCells=mesh->getNumberOfCellsWithType(*it); code[3*pos]=(int)(*it); code[3*pos+1]=nbCells; - code[3*pos+2]=0;//no profiles + code[3*pos+2]=-1;//no profiles } std::vector idsPerType;//no profiles DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType); @@ -1304,10 +1705,68 @@ void MEDFileField1TSWithoutDAS::writeLL(med_idt fid) const throw(INTERP_KERNEL:: throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutDAS::writeLL : empty field !"); if(_field_per_mesh.size()>1) throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutDAS::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !"); + _field_per_mesh[0]->copyOptionsFrom(*this); _field_per_mesh[0]->writeLL(fid); } -MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const char *mName, int renumPol, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception) +/*! + * SBT means Sort By Type. + * This method is the most basic method to assign field in this. Basic in sense that no renumbering is done. Underlying mesh in 'field' is globaly ignored except for type contiguous check. + */ +void MEDFileField1TSWithoutDAS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) +{ + const MEDCouplingMesh *mesh=field->getMesh(); + // + TypeOfField type=field->getTypeOfField(); + std::vector dummy; + copyTinyInfoFrom(field); + if(type!=ON_NODES) + { + std::vector code=MEDFileField1TSWithoutDAS::CheckSBTMesh(mesh); + // + int pos=addNewEntryIfNecessary(mesh); + _field_per_mesh[pos]->assignFieldProfile(0,code,dummy,dummy,field,0,glob);//mesh is set to 0 because no external mesh is needed to be sent because no profile. + } + else + { + int pos=addNewEntryIfNecessary(mesh); + _field_per_mesh[pos]->assignNodeFieldNoProfile(field,glob); + } +} + +/*! + * Generalization of MEDFileField1TSWithoutDAS::setFieldNoProfileSBT method. + */ +void MEDFileField1TSWithoutDAS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) +{ + TypeOfField type=field->getTypeOfField(); + copyTinyInfoFrom(field); + std::vector idsInPflPerType; + std::vector idsPerType; + std::vector code; + MEDCouplingAutoRefCountObjectPtr m=mesh->getGenMeshAtLevel(meshDimRelToMax); + if(type!=ON_NODES) + { + m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType); + // + std::vector< MEDCouplingAutoRefCountObjectPtr > idsInPflPerType2(idsInPflPerType.size()); + for(std::size_t i=0;i > idsPerType2(idsPerType.size()); + for(std::size_t i=0;iassignFieldProfile(profile,code,idsInPflPerType,idsPerType,field,m,glob); + } + else + { + int pos=addNewEntryIfNecessary(m); + _field_per_mesh[pos]->assignNodeFieldProfile(profile,field,glob); + } +} + +MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const char *mName, int renumPol, const MEDFieldFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception) { MEDCouplingAutoRefCountObjectPtr mm; if(mName==0) @@ -1317,7 +1776,7 @@ MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldAtLevel(TypeOfField t return MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm); } -MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFieldFieldGlobs *glob, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception) +MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFieldFieldGlobsReal *glob, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception) { CheckMeshDimRel(meshDimRelToMax); MEDCouplingAutoRefCountObjectPtr m=mesh->getGenMeshAtLevel(meshDimRelToMax,false); @@ -1326,13 +1785,12 @@ MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(TypeOfF return MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e); } -MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh, const DataArrayInt *cellRenum, const DataArrayInt *nodeRenum) const throw(INTERP_KERNEL::Exception) +MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFieldFieldGlobsReal *glob, const MEDCouplingMesh *mesh, const DataArrayInt *cellRenum, const DataArrayInt *nodeRenum) const throw(INTERP_KERNEL::Exception) { static const char msg1[]="MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !"; - int dimRequested=mesh->getMeshDimension(); int meshId=getMeshIdFromMeshName(mesh->getName()); bool isPfl=false; - MEDCouplingAutoRefCountObjectPtr ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,dimRequested,glob,mesh,isPfl); + MEDCouplingAutoRefCountObjectPtr ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl); switch(renumPol) { case 0: @@ -1387,6 +1845,13 @@ MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(TypeOfF } } +DataArrayDouble *MEDFileField1TSWithoutDAS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFieldFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr m=mesh->getGenMeshAtLevel(meshDimRelToMax); + int meshId=getMeshIdFromMeshName(mesh->getName()); + return _field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob); +} + MEDFileField1TSWithoutDAS::MEDFileField1TSWithoutDAS(const char *fieldName, int csit, int iteration, int order, const std::vector& infos):_name(fieldName),_infos(infos),_csit(csit),_iteration(iteration),_order(order) { @@ -1458,13 +1923,15 @@ void MEDFileField1TS::write(const char *fileName, int mode) const throw(INTERP_K MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str); MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str); } + if(_name.empty()) + throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !"); MEDfieldCr(fid,_name.c_str(),MED_FLOAT64,nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()); writeGlobals(fid,*this); writeLL(fid); } MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) -try:MEDFileField1TSWithoutDAS(fieldName,-1,iteration,order,std::vector()),MEDFieldFieldGlobs(fileName) +try:MEDFileField1TSWithoutDAS(fieldName,-1,iteration,order,std::vector()),MEDFieldFieldGlobsReal(fileName) { MEDFileUtilities::CheckFileForRead(fileName); MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); @@ -1555,7 +2022,7 @@ std::vector MEDFileField1TS::getLocsReallyUsed() const */ MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception) { - if(_file_name.empty()) + if(getFileName2().empty()) throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !"); return MEDFileField1TSWithoutDAS::getFieldAtLevel(type,meshDimRelToMax,0,renumPol,this); } @@ -1588,11 +2055,16 @@ MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, */ MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, int renumPol) const throw(INTERP_KERNEL::Exception) { - if(_file_name.empty()) + if(getFileName2().empty()) throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !"); return MEDFileField1TSWithoutDAS::getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this); } +DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception) +{ + return MEDFileField1TSWithoutDAS::getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this); +} + /*! * SBT means Sort By Type. * This method is the most basic method to assign field in this. Basic in sense that no renumbering is done. Underlying mesh in 'field' is globaly ignored except for type contiguous check. @@ -1600,24 +2072,22 @@ MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, co */ void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception) { - _file_name=""; - const MEDCouplingMesh *mesh=field->getMesh(); - // - TypeOfField type=field->getTypeOfField(); - if(type!=ON_NODES) - { - std::vector code=MEDFileField1TSWithoutDAS::CheckSBTMesh(mesh); - copyTinyInfoFrom(field); - // - int pos=addNewEntryIfNecessary(mesh); - _field_per_mesh[pos]->assignFieldNoProfile(code,field,*this); - } - else - { - copyTinyInfoFrom(field); - int pos=addNewEntryIfNecessary(mesh); - _field_per_mesh[pos]->assignNodeFieldNoProfile(field,*this); - } + setFileName(""); + MEDFileField1TSWithoutDAS::setFieldNoProfileSBT(field,*this); +} + +/*! + * This method is a generalization of MEDFileField1TS::setFieldNoProfileSBT method. Here a profile array is given in input. + * The support of field 'field' is \b not used by this method, so it can be null or incoherent with field. + * This method uses input parameters 'mesh', 'meshDimRelToMax' and 'profile' to determine what is really the support of field 'field'. If field is incoherent regarding this deduced support, + * an exception will be thrown. + * This method is trying to reduce the size of MEDfile file so profile is created only if it is absolutely necessary. If it is necessary the name of 'profile' will be used to create it in 'this'. + * In this case, if this profile name is empty an exception will be thrown. + */ +void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception) +{ + setFileName(""); + MEDFileField1TSWithoutDAS::setFieldProfile(field,mesh,meshDimRelToMax,profile,*this); } MEDFileFieldMultiTSWithoutDAS *MEDFileFieldMultiTSWithoutDAS::New(med_idt fid, const char *fieldName, int id, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception) @@ -1625,12 +2095,16 @@ MEDFileFieldMultiTSWithoutDAS *MEDFileFieldMultiTSWithoutDAS::New(med_idt fid, c return new MEDFileFieldMultiTSWithoutDAS(fid,fieldName,id,infos,nbOfStep); } +MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS() +{ +} + MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(const char *fieldName):_name(fieldName) { } MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception) -try:_name(fieldName) +try:_name(fieldName),_infos(infos) { finishLoading(fid,nbOfStep); } @@ -1660,6 +2134,34 @@ std::string MEDFileFieldMultiTSWithoutDAS::getDtUnit() const throw(INTERP_KERNEL return _time_steps[0]->getDtUnit(); } +std::string MEDFileFieldMultiTSWithoutDAS::getName() const +{ + return _name; +} + +std::vector< std::pair > MEDFileFieldMultiTSWithoutDAS::getTimeSteps(std::vector& ret1) const throw(INTERP_KERNEL::Exception) +{ + std::size_t sz=_time_steps.size(); + std::vector< std::pair > ret(sz); + ret1.resize(sz); + for(std::size_t i=0;igetIteration(); + ret[i].second=f1ts->getOrder(); + ret1[i]=f1ts->getTime(); + } + else + { + std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutDAS::getTimeSteps : At rank #" << i << " time step is not defined !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + return ret; +} + void MEDFileFieldMultiTSWithoutDAS::finishLoading(med_idt fid, int nbPdt) throw(INTERP_KERNEL::Exception) { _time_steps.resize(nbPdt); @@ -1675,6 +2177,41 @@ void MEDFileFieldMultiTSWithoutDAS::finishLoading(med_idt fid, int nbPdt) throw( } } +void MEDFileFieldMultiTSWithoutDAS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception) +{ + _name=field->getName(); + if(_name.empty()) + throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutDAS::copyTinyInfoFrom : unsupported fields with no name in MED file !"); + const DataArrayDouble *arr=field->getArray(); + if(!arr) + throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutDAS::copyTinyInfoFrom : no array set !"); + _infos=arr->getInfoOnComponent(); +} + +void MEDFileFieldMultiTSWithoutDAS::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field) const throw(INTERP_KERNEL::Exception) +{ + static const char MSG[]="MEDFileFieldMultiTSWithoutDAS::checkCoherencyOfTinyInfo : invalid "; + if(_name!=field->getName()) + { + std::ostringstream oss; oss << MSG << "name ! should be \"" << _name; + oss << "\" and it is set in input field to \"" << field->getName() << "\" !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const DataArrayDouble *arr=field->getArray(); + if(!arr) + throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutDAS::checkCoherencyOfTinyInfo : no array set !"); + if(_infos!=arr->getInfoOnComponent()) + { + std::ostringstream oss; oss << MSG << "components ! should be \""; + std::copy(_infos.begin(),_infos.end(),std::ostream_iterator(oss,", ")); + oss << " But compo in input fields are : "; + std::vector tmp=arr->getInfoOnComponent(); + std::copy(tmp.begin(),tmp.end(),std::ostream_iterator(oss,", ")); + oss << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } +} + void MEDFileFieldMultiTSWithoutDAS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) { if(_time_steps.empty()) @@ -1691,6 +2228,8 @@ void MEDFileFieldMultiTSWithoutDAS::writeLL(med_idt fid) const throw(INTERP_KERN MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str); MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str); } + if(_name.empty()) + throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutDAS::write : MED file does not accept field with empty name !"); MEDfieldCr(fid,_name.c_str(),MED_FLOAT64,nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()); int nbOfTS=_time_steps.size(); for(int i=0;i MEDFileFieldMultiTSWithoutDAS::getLocsReallyUsed2() con return ret; } +MEDFileFieldMultiTS *MEDFileFieldMultiTS::New() +{ + return new MEDFileFieldMultiTS; +} + MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception) { return new MEDFileFieldMultiTS(fileName,fieldName); } +MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutDAS& other) +{ + return new MEDFileFieldMultiTS(other); +} + void MEDFileFieldMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) { med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); @@ -1821,8 +2370,54 @@ MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type return myF1TS.getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this); } +DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception) +{ + const MEDFileField1TSWithoutDAS& myF1TS=getTimeStepEntry(iteration,order); + return myF1TS.getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this); +} + +void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception) +{ + if(_time_steps.empty()) + { + MEDCouplingAutoRefCountObjectPtr obj=new MEDFileField1TSWithoutDAS; + obj->setFieldNoProfileSBT(field,*this); + copyTinyInfoFrom(field); + _time_steps.push_back(obj); + } + else + { + checkCoherencyOfTinyInfo(field); + MEDCouplingAutoRefCountObjectPtr obj=new MEDFileField1TSWithoutDAS; + obj->setFieldNoProfileSBT(field,*this); + _time_steps.push_back(obj); + } +} + +void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception) +{ + if(_time_steps.empty()) + { + MEDCouplingAutoRefCountObjectPtr obj=new MEDFileField1TSWithoutDAS; + obj->setFieldProfile(field,mesh,meshDimRelToMax,profile,*this); + copyTinyInfoFrom(field); + _time_steps.push_back(obj); + } + else + { + checkCoherencyOfTinyInfo(field); + MEDCouplingAutoRefCountObjectPtr obj=new MEDFileField1TSWithoutDAS; + obj->setFieldProfile(field,mesh,meshDimRelToMax,profile,*this); + _time_steps.push_back(obj); + } +} + +MEDFileFieldMultiTS::MEDFileFieldMultiTS() +{ +} + MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception) -try:MEDFileFieldMultiTSWithoutDAS(fieldName),MEDFieldFieldGlobs(fileName) +try:MEDFileFieldMultiTSWithoutDAS(fieldName),MEDFieldFieldGlobsReal(fileName) { MEDFileUtilities::CheckFileForRead(fileName); MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); @@ -1867,6 +2462,10 @@ catch(INTERP_KERNEL::Exception& e) throw e; } +MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutDAS& other):MEDFileFieldMultiTSWithoutDAS(other) +{ +} + std::vector MEDFileFieldMultiTS::getPflsReallyUsed() const { return getPflsReallyUsed2(); @@ -1877,6 +2476,11 @@ std::vector MEDFileFieldMultiTS::getLocsReallyUsed() const return getLocsReallyUsed2(); } +MEDFileFields *MEDFileFields::New() +{ + return new MEDFileFields; +} + MEDFileFields *MEDFileFields::New(const char *fileName) throw(INTERP_KERNEL::Exception) { return new MEDFileFields(fileName); @@ -1887,8 +2491,32 @@ int MEDFileFields::getNumberOfFields() const return _fields.size(); } +std::vector MEDFileFields::getFieldsNames() const throw(INTERP_KERNEL::Exception) +{ + std::vector ret(_fields.size()); + int i=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++) + { + const MEDFileFieldMultiTSWithoutDAS *f=(*it); + if(f) + { + ret[i]=f->getName(); + } + else + { + std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + return ret; +} + +MEDFileFields::MEDFileFields() +{ +} + MEDFileFields::MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception) -try:MEDFieldFieldGlobs(fileName) +try:MEDFieldFieldGlobsReal(fileName) { MEDFileUtilities::CheckFileForRead(fileName); MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); @@ -1908,11 +2536,10 @@ try:MEDFieldFieldGlobs(fileName) MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep); std::vector infos(ncomp); for(int j=0;j >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++) + { + const MEDFileFieldMultiTSWithoutDAS *elt=*it; + if(!elt) + { + std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + elt->copyOptionsFrom(*this); + elt->writeLL(fid); + } +} + std::vector MEDFileFields::getPflsReallyUsed() const { std::vector ret; @@ -1955,3 +2600,76 @@ std::vector MEDFileFields::getLocsReallyUsed() const return ret; } +void MEDFileFields::resize(int newSize) throw(INTERP_KERNEL::Exception) +{ + _fields.resize(newSize); +} + +void MEDFileFields::pushField(MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception) +{ + if(!field) + throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !"); + field->incrRef(); + _fields.push_back(field); +} + +void MEDFileFields::setFieldAtPos(int i, MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception) +{ + if(!field) + throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !"); + if(i>=(int)_fields.size()) + _fields.resize(i+1); + field->incrRef(); + _fields[i]=field; +} + +void MEDFileFields::destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception) +{ + if(i<0 || i>=(int)_fields.size()) + { + std::ostringstream oss; oss << "MEDFileFields::destroyMeshAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + _fields.erase(_fields.begin()+i); +} + +MEDFileFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const throw(INTERP_KERNEL::Exception) +{ + if(i<0 || i>=(int)_fields.size()) + { + std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const MEDFileFieldMultiTSWithoutDAS *fmts=_fields[i]; + MEDCouplingAutoRefCountObjectPtr ret=MEDFileFieldMultiTS::New(*fmts); + ret->shallowCpyGlobs(*this); + ret->incrRef(); + return ret; +} + +MEDFileFieldMultiTS *MEDFileFields::getField(const char *fieldName) const throw(INTERP_KERNEL::Exception) +{ + return getFieldAtPos(getPosFromFieldName(fieldName)); +} + +int MEDFileFields::getPosFromFieldName(const char *fieldName) const throw(INTERP_KERNEL::Exception) +{ + std::string tmp(fieldName); + std::vector poss; + for(std::size_t i=0;i<_fields.size();i++) + { + const MEDFileFieldMultiTSWithoutDAS *f=_fields[i]; + if(f) + { + std::string fname(f->getName()); + if(tmp==fname) + return i; + else + poss.push_back(fname); + } + } + std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : "; + std::copy(poss.begin(),poss.end(),std::ostream_iterator(oss,", ")); + oss << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 36675bf1f..17939b7c9 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -73,6 +73,7 @@ namespace ParaMEDMEM class MEDFileFieldPerMeshPerType; class MEDFileField1TSWithoutDAS; + class MEDFieldFieldGlobsReal; class MEDFileFieldPerMesh; class MEDFileFieldPerMeshPerTypePerDisc : public RefCountObject, public MEDFileWritable @@ -80,8 +81,10 @@ namespace ParaMEDMEM public: static MEDFileFieldPerMeshPerTypePerDisc *New(MEDFileFieldPerMeshPerType *fath, med_idt fid, TypeOfField type, int profileIt) throw(INTERP_KERNEL::Exception); static MEDFileFieldPerMeshPerTypePerDisc *New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId); - void assignFieldNoProfile(int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); - void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); + void assignFieldNoProfile(int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); + void assignFieldProfile(const char *pflName, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); + void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); + void assignNodeFieldProfile(const char *pflName, const DataArrayInt *idsInPfl, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); const MEDFileFieldPerMeshPerType *getFather() const; int getIteration() const; @@ -98,7 +101,7 @@ namespace ParaMEDMEM std::string getProfile() const; std::string getLocalization() const; int getLocId() const { return _loc_id; } - void getFieldAtLevel(TypeOfField type, const MEDFieldFieldGlobs *glob, std::vector& dads, std::vector& pfls, std::vector& locs, + void getFieldAtLevel(TypeOfField type, const MEDFieldFieldGlobsReal *glob, std::vector& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const; static int ConvertType(TypeOfField type, int locId) throw(INTERP_KERNEL::Exception); private: @@ -121,8 +124,10 @@ namespace ParaMEDMEM { public: static MEDFileFieldPerMeshPerType *New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception); - void assignFieldNoProfile(int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); - void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); + void assignFieldNoProfile(int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); + void assignFieldProfile(const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); + void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); + void assignNodeFieldProfile(const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); const MEDFileFieldPerMesh *getFather() const; void finishLoading(med_idt fid, TypeOfField type) throw(INTERP_KERNEL::Exception); void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); @@ -137,11 +142,13 @@ namespace ParaMEDMEM const std::vector& getInfo() const; std::vector getPflsReallyUsed() const; std::vector getLocsReallyUsed() const; - void getFieldAtLevel(int meshDim, TypeOfField type, const MEDFieldFieldGlobs *glob, std::vector& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const; + void getFieldAtLevel(int meshDim, TypeOfField type, const MEDFieldFieldGlobsReal *glob, std::vector& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const; static med_entity_type ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType); private: std::vector addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception); std::vector addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception); + std::vector addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception); + std::vector addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells) throw(INTERP_KERNEL::Exception); MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception); private: MEDFileFieldPerMesh *_father; @@ -155,8 +162,11 @@ namespace ParaMEDMEM static MEDFileFieldPerMesh *New(MEDFileField1TSWithoutDAS *fath, const MEDCouplingMesh *mesh); static MEDFileFieldPerMesh *New(MEDFileField1TSWithoutDAS *fath, int meshCsit, int meshIteration, int meshOrder); void copyTinyInfoFrom(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception); - void assignFieldNoProfile(const std::vector& code, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); - void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); + void assignFieldProfile(const DataArrayInt *multiTypePfl, const std::vector& code, const std::vector& idsInPflPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); + void assignFieldProfileGeneral(const DataArrayInt *multiTypePfl, const std::vector& code, const std::vector& idsInPflPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); + void assignFieldNoProfileNoRenum(const std::vector& code, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); + void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); + void assignNodeFieldProfile(const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception); void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); void getDimension(int& dim) const; @@ -172,21 +182,23 @@ namespace ParaMEDMEM const std::vector& getInfo() const; std::vector getPflsReallyUsed() const; std::vector getLocsReallyUsed() const; - MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDim, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, const MEDFieldFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFieldFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception); private: int addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type); - MEDCouplingFieldDouble *finishField(TypeOfField type, const MEDFieldFieldGlobs *glob, + MEDCouplingFieldDouble *finishField(TypeOfField type, const MEDFieldFieldGlobsReal *glob, const std::vector& dads, const std::vector& locs, const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception); - MEDCouplingFieldDouble *finishField2(TypeOfField type, const MEDFieldFieldGlobs *glob, + MEDCouplingFieldDouble *finishField2(TypeOfField type, const MEDFieldFieldGlobsReal *glob, const std::vector& dads, const std::vector& locs, const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl) const throw(INTERP_KERNEL::Exception); - MEDCouplingFieldDouble *finishField3(const MEDFieldFieldGlobs *glob, + MEDCouplingFieldDouble *finishField3(const MEDFieldFieldGlobsReal *glob, const std::vector& dads, const std::vector& locs, const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl) const throw(INTERP_KERNEL::Exception); - static void SortArraysPerType(const MEDFieldFieldGlobs *glob, + DataArrayDouble *finishField4(const std::vector& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const throw(INTERP_KERNEL::Exception); + static void SortArraysPerType(const MEDFieldFieldGlobsReal *glob, TypeOfField type, const std::vector& geoTypes, const std::vector& dads, const std::vector& pfls, const std::vector& locs, std::vector& code, std::vector& notNullPfls); - static int ComputeNbOfElems(const MEDFieldFieldGlobs *glob, const std::vector& dads, const std::vector& locs) throw(INTERP_KERNEL::Exception); + static int ComputeNbOfElems(const MEDFieldFieldGlobsReal *glob, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const std::vector& dads, const std::vector& locs) throw(INTERP_KERNEL::Exception); MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, int meshCsit, int meshIteration, int meshOrder); MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, const MEDCouplingMesh *mesh); private: @@ -198,14 +210,16 @@ namespace ParaMEDMEM std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > _field_pm_pt; }; - class MEDFieldFieldGlobs + class MEDFieldFieldGlobsReal; + + class MEDFieldFieldGlobs : public RefCountObject { public: - MEDFieldFieldGlobs(const char *fname); - MEDFieldFieldGlobs(); + static MEDFieldFieldGlobs *New(const char *fname); + static MEDFieldFieldGlobs *New(); void loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception); void loadProfileInFile(med_idt fid, int id); - void loadGlobals(med_idt fid) throw(INTERP_KERNEL::Exception); + void loadGlobals(med_idt fid, const MEDFieldFieldGlobsReal& real) throw(INTERP_KERNEL::Exception); void writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception); std::vector getPfls() const; std::vector getLocs() const; @@ -213,19 +227,51 @@ namespace ParaMEDMEM int getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception); int getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception); const char *getFileName() const { return _file_name.c_str(); } + std::string getFileName2() const { return _file_name; } const MEDFileFieldLoc& getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception); - const DataArrayInt *getProfile(const std::string& pflName) const throw(INTERP_KERNEL::Exception); - virtual std::vector getPflsReallyUsed() const = 0; - virtual std::vector getLocsReallyUsed() const = 0; + const DataArrayInt *getProfile(const std::string& pflName) const throw(INTERP_KERNEL::Exception); // void appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception); void appendLoc(const char *locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& w) throw(INTERP_KERNEL::Exception); + protected: + MEDFieldFieldGlobs(const char *fname); + MEDFieldFieldGlobs(); + ~MEDFieldFieldGlobs(); protected: std::vector< MEDCouplingAutoRefCountObjectPtr > _pfls; std::vector< MEDCouplingAutoRefCountObjectPtr > _locs; std::string _file_name; }; + class MEDFieldFieldGlobsReal + { + public: + MEDFieldFieldGlobsReal(const char *fname); + MEDFieldFieldGlobsReal(); + void shallowCpyGlobs(const MEDFieldFieldGlobsReal& other); + virtual std::vector getPflsReallyUsed() const = 0; + virtual std::vector getLocsReallyUsed() const = 0; + // + void loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception); + void loadProfileInFile(med_idt fid, int id); + void loadGlobals(med_idt fid) throw(INTERP_KERNEL::Exception); + void writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception); + std::vector getPfls() const; + std::vector getLocs() const; + void setFileName(const char *fileName); + int getNbOfGaussPtPerCell(int locId) const throw(INTERP_KERNEL::Exception); + int getLocalizationId(const char *loc) const throw(INTERP_KERNEL::Exception); + const char *getFileName() const; + std::string getFileName2() const; + const MEDFileFieldLoc& getLocalizationFromId(int locId) const throw(INTERP_KERNEL::Exception); + const DataArrayInt *getProfile(const std::string& pflName) const throw(INTERP_KERNEL::Exception); + // + void appendProfile(DataArrayInt *pfl) throw(INTERP_KERNEL::Exception); + void appendLoc(const char *locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& w) throw(INTERP_KERNEL::Exception); + protected: + MEDCouplingAutoRefCountObjectPtr< MEDFieldFieldGlobs > _globals; + }; + class MEDFileField1TSWithoutDAS : public RefCountObject, public MEDFileWritable { public: @@ -252,14 +298,19 @@ namespace ParaMEDMEM std::vector getLocsReallyUsed2() const; static void CheckMeshDimRel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception); static std::vector CheckSBTMesh(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception); + // + void setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); + void setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); public: - MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const char *mName, int renumPol, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception); - MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFieldFieldGlobs *glob, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception); - MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh, const DataArrayInt *cellRenum, const DataArrayInt *nodeRenum) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const char *mName, int renumPol, const MEDFieldFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFieldFieldGlobsReal *glob, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFieldFieldGlobsReal *glob, const MEDCouplingMesh *mesh, const DataArrayInt *cellRenum, const DataArrayInt *nodeRenum) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFieldFieldGlobsReal *glob) const throw(INTERP_KERNEL::Exception); protected: int addNewEntryIfNecessary(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception); int getMeshIdFromMeshName(const char *mName) const throw(INTERP_KERNEL::Exception); MEDFileField1TSWithoutDAS(const char *fieldName, int csit, int iteration, int order, const std::vector& infos); + public: MEDFileField1TSWithoutDAS(); protected: std::string _name; @@ -275,19 +326,20 @@ namespace ParaMEDMEM /*! * User class. */ - class MEDFileField1TS : public MEDFileField1TSWithoutDAS, public MEDFieldFieldGlobs + class MEDFileField1TS : public MEDFileField1TSWithoutDAS, public MEDFieldFieldGlobsReal { public: static MEDFileField1TS *New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); static MEDFileField1TS *New(); void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); - void setFileName(const char *fileName); MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception); // void setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception); + void setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); private: std::vector getPflsReallyUsed() const; std::vector getLocsReallyUsed() const; @@ -301,6 +353,9 @@ namespace ParaMEDMEM static MEDFileFieldMultiTSWithoutDAS *New(med_idt fid, const char *fieldName, int id, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception); int getNumberOfTS() const; std::vector< std::pair > getIterations() const; + void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); + std::string getName() const; + std::vector< std::pair > getTimeSteps(std::vector& ret1) const throw(INTERP_KERNEL::Exception); public: std::vector getPflsReallyUsed2() const; std::vector getLocsReallyUsed2() const; @@ -310,10 +365,12 @@ namespace ParaMEDMEM const std::vector& getInfo() const throw(INTERP_KERNEL::Exception); std::string getMeshName() const throw(INTERP_KERNEL::Exception); std::string getDtUnit() const throw(INTERP_KERNEL::Exception); + MEDFileFieldMultiTSWithoutDAS(); MEDFileFieldMultiTSWithoutDAS(const char *fieldName); MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception); void finishLoading(med_idt fid, int nbPdt) throw(INTERP_KERNEL::Exception); - void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); + void copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception); + void checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field) const throw(INTERP_KERNEL::Exception); protected: std::string _name; std::vector _infos; @@ -323,34 +380,54 @@ namespace ParaMEDMEM /*! * User class. */ - class MEDFileFieldMultiTS : public MEDFileFieldMultiTSWithoutDAS, public MEDFieldFieldGlobs + class MEDFileFieldMultiTS : public MEDFileFieldMultiTSWithoutDAS, public MEDFieldFieldGlobsReal { public: + static MEDFileFieldMultiTS *New(); static MEDFileFieldMultiTS *New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception); + static MEDFileFieldMultiTS *New(const MEDFileFieldMultiTSWithoutDAS& other); void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, const char *mname, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const throw(INTERP_KERNEL::Exception); + // + void appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception); + void appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); private: std::vector getPflsReallyUsed() const; std::vector getLocsReallyUsed() const; private: + MEDFileFieldMultiTS(); + MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutDAS& other); MEDFileFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception); }; /*! * Use class. */ - class MEDFileFields : public RefCountObject, public MEDFieldFieldGlobs, public MEDFileWritable + class MEDFileFields : public RefCountObject, public MEDFieldFieldGlobsReal, public MEDFileWritable { public: + static MEDFileFields *New(); static MEDFileFields *New(const char *fileName) throw(INTERP_KERNEL::Exception); + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); int getNumberOfFields() const; + std::vector getFieldsNames() const throw(INTERP_KERNEL::Exception); + // + void resize(int newSize) throw(INTERP_KERNEL::Exception); + void pushField(MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception); + void setFieldAtPos(int i, MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception); + MEDFileFieldMultiTS *getFieldAtPos(int i) const throw(INTERP_KERNEL::Exception); + MEDFileFieldMultiTS *getField(const char *fieldName) const throw(INTERP_KERNEL::Exception); + void destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception); private: + int getPosFromFieldName(const char *fieldName) const throw(INTERP_KERNEL::Exception); std::vector getPflsReallyUsed() const; std::vector getLocsReallyUsed() const; private: + MEDFileFields(); MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception); private: std::vector< MEDCouplingAutoRefCountObjectPtr > _fields; diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 3d66475b0..ffacbfe8b 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -705,6 +705,31 @@ void MEDFileMesh::TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vect std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::bind2nd(std::plus(),offset)); } +/*! + * This method should be called by any set* method of subclasses to deal automatically with _name attribute. + * If _name attribute is empty the name of 'm' if taken as _name attribute. + * If _name is not empty and that 'm' has the same name nothing is done. + * If _name is not emplt and that 'm' has \b NOT the same name an exception is thrown. + */ +void MEDFileMesh::dealWithTinyInfo(const MEDCouplingMesh *m) throw(INTERP_KERNEL::Exception) +{ + if(_name.empty()) + _name=m->getName(); + else + { + std::string name(m->getName()); + if(!name.empty()) + { + if(_name!=name) + { + std::ostringstream oss; oss << "MEDFileMesh::dealWithTinyInfo : name of current MEDfile mesh is '" << _name << "' whereas name of input mesh is : '"; + oss << name << "' ! Names must match !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + } +} + MEDFileUMesh *MEDFileUMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) { MEDFileUtilities::CheckFileForRead(fileName); @@ -1364,6 +1389,7 @@ void MEDFileUMesh::setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m, bool void MEDFileUMesh::setMeshAtLevelGen(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception) { + dealWithTinyInfo(m); std::vector levSet=getNonEmptyLevels(); if(std::find(levSet.begin(),levSet.end(),meshDimRelToMax)==levSet.end()) { @@ -1773,8 +1799,9 @@ MEDCouplingMesh *MEDFileCMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum return const_cast(m); } -void MEDFileCMesh::setMesh(MEDCouplingCMesh *m) +void MEDFileCMesh::setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception) { + dealWithTinyInfo(m); if(m) m->incrRef(); _cmesh=m; @@ -1975,3 +2002,209 @@ const DataArrayInt *MEDFileCMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxEx throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no node renumbering for a request on reverse numbering !"); } } + + +MEDFileMeshMultiTS *MEDFileMeshMultiTS::New() +{ + return new MEDFileMeshMultiTS; +} + +MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileMeshMultiTS(fileName); +} + +MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileMeshMultiTS(fileName,mName); +} + +const char *MEDFileMeshMultiTS::getName() const throw(INTERP_KERNEL::Exception) +{ + if(_mesh_one_ts.empty()) + throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::getName : no time steps set !"); + return _mesh_one_ts[0]->getName(); +} + +MEDFileMesh *MEDFileMeshMultiTS::getOneTimeStep() const throw(INTERP_KERNEL::Exception) +{ + if(_mesh_one_ts.empty()) + throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::getOneTimeStep : empty time step set !"); + return const_cast(static_cast(_mesh_one_ts[0])); +} + +void MEDFileMeshMultiTS::setOneTimeStep(MEDFileMesh *mesh1TimeStep) throw(INTERP_KERNEL::Exception) +{ + if(!mesh1TimeStep) + throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::setOneTimeStep : input pointer should be different from 0 !"); + _mesh_one_ts.resize(1); + mesh1TimeStep->incrRef(); + //MEDCouplingAutoRefCountObjectPtr toto=mesh1TimeStep; + _mesh_one_ts[0]=mesh1TimeStep; +} + +void MEDFileMeshMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++) + { + (*it)->copyOptionsFrom(*this); + (*it)->write(fileName,mode); + } +} + +void MEDFileMeshMultiTS::loadFromFile(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception) +{//for the moment to be improved + _mesh_one_ts.resize(1); + _mesh_one_ts[0]=MEDFileMesh::New(fileName,mName,-1,-1); +} + +MEDFileMeshMultiTS::MEDFileMeshMultiTS() +{ +} + +MEDFileMeshMultiTS::MEDFileMeshMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception) +try + { + std::vector ms=MEDLoader::GetMeshNames(fileName); + if(ms.empty()) + { + std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + int dt,it; + ParaMEDMEM::MEDCouplingMeshType meshType; + std::string dummy2; + MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2); + loadFromFile(fileName,ms.front().c_str()); + } +catch(INTERP_KERNEL::Exception& e) + { + throw e; + } + +MEDFileMeshMultiTS::MEDFileMeshMultiTS(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception) +try + { + loadFromFile(fileName,mName); + } +catch(INTERP_KERNEL::Exception& e) + { + throw e; + } + +MEDFileMeshes *MEDFileMeshes::New() +{ + return new MEDFileMeshes; +} + +MEDFileMeshes *MEDFileMeshes::New(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + return new MEDFileMeshes(fileName); +} + +void MEDFileMeshes::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +{ + checkCoherency(); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_meshes.begin();it!=_meshes.end();it++) + { + (*it)->copyOptionsFrom(*this); + (*it)->write(fileName,mode); + } +} + +int MEDFileMeshes::getNumberOfMeshes() const throw(INTERP_KERNEL::Exception) +{ + return _meshes.size(); +} + +MEDFileMesh *MEDFileMeshes::getMeshAtPos(int i) const throw(INTERP_KERNEL::Exception) +{ + if(i<0 || i>=(int)_meshes.size()) + { + std::ostringstream oss; oss << "MEDFileMeshes::getMeshAtPos : invalid mesh id given in parameter ! Should be in [0;" << _meshes.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return _meshes[i]->getOneTimeStep(); +} + +void MEDFileMeshes::resize(int newSize) throw(INTERP_KERNEL::Exception) +{ + _meshes.resize(newSize); +} + +void MEDFileMeshes::pushMesh(MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception) +{ + if(!mesh) + throw INTERP_KERNEL::Exception("MEDFileMeshes::pushMesh : invalid input pointer ! should be different from 0 !"); + MEDFileMeshMultiTS *elt=MEDFileMeshMultiTS::New(); + elt->setOneTimeStep(mesh); + _meshes.push_back(elt); +} + +void MEDFileMeshes::setMeshAtPos(int i, MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception) +{ + if(!mesh) + throw INTERP_KERNEL::Exception("MEDFileMeshes::setMeshAtPos : invalid input pointer ! should be different from 0 !"); + if(i>=(int)_meshes.size()) + _meshes.resize(i+1); + MEDFileMeshMultiTS *elt=MEDFileMeshMultiTS::New(); + elt->setOneTimeStep(mesh); + _meshes[i]=elt; +} + +void MEDFileMeshes::destroyMeshAtPos(int i) throw(INTERP_KERNEL::Exception) +{ + if(i<0 || i>=(int)_meshes.size()) + { + std::ostringstream oss; oss << "MEDFileMeshes::destroyMeshAtPos : Invalid given id in input (" << i << ") should be in [0," << _meshes.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + _meshes.erase(_meshes.begin()+i); +} + +void MEDFileMeshes::loadFromFile(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + std::vector ms=MEDLoader::GetMeshNames(fileName); + int i=0; + _meshes.resize(ms.size()); + for(std::vector::const_iterator it=ms.begin();it!=ms.end();it++,i++) + _meshes[i]=MEDFileMeshMultiTS::New(fileName,(*it).c_str()); +} + +MEDFileMeshes::MEDFileMeshes() +{ +} + +MEDFileMeshes::MEDFileMeshes(const char *fileName) throw(INTERP_KERNEL::Exception) +try + { + loadFromFile(fileName); + } +catch(INTERP_KERNEL::Exception& e) + { + } + +void MEDFileMeshes::checkCoherency() const throw(INTERP_KERNEL::Exception) +{ + static const char MSG[]="MEDFileMeshes::checkCoherency : mesh at rank "; + int i=0; + std::set s; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++) + { + const MEDFileMeshMultiTS *elt=(*it); + if(!elt) + { + std::ostringstream oss; oss << MSG << i << "/" << _meshes.size() << " is empty !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + std::size_t sz=s.size(); + s.insert(std::string((*it)->getName())); + if(s.size()==sz) + { + std::ostringstream oss; oss << MSG << i << " has a name (\"" << (*it)->getName() << "\") already used by an another mesh in list !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } +} diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 257e68111..5429133cc 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -101,6 +101,7 @@ namespace ParaMEDMEM virtual DataArrayInt *getNodeFamiliesArr(const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); protected: MEDFileMesh(); + void dealWithTinyInfo(const MEDCouplingMesh *m) throw(INTERP_KERNEL::Exception); virtual void synchronizeTinyInfoOnLeaves() const = 0; virtual void appendFamilyEntries(const std::set& famIds, const std::vector< std::vector >& fidsOfGrps, const std::vector& grpNames); static void TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector >& famIdsPerGrp); @@ -190,7 +191,6 @@ namespace ParaMEDMEM mutable MEDCouplingAutoRefCountObjectPtr _rev_num_coords; }; - class MEDFileCMesh : public MEDFileMesh { friend class MEDFileMesh; @@ -203,7 +203,7 @@ namespace ParaMEDMEM void clearNonDiscrAttributes() const; const MEDCouplingCMesh *getMesh() const; MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const throw(INTERP_KERNEL::Exception); - void setMesh(MEDCouplingCMesh *m); + void setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception); void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); @@ -226,6 +226,47 @@ namespace ParaMEDMEM mutable MEDCouplingAutoRefCountObjectPtr _rev_num_nodes; mutable MEDCouplingAutoRefCountObjectPtr _rev_num_cells; }; + + class MEDFileMeshMultiTS : public RefCountObject, public MEDFileWritable + { + public: + static MEDFileMeshMultiTS *New(); + static MEDFileMeshMultiTS *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileMeshMultiTS *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + const char *getName() const throw(INTERP_KERNEL::Exception); + MEDFileMesh *getOneTimeStep() const throw(INTERP_KERNEL::Exception); + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + void setOneTimeStep(MEDFileMesh *mesh1TimeStep) throw(INTERP_KERNEL::Exception); + private: + void loadFromFile(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + MEDFileMeshMultiTS(); + MEDFileMeshMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception); + MEDFileMeshMultiTS(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + private: + std::vector< MEDCouplingAutoRefCountObjectPtr > _mesh_one_ts; + }; + + class MEDFileMeshes : public RefCountObject, public MEDFileWritable + { + public: + static MEDFileMeshes *New(); + static MEDFileMeshes *New(const char *fileName) throw(INTERP_KERNEL::Exception); + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception); + MEDFileMesh *getMeshAtPos(int i) const throw(INTERP_KERNEL::Exception); + // + void resize(int newSize) throw(INTERP_KERNEL::Exception); + void pushMesh(MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception); + void setMeshAtPos(int i, MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception); + void destroyMeshAtPos(int i) throw(INTERP_KERNEL::Exception); + private: + void checkCoherency() const throw(INTERP_KERNEL::Exception); + void loadFromFile(const char *fileName) throw(INTERP_KERNEL::Exception); + MEDFileMeshes(); + MEDFileMeshes(const char *fileName) throw(INTERP_KERNEL::Exception); + private: + std::vector< MEDCouplingAutoRefCountObjectPtr > _meshes; + }; } #endif diff --git a/src/MEDLoader/Makefile.am b/src/MEDLoader/Makefile.am index 8835f6c1e..3c1a8e523 100755 --- a/src/MEDLoader/Makefile.am +++ b/src/MEDLoader/Makefile.am @@ -37,12 +37,12 @@ lib_LTLIBRARIES = libmedloader.la salomeinclude_HEADERS= \ MEDLoaderDefines.hxx \ MEDLoader.hxx MEDLoaderBase.hxx MEDFileUtilities.hxx MEDFileMesh.hxx MEDFileMeshLL.hxx \ -MEDFileMeshElt.hxx MEDFileBasis.hxx MEDFileField.hxx +MEDFileMeshElt.hxx MEDFileBasis.hxx MEDFileField.hxx MEDFileData.hxx dist_libmedloader_la_SOURCES= \ MEDLoader.cxx MEDLoaderBase.cxx MEDFileUtilities.cxx \ MEDFileMesh.cxx MEDFileMeshElt.cxx MEDFileBasis.cxx \ -MEDFileMeshLL.cxx MEDFileField.cxx +MEDFileMeshLL.cxx MEDFileField.cxx MEDFileData.cxx libmedloader_la_CPPFLAGS= $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \ -I$(srcdir)/../INTERP_KERNEL \ diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 76897ec63..dc65a37c4 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -28,6 +28,7 @@ #include "MEDLoader.hxx" #include "MEDFileMesh.hxx" #include "MEDFileField.hxx" +#include "MEDFileData.hxx" #include "MEDLoaderTypemaps.i" using namespace ParaMEDMEM; @@ -72,8 +73,14 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDFileUMesh::getLevelM2Mesh; %newobject ParaMEDMEM::MEDFileUMesh::getLevelM3Mesh; %newobject ParaMEDMEM::MEDFileCMesh::New; +%newobject ParaMEDMEM::MEDFileMeshMultiTS::New; +%newobject ParaMEDMEM::MEDFileMeshMultiTS::getOneTimeStep; +%newobject ParaMEDMEM::MEDFileMeshes::New; +%newobject ParaMEDMEM::MEDFileMeshes::getMeshAtPos; %newobject ParaMEDMEM::MEDFileFields::New; +%newobject ParaMEDMEM::MEDFileFields::getField; +%newobject ParaMEDMEM::MEDFileFields::getFieldAtPos; %newobject ParaMEDMEM::MEDFileFieldMultiTS::New; %newobject ParaMEDMEM::MEDFileFieldMultiTS::getFieldAtLevel; %newobject ParaMEDMEM::MEDFileFieldMultiTS::getFieldOnMeshAtLevel; @@ -83,6 +90,17 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDFileField1TS::getFieldOnMeshAtLevel; %newobject ParaMEDMEM::MEDFileField1TS::getFieldAtLevelOld; +%newobject ParaMEDMEM::MEDFileData::New; + +%feature("unref") MEDFileMesh "$this->decrRef();" +%feature("unref") MEDFileUMesh "$this->decrRef();" +%feature("unref") MEDFileCMesh "$this->decrRef();" +%feature("unref") MEDFileMeshMultiTS "$this->decrRef();" +%feature("unref") MEDFileMeshes "$this->decrRef();" +%feature("unref") MEDFileField1TS "$this->decrRef();" +%feature("unref") MEDFileFieldMultiTS "$this->decrRef();" +%feature("unref") MEDFileFields "$this->decrRef();" + class MEDLoader { public: @@ -437,7 +455,7 @@ namespace ParaMEDMEM static MEDFileCMesh *New(); static MEDFileCMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); static MEDFileCMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception); - void setMesh(MEDCouplingCMesh *m); + void setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception); %extend { PyObject *getMesh() const @@ -450,9 +468,55 @@ namespace ParaMEDMEM } }; - class MEDFieldFieldGlobs + class MEDFileMeshMultiTS : public RefCountObject, public MEDFileWritable + { + public: + static MEDFileMeshMultiTS *New(); + static MEDFileMeshMultiTS *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileMeshMultiTS *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + const char *getName() const throw(INTERP_KERNEL::Exception); + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + void setOneTimeStep(MEDFileMesh *mesh1TimeStep) throw(INTERP_KERNEL::Exception); + %extend + { + MEDFileMesh *getOneTimeStep() const throw(INTERP_KERNEL::Exception) + { + MEDFileMesh *ret=self->getOneTimeStep(); + if(ret) + ret->incrRef(); + return ret; + } + } + }; + + class MEDFileMeshes : public RefCountObject, public MEDFileWritable { public: + static MEDFileMeshes *New(); + static MEDFileMeshes *New(const char *fileName) throw(INTERP_KERNEL::Exception); + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception); + // + void resize(int newSize) throw(INTERP_KERNEL::Exception); + void pushMesh(MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception); + void setMeshAtPos(int i, MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception); + void destroyMeshAtPos(int i) throw(INTERP_KERNEL::Exception); + %extend + { + MEDFileMesh *getMeshAtPos(int i) const throw(INTERP_KERNEL::Exception) + { + MEDFileMesh *ret=self->getMeshAtPos(i); + if(ret) + ret->incrRef(); + return ret; + } + } + }; + + class MEDFieldFieldGlobsReal + { + public: + void shallowCpyGlobs(const MEDFieldFieldGlobsReal& other); std::vector getPfls() const; std::vector getLocs() const; virtual std::vector getPflsReallyUsed() const = 0; @@ -485,7 +549,7 @@ namespace ParaMEDMEM } }; - class MEDFileField1TS : public MEDFileField1TSWithoutDAS, public MEDFieldFieldGlobs, public MEDFileWritable + class MEDFileField1TS : public MEDFileField1TSWithoutDAS, public MEDFieldFieldGlobsReal, public MEDFileWritable { public: static MEDFileField1TS *New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); @@ -497,12 +561,26 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, const char *mname, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); // void setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception); + void setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); + %extend + { + PyObject *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *ret1=0; + DataArrayDouble *ret0=self->getFieldWithProfile(type,meshDimRelToMax,mesh,ret1); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + } }; class MEDFileFieldMultiTSWithoutDAS { public: int getNumberOfTS() const; + std::string getName() const; %extend { PyObject *getIterations() const @@ -519,26 +597,82 @@ namespace ParaMEDMEM } return ret; } + + PyObject *getTimeSteps() const throw(INTERP_KERNEL::Exception) + { + std::vector ret1; + std::vector< std::pair > ret=self->getTimeSteps(ret1); + std::size_t sz=ret.size(); + PyObject *ret2=PyList_New(sz); + for(std::size_t i=0;igetFieldWithProfile(type,iteration,order,meshDimRelToMax,mesh,ret1); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + } }; - class MEDFileFields : public RefCountObject, public MEDFieldFieldGlobs, public MEDFileWritable + class MEDFileFields : public RefCountObject, public MEDFieldFieldGlobsReal, public MEDFileWritable { public: + static MEDFileFields *New(); static MEDFileFields *New(const char *fileName) throw(INTERP_KERNEL::Exception); + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); int getNumberOfFields() const; - std::vector getPfls() const; - std::vector getLocs() const; + std::vector getFieldsNames() const throw(INTERP_KERNEL::Exception); + // + void resize(int newSize) throw(INTERP_KERNEL::Exception); + void pushField(MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception); + void setFieldAtPos(int i, MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception); + MEDFileFieldMultiTS *getFieldAtPos(int i) const throw(INTERP_KERNEL::Exception); + MEDFileFieldMultiTS *getField(const char *fieldName) const throw(INTERP_KERNEL::Exception); + void destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception); + }; + + class MEDFileData : public RefCountObject, public MEDFileWritable + { + public: + static MEDFileData *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileData *New(); + MEDFileFields *getFields() const; + MEDFileMeshes *getMeshes() const; + void setFields(MEDFileFields *fields) throw(INTERP_KERNEL::Exception); + void setMeshes(MEDFileMeshes *meshes) throw(INTERP_KERNEL::Exception); + int getNumberOfFields() const throw(INTERP_KERNEL::Exception); + int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception); + // + void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); }; } diff --git a/src/MEDLoader/Swig/MEDLoaderDataForTest.py b/src/MEDLoader/Swig/MEDLoaderDataForTest.py index bcf2fed60..3436e073b 100644 --- a/src/MEDLoader/Swig/MEDLoaderDataForTest.py +++ b/src/MEDLoader/Swig/MEDLoaderDataForTest.py @@ -440,6 +440,56 @@ class MEDLoaderDataForTest: f.checkCoherency(); return f; + # idem buildVecFieldOnGauss_2 except that different discretizations are sorted inside one type + def buildVecFieldOnGauss_2_Simpler(cls): + _a=0.446948490915965; + _b=0.091576213509771; + _p1=0.11169079483905; + _p2=0.0549758718227661; + refCoo1=[ 0.,0., 1.,0., 0.,1. ] + gsCoo1=[ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b, + 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 ]; + wg1=[ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 ] + _refCoo1=refCoo1; + _gsCoo1=gsCoo1; + _wg1=wg1; + m=MEDLoaderDataForTest.build2DMesh_3(); + f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME); + f.setTime(3.14,1,5); + f.setMesh(m); + di=DataArrayInt.New(); di.setValues([0,1,2],3,1) + f.setGaussLocalizationOnCells(di,_refCoo1,_gsCoo1,_wg1) + _wg1[-1]*=2 + f.setGaussLocalizationOnCells([3,4],_refCoo1,_gsCoo1,_wg1); + _wg1[-1]*=2 + f.setGaussLocalizationOnCells([5],_refCoo1,_gsCoo1,_wg1); + refCoo2=[-1.0,1.0, -1.0,-1.0, 1.0,-1.0, -1.0,0.0, 0.0,-1.0, 0.0,0.0 ] + _refCoo2=refCoo2; + _gsCoo1=_gsCoo1[0:6]; + _gsCoo2=_gsCoo1 + _wg1=_wg1[0:3]; + _wg2=_wg1 + refCoo3=[ 0.,0., 1.,0., 1.,1., 0.,1. ] + _refCoo3=refCoo3; + _gsCoo1=_gsCoo1[0:4]; + _wg1=_wg1[0:2]; + f.setGaussLocalizationOnCells([6,7,8],_refCoo3,_gsCoo1,_wg1); + _wg1[-1]*=2 + f.setGaussLocalizationOnCells([9],_refCoo3,_gsCoo1,_wg1); + f.setGaussLocalizationOnType(NORM_TRI6,_refCoo2,_gsCoo2,_wg2); + array=DataArrayDouble.New(); + array.alloc(53,2); + ptr=array.getPointer(); + for i in xrange(53*2): + array.setIJ(0,i,float(i+7)); + pass + f.setArray(array); + f.setName("MyFirstFieldOnGaussPoint"); + array.setInfoOnComponent(0,"power [MW/m^3]"); + array.setInfoOnComponent(1,"density"); + f.checkCoherency(); + return f; + def buildVecFieldOnGaussNE_1(cls): m=MEDLoaderDataForTest.build2DMesh_2(); f=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME); @@ -469,5 +519,6 @@ class MEDLoaderDataForTest: buildVecFieldOnNodes_1=classmethod(buildVecFieldOnNodes_1) buildVecFieldOnGauss_1=classmethod(buildVecFieldOnGauss_1) buildVecFieldOnGauss_2=classmethod(buildVecFieldOnGauss_2) + buildVecFieldOnGauss_2_Simpler=classmethod(buildVecFieldOnGauss_2_Simpler) buildVecFieldOnGaussNE_1=classmethod(buildVecFieldOnGaussNE_1) pass diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 3c8ba6aaa..30b73be2e 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -475,7 +475,7 @@ class MEDLoaderTest(unittest.TestCase): self.assertTrue(f1.isEqual(f2,1e-12,1e-12)) # fname="Pyfile28.med" - f1=MEDLoaderDataForTest.buildVecFieldOnGauss_2(); + f1=MEDLoaderDataForTest.buildVecFieldOnGauss_2_Simpler(); m1=f1.getMesh() mm1=MEDFileUMesh.New() mm1.setCoords(m1.getCoords()) @@ -486,8 +486,233 @@ class MEDLoaderTest(unittest.TestCase): ff1.setFieldNoProfileSBT(f1) ff1.write(fname,0) ff2=MEDFileField1TS.New(fname,f1.getName(),f1.getTime()[1],f1.getTime()[2]) - #f2=ff2.getFieldAtLevel(ON_GAUSS_PT,0) BUG TONY - #self.assertTrue(f1.isEqual(f2,1e-12,1e-12)) + f2=ff2.getFieldAtLevel(ON_GAUSS_PT,0) + self.assertTrue(f1.isEqual(f2,1e-12,1e-12)) + # + pass + + def testMEDFileData1(self): + fname="Pyfile29.med" + d=MEDFileData.New() + # + m1=MEDLoaderDataForTest.build1DMesh_1() + mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName()) + mmm1=MEDFileMeshMultiTS.New() ; + mmm1.setOneTimeStep(mm1) + m2=MEDLoaderDataForTest.build2DCurveMesh_1() + mm2=MEDFileUMesh.New() ; mm2.setCoords(m2.getCoords()) ; mm2.setMeshAtLevel(0,m2) ; mm2.setName(m2.getName()) + mmm2=MEDFileMeshMultiTS.New() ; mmm2.setOneTimeStep(mm2) + ms=MEDFileMeshes.New(); ms.setMeshAtPos(0,mm1) ; ms.setMeshAtPos(1,mm2) + d.setMeshes(ms) + # + ff1=MEDFileFieldMultiTS.New() + ff21=MEDFileFieldMultiTS.New() + ff22=MEDFileFieldMultiTS.New() + f1=m1.getMeasureField(True) ; f1.setName("f1") ; f1=f1.buildNewTimeReprFromThis(ONE_TIME,False) + f1.getArray().setInfoOnComponent(0,"power [kW]") + ff1.appendFieldNoProfileSBT(f1) + f21=m2.getMeasureField(True) ; f21.setName("f21") ; f21=f21.buildNewTimeReprFromThis(ONE_TIME,False) + f21.getArray().setInfoOnComponent(0,"sta [mm]") ; + ff21.appendFieldNoProfileSBT(f21) + f22=f21.deepCpy() ; f22.setName("f22") ; f22=f22.buildNewTimeReprFromThis(ONE_TIME,False) ; + f22.applyFunc(2,"3*x*IVec+2*x*JVec") + f22.getArray().setInfoOnComponent(0,"distance [km]") ; f22.getArray().setInfoOnComponent(1,"displacement [cm]") + ff22.appendFieldNoProfileSBT(f22) + fs=MEDFileFields.New() + fs.pushField(ff1) ; fs.pushField(ff21) ; fs.pushField(ff22) + d.setFields(fs) + # + d.write(fname,0) + # + d2=MEDFileData.New(fname) + self.assertEqual(2,d2.getNumberOfMeshes()) + self.assertEqual(3,d2.getNumberOfFields()) + self.assertTrue(isinstance(d2.getMeshes().getMeshAtPos(0),MEDFileUMesh)) + m1bis=d2.getMeshes().getMeshAtPos(0).getMeshAtLevel(0) + self.assertTrue(m1.isEqual(m1bis,1e-12)) + self.assertEqual(('f1', 'f21', 'f22'),d2.getFields().getFieldsNames()) + self.assertEqual([(-1, -1, 0.0)],d2.getFields().getFieldAtPos(2).getTimeSteps()) + self.assertEqual([(-1, -1, 0.0)],d2.getFields().getField("f21").getTimeSteps()) + pass + + def testMEDField9(self): + # first test field profile WR. Full type but with some type missing + fname="Pyfile30.med" + m1=MEDLoaderDataForTest.build2DMesh_3() + mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; + mm1.write(fname,2) + ff1=MEDFileField1TS.New() + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F1") + d=DataArrayDouble.New() ; d.alloc(2*9,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]") + f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that. + da=DataArrayInt.New(); da.alloc(9,1) ; da.iota(0) ; da.setName("sup1") + # + ff1.setFieldProfile(f1,mm1,0,da) + ff1.write(fname,0) + # + vals,pfl=ff1.getFieldWithProfile(ON_CELLS,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da))# profiles names cannot be contracted in pfl array name + self.assertTrue(vals.isEqual(d,1e-14)) + # + ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1) + vals,pfl=ff2.getFieldWithProfile(ON_CELLS,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(d,1e-14)) + pass + + def testMEDField10(self): + fname="Pyfile31.med" + m1=MEDLoaderDataForTest.build2DMesh_1() + m1.renumberCells([0,1,4,2,3,5],False) + mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName()) + mm1.write(fname,2) + ff1=MEDFileFieldMultiTS.New() + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2") + d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]") + f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that. + da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2") + # + ff1.appendFieldProfile(f1,mm1,0,da) + f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ; + ff1.appendFieldProfile(f1,mm1,0,da) + ff1.write(fname,0) + # + vals,pfl=ff1.getFieldWithProfile(ON_CELLS,1,2,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(e,1e-14)) + vals,pfl=ff1.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(d,1e-14)) + # + ff2=MEDFileFieldMultiTS.New(fname,f1.getName()) + self.assertEqual([(-1, -1, 0.0), (1, 2, 1.2)],ff2.getTimeSteps()) + vals,pfl=ff2.getFieldWithProfile(ON_CELLS,1,2,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(e,1e-14)) + vals,pfl=ff2.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(d,1e-14)) + pass + + # idem testMEDField9 method except that here testing profile on nodes and not on cells. + def testMEDField11(self): + fname="Pyfile32.med" + m1=MEDLoaderDataForTest.build2DMesh_1() + m1.renumberCells([0,1,4,2,3,5],False) + mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; + mm1.write(fname,2) + ff1=MEDFileField1TS.New() + f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node") + d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]") + f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that. + da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node") + # + ff1.setFieldProfile(f1,mm1,0,da) + ff1.write(fname,0) + # + vals,pfl=ff1.getFieldWithProfile(ON_NODES,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(d,1e-14)) + ## # + ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1) + vals,pfl=ff2.getFieldWithProfile(ON_NODES,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(d,1e-14)) + pass + + def testMEDField12(self): + fname="Pyfile33.med" + m1=MEDLoaderDataForTest.build2DMesh_1() + m1.renumberCells([0,1,4,2,3,5],False) + mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; + mm1.write(fname,2) + ff1=MEDFileFieldMultiTS.New() + f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node") + d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]") + f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that. + da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node") + # + ff1.appendFieldProfile(f1,mm1,0,da) + f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ; + ff1.appendFieldProfile(f1,mm1,0,da) + ff1.write(fname,0) + # + vals,pfl=ff1.getFieldWithProfile(ON_NODES,1,2,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(e,1e-14)) + vals,pfl=ff1.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(d,1e-14)) + # + ff2=MEDFileFieldMultiTS.New(fname,f1.getName()) + vals,pfl=ff2.getFieldWithProfile(ON_NODES,1,2,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(e,1e-14)) + vals,pfl=ff2.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(d,1e-14)) + pass + + def testMEDField13(self): + fname="Pyfile34.med" + m1=MEDLoaderDataForTest.build2DMesh_1() + m1.renumberCells([0,1,4,2,3,5],False) + tmp=m1.getName(); + m1=m1.buildPartOfMySelf(range(5),True) ; m1.setName(tmp) # suppression of last cell that is a polygon + mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; + mm1.write(fname,2) + ff1=MEDFileField1TS.New() + f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F3Node") + d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]") + f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that. + da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt") + # + ff1.setFieldProfile(f1,mm1,0,da) + ff1.write(fname,0) + # + vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(d,1e-14)) + # + ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1) + vals,pfl=ff2.getFieldWithProfile(ON_GAUSS_NE,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(d,1e-14)) + pass + + def testMEDField14(self): + fname="Pyfile35.med" + m1=MEDLoaderDataForTest.build2DMesh_1() + m1.renumberCells([0,1,4,2,3,5],False) + tmp=m1.getName(); + m1=m1.buildPartOfMySelf(range(5),True) ; m1.setName(tmp) # suppression of last cell that is a polygon + mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; + mm1.write(fname,2) + ff1=MEDFileFieldMultiTS.New() + f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F4Node") + d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]") + f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that. + da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt") + # + ff1.appendFieldProfile(f1,mm1,0,da) + f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ; + ff1.appendFieldProfile(f1,mm1,0,da) + ff1.write(fname,0) + # + vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(d,1e-14)) + vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(e,1e-14)) + # + ff2=MEDFileFieldMultiTS.New(fname,f1.getName()) + vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(d,1e-14)) + vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) + self.assertTrue(pfl.isEqualWithoutConsideringStr(da)) + self.assertTrue(vals.isEqual(e,1e-14)) pass pass diff --git a/src/ParaMEDMEM/OverlapElementLocator.hxx b/src/ParaMEDMEM/OverlapElementLocator.hxx index a3358b8af..7e3e888d6 100644 --- a/src/ParaMEDMEM/OverlapElementLocator.hxx +++ b/src/ParaMEDMEM/OverlapElementLocator.hxx @@ -28,6 +28,7 @@ #include #include +#include #include #include diff --git a/src/ParaMEDMEMTest/MPI2Connector.cxx b/src/ParaMEDMEMTest/MPI2Connector.cxx index 226e30690..01ec77979 100644 --- a/src/ParaMEDMEMTest/MPI2Connector.cxx +++ b/src/ParaMEDMEMTest/MPI2Connector.cxx @@ -20,7 +20,7 @@ #include "MPI2Connector.hxx" #include -#include +#include MPI2Connector::MPI2Connector() {