1 // Copyright (C) 2007-2016 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 (EDF R&D)
21 #ifndef __MEDFILEFIELD_TXX__
22 #define __MEDFILEFIELD_TXX__
24 #include "MEDFileField.hxx"
25 #include "MEDCouplingTraits.hxx"
30 void MEDFileField1TSTemplateWithoutSDA<T>::setArray(DataArray *arr)
34 _nb_of_tuples_to_be_allocated=-1;
38 typename Traits<T>::ArrayType *arrC=dynamic_cast<typename Traits<T>::ArrayType *>(arr);
40 throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
42 _nb_of_tuples_to_be_allocated=-3;
48 * Returns a pointer to the underground DataArrayTemplate<T> instance. So the
49 * caller should not decrRef() it. This method allows for a direct access to the field
50 * values. This method is quite unusable if there is more than a nodal field or a cell
51 * field on single geometric cell type.
52 * \return DataArrayTemplate<T> * - the pointer to the field values array.
55 DataArray *MEDFileField1TSTemplateWithoutSDA<T>::getOrCreateAndGetArray()
57 return getOrCreateAndGetArrayTemplate();
61 const DataArray *MEDFileField1TSTemplateWithoutSDA<T>::getOrCreateAndGetArray() const
63 return getOrCreateAndGetArrayTemplate();
67 DataArray *MEDFileField1TSTemplateWithoutSDA<T>::createNewEmptyDataArrayInstance() const
69 return Traits<T>::ArrayType::New();
73 typename Traits<T>::ArrayType const *MEDFileField1TSTemplateWithoutSDA<T>::getOrCreateAndGetArrayTemplate() const
75 typename Traits<T>::ArrayType const *ret(_arr);
78 (const_cast< MEDFileField1TSTemplateWithoutSDA<T> *>(this))->_arr=Traits<T>::ArrayType::New();
83 typename Traits<T>::ArrayType *MEDFileField1TSTemplateWithoutSDA<T>::getOrCreateAndGetArrayTemplate()
85 typename Traits<T>::ArrayType *ret(_arr);
88 _arr=Traits<T>::ArrayType::New();
93 * Returns a pointer to the underground DataArrayTemplate<T> instance. So the
94 * caller should not decrRef() it. This method allows for a direct access to the field
95 * values. This method is quite unusable if there is more than a nodal field or a cell
96 * field on single geometric cell type.
97 * \return DataArrayTemplate<T> * - the pointer to the field values array.
100 typename Traits<T>::ArrayType *MEDFileField1TSTemplateWithoutSDA<T>::getUndergroundDataArrayTemplate() const
102 typename Traits<T>::ArrayType const *ret(_arr);
104 return const_cast<typename Traits<T>::ArrayType *>(ret);
110 * Returns a pointer to the underground DataArrayDouble instance. So the
111 * caller should not decrRef() it. This method allows for a direct access to the field
112 * values. This method is quite unusable if there is more than a nodal field or a cell
113 * field on single geometric cell type.
114 * \return DataArrayDouble * - the pointer to the field values array.
117 DataArray *MEDFileField1TSTemplateWithoutSDA<T>::getUndergroundDataArray() const
119 return getUndergroundDataArrayTemplate();
123 void MEDFileField1TSTemplateWithoutSDA<T>::aggregate(const std::vector<typename MLFieldTraits<T>::F1TSWSDAType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
126 throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : empty vector !");
127 std::size_t sz(f1tss.size()),ii(0);
128 std::vector<const MEDFileFieldPerMesh *> pms;
129 std::vector<const DataArray *> das(sz);
130 for(typename std::vector<typename MLFieldTraits<T>::F1TSWSDAType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,ii++)
133 throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : presence of null pointer in input vector !");
134 if((*it)->_field_per_mesh.empty())
135 throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : no info !");
136 const typename Traits<T>::ArrayType *arr((*it)->getUndergroundDataArrayTemplate());
138 throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : presence of null array !");
140 pms.push_back((*it)->_field_per_mesh[0]);
142 typename MLFieldTraits<T>::F1TSWSDAType const *refPt(f1tss[0]);
143 setName(refPt->getName());
145 const DataArray *arr(refPt->getUndergroundDataArray());
146 int nbCompo(arr->getNumberOfComponents());
147 for(typename std::vector<typename MLFieldTraits<T>::F1TSWSDAType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++)
149 const typename Traits<T>::ArrayType *myArr((*it)->getUndergroundDataArrayTemplate());
150 if(myArr->getNumberOfComponents()!=nbCompo)
151 throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : arrays must have same number of components !");
153 std::vector<std::pair< int, std::pair<int,int> > > extractInfo;
155 MCAuto<MEDFileFieldPerMesh> fpm(MEDFileFieldPerMesh::Aggregate(start,pms,dts,this,extractInfo));
156 _field_per_mesh.push_back(fpm);
158 double tv(f1tss[0]->getTime(iteration,order));
159 _iteration=iteration; _order=order; _dt=tv;
160 _arr=Traits<T>::ArrayType::New();
161 _arr->alloc(start,nbCompo); _arr->copyStringInfoFrom(*arr);
163 for(std::vector<std::pair< int, std::pair<int,int> > >::const_iterator it=extractInfo.begin();it!=extractInfo.end();it++)
165 const DataArray *zeArr(das[(*it).first]);
166 _arr->setContigPartOfSelectedValuesSlice(start,zeArr,(*it).second.first,(*it).second.second,1);
167 start+=(*it).second.second-(*it).second.first;