Salome HOME
On the road of fields on AMR meshes
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingAMRAttribute.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay
20
21 #include "MEDCouplingAMRAttribute.hxx"
22 #include "MEDCouplingMemArray.hxx"
23
24 using namespace ParaMEDMEM;
25
26 DataArrayDoubleCollection *DataArrayDoubleCollection::New(const std::vector< std::pair<std::string,int> >& fieldNames)
27 {
28   return new DataArrayDoubleCollection(fieldNames);
29 }
30
31 void DataArrayDoubleCollection::allocTuples(int nbOfTuples)
32 {
33   std::size_t sz(_arrs.size());
34   for(std::size_t i=0;i<sz;i++)
35     _arrs[i]->reAlloc(nbOfTuples);
36 }
37
38 void DataArrayDoubleCollection::dellocTuples()
39 {
40   std::size_t sz(_arrs.size());
41   for(std::size_t i=0;i<sz;i++)
42     _arrs[i]->reAlloc(0);
43 }
44
45 DataArrayDoubleCollection::DataArrayDoubleCollection(const std::vector< std::pair<std::string,int> >& fieldNames):_arrs(fieldNames.size())
46 {
47   std::size_t sz(fieldNames.size());
48   std::vector<std::string> names(sz);
49   for(std::size_t i=0;i<sz;i++)
50     {
51       const std::pair<std::string,int>& info(fieldNames[i]);
52       _arrs[i]=DataArrayDouble::New();
53       _arrs[i]->alloc(0,info.second);
54       _arrs[i]->setName(info.first);
55       names[i]=info.second;
56     }
57   CheckDiscriminantNames(names);
58 }
59
60 std::size_t DataArrayDoubleCollection::getHeapMemorySizeWithoutChildren() const
61 {
62   std::size_t ret(sizeof(DataArrayDoubleCollection));
63   ret+=_arrs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>);
64   return ret;
65 }
66
67 std::vector<const BigMemoryObject *> DataArrayDoubleCollection::getDirectChildren() const
68 {
69   std::vector<const BigMemoryObject *> ret;
70   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> >::const_iterator it=_arrs.begin();it!=_arrs.end();it++)
71     {
72       const DataArrayDouble *pt(*it);
73       if(pt)
74         ret.push_back(pt);
75     }
76   return ret;
77 }
78
79 void DataArrayDoubleCollection::CheckDiscriminantNames(const std::vector<std::string>& names)
80 {
81   std::set<std::string> s(names.begin(),names.end());
82   if(s.size()!=names.size())
83     throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::CheckDiscriminantNames : The names of fields must be different each other ! It is not the case !");
84 }
85
86 std::size_t MEDCouplingGridCollection::getHeapMemorySizeWithoutChildren() const
87 {
88   std::size_t ret(sizeof(MEDCouplingGridCollection));
89   ret+=_map_of_dadc.capacity()*sizeof(std::pair<MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> >);
90   return ret;
91 }
92
93 std::vector<const BigMemoryObject *> MEDCouplingGridCollection::getDirectChildren() const
94 {
95   std::vector<const BigMemoryObject *> ret;
96   for(std::vector< std::pair<MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
97     {
98       const DataArrayDoubleCollection *col((*it).second);
99       if(col)
100         ret.push_back(col);
101     }
102   return ret;
103 }
104
105 MEDCouplingAMRAttribute *MEDCouplingAMRAttribute::New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames)
106 {
107   return new MEDCouplingAMRAttribute(gf,fieldNames);
108 }
109
110 void MEDCouplingAMRAttribute::alloc()
111 {
112   _tlc.resetState();
113 }
114
115 void MEDCouplingAMRAttribute::dealloc()
116 {//tony
117 }
118
119 bool MEDCouplingAMRAttribute::changeGodFather(MEDCouplingCartesianAMRMesh *gf)
120 {
121   bool ret(MEDCouplingDataForGodFather::changeGodFather(gf));
122   return ret;
123 }
124
125 std::size_t MEDCouplingAMRAttribute::getHeapMemorySizeWithoutChildren() const
126 {
127   std::size_t ret(sizeof(MEDCouplingAMRAttribute));
128   return ret;
129 }
130
131 std::vector<const BigMemoryObject *> MEDCouplingAMRAttribute::getDirectChildren() const
132 {//tony
133   return std::vector<const BigMemoryObject *>();
134 }
135
136 void MEDCouplingAMRAttribute::updateTime() const
137 {//tony
138 }
139
140 MEDCouplingAMRAttribute::MEDCouplingAMRAttribute(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames):MEDCouplingDataForGodFather(gf)
141 {
142 }