1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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
21 #include "MEDCouplingAMRAttribute.hxx"
22 #include "MEDCouplingMemArray.hxx"
26 using namespace ParaMEDMEM;
28 DataArrayDoubleCollection *DataArrayDoubleCollection::New(const std::vector< std::pair<std::string,int> >& fieldNames)
30 return new DataArrayDoubleCollection(fieldNames);
33 void DataArrayDoubleCollection::allocTuples(int nbOfTuples)
35 std::size_t sz(_arrs.size());
36 for(std::size_t i=0;i<sz;i++)
37 _arrs[i]->reAlloc(nbOfTuples);
40 void DataArrayDoubleCollection::dellocTuples()
42 std::size_t sz(_arrs.size());
43 for(std::size_t i=0;i<sz;i++)
47 void DataArrayDoubleCollection::spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames)
49 std::size_t sz(_arrs.size());
50 if(sz!=compNames.size())
51 throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::spillInfoOnComponents : first size of compNames has to be equal to the number of fields defined !");
52 for(std::size_t i=0;i<sz;i++)
54 const std::vector<std::string>& names(compNames[i]);
55 _arrs[i]->setInfoOnComponents(names);
59 std::vector<DataArrayDouble *> DataArrayDoubleCollection::retrieveFields() const
61 std::size_t sz(_arrs.size());
62 std::vector<DataArrayDouble *> ret(sz);
63 for(std::size_t i=0;i<sz;i++)
65 const DataArrayDouble *tmp(_arrs[i]);
66 ret[i]=const_cast<DataArrayDouble *>(tmp);
73 const DataArrayDouble *DataArrayDoubleCollection::getFieldWithName(const std::string& name) const
75 std::vector<std::string> vec;
76 for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> >::const_iterator it=_arrs.begin();it!=_arrs.end();it++)
78 const DataArrayDouble *obj(*it);
81 if(obj->getName()==name)
84 vec.push_back(obj->getName());
87 std::ostringstream oss; oss << "DataArrayDoubleCollection::getFieldWithName : fieldName \"" << name << "\" does not exist in this ! Possibilities are :";
88 std::copy(vec.begin(),vec.end(),std::ostream_iterator<std::string>(oss," "));
89 throw INTERP_KERNEL::Exception(oss.str().c_str());
92 void DataArrayDoubleCollection::SynchronizeFineToCoarse(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *fine, DataArrayDoubleCollection *coarse)
95 throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::SynchronizeFineToCoarse : the input DataArrayDouble collections must be non NULL !");
96 std::size_t sz(coarse->_arrs.size());
97 if(fine->_arrs.size()!=sz)
98 throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::SynchronizeFineToCoarse : the input DataArrayDouble collection must have the same size !");
99 for(std::size_t i=0;i<sz;i++)
100 fatherOfFineMesh->fillCellFieldComingFromPatchGhost(patchId,fine->_arrs[i],coarse->_arrs[i],ghostLev);
103 void DataArrayDoubleCollection::SynchronizeCoarseToFine(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *coarse, DataArrayDoubleCollection *fine)
106 throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::SynchronizeCoarseToFine : the input DataArrayDouble collections must be non NULL !");
107 std::size_t sz(coarse->_arrs.size());
108 if(fine->_arrs.size()!=sz)
109 throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::SynchronizeCoarseToFine : the input DataArrayDouble collection must have the same size !");
110 for(std::size_t i=0;i<sz;i++)
111 fatherOfFineMesh->fillCellFieldOnPatchGhost(patchId,coarse->_arrs[i],fine->_arrs[i],ghostLev);
114 void DataArrayDoubleCollection::SynchronizeFineEachOther(int patchId, int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, const std::vector<const MEDCouplingCartesianAMRMeshGen *>& children, const std::vector<DataArrayDoubleCollection *>& fieldsOnFine)
116 if(!fatherOfFineMesh)
117 throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::SynchronizeFineEachOther : father is NULL !");
118 std::size_t sz(children.size());
119 if(fieldsOnFine.size()!=sz)
120 throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::SynchronizeFineEachOther : sizes of vectors mismatch !");
123 std::size_t nbOfCall(fieldsOnFine[0]->_arrs.size());
124 for(std::size_t i=0;i<sz;i++)
125 if(fatherOfFineMesh->getPatchIdFromChildMesh(children[i])!=(int)i)
126 throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::SynchronizeFineEachOther : internal error !");
127 for(std::size_t i=1;i<sz;i++)
128 if(nbOfCall!=fieldsOnFine[i]->_arrs.size())
129 throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::SynchronizeFineEachOther : the collection of DataArrayDouble must have all the same size !");
130 for(std::size_t i=0;i<nbOfCall;i++)
132 std::vector<const DataArrayDouble *> arrs(sz);
133 for(std::size_t j=0;j<sz;j++)
134 arrs[j]=fieldsOnFine[j]->_arrs[i];
135 fatherOfFineMesh->fillCellFieldOnPatchOnlyGhostAdv(patchId,ghostLev,arrs);
139 void DataArrayDoubleCollection::SynchronizeCoarseToFineOnlyInGhostZone(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *coarse, DataArrayDoubleCollection *fine)
142 throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::SynchronizeCoarseToFineOnlyInGhostZone : the input DataArrayDouble collections must be non NULL !");
143 std::size_t sz(coarse->_arrs.size());
144 if(fine->_arrs.size()!=sz)
145 throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::SynchronizeCoarseToFineOnlyInGhostZone : the input DataArrayDouble collection must have the same size !");
146 for(std::size_t i=0;i<sz;i++)
147 fatherOfFineMesh->fillCellFieldOnPatchOnlyOnGhostZone(patchId,coarse->_arrs[i],fine->_arrs[i],ghostLev);
150 DataArrayDoubleCollection::DataArrayDoubleCollection(const std::vector< std::pair<std::string,int> >& fieldNames):_arrs(fieldNames.size())
152 std::size_t sz(fieldNames.size());
153 std::vector<std::string> names(sz);
154 for(std::size_t i=0;i<sz;i++)
156 const std::pair<std::string,int>& info(fieldNames[i]);
157 _arrs[i]=DataArrayDouble::New();
158 _arrs[i]->alloc(0,info.second);
159 _arrs[i]->setName(info.first);
160 names[i]=info.second;
162 CheckDiscriminantNames(names);
165 std::size_t DataArrayDoubleCollection::getHeapMemorySizeWithoutChildren() const
167 std::size_t ret(sizeof(DataArrayDoubleCollection));
168 ret+=_arrs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>);
172 std::vector<const BigMemoryObject *> DataArrayDoubleCollection::getDirectChildren() const
174 std::vector<const BigMemoryObject *> ret;
175 for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> >::const_iterator it=_arrs.begin();it!=_arrs.end();it++)
177 const DataArrayDouble *pt(*it);
184 void DataArrayDoubleCollection::updateTime() const
186 for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> >::const_iterator it=_arrs.begin();it!=_arrs.end();it++)
188 const DataArrayDouble *pt(*it);
194 void DataArrayDoubleCollection::CheckDiscriminantNames(const std::vector<std::string>& names)
196 std::set<std::string> s(names.begin(),names.end());
197 if(s.size()!=names.size())
198 throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::CheckDiscriminantNames : The names of fields must be different each other ! It is not the case !");
201 MEDCouplingGridCollection *MEDCouplingGridCollection::New(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames)
203 return new MEDCouplingGridCollection(ms,fieldNames);
206 void MEDCouplingGridCollection::alloc(int ghostLev)
208 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
210 int nbTuples((*it).first->getNumberOfCellsAtCurrentLevelGhost(ghostLev));
211 DataArrayDoubleCollection *dadc((*it).second);
213 dadc->allocTuples(nbTuples);
215 throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::alloc : internal error !");
219 void MEDCouplingGridCollection::dealloc()
221 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
223 DataArrayDoubleCollection *dadc((*it).second);
225 dadc->dellocTuples();
227 throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::dealloc : internal error !");
231 void MEDCouplingGridCollection::spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames)
233 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
234 (*it).second->spillInfoOnComponents(compNames);
237 bool MEDCouplingGridCollection::presenceOf(const MEDCouplingCartesianAMRMeshGen *m, int& pos) const
240 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++,ret++)
251 const DataArrayDoubleCollection& MEDCouplingGridCollection::retrieveFieldsAt(int pos) const
253 if(pos<0 || pos>(int)_map_of_dadc.size())
254 throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::retrieveFieldsAt : invalid pos given in input ! Must be in [0,size) !");
255 return *_map_of_dadc[pos].second;
258 void MEDCouplingGridCollection::SynchronizeFineToCoarse(int ghostLev, const MEDCouplingGridCollection *fine, const MEDCouplingGridCollection *coarse)
261 throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::SynchronizeFineToCoarse : one or more input pointer is NULL !");
262 const std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >& mf(fine->_map_of_dadc);
263 const std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >& mc(coarse->_map_of_dadc);
264 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it=mf.begin();it!=mf.end();it++)
266 const MEDCouplingCartesianAMRMeshGen *fineMesh((*it).first);
267 const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh(fineMesh->getFather());
269 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it0=mc.begin();it0!=mc.end() && !found;it0++)
271 if((*it0).first==fatherOfFineMesh)
274 int patchId(fatherOfFineMesh->getPatchIdFromChildMesh(fineMesh));
275 const DataArrayDoubleCollection *coarseDaCol((*it0).second);
276 DataArrayDoubleCollection *coarseModified(const_cast<DataArrayDoubleCollection *>(coarseDaCol));//coarse values in DataArrayDouble will be altered
277 DataArrayDoubleCollection::SynchronizeFineToCoarse(ghostLev,fatherOfFineMesh,patchId,(*it).second,coarseModified);
281 throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::SynchronizeFineToCoarse : a fine mesh is orphan regarding given coarse meshes !");
285 void MEDCouplingGridCollection::SynchronizeCoarseToFine(int ghostLev, const MEDCouplingGridCollection *coarse, const MEDCouplingGridCollection *fine)
288 throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::SynchronizeCoarseToFine : one or more input pointer is NULL !");
289 const std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >& mf(fine->_map_of_dadc);
290 const std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >& mc(coarse->_map_of_dadc);
291 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it=mf.begin();it!=mf.end();it++)
293 const MEDCouplingCartesianAMRMeshGen *fineMesh((*it).first);
294 const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh(fineMesh->getFather());
296 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it0=mc.begin();it0!=mc.end() && !found;it0++)
298 if((*it0).first==fatherOfFineMesh)
301 int patchId(fatherOfFineMesh->getPatchIdFromChildMesh(fineMesh));
302 const DataArrayDoubleCollection *fineDaCol((*it).second);
303 DataArrayDoubleCollection *fineModified(const_cast<DataArrayDoubleCollection *>(fineDaCol));//fine values in DataArrayDouble will be altered
304 DataArrayDoubleCollection::SynchronizeCoarseToFine(ghostLev,fatherOfFineMesh,patchId,(*it0).second,fineModified);
308 throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::SynchronizeCoarseToFine : a fine mesh is orphan regarding given coarse meshes !");
312 void MEDCouplingGridCollection::synchronizeFineEachOther(int ghostLev) const
314 std::map<const MEDCouplingCartesianAMRMeshGen *,std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *, const DataArrayDoubleCollection *> > > m;
315 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
317 const MEDCouplingCartesianAMRMeshGen *fineMesh((*it).first);
318 const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh(fineMesh->getFather());
319 m[fatherOfFineMesh].push_back(std::pair<const MEDCouplingCartesianAMRMeshGen *, const DataArrayDoubleCollection *>(fineMesh,(*it).second));
321 for(std::map<const MEDCouplingCartesianAMRMeshGen *,std::vector<std::pair<const MEDCouplingCartesianAMRMeshGen *, const DataArrayDoubleCollection *> > >::const_iterator it0=m.begin();it0!=m.end();it0++)
323 std::size_t sz((*it0).second.size());
324 std::vector<const MEDCouplingCartesianAMRMeshGen *> v0(sz);
325 std::vector<DataArrayDoubleCollection *> v1(sz);
326 for(std::size_t i=0;i<sz;i++)
328 v0[i]=(*it0).second[i].first;
329 const DataArrayDoubleCollection *tmp((*it0).second[i].second);
330 v1[i]=const_cast<DataArrayDoubleCollection *>(tmp);
332 for(std::vector<std::pair<const MEDCouplingCartesianAMRMeshGen *, const DataArrayDoubleCollection *> >::const_iterator it1=(*it0).second.begin();it1!=(*it0).second.end();it1++)
334 int patchId((*it0).first->getPatchIdFromChildMesh((*it1).first));
335 DataArrayDoubleCollection::SynchronizeFineEachOther(patchId,ghostLev,(*it0).first,v0,v1);
340 void MEDCouplingGridCollection::SynchronizeCoarseToFineOnlyInGhostZone(int ghostLev, const MEDCouplingGridCollection *coarse, const MEDCouplingGridCollection *fine)
343 throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::SynchronizeCoarseToFineOnlyInGhostZone : one or more input pointer is NULL !");
344 const std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >& mf(fine->_map_of_dadc);
345 const std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >& mc(coarse->_map_of_dadc);
346 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it=mf.begin();it!=mf.end();it++)
348 const MEDCouplingCartesianAMRMeshGen *fineMesh((*it).first);
349 const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh(fineMesh->getFather());
351 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it0=mc.begin();it0!=mc.end() && !found;it0++)
353 if((*it0).first==fatherOfFineMesh)
356 int patchId(fatherOfFineMesh->getPatchIdFromChildMesh(fineMesh));
357 const DataArrayDoubleCollection *fineDaCol((*it).second);
358 DataArrayDoubleCollection *fineModified(const_cast<DataArrayDoubleCollection *>(fineDaCol));//fine values in DataArrayDouble will be altered
359 DataArrayDoubleCollection::SynchronizeCoarseToFineOnlyInGhostZone(ghostLev,fatherOfFineMesh,patchId,(*it0).second,fineModified);
363 throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::SynchronizeCoarseToFineOnlyInGhostZone : a fine mesh is orphan regarding given coarse meshes !");
367 void MEDCouplingGridCollection::fillIfInTheProgenyOf(const std::string& fieldName, const MEDCouplingCartesianAMRMeshGen *head, std::vector<const DataArrayDouble *>& recurseArrs) const
369 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
371 const MEDCouplingCartesianAMRMeshGen *a((*it).first);
372 if(head==a || head->isObjectInTheProgeny(a))
374 const DataArrayDoubleCollection *gc((*it).second);
375 recurseArrs.push_back(gc->getFieldWithName(fieldName));
380 MEDCouplingGridCollection::MEDCouplingGridCollection(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames):_map_of_dadc(ms.size())
382 std::size_t sz(ms.size());
383 for(std::size_t i=0;i<sz;i++)
386 throw INTERP_KERNEL::Exception("MEDCouplingGridCollection constructor : presence of NULL MEDCouplingCartesianAMRMeshGen instance !");
387 _map_of_dadc[i].first=ms[i];
388 _map_of_dadc[i].second=DataArrayDoubleCollection::New(fieldNames);
392 std::size_t MEDCouplingGridCollection::getHeapMemorySizeWithoutChildren() const
394 std::size_t ret(sizeof(MEDCouplingGridCollection));
395 ret+=_map_of_dadc.capacity()*sizeof(std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> >);
399 std::vector<const BigMemoryObject *> MEDCouplingGridCollection::getDirectChildren() const
401 std::vector<const BigMemoryObject *> ret;
402 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
404 const DataArrayDoubleCollection *col((*it).second);
411 void MEDCouplingGridCollection::updateTime() const
413 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
415 const MEDCouplingCartesianAMRMeshGen *a((*it).first);
418 const DataArrayDoubleCollection *b((*it).second);
425 * This method creates, attach to a main AMR mesh \a gf ( called god father :-) ) and returns a data linked to \a gf ready for the computation.
427 MEDCouplingAMRAttribute *MEDCouplingAMRAttribute::New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames)
429 return new MEDCouplingAMRAttribute(gf,fieldNames);
432 MEDCouplingAMRAttribute *MEDCouplingAMRAttribute::New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string, std::vector<std::string> > >& fieldNames)
434 std::size_t sz(fieldNames.size());
435 std::vector< std::pair<std::string,int> > fieldNames2(sz);
436 std::vector< std::vector<std::string> > compNames(sz);
437 for(std::size_t i=0;i<sz;i++)
439 fieldNames2[i].first=fieldNames[i].first;
440 fieldNames2[i].second=(int)fieldNames[i].second.size();
441 compNames[i]=fieldNames[i].second;
443 MEDCouplingAutoRefCountObjectPtr<MEDCouplingAMRAttribute> ret(New(gf,fieldNames2));
444 ret->spillInfoOnComponents(compNames);
449 * Assign the info on components for all DataArrayDouble instance recursively stored in \a this.
450 * The first dim of input \a compNames is the field id in the same order than those implicitely specified in \a fieldNames parameter of MEDCouplingAMRAttribute::New.
451 * The second dim of \a compNames represent the component names component per component corresponding to the field. The size of this 2nd dimension has
452 * to perfectly fit with those specified in MEDCouplingAMRAttribute::New.
454 void MEDCouplingAMRAttribute::spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames)
457 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::iterator it=_levs.begin();it!=_levs.end();it++)
458 (*it)->spillInfoOnComponents(compNames);
462 * This method returns all DataArrayDouble instances lying on the specified mesh \a mesh.
463 * If \a mesh is not part of the progeny of god father object given at construction of \a this an exception will be thrown.
465 * \return std::vector<DataArrayDouble *> - DataArrayDouble instances to be deallocated by the caller (using decrRef).
466 * \sa retrieveFieldOn
468 std::vector<DataArrayDouble *> MEDCouplingAMRAttribute::retrieveFieldsOn(MEDCouplingCartesianAMRMeshGen *mesh) const
470 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::const_iterator it=_levs.begin();it!=_levs.end();it++)
473 if((*it)->presenceOf(mesh,tmp))
475 const DataArrayDoubleCollection& ddc((*it)->retrieveFieldsAt(tmp));
476 return ddc.retrieveFields();
479 throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::retrieveFieldsOn : the mesh specified is not in the progeny of this !");
483 * \sa retrieveFieldsOn
485 const DataArrayDouble *MEDCouplingAMRAttribute::getFieldOn(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const
487 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::const_iterator it=_levs.begin();it!=_levs.end();it++)
490 if((*it)->presenceOf(mesh,tmp))
492 const DataArrayDoubleCollection& ddc((*it)->retrieveFieldsAt(tmp));
493 return ddc.getFieldWithName(fieldName);
496 throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::retrieveFieldOn : the mesh specified is not in the progeny of this !");
500 * This method returns a field on an unstructured mesh the most refined as possible without overlap.
501 * Ghost part are not visible here.
503 * \return MEDCouplingFieldDouble * - a field on cells that the caller has to deal with (deallocate it).
505 MEDCouplingFieldDouble *MEDCouplingAMRAttribute::buildCellFieldOnRecurseWithoutOverlapWithoutGhost(int ghostLev, MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const
507 std::vector<const DataArrayDouble *> recurseArrs;
509 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::const_iterator it=_levs.begin();it!=_levs.end();it++,lev++)
512 if((*it)->presenceOf(mesh,tmp))
514 const DataArrayDoubleCollection& ddc((*it)->retrieveFieldsAt(tmp));
515 recurseArrs.push_back(ddc.getFieldWithName(fieldName));
520 for(std::size_t i=lev;i<_levs.size();i++)
522 const MEDCouplingGridCollection *gc(_levs[i]);
523 gc->fillIfInTheProgenyOf(fieldName,mesh,recurseArrs);
525 return mesh->buildCellFieldOnRecurseWithoutOverlapWithoutGhost(ghostLev,recurseArrs);
529 * This method builds a newly created field on cell just lying on mesh \a mesh without its eventual refinement.
531 * \return MEDCouplingFieldDouble * - a field on cells that the caller has to deal with (deallocate it).
534 MEDCouplingFieldDouble *MEDCouplingAMRAttribute::buildCellFieldOnWithGhost(int ghostLev, MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const
536 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::const_iterator it=_levs.begin();it!=_levs.end();it++)
539 if((*it)->presenceOf(mesh,tmp))
541 const DataArrayDoubleCollection& ddc((*it)->retrieveFieldsAt(tmp));
542 const DataArrayDouble *arr(ddc.getFieldWithName(fieldName));
545 throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::buildCellFieldOnWithGhost : the mesh specified is not in the progeny of this !");
549 * This method synchronizes from fine to coarse direction arrays. This method makes the hypothesis that \a this has been allocated before using
550 * MEDCouplingAMRAttribute::alloc method.
552 void MEDCouplingAMRAttribute::synchronizeFineToCoarse(int ghostLev)
555 throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeFineToCoarse : not any levels in this !");
556 std::size_t sz(_levs.size());
561 const MEDCouplingGridCollection *fine(_levs[sz]),*coarse(_levs[sz-1]);
562 MEDCouplingGridCollection::SynchronizeFineToCoarse(ghostLev,fine,coarse);
567 * This method synchronizes from coarse to fine arrays and fine to fine each other (if ghostLev is >0). This method makes the hypothesis that \a this has been allocated before using
568 * MEDCouplingAMRAttribute::alloc method.
570 void MEDCouplingAMRAttribute::synchronizeCoarseToFine(int ghostLev)
573 throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeCoarseToFine : not any levels in this !");
574 std::size_t sz(_levs.size());
576 for(std::size_t i=1;i<sz;i++)
578 const MEDCouplingGridCollection *fine(_levs[sz]),*coarse(_levs[sz-1]);
579 MEDCouplingGridCollection::SynchronizeCoarseToFine(ghostLev,coarse,fine);
584 * This method performs coarse to fine spread only in the ghost zone.
585 * This method makes the hypothesis that \a this has been allocated before using MEDCouplingAMRAttribute::alloc method.
586 * So if \a ghostLev == 0 this method has no effect.
588 void MEDCouplingAMRAttribute::synchronizeCoarseToFineOnlyInGhostZone(int ghostLev)
591 throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeCoarseToFineOnlyInGhostZone : not any levels in this !");
592 std::size_t sz(_levs.size());
594 for(std::size_t i=1;i<sz;i++)
596 const MEDCouplingGridCollection *fine(_levs[sz]),*coarse(_levs[sz-1]);
597 MEDCouplingGridCollection::SynchronizeCoarseToFineOnlyInGhostZone(ghostLev,coarse,fine);
602 * This method synchronizes fine each other only in the ghost zone.
604 void MEDCouplingAMRAttribute::synchronizeFineEachOtherInGhostZone(int ghostLev)
607 throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeFineEachOther : not any levels in this !");
608 std::size_t sz(_levs.size());
610 for(std::size_t i=1;i<sz;i++)
612 const MEDCouplingGridCollection *fine(_levs[sz]);
614 throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeFineEachOtherInGhostZone : presence of a NULL element !");
615 fine->synchronizeFineEachOther(ghostLev);
620 * This method allocates all DataArrayDouble instances stored recursively in \a this.
622 * \param [in] ghostLev - The size of ghost zone.
626 void MEDCouplingAMRAttribute::alloc(int ghostLev)
629 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::iterator it=_levs.begin();it!=_levs.end();it++)
631 MEDCouplingGridCollection *elt(*it);
633 elt->alloc(ghostLev);
635 throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::alloc : internal error !");
640 * This method deallocates all DataArrayDouble instances stored recursively in \a this.
643 void MEDCouplingAMRAttribute::dealloc()
646 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::iterator it=_levs.begin();it!=_levs.end();it++)
648 MEDCouplingGridCollection *elt(*it);
652 throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::dealloc : internal error !");
656 bool MEDCouplingAMRAttribute::changeGodFather(MEDCouplingCartesianAMRMesh *gf)
658 bool ret(MEDCouplingDataForGodFather::changeGodFather(gf));
662 std::size_t MEDCouplingAMRAttribute::getHeapMemorySizeWithoutChildren() const
664 std::size_t ret(sizeof(MEDCouplingAMRAttribute));
665 ret+=_levs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection>);
669 std::vector<const BigMemoryObject *> MEDCouplingAMRAttribute::getDirectChildren() const
671 std::vector<const BigMemoryObject *> ret;
672 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::const_iterator it=_levs.begin();it!=_levs.end();it++)
674 const MEDCouplingGridCollection *elt(*it);
681 void MEDCouplingAMRAttribute::updateTime() const
685 MEDCouplingAMRAttribute::MEDCouplingAMRAttribute(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames):MEDCouplingDataForGodFather(gf)
687 //gf non empty, checked by constructor
688 int maxLev(gf->getMaxNumberOfLevelsRelativeToThis());
689 _levs.resize(maxLev);
690 for(int i=0;i<maxLev;i++)
692 std::vector<MEDCouplingCartesianAMRPatchGen *> patches(gf->retrieveGridsAt(i));
693 std::size_t sz(patches.size());
694 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRPatchGen> > patchesSafe(patches.size());
695 for(std::size_t j=0;j<sz;j++)
696 patchesSafe[j]=patches[j];
697 std::vector<const MEDCouplingCartesianAMRMeshGen *> ms(sz);
698 for(std::size_t j=0;j<sz;j++)
700 ms[j]=patches[j]->getMesh();
702 _levs[i]=MEDCouplingGridCollection::New(ms,fieldNames);