THROW_IK_EXCEPTION("Nodes and coordinates mismatch");
}
+//================================================================================
+/*!
+ * \brief Safely adds a new Group
+ */
+//================================================================================
+
+Group* IntermediateMED::addNewGroup(std::vector<SauvUtilities::Group*>* groupsToFix)
+{
+ if ( _groups.size() == _groups.capacity() ) // re-allocation would occure
+ {
+ std::vector<Group> newGroups( _groups.size() );
+ newGroups.push_back( Group() );
+
+ for ( size_t i = 0; i < _groups.size(); ++i )
+ {
+ // avoid copying _cells
+ std::vector<const Cell*> 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<DoubleField* >& 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
std::string _name;
std::vector<const Cell*> _cells;
std::vector< Group* > _groups; // des sous-groupes composant le Group
- //bool _isShared; // true if any Cell was added to the mesh from other Group
bool _isProfile; // is a field support or not
std::vector<std::string> _refNames; /* names of groups referring this one;
_refNames is resized according to nb of references
Node* getNode( TID nID ) { return _points.getNode( nID ); }
int getNbCellsOfType( TCellType type ) const { return _cellsByType[type].size(); }
const Cell* insert(TCellType type, const Cell& ma) { return &( *_cellsByType[type].insert( ma ).first ); }
+ Group* addNewGroup(std::vector<SauvUtilities::Group*>* groupsToFix=0);
ParaMEDMEM::MEDFileData* convertInMEDFileDS();
private:
SauvUtilities::Group & grp = _iMed->_groups[ grpID-1 ];
if ( !grp._name.empty() ) // a group has several names
{ // create a group with subgroup grp and named grp.name
- _iMed->_groups.push_back(Group());
- _iMed->_groups.back()._groups.push_back( &_iMed->_groups[ grpID-1 ]);
- _iMed->_groups.back()._name = grp._name;
+ SauvUtilities::Group* newGroup = _iMed->addNewGroup();
+ newGroup->_groups.push_back( &_iMed->_groups[ grpID-1 ]);
+ newGroup->_name = grp._name;
}
grp._name=objectNames[i];
#ifdef _DEBUG
sameOrder = ( supports[j] == newGroups[ j % newGroups.size() ]);
if ( sameOrder )
{
- _iMed->_groups.push_back( SauvUtilities::Group() );
- group = & _iMed->_groups.back();
+ group = _iMed->addNewGroup( & newGroups );
group->_groups.swap( newGroups );
}
}