X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FMEDLoader.cxx;h=8b1ffc7c63e135d9d86c4c8430190cd36070d1ce;hb=8d65b3fe9fcfb3f41dadfe696f3853bfcc2d1cdf;hp=e9069171676bd8e1ab0d33de49ac02280e82f76b;hpb=eb62814b5284621fc35a2684885a8c5e2c2a3f67;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index e90691716..8b1ffc7c6 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D +// Copyright (C) 2007-2019 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 @@ -29,7 +29,10 @@ #include "MEDCouplingUMesh.hxx" #include "MEDCouplingMemArray.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingFieldFloat.hxx" +#include "MEDCouplingFieldInt.hxx" #include "MEDCouplingGaussLocalization.hxx" +#include "MEDCouplingTraits.hxx" #include "MCAuto.hxx" #include "InterpKernelAutoPtr.hxx" @@ -64,6 +67,7 @@ med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1, MED_TETRA10, MED_PYRA13, MED_PENTA15, + MED_PENTA18, MED_HEXA20, MED_HEXA27, MED_POLYGON, @@ -90,6 +94,7 @@ INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNE INTERP_KERNEL::NORM_TETRA10, INTERP_KERNEL::NORM_PYRA13, INTERP_KERNEL::NORM_PENTA15, + INTERP_KERNEL::NORM_PENTA18, INTERP_KERNEL::NORM_HEXA20, INTERP_KERNEL::NORM_HEXA27, INTERP_KERNEL::NORM_POLYGON, @@ -124,7 +129,7 @@ med_geometry_type typmai3[34] = { MED_POINT1,//0 MED_PENTA15,//25 MED_NONE,//26 MED_HEXA27,//27 - MED_NONE,//28 + MED_PENTA18,//28 MED_NONE,//29 MED_HEXA20,//30 MED_POLYHEDRON,//31 @@ -308,7 +313,7 @@ std::string MEDCoupling::MEDFileVersionStr() std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName) { -#if MED_NUM_MAJEUR>=3 && MED_NUM_MINEUR>=2 && MED_NUM_RELEASE>=1 +#if MED_NUM_MAJEUR>3 || ( MED_NUM_MAJEUR==3 && ( (MED_NUM_MINEUR==2 && MED_NUM_RELEASE>=1) || MED_NUM_MINEUR>=3) ) MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName)); const int SZ=20; const char START_EXPECTED[]="MED-"; @@ -341,7 +346,7 @@ void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release) } /*! - * This method sets the epsilon value used for node comparison when trying to buid a profile for a field on node/cell on an already written mesh. + * This method sets the epsilon value used for node comparison when trying to build a profile for a field on node/cell on an already written mesh. */ void MEDCoupling::SetEpsilonForNodeComp(double val) { @@ -1153,7 +1158,7 @@ MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromGroups(const std::strin return mmuPtr->getGroups(meshDimRelToMax,grps,true); } -MCAuto MEDCoupling::ReadField(const std::string& fileName) +MCAuto MEDCoupling::ReadField(const std::string& fileName) { std::vector fieldNames(GetAllFieldNames(fileName)); std::size_t sz(fieldNames.size()); @@ -1176,7 +1181,7 @@ MCAuto MEDCoupling::ReadField(const std::st return ReadField(fileName,fieldNames[0]); } -MCAuto MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName) +MCAuto MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName) { std::vector< std::pair< std::pair, double> > iterations(GetAllFieldIterations(fileName,fieldName)); std::size_t sz(iterations.size()); @@ -1199,27 +1204,50 @@ MCAuto MEDCoupling::ReadField(const std::st return ReadField(fileName,fieldName,iterations[0].first.first,iterations[0].first.second); } -MCAuto MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName, int iteration, int order) +MCAuto MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName, int iteration, int order) { - MCAuto f(MEDFileField1TS::New(fileName,fieldName,iteration,order)); + MCAuto f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order)); MCAuto mesh(MEDFileMesh::New(fileName,f->getMeshName())); - MCAuto ret(f->field(mesh)); - return 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()) + { + MCAuto ret(f1->field(mesh)); + return MEDCoupling::DynamicCast(ret); + } + } + { + MCAuto f1(MEDCoupling::DynamicCast(f)); + if(f1.isNotNull()) + { + MCAuto ret(f1->field(mesh)); + return MEDCoupling::DynamicCast(ret); + } + } + throw INTERP_KERNEL::Exception("MEDCoupling::ReadField : only FLOAT32, FLOAT64 and INT32 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) +MCAuto MEDCoupling::ReadField(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) { MEDCoupling::CheckFileForRead(fileName); switch(type) { case ON_CELLS: - return MCAuto(ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order)); + return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order); case ON_NODES: - return MCAuto(ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order)); + return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order); case ON_GAUSS_PT: - return MCAuto(ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order)); + return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order); case ON_GAUSS_NE: - return MCAuto(ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order)); + return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order); default: throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !"); } @@ -1286,97 +1314,139 @@ std::vector MEDCoupling::ReadFieldsGaussN return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its); } -MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) +namespace MEDCoupling { - MCAuto ff(MEDFileField1TS::New(fileName,fieldName,iteration,order)); - MCAuto mm(MEDFileMesh::New(fileName,meshName)); - MCAuto m(mm->getMeshAtLevel(meshDimRelToMax,false)); - MEDFileMesh *mPtr(mm); - MEDFileUMesh *muPtr=dynamic_cast(mPtr); - MCAuto ret(ff->getFieldOnMeshAtLevel(ON_CELLS,m)); - if(muPtr) - { - const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax)); - if(num) - ret->renumberCells(num->begin()); - } - return ret.retn(); -} + template + MCAuto::FieldType> ReadFieldCellLikeT(typename MLFieldTraits::F1TSType *ff, MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) + { + MCAuto mm(MEDFileMesh::New(fileName,meshName)); + MCAuto muPtr(MEDCoupling::DynamicCast(mm)); + MCAuto m(mm->getMeshAtLevel(meshDimRelToMax,false)); + MCAuto::FieldType> ret(ff->getFieldOnMeshAtLevel(type,m)); + if(muPtr.isNotNull()) + { + const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax)); + if(num) + ret->renumberCells(num->begin()); + } + return ret; + } -MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) -{ - MCAuto ff(MEDFileField1TS::New(fileName,fieldName,iteration,order)); - MCAuto mm(MEDFileMesh::New(fileName,meshName)); - MCAuto m(mm->getMeshAtLevel(meshDimRelToMax,false)); - MEDFileMesh *mPtr(mm); - MCAuto ret(ff->getFieldOnMeshAtLevel(ON_NODES,m)); - MEDFileUMesh *muPtr=dynamic_cast(mPtr); - if(ff->getPflsReallyUsed().empty()) + MEDCoupling::MEDCouplingField *ReadFieldCellLike(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) + { + MCAuto f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order)); { - if(muPtr) + MCAuto f1(MEDCoupling::DynamicCast(f)); + if(f1.isNotNull()) { - const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax)); - if(num) - ret->renumberCells(num->begin()); + MCAuto ret(ReadFieldCellLikeT(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order)); + return ret.retn(); } } - else { - DataArrayInt *pfl=0,*arr2=0; - MCAuto arr(ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl)); - MCAuto pflSafe(pfl); - MCAuto mp(m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end())); - MCAuto mzip(static_cast(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2))); - MCAuto arr2Safe(arr2); - MCAuto arr3(arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes())); - MCAuto pflSorted(pflSafe->deepCopy()); pflSorted->sort(true); - if(!arr3->isEqualWithoutConsideringStr(*pflSorted)) - throw INTERP_KERNEL::Exception("ReadFieldNode : not implemented yet !"); - if(!arr3->isEqualWithoutConsideringStr(*pflSafe)) + MCAuto f1(MEDCoupling::DynamicCast(f)); + if(f1.isNotNull()) { - MCAuto o2n2(pflSafe->checkAndPreparePermutation()); - MCAuto n2o2(o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples())); - mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples()); - arr->setName(""); - ret->setArray(arr); + MCAuto ret(ReadFieldCellLikeT(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order)); + return ret.retn(); } - ret->setMesh(mzip); } - 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(); + } + } + throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldCell : only FLOAT32, FLOAT64 and INT32 supported for the moment !"); + } + + template + MCAuto::FieldType> ReadFieldNodeT(typename MLFieldTraits::F1TSType *ff, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) + { + MCAuto mm(MEDFileMesh::New(fileName,meshName)); + MCAuto m(mm->getMeshAtLevel(meshDimRelToMax,false)); + MCAuto::FieldType> ret(ff->getFieldOnMeshAtLevel(ON_NODES,m)); + MCAuto muPtr(MEDCoupling::DynamicCast(mm)); + if(ff->getPflsReallyUsed().empty()) + { + if(muPtr.isNotNull()) + { + const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax)); + if(num) + ret->renumberCells(num->begin()); + } + } + else + { + DataArrayInt *pfl(nullptr),*arr2(nullptr); + MCAuto::ArrayType> arr(ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl)); + MCAuto pflSafe(pfl); + MCAuto mp(m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end())); + MCAuto mzip(static_cast(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2))); + MCAuto arr2Safe(arr2); + MCAuto arr3(arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes())); + MCAuto pflSorted(pflSafe->deepCopy()); pflSorted->sort(true); + if(!arr3->isEqualWithoutConsideringStr(*pflSorted)) + throw INTERP_KERNEL::Exception("ReadFieldNode : not implemented yet !"); + if(!arr3->isEqualWithoutConsideringStr(*pflSafe)) + { + MCAuto o2n2(pflSafe->checkAndPreparePermutation()); + MCAuto n2o2(o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples())); + mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples()); + arr->setName(""); + ret->setArray(arr); + } + ret->setMesh(mzip); + } + return ret; + } } -MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) +MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) { - MCAuto ff(MEDFileField1TS::New(fileName,fieldName,iteration,order)); - MCAuto mm(MEDFileMesh::New(fileName,meshName)); - MCAuto m(mm->getMeshAtLevel(meshDimRelToMax,false)); - MEDFileMesh *mPtr(mm); - MEDFileUMesh *muPtr=dynamic_cast(mPtr); - MCAuto ret(ff->getFieldOnMeshAtLevel(ON_GAUSS_PT,m)); - if(muPtr) - { - const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax)); - if(num) - ret->renumberCells(num->begin()); - } - return ret.retn(); + return ReadFieldCellLike(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,iteration,order); } -MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) +MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) { - MCAuto ff(MEDFileField1TS::New(fileName,fieldName,iteration,order)); - MCAuto mm(MEDFileMesh::New(fileName,meshName)); - MCAuto m(mm->getMeshAtLevel(meshDimRelToMax,false)); - MEDFileMesh *mPtr(mm); - MEDFileUMesh *muPtr=dynamic_cast(mPtr); - MCAuto ret(ff->getFieldOnMeshAtLevel(ON_GAUSS_NE,m)); - if(muPtr) - { - const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax)); - if(num) - ret->renumberCells(num->begin()); - } - return ret.retn(); + MCAuto f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order)); + { + 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()) + { + MCAuto ret(ReadFieldNodeT(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order)); + return ret.retn(); + } + } + { + MCAuto f1(MEDCoupling::DynamicCast(f)); + if(f1.isNotNull()) + { + MCAuto ret(ReadFieldNodeT(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order)); + return ret.retn(); + } + } + throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldNode : only FLOAT32, FLOAT64 and INT32 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) +{ + return ReadFieldCellLike(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,iteration,order); +} + +MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order) +{ + return ReadFieldCellLike(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,iteration,order); } void MEDCoupling::WriteMesh(const std::string& fileName, const MEDCoupling::MEDCouplingMesh *mesh, bool writeFromScratch) @@ -1463,25 +1533,26 @@ void MEDCoupling::WriteUMeshesPartitionDep(const std::string& fileName, const st void MEDCoupling::WriteUMeshes(const std::string& fileName, const std::vector& meshes, bool writeFromScratch) { - int mod=writeFromScratch?2:0; + int mod(writeFromScratch?2:0); MCAuto m(MEDFileUMesh::New()); AssignStaticWritePropertiesTo(*m); m->setMeshes(meshes,true); m->write(fileName,mod); } -void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch) +template +void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const typename MEDCoupling::Traits::FieldType *f, bool writeFromScratch) { - MCAuto ff(MEDFileField1TS::New()); + MCAuto< typename MLFieldTraits::F1TSType > ff(MLFieldTraits::F1TSType::New()); AssignStaticWritePropertiesTo(*ff); - MCAuto f2(f->deepCopy()); + MCAuto::FieldType> f2(f->deepCopy()); const MEDCouplingMesh *m(f2->getMesh()); const MEDCouplingUMesh *um(dynamic_cast(m)); const MEDCoupling1GTUMesh *um2(dynamic_cast(m)); const MEDCouplingCMesh *um3(dynamic_cast(m)); const MEDCouplingCurveLinearMesh *um4(dynamic_cast(m)); MCAuto mm; - int mod=writeFromScratch?2:0; + int mod(writeFromScratch?2:0); if(um) { MCAuto mmu(MEDFileUMesh::New()); @@ -1523,12 +1594,13 @@ void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::stri ff->write(fileName,0); } -void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch) +template +void WriteFieldT(const std::string& fileName, const typename MEDCoupling::Traits::FieldType *f, bool writeFromScratch) { if(!f) throw INTERP_KERNEL::Exception("WriteField : input field is NULL !"); f->checkConsistencyLight(); - int status=MEDLoaderBase::getStatusOfFile(fileName); + int status(MEDLoaderBase::getStatusOfFile(fileName)); if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST) { std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !"; @@ -1536,44 +1608,47 @@ void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MED } if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST)) { - MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,true); + MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,true); } else { - std::vector meshNames=GetMeshNames(fileName); + std::vector meshNames(GetMeshNames(fileName)); if(!f->getMesh()) throw INTERP_KERNEL::Exception("WriteField : trying to write a field with no mesh !"); std::string fileNameCpp(f->getMesh()->getName()); if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end()) - MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false); + MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false); else { MCAuto mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str())); AssignStaticWritePropertiesTo(*mm); const MEDFileMesh *mmPtr(mm); - const MEDFileUMesh *mmuPtr=dynamic_cast(mmPtr); + const MEDFileUMesh *mmuPtr(dynamic_cast(mmPtr)); if(!mmuPtr) throw INTERP_KERNEL::Exception("WriteField : only umeshes are supported now !"); - MCAuto f2(f->deepCopy()); - MEDCouplingUMesh *m=dynamic_cast(const_cast(f2->getMesh())); + MCAuto< typename MEDCoupling::Traits::FieldType > f2(f->deepCopy()); + MEDCouplingUMesh *m(dynamic_cast(const_cast(f2->getMesh()))); if(!m) throw INTERP_KERNEL::Exception("WriteField : only umesh in input field supported !"); - MCAuto o2n=m->getRenumArrForMEDFileFrmt(); + MCAuto o2n(m->getRenumArrForMEDFileFrmt()); f2->renumberCells(o2n->begin(),false); m=static_cast(const_cast(f2->getMesh())); - MCAuto mread=mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension()); + MCAuto mread(mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension())); if(f2->getTypeOfField()!=ON_NODES) { - m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP); - DataArrayInt *part=0; - bool b=mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part); + if(!m->getCoords()->isEqualWithoutConsideringStr(*mread->getCoords(),_EPS_FOR_NODE_COMP)) + m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP); + else + mread->setCoords(m->getCoords()); + DataArrayInt *part(NULL); + bool b(mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part)); MCAuto partSafe(part); if(!b) { std::ostringstream oss; oss << "WriteField : The file \""<< fileName << "\" already contains a mesh named \""<< f->getMesh()->getName() << "\" and this mesh in the file is not compatible (a subpart) with the mesh you intend to write ! This is maybe due to a too strict policy ! Try with to lease it by calling SetCompPolicyForCell !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - MCAuto f1ts(MEDFileField1TS::New()); + MCAuto< typename MLFieldTraits::F1TSType > f1ts(MLFieldTraits::F1TSType::New()); AssignStaticWritePropertiesTo(*f1ts); if(part->isIota(mread->getNumberOfCells())) f1ts->setFieldNoProfileSBT(f2); @@ -1587,15 +1662,15 @@ void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MED } else { - DataArrayInt *part=0; - bool b=mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part); + DataArrayInt *part(NULL); + bool b(mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part)); MCAuto partSafe(part); if(!b) { std::ostringstream oss; oss << "WriteField : The file \""<< fileName << "\" already contains a mesh named \""<< f->getMesh()->getName() << "\" and this mesh in the file is not compatible (a subpart regarding nodes) with the mesh you intend to write ! This is maybe due to a too strict epsilon ! Try with to lease it by calling SetEpsilonForNodeComp !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - MCAuto f1ts(MEDFileField1TS::New()); + MCAuto< typename MLFieldTraits::F1TSType > f1ts(MLFieldTraits::F1TSType::New()); AssignStaticWritePropertiesTo(*f1ts); if(part->isIota(mread->getNumberOfNodes())) f1ts->setFieldNoProfileSBT(f2); @@ -1610,29 +1685,61 @@ void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MED } } -void MEDCoupling::WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch) +void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingField *f, bool writeFromScratch) +{ + if(!f) + throw INTERP_KERNEL::Exception("WriteField : input field is null !"); + { + const MEDCoupling::MEDCouplingFieldDouble *f1(dynamic_cast(f)); + if(f1) + { + WriteFieldT(fileName,f1,writeFromScratch); + return ; + } + } + { + const MEDCoupling::MEDCouplingFieldInt *f1(dynamic_cast(f)); + if(f1) + { + WriteFieldT(fileName,f1,writeFromScratch); + return ; + } + } + { + const MEDCoupling::MEDCouplingFieldFloat *f1(dynamic_cast(f)); + if(f1) + { + WriteFieldT(fileName,f1,writeFromScratch); + return ; + } + } + throw INTERP_KERNEL::Exception("WriteField : input field is not in FLOAT32, FLOAT64, INT32 !"); +} + +void MEDCoupling::WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingField *f, bool writeFromScratch) { WriteField(fileName,f,writeFromScratch); } -void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f) +template +void WriteFieldUsingAlreadyWrittenMeshT(const std::string& fileName, const typename MEDCoupling::Traits::FieldType *f) { if(!f) - throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is null !"); + throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMeshT : input field is null !"); f->checkConsistencyLight(); - int status=MEDLoaderBase::getStatusOfFile(fileName); + int status(MEDLoaderBase::getStatusOfFile(fileName)); if(status!=MEDLoaderBase::EXIST_RW) { std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - MCAuto f1ts(MEDFileField1TS::New()); + MCAuto< typename MLFieldTraits::F1TSType > f1ts(MLFieldTraits::F1TSType::New()); AssignStaticWritePropertiesTo(*f1ts); MEDCouplingUMesh *m(dynamic_cast(const_cast(f->getMesh()))); if(m) { MCAuto o2n(m->getRenumArrForMEDFileFrmt()); - MCAuto f2(f->deepCopy()); + MCAuto< typename MEDCoupling::Traits::FieldType > f2(f->deepCopy()); f2->renumberCells(o2n->begin(),false); f1ts->setFieldNoProfileSBT(f2); } @@ -1640,3 +1747,28 @@ void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, f1ts->setFieldNoProfileSBT(f); f1ts->write(fileName,0); } + +void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingField *f) +{ + if(!f) + throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is null !"); + { + const MEDCoupling::MEDCouplingFieldDouble *f1(dynamic_cast(f)); + if(f1) + WriteFieldUsingAlreadyWrittenMeshT(fileName,f1); + return ; + } + { + const MEDCoupling::MEDCouplingFieldInt *f1(dynamic_cast(f)); + if(f1) + WriteFieldUsingAlreadyWrittenMeshT(fileName,f1); + return ; + } + { + const MEDCoupling::MEDCouplingFieldFloat *f1(dynamic_cast(f)); + if(f1) + WriteFieldUsingAlreadyWrittenMeshT(fileName,f1); + return ; + } + throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is not in FLOAT32, FLOAT64, INT32 !"); +}