From 19a65812ae7b522811413fff6e642d1273b13d48 Mon Sep 17 00:00:00 2001 From: Yoann Audouin Date: Thu, 26 Aug 2021 16:48:22 +0200 Subject: [PATCH] Adding support for int64 field in basic api --- src/MEDLoader/MEDFileFieldInternal.cxx | 2 +- src/MEDLoader/MEDFileFieldMultiTS.cxx | 26 ++++++------ src/MEDLoader/MEDLoader.cxx | 55 +++++++++++++++++++++++--- src/MEDLoader/Test/MEDLoaderTest.cxx | 31 +++++++++++++++ src/MEDLoader/Test/MEDLoaderTest.hxx | 1 + 5 files changed, 95 insertions(+), 20 deletions(-) diff --git a/src/MEDLoader/MEDFileFieldInternal.cxx b/src/MEDLoader/MEDFileFieldInternal.cxx index fffb38ef8..4bcd2a1ca 100644 --- a/src/MEDLoader/MEDFileFieldInternal.cxx +++ b/src/MEDLoader/MEDFileFieldInternal.cxx @@ -745,7 +745,7 @@ void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileF goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast(startFeeding)); return ; } - throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 FLOAT32 or INT32 !"); + throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 FLOAT32 INT32 or INT64 !"); } /*! diff --git a/src/MEDLoader/MEDFileFieldMultiTS.cxx b/src/MEDLoader/MEDFileFieldMultiTS.cxx index 74bc171d6..b8f0e9f7f 100644 --- a/src/MEDLoader/MEDFileFieldMultiTS.cxx +++ b/src/MEDLoader/MEDFileFieldMultiTS.cxx @@ -47,7 +47,7 @@ template class MEDCoupling::MEDFileNDTemplateFieldMultiTS; template class MEDCoupling::MEDFileNDTemplateFieldMultiTS; extern INTERP_KERNEL::NormalizedCellType ConvertGeometryType(med_geometry_type geotype); - + //= MEDFileAnyTypeFieldMultiTSWithoutSDA MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA() @@ -680,7 +680,7 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, in int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const { int ret=0; - std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; + std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; for(std::vector< MCAuto >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++) { const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it); @@ -730,7 +730,7 @@ std::vector< std::pair > MEDFileAnyTypeFieldMultiTSWithoutSDA::getItera /*! * This method has 3 inputs 'iteration' 'order' 'mname'. 'mname' can be null if the user is the general case where there is only one meshName lying on 'this' * This method returns two things. - * - The absolute dimension of 'this' in first parameter. + * - The absolute dimension of 'this' in first parameter. * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative * to the first output parameter. The values in 'levs' will be returned in decreasing order. * @@ -743,7 +743,7 @@ std::vector< std::pair > MEDFileAnyTypeFieldMultiTSWithoutSDA::getItera * * This method is useful to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'. * It is possible (even if it is not common) that the highest level in 'this' were not equal to the meshDimension of the underlying mesh in 'this'. - * + * * Let's consider the typical following case : * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2 @@ -752,7 +752,7 @@ std::vector< std::pair > MEDFileAnyTypeFieldMultiTSWithoutSDA::getItera * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2 * * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1]) - * + * * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev @@ -933,10 +933,10 @@ std::vector< MCAuto > MEDFileAnyTypeFieldM const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]); if(!timeStep) { - std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; + std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; throw INTERP_KERNEL::Exception(oss.str()); } - items[i]=timeStep->splitDiscretizations(); + items[i]=timeStep->splitDiscretizations(); } // std::vector< MCAuto > ret; @@ -1331,7 +1331,7 @@ MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromCont ret->_content=c; c->incrRef(); return ret.retn(); } - throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 FLOAT32 and INT32 has been built but not intercepted !"); + throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 FLOAT32 INT32 and INT64 has been built but not intercepted !"); } MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid) @@ -1648,7 +1648,7 @@ void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const * This method alloc the arrays and load potentially huge arrays contained in this field. * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter. * This method can be also called to refresh or reinit values from a file. - * + * * \throw If the fileName is not set or points to a non readable MED file. */ void MEDFileAnyTypeFieldMultiTS::loadArrays() @@ -1662,7 +1662,7 @@ void MEDFileAnyTypeFieldMultiTS::loadArrays() /*! * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays. * But once data loaded once, this method does nothing. - * + * * \throw If the fileName is not set or points to a non readable MED file. * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays */ @@ -1679,7 +1679,7 @@ void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary() * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false. * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file. * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead. - * + * * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss */ void MEDFileAnyTypeFieldMultiTS::unloadArrays() @@ -1691,7 +1691,7 @@ void MEDFileAnyTypeFieldMultiTS::unloadArrays() * This method potentially releases big data arrays if \a this is coming from a file. If \a this has been built from scratch this method will have no effect. * This method is the symmetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary. * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database. - * + * * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary */ void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss() @@ -2209,7 +2209,7 @@ MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAn } } -MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() +MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() { } diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index 6720c9503..b697525e6 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -31,6 +31,7 @@ #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingFieldFloat.hxx" #include "MEDCouplingFieldInt32.hxx" +#include "MEDCouplingFieldInt64.hxx" #include "MEDCouplingGaussLocalization.hxx" #include "MEDCouplingTraits.hxx" #include "MCAuto.hxx" @@ -195,7 +196,7 @@ int MEDLoaderNS::readUMeshDimFromFile(const std::string& fileName, const std::st if(nstep!=1) { throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !"); - } + } med_int numdt,numit; med_float dt; MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt)); @@ -1276,6 +1277,14 @@ MCAuto MEDCoupling::ReadField(const std::string& return MEDCoupling::DynamicCast(ret); } } + { + MCAuto f1(MEDCoupling::DynamicCast(f)); + if(f1.isNotNull()) + { + MCAuto ret(f1->field(mesh)); + return MEDCoupling::DynamicCast(ret); + } + } { MCAuto f1(MEDCoupling::DynamicCast(f)); if(f1.isNotNull()) @@ -1284,7 +1293,8 @@ MCAuto MEDCoupling::ReadField(const std::string& return MEDCoupling::DynamicCast(ret); } } - throw INTERP_KERNEL::Exception("MEDCoupling::ReadField : only FLOAT32, FLOAT64 and INT32 supported for the moment !"); + + throw INTERP_KERNEL::Exception("MEDCoupling::ReadField : only FLOAT32, FLOAT64, INT32 and INT64 supported for the moment !"); } MCAuto MEDCoupling::ReadField(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) @@ -1403,6 +1413,14 @@ namespace MEDCoupling return ret.retn(); } } + { + MCAuto f1(MEDCoupling::DynamicCast(f)); + if(f1.isNotNull()) + { + MCAuto ret(ReadFieldCellLikeT(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order)); + return ret.retn(); + } + } { MCAuto f1(MEDCoupling::DynamicCast(f)); if(f1.isNotNull()) @@ -1411,7 +1429,7 @@ namespace MEDCoupling return ret.retn(); } } - throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldCell : only FLOAT32, FLOAT64 and INT32 supported for the moment !"); + throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldCell : only FLOAT32, FLOAT64, INT32 and INT64 supported for the moment !"); } template @@ -1480,6 +1498,14 @@ MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldNode(const std::string& fil return ret.retn(); } } + { + MCAuto f1(MEDCoupling::DynamicCast(f)); + if(f1.isNotNull()) + { + MCAuto ret(ReadFieldNodeT(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order)); + return ret.retn(); + } + } { MCAuto f1(MEDCoupling::DynamicCast(f)); if(f1.isNotNull()) @@ -1488,7 +1514,7 @@ MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldNode(const std::string& fil return ret.retn(); } } - throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldNode : only FLOAT32, FLOAT64 and INT32 supported for the moment !"); + throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldNode : only FLOAT32, FLOAT64, INT32 and INT64 supported for the moment !"); } MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) @@ -1757,6 +1783,15 @@ void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MED return ; } } + { + const MEDCoupling::MEDCouplingFieldInt64 *f1(dynamic_cast(f)); + if(f1) + { + WriteFieldT(fileName,f1,writeFromScratch); + return ; + } + } + { const MEDCoupling::MEDCouplingFieldFloat *f1(dynamic_cast(f)); if(f1) @@ -1765,7 +1800,7 @@ void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MED return ; } } - throw INTERP_KERNEL::Exception("WriteField : input field is not in FLOAT32, FLOAT64, INT32 !"); + throw INTERP_KERNEL::Exception("WriteField : input field is not in FLOAT32, FLOAT64, INT32 and INT64!"); } void MEDCoupling::WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingField *f, bool writeFromScratch) @@ -1820,6 +1855,14 @@ void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, return ; } } + { + const MEDCoupling::MEDCouplingFieldInt64 *f1(dynamic_cast(f)); + if(f1) + { + WriteFieldUsingAlreadyWrittenMeshT(fileName,f1); + return ; + } + } { const MEDCoupling::MEDCouplingFieldFloat *f1(dynamic_cast(f)); if(f1) @@ -1828,5 +1871,5 @@ void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, return ; } } - throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is not in FLOAT32, FLOAT64, INT32 !"); + throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is not in FLOAT32, FLOAT64, INT32 and INT64 !"); } diff --git a/src/MEDLoader/Test/MEDLoaderTest.cxx b/src/MEDLoader/Test/MEDLoaderTest.cxx index 2d56bfecc..9d3ce167e 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.cxx +++ b/src/MEDLoader/Test/MEDLoaderTest.cxx @@ -24,6 +24,7 @@ #include "MEDCouplingUMesh.hxx" #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingFieldFloat.hxx" +#include "MEDCouplingFieldInt64.hxx" #include "MEDCouplingMemArray.hxx" #include "TestInterpKernelUtils.hxx" // getResourceFile() @@ -121,10 +122,12 @@ void MEDLoaderTest::testFieldRW2() MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1(); MEDCouplingFieldInt *f1_int=buildIntVecFieldOnCells_1(); MEDCouplingFieldFloat *f1_fl=buildFloatVecFieldOnCells_1(); + MEDCouplingFieldInt64 *f1_int64=buildInt64VecFieldOnCells_1(); WriteField(fileName,f1,true); f1->setTime(10.,8,9); f1_int->setTime(10.,8,9); f1_fl->setTime(10.,8,9); + f1_int64->setTime(10.,8,9); double *tmp=f1->getArray()->getPointer(); tmp[0]=VAL1; WriteFieldUsingAlreadyWrittenMesh(fileName,f1); @@ -133,6 +136,7 @@ void MEDLoaderTest::testFieldRW2() WriteFieldUsingAlreadyWrittenMesh(fileName,f1); // Write int and float fields: WriteFieldUsingAlreadyWrittenMesh(fileName,f1_int); + WriteFieldUsingAlreadyWrittenMesh(fileName,f1_int64); WriteFieldUsingAlreadyWrittenMesh(fileName,f1_fl); //retrieving time steps... MEDCouplingFieldDouble *f2=dynamic_cast(ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),8,9)); @@ -158,6 +162,10 @@ void MEDLoaderTest::testFieldRW2() CPPUNIT_ASSERT(f1_int->isEqual(f2_int,1e-12,0)); // exact equality for int values f2_int->decrRef(); f1_int->decrRef(); + MEDCouplingFieldInt64 *f2_int64=dynamic_cast(ReadFieldCell(fileName,f1_int64->getMesh()->getName().c_str(),0,f1_int64->getName().c_str(),8,9)); + CPPUNIT_ASSERT(f1_int64->isEqual(f2_int64,1e-12,0)); // exact equality for int values + f2_int64->decrRef(); + f1_int64->decrRef(); MEDCouplingFieldFloat *f2_fl=dynamic_cast(ReadFieldCell(fileName,f1_fl->getMesh()->getName().c_str(),0,f1_fl->getName().c_str(),8,9)); CPPUNIT_ASSERT(f1_fl->isEqual(f2_fl,1e-12,1e-07f)); // float comparison f2_fl->decrRef(); @@ -1425,6 +1433,29 @@ MEDCouplingFieldInt *MEDLoaderTest::buildIntVecFieldOnCells_1() return f1; } +MEDCouplingFieldInt64 *MEDLoaderTest::buildInt64VecFieldOnCells_1() +{ + MEDCouplingUMesh *mesh=build3DSurfMesh_1(); + mcIdType nbOfCells=mesh->getNumberOfCells(); + MEDCouplingFieldInt64 *f1=MEDCouplingFieldInt64::New(ON_CELLS,ONE_TIME); + f1->setName("Int64VectorFieldOnCells"); + f1->setMesh(mesh); + DataArrayInt64 *array=DataArrayInt64::New(); + array->alloc(nbOfCells,3); + array->setInfoOnComponent(0,"val1 [MW/m^3]"); + array->setInfoOnComponent(1,"va2 [g/cm^3]"); + array->setInfoOnComponent(2,"val3 [K]"); + f1->setArray(array); + array->decrRef(); + int64_t *tmp=array->getPointer(); + const int64_t arr1[18]={0,10,20,1,11,21,2,12,22,3,13,23,4,14,24,5,15,25}; + std::copy(arr1,arr1+18,tmp); + f1->setTime(2.,0,1); + f1->checkConsistencyLight(); + mesh->decrRef(); + return f1; +} + MEDCouplingFieldFloat *MEDLoaderTest::buildFloatVecFieldOnCells_1() { MEDCouplingUMesh *mesh=build3DSurfMesh_1(); diff --git a/src/MEDLoader/Test/MEDLoaderTest.hxx b/src/MEDLoader/Test/MEDLoaderTest.hxx index 5b1c038d5..baee488d5 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.hxx +++ b/src/MEDLoader/Test/MEDLoaderTest.hxx @@ -99,6 +99,7 @@ namespace MEDCoupling MEDCouplingUMesh *build3DMesh_2(); MEDCouplingFieldDouble *buildVecFieldOnCells_1(); MEDCouplingFieldInt *buildIntVecFieldOnCells_1(); + MEDCouplingFieldInt64 *buildInt64VecFieldOnCells_1(); MEDCouplingFieldFloat *buildFloatVecFieldOnCells_1(); MEDCouplingFieldDouble *buildVecFieldOnNodes_1(); MEDCouplingFieldDouble *buildVecFieldOnGauss_1(); -- 2.39.2