From: eap Date: Fri, 11 Oct 2013 10:58:24 +0000 (+0000) Subject: 22341: [CEA 958] sauv2med: different nb of gauss points in components X-Git-Tag: V7_3_0a1~97 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=188d0c3653727749403c91c14554e9e597d6a530;p=modules%2Fmed.git 22341: [CEA 958] sauv2med: different nb of gauss points in components + void splitSubWithDiffNbGauss(); --- diff --git a/src/MEDLoader/SauvMedConvertor.cxx b/src/MEDLoader/SauvMedConvertor.cxx index f277c8347..f243840ce 100644 --- a/src/MEDLoader/SauvMedConvertor.cxx +++ b/src/MEDLoader/SauvMedConvertor.cxx @@ -3276,17 +3276,21 @@ void IntermediateMED::setFields( SauvUtilities::DoubleField* fld, const TID castemID, set< string >& usedFieldNames) { - if ( !fld || !fld->isMedCompatible() ) return; + bool sameNbGauss = true; + if ( !fld || !fld->isMedCompatible( sameNbGauss )) return; + + if ( !sameNbGauss ) + fld->splitSubWithDiffNbGauss(); // if ( !fld->hasCommonSupport() ): // each sub makes MEDFileFieldMultiTS // else: // unite several subs into a MEDCouplingFieldDouble - const bool uniteSubs = fld->hasCommonSupport(); + const bool uniteSubs = fld->hasCommonSupport() && sameNbGauss; if ( !uniteSubs ) - cout << "Castem field #" << castemID << " " << fld->_name - << " is incompatible with MED format, so we split it into several fields" << endl; + cout << "Castem field #" << castemID << " <" << fld->_name + << "> is incompatible with MED format, so we split it into several fields" << endl; for ( size_t iSub = 0; iSub < fld->_sub.size(); ) { @@ -3327,7 +3331,7 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField* fld, ParaMEDMEM::MEDFileUMesh* mesh, const int iSub) { - // analyze a field support + // treat a field support const Group* support = fld->getSupport( iSub ); int dimRel; const bool onAll = isOnAll( support, dimRel ); @@ -3337,33 +3341,39 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField* fld, support->_medGroup->setName( support->_name.c_str() ); } - // make a time-stamp + // make and fill a time-stamp + MEDCouplingFieldDouble * timeStamp = MEDCouplingFieldDouble::New( fld->getMedType( iSub ), fld->getMedTimeDisc() ); timeStamp->setName( fld->_name.c_str() ); timeStamp->setDescription( fld->_description.c_str() ); + // set the mesh MEDCouplingAutoRefCountObjectPtr< MEDCouplingUMesh > dimMesh = mesh->getMeshAtLevel( dimRel ); - timeStamp->setMesh( dimMesh ); + if ( onAll ) + { + timeStamp->setMesh( dimMesh ); + } + else + { + MEDCouplingAutoRefCountObjectPtr + subMesh = dimMesh->buildPart(support->_medGroup->begin(), + support->_medGroup->end()); + timeStamp->setMesh( subMesh); + } + // set values for ( size_t i = 0; i < (size_t)fld->_sub[iSub].nbComponents(); ++i ) values->setInfoOnComponent( i, fld->_sub[iSub]._comp_names[ i ].c_str() ); timeStamp->setArray( values ); values->decrRef(); + // set gauss points if ( timeStamp->getTypeOfField() == ParaMEDMEM::ON_GAUSS_PT ) { TGaussDef gaussDef( support->_cellType, fld->_sub[iSub].nbGauss() ); - if ( !onAll ) - { - MEDCouplingAutoRefCountObjectPtr - submesh = dimMesh->buildPart(support->_medGroup->begin(), - support->_medGroup->end()); - timeStamp->setMesh( submesh); - } - timeStamp->setGaussLocalizationOnType( support->_cellType, - gaussDef.myRefCoords, - gaussDef.myCoords, - gaussDef.myWeights ); + timeStamp->setGaussLocalizationOnType( support->_cellType, + gaussDef.myRefCoords, + gaussDef.myCoords, + gaussDef.myWeights ); } - // get a field to add the time-stamp bool isNewMedField = false; if ( !fld->_curMedField || fld->_name != fld->_curMedField->getName() ) @@ -3422,6 +3432,35 @@ void IntermediateMED::makeFieldNewName(std::set< std::string >& usedNames, while( !usedNames.insert( fld->_name ).second ); } +//================================================================================ +/*! + * \brief Split sub-components with different nb of gauss points into several sub-components + * \param [in,out] fld - a field to split if necessary + */ +//================================================================================ + +void DoubleField::splitSubWithDiffNbGauss() +{ + for ( size_t iSub = 0; iSub < _sub.size(); ++iSub ) + { + if ( _sub[iSub].isSameNbGauss() ) continue; + + _sub.insert( _sub.begin() + iSub + 1, 1, _Sub_data() ); + _Sub_data & subToSplit = _sub[iSub]; + _Sub_data & subNew = _sub[iSub+1]; + size_t iDiff = 1; + while ( subToSplit._nb_gauss[ 0 ] == subToSplit._nb_gauss[ iDiff ] ) + ++iDiff; + subNew._support = subToSplit._support; + subNew._comp_names.assign( subToSplit._comp_names.begin() + iDiff, + subToSplit._comp_names.end() ); + subNew._nb_gauss.assign ( subToSplit._nb_gauss.begin() + iDiff, + subToSplit._nb_gauss.end() ); + subToSplit._comp_names.resize( iDiff ); + subToSplit._nb_gauss.resize ( iDiff ); + } +} + //================================================================================ /*! * \brief Return a vector ready to fill in @@ -3477,22 +3516,21 @@ bool DoubleField::isMultiTimeStamps() const */ //================================================================================ -bool DoubleField::isMedCompatible() const +bool DoubleField::isMedCompatible(bool& sameNbGauss) const { for ( size_t iSub = 0; iSub < _sub.size(); ++iSub ) { if ( !getSupport(iSub) || !getSupport(iSub)->_medGroup ) THROW_IK_EXCEPTION("SauvReader INTERNAL ERROR: NULL field support"); - if ( !_sub[iSub].isValidNbGauss() ) + sameNbGauss = true; + if ( !_sub[iSub].isSameNbGauss() ) { - cout << "Skip field <" << _name << "> : different nb of gauss points in components" < : different nb of gauss points in components" < 1; } }; // ---------------------------------------------------------------------------- @@ -155,7 +155,7 @@ namespace SauvUtilities bool hasSameComponentsBySupport() const; bool isMultiTimeStamps() const; - bool isMedCompatible() const; + bool isMedCompatible(bool& sameNbGauss) const; ParaMEDMEM::TypeOfField getMedType( const int iSub=0 ) const; ParaMEDMEM::TypeOfTimeDiscretization getMedTimeDisc() const; int getNbTuples( const int iSub=0 ) const; @@ -163,6 +163,7 @@ namespace SauvUtilities int getNbGauss( const int iSub=0 ) const; const Group* getSupport( const int iSub=0 ) const; int setValues( double * valPtr, const int iSub, const int elemShift=0 ) const; + void splitSubWithDiffNbGauss(); //virtual void dump(std::ostream&) const; //virtual ~DoubleField() {}