From: karadaniz Date: Tue, 28 May 2024 15:50:58 +0000 (+0200) Subject: Fix spns #42137 Wrong mesh format writing: X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fspns_42137_fix_mesh_format_writing;p=tools%2Fmedcoupling.git Fix spns #42137 Wrong mesh format writing: - elements numbering : for a given element type: take into account the presence of elements of other types - variables counting for elements by type needed else where in the code are transformed into attributes Picked from branch spns_40523_family_cells, look at spns #40523 and new --- diff --git a/src/MEDLoader/MeshFormatReader.cxx b/src/MEDLoader/MeshFormatReader.cxx index 83eb4232e..773c6ac12 100644 --- a/src/MEDLoader/MeshFormatReader.cxx +++ b/src/MEDLoader/MeshFormatReader.cxx @@ -98,18 +98,17 @@ MeshFormat::Status MeshFormatReader::perform() MEDCoupling::DataArrayDouble* coordArray = MEDCoupling::DataArrayDouble::New(); setNodes(coordArray); - int nbEdges = _reader.GmfStatKwd(_myCurrentFileId, MeshFormat::GmfEdges); - int nbTria = _reader.GmfStatKwd(_myCurrentFileId, MeshFormat::GmfTriangles); int nbQuad = _reader.GmfStatKwd(_myCurrentFileId, MeshFormat::GmfQuadrilaterals); - int nbTet = _reader.GmfStatKwd( _myCurrentFileId, MeshFormat::GmfTetrahedra ); - int nbPyr = _reader.GmfStatKwd(_myCurrentFileId, MeshFormat::GmfPyramids); - int nbHex = _reader.GmfStatKwd(_myCurrentFileId, MeshFormat::GmfHexahedra); int nbPrism = _reader.GmfStatKwd(_myCurrentFileId, MeshFormat::GmfPrisms); - + _nbTria = _reader.GmfStatKwd(_myCurrentFileId, MeshFormat::GmfTriangles); + _nbTet = _reader.GmfStatKwd( _myCurrentFileId, MeshFormat::GmfTetrahedra ); + _nbPyr = _reader.GmfStatKwd(_myCurrentFileId, MeshFormat::GmfPyramids); + _nbHex = _reader.GmfStatKwd(_myCurrentFileId, MeshFormat::GmfHexahedra); + _dim1NbEl = nbEdges; - _dim2NbEl = nbTria + nbQuad; - _dim3NbEl = nbTet + nbPyr + nbHex + nbPrism; + _dim2NbEl = _nbTria + nbQuad; + _dim3NbEl = _nbTet + _nbPyr + _nbHex + nbPrism; bool okdim1 = (nbEdges > 0), okdim2= (_dim2NbEl > 0), okdim3= (_dim3NbEl > 0); MEDCoupling::MEDCouplingUMesh* dimMesh1; @@ -151,11 +150,13 @@ MeshFormat::Status MeshFormatReader::perform() } /* Read triangles */ - if (nbTria) + + if (_nbTria) { - setTriangles(dimMesh2, nbTria); + setTriangles(dimMesh2); } + /* Read quadrangles */ if (nbQuad) { @@ -169,21 +170,21 @@ MeshFormat::Status MeshFormatReader::perform() dimMesh2->decrRef(); } /* Read terahedra */ - if ( nbTet ) + if ( _nbTet ) { - setTetrahedras( dimMesh3, nbTet); + setTetrahedras( dimMesh3); } /* Read pyramids */ - if ( nbPyr ) + if ( _nbPyr ) { - setPyramids( dimMesh3, nbPyr); + setPyramids( dimMesh3); } /* Read hexahedra */ - if ( nbHex ) + if ( _nbHex ) { - setHexahedras(dimMesh3, nbHex); + setHexahedras(dimMesh3); } /* Read prism */ @@ -515,12 +516,12 @@ void MeshFormatReader::setEdges( MEDCoupling::MEDCouplingUMesh* dimMesh1, int nb _uMesh->setMeshAtLevel( 1 - _dim, dimMesh1 ); } -void MeshFormatReader::setTriangles(MEDCoupling::MEDCouplingUMesh* dimMesh2, int nbTria) +void MeshFormatReader::setTriangles(MEDCoupling::MEDCouplingUMesh* dimMesh2) { int iN[28]; // 28 - nb nodes in HEX27 (+ 1 for safety :) int ref; // read extra vertices for quadratic triangles - std::vector< std::vector > quadNodesAtTriangles( nbTria + 1 ); + std::vector< std::vector > quadNodesAtTriangles( _nbTria + 1 ); if ( int nbQuadTria = _reader.GmfStatKwd(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtTriangles )) { _reader.GmfGotoKwd( _myCurrentFileId, MeshFormat::GmfExtraVerticesAtTriangles ); @@ -529,7 +530,7 @@ void MeshFormatReader::setTriangles(MEDCoupling::MEDCouplingUMesh* dimMesh2, int _reader.GmfGetLin(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtTriangles, &iN[0], &iN[1], &iN[2], &iN[3], &iN[4], &iN[5]); // iN[5] - preview TRIA7 - if ( iN[0] <= nbTria ) + if ( iN[0] <= _nbTria ) { std::vector& nodes = quadNodesAtTriangles[ iN[0] ]; nodes.insert( nodes.end(), & iN[2], & iN[5+1] ); @@ -537,12 +538,11 @@ void MeshFormatReader::setTriangles(MEDCoupling::MEDCouplingUMesh* dimMesh2, int } } } - // create triangles _reader.GmfGotoKwd(_myCurrentFileId, MeshFormat::GmfTriangles); - for ( int i = 1; i <= nbTria; ++i ) + for ( int i = 1; i <= _nbTria; ++i ) { _reader.GmfGetLin(_myCurrentFileId, MeshFormat::GmfTriangles, &iN[0], &iN[1], &iN[2], &ref); std::vector& midN = quadNodesAtTriangles[ i ]; @@ -566,7 +566,6 @@ void MeshFormatReader::setTriangles(MEDCoupling::MEDCouplingUMesh* dimMesh2, int if ( !midN.empty() ) MeshFormat::FreeVector( midN ); } - } void MeshFormatReader::setQuadrangles( MEDCoupling::MEDCouplingUMesh* dimMesh2, int nbQuad) @@ -592,7 +591,7 @@ void MeshFormatReader::setQuadrangles( MEDCoupling::MEDCouplingUMesh* dimMesh2, } // create quadrangles _reader.GmfGotoKwd(_myCurrentFileId, MeshFormat::GmfQuadrilaterals); - for ( int i = 1; i <= nbQuad; ++i ) + for ( int i = 1 ; i <= nbQuad; ++i ) { _reader.GmfGetLin(_myCurrentFileId, MeshFormat::GmfQuadrilaterals, &iN[0], &iN[1], &iN[2], &iN[3], &ref); std::vector& midN = quadNodesAtQuadrilaterals[ i ]; @@ -603,7 +602,7 @@ void MeshFormatReader::setQuadrangles( MEDCoupling::MEDCouplingUMesh* dimMesh2, }; backward_shift(nodalConnPerCell, 8); dimMesh2->insertNextCell(INTERP_KERNEL::NORM_QUAD8,8, nodalConnPerCell); - MeshFormatElement e(MeshFormat::GmfQuadrilaterals, i-1); + MeshFormatElement e(MeshFormat::GmfQuadrilaterals, i-1+_nbTria); _fams.insert(std::pair (ref, e), 2 -_dim); } else if ( midN.size() > 8-4 ) // QUAD9 @@ -613,7 +612,7 @@ void MeshFormatReader::setQuadrangles( MEDCoupling::MEDCouplingUMesh* dimMesh2, }; backward_shift(nodalConnPerCell, 9); dimMesh2->insertNextCell(INTERP_KERNEL::NORM_QUAD9,9, nodalConnPerCell); - MeshFormatElement e(MeshFormat::GmfQuadrilaterals, i-1); + MeshFormatElement e(MeshFormat::GmfQuadrilaterals, i-1+_nbTria); _fams.insert(std::pair (ref, e), 2 -_dim); } else // QUAD4 @@ -621,7 +620,7 @@ void MeshFormatReader::setQuadrangles( MEDCoupling::MEDCouplingUMesh* dimMesh2, mcIdType nodalConnPerCell[4] = {iN[0], iN[1], iN[2], iN[3]}; backward_shift(nodalConnPerCell, 4); dimMesh2->insertNextCell(INTERP_KERNEL::NORM_QUAD4, 4, nodalConnPerCell); - MeshFormatElement e(MeshFormat::GmfQuadrilaterals, i-1); + MeshFormatElement e(MeshFormat::GmfQuadrilaterals, i-1+_nbTria); _fams.insert(std::pair (ref, e), 2 -_dim); } if ( !midN.empty() ) MeshFormat::FreeVector( midN ); @@ -629,12 +628,12 @@ void MeshFormatReader::setQuadrangles( MEDCoupling::MEDCouplingUMesh* dimMesh2, } -void MeshFormatReader::setTetrahedras( MEDCoupling::MEDCouplingUMesh* dimMesh3, int nbTet) +void MeshFormatReader::setTetrahedras( MEDCoupling::MEDCouplingUMesh* dimMesh3) { int iN[28]; // 28 - nb nodes in HEX27 (+ 1 for safety :) int ref; // read extra vertices for quadratic tetrahedra - std::vector< std::vector > quadNodesAtTetrahedra( nbTet + 1 ); + std::vector< std::vector > quadNodesAtTetrahedra( _nbTet + 1 ); if ( int nbQuadTetra = _reader.GmfStatKwd( _myCurrentFileId, MeshFormat::GmfExtraVerticesAtTetrahedra )) { _reader.GmfGotoKwd(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtTetrahedra); @@ -642,7 +641,7 @@ void MeshFormatReader::setTetrahedras( MEDCoupling::MEDCouplingUMesh* dimMesh3, { _reader.GmfGetLin(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtTetrahedra, &iN[0], &iN[1], &iN[2], &iN[3], &iN[4], &iN[5], &iN[6], &iN[7]); - if ( iN[0] <= nbTet ) + if ( iN[0] <= _nbTet ) { std::vector& nodes = quadNodesAtTetrahedra[ iN[0] ]; nodes.insert( nodes.end(), & iN[2], & iN[7+1] ); @@ -652,7 +651,7 @@ void MeshFormatReader::setTetrahedras( MEDCoupling::MEDCouplingUMesh* dimMesh3, } // create tetrahedra _reader.GmfGotoKwd(_myCurrentFileId, MeshFormat::GmfTetrahedra); - for ( int i = 1; i <= nbTet; ++i ) + for ( int i = 1; i <= _nbTet; ++i ) { _reader.GmfGetLin(_myCurrentFileId, MeshFormat::GmfTetrahedra, &iN[0], &iN[1], &iN[2], &iN[3], &ref); std::vector& midN = quadNodesAtTetrahedra[ i ]; @@ -680,30 +679,30 @@ void MeshFormatReader::setTetrahedras( MEDCoupling::MEDCouplingUMesh* dimMesh3, } -void MeshFormatReader::setPyramids( MEDCoupling::MEDCouplingUMesh* dimMesh3, int nbPyr) +void MeshFormatReader::setPyramids( MEDCoupling::MEDCouplingUMesh* dimMesh3) { int iN[28]; // 28 - nb nodes in HEX27 (+ 1 for safety :) int ref; _reader.GmfGotoKwd(_myCurrentFileId, MeshFormat::GmfPyramids); - for ( int i = 1; i <= nbPyr; ++i ) + for ( int i = 1; i <= _nbPyr; ++i ) { _reader.GmfGetLin(_myCurrentFileId, MeshFormat::GmfPyramids, &iN[0], &iN[1], &iN[2], &iN[3], &iN[4], &ref); mcIdType nodalConnPerCell[5] = {iN[3], iN[2], iN[1], iN[0], iN[4]}; backward_shift(nodalConnPerCell, 5); dimMesh3->insertNextCell(INTERP_KERNEL::NORM_PYRA5, 5,nodalConnPerCell); - MeshFormatElement e(MeshFormat::GmfPyramids, i-1); + MeshFormatElement e(MeshFormat::GmfPyramids, i-1+_nbTet); _fams.insert(std::pair (ref, e), 3 -_dim); } } -void MeshFormatReader::setHexahedras( MEDCoupling::MEDCouplingUMesh* dimMesh3, int nbHex) +void MeshFormatReader::setHexahedras( MEDCoupling::MEDCouplingUMesh* dimMesh3) { int iN[28]; // 28 - nb nodes in HEX27 (+ 1 for safety :) int ref; // read extra vertices for quadratic hexahedra - std::vector< std::vector > quadNodesAtHexahedra( nbHex + 1 ); + std::vector< std::vector > quadNodesAtHexahedra( _nbHex + 1 ); if ( int nbQuadHexa = _reader.GmfStatKwd( _myCurrentFileId, MeshFormat::GmfExtraVerticesAtHexahedra )) { _reader.GmfGotoKwd(_myCurrentFileId, MeshFormat::GmfExtraVerticesAtHexahedra); @@ -717,7 +716,7 @@ void MeshFormatReader::setHexahedras( MEDCoupling::MEDCouplingUMesh* dimMesh3, i &iN[15], &iN[16], &iN[17], &iN[18], &iN[19], &iN[20]); // HEXA27 - if ( iN[0] <= nbHex ) + if ( iN[0] <= _nbHex ) { std::vector& nodes = quadNodesAtHexahedra[ iN[0] ]; nodes.insert( nodes.end(), & iN[2], & iN[20+1] ); @@ -727,9 +726,8 @@ void MeshFormatReader::setHexahedras( MEDCoupling::MEDCouplingUMesh* dimMesh3, i } // create hexhedra - _reader.GmfGotoKwd(_myCurrentFileId, MeshFormat::GmfHexahedra); - for ( int i = 1; i <= nbHex; ++i ) + for ( int i = 1; i <= _nbHex; ++i ) { _reader.GmfGetLin(_myCurrentFileId, MeshFormat::GmfHexahedra, &iN[0], &iN[1], &iN[2], &iN[3], &iN[4], &iN[5], &iN[6], &iN[7], &ref); @@ -744,7 +742,7 @@ void MeshFormatReader::setHexahedras( MEDCoupling::MEDCouplingUMesh* dimMesh3, i }; backward_shift(nodalConnPerCell, 20); dimMesh3->insertNextCell(INTERP_KERNEL::NORM_HEXA20,20, nodalConnPerCell); - MeshFormatElement e(MeshFormat::GmfHexahedra, i-1); + MeshFormatElement e(MeshFormat::GmfHexahedra, i-1+_nbTet+_nbPyr); _fams.insert(std::pair (ref, e), 3 -_dim); @@ -763,7 +761,7 @@ void MeshFormatReader::setHexahedras( MEDCoupling::MEDCouplingUMesh* dimMesh3, i }; backward_shift(nodalConnPerCell, 27); dimMesh3->insertNextCell(INTERP_KERNEL::NORM_HEXA27,27, nodalConnPerCell); - MeshFormatElement e(MeshFormat::GmfHexahedra, i-1); + MeshFormatElement e(MeshFormat::GmfHexahedra, i-1+_nbTet+_nbPyr); _fams.insert(std::pair (ref, e), 3 -_dim); } @@ -774,7 +772,7 @@ void MeshFormatReader::setHexahedras( MEDCoupling::MEDCouplingUMesh* dimMesh3, i }; backward_shift(nodalConnPerCell, 8); dimMesh3->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8, nodalConnPerCell); - MeshFormatElement e(MeshFormat::GmfHexahedra, i-1); + MeshFormatElement e(MeshFormat::GmfHexahedra, i-1+_nbTet+_nbPyr); _fams.insert(std::pair (ref, e), 3 -_dim); } @@ -797,7 +795,7 @@ void MeshFormatReader::setPrisms(MEDCoupling::MEDCouplingUMesh* dimMesh3, int nb mcIdType nodalConnPerCell[8] = {iN[0], iN[2], iN[1], iN[3], iN[5], iN[4]}; backward_shift(nodalConnPerCell, 8); dimMesh3->insertNextCell(INTERP_KERNEL::NORM_PENTA6, 6,nodalConnPerCell); - MeshFormatElement e(MeshFormat::GmfPrisms, i-1); + MeshFormatElement e(MeshFormat::GmfPrisms, i-1+_nbTet+_nbPyr+_nbHex); _fams.insert(std::pair (ref, e), 3 -_dim); } diff --git a/src/MEDLoader/MeshFormatReader.hxx b/src/MEDLoader/MeshFormatReader.hxx index d87929d6b..70ffaea88 100644 --- a/src/MEDLoader/MeshFormatReader.hxx +++ b/src/MEDLoader/MeshFormatReader.hxx @@ -187,11 +187,11 @@ namespace MEDCoupling MeshFormat::Status performFields(); MeshFormat::Status setNodes(MEDCoupling::DataArrayDouble *coordArray); void setEdges(MEDCoupling::MEDCouplingUMesh *dimMesh1, int nbEdges); - void setTriangles(MEDCoupling::MEDCouplingUMesh *dimMesh2, int nbTria); + void setTriangles(MEDCoupling::MEDCouplingUMesh *dimMesh2); void setQuadrangles(MEDCoupling::MEDCouplingUMesh *dimMesh2, int nbQuad); - void setTetrahedras(MEDCoupling::MEDCouplingUMesh *dimMesh3, int nbTet); - void setPyramids(MEDCoupling::MEDCouplingUMesh *dimMesh3, int nbPyr); - void setHexahedras(MEDCoupling::MEDCouplingUMesh *dimMesh3, int nbHex); + void setTetrahedras(MEDCoupling::MEDCouplingUMesh *dimMesh3); + void setPyramids(MEDCoupling::MEDCouplingUMesh *dimMesh3); + void setHexahedras(MEDCoupling::MEDCouplingUMesh *dimMesh3); void setPrisms(MEDCoupling::MEDCouplingUMesh *dimMesh3, int nbPrism); void callParserGetLin(MeshFormat::GmfKwdCod kwd, double *val, int valSize, int *ref); void setTypeOfFieldAndDimRel(MeshFormat::GmfKwdCod kwd, MEDCoupling::TypeOfField *typeOfField, int *dimRel); @@ -220,6 +220,10 @@ namespace MEDCoupling int _dim1NbEl; int _dim2NbEl; int _dim3NbEl; + int _nbTria; + int _nbTet; + int _nbPyr; + int _nbHex; }; } // namespace MEDCoupling #endif //MESHFORMATREADER_HXX