1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCoupling1GTUMesh.hxx"
22 #include "MEDCouplingUMesh.hxx"
23 #include "MEDCouplingFieldDouble.hxx"
25 #include "SplitterTetra.hxx"
27 using namespace ParaMEDMEM;
29 MEDCoupling1GTUMesh::MEDCoupling1GTUMesh(const char *name, const INTERP_KERNEL::CellModel& cm):_cm(&cm)
34 MEDCoupling1GTUMesh::MEDCoupling1GTUMesh(const MEDCoupling1GTUMesh& other, bool recDeepCpy):MEDCouplingPointSet(other,recDeepCpy),_cm(other._cm)
38 MEDCoupling1GTUMesh *MEDCoupling1GTUMesh::New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception)
40 if(type==INTERP_KERNEL::NORM_ERROR)
41 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::New : NORM_ERROR is not a valid type to be used as base geometric type for a mesh !");
42 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
44 return MEDCoupling1SGTUMesh::New(name,type);
46 return MEDCoupling1DGTUMesh::New(name,type);
49 MEDCoupling1GTUMesh *MEDCoupling1GTUMesh::New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception)
52 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::New : input mesh is null !");
53 std::set<INTERP_KERNEL::NormalizedCellType> gts(m->getAllGeoTypes());
55 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::New : input mesh must have exactly one geometric type !");
56 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*gts.begin());
58 return MEDCoupling1SGTUMesh::New(m);
60 return MEDCoupling1DGTUMesh::New(m);
63 const INTERP_KERNEL::CellModel& MEDCoupling1GTUMesh::getCellModel() const throw(INTERP_KERNEL::Exception)
68 INTERP_KERNEL::NormalizedCellType MEDCoupling1GTUMesh::getCellModelEnum() const throw(INTERP_KERNEL::Exception)
70 return _cm->getEnum();
73 int MEDCoupling1GTUMesh::getMeshDimension() const
75 return (int)_cm->getDimension();
79 * This method returns a newly allocated array containing cell ids (ascendingly sorted) whose geometric type are equal to type.
80 * This method does not throw exception if geometric type \a type is not in \a this.
81 * This method throws an INTERP_KERNEL::Exception if meshdimension of \b this is not equal to those of \b type.
82 * The coordinates array is not considered here.
84 * \param [in] type the geometric type
85 * \return cell ids in this having geometric type \a type.
87 DataArrayInt *MEDCoupling1GTUMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
89 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
90 if(type==getCellModelEnum())
91 ret->alloc(getNumberOfCells(),1);
99 * Returns nb of cells having the geometric type \a type. No throw if no cells in \a this has the geometric type \a type.
101 int MEDCoupling1GTUMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
103 return type==getCellModelEnum()?getNumberOfCells():0;
107 * Returns a type of a cell by its id.
108 * \param [in] cellId - the id of the cell of interest.
109 * \return INTERP_KERNEL::NormalizedCellType - enumeration item describing the cell type.
110 * \throw If \a cellId is invalid. Valid range is [0, \a this->getNumberOfCells() ).
112 INTERP_KERNEL::NormalizedCellType MEDCoupling1GTUMesh::getTypeOfCell(int cellId) const
114 if(cellId>=0 && cellId<getNumberOfCells())
115 return getCellModelEnum();
116 std::ostringstream oss; oss << "MEDCoupling1GTUMesh::getTypeOfCell : Requesting type of cell #" << cellId << " but it should be in [0," << getNumberOfCells() << ") !";
117 throw INTERP_KERNEL::Exception(oss.str().c_str());
121 * Returns a set of all cell types available in \a this mesh.
122 * \return std::set<INTERP_KERNEL::NormalizedCellType> - the set of cell types.
123 * \warning this method does not throw any exception even if \a this is not defined.
125 std::set<INTERP_KERNEL::NormalizedCellType> MEDCoupling1GTUMesh::getAllGeoTypes() const
127 std::set<INTERP_KERNEL::NormalizedCellType> ret;
128 ret.insert(getCellModelEnum());
133 * This method expects that \a this is sorted by types. If not an exception will be thrown.
134 * This method returns in the same format as code (see MEDCouplingUMesh::checkTypeConsistencyAndContig or MEDCouplingUMesh::splitProfilePerType) how
135 * \a this is composed in cell types.
136 * The returned array is of size 3*n where n is the number of different types present in \a this.
137 * For every k in [0,n] ret[3*k+2]==-1 because it has no sense here.
138 * This parameter is kept only for compatibility with other methode listed above.
140 std::vector<int> MEDCoupling1GTUMesh::getDistributionOfTypes() const throw(INTERP_KERNEL::Exception)
142 std::vector<int> ret(3);
143 ret[0]=(int)getCellModelEnum(); ret[1]=getNumberOfCells(); ret[2]=-1;
148 * This method is the opposite of MEDCouplingUMesh::checkTypeConsistencyAndContig method. Given a list of cells in \a profile it returns a list of sub-profiles sorted by geo type.
149 * The result is put in the array \a idsPerType. In the returned parameter \a code, foreach i \a code[3*i+2] refers (if different from -1) to a location into the \a idsPerType.
150 * This method has 1 input \a profile and 3 outputs \a code \a idsInPflPerType and \a idsPerType.
152 * \param [out] code is a vector of size 3*n where n is the number of different geometric type in \a this \b reduced to the profile \a profile. \a code has exactly the same semantic than in MEDCouplingUMesh::checkTypeConsistencyAndContig method.
153 * \param [out] idsInPflPerType is a vector of size of different geometric type in the subpart defined by \a profile of \a this ( equal to \a code.size()/3). For each i,
154 * \a idsInPflPerType[i] stores the tuple ids in \a profile that correspond to the geometric type code[3*i+0]
155 * \param [out] idsPerType is a vector of size of different sub profiles needed to be defined to represent the profile \a profile for a given geometric type.
156 * This vector can be empty in case of all geometric type cells are fully covered in ascending in the given input \a profile.
158 * \warning for performance reasons no deep copy will be performed, if \a profile can been used as this in output parameters \a idsInPflPerType and \a idsPerType.
160 * \throw if \a profile has not exactly one component. It throws too, if \a profile contains some values not in [0,getNumberOfCells()) or if \a this is not fully defined
163 * - Before \a this has 3 cells \a profile contains [0,1,2]
164 * - After \a code contains [NORM_...,nbCells,-1], \a idsInPflPerType [[0,1,2]] and \a idsPerType is empty <br>
167 * - Before \a this has 3 cells \a profile contains [1,2]
168 * - After \a code contains [NORM_...,nbCells,0], \a idsInPflPerType [[0,1]] and \a idsPerType is [[1,2]] <br>
171 void MEDCoupling1GTUMesh::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsInPflPerType, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
174 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::splitProfilePerType : input profile is NULL !");
175 if(profile->getNumberOfComponents()!=1)
176 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::splitProfilePerType : input profile should have exactly one component !");
177 int nbTuples=profile->getNumberOfTuples();
178 int nbOfCells=getNumberOfCells();
179 code.resize(3); idsInPflPerType.resize(1);
180 code[0]=(int)getCellModelEnum(); code[1]=nbTuples;
181 idsInPflPerType.resize(1);
182 if(profile->isIdentity() && nbTuples==nbOfCells)
185 idsInPflPerType[0]=const_cast<DataArrayInt *>(profile); idsInPflPerType[0]->incrRef();
190 profile->checkAllIdsInRange(0,nbOfCells);
191 idsPerType.resize(1);
192 idsPerType[0]=const_cast<DataArrayInt *>(profile); idsPerType[0]->incrRef();
193 idsInPflPerType[0]=DataArrayInt::Range(0,nbTuples,1);
197 * This method tries to minimize at most the number of deep copy.
198 * So if \a idsPerType is not empty it can be returned directly (without copy, but with ref count incremented) in return.
200 * \sa MEDCouplingUMesh::checkTypeConsistencyAndContig
202 DataArrayInt *MEDCoupling1GTUMesh::checkTypeConsistencyAndContig(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
204 int nbOfCells=getNumberOfCells();
206 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : invalid input code should be exactly of size 3 !");
207 if(code[0]!=(int)getCellModelEnum())
209 std::ostringstream oss; oss << "MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : Mismatch of geometric type ! Asking for " << code[0] << " whereas the geometric type is \a this is " << getCellModelEnum() << " (" << _cm->getRepr() << ") !";
210 throw INTERP_KERNEL::Exception(oss.str().c_str());
214 if(code[1]==nbOfCells)
218 std::ostringstream oss; oss << "MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : mismatch between the number of cells in this (" << nbOfCells << ") and the number of non profile (" << code[1] << ") !";
219 throw INTERP_KERNEL::Exception(oss.str().c_str());
223 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : single geo type mesh ! 0 or -1 is expected at pos #2 of input code !");
224 if(idsPerType.size()!=1)
225 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : input code points to DataArrayInt #0 whereas the size of idsPerType is not equal to 1 !");
226 const DataArrayInt *pfl=idsPerType[0];
228 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : the input code points to a NULL DataArrayInt at rank 0 !");
229 if(pfl->getNumberOfComponents()!=1)
230 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : input profile should have exactly one component !");
231 pfl->checkAllIdsInRange(0,nbOfCells);
233 return const_cast<DataArrayInt *>(pfl);
236 void MEDCoupling1GTUMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception)
238 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
239 m->writeVTKLL(ofs,cellData,pointData);
242 std::string MEDCoupling1GTUMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exception)
244 return std::string("UnstructuredGrid");
247 std::size_t MEDCoupling1GTUMesh::getHeapMemorySize() const
249 return MEDCouplingPointSet::getHeapMemorySize();
252 bool MEDCoupling1GTUMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception)
254 if(!MEDCouplingPointSet::isEqualIfNotWhy(other,prec,reason))
257 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::isEqualIfNotWhy : input other pointer is null !");
258 const MEDCoupling1GTUMesh *otherC=dynamic_cast<const MEDCoupling1GTUMesh *>(other);
261 reason="mesh given in input is not castable in MEDCouplingSGTUMesh !";
266 reason="mismatch in geometric type !";
272 bool MEDCoupling1GTUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const
274 if(!MEDCouplingPointSet::isEqualWithoutConsideringStr(other,prec))
277 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::isEqualWithoutConsideringStr : input other pointer is null !");
278 const MEDCoupling1GTUMesh *otherC=dynamic_cast<const MEDCoupling1GTUMesh *>(other);
286 void MEDCoupling1GTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
288 MEDCouplingPointSet::checkCoherency();
291 DataArrayDouble *MEDCoupling1GTUMesh::getBarycenterAndOwner() const
293 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
294 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=m->getBarycenterAndOwner();
298 MEDCouplingFieldDouble *MEDCoupling1GTUMesh::getMeasureField(bool isAbs) const
300 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
301 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=m->getMeasureField(isAbs);
306 MEDCouplingFieldDouble *MEDCoupling1GTUMesh::getMeasureFieldOnNode(bool isAbs) const
308 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
309 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=m->getMeasureFieldOnNode(isAbs);
317 int MEDCoupling1GTUMesh::getCellContainingPoint(const double *pos, double eps) const
319 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
320 return m->getCellContainingPoint(pos,eps);
323 MEDCouplingFieldDouble *MEDCoupling1GTUMesh::buildOrthogonalField() const
325 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
326 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=m->buildOrthogonalField();
331 DataArrayInt *MEDCoupling1GTUMesh::getCellsInBoundingBox(const double *bbox, double eps) const
333 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
334 return m->getCellsInBoundingBox(bbox,eps);
337 DataArrayInt *MEDCoupling1GTUMesh::getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps)
339 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
340 return m->getCellsInBoundingBox(bbox,eps);
343 MEDCouplingPointSet *MEDCoupling1GTUMesh::buildFacePartOfMySelfNode(const int *start, const int *end, bool fullyIn) const
345 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
346 return m->buildFacePartOfMySelfNode(start,end,fullyIn);
349 DataArrayInt *MEDCoupling1GTUMesh::findBoundaryNodes() const
351 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
352 return m->findBoundaryNodes();
355 MEDCouplingPointSet *MEDCoupling1GTUMesh::buildBoundaryMesh(bool keepCoords) const
357 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
358 return m->buildBoundaryMesh(keepCoords);
361 void MEDCoupling1GTUMesh::findCommonCells(int compType, int startCellId, DataArrayInt *& commonCellsArr, DataArrayInt *& commonCellsIArr) const throw(INTERP_KERNEL::Exception)
363 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
364 m->findCommonCells(compType,startCellId,commonCellsArr,commonCellsIArr);
367 int MEDCoupling1GTUMesh::getNodalConnectivityLength() const throw(INTERP_KERNEL::Exception)
369 const DataArrayInt *c1(getNodalConnectivity());
371 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::getNodalConnectivityLength : no connectivity set !");
372 if(c1->getNumberOfComponents()!=1)
373 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::getNodalConnectivityLength : Nodal connectivity array set must have exactly one component !");
374 if(!c1->isAllocated())
375 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::getNodalConnectivityLength : Nodal connectivity array must be allocated !");
376 return c1->getNumberOfTuples();
380 * This method aggregates all the meshes in \a parts to put them in a single unstructured mesh (those returned).
381 * The order of cells is the returned instance is those in the order of instances in \a parts.
383 * \param [in] parts - all not null parts of single geo type meshes to be aggreagated having the same mesh dimension and same coordinates.
384 * \return MEDCouplingUMesh * - new object to be dealt by the caller.
386 * \throw If one element is null in \a parts.
387 * \throw If not all the parts do not have the same mesh dimension.
388 * \throw If not all the parts do not share the same coordinates.
389 * \throw If not all the parts have their connectivity set properly.
390 * \throw If \a parts is empty.
392 MEDCouplingUMesh *MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(const std::vector< const MEDCoupling1GTUMesh *>& parts) throw(INTERP_KERNEL::Exception)
395 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : input parts vector is empty !");
396 const MEDCoupling1GTUMesh *firstPart(parts[0]);
398 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : the first instance in input parts is null !");
399 const DataArrayDouble *coords(firstPart->getCoords());
400 int meshDim(firstPart->getMeshDimension());
401 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret(MEDCouplingUMesh::New(firstPart->getName(),meshDim)); ret->setDescription(firstPart->getDescription());
402 ret->setCoords(coords);
403 int nbOfCells(0),connSize(0);
404 for(std::vector< const MEDCoupling1GTUMesh *>::const_iterator it=parts.begin();it!=parts.end();it++)
407 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : presence of null pointer in input vector !");
408 if((*it)->getMeshDimension()!=meshDim)
409 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : all the instances in input vector must have same mesh dimension !");
410 if((*it)->getCoords()!=coords)
411 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : all the instances must share the same coordinates pointer !");
412 nbOfCells+=(*it)->getNumberOfCells();
413 connSize+=(*it)->getNodalConnectivityLength();
415 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New()),connI(DataArrayInt::New());
416 connI->alloc(nbOfCells+1,1); conn->alloc(connSize+nbOfCells,1);
417 int *c(conn->getPointer()),*ci(connI->getPointer()); *ci=0;
418 for(std::vector< const MEDCoupling1GTUMesh *>::const_iterator it=parts.begin();it!=parts.end();it++)
420 int curNbCells((*it)->getNumberOfCells());
421 int geoType((int)(*it)->getCellModelEnum());
422 const int *cinPtr((*it)->getNodalConnectivity()->begin());
423 const MEDCoupling1SGTUMesh *ps(dynamic_cast<const MEDCoupling1SGTUMesh *>(*it));
424 const MEDCoupling1DGTUMesh *pd(dynamic_cast<const MEDCoupling1DGTUMesh *>(*it));
427 int nNodesPerCell(ps->getNumberOfNodesPerCell());
428 for(int i=0;i<curNbCells;i++,ci++,cinPtr+=nNodesPerCell)
431 c=std::copy(cinPtr,cinPtr+nNodesPerCell,c);
432 ci[1]=ci[0]+nNodesPerCell+1;
437 const int *ciinPtr(pd->getNodalConnectivityIndex()->begin());
438 for(int i=0;i<curNbCells;i++,ci++,ciinPtr++)
441 c=std::copy(cinPtr+ciinPtr[0],cinPtr+ciinPtr[1],c);
442 ci[1]=ci[0]+ciinPtr[1]-ciinPtr[0]+1;
446 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : presence of instance which type is not in [MEDCoupling1SGTUMesh,MEDCoupling1DGTUMesh] !");
448 ret->setConnectivity(conn,connI,true);
454 MEDCoupling1SGTUMesh::MEDCoupling1SGTUMesh(const MEDCoupling1SGTUMesh& other, bool recDeepCpy):MEDCoupling1GTUMesh(other,recDeepCpy),_conn(other._conn)
458 const DataArrayInt *c(other._conn);
464 MEDCoupling1SGTUMesh::MEDCoupling1SGTUMesh(const char *name, const INTERP_KERNEL::CellModel& cm):MEDCoupling1GTUMesh(name,cm)
468 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception)
470 if(type==INTERP_KERNEL::NORM_ERROR)
471 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::New : NORM_ERROR is not a valid type to be used as base geometric type for a mesh !");
472 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
475 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::New : the input geometric type " << cm.getRepr() << " is dynamic ! Only static types are allowed here !";
476 throw INTERP_KERNEL::Exception(oss.str().c_str());
478 return new MEDCoupling1SGTUMesh(name,cm);
481 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception)
484 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::New : input mesh is null !");
485 std::set<INTERP_KERNEL::NormalizedCellType> gts(m->getAllGeoTypes());
487 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::New : input mesh must have exactly one geometric type !");
488 int geoType((int)*gts.begin());
489 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(MEDCoupling1SGTUMesh::New(m->getName(),*gts.begin()));
490 ret->setCoords(m->getCoords()); ret->setDescription(m->getDescription());
491 int nbCells(m->getNumberOfCells());
492 int nbOfNodesPerCell(ret->getNumberOfNodesPerCell());
493 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New()); conn->alloc(nbCells*nbOfNodesPerCell,1);
494 int *c(conn->getPointer());
495 const int *cin(m->getNodalConnectivity()->begin()),*ciin(m->getNodalConnectivityIndex()->begin());
496 for(int i=0;i<nbCells;i++,ciin++)
498 if(cin[ciin[0]]==geoType)
500 if(ciin[1]-ciin[0]==nbOfNodesPerCell+1)
501 c=std::copy(cin+ciin[0]+1,cin+ciin[1],c);
504 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::New(const MEDCouplingUMesh *m) : something is wrong in the input mesh at cell #" << i << " ! The size of cell is not those expected (" << nbOfNodesPerCell << ") !";
505 throw INTERP_KERNEL::Exception(oss.str().c_str());
510 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::New(const MEDCouplingUMesh *m) : something is wrong in the input mesh at cell #" << i << " ! The geometric type is not those expected !";
511 throw INTERP_KERNEL::Exception(oss.str().c_str());
514 ret->setNodalConnectivity(conn);
518 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::clone(bool recDeepCpy) const
520 return new MEDCoupling1SGTUMesh(*this,recDeepCpy);
524 * This method behaves mostly like MEDCoupling1SGTUMesh::deepCpy method, except that only nodal connectivity arrays are deeply copied.
525 * The coordinates are shared between \a this and the returned instance.
527 * \return MEDCouplingUMesh * - A new object instance holding the copy of \a this (deep for connectivity, shallow for coordiantes)
528 * \sa MEDCoupling1SGTUMesh::deepCpy
530 MEDCouplingPointSet *MEDCoupling1SGTUMesh::deepCpyConnectivityOnly() const throw(INTERP_KERNEL::Exception)
533 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(clone(false));
534 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(_conn->deepCpy());
535 ret->setNodalConnectivity(c);
539 void MEDCoupling1SGTUMesh::shallowCopyConnectivityFrom(const MEDCouplingPointSet *other) throw(INTERP_KERNEL::Exception)
542 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::shallowCopyConnectivityFrom : input pointer is null !");
543 const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
545 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::shallowCopyConnectivityFrom : input pointer is not an MEDCoupling1SGTUMesh instance !");
546 setNodalConnectivity(otherC->getNodalConnectivity());
549 void MEDCoupling1SGTUMesh::updateTime() const
551 MEDCoupling1GTUMesh::updateTime();
552 const DataArrayInt *c(_conn);
557 std::size_t MEDCoupling1SGTUMesh::getHeapMemorySize() const
560 const DataArrayInt *c(_conn);
562 ret+=c->getHeapMemorySize();
563 return MEDCoupling1GTUMesh::getHeapMemorySize()+ret;
566 MEDCouplingMesh *MEDCoupling1SGTUMesh::deepCpy() const
571 bool MEDCoupling1SGTUMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception)
574 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::isEqualIfNotWhy : input other pointer is null !");
575 std::ostringstream oss; oss.precision(15);
576 const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
579 reason="mesh given in input is not castable in MEDCoupling1SGTUMesh !";
582 if(!MEDCoupling1GTUMesh::isEqualIfNotWhy(other,prec,reason))
584 const DataArrayInt *c1(_conn),*c2(otherC->_conn);
589 reason="in connectivity of single static geometric type exactly one among this and other is null !";
592 if(!c1->isEqualIfNotWhy(*c2,reason))
594 reason.insert(0,"Nodal connectivity DataArrayInt differ : ");
600 bool MEDCoupling1SGTUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const
603 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::isEqualWithoutConsideringStr : input other pointer is null !");
604 const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
607 if(!MEDCoupling1GTUMesh::isEqualWithoutConsideringStr(other,prec))
609 const DataArrayInt *c1(_conn),*c2(otherC->_conn);
614 if(!c1->isEqualWithoutConsideringStr(*c2))
619 void MEDCoupling1SGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
621 MEDCouplingPointSet::checkCoherency();
622 const DataArrayInt *c1(_conn);
625 if(c1->getNumberOfComponents()!=1)
626 throw INTERP_KERNEL::Exception("Nodal connectivity array is expected to be with number of components set to one !");
627 if(c1->getInfoOnComponent(0)!="")
628 throw INTERP_KERNEL::Exception("Nodal connectivity array is expected to have no info on its single component !");
629 c1->checkAllocated();
632 throw INTERP_KERNEL::Exception("Nodal connectivity array not defined !");
635 void MEDCoupling1SGTUMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception)
638 const DataArrayInt *c1(_conn);
639 int nbOfTuples=c1->getNumberOfTuples();
640 int nbOfNodesPerCell=(int)_cm->getNumberOfNodes();
641 if(nbOfTuples%nbOfNodesPerCell!=0)
643 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::checkCoherency1 : the nb of tuples in conn is " << nbOfTuples << " and number of nodes per cell is " << nbOfNodesPerCell << ". But " << nbOfTuples << "%" << nbOfNodesPerCell << " !=0 !";
644 throw INTERP_KERNEL::Exception(oss.str().c_str());
646 int nbOfNodes=getNumberOfNodes();
647 int nbOfCells=nbOfTuples/nbOfNodesPerCell;
648 const int *w(c1->begin());
649 for(int i=0;i<nbOfCells;i++)
650 for(int j=0;j<nbOfNodesPerCell;j++,w++)
652 if(*w<0 || *w>=nbOfNodes)
654 std::ostringstream oss; oss << "At node #" << j << " of cell #" << i << ", is equal to " << *w << " must be in [0," << nbOfNodes << ") !";
655 throw INTERP_KERNEL::Exception(oss.str().c_str());
660 void MEDCoupling1SGTUMesh::checkCoherency2(double eps) const throw(INTERP_KERNEL::Exception)
662 checkCoherency1(eps);
665 int MEDCoupling1SGTUMesh::getNumberOfCells() const
667 int nbOfTuples=getNodalConnectivityLength();
668 int nbOfNodesPerCell=getNumberOfNodesPerCell();
669 if(nbOfTuples%nbOfNodesPerCell!=0)
671 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh:getNumberOfCells: : the nb of tuples in conn is " << nbOfTuples << " and number of nodes per cell is " << nbOfNodesPerCell << ". But " << nbOfTuples << "%" << nbOfNodesPerCell << " !=0 !";
672 throw INTERP_KERNEL::Exception(oss.str().c_str());
674 return nbOfTuples/nbOfNodesPerCell;
677 int MEDCoupling1SGTUMesh::getNumberOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
679 checkNonDynamicGeoType();
680 return (int)_cm->getNumberOfNodes();
683 DataArrayInt *MEDCoupling1SGTUMesh::computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
685 checkNonDynamicGeoType();
686 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
687 ret->alloc(getNumberOfCells(),1);
688 ret->fillWithValue((int)_cm->getNumberOfNodes());
692 DataArrayInt *MEDCoupling1SGTUMesh::computeNbOfFacesPerCell() const throw(INTERP_KERNEL::Exception)
694 checkNonDynamicGeoType();
695 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
696 ret->alloc(getNumberOfCells(),1);
697 ret->fillWithValue((int)_cm->getNumberOfSons());
701 void MEDCoupling1SGTUMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
703 int sz=getNumberOfNodesPerCell();
705 if(cellId>=0 && cellId<getNumberOfCells())
706 std::copy(_conn->begin()+cellId*sz,_conn->begin()+(cellId+1)*sz,conn.begin());
709 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getNodeIdsOfCell : request for cellId #" << cellId << " must be in [0," << getNumberOfCells() << ") !";
710 throw INTERP_KERNEL::Exception(oss.str().c_str());
714 void MEDCoupling1SGTUMesh::checkNonDynamicGeoType() const throw(INTERP_KERNEL::Exception)
717 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkNonDynamicGeoType : internal error ! the internal geo type is dynamic ! should be static !");
720 std::string MEDCoupling1SGTUMesh::simpleRepr() const
722 static const char msg0[]="No coordinates specified !";
723 std::ostringstream ret;
724 ret << "Single static geometic type (" << _cm->getRepr() << ") unstructured mesh with name : \"" << getName() << "\"\n";
725 ret << "Description of mesh : \"" << getDescription() << "\"\n";
727 double tt=getTime(tmpp1,tmpp2);
728 ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n";
729 ret << "Iteration : " << tmpp1 << " Order : " << tmpp2 << "\n";
730 ret << "Mesh dimension : " << getMeshDimension() << "\nSpace dimension : ";
733 const int spaceDim=getSpaceDimension();
734 ret << spaceDim << "\nInfo attached on space dimension : ";
735 for(int i=0;i<spaceDim;i++)
736 ret << "\"" << _coords->getInfoOnComponent(i) << "\" ";
741 ret << "Number of nodes : ";
743 ret << getNumberOfNodes() << "\n";
746 ret << "Number of cells : ";
747 if((const DataArrayInt *)_conn)
749 if(_conn->isAllocated())
751 if(_conn->getNumberOfComponents()==1)
752 ret << getNumberOfCells() << "\n";
754 ret << "Nodal connectivity array specified and allocated but with not exactly one component !" << "\n";
757 ret << "Nodal connectivity array specified but not allocated !" << "\n";
760 ret << "No connectivity specified !" << "\n";
761 ret << "Cell type : " << _cm->getRepr() << "\n";
765 std::string MEDCoupling1SGTUMesh::advancedRepr() const
767 std::ostringstream ret;
769 ret << "\nCoordinates array : \n___________________\n\n";
771 _coords->reprWithoutNameStream(ret);
773 ret << "No array set !\n";
774 ret << "\n\nConnectivity array : \n____________________\n\n";
776 if((const DataArrayInt *)_conn)
778 if(_conn->isAllocated())
780 if(_conn->getNumberOfComponents()==1)
782 int nbOfCells=getNumberOfCells();
783 int sz=getNumberOfNodesPerCell();
784 const int *connPtr=_conn->begin();
785 for(int i=0;i<nbOfCells;i++,connPtr+=sz)
787 ret << "Cell #" << i << " : ";
788 std::copy(connPtr,connPtr+sz,std::ostream_iterator<int>(ret," "));
793 ret << "Nodal connectivity array specified and allocated but with not exactly one component !" << "\n";
796 ret << "Nodal connectivity array specified but not allocated !" << "\n";
799 ret << "No connectivity specified !" << "\n";
803 DataArrayDouble *MEDCoupling1SGTUMesh::computeIsoBarycenterOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
805 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
806 int spaceDim=getSpaceDimension();
807 int nbOfCells=getNumberOfCells();//checkCoherency()
808 int nbOfNodes=getNumberOfNodes();
809 ret->alloc(nbOfCells,spaceDim);
810 double *ptToFill=ret->getPointer();
811 const double *coor=_coords->begin();
812 const int *nodal=_conn->begin();
813 int sz=getNumberOfNodesPerCell();
814 double coeff=1./(double)sz;
815 for(int i=0;i<nbOfCells;i++,ptToFill+=spaceDim)
817 std::fill(ptToFill,ptToFill+spaceDim,0.);
818 for(int j=0;j<sz;j++,nodal++)
819 if(*nodal>=0 && *nodal<nbOfNodes)
820 std::transform(coor+spaceDim*nodal[0],coor+spaceDim*(nodal[0]+1),ptToFill,ptToFill,std::plus<double>());
823 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::computeIsoBarycenterOfNodesPerCell : on cell #" << i << " presence of nodeId #" << *nodal << " should be in [0," << nbOfNodes << ") !";
824 throw INTERP_KERNEL::Exception(oss.str().c_str());
826 std::transform(ptToFill,ptToFill+spaceDim,ptToFill,std::bind2nd(std::multiplies<double>(),coeff));
831 void MEDCoupling1SGTUMesh::renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception)
833 int nbCells=getNumberOfCells();
834 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::New();
835 o2n->useArray(old2NewBg,false,C_DEALLOC,nbCells,1);
837 o2n=o2n->checkAndPreparePermutation();
839 const int *conn=_conn->begin();
840 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o=o2n->invertArrayO2N2N2O(nbCells);
841 const int *n2oPtr=n2o->begin();
842 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New();
843 newConn->alloc(_conn->getNumberOfTuples(),1);
844 newConn->copyStringInfoFrom(*_conn);
845 int sz=getNumberOfNodesPerCell();
847 int *newC=newConn->getPointer();
848 for(int i=0;i<nbCells;i++,newC+=sz)
851 std::copy(conn+pos*sz,conn+(pos+1)*sz,newC);
857 * Keeps from \a this only cells which constituing point id are in the ids specified by [\a begin,\a end).
858 * The resulting cell ids are stored at the end of the 'cellIdsKept' parameter.
859 * Parameter \a fullyIn specifies if a cell that has part of its nodes in ids array is kept or not.
860 * If \a fullyIn is true only cells whose ids are \b fully contained in [\a begin,\a end) tab will be kept.
862 * \param [in] begin input start of array of node ids.
863 * \param [in] end input end of array of node ids.
864 * \param [in] fullyIn input that specifies if all node ids must be in [\a begin,\a end) array to consider cell to be in.
865 * \param [in,out] cellIdsKeptArr array where all candidate cell ids are put at the end.
867 void MEDCoupling1SGTUMesh::fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const
869 int nbOfCells=getNumberOfCells();
870 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsKept=DataArrayInt::New(); cellIdsKept->alloc(0,1);
872 int sz=_conn->getMaxValue(tmp); sz=std::max(sz,0)+1;
873 std::vector<bool> fastFinder(sz,false);
874 for(const int *work=begin;work!=end;work++)
875 if(*work>=0 && *work<sz)
876 fastFinder[*work]=true;
877 const int *conn=_conn->begin();
878 int nbNodesPerCell=getNumberOfNodesPerCell();
879 for(int i=0;i<nbOfCells;i++,conn+=nbNodesPerCell)
882 for(int j=0;j<nbNodesPerCell;j++)
886 if(fastFinder[conn[j]])
889 if((ref==nbOfHit && fullyIn) || (nbOfHit!=0 && !fullyIn))
890 cellIdsKept->pushBackSilent(i);
892 cellIdsKeptArr=cellIdsKept.retn();
895 MEDCouplingMesh *MEDCoupling1SGTUMesh::mergeMyselfWith(const MEDCouplingMesh *other) const
897 if(other->getType()!=SINGLE_STATIC_GEO_TYPE_UNSTRUCTURED)
898 throw INTERP_KERNEL::Exception("Merge of umesh only available with umesh single static geo type each other !");
899 const MEDCoupling1SGTUMesh *otherC=static_cast<const MEDCoupling1SGTUMesh *>(other);
900 return Merge1SGTUMeshes(this,otherC);
903 MEDCouplingUMesh *MEDCoupling1SGTUMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception)
905 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New(getName(),getMeshDimension());
906 ret->setCoords(getCoords());
907 const int *nodalConn=_conn->begin();
908 int nbCells=getNumberOfCells();
909 int nbNodesPerCell=getNumberOfNodesPerCell();
910 int geoType=(int)getCellModelEnum();
911 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c=DataArrayInt::New(); c->alloc(nbCells*(nbNodesPerCell+1),1);
912 int *cPtr=c->getPointer();
913 for(int i=0;i<nbCells;i++,nodalConn+=nbNodesPerCell)
916 cPtr=std::copy(nodalConn,nodalConn+nbNodesPerCell,cPtr);
918 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cI=DataArrayInt::Range(0,(nbCells+1)*(nbNodesPerCell+1),nbNodesPerCell+1);
919 ret->setConnectivity(c,cI,true);
923 DataArrayInt *MEDCoupling1SGTUMesh::simplexize(int policy) throw(INTERP_KERNEL::Exception)
928 return simplexizePol0();
930 return simplexizePol1();
931 case (int) INTERP_KERNEL::PLANAR_FACE_5:
932 return simplexizePlanarFace5();
933 case (int) INTERP_KERNEL::PLANAR_FACE_6:
934 return simplexizePlanarFace6();
936 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::simplexize : unrecognized policy ! Must be :\n - 0 or 1 (only available for meshdim=2) \n - PLANAR_FACE_5, PLANAR_FACE_6 (only for meshdim=3)");
942 struct MEDCouplingAccVisit
944 MEDCouplingAccVisit():_new_nb_of_nodes(0) { }
945 int operator()(int val) { if(val!=-1) return _new_nb_of_nodes++; else return -1; }
946 int _new_nb_of_nodes;
952 * Finds nodes not used in any cell and returns an array giving a new id to every node
953 * by excluding the unused nodes, for which the array holds -1. The result array is
954 * a mapping in "Old to New" mode.
955 * \param [out] nbrOfNodesInUse - number of node ids present in the nodal connectivity.
956 * \return DataArrayInt * - a new instance of DataArrayInt. Its length is \a
957 * this->getNumberOfNodes(). It holds for each node of \a this mesh either -1
958 * if the node is unused or a new id else. The caller is to delete this
959 * array using decrRef() as it is no more needed.
960 * \throw If the coordinates array is not set.
961 * \throw If the nodal connectivity of cells is not defined.
962 * \throw If the nodal connectivity includes an invalid id.
964 DataArrayInt *MEDCoupling1SGTUMesh::getNodeIdsInUse(int& nbrOfNodesInUse) const throw(INTERP_KERNEL::Exception)
967 int nbOfNodes=getNumberOfNodes();
968 int nbOfCells=getNumberOfCells();
969 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
970 ret->alloc(nbOfNodes,1);
971 int *traducer=ret->getPointer();
972 std::fill(traducer,traducer+nbOfNodes,-1);
973 const int *conn=_conn->begin();
974 int nbNodesPerCell=getNumberOfNodesPerCell();
975 for(int i=0;i<nbOfCells;i++)
976 for(int j=0;j<nbNodesPerCell;j++,conn++)
977 if(*conn>=0 && *conn<nbOfNodes)
981 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getNodeIdsInUse : In cell #" << i << " presence of node id " << conn[j] << " not in [0," << nbOfNodes << ") !";
982 throw INTERP_KERNEL::Exception(oss.str().c_str());
984 nbrOfNodesInUse=(int)std::count(traducer,traducer+nbOfNodes,1);
985 std::transform(traducer,traducer+nbOfNodes,traducer,MEDCouplingAccVisit());
990 * Changes ids of nodes within the nodal connectivity arrays according to a permutation
991 * array in "Old to New" mode. The node coordinates array is \b not changed by this method.
992 * This method is a generalization of shiftNodeNumbersInConn().
993 * \warning This method performs no check of validity of new ids. **Use it with care !**
994 * \param [in] newNodeNumbersO2N - a permutation array, of length \a
995 * this->getNumberOfNodes(), in "Old to New" mode.
996 * See \ref MEDCouplingArrayRenumbering for more info on renumbering modes.
997 * \throw If the nodal connectivity of cells is not defined.
999 void MEDCoupling1SGTUMesh::renumberNodesInConn(const int *newNodeNumbersO2N)
1001 getNumberOfCells();//only to check that all is well defined.
1002 _conn->transformWithIndArr(newNodeNumbersO2N,newNodeNumbersO2N+getNumberOfNodes());
1006 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshes(const MEDCoupling1SGTUMesh *mesh1, const MEDCoupling1SGTUMesh *mesh2) throw(INTERP_KERNEL::Exception)
1008 std::vector<const MEDCoupling1SGTUMesh *> tmp(2);
1009 tmp[0]=const_cast<MEDCoupling1SGTUMesh *>(mesh1); tmp[1]=const_cast<MEDCoupling1SGTUMesh *>(mesh2);
1010 return Merge1SGTUMeshes(tmp);
1013 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshes(std::vector<const MEDCoupling1SGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
1015 std::size_t sz=a.size();
1017 return Merge1SGTUMeshesLL(a);
1018 for(std::size_t ii=0;ii<sz;ii++)
1021 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::Merge1SGTUMeshes : item #" << ii << " in input array of size "<< sz << " is empty !";
1022 throw INTERP_KERNEL::Exception(oss.str().c_str());
1024 const INTERP_KERNEL::CellModel *cm=&(a[0]->getCellModel());
1025 for(std::size_t ii=0;ii<sz;ii++)
1026 if(&(a[ii]->getCellModel())!=cm)
1027 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshes : all items must have the same geo type !");
1028 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> > bb(sz);
1029 std::vector< const MEDCoupling1SGTUMesh * > aa(sz);
1031 for(std::size_t i=0;i<sz && spaceDim==-3;i++)
1033 const MEDCoupling1SGTUMesh *cur=a[i];
1034 const DataArrayDouble *coo=cur->getCoords();
1036 spaceDim=coo->getNumberOfComponents();
1039 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshes : no spaceDim specified ! unable to perform merge !");
1040 for(std::size_t i=0;i<sz;i++)
1042 bb[i]=a[i]->buildSetInstanceFromThis(spaceDim);
1045 return Merge1SGTUMeshesLL(aa);
1049 * \throw If presence of a null instance in the input vector \a a.
1050 * \throw If a is empty
1052 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords(std::vector<const MEDCoupling1SGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
1055 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords : input array must be NON EMPTY !");
1056 std::vector<const MEDCoupling1SGTUMesh *>::const_iterator it=a.begin();
1058 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords : null instance in the first element of input vector !");
1059 std::vector<const DataArrayInt *> ncs(a.size());
1060 int nbOfCells=(*it)->getNumberOfCells();
1061 const DataArrayDouble *coords=(*it)->getCoords();
1062 const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel());
1063 int nbNodesPerCell=(*it)->getNumberOfNodesPerCell();
1064 ncs[0]=(*it)->getNodalConnectivity();
1066 for(int i=1;it!=a.end();i++,it++)
1069 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords : presence of a null instance in the input vector !");
1070 if(cm!=&((*it)->getCellModel()))
1071 throw INTERP_KERNEL::Exception("Geometric types mismatches, Merge1SGTUMeshes impossible !");
1072 (*it)->getNumberOfCells();//to check that all is OK
1073 ncs[i]=(*it)->getNodalConnectivity();
1074 if(coords!=(*it)->getCoords())
1075 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords : not lying on same coords !");
1077 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh("merge",*cm));
1078 ret->setCoords(coords);
1079 ret->_conn=DataArrayInt::Aggregate(ncs);
1084 * Assume that all instances in \a a are non null. If null it leads to a crash. That's why this method is assigned to be low level (LL)
1086 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshesLL(std::vector<const MEDCoupling1SGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
1089 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshes : input array must be NON EMPTY !");
1090 std::vector<const MEDCoupling1SGTUMesh *>::const_iterator it=a.begin();
1091 int nbOfCells=(*it)->getNumberOfCells();
1092 const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel());
1093 int nbNodesPerCell=(*it)->getNumberOfNodesPerCell();
1095 for(;it!=a.end();it++)
1097 if(cm!=&((*it)->getCellModel()))
1098 throw INTERP_KERNEL::Exception("Geometric types mismatches, Merge1SGTUMeshes impossible !");
1099 nbOfCells+=(*it)->getNumberOfCells();
1101 std::vector<const MEDCouplingPointSet *> aps(a.size());
1102 std::copy(a.begin(),a.end(),aps.begin());
1103 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> pts=MergeNodesArray(aps);
1104 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh("merge",*cm));
1105 ret->setCoords(pts);
1106 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c=DataArrayInt::New();
1107 c->alloc(nbOfCells*nbNodesPerCell,1);
1108 int *cPtr=c->getPointer();
1110 for(it=a.begin();it!=a.end();it++)
1112 int curConnLgth=(*it)->getNodalConnectivityLength();
1113 const int *curC=(*it)->_conn->begin();
1114 cPtr=std::transform(curC,curC+curConnLgth,cPtr,std::bind2nd(std::plus<int>(),offset));
1115 offset+=(*it)->getNumberOfNodes();
1118 ret->setNodalConnectivity(c);
1122 MEDCouplingPointSet *MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords(const int *begin, const int *end) const
1124 int ncell=getNumberOfCells();
1125 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName(),*_cm));
1126 ret->setCoords(_coords);
1127 std::size_t nbOfElemsRet=std::distance(begin,end);
1128 const int *inConn=_conn->getConstPointer();
1129 int sz=getNumberOfNodesPerCell();
1130 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> connRet=DataArrayInt::New(); connRet->alloc((int)nbOfElemsRet*sz,1);
1131 int *connPtr=connRet->getPointer();
1132 for(const int *work=begin;work!=end;work++,connPtr+=sz)
1134 if(*work>=0 && *work<ncell)
1135 std::copy(inConn+(work[0])*sz,inConn+(work[0]+1)*sz,connPtr);
1138 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords : On pos #" << std::distance(begin,work) << " input cell id =" << *work << " should be in [0," << ncell << ") !";
1139 throw INTERP_KERNEL::Exception(oss.str().c_str());
1143 ret->copyTinyInfoFrom(this);
1147 MEDCouplingPointSet *MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2(int start, int end, int step) const
1149 int ncell=getNumberOfCells();
1150 int nbOfElemsRet=DataArray::GetNumberOfItemGivenBESRelative(start,end,step,"MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2 : ");
1151 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName(),*_cm));
1152 ret->setCoords(_coords);
1153 const int *inConn=_conn->getConstPointer();
1154 int sz=getNumberOfNodesPerCell();
1155 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> connRet=DataArrayInt::New(); connRet->alloc((int)nbOfElemsRet*sz,1);
1156 int *connPtr=connRet->getPointer();
1158 for(int i=0;i<nbOfElemsRet;i++,connPtr+=sz,curId+=step)
1160 if(curId>=0 && curId<ncell)
1161 std::copy(inConn+curId*sz,inConn+(curId+1)*sz,connPtr);
1164 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2 : On pos #" << i << " input cell id =" << curId << " should be in [0," << ncell << ") !";
1165 throw INTERP_KERNEL::Exception(oss.str().c_str());
1169 ret->copyTinyInfoFrom(this);
1173 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception)
1175 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName(),*_cm));
1176 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1;
1177 const DataArrayInt *nodalConn(_conn);
1180 tmp1=DataArrayInt::New(); tmp1->alloc(0,1);
1187 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords=DataArrayDouble::New(); coords->alloc(0,spaceDim);
1188 ret->setCoords(coords);
1191 ret->setCoords(_coords);
1195 DataArrayInt *MEDCoupling1SGTUMesh::simplexizePol0() throw(INTERP_KERNEL::Exception)
1197 int nbOfCells=getNumberOfCells();
1198 if(getCellModelEnum()!=INTERP_KERNEL::NORM_QUAD4)
1199 return DataArrayInt::Range(0,nbOfCells,1);
1200 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(2*3*nbOfCells,1);
1201 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(2*nbOfCells,1);
1202 const int *c(_conn->begin());
1203 int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
1204 for(int i=0;i<nbOfCells;i++,c+=4,newConnPtr+=6,retPtr+=2)
1206 newConnPtr[0]=c[0]; newConnPtr[1]=c[1]; newConnPtr[2]=c[2];
1207 newConnPtr[3]=c[0]; newConnPtr[4]=c[2]; newConnPtr[5]=c[3];
1208 retPtr[0]=i; retPtr[1]=i;
1211 _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TRI3);
1216 DataArrayInt *MEDCoupling1SGTUMesh::simplexizePol1() throw(INTERP_KERNEL::Exception)
1218 int nbOfCells=getNumberOfCells();
1219 if(getCellModelEnum()!=INTERP_KERNEL::NORM_QUAD4)
1220 return DataArrayInt::Range(0,nbOfCells,1);
1221 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(2*3*nbOfCells,1);
1222 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(2*nbOfCells,1);
1223 const int *c(_conn->begin());
1224 int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
1225 for(int i=0;i<nbOfCells;i++,c+=4,newConnPtr+=6,retPtr+=2)
1227 newConnPtr[0]=c[0]; newConnPtr[1]=c[1]; newConnPtr[2]=c[3];
1228 newConnPtr[3]=c[1]; newConnPtr[4]=c[2]; newConnPtr[5]=c[3];
1229 retPtr[0]=i; retPtr[1]=i;
1232 _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TRI3);
1237 DataArrayInt *MEDCoupling1SGTUMesh::simplexizePlanarFace5() throw(INTERP_KERNEL::Exception)
1239 int nbOfCells=getNumberOfCells();
1240 if(getCellModelEnum()!=INTERP_KERNEL::NORM_HEXA8)
1241 return DataArrayInt::Range(0,nbOfCells,1);
1242 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(5*4*nbOfCells,1);
1243 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(5*nbOfCells,1);
1244 const int *c(_conn->begin());
1245 int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
1246 for(int i=0;i<nbOfCells;i++,c+=8,newConnPtr+=20,retPtr+=5)
1248 for(int j=0;j<20;j++)
1249 newConnPtr[j]=c[INTERP_KERNEL::SPLIT_NODES_5_WO[j]];
1250 retPtr[0]=i; retPtr[1]=i; retPtr[2]=i; retPtr[3]=i; retPtr[4]=i;
1253 _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TETRA4);
1258 DataArrayInt *MEDCoupling1SGTUMesh::simplexizePlanarFace6() throw(INTERP_KERNEL::Exception)
1260 int nbOfCells=getNumberOfCells();
1261 if(getCellModelEnum()!=INTERP_KERNEL::NORM_HEXA8)
1262 return DataArrayInt::Range(0,nbOfCells,1);
1263 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(6*4*nbOfCells,1);
1264 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(6*nbOfCells,1);
1265 const int *c(_conn->begin());
1266 int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
1267 for(int i=0;i<nbOfCells;i++,c+=8,newConnPtr+=24,retPtr+=6)
1269 for(int j=0;j<24;j++)
1270 newConnPtr[j]=c[INTERP_KERNEL::SPLIT_NODES_6_WO[j]];
1271 retPtr[0]=i; retPtr[1]=i; retPtr[2]=i; retPtr[3]=i; retPtr[4]=i; retPtr[5]=i;
1274 _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TETRA4);
1279 void MEDCoupling1SGTUMesh::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1281 stream << "MEDCoupling1SGTUMesh C++ instance at " << this << ". Type=" << _cm->getRepr() << ". Name : \"" << getName() << "\".";
1282 stream << " Mesh dimension : " << getMeshDimension() << ".";
1284 { stream << " No coordinates set !"; return ; }
1285 if(!_coords->isAllocated())
1286 { stream << " Coordinates set but not allocated !"; return ; }
1287 stream << " Space dimension : " << _coords->getNumberOfComponents() << "." << std::endl;
1288 stream << "Number of nodes : " << _coords->getNumberOfTuples() << ".";
1289 if(!(const DataArrayInt *)_conn)
1290 { stream << std::endl << "Nodal connectivity NOT set !"; return ; }
1291 if(_conn->isAllocated())
1293 if(_conn->getNumberOfComponents()==1)
1294 stream << std::endl << "Number of cells : " << getNumberOfCells() << ".";
1298 void MEDCoupling1SGTUMesh::checkFullyDefined() const throw(INTERP_KERNEL::Exception)
1300 if(!((const DataArrayInt *)_conn) || !((const DataArrayDouble *)_coords))
1301 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFullyDefined : part of this is not fully defined.");
1305 * First step of unserialization process.
1307 bool MEDCoupling1SGTUMesh::isEmptyMesh(const std::vector<int>& tinyInfo) const
1309 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::isEmptyMesh : not implemented yet !");
1313 * Checks if \a this and \a other meshes are geometrically equivalent with high
1314 * probability, else an exception is thrown. The meshes are considered equivalent if
1315 * (1) meshes contain the same number of nodes and the same number of elements of the
1316 * same types (2) three cells of the two meshes (first, last and middle) are based
1317 * on coincident nodes (with a specified precision).
1318 * \param [in] other - the mesh to compare with.
1319 * \param [in] prec - the precision used to compare nodes of the two meshes.
1320 * \throw If the two meshes do not match.
1322 void MEDCoupling1SGTUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception)
1324 MEDCouplingPointSet::checkFastEquivalWith(other,prec);
1325 const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
1327 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : Two meshes are not unstructured with single static geometric type !");
1328 const DataArrayInt *c1(_conn),*c2(otherC->_conn);
1332 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : presence of nodal connectivity only in one of the 2 meshes !");
1333 if((c1->isAllocated() && !c2->isAllocated()) || (!c1->isAllocated() && c2->isAllocated()))
1334 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : in nodal connectivity, only one is allocated !");
1335 if(c1->getNumberOfComponents()!=1 || c1->getNumberOfComponents()!=1)
1336 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : in nodal connectivity, must have 1 and only 1 component !");
1337 if(c1->getHashCode()!=c2->getHashCode())
1338 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : nodal connectivity differs");
1341 MEDCouplingPointSet *MEDCoupling1SGTUMesh::mergeMyselfWithOnSameCoords(const MEDCouplingPointSet *other) const
1344 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::mergeMyselfWithOnSameCoords : input other is null !");
1345 const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
1347 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::mergeMyselfWithOnSameCoords : the input other mesh is not of type single statuc geo type unstructured !");
1348 std::vector<const MEDCoupling1SGTUMesh *> ms(2);
1351 return Merge1SGTUMeshesOnSameCoords(ms);
1354 void MEDCoupling1SGTUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const throw(INTERP_KERNEL::Exception)
1356 checkFullyDefined();
1357 int nbOfNodes=getNumberOfNodes();
1358 int *revNodalIndxPtr=(int *)malloc((nbOfNodes+1)*sizeof(int));
1359 revNodalIndx->useArray(revNodalIndxPtr,true,C_DEALLOC,nbOfNodes+1,1);
1360 std::fill(revNodalIndxPtr,revNodalIndxPtr+nbOfNodes+1,0);
1361 const int *conn=_conn->begin();
1362 int nbOfCells=getNumberOfCells();
1363 int nbOfEltsInRevNodal=0;
1364 int nbOfNodesPerCell=getNumberOfNodesPerCell();
1365 for(int eltId=0;eltId<nbOfCells;eltId++)
1367 for(int j=0;j<nbOfNodesPerCell;j++,conn++)
1369 if(conn[0]>=0 && conn[0]<nbOfNodes)
1371 nbOfEltsInRevNodal++;
1372 revNodalIndxPtr[conn[0]+1]++;
1376 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getReverseNodalConnectivity : At cell #" << eltId << " presence of nodeId #" << conn[0] << " should be in [0," << nbOfNodes << ") !";
1377 throw INTERP_KERNEL::Exception(oss.str().c_str());
1381 std::transform(revNodalIndxPtr+1,revNodalIndxPtr+nbOfNodes+1,revNodalIndxPtr,revNodalIndxPtr+1,std::plus<int>());
1382 conn=_conn->begin();
1383 int *revNodalPtr=(int *)malloc((nbOfEltsInRevNodal)*sizeof(int));
1384 revNodal->useArray(revNodalPtr,true,C_DEALLOC,nbOfEltsInRevNodal,1);
1385 std::fill(revNodalPtr,revNodalPtr+nbOfEltsInRevNodal,-1);
1386 for(int eltId=0;eltId<nbOfCells;eltId++)
1388 for(int j=0;j<nbOfNodesPerCell;j++,conn++)
1390 *std::find_if(revNodalPtr+revNodalIndxPtr[*conn],revNodalPtr+revNodalIndxPtr[*conn+1],std::bind2nd(std::equal_to<int>(),-1))=eltId;
1396 * Use \a nodalConn array as nodal connectivity of \a this. The input \a nodalConn pointer can be null.
1398 void MEDCoupling1SGTUMesh::setNodalConnectivity(DataArrayInt *nodalConn) throw(INTERP_KERNEL::Exception)
1401 nodalConn->incrRef();
1407 * \return DataArrayInt * - the internal reference to the nodal connectivity. The caller is not reponsible to deallocate it.
1409 DataArrayInt *MEDCoupling1SGTUMesh::getNodalConnectivity() const throw(INTERP_KERNEL::Exception)
1411 const DataArrayInt *ret(_conn);
1412 return const_cast<DataArrayInt *>(ret);
1416 * Allocates memory to store an estimation of the given number of cells. Closer is the estimation to the number of cells effectively inserted,
1417 * less will be the needs to realloc. If the number of cells to be inserted is not known simply put 0 to this parameter.
1418 * If a nodal connectivity previouly existed before the call of this method, it will be reset.
1420 * \param [in] nbOfCells - estimation of the number of cell \a this mesh will contain.
1422 void MEDCoupling1SGTUMesh::allocateCells(int nbOfCells) throw(INTERP_KERNEL::Exception)
1425 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::allocateCells : the input number of cells should be >= 0 !");
1426 _conn=DataArrayInt::New();
1427 _conn->reserve(getNumberOfNodesPerCell()*nbOfCells);
1432 * Appends at the end of \a this a cell having nodal connectivity array defined in [ \a nodalConnOfCellBg, \a nodalConnOfCellEnd ).
1434 * \param [in] nodalConnOfCellBg - the begin (included) of nodal connectivity of the cell to add.
1435 * \param [in] nodalConnOfCellEnd - the end (excluded) of nodal connectivity of the cell to add.
1436 * \throw If the length of the input nodal connectivity array of the cell to add is not equal to number of nodes per cell relative to the unique geometric type
1437 * attached to \a this.
1438 * \thow If the nodal connectivity array in \a this is null (call MEDCoupling1SGTUMesh::allocateCells before).
1440 void MEDCoupling1SGTUMesh::insertNextCell(const int *nodalConnOfCellBg, const int *nodalConnOfCellEnd) throw(INTERP_KERNEL::Exception)
1442 int sz=(int)std::distance(nodalConnOfCellBg,nodalConnOfCellEnd);
1443 int ref=getNumberOfNodesPerCell();
1446 DataArrayInt *c(_conn);
1448 c->pushBackValsSilent(nodalConnOfCellBg,nodalConnOfCellEnd);
1450 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::insertNextCell : nodal connectivity array is null ! Call MEDCoupling1SGTUMesh::allocateCells before !");
1454 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::insertNextCell : input nodal size (" << sz << ") does not match number of nodes per cell of this (";
1455 oss << ref << ") !";
1456 throw INTERP_KERNEL::Exception(oss.str().c_str());
1462 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception)
1464 if(type==INTERP_KERNEL::NORM_ERROR)
1465 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::New : NORM_ERROR is not a valid type to be used as base geometric type for a mesh !");
1466 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
1469 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::New : the input geometric type " << cm.getRepr() << " is static ! Only dynamic types are allowed here !";
1470 throw INTERP_KERNEL::Exception(oss.str().c_str());
1472 return new MEDCoupling1DGTUMesh(name,cm);
1475 MEDCoupling1DGTUMesh::MEDCoupling1DGTUMesh(const char *name, const INTERP_KERNEL::CellModel& cm):MEDCoupling1GTUMesh(name,cm)
1479 MEDCoupling1DGTUMesh::MEDCoupling1DGTUMesh(const MEDCoupling1DGTUMesh& other, bool recDeepCpy):MEDCoupling1GTUMesh(other,recDeepCpy),_conn(other._conn)
1483 const DataArrayInt *c(other._conn);
1488 _conn_indx=c->deepCpy();
1492 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::clone(bool recDeepCpy) const
1494 return new MEDCoupling1DGTUMesh(*this,recDeepCpy);
1498 * This method behaves mostly like MEDCoupling1DGTUMesh::deepCpy method, except that only nodal connectivity arrays are deeply copied.
1499 * The coordinates are shared between \a this and the returned instance.
1501 * \return MEDCouplingUMesh * - A new object instance holding the copy of \a this (deep for connectivity, shallow for coordiantes)
1502 * \sa MEDCoupling1DGTUMesh::deepCpy
1504 MEDCouplingPointSet *MEDCoupling1DGTUMesh::deepCpyConnectivityOnly() const throw(INTERP_KERNEL::Exception)
1507 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(clone(false));
1508 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(_conn->deepCpy()),ci(_conn_indx->deepCpy());
1509 ret->setNodalConnectivity(c,ci);
1513 void MEDCoupling1DGTUMesh::updateTime() const
1515 MEDCoupling1GTUMesh::updateTime();
1516 const DataArrayInt *c(_conn);
1524 std::size_t MEDCoupling1DGTUMesh::getHeapMemorySize() const
1527 const DataArrayInt *c(_conn);
1529 ret+=c->getHeapMemorySize();
1532 ret+=c->getHeapMemorySize();
1533 return MEDCoupling1GTUMesh::getHeapMemorySize()+ret;
1536 MEDCouplingMesh *MEDCoupling1DGTUMesh::deepCpy() const
1541 bool MEDCoupling1DGTUMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception)
1544 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::isEqualIfNotWhy : input other pointer is null !");
1545 std::ostringstream oss; oss.precision(15);
1546 const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
1549 reason="mesh given in input is not castable in MEDCoupling1DGTUMesh !";
1552 if(!MEDCoupling1GTUMesh::isEqualIfNotWhy(other,prec,reason))
1554 const DataArrayInt *c1(_conn),*c2(otherC->_conn);
1559 reason="in connectivity of single dynamic geometric type exactly one among this and other is null !";
1562 if(!c1->isEqualIfNotWhy(*c2,reason))
1564 reason.insert(0,"Nodal connectivity DataArrayInt differs : ");
1567 c1=_conn_indx; c2=otherC->_conn_indx;
1572 reason="in connectivity index of single dynamic geometric type exactly one among this and other is null !";
1575 if(!c1->isEqualIfNotWhy(*c2,reason))
1577 reason.insert(0,"Nodal connectivity index DataArrayInt differs : ");
1583 bool MEDCoupling1DGTUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const
1586 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::isEqualWithoutConsideringStr : input other pointer is null !");
1587 const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
1590 if(!MEDCoupling1GTUMesh::isEqualWithoutConsideringStr(other,prec))
1592 const DataArrayInt *c1(_conn),*c2(otherC->_conn);
1597 if(!c1->isEqualWithoutConsideringStr(*c2))
1600 c1=_conn_indx; c2=otherC->_conn_indx;
1605 if(!c1->isEqualWithoutConsideringStr(*c2))
1611 * Checks if \a this and \a other meshes are geometrically equivalent with high
1612 * probability, else an exception is thrown. The meshes are considered equivalent if
1613 * (1) meshes contain the same number of nodes and the same number of elements of the
1614 * same types (2) three cells of the two meshes (first, last and middle) are based
1615 * on coincident nodes (with a specified precision).
1616 * \param [in] other - the mesh to compare with.
1617 * \param [in] prec - the precision used to compare nodes of the two meshes.
1618 * \throw If the two meshes do not match.
1620 void MEDCoupling1DGTUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception)
1622 MEDCouplingPointSet::checkFastEquivalWith(other,prec);
1623 const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
1625 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : Two meshes are not unstructured with single dynamic geometric type !");
1626 const DataArrayInt *c1(_conn),*c2(otherC->_conn);
1630 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : presence of nodal connectivity only in one of the 2 meshes !");
1631 if((c1->isAllocated() && !c2->isAllocated()) || (!c1->isAllocated() && c2->isAllocated()))
1632 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : in nodal connectivity, only one is allocated !");
1633 if(c1->getNumberOfComponents()!=1 || c1->getNumberOfComponents()!=1)
1634 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : in nodal connectivity, must have 1 and only 1 component !");
1635 if(c1->getHashCode()!=c2->getHashCode())
1636 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : nodal connectivity differs");
1638 c1=_conn_indx; c2=otherC->_conn_indx;
1642 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : presence of nodal connectivity index only in one of the 2 meshes !");
1643 if((c1->isAllocated() && !c2->isAllocated()) || (!c1->isAllocated() && c2->isAllocated()))
1644 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : in nodal connectivity index, only one is allocated !");
1645 if(c1->getNumberOfComponents()!=1 || c1->getNumberOfComponents()!=1)
1646 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : in nodal connectivity index, must have 1 and only 1 component !");
1647 if(c1->getHashCode()!=c2->getHashCode())
1648 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : nodal connectivity index differs");
1653 * If \a this pass this method, you are sure that connectivity arrays are not null, with exactly one component, no name, no component name, allocated.
1654 * In addition you are sure that the length of nodal connectivity index array is bigger than or equal to one.
1655 * In addition you are also sure that length of nodal connectivity is coherent with the content of the last value in the index array.
1657 void MEDCoupling1DGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
1659 MEDCouplingPointSet::checkCoherency();
1660 const DataArrayInt *c1(_conn);
1663 if(c1->getNumberOfComponents()!=1)
1664 throw INTERP_KERNEL::Exception("Nodal connectivity array is expected to be with number of components set to one !");
1665 if(c1->getInfoOnComponent(0)!="")
1666 throw INTERP_KERNEL::Exception("Nodal connectivity array is expected to have no info on its single component !");
1667 c1->checkAllocated();
1670 throw INTERP_KERNEL::Exception("Nodal connectivity array not defined !");
1672 int sz2=_conn->getNumberOfTuples();
1676 if(c1->getNumberOfComponents()!=1)
1677 throw INTERP_KERNEL::Exception("Nodal connectivity index array is expected to be with number of components set to one !");
1678 c1->checkAllocated();
1679 if(c1->getNumberOfTuples()<1)
1680 throw INTERP_KERNEL::Exception("Nodal connectivity index array is expected to have a a size of 1 at least !");
1681 if(c1->getInfoOnComponent(0)!="")
1682 throw INTERP_KERNEL::Exception("Nodal connectivity index array is expected to have no info on its single component !");
1683 int f=c1->front(),ll=c1->back();
1686 std::ostringstream oss; oss << "Nodal connectivity index array first value (" << f << ") is expected to be exactly in [0," << sz2 << ") !";
1687 throw INTERP_KERNEL::Exception(oss.str().c_str());
1691 std::ostringstream oss; oss << "Nodal connectivity index array last value (" << ll << ") is expected to be exactly in [0," << sz2 << "] !";
1692 throw INTERP_KERNEL::Exception(oss.str().c_str());
1696 std::ostringstream oss; oss << "Nodal connectivity index array looks very bad (not increasing monotonic) because front (" << f << ") is greater that back (" << ll << ") !";
1697 throw INTERP_KERNEL::Exception(oss.str().c_str());
1701 throw INTERP_KERNEL::Exception("Nodal connectivity index array not defined !");
1702 int szOfC1Exp=_conn_indx->back();
1705 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::checkCoherency : The expected length of nodal connectivity array regarding index is " << szOfC1Exp << " but the actual size of it is " << c1->getNumberOfTuples() << " !";
1706 throw INTERP_KERNEL::Exception(oss.str().c_str());
1710 void MEDCoupling1DGTUMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception)
1713 const DataArrayInt *c1(_conn),*c2(_conn_indx);
1714 if(!c2->isMonotonic(true))
1715 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkCoherency1 : the nodal connectivity index is expected to be increasing monotinic !");
1717 int nbOfTuples=c1->getNumberOfTuples();
1718 int nbOfNodes=getNumberOfNodes();
1719 const int *w(c1->begin());
1720 for(int i=0;i<nbOfTuples;i++,w++)
1722 if(*w==-1) continue;
1723 if(*w<0 || *w>=nbOfNodes)
1725 std::ostringstream oss; oss << "At pos #" << i << " of nodal connectivity array references to node id #" << *w << " must be in [0," << nbOfNodes << ") !";
1726 throw INTERP_KERNEL::Exception(oss.str().c_str());
1731 void MEDCoupling1DGTUMesh::checkCoherency2(double eps) const throw(INTERP_KERNEL::Exception)
1733 checkCoherency1(eps);
1736 int MEDCoupling1DGTUMesh::getNumberOfCells() const
1738 checkCoherency();//do not remove
1739 return _conn_indx->getNumberOfTuples()-1;
1743 * This method returns a newly allocated array containing this->getNumberOfCells() tuples and 1 component.
1744 * For each cell in \b this the number of nodes constituting cell is computed.
1745 * For each polyhedron cell, the sum of the number of nodes of each face constituting polyhedron cell is returned.
1746 * So for pohyhedrons some nodes can be counted several times in the returned result.
1748 * \return a newly allocated array
1750 DataArrayInt *MEDCoupling1DGTUMesh::computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
1753 _conn_indx->checkMonotonic(true);
1754 if(getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
1755 return _conn_indx->deltaShiftIndex();
1757 int nbOfCells=_conn_indx->getNumberOfTuples()-1;
1758 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
1759 ret->alloc(nbOfCells,1);
1760 int *retPtr=ret->getPointer();
1761 const int *ci=_conn_indx->begin(),*c=_conn->begin();
1762 for(int i=0;i<nbOfCells;i++,retPtr++,ci++)
1763 *retPtr=ci[1]-ci[0]-std::count(c+ci[0],c+ci[1],-1);
1768 * This method returns a newly allocated array containing this->getNumberOfCells() tuples and 1 component.
1769 * For each cell in \b this the number of faces constituting (entity of dimension this->getMeshDimension()-1) cell is computed.
1771 * \return a newly allocated array
1773 DataArrayInt *MEDCoupling1DGTUMesh::computeNbOfFacesPerCell() const throw(INTERP_KERNEL::Exception)
1776 _conn_indx->checkMonotonic(true);
1777 if(getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED && getCellModelEnum()!=INTERP_KERNEL::NORM_QPOLYG)
1778 return _conn_indx->deltaShiftIndex();
1779 if(getCellModelEnum()==INTERP_KERNEL::NORM_QPOLYG)
1781 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=_conn_indx->deltaShiftIndex();
1782 ret->applyDivideBy(2);
1786 int nbOfCells=_conn_indx->getNumberOfTuples()-1;
1787 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
1788 ret->alloc(nbOfCells,1);
1789 int *retPtr=ret->getPointer();
1790 const int *ci=_conn_indx->begin(),*c=_conn->begin();
1791 for(int i=0;i<nbOfCells;i++,retPtr++,ci++)
1792 *retPtr=std::count(c+ci[0],c+ci[1],-1)+1;
1796 void MEDCoupling1DGTUMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
1798 int nbOfCells=getNumberOfCells();//performs checks
1799 if(cellId>=0 && cellId<nbOfCells)
1801 int strt=_conn_indx->getIJ(cellId,0),stp=_conn_indx->getIJ(cellId+1,0);
1802 int nbOfNodes=stp-strt;
1804 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::getNodeIdsOfCell : the index array is invalid ! Should be increasing monotonic !");
1805 conn.resize(nbOfNodes);
1806 std::copy(_conn->begin()+strt,_conn->begin()+stp,conn.begin());
1810 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getNodeIdsOfCell : request for cellId #" << cellId << " must be in [0," << nbOfCells << ") !";
1811 throw INTERP_KERNEL::Exception(oss.str().c_str());
1815 std::string MEDCoupling1DGTUMesh::simpleRepr() const
1817 static const char msg0[]="No coordinates specified !";
1818 std::ostringstream ret;
1819 ret << "Single dynamic geometic type (" << _cm->getRepr() << ") unstructured mesh with name : \"" << getName() << "\"\n";
1820 ret << "Description of mesh : \"" << getDescription() << "\"\n";
1822 double tt=getTime(tmpp1,tmpp2);
1823 ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n";
1824 ret << "Iteration : " << tmpp1 << " Order : " << tmpp2 << "\n";
1825 ret << "Mesh dimension : " << getMeshDimension() << "\nSpace dimension : ";
1828 const int spaceDim=getSpaceDimension();
1829 ret << spaceDim << "\nInfo attached on space dimension : ";
1830 for(int i=0;i<spaceDim;i++)
1831 ret << "\"" << _coords->getInfoOnComponent(i) << "\" ";
1835 ret << msg0 << "\n";
1836 ret << "Number of nodes : ";
1838 ret << getNumberOfNodes() << "\n";
1840 ret << msg0 << "\n";
1841 ret << "Number of cells : ";
1843 try { checkCoherency(); } catch(INTERP_KERNEL::Exception& e)
1845 ret << "Nodal connectivity arrays are not set or badly set !\n";
1849 ret << getNumberOfCells() << "\n";
1850 ret << "Cell type : " << _cm->getRepr() << "\n";
1854 std::string MEDCoupling1DGTUMesh::advancedRepr() const
1856 std::ostringstream ret;
1857 ret << simpleRepr();
1858 ret << "\nCoordinates array : \n___________________\n\n";
1860 _coords->reprWithoutNameStream(ret);
1862 ret << "No array set !\n";
1863 ret << "\n\nNodal Connectivity : \n____________________\n\n";
1866 try { checkCoherency1(); } catch(INTERP_KERNEL::Exception& e)
1868 ret << "Nodal connectivity arrays are not set or badly set !\n";
1873 int nbOfCells=getNumberOfCells();
1874 const int *ci=_conn_indx->begin(),*c=_conn->begin();
1875 for(int i=0;i<nbOfCells;i++,ci++)
1877 ret << "Cell #" << i << " : ";
1878 std::copy(c+ci[0],c+ci[1],std::ostream_iterator<int>(ret," "));
1884 DataArrayDouble *MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
1886 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1887 int spaceDim=getSpaceDimension();
1888 int nbOfCells=getNumberOfCells();//checkCoherency()
1889 int nbOfNodes=getNumberOfNodes();
1890 ret->alloc(nbOfCells,spaceDim);
1891 double *ptToFill=ret->getPointer();
1892 const double *coor=_coords->begin();
1893 const int *nodal=_conn->begin(),*nodali=_conn_indx->begin();
1895 if(getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
1897 for(int i=0;i<nbOfCells;i++,ptToFill+=spaceDim,nodali++)
1899 std::fill(ptToFill,ptToFill+spaceDim,0.);
1900 if(nodali[0]<nodali[1])// >= to avoid division by 0.
1902 for(int j=nodali[0];j<nodali[1];j++,nodal++)
1904 if(*nodal>=0 && *nodal<nbOfNodes)
1905 std::transform(coor+spaceDim*nodal[0],coor+spaceDim*(nodal[0]+1),ptToFill,ptToFill,std::plus<double>());
1908 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell : on cell #" << i << " presence of nodeId #" << *nodal << " should be in [0," << nbOfNodes << ") !";
1909 throw INTERP_KERNEL::Exception(oss.str().c_str());
1911 std::transform(ptToFill,ptToFill+spaceDim,ptToFill,std::bind2nd(std::multiplies<double>(),1./(nodali[1]-nodali[0])));
1916 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell : at cell #" << i << " the nodal index array is invalid !";
1917 throw INTERP_KERNEL::Exception(oss.str().c_str());
1923 for(int i=0;i<nbOfCells;i++,ptToFill+=spaceDim,nodali++)
1925 std::fill(ptToFill,ptToFill+spaceDim,0.);
1926 if(nodali[0]<nodali[1])// >= to avoid division by 0.
1929 for(int j=nodali[0];j<nodali[1];j++,nodal++)
1931 if(*nodal==-1) continue;
1932 if(*nodal>=0 && *nodal<nbOfNodes)
1934 std::transform(coor+spaceDim*nodal[0],coor+spaceDim*(nodal[0]+1),ptToFill,ptToFill,std::plus<double>());
1939 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell (polyhedron) : on cell #" << i << " presence of nodeId #" << *nodal << " should be in [0," << nbOfNodes << ") !";
1940 throw INTERP_KERNEL::Exception(oss.str().c_str());
1944 std::transform(ptToFill,ptToFill+spaceDim,ptToFill,std::bind2nd(std::multiplies<double>(),1./nbOfNod));
1947 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell (polyhedron) : no nodes in cell #" << i << " !";
1948 throw INTERP_KERNEL::Exception(oss.str().c_str());
1953 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell (polyhedron) : at cell #" << i << " the nodal index array is invalid !";
1954 throw INTERP_KERNEL::Exception(oss.str().c_str());
1961 void MEDCoupling1DGTUMesh::renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception)
1963 int nbCells=getNumberOfCells();
1964 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::New();
1965 o2n->useArray(old2NewBg,false,C_DEALLOC,nbCells,1);
1967 o2n=o2n->checkAndPreparePermutation();
1969 const int *o2nPtr=o2n->getPointer();
1970 const int *conn=_conn->begin(),*conni=_conn_indx->begin();
1971 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New();
1972 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConnI=DataArrayInt::New();
1973 newConn->alloc(_conn->getNumberOfTuples(),1); newConnI->alloc(nbCells,1);
1974 newConn->copyStringInfoFrom(*_conn); newConnI->copyStringInfoFrom(*_conn_indx);
1976 int *newC=newConn->getPointer(),*newCI=newConnI->getPointer();
1977 for(int i=0;i<nbCells;i++)
1979 int newPos=o2nPtr[i];
1980 int sz=conni[i+1]-conni[i];
1985 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::renumberCells : the index nodal array is invalid for cell #" << i << " !";
1986 throw INTERP_KERNEL::Exception(oss.str().c_str());
1989 newConnI->computeOffsets2(); newCI=newConnI->getPointer();
1991 for(int i=0;i<nbCells;i++,conni++)
1993 int sz=conni[1]-conni[0];
1995 std::copy(conn+conni[0],conn+conni[1],newC+newCI[newp]);
1998 _conn_indx=newConnI;
2001 MEDCouplingMesh *MEDCoupling1DGTUMesh::mergeMyselfWith(const MEDCouplingMesh *other) const
2003 if(other->getType()!=SINGLE_DYNAMIC_GEO_TYPE_UNSTRUCTURED)
2004 throw INTERP_KERNEL::Exception("Merge of umesh only available with umesh single dynamic geo type each other !");
2005 const MEDCoupling1DGTUMesh *otherC=static_cast<const MEDCoupling1DGTUMesh *>(other);
2006 return Merge1DGTUMeshes(this,otherC);
2009 MEDCouplingUMesh *MEDCoupling1DGTUMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception)
2011 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New(getName(),getMeshDimension());
2012 ret->setCoords(getCoords());
2013 const int *nodalConn=_conn->begin(),*nodalConnI=_conn_indx->begin();
2014 int nbCells=getNumberOfCells();//checkCoherency
2015 int geoType=(int)getCellModelEnum();
2016 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c=DataArrayInt::New(); c->alloc(nbCells+_conn->getNumberOfTuples(),1);
2017 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cI=DataArrayInt::New(); cI->alloc(nbCells+1);
2018 int *cPtr=c->getPointer(),*ciPtr=cI->getPointer();
2020 for(int i=0;i<nbCells;i++,ciPtr++)
2022 int sz=nodalConnI[i+1]-nodalConnI[i];
2026 cPtr=std::copy(nodalConn+nodalConnI[i],nodalConn+nodalConnI[i+1],cPtr);
2027 ciPtr[1]=ciPtr[0]+sz+1;
2031 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::buildUnstructured : Invalid for nodal index for cell #" << i << " !";
2032 throw INTERP_KERNEL::Exception(oss.str().c_str());
2035 ret->setConnectivity(c,cI,true);
2040 * Do nothing for the moment, because there is no policy that allows to split polygons, polyhedrons ... into simplexes
2042 DataArrayInt *MEDCoupling1DGTUMesh::simplexize(int policy) throw(INTERP_KERNEL::Exception)
2044 int nbOfCells=getNumberOfCells();
2045 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
2046 ret->alloc(nbOfCells,1);
2051 void MEDCoupling1DGTUMesh::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
2053 stream << "MEDCoupling1DGTUMesh C++ instance at " << this << ". Type=" << _cm->getRepr() << ". Name : \"" << getName() << "\".";
2054 stream << " Mesh dimension : " << getMeshDimension() << ".";
2056 { stream << " No coordinates set !"; return ; }
2057 if(!_coords->isAllocated())
2058 { stream << " Coordinates set but not allocated !"; return ; }
2059 stream << " Space dimension : " << _coords->getNumberOfComponents() << "." << std::endl;
2060 stream << "Number of nodes : " << _coords->getNumberOfTuples() << ".";
2062 try { checkCoherency(); } catch(INTERP_KERNEL::Exception& e)
2064 stream << std::endl << "Nodal connectivity NOT set properly !\n";
2068 stream << std::endl << "Number of cells : " << getNumberOfCells() << ".";
2071 void MEDCoupling1DGTUMesh::shallowCopyConnectivityFrom(const MEDCouplingPointSet *other) throw(INTERP_KERNEL::Exception)
2074 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::shallowCopyConnectivityFrom : input pointer is null !");
2075 const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
2077 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::shallowCopyConnectivityFrom : input pointer is not an MEDCoupling1DGTUMesh instance !");
2078 setNodalConnectivity(otherC->getNodalConnectivity(),otherC->getNodalConnectivityIndex());
2081 MEDCouplingPointSet *MEDCoupling1DGTUMesh::mergeMyselfWithOnSameCoords(const MEDCouplingPointSet *other) const
2084 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::mergeMyselfWithOnSameCoords : input other is null !");
2085 const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
2087 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::mergeMyselfWithOnSameCoords : the input other mesh is not of type single statuc geo type unstructured !");
2088 std::vector<const MEDCoupling1DGTUMesh *> ms(2);
2091 return Merge1DGTUMeshesOnSameCoords(ms);
2094 MEDCouplingPointSet *MEDCoupling1DGTUMesh::buildPartOfMySelfKeepCoords(const int *begin, const int *end) const
2097 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName(),*_cm));
2098 ret->setCoords(_coords);
2099 DataArrayInt *c=0,*ci=0;
2100 MEDCouplingUMesh::ExtractFromIndexedArrays(begin,end,_conn,_conn_indx,c,ci);
2101 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cSafe(c),ciSafe(ci);
2102 ret->setNodalConnectivity(c,ci);
2106 MEDCouplingPointSet *MEDCoupling1DGTUMesh::buildPartOfMySelfKeepCoords2(int start, int end, int step) const
2109 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName(),*_cm));
2110 ret->setCoords(_coords);
2111 DataArrayInt *c=0,*ci=0;
2112 MEDCouplingUMesh::ExtractFromIndexedArrays2(start,end,step,_conn,_conn_indx,c,ci);
2113 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cSafe(c),ciSafe(ci);
2114 ret->setNodalConnectivity(c,ci);
2118 void MEDCoupling1DGTUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const throw(INTERP_KERNEL::Exception)
2120 checkFullyDefined();
2121 int nbOfNodes=getNumberOfNodes();
2122 int *revNodalIndxPtr=(int *)malloc((nbOfNodes+1)*sizeof(int));
2123 revNodalIndx->useArray(revNodalIndxPtr,true,C_DEALLOC,nbOfNodes+1,1);
2124 std::fill(revNodalIndxPtr,revNodalIndxPtr+nbOfNodes+1,0);
2125 const int *conn=_conn->begin(),*conni=_conn_indx->begin();
2126 int nbOfCells=getNumberOfCells();
2127 int nbOfEltsInRevNodal=0;
2128 for(int eltId=0;eltId<nbOfCells;eltId++)
2130 int nbOfNodesPerCell=conni[eltId+1]-conni[eltId];
2131 if(nbOfNodesPerCell>=0)
2133 for(int j=0;j<nbOfNodesPerCell;j++)
2135 int nodeId=conn[conni[eltId]+j];
2136 if(nodeId==-1) continue;
2137 if(nodeId>=0 && nodeId<nbOfNodes)
2139 nbOfEltsInRevNodal++;
2140 revNodalIndxPtr[nodeId+1]++;
2144 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::getReverseNodalConnectivity : At cell #" << eltId << " presence of nodeId #" << conn[0] << " should be in [0," << nbOfNodes << ") !";
2145 throw INTERP_KERNEL::Exception(oss.str().c_str());
2151 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::getReverseNodalConnectivity : At cell #" << eltId << "nodal connectivity is invalid !";
2152 throw INTERP_KERNEL::Exception(oss.str().c_str());
2155 std::transform(revNodalIndxPtr+1,revNodalIndxPtr+nbOfNodes+1,revNodalIndxPtr,revNodalIndxPtr+1,std::plus<int>());
2156 conn=_conn->begin();
2157 int *revNodalPtr=(int *)malloc((nbOfEltsInRevNodal)*sizeof(int));
2158 revNodal->useArray(revNodalPtr,true,C_DEALLOC,nbOfEltsInRevNodal,1);
2159 std::fill(revNodalPtr,revNodalPtr+nbOfEltsInRevNodal,-1);
2160 for(int eltId=0;eltId<nbOfCells;eltId++)
2162 int nbOfNodesPerCell=conni[eltId+1]-conni[eltId];
2163 for(int j=0;j<nbOfNodesPerCell;j++)
2165 int nodeId=conn[conni[eltId]+j];
2167 *std::find_if(revNodalPtr+revNodalIndxPtr[nodeId],revNodalPtr+revNodalIndxPtr[nodeId+1],std::bind2nd(std::equal_to<int>(),-1))=eltId;
2172 void MEDCoupling1DGTUMesh::checkFullyDefined() const throw(INTERP_KERNEL::Exception)
2174 if(!((const DataArrayInt *)_conn) || !((const DataArrayInt *)_conn_indx) || !((const DataArrayDouble *)_coords))
2175 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFullyDefined : part of this is not fully defined.");
2178 bool MEDCoupling1DGTUMesh::isEmptyMesh(const std::vector<int>& tinyInfo) const
2180 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::isEmptyMesh : not implemented yet !");
2184 * Finds nodes not used in any cell and returns an array giving a new id to every node
2185 * by excluding the unused nodes, for which the array holds -1. The result array is
2186 * a mapping in "Old to New" mode.
2187 * \param [out] nbrOfNodesInUse - number of node ids present in the nodal connectivity.
2188 * \return DataArrayInt * - a new instance of DataArrayInt. Its length is \a
2189 * this->getNumberOfNodes(). It holds for each node of \a this mesh either -1
2190 * if the node is unused or a new id else. The caller is to delete this
2191 * array using decrRef() as it is no more needed.
2192 * \throw If the coordinates array is not set.
2193 * \throw If the nodal connectivity of cells is not defined.
2194 * \throw If the nodal connectivity includes an invalid id.
2196 DataArrayInt *MEDCoupling1DGTUMesh::getNodeIdsInUse(int& nbrOfNodesInUse) const throw(INTERP_KERNEL::Exception)
2199 int nbOfNodes=getNumberOfNodes();
2200 int nbOfCells=getNumberOfCells();//checkCoherency
2201 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
2202 ret->alloc(nbOfNodes,1);
2203 int *traducer=ret->getPointer();
2204 std::fill(traducer,traducer+nbOfNodes,-1);
2205 const int *conn=_conn->begin(),*conni(_conn_indx->begin());
2206 for(int i=0;i<nbOfCells;i++,conni++)
2208 int nbNodesPerCell=conni[1]-conni[0];
2209 for(int j=0;j<nbNodesPerCell;j++)
2211 int nodeId=conn[conni[0]+j];
2212 if(nodeId==-1) continue;
2213 if(nodeId>=0 && nodeId<nbOfNodes)
2217 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::getNodeIdsInUse : In cell #" << i << " presence of node id " << nodeId << " not in [0," << nbOfNodes << ") !";
2218 throw INTERP_KERNEL::Exception(oss.str().c_str());
2222 nbrOfNodesInUse=(int)std::count(traducer,traducer+nbOfNodes,1);
2223 std::transform(traducer,traducer+nbOfNodes,traducer,MEDCouplingAccVisit());
2228 * Changes ids of nodes within the nodal connectivity arrays according to a permutation
2229 * array in "Old to New" mode. The node coordinates array is \b not changed by this method.
2230 * This method is a generalization of shiftNodeNumbersInConn().
2231 * \warning This method performs no check of validity of new ids. **Use it with care !**
2232 * \param [in] newNodeNumbersO2N - a permutation array, of length \a
2233 * this->getNumberOfNodes(), in "Old to New" mode.
2234 * See \ref MEDCouplingArrayRenumbering for more info on renumbering modes.
2235 * \throw If the nodal connectivity of cells is not defined.
2237 void MEDCoupling1DGTUMesh::renumberNodesInConn(const int *newNodeNumbersO2N)
2239 getNumberOfCells();//only to check that all is well defined.
2241 int nbElemsIn=getNumberOfNodes();
2242 int nbOfTuples=_conn->getNumberOfTuples();
2243 int *pt=_conn->getPointer();
2244 for(int i=0;i<nbOfTuples;i++,pt++)
2246 if(*pt==-1) continue;
2247 if(*pt>=0 && *pt<nbElemsIn)
2248 *pt=newNodeNumbersO2N[*pt];
2251 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::renumberNodesInConn : error on tuple #" << i << " value is " << *pt << " and indirectionnal array as a size equal to " << nbElemsIn;
2252 throw INTERP_KERNEL::Exception(oss.str().c_str());
2255 _conn->declareAsNew();
2261 * Keeps from \a this only cells which constituing point id are in the ids specified by [\a begin,\a end).
2262 * The resulting cell ids are stored at the end of the 'cellIdsKept' parameter.
2263 * Parameter \a fullyIn specifies if a cell that has part of its nodes in ids array is kept or not.
2264 * If \a fullyIn is true only cells whose ids are \b fully contained in [\a begin,\a end) tab will be kept.
2266 * \param [in] begin input start of array of node ids.
2267 * \param [in] end input end of array of node ids.
2268 * \param [in] fullyIn input that specifies if all node ids must be in [\a begin,\a end) array to consider cell to be in.
2269 * \param [in,out] cellIdsKeptArr array where all candidate cell ids are put at the end.
2271 void MEDCoupling1DGTUMesh::fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const
2273 int nbOfCells=getNumberOfCells();
2274 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsKept=DataArrayInt::New(); cellIdsKept->alloc(0,1);
2276 int sz=_conn->getMaxValue(tmp); sz=std::max(sz,0)+1;
2277 std::vector<bool> fastFinder(sz,false);
2278 for(const int *work=begin;work!=end;work++)
2279 if(*work>=0 && *work<sz)
2280 fastFinder[*work]=true;
2281 const int *conn=_conn->begin(),*conni=_conn_indx->begin();
2282 for(int i=0;i<nbOfCells;i++,conni++)
2284 int ref=0,nbOfHit=0;
2285 int nbNodesPerCell=conni[1]-conni[0];
2286 if(nbNodesPerCell>=0)
2288 for(int j=0;j<nbNodesPerCell;j++)
2290 int nodeId=conn[conni[0]+j];
2294 if(fastFinder[nodeId])
2301 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::fillCellIdsToKeepFromNodeIds : invalid index array for cell #" << i << " !";
2302 throw INTERP_KERNEL::Exception(oss.str().c_str());
2304 if((ref==nbOfHit && fullyIn) || (nbOfHit!=0 && !fullyIn))
2305 cellIdsKept->pushBackSilent(i);
2307 cellIdsKeptArr=cellIdsKept.retn();
2310 void MEDCoupling1DGTUMesh::allocateCells(int nbOfCells) throw(INTERP_KERNEL::Exception)
2313 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::allocateCells : the input number of cells should be >= 0 !");
2314 _conn=DataArrayInt::New();
2315 _conn->reserve(nbOfCells*3);
2316 _conn_indx=DataArrayInt::New();
2317 _conn_indx->reserve(nbOfCells+1); _conn_indx->pushBackSilent(0);
2322 * Appends at the end of \a this a cell having nodal connectivity array defined in [ \a nodalConnOfCellBg, \a nodalConnOfCellEnd ).
2324 * \param [in] nodalConnOfCellBg - the begin (included) of nodal connectivity of the cell to add.
2325 * \param [in] nodalConnOfCellEnd - the end (excluded) of nodal connectivity of the cell to add.
2326 * \throw If the length of the input nodal connectivity array of the cell to add is not equal to number of nodes per cell relative to the unique geometric type
2327 * attached to \a this.
2328 * \thow If the nodal connectivity array in \a this is null (call MEDCoupling1SGTUMesh::allocateCells before).
2330 void MEDCoupling1DGTUMesh::insertNextCell(const int *nodalConnOfCellBg, const int *nodalConnOfCellEnd) throw(INTERP_KERNEL::Exception)
2332 int sz=(int)std::distance(nodalConnOfCellBg,nodalConnOfCellEnd);
2333 DataArrayInt *c(_conn),*c2(_conn_indx);
2337 if(pos==c->getNumberOfTuples())
2339 c->pushBackValsSilent(nodalConnOfCellBg,nodalConnOfCellEnd);
2340 c2->pushBackSilent(pos+sz);
2344 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::insertNextCell : The nodal index array (end=" << pos << ") mismatches with nodal array (length=" << c->getNumberOfTuples() << ") !";
2345 throw INTERP_KERNEL::Exception(oss.str().c_str());
2349 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::insertNextCell : nodal connectivity array is null ! Call MEDCoupling1DGTUMesh::allocateCells before !");
2352 void MEDCoupling1DGTUMesh::setNodalConnectivity(DataArrayInt *nodalConn, DataArrayInt *nodalConnIndex) throw(INTERP_KERNEL::Exception)
2355 nodalConn->incrRef();
2358 nodalConnIndex->incrRef();
2359 _conn_indx=nodalConnIndex;
2364 * \return DataArrayInt * - the internal reference to the nodal connectivity. The caller is not reponsible to deallocate it.
2366 DataArrayInt *MEDCoupling1DGTUMesh::getNodalConnectivity() const throw(INTERP_KERNEL::Exception)
2368 const DataArrayInt *ret(_conn);
2369 return const_cast<DataArrayInt *>(ret);
2373 * \return DataArrayInt * - the internal reference to the nodal connectivity index. The caller is not reponsible to deallocate it.
2375 DataArrayInt *MEDCoupling1DGTUMesh::getNodalConnectivityIndex() const throw(INTERP_KERNEL::Exception)
2377 const DataArrayInt *ret(_conn_indx);
2378 return const_cast<DataArrayInt *>(ret);
2382 * See the definition of the nodal connectivity pack \ref MEDCoupling1DGTUMesh::isPacked "here".
2383 * This method tries to build a new instance geometrically equivalent to \a this, by limiting at most the number of new object (nodal connectivity).
2384 * Geometrically the returned mesh is equal to \a this. So if \a this is already packed, the return value is a shallow copy of \a this.
2386 * Whatever the status of pack of \a this, the coordinates array of the returned newly created instance is the same than those in \a this.
2388 * \param [out] isShallowCpyOfNodalConnn - tells if the returned instance share the same pair of nodal connectivity arrays (true) or if nodal
2389 * connectivity arrays are different (false)
2390 * \return a new object to be managed by the caller.
2392 * \sa MEDCoupling1DGTUMesh::retrievePackedNodalConnectivity, MEDCoupling1DGTUMesh::isPacked
2394 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::copyWithNodalConnectivityPacked(bool& isShallowCpyOfNodalConnn) const throw(INTERP_KERNEL::Exception)
2396 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName(),*_cm));
2397 DataArrayInt *nc=0,*nci=0;
2398 isShallowCpyOfNodalConnn=retrievePackedNodalConnectivity(nc,nci);
2399 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ncs(nc),ncis(nci);
2400 ret->_conn=ncs; ret->_conn_indx=ncis;
2401 ret->setCoords(getCoords());
2406 * This method allows to compute, if needed, the packed nodal connectivity pair.
2407 * Indeed, it is possible to store in \a this a nodal connectivity array bigger than ranges convered by nodal connectivity index array.
2408 * It is typically the case when nodalConnIndx starts with an id greater than 0, and finishes with id less than number of tuples in \c this->_conn.
2410 * If \a this looks packed (the front of nodal connectivity index equal to 0 and back of connectivity index equal to number of tuple of nodal connectivity array)
2411 * true will be returned and respectively \a this->_conn and \a this->_conn_indx (with ref counter incremented). This is the classical case.
2413 * If nodal connectivity index points to a subpart of nodal connectivity index the packed pair of arrays will be computed (new objects) and returned and false
2416 * This method return 3 elements.
2417 * \param [out] nodalConn - a pointer that can be equal to \a this->_conn if true is returned (general case). Whatever the value of return parameter
2418 * this pointer can be seen as a new object, that is to managed by the caller.
2419 * \param [out] nodalConnIndx - a pointer that can be equal to \a this->_conn_indx if true is returned (general case). Whatever the value of return parameter
2420 * this pointer can be seen as a new object, that is to managed by the caller.
2421 * \return bool - an indication of the content of the 2 output parameters. If true, \a this looks packed (general case), if true, \a this is not packed then
2422 * output parameters are newly created objects.
2424 * \throw if \a this does not pass MEDCoupling1DGTUMesh::checkCoherency test
2426 bool MEDCoupling1DGTUMesh::retrievePackedNodalConnectivity(DataArrayInt *&nodalConn, DataArrayInt *&nodalConnIndx) const throw(INTERP_KERNEL::Exception)
2428 if(isPacked())//performs the checkCoherency
2430 const DataArrayInt *c0(_conn),*c1(_conn_indx);
2431 nodalConn=const_cast<DataArrayInt *>(c0); nodalConnIndx=const_cast<DataArrayInt *>(c1);
2432 nodalConn->incrRef(); nodalConnIndx->incrRef();
2435 int bg=_conn_indx->front(),end=_conn_indx->back();
2436 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nc(_conn->selectByTupleId2(bg,end,1));
2437 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nci(_conn_indx->deepCpy());
2438 nci->applyLin(1,-bg);
2439 nodalConn=nc.retn(); nodalConnIndx=nci.retn();
2444 * If \a this looks packed (the front of nodal connectivity index equal to 0 and back of connectivity index equal to number of tuple of nodal connectivity array)
2445 * true will be returned and respectively \a this->_conn and \a this->_conn_indx (with ref counter incremented). This is the classical case.
2446 * If nodal connectivity index points to a subpart of nodal connectivity index false will be returned.
2447 * \return bool - true if \a this looks packed, false is not.
2449 * \throw if \a this does not pass MEDCoupling1DGTUMesh::checkCoherency test
2451 bool MEDCoupling1DGTUMesh::isPacked() const throw(INTERP_KERNEL::Exception)
2454 return _conn_indx->front()==0 && _conn_indx->back()==_conn->getNumberOfTuples();
2457 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::Merge1DGTUMeshes(const MEDCoupling1DGTUMesh *mesh1, const MEDCoupling1DGTUMesh *mesh2) throw(INTERP_KERNEL::Exception)
2459 std::vector<const MEDCoupling1DGTUMesh *> tmp(2);
2460 tmp[0]=const_cast<MEDCoupling1DGTUMesh *>(mesh1); tmp[1]=const_cast<MEDCoupling1DGTUMesh *>(mesh2);
2461 return Merge1DGTUMeshes(tmp);
2464 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::Merge1DGTUMeshes(std::vector<const MEDCoupling1DGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
2466 std::size_t sz=a.size();
2468 return Merge1DGTUMeshesLL(a);
2469 for(std::size_t ii=0;ii<sz;ii++)
2472 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::Merge1DGTUMeshes : item #" << ii << " in input array of size "<< sz << " is empty !";
2473 throw INTERP_KERNEL::Exception(oss.str().c_str());
2475 const INTERP_KERNEL::CellModel *cm=&(a[0]->getCellModel());
2476 for(std::size_t ii=0;ii<sz;ii++)
2477 if(&(a[ii]->getCellModel())!=cm)
2478 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshes : all items must have the same geo type !");
2479 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> > bb(sz);
2480 std::vector< const MEDCoupling1DGTUMesh * > aa(sz);
2482 for(std::size_t i=0;i<sz && spaceDim==-3;i++)
2484 const MEDCoupling1DGTUMesh *cur=a[i];
2485 const DataArrayDouble *coo=cur->getCoords();
2487 spaceDim=coo->getNumberOfComponents();
2490 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshes : no spaceDim specified ! unable to perform merge !");
2491 for(std::size_t i=0;i<sz;i++)
2493 bb[i]=a[i]->buildSetInstanceFromThis(spaceDim);
2496 return Merge1DGTUMeshesLL(aa);
2500 * \throw If presence of a null instance in the input vector \a a.
2501 * \throw If a is empty
2503 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords(std::vector<const MEDCoupling1DGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
2506 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords : input array must be NON EMPTY !");
2507 std::vector<const MEDCoupling1DGTUMesh *>::const_iterator it=a.begin();
2509 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords : null instance in the first element of input vector !");
2510 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> > objs(a.size());
2511 std::vector<const DataArrayInt *> ncs(a.size()),ncis(a.size());
2512 int nbOfCells=(*it)->getNumberOfCells();
2513 const DataArrayDouble *coords=(*it)->getCoords();
2514 const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel());
2516 objs[0]=(*it)->copyWithNodalConnectivityPacked(tmp);
2517 ncs[0]=objs[0]->getNodalConnectivity(); ncis[0]=objs[0]->getNodalConnectivityIndex();
2519 for(int i=1;it!=a.end();i++,it++)
2522 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords : presence of null instance !");
2523 if(cm!=&((*it)->getCellModel()))
2524 throw INTERP_KERNEL::Exception("Geometric types mismatches, Merge1DGTUMeshes impossible !");
2525 (*it)->getNumberOfCells();//to check that all is OK
2526 objs[i]=(*it)->copyWithNodalConnectivityPacked(tmp);
2527 ncs[i]=objs[i]->getNodalConnectivity(); ncis[i]=objs[i]->getNodalConnectivityIndex();
2528 if(coords!=(*it)->getCoords())
2529 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords : not lying on same coords !");
2531 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh("merge",*cm));
2532 ret->setCoords(coords);
2533 ret->_conn=DataArrayInt::Aggregate(ncs);
2534 ret->_conn_indx=DataArrayInt::AggregateIndexes(ncis);
2539 * Assume that all instances in \a a are non null. If null it leads to a crash. That's why this method is assigned to be low level (LL)
2541 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::Merge1DGTUMeshesLL(std::vector<const MEDCoupling1DGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
2544 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshes : input array must be NON EMPTY !");
2545 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> > objs(a.size());
2546 std::vector<const DataArrayInt *> ncs(a.size()),ncis(a.size());
2547 std::vector<const MEDCoupling1DGTUMesh *>::const_iterator it=a.begin();
2548 std::vector<int> nbNodesPerElt(a.size());
2549 int nbOfCells=(*it)->getNumberOfCells();
2551 objs[0]=(*it)->copyWithNodalConnectivityPacked(tmp);
2552 ncs[0]=objs[0]->getNodalConnectivity(); ncis[0]=objs[0]->getNodalConnectivityIndex();
2554 int prevNbOfNodes=(*it)->getNumberOfNodes();
2555 const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel());
2557 for(int i=1;it!=a.end();i++,it++)
2559 if(cm!=&((*it)->getCellModel()))
2560 throw INTERP_KERNEL::Exception("Geometric types mismatches, Merge1DGTUMeshes impossible !");
2561 objs[i]=(*it)->copyWithNodalConnectivityPacked(tmp);
2562 ncs[i]=objs[i]->getNodalConnectivity(); ncis[i]=objs[i]->getNodalConnectivityIndex();
2563 nbOfCells+=(*it)->getNumberOfCells();
2564 nbNodesPerElt[i]=nbNodesPerElt[i-1]+prevNbOfNodes;
2565 prevNbOfNodes=(*it)->getNumberOfNodes();
2567 std::vector<const MEDCouplingPointSet *> aps(a.size());
2568 std::copy(a.begin(),a.end(),aps.begin());
2569 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> pts=MergeNodesArray(aps);
2570 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh("merge",*cm));
2571 ret->setCoords(pts);
2572 ret->_conn=AggregateNodalConnAndShiftNodeIds(ncs,nbNodesPerElt);
2573 ret->_conn_indx=DataArrayInt::AggregateIndexes(ncis);
2577 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception)
2579 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName(),*_cm));
2580 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1,tmp2;
2581 const DataArrayInt *nodalConn(_conn),*nodalConnI(_conn_indx);
2584 tmp1=DataArrayInt::New(); tmp1->alloc(0,1);
2592 tmp2=DataArrayInt::New(); tmp2->alloc(1,1); tmp2->setIJ(0,0,0);
2596 ret->_conn_indx=tmp2;
2600 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords=DataArrayDouble::New(); coords->alloc(0,spaceDim);
2601 ret->setCoords(coords);
2604 ret->setCoords(_coords);
2609 * This method performs an aggregation of \a nodalConns (as DataArrayInt::Aggregate does) but in addition of that a shift is applied on the
2610 * values contained in \a nodalConns using corresponding offset specified in input \a offsetInNodeIdsPerElt.
2611 * But it also manage the values -1, that have a semantic in MEDCoupling1DGTUMesh class (separator for polyhedron).
2613 * \param [in] nodalConns - a list of nodal connectivity arrays same size than \a offsetInNodeIdsPerElt.
2614 * \param [in] offsetInNodeIdsPerElt - a list of offsets to apply.
2615 * \return DataArrayInt * - A new object (to be managed by the caller) that is the result of the aggregation.
2616 * \throw If \a nodalConns or \a offsetInNodeIdsPerElt are empty.
2617 * \throw If \a nodalConns and \a offsetInNodeIdsPerElt have not the same size.
2618 * \throw If presence of null pointer in \a nodalConns.
2619 * \throw If presence of not allocated or array with not exactly one component in \a nodalConns.
2621 DataArrayInt *MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds(const std::vector<const DataArrayInt *>& nodalConns, const std::vector<int>& offsetInNodeIdsPerElt) throw(INTERP_KERNEL::Exception)
2623 std::size_t sz1(nodalConns.size()),sz2(offsetInNodeIdsPerElt.size());
2625 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds : input vectors do not have the same size !");
2627 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds : empty vectors in input !");
2629 for(std::vector<const DataArrayInt *>::const_iterator it=nodalConns.begin();it!=nodalConns.end();it++)
2632 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds : presence of null pointer in input vector !");
2633 if(!(*it)->isAllocated())
2634 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds : presence of non allocated array in input vector !");
2635 if((*it)->getNumberOfComponents()!=1)
2636 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds : presence of array with not exactly one component !");
2637 nbOfTuples+=(*it)->getNumberOfTuples();
2639 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbOfTuples,1);
2640 int *pt=ret->getPointer();
2642 for(std::vector<const DataArrayInt *>::const_iterator it=nodalConns.begin();it!=nodalConns.end();it++,i++)
2644 int curNbt=(*it)->getNumberOfTuples();
2645 const int *inPt=(*it)->begin();
2646 int offset=offsetInNodeIdsPerElt[i];
2647 for(int j=0;j<curNbt;j++,pt++)
2658 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::New(const MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception)
2661 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::New : input mesh is null !");
2662 std::set<INTERP_KERNEL::NormalizedCellType> gts(m->getAllGeoTypes());
2664 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::New : input mesh must have exactly one geometric type !");
2665 int geoType((int)*gts.begin());
2666 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(MEDCoupling1DGTUMesh::New(m->getName(),*gts.begin()));
2667 ret->setCoords(m->getCoords()); ret->setDescription(m->getDescription());
2668 int nbCells(m->getNumberOfCells());
2669 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New()),connI(DataArrayInt::New());
2670 conn->alloc(m->getMeshLength()-nbCells,1); connI->alloc(nbCells+1,1);
2671 int *c(conn->getPointer()),*ci(connI->getPointer()); *ci=0;
2672 const int *cin(m->getNodalConnectivity()->begin()),*ciin(m->getNodalConnectivityIndex()->begin());
2673 for(int i=0;i<nbCells;i++,ciin++,ci++)
2675 if(cin[ciin[0]]==geoType)
2677 if(ciin[1]-ciin[0]>=1)
2679 c=std::copy(cin+ciin[0]+1,cin+ciin[1],c);
2680 ci[1]=ci[0]+ciin[1]-ciin[0]-1;
2684 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::New(const MEDCouplingUMesh *m) : something is wrong in the input mesh at cell #" << i << " ! The size of cell is not >=0 !";
2685 throw INTERP_KERNEL::Exception(oss.str().c_str());
2690 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::New(const MEDCouplingUMesh *m) : something is wrong in the input mesh at cell #" << i << " ! The geometric type is not those expected !";
2691 throw INTERP_KERNEL::Exception(oss.str().c_str());
2694 ret->setNodalConnectivity(conn,connI);