X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FMEDFileField.txx;h=a6814f4b4fd7d5fd6aa564efba780df021f2898e;hb=3ccbd6672d4cab9ddd873774deb1276b43ccb621;hp=f0070f5decb623a1914ef7bc8ea38e0b7e174e31;hpb=b4634cfcaa239b987c02485ba0b9b5e6a666676f;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/MEDFileField.txx b/src/MEDLoader/MEDFileField.txx index f0070f5de..a6814f4b4 100644 --- a/src/MEDLoader/MEDFileField.txx +++ b/src/MEDLoader/MEDFileField.txx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D +// Copyright (C) 2007-2024 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -18,12 +18,12 @@ // // Author : Anthony Geay (EDF R&D) -#ifndef __MEDFILEFIELD_TXX__ -#define __MEDFILEFIELD_TXX__ +#pragma once #include "MEDFileField.hxx" #include "MEDCouplingTraits.hxx" -#include "MEDCouplingFieldInt.hxx" +#include "MEDCouplingFieldInt32.hxx" +#include "MEDCouplingFieldInt64.hxx" #include "MEDCouplingFieldFloat.hxx" #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingFieldTemplate.hxx" @@ -127,7 +127,7 @@ namespace MEDCoupling * \sa getUndergroundDataArrayTemplate() */ template - typename Traits::ArrayType *MEDFileField1TSTemplateWithoutSDA::getUndergroundDataArrayTemplateExt(std::vector< std::pair,std::pair > >& entries) const + typename Traits::ArrayType *MEDFileField1TSTemplateWithoutSDA::getUndergroundDataArrayTemplateExt(std::vector< std::pair,std::pair > >& entries) const { if(this->_field_per_mesh.size()!=1) throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !"); @@ -151,7 +151,7 @@ namespace MEDCoupling } template - void MEDFileField1TSTemplateWithoutSDA::aggregate(const std::vector::F1TSWSDAType const *>& f1tss, const std::vector< std::vector< std::pair > >& dts) + 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 !"); @@ -174,15 +174,15 @@ namespace MEDCoupling setName(refPt->getName()); const DataArray *arr(refPt->getUndergroundDataArray()); - int nbCompo(arr->getNumberOfComponents()); + std::size_t 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); + std::vector > > extractInfo; + mcIdType start(0); MCAuto fpm(MEDFileFieldPerMesh::Aggregate(start,pms,dts,this,extractInfo)); _field_per_mesh.push_back(fpm); int iteration,order; @@ -191,12 +191,14 @@ namespace MEDCoupling _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++) + 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; } + // see definition of _nb_of_tuples_to_be_allocated. array is built from scratch and allocated. + _nb_of_tuples_to_be_allocated=-3; } template @@ -401,7 +403,7 @@ namespace MEDCoupling * \throw If no field values of the given \a type or given \a meshDimRelToMax are available. */ template - typename Traits::ArrayType *MEDFileTemplateField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const + typename Traits::ArrayType *MEDFileTemplateField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayIdType *&pfl) const { MCAuto arr(contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull())); return ReturnSafelyTypedDataArray(arr); @@ -420,7 +422,7 @@ namespace MEDCoupling } template - typename Traits::ArrayType *MEDFileTemplateField1TS::getUndergroundDataArrayExt(std::vector< std::pair,std::pair > >& entries) const + typename Traits::ArrayType *MEDFileTemplateField1TS::getUndergroundDataArrayExt(std::vector< std::pair,std::pair > >& entries) const { return contentNotNull()->getUndergroundDataArrayTemplateExt(entries); } @@ -611,7 +613,7 @@ namespace MEDCoupling * has not been constructed via file reading, an exception is thrown. * For more info, see \ref AdvMEDLoaderAPIFieldRW * \param [in] type - a spatial discretization of interest. - * \param [in] mName - a name of the supporting mesh. + * \param [in] mname - a name of the supporting mesh. * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities. * \param [in] renumPol - specifies how to permute values of the result field according to * the optional numbers of cells and nodes, if any. The valid values are @@ -682,16 +684,32 @@ namespace MEDCoupling * \throw If the data array of \a this is already allocated but has different number of * components than \a field. * \throw If elements in \a mesh are not in the order suitable for writing to the MED file. - * \sa setFieldNoProfileSBT() + * \sa setFieldNoProfileSBT, setFieldProfileFlatly */ template - void MEDFileTemplateField1TS::setFieldProfile(const typename Traits::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) + void MEDFileTemplateField1TS::setFieldProfile(const typename Traits::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile) + { + setFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,true); + } + + /*! + * Same as setFieldProfile except that here profile will be created unconditionally + * \sa setFieldProfile + */ + template + void MEDFileTemplateField1TS::setFieldProfileFlatly(const typename Traits::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile) + { + setFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,false); + } + + template + void MEDFileTemplateField1TS::setFieldProfileGeneral(const typename Traits::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile, bool smartPflKiller) { setFileName(""); MCAuto ft(MEDCouplingFieldTemplate::NewWithoutCheck(*field)); - contentNotNull()->setFieldProfile(field->timeDiscrSafe(),ft,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull()); + contentNotNull()->setFieldProfile(field->timeDiscrSafe(),ft,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull(),smartPflKiller); } - + /*! * Return an extraction of \a this using \a extractDef map to specify the extraction. * The keys of \a extractDef is level relative to max ext of \a mm mesh. @@ -700,7 +718,7 @@ namespace MEDCoupling * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart */ template - typename MLFieldTraits::F1TSType *MEDFileTemplateField1TS::extractPartImpl(const std::map >& extractDef, MEDFileMesh *mm) const + typename MLFieldTraits::F1TSType *MEDFileTemplateField1TS::extractPartImpl(const std::map >& extractDef, MEDFileMesh *mm) const { if(!mm) throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !"); @@ -714,10 +732,10 @@ namespace MEDCoupling getNonEmptyLevels(mm->getName(),levs); for(std::vector::const_iterator lev=levs.begin();lev!=levs.end();lev++) { - std::map >::const_iterator it2(extractDef.find(*lev)); + std::map >::const_iterator it2(extractDef.find(*lev)); if(it2!=extractDef.end()) { - MCAuto t((*it2).second); + MCAuto t((*it2).second); if(t.isNull()) throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !"); MCAuto::FieldType> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm)); @@ -728,10 +746,10 @@ namespace MEDCoupling } else { - std::map >::const_iterator it2(extractDef.find(1)); + std::map >::const_iterator it2(extractDef.find(1)); if(it2==extractDef.end()) throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !"); - MCAuto t((*it2).second); + MCAuto t((*it2).second); if(t.isNull()) throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !"); MCAuto::FieldType> f(getFieldOnMeshAtLevel(ON_NODES,0,mm)); @@ -872,7 +890,7 @@ namespace MEDCoupling * \return A new object that the caller is responsible to deallocate. */ template - typename MLFieldTraits::FMTSType *MEDFileTemplateFieldMultiTS::extractPartImpl(const std::map >& extractDef, MEDFileMesh *mm) const + typename MLFieldTraits::FMTSType *MEDFileTemplateFieldMultiTS::extractPartImpl(const std::map >& extractDef, MEDFileMesh *mm) const { if(!mm) throw INTERP_KERNEL::Exception("MEDFileTemplateFieldMultiTS::extractPart : mesh is null !"); @@ -1159,11 +1177,10 @@ namespace MEDCoupling * \param [in] order - the iteration order number of required time step. * \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities. * \param [in] mesh - the supporting mesh. - * \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the + * \param [out] pfl - a new instance of DataArrayIdType holding ids of mesh entities the * field of interest lies on. If the field lies on all entities of the given * dimension, all ids in \a pfl are zero. The caller is to delete this array * using decrRef() as it is no more needed. - * \param [in] glob - the global data storing profiles and localization. * \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the * field. The caller is to delete this array using decrRef() as it is no more needed. * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh. @@ -1171,7 +1188,7 @@ namespace MEDCoupling * \throw If no field values of the required parameters are available. */ template - typename Traits::ArrayType *MEDFileTemplateFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const + typename Traits::ArrayType *MEDFileTemplateFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayIdType *&pfl) const { const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order)); const typename MLFieldTraits::F1TSWSDAType *myF1TSC(dynamic_cast::F1TSWSDAType *>(&myF1TS)); @@ -1222,18 +1239,33 @@ namespace MEDCoupling * \throw If the data array of \a this is already allocated but has different number of * components than \a field. * \throw If elements in \a mesh are not in the order suitable for writing to the MED file. - * \sa setFieldNoProfileSBT() + * \sa setFieldNoProfileSBT, appendFieldProfileFlatly */ template - void MEDFileTemplateFieldMultiTS::appendFieldProfile(const typename Traits::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) + void MEDFileTemplateFieldMultiTS::appendFieldProfile(const typename Traits::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile) + { + appendFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,true); + } + + /*! + * same as appendFieldProfile except that here profile is created unconditionaly + */ + template + void MEDFileTemplateFieldMultiTS::appendFieldProfileFlatly(const typename Traits::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile) + { + appendFieldProfileGeneral(field,mesh,meshDimRelToMax,profile,false); + } + + template + void MEDFileTemplateFieldMultiTS::appendFieldProfileGeneral(const typename Traits::FieldType *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayIdType *profile, bool smartPflKiller) { const typename Traits::ArrayType *arr(NULL); if(field) arr=field->getArray(); MCAuto field2(MEDFileTemplateField1TS::ToFieldTemplateWithTime(field)); - contentNotNull()->appendFieldProfile(field2,arr,mesh,meshDimRelToMax,profile,*this); + contentNotNull()->appendFieldProfile(field2,arr,mesh,meshDimRelToMax,profile,*this,smartPflKiller); } - + template const typename MLFieldTraits::FMTSWSDAType *MEDFileTemplateFieldMultiTS::contentNotNull() const { @@ -1301,7 +1333,7 @@ namespace MEDCoupling } template - typename Traits::ArrayType *MEDFileTemplateFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair,std::pair > >& entries) const + typename Traits::ArrayType *MEDFileTemplateFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair,std::pair > >& entries) const { DataArray *ret(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries)); if(!ret) @@ -1366,5 +1398,3 @@ namespace MEDCoupling return ret.retn(); } } - -#endif