From: ageay Date: Thu, 30 Jun 2011 13:33:21 +0000 (+0000) Subject: Dealing with profiles on nodes. X-Git-Tag: V6_3_1rc1~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=53917c9e447d10f4a15299b1c8fe1b61d524ef9e;p=tools%2Fmedcoupling.git Dealing with profiles on nodes. --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 9f2ab9a9d..a9d36304e 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -173,6 +173,12 @@ void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(const char *pflName, const DataArrayDouble *da=field->getArray(); switch(_type) { + case ON_NODES: + { + _nval=globIds->getNumberOfTuples(); + _arr=da->deepCpy(); + break; + } case ON_CELLS: { _nval=globIds->getNumberOfTuples(); @@ -386,7 +392,7 @@ void MEDFileFieldPerMeshPerType::assignFieldProfile(const DataArrayInt *globIds, 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 << locIds->getName() << "_" << cm.getRepr(); + std::ostringstream oss; oss << pflName << "_" << cm.getRepr(); locIds->setName(oss.str().c_str()); glob.appendProfile(locIds); // @@ -407,6 +413,21 @@ void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(const MEDCouplingField _field_pm_pt_pd[0]->assignNodeFieldNoProfile(field,glob); } +void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& 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(),pfl2,field,glob); +} + std::vector MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception) { TypeOfField type=field->getTypeOfField(); @@ -757,6 +778,12 @@ void MEDFileFieldPerMesh::assignNodeFieldNoProfile(const MEDCouplingFieldDouble _field_pm_pt[pos]->assignNodeFieldNoProfile(field,glob); } +void MEDFileFieldPerMesh::assignNodeFieldProfile(const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& 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); @@ -949,7 +976,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 MEDFieldFieldGlobs *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 !"); @@ -960,7 +987,7 @@ 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); if(code.empty()) @@ -1002,6 +1029,52 @@ MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField t } } +DataArrayDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFieldFieldGlobs *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,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; @@ -1116,6 +1189,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) { @@ -1510,12 +1610,12 @@ void MEDFileField1TSWithoutDAS::setFieldProfile(const MEDCouplingFieldDouble *fi { TypeOfField type=field->getTypeOfField(); copyTinyInfoFrom(field); + std::vector globIdsPerType; + std::vector idsPerType; + std::vector code; + MEDCouplingAutoRefCountObjectPtr m=mesh->getGenMeshAtLevel(meshDimRelToMax); if(type!=ON_NODES) { - std::vector code; - std::vector globIdsPerType; - std::vector idsPerType; - MEDCouplingAutoRefCountObjectPtr m=mesh->getGenMeshAtLevel(meshDimRelToMax); m->splitProfilePerType(profile,code,globIdsPerType,idsPerType); // std::vector< MEDCouplingAutoRefCountObjectPtr > globIdsPerType2(globIdsPerType.size()); @@ -1529,7 +1629,10 @@ void MEDFileField1TSWithoutDAS::setFieldProfile(const MEDCouplingFieldDouble *fi _field_per_mesh[pos]->assignFieldProfile(code,globIdsPerType,idsPerType,field,glob); } else - throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutDAS::setFieldProfile : not implemented yet !"); + { + 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 MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception) @@ -1554,10 +1657,9 @@ MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(TypeOfF MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFieldFieldGlobs *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: @@ -1612,6 +1714,13 @@ MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(TypeOfF } } +DataArrayDouble *MEDFileField1TSWithoutDAS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFieldFieldGlobs *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) { @@ -1820,6 +1929,11 @@ MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, co 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. @@ -2092,6 +2206,12 @@ 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()) diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 0b7260910..d129bfbd4 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -83,6 +83,7 @@ namespace ParaMEDMEM void assignFieldNoProfile(int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); void assignFieldProfile(const char *pflName, const DataArrayInt *globIds, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); + void assignNodeFieldProfile(const char *pflName, const DataArrayInt *globIds, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); const MEDFileFieldPerMeshPerType *getFather() const; int getIteration() const; @@ -125,6 +126,7 @@ namespace ParaMEDMEM void assignFieldNoProfile(int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobs& glob) throw(INTERP_KERNEL::Exception); void assignFieldProfile(const DataArrayInt *globIds, DataArrayInt *locIds, 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); 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); @@ -163,6 +165,7 @@ namespace ParaMEDMEM void assignFieldProfileGeneral(const std::vector& code, const std::vector& globIdsPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, 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 finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception); void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); void getDimension(int& dim) const; @@ -178,7 +181,8 @@ 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 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); private: int addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type); MEDCouplingFieldDouble *finishField(TypeOfField type, const MEDFieldFieldGlobs *glob, @@ -189,6 +193,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *finishField3(const MEDFieldFieldGlobs *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, const std::vector& geoTypes, const std::vector& dads, const std::vector& pfls, const std::vector& locs, std::vector& code, std::vector& notNullPfls); @@ -265,6 +270,7 @@ namespace ParaMEDMEM 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); protected: int addNewEntryIfNecessary(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception); int getMeshIdFromMeshName(const char *mName) const throw(INTERP_KERNEL::Exception); @@ -296,6 +302,7 @@ namespace ParaMEDMEM 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); @@ -347,6 +354,7 @@ namespace ParaMEDMEM 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); diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 8be720510..835757f40 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -559,6 +559,18 @@ namespace ParaMEDMEM // 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 @@ -597,6 +609,18 @@ namespace ParaMEDMEM // 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); + %extend + { + PyObject *getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *ret1=0; + DataArrayDouble *ret0=self->getFieldWithProfile(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 diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index d35dbf2ac..e4712ce18 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -490,6 +490,7 @@ class MEDLoaderTest(unittest.TestCase): self.assertTrue(f1.isEqual(f2,1e-12,1e-12)) # pass + def testMEDFileData1(self): fname="Pyfile29.med" d=MEDFileData.New() @@ -526,9 +527,11 @@ class MEDLoaderTest(unittest.TestCase): 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)) - pass + pass + def testMEDField9(self): # first test field profile WR. Full type but with some type missing fname="Pyfile30.med" @@ -537,13 +540,23 @@ class MEDLoaderTest(unittest.TestCase): mm1.write(fname,2) ff1=MEDFileField1TS.New() f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F1") - d=DataArrayDouble.New() ; d.alloc(2*10,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]") + 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() @@ -560,6 +573,47 @@ class MEDLoaderTest(unittest.TestCase): 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()) + 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 pass