X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FMEDLoader.cxx;h=8b1ffc7c63e135d9d86c4c8430190cd36070d1ce;hb=844b1a4785909ad42206965838a6d0f826dfb5c1;hp=3ff93db3788140f1820fac339a376d7d72ad3b44;hpb=22a4bd76f2e2c06917d391a07efa1aa293b35177;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index 3ff93db37..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 @@ -1233,24 +1233,21 @@ MCAuto MEDCoupling::ReadField(const std::string& } } throw INTERP_KERNEL::Exception("MEDCoupling::ReadField : only FLOAT32, FLOAT64 and INT32 supported for the moment !"); - //MCAuto mesh(MEDFileMesh::New(fileName,f->getMeshName())); - //MCAuto ret(f->field(mesh)); - //return ret; } -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 !"); } @@ -1317,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(); + } + } + { + MCAuto f1(MEDCoupling::DynamicCast(f)); + if(f1.isNotNull()) + { + 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(); + 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) @@ -1597,7 +1636,10 @@ void WriteFieldT(const std::string& fileName, const typename MEDCoupling::Traits MCAuto mread(mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension())); if(f2->getTypeOfField()!=ON_NODES) { - m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP); + 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); @@ -1650,20 +1692,26 @@ void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MED { const MEDCoupling::MEDCouplingFieldDouble *f1(dynamic_cast(f)); if(f1) - WriteFieldT(fileName,f1,writeFromScratch); - return ; + { + WriteFieldT(fileName,f1,writeFromScratch); + return ; + } } { const MEDCoupling::MEDCouplingFieldInt *f1(dynamic_cast(f)); if(f1) - WriteFieldT(fileName,f1,writeFromScratch); - return ; + { + WriteFieldT(fileName,f1,writeFromScratch); + return ; + } } { const MEDCoupling::MEDCouplingFieldFloat *f1(dynamic_cast(f)); if(f1) - WriteFieldT(fileName,f1,writeFromScratch); - return ; + { + WriteFieldT(fileName,f1,writeFromScratch); + return ; + } } throw INTERP_KERNEL::Exception("WriteField : input field is not in FLOAT32, FLOAT64, INT32 !"); }