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 const INTERP_KERNEL::CellModel& MEDCoupling1GTUMesh::getCellModel() const throw(INTERP_KERNEL::Exception)
54 INTERP_KERNEL::NormalizedCellType MEDCoupling1GTUMesh::getCellModelEnum() const throw(INTERP_KERNEL::Exception)
56 return _cm->getEnum();
59 int MEDCoupling1GTUMesh::getMeshDimension() const
61 return (int)_cm->getDimension();
65 * This method returns a newly allocated array containing cell ids (ascendingly sorted) whose geometric type are equal to type.
66 * This method does not throw exception if geometric type \a type is not in \a this.
67 * This method throws an INTERP_KERNEL::Exception if meshdimension of \b this is not equal to those of \b type.
68 * The coordinates array is not considered here.
70 * \param [in] type the geometric type
71 * \return cell ids in this having geometric type \a type.
73 DataArrayInt *MEDCoupling1GTUMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
75 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
76 if(type==getCellModelEnum())
77 ret->alloc(getNumberOfCells(),1);
85 * Returns nb of cells having the geometric type \a type. No throw if no cells in \a this has the geometric type \a type.
87 int MEDCoupling1GTUMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
89 return type==getCellModelEnum()?getNumberOfCells():0;
93 * Returns a type of a cell by its id.
94 * \param [in] cellId - the id of the cell of interest.
95 * \return INTERP_KERNEL::NormalizedCellType - enumeration item describing the cell type.
96 * \throw If \a cellId is invalid. Valid range is [0, \a this->getNumberOfCells() ).
98 INTERP_KERNEL::NormalizedCellType MEDCoupling1GTUMesh::getTypeOfCell(int cellId) const
100 if(cellId>=0 && cellId<getNumberOfCells())
101 return getCellModelEnum();
102 std::ostringstream oss; oss << "MEDCoupling1GTUMesh::getTypeOfCell : Requesting type of cell #" << cellId << " but it should be in [0," << getNumberOfCells() << ") !";
103 throw INTERP_KERNEL::Exception(oss.str().c_str());
107 * Returns a set of all cell types available in \a this mesh.
108 * \return std::set<INTERP_KERNEL::NormalizedCellType> - the set of cell types.
109 * \warning this method does not throw any exception even if \a this is not defined.
111 std::set<INTERP_KERNEL::NormalizedCellType> MEDCoupling1GTUMesh::getAllGeoTypes() const
113 std::set<INTERP_KERNEL::NormalizedCellType> ret;
114 ret.insert(getCellModelEnum());
119 * This method expects that \a this is sorted by types. If not an exception will be thrown.
120 * This method returns in the same format as code (see MEDCouplingUMesh::checkTypeConsistencyAndContig or MEDCouplingUMesh::splitProfilePerType) how
121 * \a this is composed in cell types.
122 * The returned array is of size 3*n where n is the number of different types present in \a this.
123 * For every k in [0,n] ret[3*k+2]==-1 because it has no sense here.
124 * This parameter is kept only for compatibility with other methode listed above.
126 std::vector<int> MEDCoupling1GTUMesh::getDistributionOfTypes() const throw(INTERP_KERNEL::Exception)
128 std::vector<int> ret(3);
129 ret[0]=(int)getCellModelEnum(); ret[1]=getNumberOfCells(); ret[2]=-1;
134 * 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.
135 * 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.
136 * This method has 1 input \a profile and 3 outputs \a code \a idsInPflPerType and \a idsPerType.
138 * \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.
139 * \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,
140 * \a idsInPflPerType[i] stores the tuple ids in \a profile that correspond to the geometric type code[3*i+0]
141 * \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.
142 * This vector can be empty in case of all geometric type cells are fully covered in ascending in the given input \a profile.
144 * \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.
146 * \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
149 * - Before \a this has 3 cells \a profile contains [0,1,2]
150 * - After \a code contains [NORM_...,nbCells,-1], \a idsInPflPerType [[0,1,2]] and \a idsPerType is empty <br>
153 * - Before \a this has 3 cells \a profile contains [1,2]
154 * - After \a code contains [NORM_...,nbCells,0], \a idsInPflPerType [[0,1]] and \a idsPerType is [[1,2]] <br>
157 void MEDCoupling1GTUMesh::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsInPflPerType, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
160 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::splitProfilePerType : input profile is NULL !");
161 if(profile->getNumberOfComponents()!=1)
162 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::splitProfilePerType : input profile should have exactly one component !");
163 int nbTuples=profile->getNumberOfTuples();
164 int nbOfCells=getNumberOfCells();
165 code.resize(3); idsInPflPerType.resize(1);
166 code[0]=(int)getCellModelEnum(); code[1]=nbTuples;
167 idsInPflPerType.resize(1);
168 if(profile->isIdentity() && nbTuples==nbOfCells)
171 idsInPflPerType[0]=const_cast<DataArrayInt *>(profile); idsInPflPerType[0]->incrRef();
176 profile->checkAllIdsInRange(0,nbOfCells);
177 idsPerType.resize(1);
178 idsPerType[0]=const_cast<DataArrayInt *>(profile); idsPerType[0]->incrRef();
179 idsInPflPerType[0]=DataArrayInt::Range(0,nbTuples,1);
183 * This method tries to minimize at most the number of deep copy.
184 * So if \a idsPerType is not empty it can be returned directly (without copy, but with ref count incremented) in return.
186 * \sa MEDCouplingUMesh::checkTypeConsistencyAndContig
188 DataArrayInt *MEDCoupling1GTUMesh::checkTypeConsistencyAndContig(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
190 int nbOfCells=getNumberOfCells();
192 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : invalid input code should be exactly of size 3 !");
193 if(code[0]!=(int)getCellModelEnum())
195 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() << ") !";
196 throw INTERP_KERNEL::Exception(oss.str().c_str());
200 if(code[1]==nbOfCells)
204 std::ostringstream oss; oss << "MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : mismatch between the number of cells in this (" << nbOfCells << ") and the number of non profile (" << code[1] << ") !";
205 throw INTERP_KERNEL::Exception(oss.str().c_str());
209 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : single geo type mesh ! 0 or -1 is expected at pos #2 of input code !");
210 if(idsPerType.size()!=1)
211 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : input code points to DataArrayInt #0 whereas the size of idsPerType is not equal to 1 !");
212 const DataArrayInt *pfl=idsPerType[0];
214 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : the input code points to a NULL DataArrayInt at rank 0 !");
215 if(pfl->getNumberOfComponents()!=1)
216 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::checkTypeConsistencyAndContig : input profile should have exactly one component !");
217 pfl->checkAllIdsInRange(0,nbOfCells);
219 return const_cast<DataArrayInt *>(pfl);
222 void MEDCoupling1GTUMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception)
224 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
225 m->writeVTKLL(ofs,cellData,pointData);
228 std::string MEDCoupling1GTUMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exception)
230 return std::string("UnstructuredGrid");
233 std::size_t MEDCoupling1GTUMesh::getHeapMemorySize() const
235 return MEDCouplingPointSet::getHeapMemorySize();
238 bool MEDCoupling1GTUMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception)
240 if(!MEDCouplingPointSet::isEqualIfNotWhy(other,prec,reason))
243 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::isEqualIfNotWhy : input other pointer is null !");
244 const MEDCoupling1GTUMesh *otherC=dynamic_cast<const MEDCoupling1GTUMesh *>(other);
247 reason="mesh given in input is not castable in MEDCouplingSGTUMesh !";
252 reason="mismatch in geometric type !";
258 bool MEDCoupling1GTUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const
260 if(!MEDCouplingPointSet::isEqualWithoutConsideringStr(other,prec))
263 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::isEqualWithoutConsideringStr : input other pointer is null !");
264 const MEDCoupling1GTUMesh *otherC=dynamic_cast<const MEDCoupling1GTUMesh *>(other);
272 void MEDCoupling1GTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
274 MEDCouplingPointSet::checkCoherency();
277 DataArrayDouble *MEDCoupling1GTUMesh::getBarycenterAndOwner() const
279 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
280 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=m->getBarycenterAndOwner();
284 MEDCouplingFieldDouble *MEDCoupling1GTUMesh::getMeasureField(bool isAbs) const
286 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
287 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=m->getMeasureField(isAbs);
292 MEDCouplingFieldDouble *MEDCoupling1GTUMesh::getMeasureFieldOnNode(bool isAbs) const
294 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
295 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=m->getMeasureFieldOnNode(isAbs);
303 int MEDCoupling1GTUMesh::getCellContainingPoint(const double *pos, double eps) const
305 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
306 return m->getCellContainingPoint(pos,eps);
309 MEDCouplingFieldDouble *MEDCoupling1GTUMesh::buildOrthogonalField() const
311 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
312 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=m->buildOrthogonalField();
317 DataArrayInt *MEDCoupling1GTUMesh::getCellsInBoundingBox(const double *bbox, double eps) const
319 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
320 return m->getCellsInBoundingBox(bbox,eps);
323 DataArrayInt *MEDCoupling1GTUMesh::getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps)
325 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
326 return m->getCellsInBoundingBox(bbox,eps);
329 MEDCouplingPointSet *MEDCoupling1GTUMesh::buildFacePartOfMySelfNode(const int *start, const int *end, bool fullyIn) const
331 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
332 return m->buildFacePartOfMySelfNode(start,end,fullyIn);
335 DataArrayInt *MEDCoupling1GTUMesh::findBoundaryNodes() const
337 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
338 return m->findBoundaryNodes();
341 MEDCouplingPointSet *MEDCoupling1GTUMesh::buildBoundaryMesh(bool keepCoords) const
343 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
344 return m->buildBoundaryMesh(keepCoords);
347 void MEDCoupling1GTUMesh::findCommonCells(int compType, int startCellId, DataArrayInt *& commonCellsArr, DataArrayInt *& commonCellsIArr) const throw(INTERP_KERNEL::Exception)
349 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=buildUnstructured();
350 m->findCommonCells(compType,startCellId,commonCellsArr,commonCellsIArr);
353 int MEDCoupling1GTUMesh::getNodalConnectivityLength() const throw(INTERP_KERNEL::Exception)
355 const DataArrayInt *c1(getNodalConnectivity());
357 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::getNodalConnectivityLength : no connectivity set !");
358 if(c1->getNumberOfComponents()!=1)
359 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::getNodalConnectivityLength : Nodal connectivity array set must have exactly one component !");
360 if(!c1->isAllocated())
361 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::getNodalConnectivityLength : Nodal connectivity array must be allocated !");
362 return c1->getNumberOfTuples();
366 * This method aggregates all the meshes in \a parts to put them in a single unstructured mesh (those returned).
367 * The order of cells is the returned instance is those in the order of instances in \a parts.
369 * \param [in] parts - all not null parts of single geo type meshes to be aggreagated having the same mesh dimension and same coordinates.
370 * \return MEDCouplingUMesh * - new object to be dealt by the caller.
372 * \throw If one element is null in \a parts.
373 * \throw If not all the parts do not have the same mesh dimension.
374 * \throw If not all the parts do not share the same coordinates.
375 * \throw If not all the parts have their connectivity set properly.
376 * \throw If \a parts is empty.
378 MEDCouplingUMesh *MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(const std::vector< const MEDCoupling1GTUMesh *>& parts) throw(INTERP_KERNEL::Exception)
381 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : input parts vector is empty !");
382 const MEDCoupling1GTUMesh *firstPart(parts[0]);
384 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : the first instance in input parts is null !");
385 const DataArrayDouble *coords(firstPart->getCoords());
386 int meshDim(firstPart->getMeshDimension());
387 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret(MEDCouplingUMesh::New(firstPart->getName(),meshDim));
388 ret->setCoords(coords);
389 int nbOfCells(0),connSize(0);
390 for(std::vector< const MEDCoupling1GTUMesh *>::const_iterator it=parts.begin();it!=parts.end();it++)
393 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : presence of null pointer in input vector !");
394 if((*it)->getMeshDimension()!=meshDim)
395 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : all the instances in input vector must have same mesh dimension !");
396 if((*it)->getCoords()!=coords)
397 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : all the instances must share the same coordinates pointer !");
398 nbOfCells+=(*it)->getNumberOfCells();
399 connSize+=(*it)->getNodalConnectivityLength();
401 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New()),connI(DataArrayInt::New());
402 connI->alloc(nbOfCells+1,1); conn->alloc(connSize+nbOfCells,1);
403 int *c(conn->getPointer()),*ci(connI->getPointer()); *ci=0;
404 for(std::vector< const MEDCoupling1GTUMesh *>::const_iterator it=parts.begin();it!=parts.end();it++)
406 int curNbCells((*it)->getNumberOfCells());
407 int geoType((int)(*it)->getCellModelEnum());
408 const int *cinPtr((*it)->getNodalConnectivity()->begin());
409 const MEDCoupling1SGTUMesh *ps(dynamic_cast<const MEDCoupling1SGTUMesh *>(*it));
410 const MEDCoupling1DGTUMesh *pd(dynamic_cast<const MEDCoupling1DGTUMesh *>(*it));
413 int nNodesPerCell(ps->getNumberOfNodesPerCell());
414 for(int i=0;i<curNbCells;i++,ci++,cinPtr+=nNodesPerCell)
417 c=std::copy(cinPtr,cinPtr+nNodesPerCell,c);
418 ci[1]=ci[0]+nNodesPerCell+1;
423 const int *ciinPtr(pd->getNodalConnectivityIndex()->begin());
424 for(int i=0;i<curNbCells;i++,ci++,ciinPtr++)
427 c=std::copy(cinPtr+ciinPtr[0],cinPtr+ciinPtr[1],c);
428 ci[1]=ci[0]+ciinPtr[1]-ciinPtr[0]+1;
432 throw INTERP_KERNEL::Exception("MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh : presence of instance which type is not in [MEDCoupling1SGTUMesh,MEDCoupling1DGTUMesh] !");
434 ret->setConnectivity(conn,connI,true);
440 MEDCoupling1SGTUMesh::MEDCoupling1SGTUMesh(const MEDCoupling1SGTUMesh& other, bool recDeepCpy):MEDCoupling1GTUMesh(other,recDeepCpy),_conn(other._conn)
444 const DataArrayInt *c(other._conn);
450 MEDCoupling1SGTUMesh::MEDCoupling1SGTUMesh(const char *name, const INTERP_KERNEL::CellModel& cm):MEDCoupling1GTUMesh(name,cm)
454 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception)
456 if(type==INTERP_KERNEL::NORM_ERROR)
457 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::New : NORM_ERROR is not a valid type to be used as base geometric type for a mesh !");
458 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
461 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::New : the input geometric type " << cm.getRepr() << " is dynamic ! Only static types are allowed here !";
462 throw INTERP_KERNEL::Exception(oss.str().c_str());
464 return new MEDCoupling1SGTUMesh(name,cm);
467 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::clone(bool recDeepCpy) const
469 return new MEDCoupling1SGTUMesh(*this,recDeepCpy);
473 * This method behaves mostly like MEDCoupling1SGTUMesh::deepCpy method, except that only nodal connectivity arrays are deeply copied.
474 * The coordinates are shared between \a this and the returned instance.
476 * \return MEDCouplingUMesh * - A new object instance holding the copy of \a this (deep for connectivity, shallow for coordiantes)
477 * \sa MEDCoupling1SGTUMesh::deepCpy
479 MEDCouplingPointSet *MEDCoupling1SGTUMesh::deepCpyConnectivityOnly() const throw(INTERP_KERNEL::Exception)
482 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(clone(false));
483 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(_conn->deepCpy());
484 ret->setNodalConnectivity(c);
488 void MEDCoupling1SGTUMesh::shallowCopyConnectivityFrom(const MEDCouplingPointSet *other) throw(INTERP_KERNEL::Exception)
491 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::shallowCopyConnectivityFrom : input pointer is null !");
492 const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
494 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::shallowCopyConnectivityFrom : input pointer is not an MEDCoupling1SGTUMesh instance !");
495 setNodalConnectivity(otherC->getNodalConnectivity());
498 void MEDCoupling1SGTUMesh::updateTime() const
500 MEDCoupling1GTUMesh::updateTime();
501 const DataArrayInt *c(_conn);
506 std::size_t MEDCoupling1SGTUMesh::getHeapMemorySize() const
509 const DataArrayInt *c(_conn);
511 ret+=c->getHeapMemorySize();
512 return MEDCoupling1GTUMesh::getHeapMemorySize()+ret;
515 MEDCouplingMesh *MEDCoupling1SGTUMesh::deepCpy() const
520 bool MEDCoupling1SGTUMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception)
523 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::isEqualIfNotWhy : input other pointer is null !");
524 std::ostringstream oss; oss.precision(15);
525 const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
528 reason="mesh given in input is not castable in MEDCoupling1SGTUMesh !";
531 if(!MEDCoupling1GTUMesh::isEqualIfNotWhy(other,prec,reason))
533 const DataArrayInt *c1(_conn),*c2(otherC->_conn);
538 reason="in connectivity of single static geometric type exactly one among this and other is null !";
541 if(!c1->isEqualIfNotWhy(*c2,reason))
543 reason.insert(0,"Nodal connectivity DataArrayInt differ : ");
549 bool MEDCoupling1SGTUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const
552 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::isEqualWithoutConsideringStr : input other pointer is null !");
553 const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
556 if(!MEDCoupling1GTUMesh::isEqualWithoutConsideringStr(other,prec))
558 const DataArrayInt *c1(_conn),*c2(otherC->_conn);
563 if(!c1->isEqualWithoutConsideringStr(*c2))
568 void MEDCoupling1SGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
570 MEDCouplingPointSet::checkCoherency();
571 const DataArrayInt *c1(_conn);
574 if(c1->getNumberOfComponents()!=1)
575 throw INTERP_KERNEL::Exception("Nodal connectivity array is expected to be with number of components set to one !");
576 if(c1->getInfoOnComponent(0)!="")
577 throw INTERP_KERNEL::Exception("Nodal connectivity array is expected to have no info on its single component !");
578 c1->checkAllocated();
581 throw INTERP_KERNEL::Exception("Nodal connectivity array not defined !");
584 void MEDCoupling1SGTUMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception)
587 const DataArrayInt *c1(_conn);
588 int nbOfTuples=c1->getNumberOfTuples();
589 int nbOfNodesPerCell=(int)_cm->getNumberOfNodes();
590 if(nbOfTuples%nbOfNodesPerCell!=0)
592 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 !";
593 throw INTERP_KERNEL::Exception(oss.str().c_str());
595 int nbOfNodes=getNumberOfNodes();
596 int nbOfCells=nbOfTuples/nbOfNodesPerCell;
597 const int *w(c1->begin());
598 for(int i=0;i<nbOfCells;i++)
599 for(int j=0;j<nbOfNodesPerCell;j++,w++)
601 if(*w<0 || *w>=nbOfNodes)
603 std::ostringstream oss; oss << "At node #" << j << " of cell #" << i << ", is equal to " << *w << " must be in [0," << nbOfNodes << ") !";
604 throw INTERP_KERNEL::Exception(oss.str().c_str());
609 void MEDCoupling1SGTUMesh::checkCoherency2(double eps) const throw(INTERP_KERNEL::Exception)
611 checkCoherency1(eps);
614 int MEDCoupling1SGTUMesh::getNumberOfCells() const
616 int nbOfTuples=getNodalConnectivityLength();
617 int nbOfNodesPerCell=getNumberOfNodesPerCell();
618 if(nbOfTuples%nbOfNodesPerCell!=0)
620 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 !";
621 throw INTERP_KERNEL::Exception(oss.str().c_str());
623 return nbOfTuples/nbOfNodesPerCell;
626 int MEDCoupling1SGTUMesh::getNumberOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
628 checkNonDynamicGeoType();
629 return (int)_cm->getNumberOfNodes();
632 DataArrayInt *MEDCoupling1SGTUMesh::computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
634 checkNonDynamicGeoType();
635 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
636 ret->alloc(getNumberOfCells(),1);
637 ret->fillWithValue((int)_cm->getNumberOfNodes());
641 DataArrayInt *MEDCoupling1SGTUMesh::computeNbOfFacesPerCell() const throw(INTERP_KERNEL::Exception)
643 checkNonDynamicGeoType();
644 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
645 ret->alloc(getNumberOfCells(),1);
646 ret->fillWithValue((int)_cm->getNumberOfSons());
650 void MEDCoupling1SGTUMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
652 int sz=getNumberOfNodesPerCell();
654 if(cellId>=0 && cellId<getNumberOfCells())
655 std::copy(_conn->begin()+cellId*sz,_conn->begin()+(cellId+1)*sz,conn.begin());
658 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getNodeIdsOfCell : request for cellId #" << cellId << " must be in [0," << getNumberOfCells() << ") !";
659 throw INTERP_KERNEL::Exception(oss.str().c_str());
663 void MEDCoupling1SGTUMesh::checkNonDynamicGeoType() const throw(INTERP_KERNEL::Exception)
666 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkNonDynamicGeoType : internal error ! the internal geo type is dynamic ! should be static !");
669 std::string MEDCoupling1SGTUMesh::simpleRepr() const
671 static const char msg0[]="No coordinates specified !";
672 std::ostringstream ret;
673 ret << "Single static geometic type (" << _cm->getRepr() << ") unstructured mesh with name : \"" << getName() << "\"\n";
674 ret << "Description of mesh : \"" << getDescription() << "\"\n";
676 double tt=getTime(tmpp1,tmpp2);
677 ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n";
678 ret << "Iteration : " << tmpp1 << " Order : " << tmpp2 << "\n";
679 ret << "Mesh dimension : " << getMeshDimension() << "\nSpace dimension : ";
682 const int spaceDim=getSpaceDimension();
683 ret << spaceDim << "\nInfo attached on space dimension : ";
684 for(int i=0;i<spaceDim;i++)
685 ret << "\"" << _coords->getInfoOnComponent(i) << "\" ";
690 ret << "Number of nodes : ";
692 ret << getNumberOfNodes() << "\n";
695 ret << "Number of cells : ";
696 if((const DataArrayInt *)_conn)
698 if(_conn->isAllocated())
700 if(_conn->getNumberOfComponents()==1)
701 ret << getNumberOfCells() << "\n";
703 ret << "Nodal connectivity array specified and allocated but with not exactly one component !" << "\n";
706 ret << "Nodal connectivity array specified but not allocated !" << "\n";
709 ret << "No connectivity specified !" << "\n";
710 ret << "Cell type : " << _cm->getRepr() << "\n";
714 std::string MEDCoupling1SGTUMesh::advancedRepr() const
716 std::ostringstream ret;
718 ret << "\nCoordinates array : \n___________________\n\n";
720 _coords->reprWithoutNameStream(ret);
722 ret << "No array set !\n";
723 ret << "\n\nConnectivity array : \n____________________\n\n";
725 if((const DataArrayInt *)_conn)
727 if(_conn->isAllocated())
729 if(_conn->getNumberOfComponents()==1)
731 int nbOfCells=getNumberOfCells();
732 int sz=getNumberOfNodesPerCell();
733 const int *connPtr=_conn->begin();
734 for(int i=0;i<nbOfCells;i++,connPtr+=sz)
736 ret << "Cell #" << i << " : ";
737 std::copy(connPtr,connPtr+sz,std::ostream_iterator<int>(ret," "));
742 ret << "Nodal connectivity array specified and allocated but with not exactly one component !" << "\n";
745 ret << "Nodal connectivity array specified but not allocated !" << "\n";
748 ret << "No connectivity specified !" << "\n";
752 DataArrayDouble *MEDCoupling1SGTUMesh::computeIsoBarycenterOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
754 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
755 int spaceDim=getSpaceDimension();
756 int nbOfCells=getNumberOfCells();//checkCoherency()
757 int nbOfNodes=getNumberOfNodes();
758 ret->alloc(nbOfCells,spaceDim);
759 double *ptToFill=ret->getPointer();
760 const double *coor=_coords->begin();
761 const int *nodal=_conn->begin();
762 int sz=getNumberOfNodesPerCell();
763 double coeff=1./(double)sz;
764 for(int i=0;i<nbOfCells;i++,ptToFill+=spaceDim)
766 std::fill(ptToFill,ptToFill+spaceDim,0.);
767 for(int j=0;j<sz;j++,nodal++)
768 if(*nodal>=0 && *nodal<nbOfNodes)
769 std::transform(coor+spaceDim*nodal[0],coor+spaceDim*(nodal[0]+1),ptToFill,ptToFill,std::plus<double>());
772 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::computeIsoBarycenterOfNodesPerCell : on cell #" << i << " presence of nodeId #" << *nodal << " should be in [0," << nbOfNodes << ") !";
773 throw INTERP_KERNEL::Exception(oss.str().c_str());
775 std::transform(ptToFill,ptToFill+spaceDim,ptToFill,std::bind2nd(std::multiplies<double>(),coeff));
780 void MEDCoupling1SGTUMesh::renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception)
782 int nbCells=getNumberOfCells();
783 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::New();
784 o2n->useArray(old2NewBg,false,C_DEALLOC,nbCells,1);
786 o2n=o2n->checkAndPreparePermutation();
788 const int *conn=_conn->begin();
789 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o=o2n->invertArrayO2N2N2O(nbCells);
790 const int *n2oPtr=n2o->begin();
791 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New();
792 newConn->alloc(_conn->getNumberOfTuples(),1);
793 newConn->copyStringInfoFrom(*_conn);
794 int sz=getNumberOfNodesPerCell();
796 int *newC=newConn->getPointer();
797 for(int i=0;i<nbCells;i++,newC+=sz)
800 std::copy(conn+pos*sz,conn+(pos+1)*sz,newC);
806 * Keeps from \a this only cells which constituing point id are in the ids specified by [\a begin,\a end).
807 * The resulting cell ids are stored at the end of the 'cellIdsKept' parameter.
808 * Parameter \a fullyIn specifies if a cell that has part of its nodes in ids array is kept or not.
809 * If \a fullyIn is true only cells whose ids are \b fully contained in [\a begin,\a end) tab will be kept.
811 * \param [in] begin input start of array of node ids.
812 * \param [in] end input end of array of node ids.
813 * \param [in] fullyIn input that specifies if all node ids must be in [\a begin,\a end) array to consider cell to be in.
814 * \param [in,out] cellIdsKeptArr array where all candidate cell ids are put at the end.
816 void MEDCoupling1SGTUMesh::fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const
818 int nbOfCells=getNumberOfCells();
819 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsKept=DataArrayInt::New(); cellIdsKept->alloc(0,1);
821 int sz=_conn->getMaxValue(tmp); sz=std::max(sz,0)+1;
822 std::vector<bool> fastFinder(sz,false);
823 for(const int *work=begin;work!=end;work++)
824 if(*work>=0 && *work<sz)
825 fastFinder[*work]=true;
826 const int *conn=_conn->begin();
827 int nbNodesPerCell=getNumberOfNodesPerCell();
828 for(int i=0;i<nbOfCells;i++,conn+=nbNodesPerCell)
831 for(int j=0;j<nbNodesPerCell;j++)
835 if(fastFinder[conn[j]])
838 if((ref==nbOfHit && fullyIn) || (nbOfHit!=0 && !fullyIn))
839 cellIdsKept->pushBackSilent(i);
841 cellIdsKeptArr=cellIdsKept.retn();
844 MEDCouplingMesh *MEDCoupling1SGTUMesh::mergeMyselfWith(const MEDCouplingMesh *other) const
846 if(other->getType()!=SINGLE_STATIC_GEO_TYPE_UNSTRUCTURED)
847 throw INTERP_KERNEL::Exception("Merge of umesh only available with umesh single static geo type each other !");
848 const MEDCoupling1SGTUMesh *otherC=static_cast<const MEDCoupling1SGTUMesh *>(other);
849 return Merge1SGTUMeshes(this,otherC);
852 MEDCouplingUMesh *MEDCoupling1SGTUMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception)
854 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New(getName(),getMeshDimension());
855 ret->setCoords(getCoords());
856 const int *nodalConn=_conn->begin();
857 int nbCells=getNumberOfCells();
858 int nbNodesPerCell=getNumberOfNodesPerCell();
859 int geoType=(int)getCellModelEnum();
860 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c=DataArrayInt::New(); c->alloc(nbCells*(nbNodesPerCell+1),1);
861 int *cPtr=c->getPointer();
862 for(int i=0;i<nbCells;i++,nodalConn+=nbNodesPerCell)
865 cPtr=std::copy(nodalConn,nodalConn+nbNodesPerCell,cPtr);
867 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cI=DataArrayInt::Range(0,(nbCells+1)*(nbNodesPerCell+1),nbNodesPerCell+1);
868 ret->setConnectivity(c,cI,true);
872 DataArrayInt *MEDCoupling1SGTUMesh::simplexize(int policy) throw(INTERP_KERNEL::Exception)
877 return simplexizePol0();
879 return simplexizePol1();
880 case (int) INTERP_KERNEL::PLANAR_FACE_5:
881 return simplexizePlanarFace5();
882 case (int) INTERP_KERNEL::PLANAR_FACE_6:
883 return simplexizePlanarFace6();
885 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)");
891 struct MEDCouplingAccVisit
893 MEDCouplingAccVisit():_new_nb_of_nodes(0) { }
894 int operator()(int val) { if(val!=-1) return _new_nb_of_nodes++; else return -1; }
895 int _new_nb_of_nodes;
901 * Finds nodes not used in any cell and returns an array giving a new id to every node
902 * by excluding the unused nodes, for which the array holds -1. The result array is
903 * a mapping in "Old to New" mode.
904 * \param [out] nbrOfNodesInUse - number of node ids present in the nodal connectivity.
905 * \return DataArrayInt * - a new instance of DataArrayInt. Its length is \a
906 * this->getNumberOfNodes(). It holds for each node of \a this mesh either -1
907 * if the node is unused or a new id else. The caller is to delete this
908 * array using decrRef() as it is no more needed.
909 * \throw If the coordinates array is not set.
910 * \throw If the nodal connectivity of cells is not defined.
911 * \throw If the nodal connectivity includes an invalid id.
913 DataArrayInt *MEDCoupling1SGTUMesh::getNodeIdsInUse(int& nbrOfNodesInUse) const throw(INTERP_KERNEL::Exception)
916 int nbOfNodes=getNumberOfNodes();
917 int nbOfCells=getNumberOfCells();
918 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
919 ret->alloc(nbOfNodes,1);
920 int *traducer=ret->getPointer();
921 std::fill(traducer,traducer+nbOfNodes,-1);
922 const int *conn=_conn->begin();
923 int nbNodesPerCell=getNumberOfNodesPerCell();
924 for(int i=0;i<nbOfCells;i++)
925 for(int j=0;j<nbNodesPerCell;j++,conn++)
926 if(*conn>=0 && *conn<nbOfNodes)
930 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getNodeIdsInUse : In cell #" << i << " presence of node id " << conn[j] << " not in [0," << nbOfNodes << ") !";
931 throw INTERP_KERNEL::Exception(oss.str().c_str());
933 nbrOfNodesInUse=(int)std::count(traducer,traducer+nbOfNodes,1);
934 std::transform(traducer,traducer+nbOfNodes,traducer,MEDCouplingAccVisit());
939 * Changes ids of nodes within the nodal connectivity arrays according to a permutation
940 * array in "Old to New" mode. The node coordinates array is \b not changed by this method.
941 * This method is a generalization of shiftNodeNumbersInConn().
942 * \warning This method performs no check of validity of new ids. **Use it with care !**
943 * \param [in] newNodeNumbersO2N - a permutation array, of length \a
944 * this->getNumberOfNodes(), in "Old to New" mode.
945 * See \ref MEDCouplingArrayRenumbering for more info on renumbering modes.
946 * \throw If the nodal connectivity of cells is not defined.
948 void MEDCoupling1SGTUMesh::renumberNodesInConn(const int *newNodeNumbersO2N)
950 getNumberOfCells();//only to check that all is well defined.
951 _conn->transformWithIndArr(newNodeNumbersO2N,newNodeNumbersO2N+getNumberOfNodes());
955 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshes(const MEDCoupling1SGTUMesh *mesh1, const MEDCoupling1SGTUMesh *mesh2) throw(INTERP_KERNEL::Exception)
957 std::vector<const MEDCoupling1SGTUMesh *> tmp(2);
958 tmp[0]=const_cast<MEDCoupling1SGTUMesh *>(mesh1); tmp[1]=const_cast<MEDCoupling1SGTUMesh *>(mesh2);
959 return Merge1SGTUMeshes(tmp);
962 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshes(std::vector<const MEDCoupling1SGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
964 std::size_t sz=a.size();
966 return Merge1SGTUMeshesLL(a);
967 for(std::size_t ii=0;ii<sz;ii++)
970 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::Merge1SGTUMeshes : item #" << ii << " in input array of size "<< sz << " is empty !";
971 throw INTERP_KERNEL::Exception(oss.str().c_str());
973 const INTERP_KERNEL::CellModel *cm=&(a[0]->getCellModel());
974 for(std::size_t ii=0;ii<sz;ii++)
975 if(&(a[ii]->getCellModel())!=cm)
976 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshes : all items must have the same geo type !");
977 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> > bb(sz);
978 std::vector< const MEDCoupling1SGTUMesh * > aa(sz);
980 for(std::size_t i=0;i<sz && spaceDim==-3;i++)
982 const MEDCoupling1SGTUMesh *cur=a[i];
983 const DataArrayDouble *coo=cur->getCoords();
985 spaceDim=coo->getNumberOfComponents();
988 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshes : no spaceDim specified ! unable to perform merge !");
989 for(std::size_t i=0;i<sz;i++)
991 bb[i]=a[i]->buildSetInstanceFromThis(spaceDim);
994 return Merge1SGTUMeshesLL(aa);
998 * \throw If presence of a null instance in the input vector \a a.
999 * \throw If a is empty
1001 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords(std::vector<const MEDCoupling1SGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
1004 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords : input array must be NON EMPTY !");
1005 std::vector<const MEDCoupling1SGTUMesh *>::const_iterator it=a.begin();
1007 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords : null instance in the first element of input vector !");
1008 std::vector<const DataArrayInt *> ncs(a.size());
1009 int nbOfCells=(*it)->getNumberOfCells();
1010 const DataArrayDouble *coords=(*it)->getCoords();
1011 const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel());
1012 int nbNodesPerCell=(*it)->getNumberOfNodesPerCell();
1013 ncs[0]=(*it)->getNodalConnectivity();
1015 for(int i=1;it!=a.end();i++,it++)
1018 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords : presence of a null instance in the input vector !");
1019 if(cm!=&((*it)->getCellModel()))
1020 throw INTERP_KERNEL::Exception("Geometric types mismatches, Merge1SGTUMeshes impossible !");
1021 (*it)->getNumberOfCells();//to check that all is OK
1022 ncs[i]=(*it)->getNodalConnectivity();
1023 if(coords!=(*it)->getCoords())
1024 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords : not lying on same coords !");
1026 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh("merge",*cm));
1027 ret->setCoords(coords);
1028 ret->_conn=DataArrayInt::Aggregate(ncs);
1033 * 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)
1035 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshesLL(std::vector<const MEDCoupling1SGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
1038 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::Merge1SGTUMeshes : input array must be NON EMPTY !");
1039 std::vector<const MEDCoupling1SGTUMesh *>::const_iterator it=a.begin();
1040 int nbOfCells=(*it)->getNumberOfCells();
1041 const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel());
1042 int nbNodesPerCell=(*it)->getNumberOfNodesPerCell();
1044 for(;it!=a.end();it++)
1046 if(cm!=&((*it)->getCellModel()))
1047 throw INTERP_KERNEL::Exception("Geometric types mismatches, Merge1SGTUMeshes impossible !");
1048 nbOfCells+=(*it)->getNumberOfCells();
1050 std::vector<const MEDCouplingPointSet *> aps(a.size());
1051 std::copy(a.begin(),a.end(),aps.begin());
1052 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> pts=MergeNodesArray(aps);
1053 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh("merge",*cm));
1054 ret->setCoords(pts);
1055 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c=DataArrayInt::New();
1056 c->alloc(nbOfCells*nbNodesPerCell,1);
1057 int *cPtr=c->getPointer();
1059 for(it=a.begin();it!=a.end();it++)
1061 int curConnLgth=(*it)->getNodalConnectivityLength();
1062 const int *curC=(*it)->_conn->begin();
1063 cPtr=std::transform(curC,curC+curConnLgth,cPtr,std::bind2nd(std::plus<int>(),offset));
1064 offset+=(*it)->getNumberOfNodes();
1067 ret->setNodalConnectivity(c);
1071 MEDCouplingPointSet *MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords(const int *begin, const int *end) const
1073 int ncell=getNumberOfCells();
1074 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName(),*_cm));
1075 ret->setCoords(_coords);
1076 std::size_t nbOfElemsRet=std::distance(begin,end);
1077 const int *inConn=_conn->getConstPointer();
1078 int sz=getNumberOfNodesPerCell();
1079 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> connRet=DataArrayInt::New(); connRet->alloc((int)nbOfElemsRet*sz,1);
1080 int *connPtr=connRet->getPointer();
1081 for(const int *work=begin;work!=end;work++,connPtr+=sz)
1083 if(*work>=0 && *work<ncell)
1084 std::copy(inConn+(work[0])*sz,inConn+(work[0]+1)*sz,connPtr);
1087 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords : On pos #" << std::distance(begin,work) << " input cell id =" << *work << " should be in [0," << ncell << ") !";
1088 throw INTERP_KERNEL::Exception(oss.str().c_str());
1092 ret->copyTinyInfoFrom(this);
1096 MEDCouplingPointSet *MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2(int start, int end, int step) const
1098 int ncell=getNumberOfCells();
1099 int nbOfElemsRet=DataArray::GetNumberOfItemGivenBESRelative(start,end,step,"MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2 : ");
1100 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName(),*_cm));
1101 ret->setCoords(_coords);
1102 const int *inConn=_conn->getConstPointer();
1103 int sz=getNumberOfNodesPerCell();
1104 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> connRet=DataArrayInt::New(); connRet->alloc((int)nbOfElemsRet*sz,1);
1105 int *connPtr=connRet->getPointer();
1107 for(int i=0;i<nbOfElemsRet;i++,connPtr+=sz,curId+=step)
1109 if(curId>=0 && curId<ncell)
1110 std::copy(inConn+curId*sz,inConn+(curId+1)*sz,connPtr);
1113 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::buildPartOfMySelfKeepCoords2 : On pos #" << i << " input cell id =" << curId << " should be in [0," << ncell << ") !";
1114 throw INTERP_KERNEL::Exception(oss.str().c_str());
1118 ret->copyTinyInfoFrom(this);
1122 MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception)
1124 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(new MEDCoupling1SGTUMesh(getName(),*_cm));
1125 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1;
1126 const DataArrayInt *nodalConn(_conn);
1129 tmp1=DataArrayInt::New(); tmp1->alloc(0,1);
1136 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords=DataArrayDouble::New(); coords->alloc(0,spaceDim);
1137 ret->setCoords(coords);
1140 ret->setCoords(_coords);
1144 DataArrayInt *MEDCoupling1SGTUMesh::simplexizePol0() throw(INTERP_KERNEL::Exception)
1146 int nbOfCells=getNumberOfCells();
1147 if(getCellModelEnum()!=INTERP_KERNEL::NORM_QUAD4)
1148 return DataArrayInt::Range(0,nbOfCells,1);
1149 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(2*3*nbOfCells,1);
1150 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(2*nbOfCells,1);
1151 const int *c(_conn->begin());
1152 int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
1153 for(int i=0;i<nbOfCells;i++,c+=4,newConnPtr+=6,retPtr+=2)
1155 newConnPtr[0]=c[0]; newConnPtr[1]=c[1]; newConnPtr[2]=c[2];
1156 newConnPtr[3]=c[0]; newConnPtr[4]=c[2]; newConnPtr[5]=c[3];
1157 retPtr[0]=i; retPtr[1]=i;
1160 _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TRI3);
1165 DataArrayInt *MEDCoupling1SGTUMesh::simplexizePol1() throw(INTERP_KERNEL::Exception)
1167 int nbOfCells=getNumberOfCells();
1168 if(getCellModelEnum()!=INTERP_KERNEL::NORM_QUAD4)
1169 return DataArrayInt::Range(0,nbOfCells,1);
1170 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(2*3*nbOfCells,1);
1171 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(2*nbOfCells,1);
1172 const int *c(_conn->begin());
1173 int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
1174 for(int i=0;i<nbOfCells;i++,c+=4,newConnPtr+=6,retPtr+=2)
1176 newConnPtr[0]=c[0]; newConnPtr[1]=c[1]; newConnPtr[2]=c[3];
1177 newConnPtr[3]=c[1]; newConnPtr[4]=c[2]; newConnPtr[5]=c[3];
1178 retPtr[0]=i; retPtr[1]=i;
1181 _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TRI3);
1186 DataArrayInt *MEDCoupling1SGTUMesh::simplexizePlanarFace5() throw(INTERP_KERNEL::Exception)
1188 int nbOfCells=getNumberOfCells();
1189 if(getCellModelEnum()!=INTERP_KERNEL::NORM_HEXA8)
1190 return DataArrayInt::Range(0,nbOfCells,1);
1191 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(5*4*nbOfCells,1);
1192 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(5*nbOfCells,1);
1193 const int *c(_conn->begin());
1194 int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
1195 for(int i=0;i<nbOfCells;i++,c+=8,newConnPtr+=20,retPtr+=5)
1197 for(int j=0;j<20;j++)
1198 newConnPtr[j]=c[INTERP_KERNEL::SPLIT_NODES_5_WO[j]];
1199 retPtr[0]=i; retPtr[1]=i; retPtr[2]=i; retPtr[3]=i; retPtr[4]=i;
1202 _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TETRA4);
1207 DataArrayInt *MEDCoupling1SGTUMesh::simplexizePlanarFace6() throw(INTERP_KERNEL::Exception)
1209 int nbOfCells=getNumberOfCells();
1210 if(getCellModelEnum()!=INTERP_KERNEL::NORM_HEXA8)
1211 return DataArrayInt::Range(0,nbOfCells,1);
1212 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New(); newConn->alloc(6*4*nbOfCells,1);
1213 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(6*nbOfCells,1);
1214 const int *c(_conn->begin());
1215 int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer());
1216 for(int i=0;i<nbOfCells;i++,c+=8,newConnPtr+=24,retPtr+=6)
1218 for(int j=0;j<24;j++)
1219 newConnPtr[j]=c[INTERP_KERNEL::SPLIT_NODES_6_WO[j]];
1220 retPtr[0]=i; retPtr[1]=i; retPtr[2]=i; retPtr[3]=i; retPtr[4]=i; retPtr[5]=i;
1223 _cm=&INTERP_KERNEL::CellModel::GetCellModel(INTERP_KERNEL::NORM_TETRA4);
1228 void MEDCoupling1SGTUMesh::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1230 stream << "MEDCoupling1SGTUMesh C++ instance at " << this << ". Type=" << _cm->getRepr() << ". Name : \"" << getName() << "\".";
1231 stream << " Mesh dimension : " << getMeshDimension() << ".";
1233 { stream << " No coordinates set !"; return ; }
1234 if(!_coords->isAllocated())
1235 { stream << " Coordinates set but not allocated !"; return ; }
1236 stream << " Space dimension : " << _coords->getNumberOfComponents() << "." << std::endl;
1237 stream << "Number of nodes : " << _coords->getNumberOfTuples() << ".";
1238 if(!(const DataArrayInt *)_conn)
1239 { stream << std::endl << "Nodal connectivity NOT set !"; return ; }
1240 if(_conn->isAllocated())
1242 if(_conn->getNumberOfComponents()==1)
1243 stream << std::endl << "Number of cells : " << getNumberOfCells() << ".";
1247 void MEDCoupling1SGTUMesh::checkFullyDefined() const throw(INTERP_KERNEL::Exception)
1249 if(!((const DataArrayInt *)_conn) || !((const DataArrayDouble *)_coords))
1250 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFullyDefined : part of this is not fully defined.");
1254 * First step of unserialization process.
1256 bool MEDCoupling1SGTUMesh::isEmptyMesh(const std::vector<int>& tinyInfo) const
1258 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::isEmptyMesh : not implemented yet !");
1262 * Checks if \a this and \a other meshes are geometrically equivalent with high
1263 * probability, else an exception is thrown. The meshes are considered equivalent if
1264 * (1) meshes contain the same number of nodes and the same number of elements of the
1265 * same types (2) three cells of the two meshes (first, last and middle) are based
1266 * on coincident nodes (with a specified precision).
1267 * \param [in] other - the mesh to compare with.
1268 * \param [in] prec - the precision used to compare nodes of the two meshes.
1269 * \throw If the two meshes do not match.
1271 void MEDCoupling1SGTUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception)
1273 MEDCouplingPointSet::checkFastEquivalWith(other,prec);
1274 const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
1276 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : Two meshes are not not unstructured with single static geometric type !");
1277 const DataArrayInt *c1(_conn),*c2(otherC->_conn);
1281 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : presence of nodal connectivity only in one of the 2 meshes !");
1282 if((c1->isAllocated() && !c2->isAllocated()) || (!c1->isAllocated() && c2->isAllocated()))
1283 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : in nodal connectivity, only one is allocated !");
1284 if(c1->getNumberOfComponents()!=1 || c1->getNumberOfComponents()!=1)
1285 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : in nodal connectivity, must have 1 and only 1 component !");
1286 if(c1->getHashCode()!=c2->getHashCode())
1287 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::checkFastEquivalWith : nodal connectivity differs");
1290 MEDCouplingPointSet *MEDCoupling1SGTUMesh::mergeMyselfWithOnSameCoords(const MEDCouplingPointSet *other) const
1293 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::mergeMyselfWithOnSameCoords : input other is null !");
1294 const MEDCoupling1SGTUMesh *otherC=dynamic_cast<const MEDCoupling1SGTUMesh *>(other);
1296 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::mergeMyselfWithOnSameCoords : the input other mesh is not of type single statuc geo type unstructured !");
1297 std::vector<const MEDCoupling1SGTUMesh *> ms(2);
1300 return Merge1SGTUMeshesOnSameCoords(ms);
1303 void MEDCoupling1SGTUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const throw(INTERP_KERNEL::Exception)
1305 checkFullyDefined();
1306 int nbOfNodes=getNumberOfNodes();
1307 int *revNodalIndxPtr=(int *)malloc((nbOfNodes+1)*sizeof(int));
1308 revNodalIndx->useArray(revNodalIndxPtr,true,C_DEALLOC,nbOfNodes+1,1);
1309 std::fill(revNodalIndxPtr,revNodalIndxPtr+nbOfNodes+1,0);
1310 const int *conn=_conn->begin();
1311 int nbOfCells=getNumberOfCells();
1312 int nbOfEltsInRevNodal=0;
1313 int nbOfNodesPerCell=getNumberOfNodesPerCell();
1314 for(int eltId=0;eltId<nbOfCells;eltId++)
1316 for(int j=0;j<nbOfNodesPerCell;j++,conn++)
1318 if(conn[0]>=0 && conn[0]<nbOfNodes)
1320 nbOfEltsInRevNodal++;
1321 revNodalIndxPtr[conn[0]+1]++;
1325 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getReverseNodalConnectivity : At cell #" << eltId << " presence of nodeId #" << conn[0] << " should be in [0," << nbOfNodes << ") !";
1326 throw INTERP_KERNEL::Exception(oss.str().c_str());
1330 std::transform(revNodalIndxPtr+1,revNodalIndxPtr+nbOfNodes+1,revNodalIndxPtr,revNodalIndxPtr+1,std::plus<int>());
1331 conn=_conn->begin();
1332 int *revNodalPtr=(int *)malloc((nbOfEltsInRevNodal)*sizeof(int));
1333 revNodal->useArray(revNodalPtr,true,C_DEALLOC,nbOfEltsInRevNodal,1);
1334 std::fill(revNodalPtr,revNodalPtr+nbOfEltsInRevNodal,-1);
1335 for(int eltId=0;eltId<nbOfCells;eltId++)
1337 for(int j=0;j<nbOfNodesPerCell;j++,conn++)
1339 *std::find_if(revNodalPtr+revNodalIndxPtr[*conn],revNodalPtr+revNodalIndxPtr[*conn+1],std::bind2nd(std::equal_to<int>(),-1))=eltId;
1345 * Use \a nodalConn array as nodal connectivity of \a this. The input \a nodalConn pointer can be null.
1347 void MEDCoupling1SGTUMesh::setNodalConnectivity(DataArrayInt *nodalConn) throw(INTERP_KERNEL::Exception)
1350 nodalConn->incrRef();
1356 * \return DataArrayInt * - the internal reference to the nodal connectivity. The caller is not reponsible to deallocate it.
1358 DataArrayInt *MEDCoupling1SGTUMesh::getNodalConnectivity() const throw(INTERP_KERNEL::Exception)
1360 const DataArrayInt *ret(_conn);
1361 return const_cast<DataArrayInt *>(ret);
1365 * Allocates memory to store an estimation of the given number of cells. Closer is the estimation to the number of cells effectively inserted,
1366 * less will be the needs to realloc. If the number of cells to be inserted is not known simply put 0 to this parameter.
1367 * If a nodal connectivity previouly existed before the call of this method, it will be reset.
1369 * \param [in] nbOfCells - estimation of the number of cell \a this mesh will contain.
1371 void MEDCoupling1SGTUMesh::allocateCells(int nbOfCells) throw(INTERP_KERNEL::Exception)
1374 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::allocateCells : the input number of cells should be >= 0 !");
1375 _conn=DataArrayInt::New();
1376 _conn->reserve(getNumberOfNodesPerCell()*nbOfCells);
1381 * Appends at the end of \a this a cell having nodal connectivity array defined in [ \a nodalConnOfCellBg, \a nodalConnOfCellEnd ).
1383 * \param [in] nodalConnOfCellBg - the begin (included) of nodal connectivity of the cell to add.
1384 * \param [in] nodalConnOfCellEnd - the end (excluded) of nodal connectivity of the cell to add.
1385 * \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
1386 * attached to \a this.
1387 * \thow If the nodal connectivity array in \a this is null (call MEDCoupling1SGTUMesh::allocateCells before).
1389 void MEDCoupling1SGTUMesh::insertNextCell(const int *nodalConnOfCellBg, const int *nodalConnOfCellEnd) throw(INTERP_KERNEL::Exception)
1391 int sz=(int)std::distance(nodalConnOfCellBg,nodalConnOfCellEnd);
1392 int ref=getNumberOfNodesPerCell();
1395 DataArrayInt *c(_conn);
1397 c->pushBackValsSilent(nodalConnOfCellBg,nodalConnOfCellEnd);
1399 throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::insertNextCell : nodal connectivity array is null ! Call MEDCoupling1SGTUMesh::allocateCells before !");
1403 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::insertNextCell : input nodal size (" << sz << ") does not match number of nodes per cell of this (";
1404 oss << ref << ") !";
1405 throw INTERP_KERNEL::Exception(oss.str().c_str());
1409 //== find static tony
1411 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::New(const char *name, INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception)
1413 if(type==INTERP_KERNEL::NORM_ERROR)
1414 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::New : NORM_ERROR is not a valid type to be used as base geometric type for a mesh !");
1415 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
1418 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::New : the input geometric type " << cm.getRepr() << " is static ! Only dynamic types are allowed here !";
1419 throw INTERP_KERNEL::Exception(oss.str().c_str());
1421 return new MEDCoupling1DGTUMesh(name,cm);
1424 MEDCoupling1DGTUMesh::MEDCoupling1DGTUMesh(const char *name, const INTERP_KERNEL::CellModel& cm):MEDCoupling1GTUMesh(name,cm)
1428 MEDCoupling1DGTUMesh::MEDCoupling1DGTUMesh(const MEDCoupling1DGTUMesh& other, bool recDeepCpy):MEDCoupling1GTUMesh(other,recDeepCpy),_conn(other._conn)
1432 const DataArrayInt *c(other._conn);
1437 _conn_indx=c->deepCpy();
1441 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::clone(bool recDeepCpy) const
1443 return new MEDCoupling1DGTUMesh(*this,recDeepCpy);
1447 * This method behaves mostly like MEDCoupling1DGTUMesh::deepCpy method, except that only nodal connectivity arrays are deeply copied.
1448 * The coordinates are shared between \a this and the returned instance.
1450 * \return MEDCouplingUMesh * - A new object instance holding the copy of \a this (deep for connectivity, shallow for coordiantes)
1451 * \sa MEDCoupling1DGTUMesh::deepCpy
1453 MEDCouplingPointSet *MEDCoupling1DGTUMesh::deepCpyConnectivityOnly() const throw(INTERP_KERNEL::Exception)
1456 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(clone(false));
1457 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(_conn->deepCpy()),ci(_conn_indx->deepCpy());
1458 ret->setNodalConnectivity(c,ci);
1462 void MEDCoupling1DGTUMesh::updateTime() const
1464 MEDCoupling1GTUMesh::updateTime();
1465 const DataArrayInt *c(_conn);
1473 std::size_t MEDCoupling1DGTUMesh::getHeapMemorySize() const
1476 const DataArrayInt *c(_conn);
1478 ret+=c->getHeapMemorySize();
1481 ret+=c->getHeapMemorySize();
1482 return MEDCoupling1GTUMesh::getHeapMemorySize()+ret;
1485 MEDCouplingMesh *MEDCoupling1DGTUMesh::deepCpy() const
1490 bool MEDCoupling1DGTUMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception)
1493 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::isEqualIfNotWhy : input other pointer is null !");
1494 std::ostringstream oss; oss.precision(15);
1495 const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
1498 reason="mesh given in input is not castable in MEDCoupling1DGTUMesh !";
1501 if(!MEDCoupling1GTUMesh::isEqualIfNotWhy(other,prec,reason))
1503 const DataArrayInt *c1(_conn),*c2(otherC->_conn);
1508 reason="in connectivity of single dynamic geometric type exactly one among this and other is null !";
1511 if(!c1->isEqualIfNotWhy(*c2,reason))
1513 reason.insert(0,"Nodal connectivity DataArrayInt differs : ");
1516 c1=_conn_indx; c2=otherC->_conn_indx;
1521 reason="in connectivity index of single dynamic geometric type exactly one among this and other is null !";
1524 if(!c1->isEqualIfNotWhy(*c2,reason))
1526 reason.insert(0,"Nodal connectivity index DataArrayInt differs : ");
1532 bool MEDCoupling1DGTUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const
1535 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::isEqualWithoutConsideringStr : input other pointer is null !");
1536 const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
1539 if(!MEDCoupling1GTUMesh::isEqualWithoutConsideringStr(other,prec))
1541 const DataArrayInt *c1(_conn),*c2(otherC->_conn);
1546 if(!c1->isEqualWithoutConsideringStr(*c2))
1549 c1=_conn_indx; c2=otherC->_conn_indx;
1554 if(!c1->isEqualWithoutConsideringStr(*c2))
1560 * Checks if \a this and \a other meshes are geometrically equivalent with high
1561 * probability, else an exception is thrown. The meshes are considered equivalent if
1562 * (1) meshes contain the same number of nodes and the same number of elements of the
1563 * same types (2) three cells of the two meshes (first, last and middle) are based
1564 * on coincident nodes (with a specified precision).
1565 * \param [in] other - the mesh to compare with.
1566 * \param [in] prec - the precision used to compare nodes of the two meshes.
1567 * \throw If the two meshes do not match.
1569 void MEDCoupling1DGTUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception)
1571 MEDCouplingPointSet::checkFastEquivalWith(other,prec);
1572 const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
1574 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : Two meshes are not not unstructured with single static geometric type !");
1575 const DataArrayInt *c1(_conn),*c2(otherC->_conn);
1579 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : presence of nodal connectivity only in one of the 2 meshes !");
1580 if((c1->isAllocated() && !c2->isAllocated()) || (!c1->isAllocated() && c2->isAllocated()))
1581 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : in nodal connectivity, only one is allocated !");
1582 if(c1->getNumberOfComponents()!=1 || c1->getNumberOfComponents()!=1)
1583 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : in nodal connectivity, must have 1 and only 1 component !");
1584 if(c1->getHashCode()!=c2->getHashCode())
1585 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : nodal connectivity differs");
1587 c1=_conn_indx; c2=otherC->_conn_indx;
1591 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : presence of nodal connectivity index only in one of the 2 meshes !");
1592 if((c1->isAllocated() && !c2->isAllocated()) || (!c1->isAllocated() && c2->isAllocated()))
1593 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : in nodal connectivity index, only one is allocated !");
1594 if(c1->getNumberOfComponents()!=1 || c1->getNumberOfComponents()!=1)
1595 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : in nodal connectivity index, must have 1 and only 1 component !");
1596 if(c1->getHashCode()!=c2->getHashCode())
1597 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFastEquivalWith : nodal connectivity index differs");
1602 * 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.
1603 * In addition you are sure that the length of nodal connectivity index array is bigger than or equal to one.
1604 * In addition you are also sure that length of nodal connectivity is coherent with the content of the last value in the index array.
1606 void MEDCoupling1DGTUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception)
1608 MEDCouplingPointSet::checkCoherency();
1609 const DataArrayInt *c1(_conn);
1612 if(c1->getNumberOfComponents()!=1)
1613 throw INTERP_KERNEL::Exception("Nodal connectivity array is expected to be with number of components set to one !");
1614 if(c1->getInfoOnComponent(0)!="")
1615 throw INTERP_KERNEL::Exception("Nodal connectivity array is expected to have no info on its single component !");
1616 c1->checkAllocated();
1619 throw INTERP_KERNEL::Exception("Nodal connectivity array not defined !");
1621 int sz2=_conn->getNumberOfTuples();
1625 if(c1->getNumberOfComponents()!=1)
1626 throw INTERP_KERNEL::Exception("Nodal connectivity index array is expected to be with number of components set to one !");
1627 c1->checkAllocated();
1628 if(c1->getNumberOfTuples()<1)
1629 throw INTERP_KERNEL::Exception("Nodal connectivity index array is expected to have a a size of 1 at least !");
1630 if(c1->getInfoOnComponent(0)!="")
1631 throw INTERP_KERNEL::Exception("Nodal connectivity index array is expected to have no info on its single component !");
1632 int f=c1->front(),ll=c1->back();
1635 std::ostringstream oss; oss << "Nodal connectivity index array first value (" << f << ") is expected to be exactly in [0," << sz2 << ") !";
1636 throw INTERP_KERNEL::Exception(oss.str().c_str());
1640 std::ostringstream oss; oss << "Nodal connectivity index array last value (" << ll << ") is expected to be exactly in [0," << sz2 << "] !";
1641 throw INTERP_KERNEL::Exception(oss.str().c_str());
1645 std::ostringstream oss; oss << "Nodal connectivity index array looks very bad (not increasing monotonic) because front (" << f << ") is greater that back (" << ll << ") !";
1646 throw INTERP_KERNEL::Exception(oss.str().c_str());
1650 throw INTERP_KERNEL::Exception("Nodal connectivity index array not defined !");
1651 int szOfC1Exp=_conn_indx->back();
1654 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() << " !";
1655 throw INTERP_KERNEL::Exception(oss.str().c_str());
1659 void MEDCoupling1DGTUMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception)
1662 const DataArrayInt *c1(_conn),*c2(_conn_indx);
1663 if(!c2->isMonotonic(true))
1664 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkCoherency1 : the nodal connectivity index is expected to be increasing monotinic !");
1666 int nbOfTuples=c1->getNumberOfTuples();
1667 int nbOfNodes=getNumberOfNodes();
1668 const int *w(c1->begin());
1669 for(int i=0;i<nbOfTuples;i++,w++)
1671 if(*w==-1) continue;
1672 if(*w<0 || *w>=nbOfNodes)
1674 std::ostringstream oss; oss << "At pos #" << i << " of nodal connectivity array references to node id #" << *w << " must be in [0," << nbOfNodes << ") !";
1675 throw INTERP_KERNEL::Exception(oss.str().c_str());
1680 void MEDCoupling1DGTUMesh::checkCoherency2(double eps) const throw(INTERP_KERNEL::Exception)
1682 checkCoherency1(eps);
1685 int MEDCoupling1DGTUMesh::getNumberOfCells() const
1687 checkCoherency();//do not remove
1688 return _conn_indx->getNumberOfTuples()-1;
1692 * This method returns a newly allocated array containing this->getNumberOfCells() tuples and 1 component.
1693 * For each cell in \b this the number of nodes constituting cell is computed.
1694 * For each polyhedron cell, the sum of the number of nodes of each face constituting polyhedron cell is returned.
1695 * So for pohyhedrons some nodes can be counted several times in the returned result.
1697 * \return a newly allocated array
1699 DataArrayInt *MEDCoupling1DGTUMesh::computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
1702 _conn_indx->checkMonotonic(true);
1703 if(getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
1704 return _conn_indx->deltaShiftIndex();
1706 int nbOfCells=_conn_indx->getNumberOfTuples()-1;
1707 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
1708 ret->alloc(nbOfCells,1);
1709 int *retPtr=ret->getPointer();
1710 const int *ci=_conn_indx->begin(),*c=_conn->begin();
1711 for(int i=0;i<nbOfCells;i++,retPtr++,ci++)
1712 *retPtr=ci[1]-ci[0]-std::count(c+ci[0],c+ci[1],-1);
1717 * This method returns a newly allocated array containing this->getNumberOfCells() tuples and 1 component.
1718 * For each cell in \b this the number of faces constituting (entity of dimension this->getMeshDimension()-1) cell is computed.
1720 * \return a newly allocated array
1722 DataArrayInt *MEDCoupling1DGTUMesh::computeNbOfFacesPerCell() const throw(INTERP_KERNEL::Exception)
1725 _conn_indx->checkMonotonic(true);
1726 if(getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED && getCellModelEnum()!=INTERP_KERNEL::NORM_QPOLYG)
1727 return _conn_indx->deltaShiftIndex();
1728 if(getCellModelEnum()==INTERP_KERNEL::NORM_QPOLYG)
1730 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=_conn_indx->deltaShiftIndex();
1731 ret->applyDivideBy(2);
1735 int nbOfCells=_conn_indx->getNumberOfTuples()-1;
1736 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
1737 ret->alloc(nbOfCells,1);
1738 int *retPtr=ret->getPointer();
1739 const int *ci=_conn_indx->begin(),*c=_conn->begin();
1740 for(int i=0;i<nbOfCells;i++,retPtr++,ci++)
1741 *retPtr=std::count(c+ci[0],c+ci[1],-1)+1;
1745 void MEDCoupling1DGTUMesh::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
1747 int nbOfCells=getNumberOfCells();//performs checks
1748 if(cellId>=0 && cellId<nbOfCells)
1750 int strt=_conn_indx->getIJ(cellId,0),stp=_conn_indx->getIJ(cellId+1,0);
1751 int nbOfNodes=stp-strt;
1753 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::getNodeIdsOfCell : the index array is invalid ! Should be increasing monotonic !");
1754 conn.resize(nbOfNodes);
1755 std::copy(_conn->begin()+strt,_conn->begin()+stp,conn.begin());
1759 std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::getNodeIdsOfCell : request for cellId #" << cellId << " must be in [0," << nbOfCells << ") !";
1760 throw INTERP_KERNEL::Exception(oss.str().c_str());
1764 std::string MEDCoupling1DGTUMesh::simpleRepr() const
1766 static const char msg0[]="No coordinates specified !";
1767 std::ostringstream ret;
1768 ret << "Single dynamic geometic type (" << _cm->getRepr() << ") unstructured mesh with name : \"" << getName() << "\"\n";
1769 ret << "Description of mesh : \"" << getDescription() << "\"\n";
1771 double tt=getTime(tmpp1,tmpp2);
1772 ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n";
1773 ret << "Iteration : " << tmpp1 << " Order : " << tmpp2 << "\n";
1774 ret << "Mesh dimension : " << getMeshDimension() << "\nSpace dimension : ";
1777 const int spaceDim=getSpaceDimension();
1778 ret << spaceDim << "\nInfo attached on space dimension : ";
1779 for(int i=0;i<spaceDim;i++)
1780 ret << "\"" << _coords->getInfoOnComponent(i) << "\" ";
1784 ret << msg0 << "\n";
1785 ret << "Number of nodes : ";
1787 ret << getNumberOfNodes() << "\n";
1789 ret << msg0 << "\n";
1790 ret << "Number of cells : ";
1792 try { checkCoherency(); } catch(INTERP_KERNEL::Exception& e)
1794 ret << "Nodal connectivity arrays are not set or badly set !\n";
1798 ret << getNumberOfCells() << "\n";
1799 ret << "Cell type : " << _cm->getRepr() << "\n";
1803 std::string MEDCoupling1DGTUMesh::advancedRepr() const
1805 std::ostringstream ret;
1806 ret << simpleRepr();
1807 ret << "\nCoordinates array : \n___________________\n\n";
1809 _coords->reprWithoutNameStream(ret);
1811 ret << "No array set !\n";
1812 ret << "\n\nNodal Connectivity : \n____________________\n\n";
1815 try { checkCoherency1(); } catch(INTERP_KERNEL::Exception& e)
1817 ret << "Nodal connectivity arrays are not set or badly set !\n";
1822 int nbOfCells=getNumberOfCells();
1823 const int *ci=_conn_indx->begin(),*c=_conn->begin();
1824 for(int i=0;i<nbOfCells;i++,ci++)
1826 ret << "Cell #" << i << " : ";
1827 std::copy(c+ci[0],c+ci[1],std::ostream_iterator<int>(ret," "));
1833 DataArrayDouble *MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
1835 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1836 int spaceDim=getSpaceDimension();
1837 int nbOfCells=getNumberOfCells();//checkCoherency()
1838 int nbOfNodes=getNumberOfNodes();
1839 ret->alloc(nbOfCells,spaceDim);
1840 double *ptToFill=ret->getPointer();
1841 const double *coor=_coords->begin();
1842 const int *nodal=_conn->begin(),*nodali=_conn_indx->begin();
1844 if(getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
1846 for(int i=0;i<nbOfCells;i++,ptToFill+=spaceDim,nodali++)
1848 std::fill(ptToFill,ptToFill+spaceDim,0.);
1849 if(nodali[0]<nodali[1])// >= to avoid division by 0.
1851 for(int j=nodali[0];j<nodali[1];j++,nodal++)
1853 if(*nodal>=0 && *nodal<nbOfNodes)
1854 std::transform(coor+spaceDim*nodal[0],coor+spaceDim*(nodal[0]+1),ptToFill,ptToFill,std::plus<double>());
1857 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell : on cell #" << i << " presence of nodeId #" << *nodal << " should be in [0," << nbOfNodes << ") !";
1858 throw INTERP_KERNEL::Exception(oss.str().c_str());
1860 std::transform(ptToFill,ptToFill+spaceDim,ptToFill,std::bind2nd(std::multiplies<double>(),1./(nodali[1]-nodali[0])));
1865 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell : at cell #" << i << " the nodal index array is invalid !";
1866 throw INTERP_KERNEL::Exception(oss.str().c_str());
1872 for(int i=0;i<nbOfCells;i++,ptToFill+=spaceDim,nodali++)
1874 std::fill(ptToFill,ptToFill+spaceDim,0.);
1875 if(nodali[0]<nodali[1])// >= to avoid division by 0.
1878 for(int j=nodali[0];j<nodali[1];j++,nodal++)
1880 if(*nodal==-1) continue;
1881 if(*nodal>=0 && *nodal<nbOfNodes)
1883 std::transform(coor+spaceDim*nodal[0],coor+spaceDim*(nodal[0]+1),ptToFill,ptToFill,std::plus<double>());
1888 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell (polyhedron) : on cell #" << i << " presence of nodeId #" << *nodal << " should be in [0," << nbOfNodes << ") !";
1889 throw INTERP_KERNEL::Exception(oss.str().c_str());
1893 std::transform(ptToFill,ptToFill+spaceDim,ptToFill,std::bind2nd(std::multiplies<double>(),1./nbOfNod));
1896 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell (polyhedron) : no nodes in cell #" << i << " !";
1897 throw INTERP_KERNEL::Exception(oss.str().c_str());
1902 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::computeIsoBarycenterOfNodesPerCell (polyhedron) : at cell #" << i << " the nodal index array is invalid !";
1903 throw INTERP_KERNEL::Exception(oss.str().c_str());
1910 void MEDCoupling1DGTUMesh::renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception)
1912 int nbCells=getNumberOfCells();
1913 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::New();
1914 o2n->useArray(old2NewBg,false,C_DEALLOC,nbCells,1);
1916 o2n=o2n->checkAndPreparePermutation();
1918 const int *o2nPtr=o2n->getPointer();
1919 const int *conn=_conn->begin(),*conni=_conn_indx->begin();
1920 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConn=DataArrayInt::New();
1921 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newConnI=DataArrayInt::New();
1922 newConn->alloc(_conn->getNumberOfTuples(),1); newConnI->alloc(nbCells,1);
1923 newConn->copyStringInfoFrom(*_conn); newConnI->copyStringInfoFrom(*_conn_indx);
1925 int *newC=newConn->getPointer(),*newCI=newConnI->getPointer();
1926 for(int i=0;i<nbCells;i++)
1928 int newPos=o2nPtr[i];
1929 int sz=conni[i+1]-conni[i];
1934 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::renumberCells : the index nodal array is invalid for cell #" << i << " !";
1935 throw INTERP_KERNEL::Exception(oss.str().c_str());
1938 newConnI->computeOffsets2(); newCI=newConnI->getPointer();
1940 for(int i=0;i<nbCells;i++,conni++)
1942 int sz=conni[1]-conni[0];
1944 std::copy(conn+conni[0],conn+conni[1],newC+newCI[newp]);
1947 _conn_indx=newConnI;
1950 MEDCouplingMesh *MEDCoupling1DGTUMesh::mergeMyselfWith(const MEDCouplingMesh *other) const
1952 if(other->getType()!=SINGLE_DYNAMIC_GEO_TYPE_UNSTRUCTURED)
1953 throw INTERP_KERNEL::Exception("Merge of umesh only available with umesh single dynamic geo type each other !");
1954 const MEDCoupling1DGTUMesh *otherC=static_cast<const MEDCoupling1DGTUMesh *>(other);
1955 return Merge1DGTUMeshes(this,otherC);
1958 MEDCouplingUMesh *MEDCoupling1DGTUMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception)
1960 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New(getName(),getMeshDimension());
1961 ret->setCoords(getCoords());
1962 const int *nodalConn=_conn->begin(),*nodalConnI=_conn_indx->begin();
1963 int nbCells=getNumberOfCells();//checkCoherency
1964 int geoType=(int)getCellModelEnum();
1965 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c=DataArrayInt::New(); c->alloc(nbCells+_conn->getNumberOfTuples(),1);
1966 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cI=DataArrayInt::New(); cI->alloc(nbCells+1);
1967 int *cPtr=c->getPointer(),*ciPtr=cI->getPointer();
1969 for(int i=0;i<nbCells;i++,ciPtr++)
1971 int sz=nodalConnI[i+1]-nodalConnI[i];
1975 cPtr=std::copy(nodalConn+nodalConnI[i],nodalConn+nodalConnI[i+1],cPtr);
1976 ciPtr[1]=ciPtr[0]+sz+1;
1980 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::buildUnstructured : Invalid for nodal index for cell #" << i << " !";
1981 throw INTERP_KERNEL::Exception(oss.str().c_str());
1984 ret->setConnectivity(c,cI,true);
1989 * Do nothing for the moment, because there is no policy that allows to split polygons, polyhedrons ... into simplexes
1991 DataArrayInt *MEDCoupling1DGTUMesh::simplexize(int policy) throw(INTERP_KERNEL::Exception)
1993 int nbOfCells=getNumberOfCells();
1994 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
1995 ret->alloc(nbOfCells,1);
2000 void MEDCoupling1DGTUMesh::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
2002 stream << "MEDCoupling1DGTUMesh C++ instance at " << this << ". Type=" << _cm->getRepr() << ". Name : \"" << getName() << "\".";
2003 stream << " Mesh dimension : " << getMeshDimension() << ".";
2005 { stream << " No coordinates set !"; return ; }
2006 if(!_coords->isAllocated())
2007 { stream << " Coordinates set but not allocated !"; return ; }
2008 stream << " Space dimension : " << _coords->getNumberOfComponents() << "." << std::endl;
2009 stream << "Number of nodes : " << _coords->getNumberOfTuples() << ".";
2011 try { checkCoherency(); } catch(INTERP_KERNEL::Exception& e)
2013 stream << std::endl << "Nodal connectivity NOT set properly !\n";
2017 stream << std::endl << "Number of cells : " << getNumberOfCells() << ".";
2020 void MEDCoupling1DGTUMesh::shallowCopyConnectivityFrom(const MEDCouplingPointSet *other) throw(INTERP_KERNEL::Exception)
2023 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::shallowCopyConnectivityFrom : input pointer is null !");
2024 const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
2026 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::shallowCopyConnectivityFrom : input pointer is not an MEDCoupling1DGTUMesh instance !");
2027 setNodalConnectivity(otherC->getNodalConnectivity(),otherC->getNodalConnectivityIndex());
2030 MEDCouplingPointSet *MEDCoupling1DGTUMesh::mergeMyselfWithOnSameCoords(const MEDCouplingPointSet *other) const
2033 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::mergeMyselfWithOnSameCoords : input other is null !");
2034 const MEDCoupling1DGTUMesh *otherC=dynamic_cast<const MEDCoupling1DGTUMesh *>(other);
2036 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::mergeMyselfWithOnSameCoords : the input other mesh is not of type single statuc geo type unstructured !");
2037 std::vector<const MEDCoupling1DGTUMesh *> ms(2);
2040 return Merge1DGTUMeshesOnSameCoords(ms);
2043 MEDCouplingPointSet *MEDCoupling1DGTUMesh::buildPartOfMySelfKeepCoords(const int *begin, const int *end) const
2046 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName(),*_cm));
2047 ret->setCoords(_coords);
2048 DataArrayInt *c=0,*ci=0;
2049 MEDCouplingUMesh::ExtractFromIndexedArrays(begin,end,_conn,_conn_indx,c,ci);
2050 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cSafe(c),ciSafe(ci);
2051 ret->setNodalConnectivity(c,ci);
2055 MEDCouplingPointSet *MEDCoupling1DGTUMesh::buildPartOfMySelfKeepCoords2(int start, int end, int step) const
2058 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName(),*_cm));
2059 ret->setCoords(_coords);
2060 DataArrayInt *c=0,*ci=0;
2061 MEDCouplingUMesh::ExtractFromIndexedArrays2(start,end,step,_conn,_conn_indx,c,ci);
2062 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cSafe(c),ciSafe(ci);
2063 ret->setNodalConnectivity(c,ci);
2067 void MEDCoupling1DGTUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const throw(INTERP_KERNEL::Exception)
2069 checkFullyDefined();
2070 int nbOfNodes=getNumberOfNodes();
2071 int *revNodalIndxPtr=(int *)malloc((nbOfNodes+1)*sizeof(int));
2072 revNodalIndx->useArray(revNodalIndxPtr,true,C_DEALLOC,nbOfNodes+1,1);
2073 std::fill(revNodalIndxPtr,revNodalIndxPtr+nbOfNodes+1,0);
2074 const int *conn=_conn->begin(),*conni=_conn_indx->begin();
2075 int nbOfCells=getNumberOfCells();
2076 int nbOfEltsInRevNodal=0;
2077 for(int eltId=0;eltId<nbOfCells;eltId++)
2079 int nbOfNodesPerCell=conni[eltId+1]-conni[eltId];
2080 if(nbOfNodesPerCell>=0)
2082 for(int j=0;j<nbOfNodesPerCell;j++)
2084 int nodeId=conn[conni[eltId]+j];
2085 if(nodeId==-1) continue;
2086 if(nodeId>=0 && nodeId<nbOfNodes)
2088 nbOfEltsInRevNodal++;
2089 revNodalIndxPtr[nodeId+1]++;
2093 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::getReverseNodalConnectivity : At cell #" << eltId << " presence of nodeId #" << conn[0] << " should be in [0," << nbOfNodes << ") !";
2094 throw INTERP_KERNEL::Exception(oss.str().c_str());
2100 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::getReverseNodalConnectivity : At cell #" << eltId << "nodal connectivity is invalid !";
2101 throw INTERP_KERNEL::Exception(oss.str().c_str());
2104 std::transform(revNodalIndxPtr+1,revNodalIndxPtr+nbOfNodes+1,revNodalIndxPtr,revNodalIndxPtr+1,std::plus<int>());
2105 conn=_conn->begin();
2106 int *revNodalPtr=(int *)malloc((nbOfEltsInRevNodal)*sizeof(int));
2107 revNodal->useArray(revNodalPtr,true,C_DEALLOC,nbOfEltsInRevNodal,1);
2108 std::fill(revNodalPtr,revNodalPtr+nbOfEltsInRevNodal,-1);
2109 for(int eltId=0;eltId<nbOfCells;eltId++)
2111 int nbOfNodesPerCell=conni[eltId+1]-conni[eltId];
2112 for(int j=0;j<nbOfNodesPerCell;j++)
2114 int nodeId=conn[conni[eltId]+j];
2116 *std::find_if(revNodalPtr+revNodalIndxPtr[nodeId],revNodalPtr+revNodalIndxPtr[nodeId+1],std::bind2nd(std::equal_to<int>(),-1))=eltId;
2121 void MEDCoupling1DGTUMesh::checkFullyDefined() const throw(INTERP_KERNEL::Exception)
2123 if(!((const DataArrayInt *)_conn) || !((const DataArrayInt *)_conn_indx) || !((const DataArrayDouble *)_coords))
2124 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::checkFullyDefined : part of this is not fully defined.");
2127 bool MEDCoupling1DGTUMesh::isEmptyMesh(const std::vector<int>& tinyInfo) const
2129 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::isEmptyMesh : not implemented yet !");
2133 * Finds nodes not used in any cell and returns an array giving a new id to every node
2134 * by excluding the unused nodes, for which the array holds -1. The result array is
2135 * a mapping in "Old to New" mode.
2136 * \param [out] nbrOfNodesInUse - number of node ids present in the nodal connectivity.
2137 * \return DataArrayInt * - a new instance of DataArrayInt. Its length is \a
2138 * this->getNumberOfNodes(). It holds for each node of \a this mesh either -1
2139 * if the node is unused or a new id else. The caller is to delete this
2140 * array using decrRef() as it is no more needed.
2141 * \throw If the coordinates array is not set.
2142 * \throw If the nodal connectivity of cells is not defined.
2143 * \throw If the nodal connectivity includes an invalid id.
2145 DataArrayInt *MEDCoupling1DGTUMesh::getNodeIdsInUse(int& nbrOfNodesInUse) const throw(INTERP_KERNEL::Exception)
2148 int nbOfNodes=getNumberOfNodes();
2149 int nbOfCells=getNumberOfCells();//checkCoherency
2150 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
2151 ret->alloc(nbOfNodes,1);
2152 int *traducer=ret->getPointer();
2153 std::fill(traducer,traducer+nbOfNodes,-1);
2154 const int *conn=_conn->begin(),*conni(_conn_indx->begin());
2155 for(int i=0;i<nbOfCells;i++,conni++)
2157 int nbNodesPerCell=conni[1]-conni[0];
2158 for(int j=0;j<nbNodesPerCell;j++)
2160 int nodeId=conn[conni[0]+j];
2161 if(nodeId==-1) continue;
2162 if(nodeId>=0 && nodeId<nbOfNodes)
2166 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::getNodeIdsInUse : In cell #" << i << " presence of node id " << nodeId << " not in [0," << nbOfNodes << ") !";
2167 throw INTERP_KERNEL::Exception(oss.str().c_str());
2171 nbrOfNodesInUse=(int)std::count(traducer,traducer+nbOfNodes,1);
2172 std::transform(traducer,traducer+nbOfNodes,traducer,MEDCouplingAccVisit());
2177 * Changes ids of nodes within the nodal connectivity arrays according to a permutation
2178 * array in "Old to New" mode. The node coordinates array is \b not changed by this method.
2179 * This method is a generalization of shiftNodeNumbersInConn().
2180 * \warning This method performs no check of validity of new ids. **Use it with care !**
2181 * \param [in] newNodeNumbersO2N - a permutation array, of length \a
2182 * this->getNumberOfNodes(), in "Old to New" mode.
2183 * See \ref MEDCouplingArrayRenumbering for more info on renumbering modes.
2184 * \throw If the nodal connectivity of cells is not defined.
2186 void MEDCoupling1DGTUMesh::renumberNodesInConn(const int *newNodeNumbersO2N)
2188 getNumberOfCells();//only to check that all is well defined.
2190 int nbElemsIn=getNumberOfNodes();
2191 int nbOfTuples=_conn->getNumberOfTuples();
2192 int *pt=_conn->getPointer();
2193 for(int i=0;i<nbOfTuples;i++,pt++)
2195 if(*pt==-1) continue;
2196 if(*pt>=0 && *pt<nbElemsIn)
2197 *pt=newNodeNumbersO2N[*pt];
2200 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::renumberNodesInConn : error on tuple #" << i << " value is " << *pt << " and indirectionnal array as a size equal to " << nbElemsIn;
2201 throw INTERP_KERNEL::Exception(oss.str().c_str());
2204 _conn->declareAsNew();
2210 * Keeps from \a this only cells which constituing point id are in the ids specified by [\a begin,\a end).
2211 * The resulting cell ids are stored at the end of the 'cellIdsKept' parameter.
2212 * Parameter \a fullyIn specifies if a cell that has part of its nodes in ids array is kept or not.
2213 * If \a fullyIn is true only cells whose ids are \b fully contained in [\a begin,\a end) tab will be kept.
2215 * \param [in] begin input start of array of node ids.
2216 * \param [in] end input end of array of node ids.
2217 * \param [in] fullyIn input that specifies if all node ids must be in [\a begin,\a end) array to consider cell to be in.
2218 * \param [in,out] cellIdsKeptArr array where all candidate cell ids are put at the end.
2220 void MEDCoupling1DGTUMesh::fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const
2222 int nbOfCells=getNumberOfCells();
2223 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsKept=DataArrayInt::New(); cellIdsKept->alloc(0,1);
2225 int sz=_conn->getMaxValue(tmp); sz=std::max(sz,0)+1;
2226 std::vector<bool> fastFinder(sz,false);
2227 for(const int *work=begin;work!=end;work++)
2228 if(*work>=0 && *work<sz)
2229 fastFinder[*work]=true;
2230 const int *conn=_conn->begin(),*conni=_conn_indx->begin();
2231 for(int i=0;i<nbOfCells;i++,conni++)
2233 int ref=0,nbOfHit=0;
2234 int nbNodesPerCell=conni[1]-conni[0];
2235 if(nbNodesPerCell>=0)
2237 for(int j=0;j<nbNodesPerCell;j++)
2239 int nodeId=conn[conni[0]+j];
2243 if(fastFinder[nodeId])
2250 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::fillCellIdsToKeepFromNodeIds : invalid index array for cell #" << i << " !";
2251 throw INTERP_KERNEL::Exception(oss.str().c_str());
2253 if((ref==nbOfHit && fullyIn) || (nbOfHit!=0 && !fullyIn))
2254 cellIdsKept->pushBackSilent(i);
2256 cellIdsKeptArr=cellIdsKept.retn();
2259 void MEDCoupling1DGTUMesh::allocateCells(int nbOfCells) throw(INTERP_KERNEL::Exception)
2262 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::allocateCells : the input number of cells should be >= 0 !");
2263 _conn=DataArrayInt::New();
2264 _conn->reserve(nbOfCells*3);
2265 _conn_indx=DataArrayInt::New();
2266 _conn_indx->reserve(nbOfCells+1); _conn_indx->pushBackSilent(0);
2271 * Appends at the end of \a this a cell having nodal connectivity array defined in [ \a nodalConnOfCellBg, \a nodalConnOfCellEnd ).
2273 * \param [in] nodalConnOfCellBg - the begin (included) of nodal connectivity of the cell to add.
2274 * \param [in] nodalConnOfCellEnd - the end (excluded) of nodal connectivity of the cell to add.
2275 * \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
2276 * attached to \a this.
2277 * \thow If the nodal connectivity array in \a this is null (call MEDCoupling1SGTUMesh::allocateCells before).
2279 void MEDCoupling1DGTUMesh::insertNextCell(const int *nodalConnOfCellBg, const int *nodalConnOfCellEnd) throw(INTERP_KERNEL::Exception)
2281 int sz=(int)std::distance(nodalConnOfCellBg,nodalConnOfCellEnd);
2282 DataArrayInt *c(_conn),*c2(_conn_indx);
2286 if(pos==c->getNumberOfTuples())
2288 c->pushBackValsSilent(nodalConnOfCellBg,nodalConnOfCellEnd);
2289 c2->pushBackSilent(pos+sz);
2293 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::insertNextCell : The nodal index array (end=" << pos << ") mismatches with nodal array (length=" << c->getNumberOfTuples() << ") !";
2294 throw INTERP_KERNEL::Exception(oss.str().c_str());
2298 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::insertNextCell : nodal connectivity array is null ! Call MEDCoupling1DGTUMesh::allocateCells before !");
2301 void MEDCoupling1DGTUMesh::setNodalConnectivity(DataArrayInt *nodalConn, DataArrayInt *nodalConnIndex) throw(INTERP_KERNEL::Exception)
2304 nodalConn->incrRef();
2307 nodalConnIndex->incrRef();
2308 _conn_indx=nodalConnIndex;
2313 * \return DataArrayInt * - the internal reference to the nodal connectivity. The caller is not reponsible to deallocate it.
2315 DataArrayInt *MEDCoupling1DGTUMesh::getNodalConnectivity() const throw(INTERP_KERNEL::Exception)
2317 const DataArrayInt *ret(_conn);
2318 return const_cast<DataArrayInt *>(ret);
2322 * \return DataArrayInt * - the internal reference to the nodal connectivity index. The caller is not reponsible to deallocate it.
2324 DataArrayInt *MEDCoupling1DGTUMesh::getNodalConnectivityIndex() const throw(INTERP_KERNEL::Exception)
2326 const DataArrayInt *ret(_conn_indx);
2327 return const_cast<DataArrayInt *>(ret);
2331 * See the definition of the nodal connectivity pack \ref MEDCoupling1DGTUMesh::isPacked "here".
2332 * This method tries to build a new instance geometrically equivalent to \a this, by limiting at most the number of new object (nodal connectivity).
2333 * 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.
2335 * 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.
2337 * \param [out] isShallowCpyOfNodalConnn - tells if the returned instance share the same pair of nodal connectivity arrays (true) or if nodal
2338 * connectivity arrays are different (false)
2339 * \return a new object to be managed by the caller.
2341 * \sa MEDCoupling1DGTUMesh::retrievePackedNodalConnectivity, MEDCoupling1DGTUMesh::isPacked
2343 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::copyWithNodalConnectivityPacked(bool& isShallowCpyOfNodalConnn) const throw(INTERP_KERNEL::Exception)
2345 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName(),*_cm));
2346 DataArrayInt *nc=0,*nci=0;
2347 isShallowCpyOfNodalConnn=retrievePackedNodalConnectivity(nc,nci);
2348 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ncs(nc),ncis(nci);
2349 ret->_conn=ncs; ret->_conn_indx=ncis;
2350 ret->setCoords(getCoords());
2355 * This method allows to compute, if needed, the packed nodal connectivity pair.
2356 * Indeed, it is possible to store in \a this a nodal connectivity array bigger than ranges convered by nodal connectivity index array.
2357 * 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.
2359 * 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)
2360 * true will be returned and respectively \a this->_conn and \a this->_conn_indx (with ref counter incremented). This is the classical case.
2362 * 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
2365 * This method return 3 elements.
2366 * \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
2367 * this pointer can be seen as a new object, that is to managed by the caller.
2368 * \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
2369 * this pointer can be seen as a new object, that is to managed by the caller.
2370 * \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
2371 * output parameters are newly created objects.
2373 * \throw if \a this does not pass MEDCoupling1DGTUMesh::checkCoherency test
2375 bool MEDCoupling1DGTUMesh::retrievePackedNodalConnectivity(DataArrayInt *&nodalConn, DataArrayInt *&nodalConnIndx) const throw(INTERP_KERNEL::Exception)
2377 if(isPacked())//performs the checkCoherency
2379 const DataArrayInt *c0(_conn),*c1(_conn_indx);
2380 nodalConn=const_cast<DataArrayInt *>(c0); nodalConnIndx=const_cast<DataArrayInt *>(c1);
2381 nodalConn->incrRef(); nodalConnIndx->incrRef();
2384 int bg=_conn_indx->front(),end=_conn_indx->back();
2385 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nc(_conn->selectByTupleId2(bg,end,1));
2386 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nci(_conn_indx->deepCpy());
2387 nci->applyLin(1,-bg);
2388 nodalConn=nc.retn(); nodalConnIndx=nci.retn();
2393 * 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)
2394 * true will be returned and respectively \a this->_conn and \a this->_conn_indx (with ref counter incremented). This is the classical case.
2395 * If nodal connectivity index points to a subpart of nodal connectivity index false will be returned.
2396 * \return bool - true if \a this looks packed, false is not.
2398 * \throw if \a this does not pass MEDCoupling1DGTUMesh::checkCoherency test
2400 bool MEDCoupling1DGTUMesh::isPacked() const throw(INTERP_KERNEL::Exception)
2403 return _conn_indx->front()==0 && _conn_indx->back()==_conn->getNumberOfTuples();
2406 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::Merge1DGTUMeshes(const MEDCoupling1DGTUMesh *mesh1, const MEDCoupling1DGTUMesh *mesh2) throw(INTERP_KERNEL::Exception)
2408 std::vector<const MEDCoupling1DGTUMesh *> tmp(2);
2409 tmp[0]=const_cast<MEDCoupling1DGTUMesh *>(mesh1); tmp[1]=const_cast<MEDCoupling1DGTUMesh *>(mesh2);
2410 return Merge1DGTUMeshes(tmp);
2413 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::Merge1DGTUMeshes(std::vector<const MEDCoupling1DGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
2415 std::size_t sz=a.size();
2417 return Merge1DGTUMeshesLL(a);
2418 for(std::size_t ii=0;ii<sz;ii++)
2421 std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::Merge1DGTUMeshes : item #" << ii << " in input array of size "<< sz << " is empty !";
2422 throw INTERP_KERNEL::Exception(oss.str().c_str());
2424 const INTERP_KERNEL::CellModel *cm=&(a[0]->getCellModel());
2425 for(std::size_t ii=0;ii<sz;ii++)
2426 if(&(a[ii]->getCellModel())!=cm)
2427 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshes : all items must have the same geo type !");
2428 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> > bb(sz);
2429 std::vector< const MEDCoupling1DGTUMesh * > aa(sz);
2431 for(std::size_t i=0;i<sz && spaceDim==-3;i++)
2433 const MEDCoupling1DGTUMesh *cur=a[i];
2434 const DataArrayDouble *coo=cur->getCoords();
2436 spaceDim=coo->getNumberOfComponents();
2439 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshes : no spaceDim specified ! unable to perform merge !");
2440 for(std::size_t i=0;i<sz;i++)
2442 bb[i]=a[i]->buildSetInstanceFromThis(spaceDim);
2445 return Merge1DGTUMeshesLL(aa);
2449 * \throw If presence of a null instance in the input vector \a a.
2450 * \throw If a is empty
2452 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords(std::vector<const MEDCoupling1DGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
2455 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords : input array must be NON EMPTY !");
2456 std::vector<const MEDCoupling1DGTUMesh *>::const_iterator it=a.begin();
2458 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords : null instance in the first element of input vector !");
2459 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> > objs(a.size());
2460 std::vector<const DataArrayInt *> ncs(a.size()),ncis(a.size());
2461 int nbOfCells=(*it)->getNumberOfCells();
2462 const DataArrayDouble *coords=(*it)->getCoords();
2463 const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel());
2465 objs[0]=(*it)->copyWithNodalConnectivityPacked(tmp);
2466 ncs[0]=objs[0]->getNodalConnectivity(); ncis[0]=objs[0]->getNodalConnectivityIndex();
2468 for(int i=1;it!=a.end();i++,it++)
2471 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords : presence of null instance !");
2472 if(cm!=&((*it)->getCellModel()))
2473 throw INTERP_KERNEL::Exception("Geometric types mismatches, Merge1DGTUMeshes impossible !");
2474 (*it)->getNumberOfCells();//to check that all is OK
2475 objs[i]=(*it)->copyWithNodalConnectivityPacked(tmp);
2476 ncs[i]=objs[i]->getNodalConnectivity(); ncis[i]=objs[i]->getNodalConnectivityIndex();
2477 if(coords!=(*it)->getCoords())
2478 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshesOnSameCoords : not lying on same coords !");
2480 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh("merge",*cm));
2481 ret->setCoords(coords);
2482 ret->_conn=DataArrayInt::Aggregate(ncs);
2483 ret->_conn_indx=DataArrayInt::AggregateIndexes(ncis);
2488 * 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)
2490 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::Merge1DGTUMeshesLL(std::vector<const MEDCoupling1DGTUMesh *>& a) throw(INTERP_KERNEL::Exception)
2493 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::Merge1DGTUMeshes : input array must be NON EMPTY !");
2494 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> > objs(a.size());
2495 std::vector<const DataArrayInt *> ncs(a.size()),ncis(a.size());
2496 std::vector<const MEDCoupling1DGTUMesh *>::const_iterator it=a.begin();
2497 std::vector<int> nbNodesPerElt(a.size());
2498 int nbOfCells=(*it)->getNumberOfCells();
2500 objs[0]=(*it)->copyWithNodalConnectivityPacked(tmp);
2501 ncs[0]=objs[0]->getNodalConnectivity(); ncis[0]=objs[0]->getNodalConnectivityIndex();
2503 int prevNbOfNodes=(*it)->getNumberOfNodes();
2504 const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel());
2506 for(int i=1;it!=a.end();i++,it++)
2508 if(cm!=&((*it)->getCellModel()))
2509 throw INTERP_KERNEL::Exception("Geometric types mismatches, Merge1DGTUMeshes impossible !");
2510 objs[i]=(*it)->copyWithNodalConnectivityPacked(tmp);
2511 ncs[i]=objs[i]->getNodalConnectivity(); ncis[i]=objs[i]->getNodalConnectivityIndex();
2512 nbOfCells+=(*it)->getNumberOfCells();
2513 nbNodesPerElt[i]=nbNodesPerElt[i-1]+prevNbOfNodes;
2514 prevNbOfNodes=(*it)->getNumberOfNodes();
2516 std::vector<const MEDCouplingPointSet *> aps(a.size());
2517 std::copy(a.begin(),a.end(),aps.begin());
2518 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> pts=MergeNodesArray(aps);
2519 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh("merge",*cm));
2520 ret->setCoords(pts);
2521 ret->_conn=AggregateNodalConnAndShiftNodeIds(ncs,nbNodesPerElt);
2522 ret->_conn_indx=DataArrayInt::AggregateIndexes(ncis);
2526 MEDCoupling1DGTUMesh *MEDCoupling1DGTUMesh::buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception)
2528 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1DGTUMesh> ret(new MEDCoupling1DGTUMesh(getName(),*_cm));
2529 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1,tmp2;
2530 const DataArrayInt *nodalConn(_conn),*nodalConnI(_conn_indx);
2533 tmp1=DataArrayInt::New(); tmp1->alloc(0,1);
2541 tmp2=DataArrayInt::New(); tmp2->alloc(1,1); tmp2->setIJ(0,0,0);
2545 ret->_conn_indx=tmp2;
2549 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords=DataArrayDouble::New(); coords->alloc(0,spaceDim);
2550 ret->setCoords(coords);
2553 ret->setCoords(_coords);
2558 * This method performs an aggregation of \a nodalConns (as DataArrayInt::Aggregate does) but in addition of that a shift is applied on the
2559 * values contained in \a nodalConns using corresponding offset specified in input \a offsetInNodeIdsPerElt.
2560 * But it also manage the values -1, that have a semantic in MEDCoupling1DGTUMesh class (separator for polyhedron).
2562 * \param [in] nodalConns - a list of nodal connectivity arrays same size than \a offsetInNodeIdsPerElt.
2563 * \param [in] offsetInNodeIdsPerElt - a list of offsets to apply.
2564 * \return DataArrayInt * - A new object (to be managed by the caller) that is the result of the aggregation.
2565 * \throw If \a nodalConns or \a offsetInNodeIdsPerElt are empty.
2566 * \throw If \a nodalConns and \a offsetInNodeIdsPerElt have not the same size.
2567 * \throw If presence of null pointer in \a nodalConns.
2568 * \throw If presence of not allocated or array with not exactly one component in \a nodalConns.
2570 DataArrayInt *MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds(const std::vector<const DataArrayInt *>& nodalConns, const std::vector<int>& offsetInNodeIdsPerElt) throw(INTERP_KERNEL::Exception)
2572 std::size_t sz1(nodalConns.size()),sz2(offsetInNodeIdsPerElt.size());
2574 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds : input vectors do not have the same size !");
2576 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds : empty vectors in input !");
2578 for(std::vector<const DataArrayInt *>::const_iterator it=nodalConns.begin();it!=nodalConns.end();it++)
2581 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds : presence of null pointer in input vector !");
2582 if(!(*it)->isAllocated())
2583 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds : presence of non allocated array in input vector !");
2584 if((*it)->getNumberOfComponents()!=1)
2585 throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::AggregateNodalConnAndShiftNodeIds : presence of array with not exactly one component !");
2586 nbOfTuples+=(*it)->getNumberOfTuples();
2588 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbOfTuples,1);
2589 int *pt=ret->getPointer();
2591 for(std::vector<const DataArrayInt *>::const_iterator it=nodalConns.begin();it!=nodalConns.end();it++,i++)
2593 int curNbt=(*it)->getNumberOfTuples();
2594 const int *inPt=(*it)->begin();
2595 int offset=offsetInNodeIdsPerElt[i];
2596 for(int j=0;j<curNbt;j++,pt++)