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"
24 using namespace ParaMEDMEM;
26 DataArrayDoubleCollection *DataArrayDoubleCollection::New(const std::vector< std::pair<std::string,int> >& fieldNames)
28 return new DataArrayDoubleCollection(fieldNames);
31 void DataArrayDoubleCollection::allocTuples(int nbOfTuples)
33 std::size_t sz(_arrs.size());
34 for(std::size_t i=0;i<sz;i++)
35 _arrs[i]->reAlloc(nbOfTuples);
38 void DataArrayDoubleCollection::dellocTuples()
40 std::size_t sz(_arrs.size());
41 for(std::size_t i=0;i<sz;i++)
45 void DataArrayDoubleCollection::spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames)
47 std::size_t sz(_arrs.size());
48 if(sz!=compNames.size())
49 throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::spillInfoOnComponents : first size of compNames has to be equal to the number of fields defined !");
50 for(std::size_t i=0;i<sz;i++)
52 const std::vector<std::string>& names(compNames[i]);
53 _arrs[i]->setInfoOnComponents(names);
57 DataArrayDoubleCollection::DataArrayDoubleCollection(const std::vector< std::pair<std::string,int> >& fieldNames):_arrs(fieldNames.size())
59 std::size_t sz(fieldNames.size());
60 std::vector<std::string> names(sz);
61 for(std::size_t i=0;i<sz;i++)
63 const std::pair<std::string,int>& info(fieldNames[i]);
64 _arrs[i]=DataArrayDouble::New();
65 _arrs[i]->alloc(0,info.second);
66 _arrs[i]->setName(info.first);
69 CheckDiscriminantNames(names);
72 std::size_t DataArrayDoubleCollection::getHeapMemorySizeWithoutChildren() const
74 std::size_t ret(sizeof(DataArrayDoubleCollection));
75 ret+=_arrs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>);
79 std::vector<const BigMemoryObject *> DataArrayDoubleCollection::getDirectChildren() const
81 std::vector<const BigMemoryObject *> ret;
82 for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> >::const_iterator it=_arrs.begin();it!=_arrs.end();it++)
84 const DataArrayDouble *pt(*it);
91 void DataArrayDoubleCollection::updateTime() const
93 for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> >::const_iterator it=_arrs.begin();it!=_arrs.end();it++)
95 const DataArrayDouble *pt(*it);
101 void DataArrayDoubleCollection::CheckDiscriminantNames(const std::vector<std::string>& names)
103 std::set<std::string> s(names.begin(),names.end());
104 if(s.size()!=names.size())
105 throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::CheckDiscriminantNames : The names of fields must be different each other ! It is not the case !");
108 MEDCouplingGridCollection *MEDCouplingGridCollection::New(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames)
110 return new MEDCouplingGridCollection(ms,fieldNames);
113 void MEDCouplingGridCollection::alloc(int ghostLev)
115 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
117 int nbTuples((*it).first->getNumberOfCellsAtCurrentLevelGhost(ghostLev));
118 DataArrayDoubleCollection *dadc((*it).second);
120 dadc->allocTuples(nbTuples);
122 throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::alloc : internal error !");
126 void MEDCouplingGridCollection::dealloc()
128 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
130 DataArrayDoubleCollection *dadc((*it).second);
132 dadc->dellocTuples();
134 throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::dealloc : internal error !");
138 void MEDCouplingGridCollection::spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames)
140 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
141 (*it).second->spillInfoOnComponents(compNames);
144 MEDCouplingGridCollection::MEDCouplingGridCollection(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames):_map_of_dadc(ms.size())
146 std::size_t sz(ms.size());
147 for(std::size_t i=0;i<sz;i++)
150 throw INTERP_KERNEL::Exception("MEDCouplingGridCollection constructor : presence of NULL MEDCouplingCartesianAMRMeshGen instance !");
151 _map_of_dadc[i].first=ms[i];
152 _map_of_dadc[i].second=DataArrayDoubleCollection::New(fieldNames);
156 std::size_t MEDCouplingGridCollection::getHeapMemorySizeWithoutChildren() const
158 std::size_t ret(sizeof(MEDCouplingGridCollection));
159 ret+=_map_of_dadc.capacity()*sizeof(std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> >);
163 std::vector<const BigMemoryObject *> MEDCouplingGridCollection::getDirectChildren() const
165 std::vector<const BigMemoryObject *> ret;
166 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
168 const DataArrayDoubleCollection *col((*it).second);
175 void MEDCouplingGridCollection::updateTime() const
177 for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
179 const MEDCouplingCartesianAMRMeshGen *a((*it).first);
182 const DataArrayDoubleCollection *b((*it).second);
189 * 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.
191 MEDCouplingAMRAttribute *MEDCouplingAMRAttribute::New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames)
193 return new MEDCouplingAMRAttribute(gf,fieldNames);
197 * Assign the info on components for all DataArrayDouble instance recursively stored in \a this.
198 * 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.
199 * The second dim of \a compNames represent the component names component per component corresponding to the field. The size of this 2nd dimension has
200 * to perfectly fit with those specified in MEDCouplingAMRAttribute::New.
202 void MEDCouplingAMRAttribute::spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames)
205 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::iterator it=_levs.begin();it!=_levs.end();it++)
206 (*it)->spillInfoOnComponents(compNames);
210 * This method allocates all DataArrayDouble instances stored recursively in \a this.
212 * \param [in] ghostLev - The size of ghost zone.
216 void MEDCouplingAMRAttribute::alloc(int ghostLev)
219 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::iterator it=_levs.begin();it!=_levs.end();it++)
221 MEDCouplingGridCollection *elt(*it);
223 elt->alloc(ghostLev);
225 throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::alloc : internal error !");
230 * This method deallocates all DataArrayDouble instances stored recursively in \a this.
233 void MEDCouplingAMRAttribute::dealloc()
236 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::iterator it=_levs.begin();it!=_levs.end();it++)
238 MEDCouplingGridCollection *elt(*it);
242 throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::dealloc : internal error !");
246 bool MEDCouplingAMRAttribute::changeGodFather(MEDCouplingCartesianAMRMesh *gf)
248 bool ret(MEDCouplingDataForGodFather::changeGodFather(gf));
252 std::size_t MEDCouplingAMRAttribute::getHeapMemorySizeWithoutChildren() const
254 std::size_t ret(sizeof(MEDCouplingAMRAttribute));
255 ret+=_levs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection>);
259 std::vector<const BigMemoryObject *> MEDCouplingAMRAttribute::getDirectChildren() const
261 std::vector<const BigMemoryObject *> ret;
262 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::const_iterator it=_levs.begin();it!=_levs.end();it++)
264 const MEDCouplingGridCollection *elt(*it);
271 void MEDCouplingAMRAttribute::updateTime() const
275 MEDCouplingAMRAttribute::MEDCouplingAMRAttribute(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames):MEDCouplingDataForGodFather(gf)
277 //gf non empty, checked by constructor
278 int maxLev(gf->getMaxNumberOfLevelsRelativeToThis()+1);
279 _levs.resize(maxLev+1);
280 for(int i=0;i<maxLev;i++)
282 std::vector<MEDCouplingCartesianAMRPatchGen *> patches(gf->retrieveGridsAt(i));
283 std::size_t sz(patches.size());
284 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRPatchGen> > patchesSafe(patches.size());
285 for(std::size_t j=0;j<sz;j++)
286 patchesSafe[j]=patches[j];
287 std::vector<const MEDCouplingCartesianAMRMeshGen *> ms(sz);
288 for(std::size_t j=0;j<sz;j++)
290 ms[j]=patches[j]->getMesh();
292 _levs[i]=MEDCouplingGridCollection::New(ms,fieldNames);