+ {
+ (*it)->renumberNodesInConn(ret->begin());
+ (*it)->setCoords(_coords);
+ }
+ }
+ // updates _part_coords
+ const PartDefinition *pc(_part_coords);
+ if(pc)
+ {
+ MEDCouplingAutoRefCountObjectPtr<PartDefinition> tmpPD(DataArrayPartDefinition::New(ret2));
+ _part_coords=tmpPD->composeWith(pc);
+ }
+ return ret.retn();
+}
+
+/*!
+ * This method performs an extrusion along a path defined by \a m1D.
+ * \a this is expected to be a mesh with max mesh dimension equal to 2.
+ * \a m1D is expected to be a mesh with space dimesion equal to 3 and mesh dimension equal to 1.
+ * Mesh dimensions of returned mesh is incremented by one compared to thoose in \a this.
+ * This method scans all levels in \a this
+ * and put them in the returned mesh. All groups in \a this are also put in the returned mesh.
+ *
+ * \param [in] m1D - the mesh defining the extrusion path.
+ * \param [in] policy - defines the policy of extrusion (see MEDCouplingUMesh::buildExtrudedMesh for more details)
+ * \return - a new reference on mesh (you have to deal with using decrRef). The returned mesh will have the same name than \a this.
+ *
+ * \sa MEDCouplingUMesh::buildExtrudedMesh
+ */
+MEDFileUMesh *MEDFileUMesh::buildExtrudedMesh(const MEDCouplingUMesh *m1D, int policy) const
+{
+ if(getMeshDimension()!=2)
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::buildExtrudedMesh : this is expected to be with mesh dimension equal to 2 !");
+ MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret(MEDFileUMesh::New());
+ m1D->checkCoherency();
+ if(m1D->getMeshDimension()!=1)
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::buildExtrudedMesh : input mesh must have a mesh dimension equal to one !");
+ int nbRep(m1D->getNumberOfCells());
+ std::vector<int> levs(getNonEmptyLevels());
+ std::vector<std::string> grps(getGroupsNames());
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> > zeList;
+ DataArrayDouble *coords(0);
+ std::size_t nbOfLevsOut(levs.size()+1);
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > o2ns(nbOfLevsOut);
+ for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
+ {
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> item(getMeshAtLevel(*lev));
+ item=item->clone(false);
+ item->changeSpaceDimension(3+(*lev),0.);//no problem non const but change DataArrayDouble for coordinates do not alter data
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp(static_cast<MEDCouplingUMesh *>(m1D->deepCpy()));
+ tmp->changeSpaceDimension(3+(*lev),0.);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> elt(item->buildExtrudedMesh(tmp,policy));
+ zeList.push_back(elt);
+ if(*lev==0)
+ coords=elt->getCoords();
+ }
+ if(!coords)
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::buildExtrudedMesh : internal error !");
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> >::iterator it=zeList.begin();it!=zeList.end();it++)
+ {
+ (*it)->setName(getName());
+ (*it)->setCoords(coords);
+ }
+ for(std::size_t ii=0;ii!=zeList.size();ii++)
+ {
+ int lev(levs[ii]);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> elt(zeList[ii]);
+ if(lev<=-1)
+ {
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> elt1(getMeshAtLevel(lev+1));
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> elt2(elt1->clone(false));
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(elt2->getNodalConnectivity()->deepCpy());
+ elt2->setConnectivity(tmp,elt2->getNodalConnectivityIndex());
+ elt2->shiftNodeNumbersInConn(nbRep*elt1->getNumberOfNodes());
+ elt1->setCoords(elt->getCoords()); elt2->setCoords(elt->getCoords());
+ std::vector<const MEDCouplingUMesh *> elts(3);
+ elts[0]=elt; elts[1]=elt1; elts[2]=elt2;
+ elt=MEDCouplingUMesh::MergeUMeshesOnSameCoords(elts);
+ elt->setName(getName());
+ }
+ //
+ o2ns[ii]=elt->sortCellsInMEDFileFrmt();
+ ret->setMeshAtLevel(lev,elt);
+ }
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> endLev(getMeshAtLevel(levs.back())),endLev2;
+ endLev=endLev->clone(false); endLev->setCoords(coords);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(endLev->getNodalConnectivity()->deepCpy());
+ endLev2=endLev->clone(false); endLev2->setConnectivity(tmp,endLev->getNodalConnectivityIndex());
+ endLev2->shiftNodeNumbersInConn(nbRep*getNumberOfNodes());
+ endLev=MEDCouplingUMesh::MergeUMeshesOnSameCoords(endLev,endLev2);
+ o2ns[levs.size()]=endLev->sortCellsInMEDFileFrmt();
+ endLev->setName(getName());
+ ret->setMeshAtLevel(levs.back()-1,endLev);
+ //
+ for(std::size_t ii=0;ii!=zeList.size();ii++)
+ {
+ int lev(levs[ii]);
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > outGrps;
+ std::vector< const DataArrayInt * > outGrps2;
+ if(lev<=-1)
+ {
+ for(std::vector<std::string>::const_iterator grp=grps.begin();grp!=grps.end();grp++)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> grpArr(getGroupArr(lev+1,*grp));
+ if(!grpArr->empty())
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> grpArr1(grpArr->deepCpy()),grpArr2(grpArr->deepCpy());
+ int offset0(zeList[ii]->getNumberOfCells());
+ int offset1(offset0+getNumberOfCellsAtLevel(lev+1));
+ grpArr1->applyLin(1,offset0); grpArr2->applyLin(1,offset1);
+ std::ostringstream oss; oss << grpArr2->getName() << "_top";
+ grpArr2->setName(oss.str());
+ grpArr1->transformWithIndArr(o2ns[ii]->begin(),o2ns[ii]->end());
+ grpArr2->transformWithIndArr(o2ns[ii]->begin(),o2ns[ii]->end());
+ outGrps.push_back(grpArr1); outGrps.push_back(grpArr2);
+ outGrps2.push_back(grpArr1); outGrps2.push_back(grpArr2);
+ }
+ }
+ }
+ //
+ for(std::vector<std::string>::const_iterator grp=grps.begin();grp!=grps.end();grp++)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> grpArr(getGroupArr(lev,*grp));
+ if(!grpArr->empty())
+ {
+ int nbCellsB4Extrusion(getNumberOfCellsAtLevel(lev));
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > grpArrs(nbRep);
+ std::vector< const DataArrayInt *> grpArrs2(nbRep);
+ for(int iii=0;iii<nbRep;iii++)
+ {
+ grpArrs[iii]=grpArr->deepCpy(); grpArrs[iii]->applyLin(1,iii*nbCellsB4Extrusion);
+ grpArrs2[iii]=grpArrs[iii];
+ }
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> grpArrExt(DataArrayInt::Aggregate(grpArrs2));
+ grpArrExt->transformWithIndArr(o2ns[ii]->begin(),o2ns[ii]->end());
+ std::ostringstream grpName; grpName << *grp << "_extruded";
+ grpArrExt->setName(grpName.str());
+ outGrps.push_back(grpArrExt);
+ outGrps2.push_back(grpArrExt);
+ }
+ }
+ ret->setGroupsAtLevel(lev,outGrps2);
+ }
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > outGrps;
+ std::vector< const DataArrayInt * > outGrps2;
+ for(std::vector<std::string>::const_iterator grp=grps.begin();grp!=grps.end();grp++)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> grpArr1(getGroupArr(levs.back(),*grp));
+ if(grpArr1->empty())
+ continue;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> grpArr2(grpArr1->deepCpy());
+ std::ostringstream grpName; grpName << *grp << "_top";
+ grpArr2->setName(grpName.str());
+ grpArr2->applyLin(1,getNumberOfCellsAtLevel(levs.back()));
+ outGrps.push_back(grpArr1); outGrps.push_back(grpArr2);
+ outGrps2.push_back(grpArr1); outGrps2.push_back(grpArr2);
+ }
+ ret->setGroupsAtLevel(levs.back()-1,outGrps2);
+ return ret.retn();
+}
+
+/*!
+ * This method converts all linear cells in \a this into quadratic cells (following the \a conversionType policy).
+ * All the cells converted are put in the returned instance. This method applies all the groups and families in \a this to returned instance.
+ * Groups on nodes and families on nodes are copied directly to the returned instance without transformation.
+ *
+ * \param [in] conversionType - conversionType specifies the type of conversion expected. Only 0 (default) and 1 are supported presently. 0 those that creates the 'most' simple
+ * corresponding quadratic cells. 1 is those creating the 'most' complex.
+ * \param [in] eps - detection threshold for coordinates.
+ * \return A new instance that is the result of the conversion. The caller has the ownership of this returned instance.
+ *
+ * \sa MEDCouplingUMesh::convertLinearCellsToQuadratic , quadraticToLinear
+ */
+MEDFileUMesh *MEDFileUMesh::linearToQuadratic(int conversionType, double eps) const
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret(MEDFileUMesh::New());
+ int initialNbNodes(getNumberOfNodes());
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m0Tmp(getMeshAtLevel(0));
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m0(dynamic_cast<MEDCouplingUMesh *>(m0Tmp->deepCpy()));
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> notUsed(m0->convertLinearCellsToQuadratic(conversionType));
+ }
+ DataArrayDouble *zeCoords(m0->getCoords());
+ ret->setMeshAtLevel(0,m0);
+ std::vector<int> levs(getNonEmptyLevels());
+ const DataArrayInt *famField(getFamilyFieldAtLevel(0));
+ if(famField)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famFieldCpy(famField->deepCpy());
+ ret->setFamilyFieldArr(0,famFieldCpy);
+ }
+ famField=getFamilyFieldAtLevel(1);
+ if(famField)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam(DataArrayInt::New()); fam->alloc(zeCoords->getNumberOfTuples(),1);
+ fam->fillWithZero();
+ fam->setPartOfValues1(famField,0,initialNbNodes,1,0,1,1);
+ ret->setFamilyFieldArr(1,fam);
+ }
+ ret->copyFamGrpMapsFrom(*this);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> partZeCoords(zeCoords->selectByTupleId2(initialNbNodes,zeCoords->getNumberOfTuples(),1));
+ for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
+ {
+ if(*lev==0)
+ continue;
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m1Tmp(getMeshAtLevel(*lev));
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m1(dynamic_cast<MEDCouplingUMesh *>(m1Tmp->deepCpy()));
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> notUsed(m1->convertLinearCellsToQuadratic(conversionType));
+ }
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> m1Coords(m1->getCoords()->selectByTupleId2(initialNbNodes,m1->getNumberOfNodes(),1));
+ DataArrayInt *b(0);
+ bool a(partZeCoords->areIncludedInMe(m1Coords,eps,b));
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> bSafe(b);
+ if(!a)
+ {
+ std::ostringstream oss; oss << "MEDFileUMesh::linearCellsToQuadratic : for level " << *lev << " problem to identify nodes generated !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ b->applyLin(1,initialNbNodes);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> l0(DataArrayInt::New()); l0->alloc(initialNbNodes,1); l0->iota();
+ std::vector<const DataArrayInt *> v(2); v[0]=l0; v[1]=b;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renum(DataArrayInt::Aggregate(v));
+ m1->renumberNodesInConn(renum->begin());
+ m1->setCoords(zeCoords);
+ ret->setMeshAtLevel(*lev,m1);
+ famField=getFamilyFieldAtLevel(*lev);
+ if(famField)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famFieldCpy(famField->deepCpy());
+ ret->setFamilyFieldArr(*lev,famFieldCpy);
+ }