+ tinyStr.push_back((*it).first);
+ layer0.push_back((*it).second);
+ }
+ layer0.push_back((int)_groups.size());//4+aa i <- key info bb layer#0
+ for(std::map<std::string, std::vector<std::string> >::const_iterator it0=_groups.begin();it0!=_groups.end();it0++)
+ {
+ layer0.push_back((int)(*it0).second.size());
+ tinyStr.push_back((*it0).first);
+ for(std::vector<std::string>::const_iterator it1=((*it0).second).begin();it1!=((*it0).second).end();it1++)
+ tinyStr.push_back(*it1);
+ }
+ // sizeof(layer0)==4+aa+1+bb layer#0
+ bigArrayD=_coords;// 0 bd
+ bigArraysI.push_back(_fam_coords);// 0 bi
+ bigArraysI.push_back(_num_coords);// 1 bi
+ const PartDefinition *pd(_part_coords);
+ if(!pd)
+ layer0.push_back(-1);
+ else
+ {
+ std::vector<int> tmp0;
+ pd->serialize(tmp0,bigArraysI);
+ tinyInt.push_back(tmp0.size());
+ tinyInt.insert(tinyInt.end(),tmp0.begin(),tmp0.end());
+ }
+ //
+ std::vector<int> layer1;
+ std::vector<int> levs(getNonEmptyLevels());
+ layer1.push_back((int)levs.size());// 0 i <- key
+ layer1.insert(layer1.end(),levs.begin(),levs.end());
+ for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
+ {
+ const MEDFileUMeshSplitL1 *lev(getMeshAtLevSafe(*it));
+ lev->serialize(layer1,bigArraysI);
+ }
+ // put layers all together.
+ tinyInt.push_back(layer0.size());
+ tinyInt.insert(tinyInt.end(),layer0.begin(),layer0.end());
+ tinyInt.push_back(layer1.size());
+ tinyInt.insert(tinyInt.end(),layer1.begin(),layer1.end());
+}
+
+void MEDFileUMesh::unserialize(std::vector<double>& tinyDouble, std::vector<int>& tinyInt, std::vector<std::string>& tinyStr,
+ std::vector< MCAuto<DataArrayInt> >& bigArraysI, MCAuto<DataArrayDouble>& bigArrayD)
+{
+ int sz0(tinyInt[0]);
+ std::vector<int> layer0(tinyInt.begin()+1,tinyInt.begin()+1+sz0);
+ int sz1(tinyInt[sz0+1]);
+ std::vector<int> layer1(tinyInt.begin()+2+sz0,tinyInt.begin()+2+sz0+sz1);
+ //
+ std::reverse(layer0.begin(),layer0.end());
+ std::reverse(layer1.begin(),layer1.end());
+ std::reverse(tinyDouble.begin(),tinyDouble.end());
+ std::reverse(tinyStr.begin(),tinyStr.end());
+ std::reverse(bigArraysI.begin(),bigArraysI.end());
+ //
+ setAxisType((MEDCouplingAxisType)layer0.back()); layer0.pop_back();
+ _order=layer0.back(); layer0.pop_back();
+ _iteration=layer0.back(); layer0.pop_back();
+ int spaceDim(layer0.back()); layer0.pop_back();
+ _time=tinyDouble.back(); tinyDouble.pop_back();
+ _name=tinyStr.back(); tinyStr.pop_back();
+ _desc_name=tinyStr.back(); tinyStr.pop_back();
+ _coords=bigArrayD; _coords->rearrange(spaceDim);
+ for(int i=0;i<spaceDim;i++)
+ {
+ _coords->setInfoOnComponent(i,tinyStr.back());
+ tinyStr.pop_back();
+ }
+ int nbOfFams(layer0.back()); layer0.pop_back();
+ _families.clear();
+ for(int i=0;i<nbOfFams;i++)
+ {
+ _families[tinyStr.back()]=layer0.back();
+ tinyStr.pop_back(); layer0.pop_back();
+ }
+ int nbGroups(layer0.back()); layer0.pop_back();
+ _groups.clear();
+ for(int i=0;i<nbGroups;i++)
+ {
+ std::string grpName(tinyStr.back()); tinyStr.pop_back();
+ int nbOfFamsOnGrp(layer0.back()); layer0.pop_back();
+ std::vector<std::string> fams(nbOfFamsOnGrp);
+ for(int j=0;j<nbOfFamsOnGrp;j++)
+ {
+ fams[j]=tinyStr.back(); tinyStr.pop_back();
+ }
+ _groups[grpName]=fams;
+ }
+ _fam_coords=bigArraysI.back(); bigArraysI.pop_back();
+ _num_coords=bigArraysI.back(); bigArraysI.pop_back();
+ _part_coords=0;
+ int isPd(layer0.back()); layer0.pop_back();
+ if(isPd!=-1)
+ {
+ std::vector<int> tmp0(layer0.begin(),layer0.begin()+isPd);
+ layer0.erase(layer0.begin(),layer0.begin()+isPd);
+ _part_coords=PartDefinition::Unserialize(tmp0,bigArraysI);
+ }
+ if(!layer0.empty())
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::unserialize : something wrong during unserialization #1 !");
+ //
+ int nbLevs(layer1.back()); layer1.pop_back();
+ std::vector<int> levs(layer1.rbegin(),layer1.rbegin()+nbLevs); layer1.erase(layer1.end()-nbLevs,layer1.end());
+ _ms.clear();
+ int maxLev(-(*std::min_element(levs.begin(),levs.end())));
+ _ms.resize(maxLev+1);
+ for(int i=0;i<nbLevs;i++)
+ {
+ int lev(levs[i]);
+ int pos(-lev);
+ _ms[pos]=MEDFileUMeshSplitL1::Unserialize(_name,_coords,layer1,bigArraysI);
+ }
+}
+
+/*!
+ * Adds a group of nodes to \a this mesh.
+ * \param [in] ids - a DataArrayInt providing ids and a name of the group to add.
+ * The ids should be sorted and different each other (MED file norm).
+ *
+ * \warning this method can alter default "FAMILLE_ZERO" family.
+ * For users sensitive to this a call to MEDFileMesh::rearrangeFamilies will be necessary after addGroup session.
+ *
+ * \throw If the node coordinates array is not set.
+ * \throw If \a ids == \c NULL.
+ * \throw If \a ids->getName() == "".
+ * \throw If \a ids does not respect the MED file norm.
+ * \throw If a group with name \a ids->getName() already exists.
+ */
+void MEDFileUMesh::addNodeGroup(const DataArrayInt *ids)
+{
+ const DataArrayDouble *coords(_coords);
+ if(!coords)
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::addNodeGroup : no coords set !");
+ int nbOfNodes(coords->getNumberOfTuples());
+ if(!((DataArrayInt *)_fam_coords))
+ { _fam_coords=DataArrayInt::New(); _fam_coords->alloc(nbOfNodes,1); _fam_coords->fillWithZero(); }
+ //
+ addGroupUnderground(true,ids,_fam_coords);
+}
+
+/*!
+ * Adds a group of nodes/cells/faces/edges to \a this mesh.
+ *
+ * \param [in] ids - a DataArrayInt providing ids and a name of the group to add.
+ * The ids should be sorted and different each other (MED file norm).
+ *
+ * \warning this method can alter default "FAMILLE_ZERO" family.
+ * For users sensitive to this a call to MEDFileMesh::rearrangeFamilies will be necessary after addGroup session.
+ *
+ * \throw If the node coordinates array is not set.
+ * \throw If \a ids == \c NULL.
+ * \throw If \a ids->getName() == "".
+ * \throw If \a ids does not respect the MED file norm.
+ * \throw If a group with name \a ids->getName() already exists.
+ */
+void MEDFileUMesh::addGroup(int meshDimRelToMaxExt, const DataArrayInt *ids)
+{
+ std::vector<int> levs(getNonEmptyLevelsExt());
+ if(std::find(levs.begin(),levs.end(),meshDimRelToMaxExt)==levs.end())
+ {
+ std::ostringstream oss; oss << "MEDFileUMesh::addGroup : level " << meshDimRelToMaxExt << " not available ! Should be in ";
+ std::copy(levs.begin(),levs.end(),std::ostream_iterator<int>(oss," ")); oss << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str());