-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2014 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
{
bool xdr_ok = false;
#ifdef HAS_XDR
+#ifdef WIN32
+ if ((_xdrs_file = ::fopen(_fileName.c_str(), "rb")))
+#else
if ((_xdrs_file = ::fopen(_fileName.c_str(), "r")))
+#endif
{
_xdrs = (XDR *)malloc(sizeof(XDR));
xdrstdio_create((XDR*)_xdrs, _xdrs_file, XDR_DECODE);
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
int dim = getDim( grp );
int nbElems = 0;
- CellsByDimIterator dimCells( *this, dim );
- while ( const std::set<Cell > * 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<Cell > * cells = dimCells.nextType() )
+ nbElems += cells->size();
+
int meshDim = 3;
for ( ; meshDim > 0; --meshDim )
{
}
dimRel = dim - meshDim;
}
+
+ bool onAll = ( nbElems == grp->size() );
return onAll;
}
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;
DataArrayDouble * coo = mesh->getCoords();
MEDCouplingAutoRefCountObjectPtr
<DataArrayDouble> subCoo = coo->selectByTupleId(support->_medGroup->begin(),
- support->_medGroup->end());
+ support->_medGroup->end());
MEDCouplingAutoRefCountObjectPtr< MEDCouplingUMesh > nodeSubMesh =
MEDCouplingUMesh::Build0DMeshFromCoords( subCoo );
timeStamp->setMesh( nodeSubMesh );
if ( _sub.size() < 2 )
return false;
bool sameSupports = true;
- Group* grp1 = _sub[0]._support;
+ Group* grpp1 = _sub[0]._support;// grpp NOT grp because XDR under Windows defines grp...
for ( size_t i = 1; i < _sub.size() && sameSupports; ++i )
- sameSupports = ( grp1 == _sub[i]._support );
+ sameSupports = ( grpp1 == _sub[i]._support );
return sameSupports;
}