X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPlugins%2FMEDReader%2FIO%2FMEDFileFieldRepresentationTree.cxx;h=540464cea1af7563cc70845f33df3cae59767bfb;hb=f671e69102c5ae8e2194509a6b719fae0b06d26c;hp=02838b6cc69d106270ee955e51587d3086b5dd91;hpb=e32938b374fc9583c1dc3a69a3b3ec23e7c49b3e;p=modules%2Fparavis.git diff --git a/src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.cxx b/src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.cxx index 02838b6c..540464ce 100644 --- a/src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.cxx +++ b/src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2010-2014 CEA/DEN, EDF R&D +// Copyright (C) 2010-2016 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 @@ -28,6 +28,10 @@ #include "MEDFileData.hxx" #include "SauvReader.hxx" +#ifdef MEDREADER_USE_MPI + #include "ParaMEDFileMesh.hxx" +#endif + #include "vtkXMLUnstructuredGridWriter.h"// #include "vtkUnstructuredGrid.h" @@ -38,6 +42,7 @@ #include "vtkInformationQuadratureSchemeDefinitionVectorKey.h" #include "vtkInformationIntegerKey.h" #include "vtkInformation.h" +#include "vtkDataArrayTemplate.h" #include "vtkIdTypeArray.h" #include "vtkDoubleArray.h" #include "vtkIntArray.h" @@ -46,12 +51,9 @@ #include "vtkFieldData.h" #include "vtkCellData.h" -#include "vtksys/stl/string" -#include "vtksys/ios/fstream" -#include "vtksys/stl/algorithm" #include "vtkMutableDirectedGraph.h" -using namespace ParaMEDMEM; +using namespace MEDCoupling; const char MEDFileFieldRepresentationLeavesArrays::ZE_SEP[]="@@][@@"; @@ -67,13 +69,15 @@ const char MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME[]="Family const char MEDFileFieldRepresentationLeavesArrays::NUM_ID_NODE_NAME[]="NumIdNode"; +const char MEDFileFieldRepresentationLeavesArrays::GLOBAL_NODE_ID_NAME[]="GlobalNodeIds";// WARNING DO NOT CHANGE IT BEFORE HAVING CHECKED IN PV SOURCES ! + const char MEDFileFieldRepresentationTree::ROOT_OF_GRPS_IN_TREE[]="zeGrps"; const char MEDFileFieldRepresentationTree::ROOT_OF_FAM_IDS_IN_TREE[]="zeFamIds"; const char MEDFileFieldRepresentationTree::COMPO_STR_TO_LOCATE_MESH_DA[]="-@?|*_"; -vtkIdTypeArray *ELGACmp::findOrCreate(const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const std::vector& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds, bool& isNew) const +vtkIdTypeArray *ELGACmp::findOrCreate(const MEDCoupling::MEDFileFieldGlobsReal *globs, const std::vector& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds, bool& isNew) const { vtkIdTypeArray *try0(isExisting(locsReallyUsed,vtkd)); if(try0) @@ -104,9 +108,9 @@ vtkIdTypeArray *ELGACmp::isExisting(const std::vector& locsReallyUs return ret; } -vtkIdTypeArray *ELGACmp::createNew(const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const std::vector& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds) const +vtkIdTypeArray *ELGACmp::createNew(const MEDCoupling::MEDFileFieldGlobsReal *globs, const std::vector& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds) const { - static const int VTK_DATA_ARRAY_DELETE=vtkDataArrayTemplate::VTK_DATA_ARRAY_DELETE; + const int VTK_DATA_ARRAY_DELETE=vtkDataArrayTemplate::VTK_DATA_ARRAY_DELETE; std::vector< std::vector > locNames(_loc_names); std::vector elgas(_elgas); std::vector< std::pair< vtkQuadratureSchemeDefinition *, unsigned char > > defs; @@ -163,7 +167,7 @@ vtkIdTypeArray *ELGACmp::createNew(const ParaMEDMEM::MEDFileFieldGlobsReal *glob offset+=delta; } elga->GetInformation()->Set(MEDUtilities::ELGA(),1); - elga->SetArray(pt,ncell,0,VTK_DATA_ARRAY_DELETE); + elga->SetVoidArray(pt,ncell,0,VTK_DATA_ARRAY_DELETE); std::ostringstream oss; oss << "ELGA" << "@" << _loc_names.size(); std::string ossStr(oss.str()); elga->SetName(ossStr.c_str()); @@ -174,6 +178,7 @@ vtkIdTypeArray *ELGACmp::createNew(const ParaMEDMEM::MEDFileFieldGlobsReal *glob _loc_names=locNames; _elgas=elgas; _defs.push_back(defs); + return elga; } void ELGACmp::appendELGAIfAny(vtkDataSet *ds) const @@ -193,25 +198,68 @@ ELGACmp::~ELGACmp() //= +template +class MEDFileVTKTraits +{ +public: + typedef void VtkType; + typedef void MCType; +}; + +template<> +class MEDFileVTKTraits +{ +public: + typedef vtkIntArray VtkType; + typedef MEDCoupling::DataArrayInt MCType; +}; + +template<> +class MEDFileVTKTraits +{ +public: + typedef vtkDoubleArray VtkType; + typedef MEDCoupling::DataArrayDouble MCType; +}; + +template +void AssignDataPointerToVTK(typename MEDFileVTKTraits::VtkType *vtkTab, typename MEDFileVTKTraits::MCType *mcTab, bool noCpyNumNodes) +{ + if(noCpyNumNodes) + vtkTab->SetArray(mcTab->getPointer(),mcTab->getNbOfElems(),1,vtkDataArrayTemplate::VTK_DATA_ARRAY_FREE); + else + { vtkTab->SetArray(mcTab->getPointer(),mcTab->getNbOfElems(),0,vtkDataArrayTemplate::VTK_DATA_ARRAY_FREE); mcTab->accessToMemArray().setSpecificDeallocator(0); } +} + +// here copy is always assumed. +template +void AssignDataPointerOther(VTKT *vtkTab, MCT *mcTab, int nbElems) +{ + vtkTab->SetVoidArray(reinterpret_cast(mcTab->getPointer()),nbElems,0,VTKT::VTK_DATA_ARRAY_FREE); + mcTab->accessToMemArray().setSpecificDeallocator(0); +} + +//= + MEDFileFieldRepresentationLeavesArrays::MEDFileFieldRepresentationLeavesArrays():_id(-1) { } -MEDFileFieldRepresentationLeavesArrays::MEDFileFieldRepresentationLeavesArrays(const ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr& arr):ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr(arr),_activated(false),_id(-1) +MEDFileFieldRepresentationLeavesArrays::MEDFileFieldRepresentationLeavesArrays(const MEDCoupling::MCAuto& arr):MEDCoupling::MCAuto(arr),_activated(false),_id(-1) { - std::vector< std::vector > typs((operator->())->getTypesOfFieldAvailable()); + std::vector< std::vector > typs((operator->())->getTypesOfFieldAvailable()); if(typs.size()<1) throw INTERP_KERNEL::Exception("There is a big internal problem in MEDLoader ! The field time spitting has failed ! A CRASH will occur soon !"); if(typs[0].size()!=1) throw INTERP_KERNEL::Exception("There is a big internal problem in MEDLoader ! The field spitting by spatial discretization has failed ! A CRASH will occur soon !"); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr fd(MEDCouplingFieldDiscretization::New(typs[0][0])); + MEDCoupling::MCAuto fd(MEDCouplingFieldDiscretization::New(typs[0][0])); std::ostringstream oss2; oss2 << (operator->())->getName() << ZE_SEP << fd->getRepr(); _ze_name=oss2.str(); } MEDFileFieldRepresentationLeavesArrays& MEDFileFieldRepresentationLeavesArrays::operator=(const MEDFileFieldRepresentationLeavesArrays& other) { - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr::operator=(other); + MEDCoupling::MCAuto::operator=(other); _id=-1; _activated=false; _ze_name=other._ze_name; @@ -234,12 +282,15 @@ std::string MEDFileFieldRepresentationLeavesArrays::getZeName() const return _ze_full_name; } -void MEDFileFieldRepresentationLeavesArrays::feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, const std::string& tsName, const std::string& meshName, const std::string& comSupStr, std::vector& names) const +const char *MEDFileFieldRepresentationLeavesArrays::getZeNameC() const +{ + return _ze_full_name.c_str(); +} + +void MEDFileFieldRepresentationLeavesArrays::feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector& names) const { vtkIdType refId(sil->AddChild(root,edge)); names.push_back(_ze_name); - std::ostringstream oss3; oss3 << tsName << "/" << meshName << "/" << comSupStr << "/" << _ze_name; - _ze_full_name=oss3.str(); // if(MEDFileFieldRepresentationTree::IsFieldMeshRegardingInfo(((operator->())->getInfo()))) { @@ -248,6 +299,12 @@ void MEDFileFieldRepresentationLeavesArrays::feedSIL(vtkMutableDirectedGraph* si } } +void MEDFileFieldRepresentationLeavesArrays::computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const +{ + std::ostringstream oss3; oss3 << tsName << "/" << meshName << "/" << comSupStr << "/" << _ze_name; + _ze_full_name=oss3.str(); +} + bool MEDFileFieldRepresentationLeavesArrays::getStatus() const { return _activated; @@ -260,15 +317,14 @@ bool MEDFileFieldRepresentationLeavesArrays::setStatus(bool status) const return ret; } -void MEDFileFieldRepresentationLeavesArrays::appendFields(const MEDTimeReq *tr, const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const ParaMEDMEM::MEDMeshMultiLev *mml, const ParaMEDMEM::MEDFileMeshStruct *mst, vtkDataSet *ds) const +void MEDFileFieldRepresentationLeavesArrays::appendFields(const MEDTimeReq *tr, const MEDCoupling::MEDFileFieldGlobsReal *globs, const MEDCoupling::MEDMeshMultiLev *mml, const MEDCoupling::MEDFileMeshStruct *mst, vtkDataSet *ds) const { - static const int VTK_DATA_ARRAY_FREE=vtkDataArrayTemplate::VTK_DATA_ARRAY_FREE; - static const int VTK_DATA_ARRAY_DELETE=vtkDataArrayTemplate::VTK_DATA_ARRAY_DELETE; + const int VTK_DATA_ARRAY_DELETE=vtkDataArrayTemplate::VTK_DATA_ARRAY_DELETE; tr->setNumberOfTS((operator->())->getNumberOfTS()); tr->initIterator(); for(int timeStepId=0;timeStepIdsize();timeStepId++,++(*tr)) { - MEDCouplingAutoRefCountObjectPtr f1ts((operator->())->getTimeStepAtPos(tr->getCurrent())); + MCAuto f1ts((operator->())->getTimeStepAtPos(tr->getCurrent())); MEDFileAnyTypeField1TS *f1tsPtr(f1ts); MEDFileField1TS *f1tsPtrDbl(dynamic_cast(f1tsPtr)); MEDFileIntField1TS *f1tsPtrInt(dynamic_cast(f1tsPtr)); @@ -281,7 +337,7 @@ void MEDFileFieldRepresentationLeavesArrays::appendFields(const MEDTimeReq *tr, throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationLeavesArrays::appendFields : only FLOAT64 and INT32 fields are dealt for the moment !"); MEDFileField1TSStructItem fsst(MEDFileField1TSStructItem::BuildItemFrom(f1ts,mst)); f1ts->loadArraysIfNecessary(); - MEDCouplingAutoRefCountObjectPtr v(mml->buildDataArray(fsst,globs,crudeArr)); + MCAuto v(mml->buildDataArray(fsst,globs,crudeArr)); postProcessedArr=v; // std::vector discs(f1ts->getTypesOfFieldAvailable()); @@ -320,14 +376,7 @@ void MEDFileFieldRepresentationLeavesArrays::appendFields(const MEDTimeReq *tr, vtkd->SetNumberOfComponents(vd->getNumberOfComponents()); for(int i=0;igetNumberOfComponents();i++) vtkd->SetComponentName(i,vd->getInfoOnComponent(i).c_str()); - if(postProcessedArr!=crudeArr) - { - vtkd->SetArray(vd->getPointer(),vd->getNbOfElems(),0,VTK_DATA_ARRAY_FREE); vd->accessToMemArray().setSpecificDeallocator(0); - } - else - { - vtkd->SetArray(vd->getPointer(),vd->getNbOfElems(),1,VTK_DATA_ARRAY_FREE); - } + AssignDataPointerToVTK(vtkd,vd,postProcessedArr==crudeArr); std::string name(tr->buildName(f1ts->getName())); vtkd->SetName(name.c_str()); att->AddArray(vtkd); @@ -353,7 +402,7 @@ void MEDFileFieldRepresentationLeavesArrays::appendFields(const MEDTimeReq *tr, offset+=delta; } elno->GetInformation()->Set(MEDUtilities::ELNO(),1); - elno->SetArray(pt,ncell,0,VTK_DATA_ARRAY_DELETE); + elno->SetVoidArray(pt,ncell,0,VTK_DATA_ARRAY_DELETE); std::string nameElno("ELNO"); nameElno+="@"; nameElno+=name; elno->SetName(nameElno.c_str()); ds->GetCellData()->AddArray(elno); @@ -372,7 +421,7 @@ void MEDFileFieldRepresentationLeavesArrays::appendFields(const MEDTimeReq *tr, vtkQuadratureSchemeDefinition *def(vtkQuadratureSchemeDefinition::New()); double *shape(new double[nbGaussPt*nbGaussPt]); std::size_t dummy; - const double *gsCoords(MEDCouplingFieldDiscretizationGaussNE::GetLocsFromGeometricType(ct,dummy)); + const double *gsCoords(MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType(ct,dummy));//GetLocsFromGeometricType const double *refCoords(MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType(ct,dummy)); const double *weights(MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometricType(ct,dummy)); std::vector gsCoords2(gsCoords,gsCoords+nbGaussPt*dim),refCoords2(refCoords,refCoords+nbGaussPt*dim); @@ -400,14 +449,7 @@ void MEDFileFieldRepresentationLeavesArrays::appendFields(const MEDTimeReq *tr, vtkd->SetNumberOfComponents(vi->getNumberOfComponents()); for(int i=0;igetNumberOfComponents();i++) vtkd->SetComponentName(i,vi->getVarOnComponent(i).c_str()); - if(postProcessedArr!=crudeArr) - { - vtkd->SetArray(vi->getPointer(),vi->getNbOfElems(),0,VTK_DATA_ARRAY_FREE); vi->accessToMemArray().setSpecificDeallocator(0); - } - else - { - vtkd->SetArray(vi->getPointer(),vi->getNbOfElems(),1,VTK_DATA_ARRAY_FREE); - } + AssignDataPointerToVTK(vtkd,vi,postProcessedArr==crudeArr); std::string name(tr->buildName(f1ts->getName())); vtkd->SetName(name.c_str()); att->AddArray(vtkd); @@ -429,8 +471,8 @@ MEDFileFieldRepresentationLeaves::MEDFileFieldRepresentationLeaves():_cached_ds( { } -MEDFileFieldRepresentationLeaves::MEDFileFieldRepresentationLeaves(const std::vector< ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr >& arr, - const ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr& fsp):_arrays(arr.size()),_fsp(fsp),_cached_ds(0) +MEDFileFieldRepresentationLeaves::MEDFileFieldRepresentationLeaves(const std::vector< MEDCoupling::MCAuto >& arr, + const MEDCoupling::MCAuto& fsp):_arrays(arr.size()),_fsp(fsp),_cached_ds(0) { for(std::size_t i=0;igetNumberOfTS(); } +void MEDFileFieldRepresentationLeaves::computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const +{ + for(std::vector::const_iterator it=_arrays.begin();it!=_arrays.end();it++) + (*it).computeFullNameInLeaves(tsName,meshName,comSupStr); +} + /*! * \param [in] ms is the meshes pointer. It can be used only for information of geometric types. No special processing will be requested on ms. */ -void MEDFileFieldRepresentationLeaves::feedSIL(const ParaMEDMEM::MEDFileMeshes *ms, vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, const std::string& tsName, const std::string& meshName, const std::string& comSupStr, std::vector& names) const +void MEDFileFieldRepresentationLeaves::feedSIL(const MEDCoupling::MEDFileMeshes *ms, const std::string& meshName, vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector& names) const { vtkIdType root2(sil->AddChild(root,edge)); names.push_back(std::string("Arrs")); for(std::vector::const_iterator it=_arrays.begin();it!=_arrays.end();it++) - (*it).feedSIL(sil,root2,edge,tsName,meshName,comSupStr,names); + (*it).feedSIL(sil,root2,edge,names); // vtkIdType root3(sil->AddChild(root,edge)); names.push_back(std::string("InfoOnGeoType")); - const ParaMEDMEM::MEDFileMesh *m(0); + const MEDCoupling::MEDFileMesh *m(0); if(ms) m=ms->getMeshWithName(meshName); - const ParaMEDMEM::MEDFileFastCellSupportComparator *fsp(_fsp); + const MEDCoupling::MEDFileFastCellSupportComparator *fsp(_fsp); if(!fsp || fsp->getNumberOfTS()==0) return ; std::vector< INTERP_KERNEL::NormalizedCellType > gts(fsp->getGeoTypesAt(0,m)); @@ -516,6 +564,12 @@ bool MEDFileFieldRepresentationLeaves::containZeName(const char *name, int& id) return false; } +void MEDFileFieldRepresentationLeaves::dumpState(std::map& status) const +{ + for(std::vector::const_iterator it=_arrays.begin();it!=_arrays.end();it++) + status[(*it).getZeName()]=(*it).getStatus(); +} + bool MEDFileFieldRepresentationLeaves::isActivated() const { for(std::vector::const_iterator it=_arrays.begin();it!=_arrays.end();it++) @@ -594,11 +648,11 @@ std::string MEDFileFieldRepresentationLeaves::getHumanReadableOverviewOfTS() con return oss.str(); } -void MEDFileFieldRepresentationLeaves::appendFields(const MEDTimeReq *tr, const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const ParaMEDMEM::MEDMeshMultiLev *mml, const ParaMEDMEM::MEDFileMeshes *meshes, vtkDataSet *ds) const +void MEDFileFieldRepresentationLeaves::appendFields(const MEDTimeReq *tr, const MEDCoupling::MEDFileFieldGlobsReal *globs, const MEDCoupling::MEDMeshMultiLev *mml, const MEDCoupling::MEDFileMeshes *meshes, vtkDataSet *ds) const { if(_arrays.size()<1) throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationLeaves::appendFields : internal error !"); - MEDCouplingAutoRefCountObjectPtr mst(MEDFileMeshStruct::New(meshes->getMeshWithName(_arrays[0]->getMeshName().c_str()))); + MCAuto mst(MEDFileMeshStruct::New(meshes->getMeshWithName(_arrays[0]->getMeshName().c_str()))); for(std::vector::const_iterator it=_arrays.begin();it!=_arrays.end();it++) if((*it).getStatus()) { @@ -609,32 +663,31 @@ void MEDFileFieldRepresentationLeaves::appendFields(const MEDTimeReq *tr, const vtkUnstructuredGrid *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInterpolationUnstructured(MEDUMeshMultiLev *mm) const { - static const int VTK_DATA_ARRAY_FREE=vtkDataArrayTemplate::VTK_DATA_ARRAY_FREE; DataArrayDouble *coordsMC(0); DataArrayByte *typesMC(0); DataArrayInt *cellLocationsMC(0),*cellsMC(0),*faceLocationsMC(0),*facesMC(0); bool statusOfCoords(mm->buildVTUArrays(coordsMC,typesMC,cellLocationsMC,cellsMC,faceLocationsMC,facesMC)); - MEDCouplingAutoRefCountObjectPtr coordsSafe(coordsMC); - MEDCouplingAutoRefCountObjectPtr typesSafe(typesMC); - MEDCouplingAutoRefCountObjectPtr cellLocationsSafe(cellLocationsMC),cellsSafe(cellsMC),faceLocationsSafe(faceLocationsMC),facesSafe(facesMC); + MCAuto coordsSafe(coordsMC); + MCAuto typesSafe(typesMC); + MCAuto cellLocationsSafe(cellLocationsMC),cellsSafe(cellsMC),faceLocationsSafe(faceLocationsMC),facesSafe(facesMC); // int nbOfCells(typesSafe->getNbOfElems()); vtkUnstructuredGrid *ret(vtkUnstructuredGrid::New()); vtkUnsignedCharArray *cellTypes(vtkUnsignedCharArray::New()); - cellTypes->SetArray(reinterpret_cast(typesSafe->getPointer()),nbOfCells,0,VTK_DATA_ARRAY_FREE); typesSafe->accessToMemArray().setSpecificDeallocator(0); + AssignDataPointerOther(cellTypes,typesSafe,nbOfCells); vtkIdTypeArray *cellLocations(vtkIdTypeArray::New()); - cellLocations->SetArray(cellLocationsSafe->getPointer(),nbOfCells,0,VTK_DATA_ARRAY_FREE); cellLocationsSafe->accessToMemArray().setSpecificDeallocator(0); + AssignDataPointerOther(cellLocations,cellLocationsSafe,nbOfCells); vtkCellArray *cells(vtkCellArray::New()); vtkIdTypeArray *cells2(vtkIdTypeArray::New()); - cells2->SetArray(cellsSafe->getPointer(),cellsSafe->getNbOfElems(),0,VTK_DATA_ARRAY_FREE); cellsSafe->accessToMemArray().setSpecificDeallocator(0); + AssignDataPointerOther(cells2,cellsSafe,cellsSafe->getNbOfElems()); cells->SetCells(nbOfCells,cells2); cells2->Delete(); if(faceLocationsMC!=0 && facesMC!=0) { vtkIdTypeArray *faces(vtkIdTypeArray::New()); - faces->SetArray(facesSafe->getPointer(),facesSafe->getNbOfElems(),0,VTK_DATA_ARRAY_FREE); facesSafe->accessToMemArray().setSpecificDeallocator(0); + AssignDataPointerOther(faces,facesSafe,facesSafe->getNbOfElems()); vtkIdTypeArray *faceLocations(vtkIdTypeArray::New()); - faceLocations->SetArray(faceLocationsSafe->getPointer(),faceLocationsSafe->getNbOfElems(),0,VTK_DATA_ARRAY_FREE); faceLocationsSafe->accessToMemArray().setSpecificDeallocator(0); + AssignDataPointerOther(faceLocations,faceLocationsSafe,faceLocationsSafe->getNbOfElems()); ret->SetCells(cellTypes,cellLocations,cells,faceLocations,faces); faceLocations->Delete(); faces->Delete(); @@ -647,13 +700,7 @@ vtkUnstructuredGrid *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInt vtkPoints *pts(vtkPoints::New()); vtkDoubleArray *pts2(vtkDoubleArray::New()); pts2->SetNumberOfComponents(3); - if(!statusOfCoords) - { - pts2->SetArray(coordsSafe->getPointer(),coordsSafe->getNbOfElems(),0,VTK_DATA_ARRAY_FREE); - coordsSafe->accessToMemArray().setSpecificDeallocator(0); - } - else - pts2->SetArray(coordsSafe->getPointer(),coordsSafe->getNbOfElems(),1,VTK_DATA_ARRAY_FREE); + AssignDataPointerToVTK(pts2,coordsSafe,statusOfCoords); pts->SetData(pts2); pts2->Delete(); ret->SetPoints(pts); @@ -662,9 +709,8 @@ vtkUnstructuredGrid *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInt return ret; } -vtkRectilinearGrid *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInterpolationCartesian(ParaMEDMEM::MEDCMeshMultiLev *mm) const +vtkRectilinearGrid *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInterpolationCartesian(MEDCoupling::MEDCMeshMultiLev *mm) const { - static const int VTK_DATA_ARRAY_FREE=vtkDataArrayTemplate::VTK_DATA_ARRAY_FREE; bool isInternal; std::vector< DataArrayDouble * > arrs(mm->buildVTUArrays(isInternal)); vtkDoubleArray *vtkTmp(0); @@ -681,10 +727,7 @@ vtkRectilinearGrid *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInte ret->SetDimensions(sizePerAxe[0],sizePerAxe[1],sizePerAxe[2]); vtkTmp=vtkDoubleArray::New(); vtkTmp->SetNumberOfComponents(1); - if(isInternal) - vtkTmp->SetArray(arrs[0]->getPointer(),arrs[0]->getNbOfElems(),1,VTK_DATA_ARRAY_FREE); - else - { vtkTmp->SetArray(arrs[0]->getPointer(),arrs[0]->getNbOfElems(),0,VTK_DATA_ARRAY_FREE); arrs[0]->accessToMemArray().setSpecificDeallocator(0); } + AssignDataPointerToVTK(vtkTmp,arrs[0],isInternal); ret->SetXCoordinates(vtkTmp); vtkTmp->Delete(); arrs[0]->decrRef(); @@ -692,10 +735,7 @@ vtkRectilinearGrid *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInte { vtkTmp=vtkDoubleArray::New(); vtkTmp->SetNumberOfComponents(1); - if(isInternal) - vtkTmp->SetArray(arrs[1]->getPointer(),arrs[1]->getNbOfElems(),1,VTK_DATA_ARRAY_FREE); - else - { vtkTmp->SetArray(arrs[1]->getPointer(),arrs[1]->getNbOfElems(),0,VTK_DATA_ARRAY_FREE); arrs[1]->accessToMemArray().setSpecificDeallocator(0); } + AssignDataPointerToVTK(vtkTmp,arrs[1],isInternal); ret->SetYCoordinates(vtkTmp); vtkTmp->Delete(); arrs[1]->decrRef(); @@ -704,10 +744,7 @@ vtkRectilinearGrid *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInte { vtkTmp=vtkDoubleArray::New(); vtkTmp->SetNumberOfComponents(1); - if(isInternal) - vtkTmp->SetArray(arrs[2]->getPointer(),arrs[2]->getNbOfElems(),1,VTK_DATA_ARRAY_FREE); - else - { vtkTmp->SetArray(arrs[2]->getPointer(),arrs[2]->getNbOfElems(),0,VTK_DATA_ARRAY_FREE); arrs[2]->accessToMemArray().setSpecificDeallocator(0); } + AssignDataPointerToVTK(vtkTmp,arrs[2],isInternal); ret->SetZCoordinates(vtkTmp); vtkTmp->Delete(); arrs[2]->decrRef(); @@ -715,9 +752,8 @@ vtkRectilinearGrid *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInte return ret; } -vtkStructuredGrid *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInterpolationCurveLinear(ParaMEDMEM::MEDCurveLinearMeshMultiLev *mm) const +vtkStructuredGrid *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInterpolationCurveLinear(MEDCoupling::MEDCurveLinearMeshMultiLev *mm) const { - static const int VTK_DATA_ARRAY_FREE=vtkDataArrayTemplate::VTK_DATA_ARRAY_FREE; int meshStr[3]={1,1,1}; DataArrayDouble *coords(0); std::vector nodeStrct; @@ -736,17 +772,11 @@ vtkStructuredGrid *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInter vtkDoubleArray *da(vtkDoubleArray::New()); da->SetNumberOfComponents(3); if(coords->getNumberOfComponents()==3) - { - if(isInternal) - da->SetArray(coords->getPointer(),coords->getNbOfElems(),1,VTK_DATA_ARRAY_FREE);//VTK has not the ownership of double * because MEDLoader main struct has it ! - else - { da->SetArray(coords->getPointer(),coords->getNbOfElems(),0,VTK_DATA_ARRAY_FREE); coords->accessToMemArray().setSpecificDeallocator(0); } - } + AssignDataPointerToVTK(da,coords,isInternal);//if isIntenal==True VTK has not the ownership of double * because MEDLoader main struct has it ! else { - MEDCouplingAutoRefCountObjectPtr coords2(coords->changeNbOfComponents(3,0.)); - da->SetArray(coords2->getPointer(),coords2->getNbOfElems(),0,VTK_DATA_ARRAY_FREE);//let VTK deal with double * - coords2->accessToMemArray().setSpecificDeallocator(0); + MCAuto coords2(coords->changeNbOfComponents(3,0.)); + AssignDataPointerToVTK(da,coords2,false);//let VTK deal with double * } coords->decrRef(); vtkPoints *points=vtkPoints::New(); @@ -757,13 +787,12 @@ vtkStructuredGrid *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInter return ret; } -vtkDataSet *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInterpolation(const MEDTimeReq *tr, const MEDFileFieldGlobsReal *globs, const ParaMEDMEM::MEDFileMeshes *meshes) const +vtkDataSet *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInterpolation(const MEDTimeReq *tr, const MEDFileFieldGlobsReal *globs, const MEDCoupling::MEDFileMeshes *meshes) const { - static const int VTK_DATA_ARRAY_FREE=vtkDataArrayTemplate::VTK_DATA_ARRAY_FREE; vtkDataSet *ret(0); //_fsp->isDataSetSupportEqualToThePreviousOne(i,globs); - MEDCouplingAutoRefCountObjectPtr mml(_fsp->buildFromScratchDataSetSupport(0,globs));//0=timestep Id. Make the hypothesis that support does not change - MEDCouplingAutoRefCountObjectPtr mml2(mml->prepare()); + MCAuto mml(_fsp->buildFromScratchDataSetSupport(0,globs));//0=timestep Id. Make the hypothesis that support does not change + MCAuto mml2(mml->prepare()); MEDMeshMultiLev *ptMML2(mml2); if(!_cached_ds) { @@ -804,10 +833,7 @@ vtkDataSet *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInterpolatio vtkIntArray *vtkTab(vtkIntArray::New()); vtkTab->SetNumberOfComponents(1); vtkTab->SetName(MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_CELL_NAME); - if(noCpyFamCells) - vtkTab->SetArray(famCells->getPointer(),famCells->getNbOfElems(),1,VTK_DATA_ARRAY_FREE); - else - { vtkTab->SetArray(famCells->getPointer(),famCells->getNbOfElems(),0,VTK_DATA_ARRAY_FREE); famCells->accessToMemArray().setSpecificDeallocator(0); } + AssignDataPointerToVTK(vtkTab,famCells,noCpyFamCells); ret->GetCellData()->AddArray(vtkTab); vtkTab->Delete(); famCells->decrRef(); @@ -818,10 +844,7 @@ vtkDataSet *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInterpolatio vtkIntArray *vtkTab(vtkIntArray::New()); vtkTab->SetNumberOfComponents(1); vtkTab->SetName(MEDFileFieldRepresentationLeavesArrays::NUM_ID_CELL_NAME); - if(noCpyNumCells) - vtkTab->SetArray(numCells->getPointer(),numCells->getNbOfElems(),1,VTK_DATA_ARRAY_FREE); - else - { vtkTab->SetArray(numCells->getPointer(),numCells->getNbOfElems(),0,VTK_DATA_ARRAY_FREE); numCells->accessToMemArray().setSpecificDeallocator(0); } + AssignDataPointerToVTK(vtkTab,numCells,noCpyNumCells); ret->GetCellData()->AddArray(vtkTab); vtkTab->Delete(); numCells->decrRef(); @@ -835,10 +858,7 @@ vtkDataSet *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInterpolatio vtkIntArray *vtkTab(vtkIntArray::New()); vtkTab->SetNumberOfComponents(1); vtkTab->SetName(MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME); - if(noCpyFamNodes) - vtkTab->SetArray(famNodes->getPointer(),famNodes->getNbOfElems(),1,VTK_DATA_ARRAY_FREE); - else - { vtkTab->SetArray(famNodes->getPointer(),famNodes->getNbOfElems(),0,VTK_DATA_ARRAY_FREE); famNodes->accessToMemArray().setSpecificDeallocator(0); } + AssignDataPointerToVTK(vtkTab,famNodes,noCpyFamNodes); ret->GetPointData()->AddArray(vtkTab); vtkTab->Delete(); famNodes->decrRef(); @@ -849,14 +869,23 @@ vtkDataSet *MEDFileFieldRepresentationLeaves::buildVTKInstanceNoTimeInterpolatio vtkIntArray *vtkTab(vtkIntArray::New()); vtkTab->SetNumberOfComponents(1); vtkTab->SetName(MEDFileFieldRepresentationLeavesArrays::NUM_ID_NODE_NAME); - if(noCpyNumNodes) - vtkTab->SetArray(numNodes->getPointer(),numNodes->getNbOfElems(),1,VTK_DATA_ARRAY_FREE); - else - { vtkTab->SetArray(numNodes->getPointer(),numNodes->getNbOfElems(),0,VTK_DATA_ARRAY_FREE); numNodes->accessToMemArray().setSpecificDeallocator(0); } + AssignDataPointerToVTK(vtkTab,numNodes,noCpyNumNodes); ret->GetPointData()->AddArray(vtkTab); vtkTab->Delete(); numNodes->decrRef(); } + // Global Node Ids if any ! (In // mode) + DataArrayInt *gni(ptMML2->retrieveGlobalNodeIdsIfAny()); + if(gni) + { + vtkIntArray *vtkTab(vtkIntArray::New()); + vtkTab->SetNumberOfComponents(1); + vtkTab->SetName(MEDFileFieldRepresentationLeavesArrays::GLOBAL_NODE_ID_NAME); + AssignDataPointerToVTK(vtkTab,gni,false); + ret->GetPointData()->AddArray(vtkTab); + vtkTab->Delete(); + gni->decrRef(); + } return ret; } @@ -884,6 +913,28 @@ void MEDFileFieldRepresentationTree::assignIds() const for(std::vector< MEDFileFieldRepresentationLeaves >::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++) (*it2).setId(zeId); } + +void MEDFileFieldRepresentationTree::computeFullNameInLeaves() const +{ + std::size_t it0Cnt(0); + for(std::vector< std::vector< std::vector< MEDFileFieldRepresentationLeaves > > >::const_iterator it0=_data_structure.begin();it0!=_data_structure.end();it0++,it0Cnt++) + { + std::ostringstream oss; oss << MEDFileFieldRepresentationLeavesArrays::TS_STR << it0Cnt; + std::string tsName(oss.str()); + for(std::vector< std::vector< MEDFileFieldRepresentationLeaves > >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++) + { + std::string meshName((*it1)[0].getMeshName()); + std::size_t it2Cnt(0); + for(std::vector< MEDFileFieldRepresentationLeaves >::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++,it2Cnt++) + { + std::ostringstream oss2; oss2 << MEDFileFieldRepresentationLeavesArrays::COM_SUP_STR << it2Cnt; + std::string comSupStr(oss2.str()); + (*it2).computeFullNameInLeaves(tsName,meshName,comSupStr); + } + } + } +} + void MEDFileFieldRepresentationTree::activateTheFirst() const { for(std::vector< std::vector< std::vector< MEDFileFieldRepresentationLeaves > > >::const_iterator it0=_data_structure.begin();it0!=_data_structure.end();it0++) @@ -938,12 +989,19 @@ void MEDFileFieldRepresentationTree::feedSIL(vtkMutableDirectedGraph* sil, vtkId std::string comSupStr(oss2.str()); vtkIdType typeId2(sil->AddChild(typeId1,edge)); names.push_back(comSupStr); - (*it2).feedSIL(_ms,sil,typeId2,edge,tsName,meshName,comSupStr,names); + (*it2).feedSIL(_ms,meshName,sil,typeId2,edge,names); } } } } +std::string MEDFileFieldRepresentationTree::getActiveMeshName() const +{ + int dummy0(0),dummy1(0),dummy2(0); + const MEDFileFieldRepresentationLeaves& leaf(getTheSingleActivated(dummy0,dummy1,dummy2)); + return leaf.getMeshName(); +} + std::string MEDFileFieldRepresentationTree::feedSILForFamsAndGrps(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector& names) const { int dummy0(0),dummy1(0),dummy2(0); @@ -1006,6 +1064,12 @@ std::string MEDFileFieldRepresentationTree::getNameOf(int id) const return elt.getZeName(); } +const char *MEDFileFieldRepresentationTree::getNameOfC(int id) const +{ + const MEDFileFieldRepresentationLeavesArrays& elt(getLeafArr(id)); + return elt.getZeNameC(); +} + bool MEDFileFieldRepresentationTree::getStatusOf(int id) const { const MEDFileFieldRepresentationLeavesArrays& elt(getLeafArr(id)); @@ -1020,7 +1084,8 @@ int MEDFileFieldRepresentationTree::getIdHavingZeName(const char *name) const for(std::vector< MEDFileFieldRepresentationLeaves >::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++) if((*it2).containZeName(name,ret)) return ret; - throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationTree::getIdHavingZeName : No such a name !"); + std::ostringstream msg; msg << "MEDFileFieldRepresentationTree::getIdHavingZeName : No such a name \"" << name << "\" !"; + throw INTERP_KERNEL::Exception(msg.str().c_str()); } bool MEDFileFieldRepresentationTree::changeStatusOfAndUpdateToHaveCoherentVTKDataSet(int id, bool status) const @@ -1043,31 +1108,15 @@ int MEDFileFieldRepresentationTree::getMaxNumberOfTimeSteps() const /*! * */ -void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileName, bool isMEDOrSauv) +void MEDFileFieldRepresentationTree::loadInMemory(MEDCoupling::MEDFileFields *fields, MEDCoupling::MEDFileMeshes *meshes) { - if(isMEDOrSauv) - { - _ms=MEDFileMeshes::New(fileName); - _fields=MEDFileFields::New(fileName,false);//false is important to not read the values - } - else - { - MEDCouplingAutoRefCountObjectPtr sr(ParaMEDMEM::SauvReader::New(fileName)); - MEDCouplingAutoRefCountObjectPtr mfd(sr->loadInMEDFileDS()); - _ms=mfd->getMeshes(); _ms->incrRef(); - int nbMeshes(_ms->getNumberOfMeshes()); - for(int i=0;igetMeshAtPos(i)); - ParaMEDMEM::MEDFileUMesh *tmp2(dynamic_cast(tmp)); - if(tmp2) - tmp2->forceComputationOfParts(); - } - _fields=mfd->getFields(); - if((ParaMEDMEM::MEDFileFields *)_fields) - _fields->incrRef(); - } - if(!((ParaMEDMEM::MEDFileFields *)_fields)) + _fields=fields; _ms=meshes; + if(_fields.isNotNull()) + _fields->incrRef(); + if(_ms.isNotNull()) + _ms->incrRef(); + // + if(_fields.isNull()) { _fields=BuildFieldFromMeshes(_ms); } @@ -1075,22 +1124,40 @@ void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileNam { AppendFieldFromMeshes(_ms,_fields); } + _ms->cartesianizeMe(); _fields->removeFieldsWithoutAnyTimeStep(); std::vector meshNames(_ms->getMeshesNames()); - std::vector< MEDCouplingAutoRefCountObjectPtr > fields_per_mesh(meshNames.size()); + std::vector< MCAuto > fields_per_mesh(meshNames.size()); for(std::size_t i=0;ipartOfThisLyingOnSpecifiedMeshName(meshNames[i].c_str()); } - std::vector< MEDCouplingAutoRefCountObjectPtr > allFMTSLeavesToDisplaySafe; + std::vector< MCAuto > allFMTSLeavesToDisplaySafe; std::size_t k(0); - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator fields=fields_per_mesh.begin();fields!=fields_per_mesh.end();fields++) + for(std::vector< MCAuto >::const_iterator fields=fields_per_mesh.begin();fields!=fields_per_mesh.end();fields++) { for(int j=0;j<(*fields)->getNumberOfFields();j++) { - MEDCouplingAutoRefCountObjectPtr fmts((*fields)->getFieldAtPos((int)j)); - std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > tmp(fmts->splitDiscretizations()); - allFMTSLeavesToDisplaySafe.insert(allFMTSLeavesToDisplaySafe.end(),tmp.begin(),tmp.end()); + MCAuto fmts((*fields)->getFieldAtPos((int)j)); + std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > tmp(fmts->splitDiscretizations()); + // EDF 8655 + for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > >::const_iterator it=tmp.begin();it!=tmp.end();it++) + { + if(!(*it)->presenceOfMultiDiscPerGeoType()) + allFMTSLeavesToDisplaySafe.push_back(*it); + else + {// The case of some parts of field have more than one discretization per geo type. + std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > subTmp((*it)->splitMultiDiscrPerGeoTypes()); + std::size_t it0Cnt(0); + for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > >::iterator it0=subTmp.begin();it0!=subTmp.end();it0++,it0Cnt++)//not const because setName + { + std::ostringstream oss; oss << (*it0)->getName() << "_" << std::setfill('M') << std::setw(3) << it0Cnt; + (*it0)->setName(oss.str()); + allFMTSLeavesToDisplaySafe.push_back(*it0); + } + } + } + // end EDF 8655 } } std::vector< MEDFileAnyTypeFieldMultiTS *> allFMTSLeavesToDisplay(allFMTSLeavesToDisplaySafe.size()); @@ -1100,7 +1167,7 @@ void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileNam } std::vector< std::vector > allFMTSLeavesPerTimeSeries(MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(allFMTSLeavesToDisplay)); // memory safety part - std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr > > allFMTSLeavesPerTimeSeriesSafe(allFMTSLeavesPerTimeSeries.size()); + std::vector< std::vector< MCAuto > > allFMTSLeavesPerTimeSeriesSafe(allFMTSLeavesPerTimeSeries.size()); for(std::size_t j=0;j_data_structure.resize(allFMTSLeavesPerTimeSeriesSafe.size()); for(std::size_t i=0;i meshNamesLoc; - std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr > > splitByMeshName; + std::vector< std::string > meshNamesLoc; + std::vector< std::vector< MCAuto > > splitByMeshName; for(std::size_t j=0;jgetMeshName()); - vtksys_stl::vector< vtksys_stl::string >::iterator it(std::find(meshNamesLoc.begin(),meshNamesLoc.end(),meshName)); + std::vector< std::string >::iterator it(std::find(meshNamesLoc.begin(),meshNamesLoc.end(),meshName)); if(it==meshNamesLoc.end()) { meshNamesLoc.push_back(meshName); @@ -1133,13 +1200,13 @@ void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileNam _data_structure[i].resize(meshNamesLoc.size()); for(std::size_t j=0;j > fsp; + std::vector< MCAuto > fsp; std::vector< MEDFileAnyTypeFieldMultiTS *> sbmn(splitByMeshName[j].size()); for(std::size_t k=0;k > commonSupSplit(MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(sbmn,_ms->getMeshWithName(meshNamesLoc[j].c_str()),fsp)); - std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr > > commonSupSplitSafe(commonSupSplit.size()); + std::vector< std::vector< MCAuto > > commonSupSplitSafe(commonSupSplit.size()); this->_data_structure[i][j].resize(commonSupSplit.size()); for(std::size_t k=0;kremoveEmptyLeaves(); this->assignIds(); + this->computeFullNameInLeaves(); +} + +void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileName, bool isMEDOrSauv, int iPart, int nbOfParts) +{ + MCAuto ms; + MCAuto fields; + if(isMEDOrSauv) + { + if((iPart==-1 && nbOfParts==-1) || (iPart==0 && nbOfParts==1)) + { + ms=MEDFileMeshes::New(fileName); + fields=MEDFileFields::New(fileName,false);//false is important to not read the values + } + else + { +#ifdef MEDREADER_USE_MPI + ms=ParaMEDFileMeshes::New(iPart,nbOfParts,fileName); + int nbMeshes(ms->getNumberOfMeshes()); + for(int i=0;igetMeshAtPos(i)); + MEDCoupling::MEDFileUMesh *tmp2(dynamic_cast(tmp)); + if(tmp2) + MCAuto tmp3(tmp2->zipCoords()); + } + fields=MEDFileFields::LoadPartOf(fileName,false,ms);//false is important to not read the values +#else + std::ostringstream oss; oss << "MEDFileFieldRepresentationTree::loadMainStructureOfFile : request for iPart/nbOfParts=" << iPart << "/" << nbOfParts << " whereas Plugin not compiled with MPI !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); +#endif + } + } + else + { + MCAuto sr(MEDCoupling::SauvReader::New(fileName)); + MCAuto mfd(sr->loadInMEDFileDS()); + ms=mfd->getMeshes(); ms->incrRef(); + int nbMeshes(ms->getNumberOfMeshes()); + for(int i=0;igetMeshAtPos(i)); + MEDCoupling::MEDFileUMesh *tmp2(dynamic_cast(tmp)); + if(tmp2) + tmp2->forceComputationOfParts(); + } + fields=mfd->getFields(); + if(fields.isNotNull()) + fields->incrRef(); + } + loadInMemory(fields,ms); } void MEDFileFieldRepresentationTree::removeEmptyLeaves() @@ -1252,7 +1370,7 @@ vtkDataSet *MEDFileFieldRepresentationTree::buildVTKInstance(bool isStdOrMode, d if(!isStdOrMode) tr=new MEDStdTimeReq((int)zeTimeId); else - tr=new MEDModeTimeReq(tk.getTheVectOfBool()); + tr=new MEDModeTimeReq(tk.getTheVectOfBool(),tk.getPostProcessedTime()); vtkDataSet *ret(leaf.buildVTKInstanceNoTimeInterpolation(tr,_fields,_ms)); delete tr; return ret; @@ -1306,76 +1424,170 @@ void MEDFileFieldRepresentationTree::printMySelf(std::ostream& os) const os << "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << std::endl; } -void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms, ParaMEDMEM::MEDFileFields *ret) +std::map MEDFileFieldRepresentationTree::dumpState() const { + std::map ret; + for(std::vector< std::vector< std::vector< MEDFileFieldRepresentationLeaves > > >::const_iterator it0=_data_structure.begin();it0!=_data_structure.end();it0++) + for(std::vector< std::vector< MEDFileFieldRepresentationLeaves > >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++) + for(std::vector< MEDFileFieldRepresentationLeaves >::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++) + (*it2).dumpState(ret); + return ret; +} + +void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const MEDCoupling::MEDFileMeshes *ms, MEDCoupling::MEDFileFields *ret) +{ + if(!ret) + throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationTree::AppendFieldFromMeshes : internal error ! NULL ret !"); for(int i=0;igetNumberOfMeshes();i++) { MEDFileMesh *mm(ms->getMeshAtPos(i)); std::vector levs(mm->getNonEmptyLevels()); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr f1tsMultiLev(ParaMEDMEM::MEDFileField1TS::New()); + MEDCoupling::MCAuto f1tsMultiLev(MEDCoupling::MEDFileField1TS::New()); MEDFileUMesh *mmu(dynamic_cast(mm)); if(mmu) - { - for(std::vector::const_iterator it=levs.begin();it!=levs.end();it++) - { - std::vector gts(mmu->getGeoTypesAtLevel(*it)); - for(std::vector::const_iterator gt=gts.begin();gt!=gts.end();gt++) - { - ParaMEDMEM::MEDCouplingMesh *m(mmu->getDirectUndergroundSingleGeoTypeMesh(*gt)); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr f(ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS)); - f->setMesh(m); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr arr(ParaMEDMEM::DataArrayDouble::New()); arr->alloc(f->getNumberOfTuplesExpected()); - arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA)); - arr->iota(); - f->setArray(arr); - f->setName(mm->getName()); - f1tsMultiLev->setFieldNoProfileSBT(f); - } - } - if(levs.empty()) - { - std::vector levsExt(mm->getNonEmptyLevelsExt()); - if(levsExt.size()==levs.size()+1) - { - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr m(mm->getGenMeshAtLevel(1)); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr f(ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES)); - f->setMesh(m); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr arr(ParaMEDMEM::DataArrayDouble::New()); arr->alloc(m->getNumberOfNodes()); - arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA)); - arr->iota(); f->setArray(arr); - f->setName(mm->getName()); - f1tsMultiLev->setFieldNoProfileSBT(f); - } - else - continue; - } - } + { + for(std::vector::const_iterator it=levs.begin();it!=levs.end();it++) + { + std::vector gts(mmu->getGeoTypesAtLevel(*it)); + for(std::vector::const_iterator gt=gts.begin();gt!=gts.end();gt++) + { + MEDCoupling::MEDCouplingMesh *m(mmu->getDirectUndergroundSingleGeoTypeMesh(*gt)); + MEDCoupling::MCAuto f(MEDCoupling::MEDCouplingFieldDouble::New(MEDCoupling::ON_CELLS)); + f->setMesh(m); + MEDCoupling::MCAuto arr(MEDCoupling::DataArrayDouble::New()); arr->alloc(f->getNumberOfTuplesExpected()); + arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA)); + arr->iota(); + f->setArray(arr); + f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret)); + f1tsMultiLev->setFieldNoProfileSBT(f); + } + } + if(levs.empty()) + { + std::vector levsExt(mm->getNonEmptyLevelsExt()); + if(levsExt.size()==levs.size()+1) + { + MEDCoupling::MCAuto m(mm->getMeshAtLevel(1)); + MEDCoupling::MCAuto f(MEDCoupling::MEDCouplingFieldDouble::New(MEDCoupling::ON_NODES)); + f->setMesh(m); + MEDCoupling::MCAuto arr(MEDCoupling::DataArrayDouble::New()); arr->alloc(m->getNumberOfNodes()); + arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA)); + arr->iota(); f->setArray(arr); + f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret)); + f1tsMultiLev->setFieldNoProfileSBT(f); + } + else + continue; + } + } else - { - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr m(mm->getGenMeshAtLevel(0)); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr f(ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS)); - f->setMesh(m); - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr arr(ParaMEDMEM::DataArrayDouble::New()); arr->alloc(f->getNumberOfTuplesExpected()); - arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA)); - arr->iota(); - f->setArray(arr); - f->setName(mm->getName()); - f1tsMultiLev->setFieldNoProfileSBT(f); - } + { + MEDCoupling::MCAuto m(mm->getMeshAtLevel(0)); + MEDCoupling::MCAuto f(MEDCoupling::MEDCouplingFieldDouble::New(MEDCoupling::ON_CELLS)); + f->setMesh(m); + MEDCoupling::MCAuto arr(MEDCoupling::DataArrayDouble::New()); arr->alloc(f->getNumberOfTuplesExpected()); + arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA)); + arr->iota(); + f->setArray(arr); + f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret)); + f1tsMultiLev->setFieldNoProfileSBT(f); + } // - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr fmtsMultiLev(ParaMEDMEM::MEDFileFieldMultiTS::New()); + MEDCoupling::MCAuto fmtsMultiLev(MEDCoupling::MEDFileFieldMultiTS::New()); fmtsMultiLev->pushBackTimeStep(f1tsMultiLev); ret->pushField(fmtsMultiLev); } } -ParaMEDMEM::MEDFileFields *MEDFileFieldRepresentationTree::BuildFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms) +std::string MEDFileFieldRepresentationTree::BuildAUniqueArrayNameForMesh(const std::string& meshName, const MEDCoupling::MEDFileFields *ret) +{ + const char KEY_STR_TO_AVOID_COLLIDE[]="MESH@"; + if(!ret) + throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationTree::BuildAUniqueArrayNameForMesh : internal error ! NULL ret !"); + std::vector fieldNamesAlreadyExisting(ret->getFieldsNames()); + if(std::find(fieldNamesAlreadyExisting.begin(),fieldNamesAlreadyExisting.end(),meshName)==fieldNamesAlreadyExisting.end()) + return meshName; + std::string tmpName(KEY_STR_TO_AVOID_COLLIDE); tmpName+=meshName; + while(std::find(fieldNamesAlreadyExisting.begin(),fieldNamesAlreadyExisting.end(),tmpName)!=fieldNamesAlreadyExisting.end()) + tmpName=std::string(KEY_STR_TO_AVOID_COLLIDE)+tmpName; + return tmpName; +} + +MEDCoupling::MEDFileFields *MEDFileFieldRepresentationTree::BuildFieldFromMeshes(const MEDCoupling::MEDFileMeshes *ms) { - ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret(ParaMEDMEM::MEDFileFields::New()); + MEDCoupling::MCAuto ret(MEDCoupling::MEDFileFields::New()); AppendFieldFromMeshes(ms,ret); return ret.retn(); } +std::vector MEDFileFieldRepresentationTree::SplitFieldNameIntoParts(const std::string& fullFieldName, char sep) +{ + std::vector ret; + std::size_t pos(0); + while(pos!=std::string::npos) + { + std::size_t curPos(fullFieldName.find_first_of(sep,pos)); + std::string elt(fullFieldName.substr(pos,curPos!=std::string::npos?curPos-pos:std::string::npos)); + ret.push_back(elt); + pos=fullFieldName.find_first_not_of(sep,curPos); + } + return ret; +} + +/*! + * Here the non regression tests. + * const char inp0[]=""; + * const char exp0[]=""; + * const char inp1[]="field"; + * const char exp1[]="field"; + * const char inp2[]="_________"; + * const char exp2[]="_________"; + * const char inp3[]="field_p"; + * const char exp3[]="field_p"; + * const char inp4[]="field__p"; + * const char exp4[]="field_p"; + * const char inp5[]="field_p__"; + * const char exp5[]="field_p"; + * const char inp6[]="field_p_"; + * const char exp6[]="field_p"; + * const char inp7[]="field_____EDFGEG//sdkjf_____PP_______________"; + * const char exp7[]="field_EDFGEG//sdkjf_PP"; + * const char inp8[]="field_____EDFGEG//sdkjf_____PP"; + * const char exp8[]="field_EDFGEG//sdkjf_PP"; + * const char inp9[]="_field_____EDFGEG//sdkjf_____PP_______________"; + * const char exp9[]="field_EDFGEG//sdkjf_PP"; + * const char inp10[]="___field_____EDFGEG//sdkjf_____PP_______________"; + * const char exp10[]="field_EDFGEG//sdkjf_PP"; +*/ +std::string MEDFileFieldRepresentationTree::PostProcessFieldName(const std::string& fullFieldName) +{ + const char SEP('_'); + std::vector v(SplitFieldNameIntoParts(fullFieldName,SEP)); + if(v.empty()) + return fullFieldName;//should never happen + if(v.size()==1) + { + if(v[0].empty()) + return fullFieldName; + else + return v[0]; + } + std::string ret(v[0]); + for(std::size_t i=1;i