X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FSauvWriter.cxx;h=c56016ddfa9a5f142f54c94c412a40d06d9e0031;hb=ac1df6b0ba8b337555fb39610c89f678d889580d;hp=908f7a5043ddd75c7992345485c5a318e6927484;hpb=cdc5bc34c06fca639aef39cf04645acf6620ae2a;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/SauvWriter.cxx b/src/MEDLoader/SauvWriter.cxx index 908f7a504..c56016ddf 100644 --- a/src/MEDLoader/SauvWriter.cxx +++ b/src/MEDLoader/SauvWriter.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D +// Copyright (C) 2007-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 // 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 @@ -34,7 +34,7 @@ #include #include -using namespace ParaMEDMEM; +using namespace MEDCoupling; using namespace SauvUtilities; using namespace std; @@ -212,11 +212,9 @@ namespace } } -//================================================================================ -/*! - * \brief Creates SauvWriter - */ -//================================================================================ +SauvWriter::SauvWriter():_cpy_grp_if_on_single_family(false) +{ +} SauvWriter* SauvWriter::New() { @@ -228,9 +226,19 @@ std::size_t SauvWriter::getHeapMemorySizeWithoutChildren() const return 0; } -std::vector SauvWriter::getDirectChildren() const +std::vector SauvWriter::getDirectChildrenWithNull() const { - return std::vector(); + return std::vector(); +} + +void SauvWriter::setCpyGrpIfOnASingleFamilyStatus(bool status) +{ + _cpy_grp_if_on_single_family=status; +} + +bool SauvWriter::getCpyGrpIfOnASingleFamilyStatus() const +{ + return _cpy_grp_if_on_single_family; } //================================================================================ @@ -366,7 +374,7 @@ void SauvWriter::fillFamilySubMeshes() for ( size_t iDim = 0; iDim < dims.size(); ++iDim ) { int dimRelExt = dims[ iDim ]; - MEDCouplingAutoRefCountObjectPtr< MEDCouplingMesh > mesh = _fileMesh->getGenMeshAtLevel(dimRelExt); + MCAuto< MEDCouplingMesh > mesh = _fileMesh->getMeshAtLevel(dimRelExt); const DataArrayInt * famIds = _fileMesh->getFamilyFieldAtLevel(dimRelExt); if ( !famIds ) continue; @@ -442,12 +450,32 @@ void SauvWriter::fillGroupSubMeshes() ++k; } } + if ( k == 0 ) + continue; // if a family exists but has no element, no submesh has been found for this family // => we have to resize famSubMeshes with the number of submeshes stored if (k != famNames.size()) - famSubMeshes.resize(k); + famSubMeshes.resize(k); SubMesh* grpSubMesh = addSubMesh( groupName, famSubMeshes[0]->_dimRelExt ); - grpSubMesh->_subs.swap( famSubMeshes ); + if( ! _cpy_grp_if_on_single_family ) + { + grpSubMesh->_subs.swap( famSubMeshes ); + } + else + { + /* If a group sub mesh consists of only one family, the group is written as + * a copy of this family. + * A mesh composed of only one submesh may cause an issue with some Gibi operators.*/ + if (famSubMeshes.size() == 1) + { + for(int i = 0; i < famSubMeshes[0]->cellIDsByTypeSize() ; i++) + { + grpSubMesh->_cellIDsByType[i] = famSubMeshes[0]->_cellIDsByType[i]; + } + } + else + grpSubMesh->_subs.swap( famSubMeshes ); + } } } @@ -464,7 +492,7 @@ void SauvWriter::fillProfileSubMeshes() SubMesh* nilSm = (SubMesh*) 0; for ( int isOnNodes = 0; isOnNodes < 2; ++isOnNodes ) { - vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTS > > + vector< MCAuto< MEDFileFieldMultiTS > > fields = isOnNodes ? _nodeFields : _cellFields; for ( size_t i = 0; i < fields.size(); ++i ) { @@ -539,8 +567,8 @@ void SauvWriter::makeProfileIDs( SubMesh* sm, INTERP_KERNEL::NormalizedCellType type, const DataArrayInt* profile ) { - MEDCouplingAutoRefCountObjectPtr< MEDCouplingMesh > - mesh = _fileMesh->getGenMeshAtLevel(sm->_dimRelExt); + MCAuto< MEDCouplingMesh > + mesh = _fileMesh->getMeshAtLevel(sm->_dimRelExt); const MEDCouplingUMesh* uMesh = dynamic_cast< const MEDCouplingUMesh* > ((const MEDCouplingMesh*) mesh ); if ( sm->_dimRelExt == 1 ) type = INTERP_KERNEL::NORM_POINT1; @@ -576,9 +604,18 @@ void SauvWriter::makeProfileIDs( SubMesh* sm, code[2] = -1; } vector idsPerType( 1, profile ); - MEDCouplingAutoRefCountObjectPtr + MCAuto resIDs = uMesh->checkTypeConsistencyAndContig( code, idsPerType ); - ids.assign( resIDs->begin(), resIDs->end() ); + if (( const DataArrayInt *) resIDs ) + { + ids.assign( resIDs->begin(), resIDs->end() ); + } + else // mesh includes only one type + { + int nbE = code[1]; + for ( ids.resize( nbE ); nbE; --nbE ) + ids[ nbE-1 ] = nbE-1; + } } } @@ -588,10 +625,10 @@ void SauvWriter::makeProfileIDs( SubMesh* sm, */ //================================================================================ -void SauvWriter::write(const char* fileName) +void SauvWriter::write(const std::string& fileName) { std::fstream fileStream; - fileStream.open( fileName, ios::out); + fileStream.open( fileName.c_str(), ios::out); if #ifdef WIN32 ( !fileStream || !fileStream.is_open() ) @@ -628,7 +665,7 @@ void SauvWriter::write(const char* fileName) void SauvWriter::writeFileHead() { - MEDCouplingAutoRefCountObjectPtr< MEDCouplingMesh > mesh = _fileMesh->getGenMeshAtLevel(0); + MCAuto< MEDCouplingMesh > mesh = _fileMesh->getMeshAtLevel(0); *_sauvFile << " ENREGISTREMENT DE TYPE 4" << endl @@ -709,9 +746,9 @@ void SauvWriter::writeSubMeshes() else { // write each sub-type as a SAUV sub-mesh - MEDCouplingAutoRefCountObjectPtr< MEDCouplingMesh > - mesh = _fileMesh->getGenMeshAtLevel( sm._dimRelExt ); - MEDCouplingAutoRefCountObjectPtr< MEDCouplingUMesh> + MCAuto< MEDCouplingMesh > + mesh = _fileMesh->getMeshAtLevel( sm._dimRelExt ); + MCAuto< MEDCouplingUMesh> umesh = mesh->buildUnstructured(); for ( int iType=0; iType < sm.cellIDsByTypeSize(); ++iType ) @@ -808,8 +845,8 @@ void SauvWriter::writeCompoundSubMesh(int iSub) void SauvWriter::writeNodes() { - MEDCouplingAutoRefCountObjectPtr< MEDCouplingMesh > mesh = _fileMesh->getGenMeshAtLevel( 1 ); - MEDCouplingAutoRefCountObjectPtr< MEDCouplingUMesh > umesh = mesh->buildUnstructured(); + MCAuto< MEDCouplingMesh > mesh = _fileMesh->getMeshAtLevel( 1 ); + MCAuto< MEDCouplingUMesh > umesh = mesh->buildUnstructured(); // write the index connecting nodes with their coodrinates @@ -838,7 +875,7 @@ void SauvWriter::writeNodes() _sauvFile->precision(14); _sauvFile->setf( ios_base::scientific, ios_base::floatfield ); _sauvFile->setf( ios_base::uppercase ); - MEDCouplingAutoRefCountObjectPtr< DataArrayDouble> coordArray = umesh->getCoordinatesAndOwner(); + MCAuto< DataArrayDouble> coordArray = umesh->getCoordinatesAndOwner(); const double precision = 1.e-99; // PAL12077 for ( int i = 0; i < nbNodes; ++i) { @@ -963,7 +1000,7 @@ void SauvWriter::writeLongNames() void SauvWriter::writeFieldNames( const bool isNodal, std::map& fldNamePrefixMap) { - vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTS > >& + vector< MCAuto< MEDFileFieldMultiTS > >& flds = isNodal ? _nodeFields : _cellFields; map nameNbMap; @@ -1133,7 +1170,7 @@ void SauvWriter::writeNodalFields(map& fldNamePrefixMap) fcount.stop(); } } - } // loop on fiels + } // loop on files } //================================================================================