X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FMEDFileFieldOverView.cxx;h=42b4759ebdfe0c3ae3eb93582fe4e4059d9b6634;hb=f13ce72017fd205546293a53f7b041824cb50eec;hp=c4a5f81a88ccb4b322417effb1666f44f8351666;hpb=744e58cde1ac894be1cbc09c9a023cc9ebc262c5;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/MEDFileFieldOverView.cxx b/src/MEDLoader/MEDFileFieldOverView.cxx index c4a5f81a8..42b4759eb 100644 --- a/src/MEDLoader/MEDFileFieldOverView.cxx +++ b/src/MEDLoader/MEDFileFieldOverView.cxx @@ -27,7 +27,7 @@ using namespace ParaMEDMEM; const unsigned char MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE[MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE_LGTH]= - {1,3,21,5,9,7,22,34,23,28,255,255,255,255,10,14,13,255,12,255,24,255,16,27,255,26,255,29,255,255,25,42,36,4}; +{1,3,21,5,9,7,22,34,23,28,255,255,255,255,10,14,13,255,12,255,24,255,16,27,255,26,255,29,255,255,25,42,36,4}; const unsigned char MEDMeshMultiLev::HEXA27_PERM_ARRAY[27]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,24,22,21,23,20,25,26}; @@ -209,6 +209,15 @@ void MEDMeshMultiLev::setNodeReduction(const DataArrayInt *nr) _node_reduction=const_cast(nr); } +void MEDMeshMultiLev::setCellReduction(const DataArrayInt *cr) +{ + if(_pfls.size()!=1) + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::setCellReduction : can be used only for single geo type mesh !"); + _pfls[0]=const_cast(cr); + if(cr) + cr->incrRef(); +} + bool MEDMeshMultiLev::isFastlyTheSameStruct(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs) const { if(fst.getType()==ON_NODES) @@ -438,7 +447,7 @@ int MEDMeshMultiLev::getNumberOfCells(INTERP_KERNEL::NormalizedCellType t) const std::size_t sz(_nb_entities.size()); for(std::size_t i=0;ideepCpy(); if(pflName.empty() && nr) - throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 2 !"); + throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 2 !"); if(!pflName.empty() && nr) { MEDCouplingAutoRefCountObjectPtr p1(globs->getProfile(pflName.c_str())->deepCpy()); @@ -852,44 +861,44 @@ MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vectorisAllocated()) - return ; - std::size_t sz(_parts.size()); - std::vector< MEDCouplingAutoRefCountObjectPtr > a(sz); - std::vector< const DataArrayInt *> aa(sz); - for(std::size_t i=0;i m(_parts[i]); - if(pfl) - m=dynamic_cast(_parts[i]->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); - DataArrayInt *cellIds=0; - m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds); - MEDCouplingAutoRefCountObjectPtr cellIdsSafe(cellIds); - MEDCouplingAutoRefCountObjectPtr m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end())); - int tmp=-1; - MEDCouplingAutoRefCountObjectPtr o2n(m2->getNodeIdsInUse(tmp)); - a[i]=o2n->invertArrayO2N2N2O(tmp); aa[i]=a[i]; - if(pfl) - _pfls[i]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end()); - else - _pfls[i]=cellIdsSafe; - } - if(!aa.empty()) - _node_reduction=DataArrayInt::Aggregate(aa);//general case - else - _node_reduction=pflNodes->deepCpy();//case where no cells in read mesh. - _node_reduction->sort(true); - _node_reduction=_node_reduction->buildUnique(); - if(_node_reduction->getNumberOfTuples()==pflNodes->getNumberOfTuples()) - return ;//This is the classical case where the input node profile corresponds perfectly to a subset of cells in _parts - if(_node_reduction->getNumberOfTuples()>pflNodes->getNumberOfTuples()) - throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::selectPartOfNodes : internal error in MEDCoupling during cell select from a list of nodes !"); - // Here the cells available in _parts is not enough to cover all the nodes in pflNodes. So adding vertices cells in _parts... - MEDCouplingAutoRefCountObjectPtr pflNodes2(pflNodes->deepCpy()); - pflNodes2->sort(true); - MEDCouplingAutoRefCountObjectPtr diff(pflNodes2->buildSubstractionOptimized(_node_reduction)); - appendVertices(diff,pflNodes2); + if(!pflNodes || !pflNodes->isAllocated()) + return ; + std::size_t sz(_parts.size()); + std::vector< MEDCouplingAutoRefCountObjectPtr > a(sz); + std::vector< const DataArrayInt *> aa(sz); + for(std::size_t i=0;i m(_parts[i]); + if(pfl) + m=dynamic_cast(_parts[i]->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); + DataArrayInt *cellIds=0; + m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds); + MEDCouplingAutoRefCountObjectPtr cellIdsSafe(cellIds); + MEDCouplingAutoRefCountObjectPtr m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end())); + int tmp=-1; + MEDCouplingAutoRefCountObjectPtr o2n(m2->getNodeIdsInUse(tmp)); + a[i]=o2n->invertArrayO2N2N2O(tmp); aa[i]=a[i]; + if(pfl) + _pfls[i]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end()); + else + _pfls[i]=cellIdsSafe; + } + if(!aa.empty()) + _node_reduction=DataArrayInt::Aggregate(aa);//general case + else + _node_reduction=pflNodes->deepCpy();//case where no cells in read mesh. + _node_reduction->sort(true); + _node_reduction=_node_reduction->buildUnique(); + if(_node_reduction->getNumberOfTuples()==pflNodes->getNumberOfTuples()) + return ;//This is the classical case where the input node profile corresponds perfectly to a subset of cells in _parts + if(_node_reduction->getNumberOfTuples()>pflNodes->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::selectPartOfNodes : internal error in MEDCoupling during cell select from a list of nodes !"); + // Here the cells available in _parts is not enough to cover all the nodes in pflNodes. So adding vertices cells in _parts... + MEDCouplingAutoRefCountObjectPtr pflNodes2(pflNodes->deepCpy()); + pflNodes2->sort(true); + MEDCouplingAutoRefCountObjectPtr diff(pflNodes2->buildSubstractionOptimized(_node_reduction)); + appendVertices(diff,pflNodes2); } MEDMeshMultiLev *MEDUMeshMultiLev::prepare() const @@ -911,6 +920,7 @@ MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const } /*! + * To be called only once ! Because due to some optimizations (sometimes aggressive) the internal state can be changed... * If returned value is false output pointer \a coords is not the internal pointer. If returned value is true output pointer \a coords is directly the internal pointer. * If true is returned, the \a coords output parameter should be used with care (non const method call) to avoid to change the internal state of MEDFileUMesh instance. */ @@ -1018,7 +1028,7 @@ bool MEDUMeshMultiLev::buildVTUArrays(DataArrayDouble *& coords, DataArrayByte * { *dPtr++=connIPtr[1]-connIPtr[0]; dPtr=std::copy(connPtr+connIPtr[0],connPtr+connIPtr[1],dPtr); - *cPtr++=k; k+=connIPtr[1]-connIPtr[0]; + *cPtr++=k; k+=connIPtr[1]-connIPtr[0]+1; } } else @@ -1068,7 +1078,7 @@ bool MEDUMeshMultiLev::buildVTUArrays(DataArrayDouble *& coords, DataArrayByte * { faceLocations=0; faces=0; } else { faceLocations=e.retn(); faces=f.retn(); } - return tmp==((DataArrayDouble *)a); + return _mesh->isObjectInTheProgeny(coords); } void MEDUMeshMultiLev::reorderNodesIfNecessary(MEDCouplingAutoRefCountObjectPtr& coords, DataArrayInt *nodalConnVTK, DataArrayInt *polyhedNodalConnVTK) const @@ -1172,11 +1182,21 @@ void MEDUMeshMultiLev::appendVertices(const DataArrayInt *verticesToAdd, DataArr //= -MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m):MEDMeshMultiLev(m),_is_internal(true) +MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, const std::vector& lev):MEDMeshMultiLev(m),_is_internal(true) +{ + initStdFieldOfIntegers(m); +} + +MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, int nbOfNodes, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities):MEDMeshMultiLev(m,nbOfNodes,gts,pfls,nbEntities),_is_internal(true) { + initStdFieldOfIntegers(m); } -MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, const std::vector& lev):MEDMeshMultiLev(m),_is_internal(true) +MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other):MEDMeshMultiLev(other),_is_internal(true),_face_fam_ids(other._face_fam_ids),_face_fam_ids_nocpy(other._face_fam_ids_nocpy),_face_num_ids(other._face_num_ids),_face_num_ids_nocpy(other._face_num_ids_nocpy) +{ +} + +void MEDStructuredMeshMultiLev::initStdFieldOfIntegers(const MEDFileStructuredMesh *m) { // ids fields management _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true; @@ -1208,44 +1228,28 @@ MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh tmp->incrRef(); _node_num_ids=const_cast(tmp); } -} - -MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, int nbOfNodes, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities):MEDMeshMultiLev(m,nbOfNodes,gts,pfls,nbEntities),_is_internal(true) -{ - // ids fields management - _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true; - const DataArrayInt *tmp(0); - tmp=m->getFamilyFieldAtLevel(0); - if(tmp) - { - tmp->incrRef(); - _cell_fam_ids=const_cast(tmp); - } - tmp=m->getNumberFieldAtLevel(0); - if(tmp) - { - tmp->incrRef(); - _cell_num_ids=const_cast(tmp); - } - // - _node_fam_ids_nocpy=true; _node_num_ids_nocpy=true; - tmp=0; - tmp=m->getFamilyFieldAtLevel(1); + // faces (if any) + _face_fam_ids_nocpy=true; _face_num_ids_nocpy=true; + tmp=m->getFamilyFieldAtLevel(-1); if(tmp) { tmp->incrRef(); - _node_fam_ids=const_cast(tmp); + _face_fam_ids=const_cast(tmp); } - tmp=m->getNumberFieldAtLevel(1); + tmp=m->getNumberFieldAtLevel(-1); if(tmp) { tmp->incrRef(); - _node_num_ids=const_cast(tmp); + _face_num_ids=const_cast(tmp); } } -MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other):MEDMeshMultiLev(other),_is_internal(true) +void MEDStructuredMeshMultiLev::moveFaceToCell() const { + const_cast(this)->_cell_fam_ids_nocpy=_face_fam_ids_nocpy; + const_cast(this)->_cell_num_ids_nocpy=_face_num_ids_nocpy; + const_cast(this)->_cell_fam_ids=_face_fam_ids; const_cast(this)->_face_fam_ids=0; + const_cast(this)->_cell_num_ids=_face_num_ids; const_cast(this)->_face_num_ids=0; } bool MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase(MEDMeshMultiLev *&ret) const @@ -1257,7 +1261,7 @@ bool MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase(MEDMeshMu throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase only one geo types supported at most supported for the moment !"); INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(_mesh->getMeshDimension())); if(_geo_types[0]==gt) - return false; + return false; MEDCoupling1GTUMesh *facesIfPresent((static_cast(_mesh))->getImplicitFaceMesh()); if(!facesIfPresent) return false; @@ -1265,9 +1269,10 @@ bool MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase(MEDMeshMu if(!_pfls.empty()) pfl=_pfls[0]; MEDCouplingAutoRefCountObjectPtr facesIfPresent2(facesIfPresent); facesIfPresent->incrRef(); + moveFaceToCell(); MEDCouplingAutoRefCountObjectPtr ret2(new MEDUMeshMultiLev(*this,facesIfPresent2)); if(pfl) - throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase : case is not treated yet for profile on implicit unstructured mesh."); + ret2->setCellReduction(pfl); if(nr) throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase : case is not treated yet for node reduction on implicit unstructured mesh."); ret=ret2.retn(); @@ -1436,7 +1441,7 @@ MEDMeshMultiLev *MEDCMeshMultiLev::prepare() const ret2->setNumberIdsOnCells(tmp,false); } return ret2.retn(); - + } else { @@ -1707,7 +1712,7 @@ bool MEDFileField1TSStructItem2::isFastlyEqual(int& startExp, INTERP_KERNEL::Nor return true; } -bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& other) const throw(INTERP_KERNEL::Exception) +bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& other) const { //_nb_of_entity is not taken into account here. It is not a bug, because no mesh consideration needed here to perform fast compare. //idem for _loc. It is not an effective attribute for support comparison. @@ -1807,7 +1812,7 @@ MEDFileField1TSStructItem::MEDFileField1TSStructItem(TypeOfField a, const std::v void MEDFileField1TSStructItem::checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) { switch(_type) - { + { case ON_NODES: { int nbOfEnt=mst->getNumberOfNodes(); @@ -1836,10 +1841,10 @@ void MEDFileField1TSStructItem::checkWithMeshStruct(const MEDFileMeshStruct *mst } default: throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : not managed field type !"); - } + } } -bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) const throw(INTERP_KERNEL::Exception) +bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) const { if(_type!=other._type) return false; @@ -1992,7 +1997,7 @@ bool MEDFileField1TSStructItem::isFullyOnOneLev(const MEDFileMeshStruct *meshSt, return false; } -const MEDFileField1TSStructItem2& MEDFileField1TSStructItem::operator[](std::size_t i) const throw(INTERP_KERNEL::Exception) +const MEDFileField1TSStructItem2& MEDFileField1TSStructItem::operator[](std::size_t i) const { if(i>=_items.size()) throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::operator[] : input is not in valid range !");