From: Anthony Geay Date: Mon, 3 Oct 2016 13:51:30 +0000 (+0200) Subject: Nearly finished... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=28aa429b0ee36c8d619cfaada5d1129d55c55909;p=tools%2Fmedcoupling.git Nearly finished... --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index d3c7904a3..2663844df 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -18,7 +18,7 @@ // // Author : Anthony Geay (CEA/DEN) -#include "MEDFileField.hxx" +#include "MEDFileField.txx" #include "MEDFileMesh.hxx" #include "MEDLoaderBase.hxx" #include "MEDLoaderTraits.hxx" @@ -43,6 +43,9 @@ extern med_geometry_type typmai3[34]; using namespace MEDCoupling; +template class MEDFileField1TSTemplateWithoutSDA; +template class MEDFileField1TSTemplateWithoutSDA; + const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64"; const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32"; @@ -2339,19 +2342,47 @@ const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAn } /*! - * dts = level 1 meshes to aggregate. Level 2 all geo type. Level 3 pair specifying geo type and number of elem in geotype. + * \param [in,out] start - Integer that gives the current position in the final aggregated array + * \param [in] pms - list of elements to aggregate. integer gives the mesh id + * \param [in] dts - (Distribution of types) = level 1 : meshes to aggregate. Level 2 : all geo type. Level 3 pair specifying geo type and number of elem in geotype. + * \param [out] extractInfo - Gives information about the where the data comes from. It is a vector of triplet. First element in the triplet the mesh pos. The 2nd one the start pos. The 3rd the end pos. */ MCAuto MEDFileFieldPerMeshPerTypePerDisc::Aggregate(int &start, const std::vector< std::pair >& pms, const std::vector< std::vector< std::pair > >& dts, TypeOfField tof, MEDFileFieldPerMeshPerType *father, std::vector > >& extractInfo) { MCAuto ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof)); + if(pms.empty()) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !"); for(std::vector >::const_iterator it=pms.begin();it!=pms.end();it++) { + if(!(*it).second) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !"); if(!(*it).second->getProfile().empty()) throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !"); if(!(*it).second->getLocalization().empty()) throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !"); - //getNumberOfTuples } + INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType()); + std::size_t i(0); + std::vector< std::pair > filteredDTS; + for(std::vector< std::vector< std::pair > >::const_iterator it=dts.begin();it!=dts.end();it++,i++) + for(std::vector< std::pair >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++) + if((*it2).first==gt) + filteredDTS.push_back(std::pair(i,(*it2).second)); + if(pms.size()!=filteredDTS.size()) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !"); + std::vector >::const_iterator it1(pms.begin()); + std::vector< std::pair >::const_iterator it2(filteredDTS.begin()); + int zeStart(start),nval(0); + for(;it1!=pms.end();it1++,it2++) + { + if((*it1).first!=(*it2).first) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !"); + int s1((*it1).second->getStart()),e1((*it1).second->getEnd()); + extractInfo.push_back(std::pair >((*it1).first,std::pair(s1,e1))); + start+=e1-s1; + nval+=((*it1).second)->getNumberOfVals(); + } + ret->_start=zeStart; ret->_end=start; ret->_nval=nval; return ret; } @@ -2372,7 +2403,7 @@ MCAuto MEDFileFieldPerMeshPerType::Aggregate(int &st return ret; } -MCAuto MEDFileFieldPerMesh::Aggregate(const std::vector& pms, const std::vector< std::vector< std::pair > >& dts, MEDFileAnyTypeField1TSWithoutSDA *father, std::vector > >& extractInfo) +MCAuto MEDFileFieldPerMesh::Aggregate(int &start, const std::vector& pms, const std::vector< std::vector< std::pair > >& dts, MEDFileAnyTypeField1TSWithoutSDA *father, std::vector > >& extractInfo) { MCAuto ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder())); std::map > > m; @@ -2386,7 +2417,6 @@ MCAuto MEDFileFieldPerMesh::Aggregate(const std::vector(i,*it2)); } } - int start(0); for(std::map > >::const_iterator it=m.begin();it!=m.end();it++) { MCAuto agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo)); @@ -5168,22 +5198,6 @@ std::vector< std::vector > MEDFileField1TSWithoutSDA::getFiel return ret; } -/*! - * Returns a pointer to the underground DataArrayDouble instance. So the - * caller should not decrRef() it. This method allows for a direct access to the field - * values. This method is quite unusable if there is more than a nodal field or a cell - * field on single geometric cell type. - * \return DataArrayDouble * - the pointer to the field values array. - */ -DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const -{ - const DataArrayDouble *ret=_arr; - if(ret) - return const_cast(ret); - else - return 0; -} - const char *MEDFileField1TSWithoutSDA::getTypeStr() const { return TYPE_STR; @@ -5203,40 +5217,6 @@ MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const return ret.retn(); } -void MEDFileField1TSWithoutSDA::aggregate(const std::vector& f1tss, const std::vector< std::vector< std::pair > >& dts) -{ - if(f1tss.empty()) - throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::aggregate : empty vector !"); - std::vector pms; - for(std::vector::const_iterator it=f1tss.begin();it!=f1tss.end();it++) - { - if(!*it) - throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::aggregate : presence of null pointer in input vector !"); - if((*it)->_field_per_mesh.empty()) - throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::aggregate : no info !"); - pms.push_back((*it)->_field_per_mesh[0]); - } - std::vector > > extractInfo; - MCAuto fpm(MEDFileFieldPerMesh::Aggregate(pms,dts,this,extractInfo)); - _field_per_mesh.push_back(fpm); - int iteration,order; - double tv(f1tss[0]->getTime(iteration,order)); - _iteration=iteration; _order=order; _dt=tv; - -} - -/*! - * Returns a pointer to the underground DataArrayDouble instance. So the - * caller should not decrRef() it. This method allows for a direct access to the field - * values. This method is quite unusable if there is more than a nodal field or a cell - * field on single geometric cell type. - * \return DataArrayDouble * - the pointer to the field values array. - */ -DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const -{ - return getUndergroundDataArrayDouble(); -} - /*! * Returns a pointer to the underground DataArrayDouble instance and a * sequence describing parameters of a support of each part of \a this field. The @@ -5260,7 +5240,7 @@ DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std if(_field_per_mesh[0]==0) throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !"); _field_per_mesh[0]->getUndergroundDataArrayExt(entries); - return getUndergroundDataArrayDouble(); + return getUndergroundDataArrayTemplate(); } /*! @@ -5284,13 +5264,13 @@ DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< st return getUndergroundDataArrayDoubleExt(entries); } -MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order) +MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector& infos):MEDFileField1TSTemplateWithoutSDA(fieldName,csit,iteration,order) { - DataArrayDouble *arr(getOrCreateAndGetArrayDouble()); + DataArrayDouble *arr(getOrCreateAndGetArrayTemplate()); arr->setInfoAndChangeNbOfCompo(infos); } -MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA() +MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA() { } @@ -5309,57 +5289,6 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const return ret.retn(); } -void MEDFileField1TSWithoutSDA::setArray(DataArray *arr) -{ - if(!arr) - { - _nb_of_tuples_to_be_allocated=-1; - _arr=0; - return ; - } - DataArrayDouble *arrC=dynamic_cast(arr); - if(!arrC) - throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !"); - else - _nb_of_tuples_to_be_allocated=-3; - arrC->incrRef(); - _arr=arrC; -} - -DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const -{ - return DataArrayDouble::New(); -} - -DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() -{ - DataArrayDouble *ret=_arr; - if(ret) - return ret; - _arr=DataArrayDouble::New(); - return _arr; -} - -DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() -{ - return getOrCreateAndGetArrayDouble(); -} - -const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const -{ - const DataArrayDouble *ret=_arr; - if(ret) - return ret; - DataArrayDouble *ret2=DataArrayDouble::New(); - const_cast(this)->_arr=DataArrayDouble::New(); - return ret2; -} - -const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const -{ - return getOrCreateAndGetArrayDouble(); -} - //= MEDFileIntField1TSWithoutSDA MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector& infos) @@ -5367,14 +5296,14 @@ MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::strin return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos); } -MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA() +MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA() { } MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, - const std::vector& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order) + const std::vector& infos):MEDFileField1TSTemplateWithoutSDA(fieldName,csit,iteration,order) { - DataArrayInt *arr(getOrCreateAndGetArrayInt()); + DataArrayInt *arr(getOrCreateAndGetArrayTemplate()); arr->setInfoAndChangeNbOfCompo(infos); } @@ -5397,34 +5326,6 @@ MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const return ret.retn(); } -/*! - * Returns a pointer to the underground DataArrayInt instance. So the - * caller should not decrRef() it. This method allows for a direct access to the field - * values. This method is quite unusable if there is more than a nodal field or a cell - * field on single geometric cell type. - * \return DataArrayInt * - the pointer to the field values array. - */ -DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const -{ - return getUndergroundDataArrayInt(); -} - -/*! - * Returns a pointer to the underground DataArrayInt instance. So the - * caller should not decrRef() it. This method allows for a direct access to the field - * values. This method is quite unusable if there is more than a nodal field or a cell - * field on single geometric cell type. - * \return DataArrayInt * - the pointer to the field values array. - */ -DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const -{ - const DataArrayInt *ret=_arr; - if(ret) - return const_cast(ret); - else - return 0; -} - /*! * Returns a pointer to the underground DataArrayInt instance and a * sequence describing parameters of a support of each part of \a this field. The @@ -5469,7 +5370,7 @@ DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::v if(_field_per_mesh[0]==0) throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !"); _field_per_mesh[0]->getUndergroundDataArrayExt(entries); - return getUndergroundDataArrayInt(); + return getUndergroundDataArrayTemplate(); } MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const @@ -5487,57 +5388,6 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const return ret.retn(); } -void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr) -{ - if(!arr) - { - _nb_of_tuples_to_be_allocated=-1; - _arr=0; - return ; - } - DataArrayInt *arrC=dynamic_cast(arr); - if(!arrC) - throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !"); - else - _nb_of_tuples_to_be_allocated=-3; - arrC->incrRef(); - _arr=arrC; -} - -DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const -{ - return DataArrayInt::New(); -} - -DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() -{ - DataArrayInt *ret=_arr; - if(ret) - return ret; - _arr=DataArrayInt::New(); - return _arr; -} - -DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() -{ - return getOrCreateAndGetArrayInt(); -} - -const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const -{ - const DataArrayInt *ret=_arr; - if(ret) - return ret; - DataArrayInt *ret2=DataArrayInt::New(); - const_cast(this)->_arr=DataArrayInt::New(); - return ret2; -} - -const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const -{ - return getOrCreateAndGetArrayInt(); -} - MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS() { } @@ -6837,7 +6687,7 @@ MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const { - return contentNotNull()->getUndergroundDataArrayDouble(); + return contentNotNull()->getUndergroundDataArrayTemplate(); } DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair,std::pair > >& entries) const @@ -7244,7 +7094,7 @@ MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const { - return contentNotNull()->getUndergroundDataArrayInt(); + return contentNotNull()->getUndergroundDataArrayTemplate(); } //= MEDFileAnyTypeFieldMultiTSWithoutSDA diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 1e8bde153..d26ae7a69 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -27,6 +27,8 @@ #include "MEDFileUtilities.hxx" #include "MCAuto.hxx" +#include "MEDLoaderTraits.hxx" +#include "MEDCouplingTraits.hxx" #include "MEDCouplingRefCountObject.hxx" #include "MEDCouplingFieldInt.hxx" #include "MEDCouplingMemArray.hxx" @@ -289,7 +291,7 @@ namespace MEDCoupling void getUndergroundDataArrayExt(std::vector< std::pair,std::pair > >& entries) const; MEDFileFieldPerMeshPerTypePerDisc *getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId); const MEDFileFieldPerMeshPerTypePerDisc *getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const; - static MCAuto Aggregate(const std::vector& pms, const std::vector< std::vector< std::pair > >& dts, MEDFileAnyTypeField1TSWithoutSDA *father, std::vector > >& extractInfo); + static MCAuto Aggregate(int &start, const std::vector& pms, const std::vector< std::vector< std::pair > >& dts, MEDFileAnyTypeField1TSWithoutSDA *father, std::vector > >& extractInfo); private: int addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type); MEDCouplingFieldDouble *finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob, @@ -569,16 +571,34 @@ namespace MEDCoupling class MEDFileIntField1TSWithoutSDA; + template + class MEDFileField1TSTemplateWithoutSDA : public MEDFileAnyTypeField1TSWithoutSDA + { + protected: + MEDFileField1TSTemplateWithoutSDA(const std::string& fieldName, int csit, int iteration, int order):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order) { } + MEDFileField1TSTemplateWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA() { } + public: + MEDLOADER_EXPORT void setArray(DataArray *arr); + MEDLOADER_EXPORT DataArray *createNewEmptyDataArrayInstance() const; + MEDLOADER_EXPORT typename Traits::ArrayType *getOrCreateAndGetArrayTemplate(); + MEDLOADER_EXPORT typename Traits::ArrayType const *getOrCreateAndGetArrayTemplate() const; + MEDLOADER_EXPORT typename Traits::ArrayType *getUndergroundDataArrayTemplate() const; + MEDLOADER_EXPORT DataArray *getOrCreateAndGetArray(); + MEDLOADER_EXPORT const DataArray *getOrCreateAndGetArray() const; + MEDLOADER_EXPORT DataArray *getUndergroundDataArray() const; + MEDLOADER_EXPORT void aggregate(const typename std::vector< typename MLFieldTraits::F1TSWSDAType const * >& f1tss, const std::vector< std::vector< std::pair > >& dts); + protected: + MCAuto< typename Traits::ArrayType > _arr; + }; + /*! * SDA is for Shared Data Arrays such as profiles. */ - class MEDFileField1TSWithoutSDA : public MEDFileAnyTypeField1TSWithoutSDA + class MEDFileField1TSWithoutSDA : public MEDFileField1TSTemplateWithoutSDA { public: MEDLOADER_EXPORT const char *getTypeStr() const; - MEDLOADER_EXPORT DataArray *getUndergroundDataArray() const; MEDLOADER_EXPORT DataArray *getUndergroundDataArrayExt(std::vector< std::pair,std::pair > >& entries) const; - MEDLOADER_EXPORT DataArrayDouble *getUndergroundDataArrayDouble() const; MEDLOADER_EXPORT DataArrayDouble *getUndergroundDataArrayDoubleExt(std::vector< std::pair,std::pair > >& entries) const; MEDLOADER_EXPORT std::vector< std::vector > getFieldSplitedByType2(const std::string& mname, std::vector& types, std::vector< std::vector >& typesF, std::vector< std::vector >& pfls, std::vector< std::vector >& locs) const; MEDLOADER_EXPORT static void CheckMeshDimRel(int meshDimRelToMax); @@ -589,16 +609,7 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector& infos); MEDLOADER_EXPORT MEDFileAnyTypeField1TSWithoutSDA *shallowCpy() const; MEDLOADER_EXPORT MEDFileAnyTypeField1TSWithoutSDA *deepCopy() const; - MEDLOADER_EXPORT void setArray(DataArray *arr); - MEDLOADER_EXPORT DataArray *createNewEmptyDataArrayInstance() const; - MEDLOADER_EXPORT DataArray *getOrCreateAndGetArray(); - MEDLOADER_EXPORT const DataArray *getOrCreateAndGetArray() const; - MEDLOADER_EXPORT DataArrayDouble *getOrCreateAndGetArrayDouble(); - MEDLOADER_EXPORT const DataArrayDouble *getOrCreateAndGetArrayDouble() const; MEDLOADER_EXPORT MEDFileIntField1TSWithoutSDA *convertToInt() const; - MEDLOADER_EXPORT void aggregate(const std::vector& f1tss, const std::vector< std::vector< std::pair > >& dts); - protected: - MCAuto< DataArrayDouble > _arr; public: static const char TYPE_STR[]; }; @@ -606,7 +617,7 @@ namespace MEDCoupling /*! * SDA is for Shared Data Arrays such as profiles. */ - class MEDFileIntField1TSWithoutSDA : public MEDFileAnyTypeField1TSWithoutSDA + class MEDFileIntField1TSWithoutSDA : public MEDFileField1TSTemplateWithoutSDA { public: MEDLOADER_EXPORT MEDFileIntField1TSWithoutSDA(); @@ -614,22 +625,11 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileAnyTypeField1TSWithoutSDA *deepCopy() const; MEDLOADER_EXPORT MEDFileAnyTypeField1TSWithoutSDA *shallowCpy() const; MEDLOADER_EXPORT const char *getTypeStr() const; - MEDLOADER_EXPORT DataArray *getUndergroundDataArray() const; MEDLOADER_EXPORT DataArray *getUndergroundDataArrayExt(std::vector< std::pair,std::pair > >& entries) const; - MEDLOADER_EXPORT void setArray(DataArray *arr); - MEDLOADER_EXPORT DataArray *createNewEmptyDataArrayInstance() const; - MEDLOADER_EXPORT DataArray *getOrCreateAndGetArray(); - MEDLOADER_EXPORT const DataArray *getOrCreateAndGetArray() const; - MEDLOADER_EXPORT DataArrayInt *getOrCreateAndGetArrayInt(); - MEDLOADER_EXPORT const DataArrayInt *getOrCreateAndGetArrayInt() const; - MEDLOADER_EXPORT DataArrayInt *getUndergroundDataArrayInt() const; MEDLOADER_EXPORT DataArrayInt *getUndergroundDataArrayIntExt(std::vector< std::pair,std::pair > >& entries) const; MEDLOADER_EXPORT MEDFileField1TSWithoutSDA *convertToDouble() const; - MEDLOADER_EXPORT void aggregate(const std::vector& f1tss, const std::vector< std::vector< std::pair > >& dts); protected: MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector& infos); - protected: - MCAuto< DataArrayInt > _arr; public: MEDLOADER_EXPORT static const char TYPE_STR[]; }; diff --git a/src/MEDLoader/MEDFileField.txx b/src/MEDLoader/MEDFileField.txx new file mode 100644 index 000000000..b2363fc90 --- /dev/null +++ b/src/MEDLoader/MEDFileField.txx @@ -0,0 +1,170 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (EDF R&D) + +#ifndef __MEDFILEFIELD_TXX__ +#define __MEDFILEFIELD_TXX__ + +#include "MEDFileField.hxx" +#include "MEDCouplingTraits.hxx" + +namespace MEDCoupling +{ + template + void MEDFileField1TSTemplateWithoutSDA::setArray(DataArray *arr) + { + if(!arr) + { + _nb_of_tuples_to_be_allocated=-1; + _arr=0; + return ; + } + typename Traits::ArrayType *arrC=dynamic_cast::ArrayType *>(arr); + if(!arrC) + throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !"); + else + _nb_of_tuples_to_be_allocated=-3; + arrC->incrRef(); + _arr=arrC; + } + + /*! + * Returns a pointer to the underground DataArrayTemplate instance. So the + * caller should not decrRef() it. This method allows for a direct access to the field + * values. This method is quite unusable if there is more than a nodal field or a cell + * field on single geometric cell type. + * \return DataArrayTemplate * - the pointer to the field values array. + */ + template + DataArray *MEDFileField1TSTemplateWithoutSDA::getOrCreateAndGetArray() + { + return getOrCreateAndGetArrayTemplate(); + } + + template + const DataArray *MEDFileField1TSTemplateWithoutSDA::getOrCreateAndGetArray() const + { + return getOrCreateAndGetArrayTemplate(); + } + + template + DataArray *MEDFileField1TSTemplateWithoutSDA::createNewEmptyDataArrayInstance() const + { + return Traits::ArrayType::New(); + } + + template + typename Traits::ArrayType const *MEDFileField1TSTemplateWithoutSDA::getOrCreateAndGetArrayTemplate() const + { + typename Traits::ArrayType const *ret(_arr); + if(ret) + return ret; + (const_cast< MEDFileField1TSTemplateWithoutSDA *>(this))->_arr=Traits::ArrayType::New(); + return _arr; + } + + template + typename Traits::ArrayType *MEDFileField1TSTemplateWithoutSDA::getOrCreateAndGetArrayTemplate() + { + typename Traits::ArrayType *ret(_arr); + if(ret) + return ret; + _arr=Traits::ArrayType::New(); + return _arr; + } + + /*! + * Returns a pointer to the underground DataArrayTemplate instance. So the + * caller should not decrRef() it. This method allows for a direct access to the field + * values. This method is quite unusable if there is more than a nodal field or a cell + * field on single geometric cell type. + * \return DataArrayTemplate * - the pointer to the field values array. + */ + template + typename Traits::ArrayType *MEDFileField1TSTemplateWithoutSDA::getUndergroundDataArrayTemplate() const + { + typename Traits::ArrayType const *ret(_arr); + if(ret) + return const_cast::ArrayType *>(ret); + else + return 0; + } + + /*! + * Returns a pointer to the underground DataArrayDouble instance. So the + * caller should not decrRef() it. This method allows for a direct access to the field + * values. This method is quite unusable if there is more than a nodal field or a cell + * field on single geometric cell type. + * \return DataArrayDouble * - the pointer to the field values array. + */ + template + DataArray *MEDFileField1TSTemplateWithoutSDA::getUndergroundDataArray() const + { + return getUndergroundDataArrayTemplate(); + } + + template + void MEDFileField1TSTemplateWithoutSDA::aggregate(const std::vector::F1TSWSDAType const *>& f1tss, const std::vector< std::vector< std::pair > >& dts) + { + if(f1tss.empty()) + throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : empty vector !"); + std::size_t sz(f1tss.size()),ii(0); + std::vector pms; + std::vector das(sz); + for(typename std::vector::F1TSWSDAType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,ii) + { + if(!*it) + throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : presence of null pointer in input vector !"); + if((*it)->_field_per_mesh.empty()) + throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : no info !"); + const typename Traits::ArrayType *arr((*it)->getUndergroundDataArrayTemplate()); + if(!arr) + throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : presence of null array !"); + das[ii]=arr; + pms.push_back((*it)->_field_per_mesh[0]); + } + typename MLFieldTraits::F1TSWSDAType const *refPt(f1tss[0]); + const DataArray *arr(refPt->getUndergroundDataArray()); + int nbCompo(arr->getNumberOfComponents()); + for(typename std::vector::F1TSWSDAType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++) + { + const typename Traits::ArrayType *myArr((*it)->getUndergroundDataArrayTemplate()); + if(myArr->getNumberOfComponents()!=nbCompo) + throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::aggregate : arrays must have same number of components !"); + } + std::vector > > extractInfo; + int start(0); + MCAuto fpm(MEDFileFieldPerMesh::Aggregate(start,pms,dts,this,extractInfo)); + _field_per_mesh.push_back(fpm); + int iteration,order; + double tv(f1tss[0]->getTime(iteration,order)); + _iteration=iteration; _order=order; _dt=tv; + _arr=Traits::ArrayType::New(); + _arr->alloc(start,nbCompo); _arr->copyStringInfoFrom(*arr); + start=0; + for(std::vector > >::const_iterator it=extractInfo.begin();it!=extractInfo.end();it++) + { + const DataArray *zeArr(das[(*it).first]); + _arr->setContigPartOfSelectedValuesSlice(start,zeArr,(*it).second.first,(*it).second.second,1); + start=(*it).second.second-(*it).second.first; + } + } +} + +#endif