X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FMEDLoader%2FSauvMedConvertor.cxx;h=f1542f90cfdc51b2cd94096297575db31bc4b5e1;hb=f810b8691a25da097d91b87793ecbf121ab9ead8;hp=f9dd4f6d5188e7dc8ac28e26cec1b5952ce9ee8b;hpb=1123dccd6613b2e8abba35182759d5c4a11ecc8d;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/SauvMedConvertor.cxx b/src/MEDLoader/SauvMedConvertor.cxx index f9dd4f6d5..f1542f90c 100644 --- a/src/MEDLoader/SauvMedConvertor.cxx +++ b/src/MEDLoader/SauvMedConvertor.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 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 @@ -46,11 +46,12 @@ #endif #ifdef HAS_XDR +#include #include #endif using namespace SauvUtilities; -using namespace ParaMEDMEM; +using namespace MEDCoupling; namespace { @@ -209,7 +210,7 @@ namespace */ struct TCellByIDCompare { - bool operator () (const Cell* i1, const Cell* i2) + bool operator () (const Cell* i1, const Cell* i2) const { return i1->_number < i2->_number; } @@ -2372,17 +2373,17 @@ Group* IntermediateMED::addNewGroup(std::vector* groupsTo //================================================================================ /*! - * \brief Makes ParaMEDMEM::MEDFileData from self + * \brief Makes MEDCoupling::MEDFileData from self */ //================================================================================ -ParaMEDMEM::MEDFileData* IntermediateMED::convertInMEDFileDS() +MEDCoupling::MEDFileData* IntermediateMED::convertInMEDFileDS() { - MEDCouplingAutoRefCountObjectPtr< MEDFileUMesh > mesh = makeMEDFileMesh(); - MEDCouplingAutoRefCountObjectPtr< MEDFileFields > fields = makeMEDFileFields(mesh); + MCAuto< MEDFileUMesh > mesh = makeMEDFileMesh(); + MCAuto< MEDFileFields > fields = makeMEDFileFields(mesh); - MEDCouplingAutoRefCountObjectPtr< MEDFileMeshes > meshes = MEDFileMeshes::New(); - MEDCouplingAutoRefCountObjectPtr< MEDFileData > medData = MEDFileData::New(); + MCAuto< MEDFileMeshes > meshes = MEDFileMeshes::New(); + MCAuto< MEDFileData > medData = MEDFileData::New(); meshes->pushMesh( mesh ); medData->setMeshes( meshes ); if ( fields ) medData->setFields( fields ); @@ -2392,11 +2393,11 @@ ParaMEDMEM::MEDFileData* IntermediateMED::convertInMEDFileDS() //================================================================================ /*! - * \brief Creates ParaMEDMEM::MEDFileUMesh from its data + * \brief Creates MEDCoupling::MEDFileUMesh from its data */ //================================================================================ -ParaMEDMEM::MEDFileUMesh* IntermediateMED::makeMEDFileMesh() +MEDCoupling::MEDFileUMesh* IntermediateMED::makeMEDFileMesh() { // check if all needed piles are present checkDataAvailability(); @@ -2683,42 +2684,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 ); + // } + // } } } @@ -2731,7 +2733,8 @@ void IntermediateMED::orientElements2D() void IntermediateMED::orientElements3D() { // set _reverse flags of faces - orientFaces3D(); + // COMMENTED for issue 0022612 note 17739 + //orientFaces3D(); // ----------------- // fix connectivity @@ -2763,7 +2766,8 @@ void IntermediateMED::orientElements3D() } } - orientVolumes(); + // COMMENTED for issue 0022612 note 17739 + //orientVolumes(); } //================================================================================ @@ -3088,7 +3092,7 @@ void IntermediateMED::numberElements() */ //================================================================================ -ParaMEDMEM::DataArrayDouble * IntermediateMED::getCoords() +MEDCoupling::DataArrayDouble * IntermediateMED::getCoords() { DataArrayDouble* coordArray = DataArrayDouble::New(); coordArray->alloc( _nbNodes, _spaceDim ); @@ -3114,8 +3118,8 @@ ParaMEDMEM::DataArrayDouble * IntermediateMED::getCoords() */ //================================================================================ -void IntermediateMED::setConnectivity( ParaMEDMEM::MEDFileUMesh* mesh, - ParaMEDMEM::DataArrayDouble* coords ) +void IntermediateMED::setConnectivity( MEDCoupling::MEDFileUMesh* mesh, + MEDCoupling::DataArrayDouble* coords ) { int meshDim = 0; @@ -3180,7 +3184,7 @@ void IntermediateMED::setConnectivity( ParaMEDMEM::MEDFileUMesh* mesh, */ //================================================================================ -void IntermediateMED::setGroups( ParaMEDMEM::MEDFileUMesh* mesh ) +void IntermediateMED::setGroups( MEDCoupling::MEDFileUMesh* mesh ) { bool isMeshNameSet = false; const int meshDim = mesh->getMeshDimension(); @@ -3189,7 +3193,7 @@ void IntermediateMED::setGroups( ParaMEDMEM::MEDFileUMesh* mesh ) const int meshDimRelToMaxExt = ( dim == 0 ? 1 : dim - meshDim ); std::vector medGroups; - std::vector > refGroups; + std::vector > refGroups; for ( size_t i = 0; i < _groups.size(); ++i ) { Group& grp = _groups[i]; @@ -3238,10 +3242,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 && @@ -3262,10 +3266,13 @@ void IntermediateMED::setGroups( ParaMEDMEM::MEDFileUMesh* mesh ) // Issue 0021311. Use case: a gibi group has references (recorded in pile 1) // and several names (pile 27) refer (pile 10) to this group. // We create a copy of this group per each named reference + std::set uniqueNames; + uniqueNames.insert( grp._name ); for ( unsigned iRef = 0 ; iRef < grp._refNames.size(); ++iRef ) - if ( !grp._refNames[ iRef ].empty() ) + if ( !grp._refNames[ iRef ].empty() && + uniqueNames.insert( grp._refNames[ iRef ]).second ) // for name uniqueness (23155) { - refGroups.push_back( grp._medGroup->deepCpy() ); + refGroups.push_back( grp._medGroup->deepCopy() ); refGroups.back()->setName( grp._refNames[ iRef ].c_str() ); medGroups.push_back( refGroups.back() ); } @@ -3285,16 +3292,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 ) { @@ -3304,6 +3312,8 @@ bool IntermediateMED::isOnAll( const Group* grp, int & dimRel ) const } dimRel = dim - meshDim; } + + bool onAll = ( nbElems == grp->size() ); return onAll; } @@ -3313,7 +3323,7 @@ bool IntermediateMED::isOnAll( const Group* grp, int & dimRel ) const */ //================================================================================ -ParaMEDMEM::MEDFileFields * IntermediateMED::makeMEDFileFields(ParaMEDMEM::MEDFileUMesh* mesh) +MEDCoupling::MEDFileFields * IntermediateMED::makeMEDFileFields(MEDCoupling::MEDFileUMesh* mesh) { if ( _nodeFields.empty() && _cellFields.empty() ) return 0; @@ -3339,8 +3349,8 @@ ParaMEDMEM::MEDFileFields * IntermediateMED::makeMEDFileFields(ParaMEDMEM::MEDFi //================================================================================ void IntermediateMED::setFields( SauvUtilities::DoubleField* fld, - ParaMEDMEM::MEDFileFields* medFields, - ParaMEDMEM::MEDFileUMesh* mesh, + MEDCoupling::MEDFileFields* medFields, + MEDCoupling::MEDFileUMesh* mesh, const TID castemID, std::set< std::string >& usedFieldNames) { @@ -3399,9 +3409,9 @@ void IntermediateMED::setFields( SauvUtilities::DoubleField* fld, //================================================================================ void IntermediateMED::setTS( SauvUtilities::DoubleField* fld, - ParaMEDMEM::DataArrayDouble* values, - ParaMEDMEM::MEDFileFields* medFields, - ParaMEDMEM::MEDFileUMesh* mesh, + MEDCoupling::DataArrayDouble* values, + MEDCoupling::MEDFileFields* medFields, + MEDCoupling::MEDFileUMesh* mesh, const int iSub) { // treat a field support @@ -3423,25 +3433,25 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField* fld, // set the mesh if ( onAll ) { - MEDCouplingAutoRefCountObjectPtr + MCAuto < MEDCouplingUMesh > dimMesh = mesh->getMeshAtLevel( dimRel ); timeStamp->setMesh( dimMesh ); } - else if ( timeStamp->getTypeOfField() == ParaMEDMEM::ON_NODES ) + else if ( timeStamp->getTypeOfField() == MEDCoupling::ON_NODES ) { DataArrayDouble * coo = mesh->getCoords(); - MEDCouplingAutoRefCountObjectPtr + MCAuto subCoo = coo->selectByTupleId(support->_medGroup->begin(), - support->_medGroup->end()); - MEDCouplingAutoRefCountObjectPtr< MEDCouplingUMesh > nodeSubMesh = + support->_medGroup->end()); + MCAuto< MEDCouplingUMesh > nodeSubMesh = MEDCouplingUMesh::Build0DMeshFromCoords( subCoo ); timeStamp->setMesh( nodeSubMesh ); } else { - MEDCouplingAutoRefCountObjectPtr + MCAuto < MEDCouplingUMesh > dimMesh = mesh->getMeshAtLevel( dimRel ); - MEDCouplingAutoRefCountObjectPtr + MCAuto subMesh = dimMesh->buildPart(support->_medGroup->begin(), support->_medGroup->end()); timeStamp->setMesh( subMesh); @@ -3452,10 +3462,11 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField* fld, timeStamp->setArray( values ); values->decrRef(); // set gauss points - if ( timeStamp->getTypeOfField() == ParaMEDMEM::ON_GAUSS_PT ) + if ( timeStamp->getTypeOfField() == MEDCoupling::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 ); @@ -3474,7 +3485,7 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField* fld, timeStamp->setOrder( nbTS ); // add the time-stamp - timeStamp->checkCoherency(); + timeStamp->checkConsistencyLight(); if ( onAll ) fld->_curMedField->appendFieldNoProfileSBT( timeStamp ); else @@ -3648,7 +3659,7 @@ bool DoubleField::hasSameComponentsBySupport() const */ //================================================================================ -ParaMEDMEM::TypeOfField DoubleField::getMedType( const int iSub ) const +MEDCoupling::TypeOfField DoubleField::getMedType( const int iSub ) const { using namespace INTERP_KERNEL; @@ -3670,7 +3681,7 @@ ParaMEDMEM::TypeOfField DoubleField::getMedType( const int iSub ) const */ //================================================================================ -ParaMEDMEM::TypeOfTimeDiscretization DoubleField::getMedTimeDisc() const +MEDCoupling::TypeOfTimeDiscretization DoubleField::getMedTimeDisc() const { return ONE_TIME; // NO_TIME = 4,