X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FSauvMedConvertor.cxx;h=28a54e390f0a7d210e5ae38f8f54e529fdf3e63e;hb=82884d74d2c60f07617849cb6c01511a475f8b2c;hp=8578ffb7a8e755379cfcc4a8b41f6942aa15b988;hpb=2604897932a567b755d2071e164870fba0ace02d;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/SauvMedConvertor.cxx b/src/MEDLoader/SauvMedConvertor.cxx index 8578ffb7a..28a54e390 100644 --- a/src/MEDLoader/SauvMedConvertor.cxx +++ b/src/MEDLoader/SauvMedConvertor.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D +// Copyright (C) 2007-2015 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 // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -2302,6 +2302,74 @@ void IntermediateMED::checkDataAvailability() const THROW_IK_EXCEPTION("Nodes and coordinates mismatch"); } +//================================================================================ +/*! + * \brief Safely adds a new Group + */ +//================================================================================ + +Group* IntermediateMED::addNewGroup(std::vector* groupsToFix) +{ + if ( _groups.size() == _groups.capacity() ) // re-allocation would occure + { + std::vector newGroups( _groups.size() ); + newGroups.push_back( Group() ); + + for ( size_t i = 0; i < _groups.size(); ++i ) + { + // avoid copying _cells + std::vector cells; + cells.swap( _groups[i]._cells ); + newGroups[i] = _groups[i]; + newGroups[i]._cells.swap( cells ); + + // correct pointers to sub-groups + for ( size_t j = 0; j < _groups[i]._groups.size(); ++j ) + { + int iG = _groups[i]._groups[j] - &_groups[0]; + newGroups[i]._groups[j] = & newGroups[ iG ]; + } + } + + // fix given groups + if ( groupsToFix ) + for ( size_t i = 0; i < groupsToFix->size(); ++i ) + if ( (*groupsToFix)[i] ) + { + int iG = (*groupsToFix)[i] - &_groups[0]; + (*groupsToFix)[i] = & newGroups[ iG ]; + } + + // fix field supports + for ( int isNode = 0; isNode < 2; ++isNode ) + { + std::vector& fields = isNode ? _nodeFields : _cellFields; + for ( size_t i = 0; i < fields.size(); ++i ) + { + if ( !fields[i] ) continue; + for ( size_t j = 0; j < fields[i]->_sub.size(); ++j ) + if ( fields[i]->_sub[j]._support ) + { + int iG = fields[i]->_sub[j]._support - &_groups[0]; + fields[i]->_sub[j]._support = & newGroups[ iG ]; + } + if ( fields[i]->_group ) + { + int iG = fields[i]->_group - &_groups[0]; + fields[i]->_group = & newGroups[ iG ]; + } + } + } + + _groups.swap( newGroups ); + } + else + { + _groups.push_back( Group() ); + } + return &_groups.back(); +} + //================================================================================ /*! * \brief Makes ParaMEDMEM::MEDFileData from self @@ -2615,42 +2683,43 @@ void IntermediateMED::orientElements2D() // -------------------------- // orient faces clockwise // -------------------------- - int iQuad = isQuadratic ? 2 : 1; - for ( elemIt = faces->begin(), elemEnd = faces->end(); elemIt != elemEnd; elemIt++ ) - { - // look for index of the most left node - int iLeft = 0, iNode, nbNodes = elemIt->_nodes.size() / iQuad; - double x, minX = nodeCoords( elemIt->_nodes[0] )[0]; - for ( iNode = 1; iNode < nbNodes; ++iNode ) - if (( x = nodeCoords( elemIt->_nodes[ iNode ])[ 0 ]) < minX ) - minX = x, iLeft = iNode; - - // indeces of the nodes neighboring the most left one - int iPrev = ( iLeft - 1 < 0 ) ? nbNodes - 1 : iLeft - 1; - int iNext = ( iLeft + 1 == nbNodes ) ? 0 : iLeft + 1; - // find components of prev-left and left-next vectors - double xP = nodeCoords( elemIt->_nodes[ iPrev ])[ 0 ]; - double yP = nodeCoords( elemIt->_nodes[ iPrev ])[ 1 ]; - double xN = nodeCoords( elemIt->_nodes[ iNext ])[ 0 ]; - double yN = nodeCoords( elemIt->_nodes[ iNext ])[ 1 ]; - double xL = nodeCoords( elemIt->_nodes[ iLeft ])[ 0 ]; - double yL = nodeCoords( elemIt->_nodes[ iLeft ])[ 1 ]; - double xPL = xL - xP, yPL = yL - yP; // components of prev-left vector - double xLN = xN - xL, yLN = yN - yL; // components of left-next vector - // normalise y of the vectors - double modPL = sqrt ( xPL * xPL + yPL * yPL ); - double modLN = sqrt ( xLN * xLN + yLN * yLN ); - if ( modLN > std::numeric_limits::min() && - modPL > std::numeric_limits::min() ) - { - yPL /= modPL; - yLN /= modLN; - // summary direction of neighboring links must be positive - bool clockwise = ( yPL + yLN > 0 ); - if ( !clockwise ) - reverse( *elemIt, swapVec ); - } - } + // COMMENTED for issue 0022612 note 17739 + // int iQuad = isQuadratic ? 2 : 1; + // for ( elemIt = faces->begin(), elemEnd = faces->end(); elemIt != elemEnd; elemIt++ ) + // { + // // look for index of the most left node + // int iLeft = 0, iNode, nbNodes = elemIt->_nodes.size() / iQuad; + // double x, minX = nodeCoords( elemIt->_nodes[0] )[0]; + // for ( iNode = 1; iNode < nbNodes; ++iNode ) + // if (( x = nodeCoords( elemIt->_nodes[ iNode ])[ 0 ]) < minX ) + // minX = x, iLeft = iNode; + + // // indeces of the nodes neighboring the most left one + // int iPrev = ( iLeft - 1 < 0 ) ? nbNodes - 1 : iLeft - 1; + // int iNext = ( iLeft + 1 == nbNodes ) ? 0 : iLeft + 1; + // // find components of prev-left and left-next vectors + // double xP = nodeCoords( elemIt->_nodes[ iPrev ])[ 0 ]; + // double yP = nodeCoords( elemIt->_nodes[ iPrev ])[ 1 ]; + // double xN = nodeCoords( elemIt->_nodes[ iNext ])[ 0 ]; + // double yN = nodeCoords( elemIt->_nodes[ iNext ])[ 1 ]; + // double xL = nodeCoords( elemIt->_nodes[ iLeft ])[ 0 ]; + // double yL = nodeCoords( elemIt->_nodes[ iLeft ])[ 1 ]; + // double xPL = xL - xP, yPL = yL - yP; // components of prev-left vector + // double xLN = xN - xL, yLN = yN - yL; // components of left-next vector + // // normalise y of the vectors + // double modPL = sqrt ( xPL * xPL + yPL * yPL ); + // double modLN = sqrt ( xLN * xLN + yLN * yLN ); + // if ( modLN > std::numeric_limits::min() && + // modPL > std::numeric_limits::min() ) + // { + // yPL /= modPL; + // yLN /= modLN; + // // summary direction of neighboring links must be positive + // bool clockwise = ( yPL + yLN > 0 ); + // if ( !clockwise ) + // reverse( *elemIt, swapVec ); + // } + // } } } @@ -2663,7 +2732,8 @@ void IntermediateMED::orientElements2D() void IntermediateMED::orientElements3D() { // set _reverse flags of faces - orientFaces3D(); + // COMMENTED for issue 0022612 note 17739 + //orientFaces3D(); // ----------------- // fix connectivity @@ -2695,7 +2765,8 @@ void IntermediateMED::orientElements3D() } } - orientVolumes(); + // COMMENTED for issue 0022612 note 17739 + //orientVolumes(); } //================================================================================ @@ -3170,10 +3241,10 @@ void IntermediateMED::setGroups( ParaMEDMEM::MEDFileUMesh* mesh ) grp._medGroup = DataArrayInt::New(); grp._medGroup->setName( grp._name.c_str() ); grp._medGroup->alloc( cell2order.size(), /*nbOfCompo=*/1 ); - int * idsPrt = grp._medGroup->getPointer(); + int * idsPtr = grp._medGroup->getPointer(); TCellToOrderMap::iterator cell2orderIt, cell2orderEnd = cell2order.end(); for ( cell2orderIt = cell2order.begin(); cell2orderIt != cell2orderEnd; ++cell2orderIt ) - *idsPrt++ = (*cell2orderIt).first->_number - 1; + *idsPtr++ = (*cell2orderIt).first->_number - 1; // try to set the mesh name if ( !isMeshNameSet && @@ -3217,16 +3288,17 @@ bool IntermediateMED::isOnAll( const Group* grp, int & dimRel ) const int dim = getDim( grp ); int nbElems = 0; - CellsByDimIterator dimCells( *this, dim ); - while ( const std::set * cells = dimCells.nextType() ) - nbElems += cells->size(); - - const bool onAll = ( nbElems == grp->size() ); - if ( dim == 0 ) - dimRel = 0; + { + nbElems = _nbNodes; + dimRel = 0; + } else { + CellsByDimIterator dimCells( *this, dim ); + while ( const std::set * cells = dimCells.nextType() ) + nbElems += cells->size(); + int meshDim = 3; for ( ; meshDim > 0; --meshDim ) { @@ -3236,6 +3308,8 @@ bool IntermediateMED::isOnAll( const Group* grp, int & dimRel ) const } dimRel = dim - meshDim; } + + bool onAll = ( nbElems == grp->size() ); return onAll; } @@ -3274,7 +3348,7 @@ void IntermediateMED::setFields( SauvUtilities::DoubleField* fld, ParaMEDMEM::MEDFileFields* medFields, ParaMEDMEM::MEDFileUMesh* mesh, const TID castemID, - std::set< std::string >& usedFieldNames) + std::set< std::string >& usedFieldNames) { bool sameNbGauss = true; if ( !fld || !fld->isMedCompatible( sameNbGauss )) return; @@ -3364,7 +3438,7 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField* fld, DataArrayDouble * coo = mesh->getCoords(); MEDCouplingAutoRefCountObjectPtr subCoo = coo->selectByTupleId(support->_medGroup->begin(), - support->_medGroup->end()); + support->_medGroup->end()); MEDCouplingAutoRefCountObjectPtr< MEDCouplingUMesh > nodeSubMesh = MEDCouplingUMesh::Build0DMeshFromCoords( subCoo ); timeStamp->setMesh( nodeSubMesh ); @@ -3386,8 +3460,9 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField* fld, // set gauss points if ( timeStamp->getTypeOfField() == ParaMEDMEM::ON_GAUSS_PT ) { - TGaussDef gaussDef( support->_cellType, fld->_sub[iSub].nbGauss() ); - timeStamp->setGaussLocalizationOnType( support->_cellType, + TGaussDef gaussDef( fld->_sub[iSub]._support->_cellType, + fld->_sub[iSub].nbGauss() ); + timeStamp->setGaussLocalizationOnType( fld->_sub[iSub]._support->_cellType, gaussDef.myRefCoords, gaussDef.myCoords, gaussDef.myWeights );