From 30bd42409b18267e08dae550148a3a8fce3aa172 Mon Sep 17 00:00:00 2001 From: ageay Date: Mon, 4 Jul 2011 07:39:34 +0000 Subject: [PATCH] *** empty log message *** --- src/MEDLoader/MEDFileField.cxx | 279 +++++++++++++++++++++++---- src/MEDLoader/MEDFileField.hxx | 120 ++++++++---- src/MEDLoader/Swig/MEDLoader.i | 32 ++- src/MEDLoader/Swig/MEDLoaderTest3.py | 4 + 4 files changed, 354 insertions(+), 81 deletions(-) diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index d36bf0f4a..17b6fe7d6 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(); @@ -169,7 +169,7 @@ void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int offset, int nbO * @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, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +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; @@ -212,7 +212,7 @@ void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(const char *pflName, } } -void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { _arr=field->getArray()->deepCpy(); _nval=field->getArray()->getNumberOfTuples(); @@ -333,7 +333,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 ; @@ -384,14 +384,14 @@ 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::assignFieldProfile(const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, 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) @@ -415,14 +415,14 @@ void MEDFileFieldPerMeshPerType::assignFieldProfile(const DataArrayInt *multiTyp } } -void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +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, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { std::string pflName(pfl->getName()); if(pflName.empty()) @@ -654,7 +654,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) { @@ -732,7 +732,7 @@ void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh) throw(IN mesh->getTime(_mesh_iteration,_mesh_order); } -void MEDFileFieldPerMesh::assignFieldProfile(const DataArrayInt *multiTypePfl, const std::vector& code, const std::vector& idsInPflPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, 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; @@ -750,7 +750,7 @@ void MEDFileFieldPerMesh::assignFieldProfile(const DataArrayInt *multiTypePfl, c assignFieldProfileGeneral(multiTypePfl,code,idsInPflPerType,idsPerType,field,mesh,glob); } -void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(const std::vector& code, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(const std::vector& code, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { int nbOfTypes=code.size()/3; int offset=0; @@ -767,7 +767,7 @@ void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(const std::vector& co /*! * 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, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +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;iassignNodeFieldNoProfile(field,glob); } -void MEDFileFieldPerMesh::assignNodeFieldProfile(const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +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); @@ -887,7 +887,7 @@ const std::vector& MEDFileFieldPerMesh::getInfo() const * - '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, TypeOfField type, 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(); @@ -934,7 +934,7 @@ void MEDFileFieldPerMesh::SortArraysPerType(const MEDFieldFieldGlobs *glob, Type /*! * 'dads' and 'locs' are input parameters that should have same size sz. sz should be >=1. */ -int MEDFileFieldPerMesh::ComputeNbOfElems(const MEDFieldFieldGlobs *glob, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, 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; @@ -993,7 +993,7 @@ std::vector MEDFileFieldPerMesh::getLocsReallyUsed() const return ret; } -MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, 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 !"); @@ -1046,7 +1046,7 @@ MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField t } } -DataArrayDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception) +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 !"); @@ -1114,7 +1114,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) { @@ -1153,7 +1153,7 @@ 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) { @@ -1175,7 +1175,7 @@ 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) { @@ -1245,6 +1245,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); @@ -1259,6 +1261,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()); @@ -1282,21 +1286,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;iloadProfileInFile(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. @@ -1599,7 +1705,7 @@ void MEDFileField1TSWithoutDAS::writeLL(med_idt fid) const throw(INTERP_KERNEL:: * 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, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +void MEDFileField1TSWithoutDAS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { const MEDCouplingMesh *mesh=field->getMesh(); // @@ -1623,7 +1729,7 @@ void MEDFileField1TSWithoutDAS::setFieldNoProfileSBT(const MEDCouplingFieldDoubl /*! * Generalization of MEDFileField1TSWithoutDAS::setFieldNoProfileSBT method. */ -void MEDFileField1TSWithoutDAS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception) +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); @@ -1652,7 +1758,7 @@ void MEDFileField1TSWithoutDAS::setFieldProfile(const MEDCouplingFieldDouble *fi } } -MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const char *mName, int renumPol, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception) +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) @@ -1662,7 +1768,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); @@ -1671,7 +1777,7 @@ 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 meshId=getMeshIdFromMeshName(mesh->getName()); @@ -1731,7 +1837,7 @@ MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(TypeOfF } } -DataArrayDouble *MEDFileField1TSWithoutDAS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception) +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()); @@ -1817,7 +1923,7 @@ void MEDFileField1TS::write(const char *fileName, int mode) const throw(INTERP_K } 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); @@ -1908,7 +2014,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); } @@ -1941,7 +2047,7 @@ 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); } @@ -1958,7 +2064,7 @@ DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int mesh */ void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception) { - _file_name=""; + setFileName(""); MEDFileField1TSWithoutDAS::setFieldNoProfileSBT(field,*this); } @@ -1972,7 +2078,7 @@ void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) */ void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception) { - _file_name=""; + setFileName(""); MEDFileField1TSWithoutDAS::setFieldProfile(field,mesh,meshDimRelToMax,profile,*this); } @@ -2020,6 +2126,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); @@ -2179,6 +2313,11 @@ MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, const char * 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); @@ -2270,7 +2409,7 @@ 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); @@ -2315,6 +2454,10 @@ catch(INTERP_KERNEL::Exception& e) throw e; } +MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutDAS& other):MEDFileFieldMultiTSWithoutDAS(other) +{ +} + std::vector MEDFileFieldMultiTS::getPflsReallyUsed() const { return getPflsReallyUsed2(); @@ -2340,12 +2483,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); @@ -2369,7 +2532,6 @@ try:MEDFieldFieldGlobs(fileName) _fields[i]=MEDFileFieldMultiTSWithoutDAS::New(fid,nomcha,i+1,infos,nbOfStep); } int nProfil=MEDnProfile(fid); - _pfls.resize(nProfil); for(int 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 fd83b6343..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,10 +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 assignFieldProfile(const char *pflName, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); - void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); - void assignNodeFieldProfile(const char *pflName, const DataArrayInt *idsInPfl, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, 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; @@ -100,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: @@ -123,10 +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 assignFieldProfile(const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); - void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); - void assignNodeFieldProfile(const DataArrayInt *pfl, 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); @@ -141,7 +142,7 @@ 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); @@ -161,11 +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 assignFieldProfile(const DataArrayInt *multiTypePfl, const std::vector& code, const std::vector& idsInPflPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFieldFieldGlobs& 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, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); - void assignFieldNoProfileNoRenum(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 assignNodeFieldProfile(const DataArrayInt *pfl, 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; @@ -181,23 +182,23 @@ namespace ParaMEDMEM const std::vector& getInfo() const; std::vector getPflsReallyUsed() const; std::vector getLocsReallyUsed() const; - MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception); - DataArrayDouble *getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFieldFieldGlobs *glob) 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); DataArrayDouble *finishField4(const std::vector& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const throw(INTERP_KERNEL::Exception); - static void SortArraysPerType(const MEDFieldFieldGlobs *glob, TypeOfField type, + 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, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, 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: @@ -209,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; @@ -224,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: @@ -264,13 +299,13 @@ namespace ParaMEDMEM 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, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); - void setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFieldFieldGlobs& glob) 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); - DataArrayDouble *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFieldFieldGlobs *glob) 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); @@ -291,13 +326,12 @@ 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); @@ -320,6 +354,8 @@ namespace ParaMEDMEM 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; @@ -344,11 +380,12 @@ 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); @@ -363,25 +400,30 @@ namespace ParaMEDMEM 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: diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 835757f40..dc65a37c4 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -79,6 +79,8 @@ using namespace ParaMEDMEM; %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; @@ -511,9 +513,10 @@ namespace ParaMEDMEM } }; - class MEDFieldFieldGlobs + class MEDFieldFieldGlobsReal { public: + void shallowCpyGlobs(const MEDFieldFieldGlobsReal& other); std::vector getPfls() const; std::vector getLocs() const; virtual std::vector getPflsReallyUsed() const = 0; @@ -546,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); @@ -577,6 +580,7 @@ namespace ParaMEDMEM { public: int getNumberOfTS() const; + std::string getName() const; %extend { PyObject *getIterations() const @@ -593,10 +597,27 @@ 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;i 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); }; diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index fe2520514..30b73be2e 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -530,6 +530,9 @@ class MEDLoaderTest(unittest.TestCase): 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): @@ -582,6 +585,7 @@ class MEDLoaderTest(unittest.TestCase): 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)) -- 2.39.2