From: karadaniz Date: Mon, 25 Mar 2024 15:16:09 +0000 (+0100) Subject: Fix spns #40523 export .mesh is too slow. Extract only unique family ids before using... X-Git-Tag: V9_13_0a1~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=589f816b4fb1c9362a05de1426aff00a4ea3b7dc;p=tools%2Fmedcoupling.git Fix spns #40523 export .mesh is too slow. Extract only unique family ids before using them in to iterate over cells. And ignore operation on fields if no field exists to avoid crash when writing .mesh file --- diff --git a/src/MEDLoader/MeshFormatWriter.cxx b/src/MEDLoader/MeshFormatWriter.cxx index 447b84a22..d86046d4b 100644 --- a/src/MEDLoader/MeshFormatWriter.cxx +++ b/src/MEDLoader/MeshFormatWriter.cxx @@ -74,11 +74,14 @@ void MeshFormatWriter::setMEDFileDS(MEDCoupling::MEDFileData* mfd) _mesh->incrRef(); MEDCoupling::MEDFileFields* fields = mfd->getFields(); - for (int i = 0; igetNumberOfFields(); i++ ) + if (fields) { - MEDCoupling::MEDFileAnyTypeFieldMultiTS* field = fields->getFieldAtPos(i); - MEDCoupling::MEDFileFieldMultiTS * f = dynamic_cast(field); - _fields.push_back(f); + for (int i = 0; igetNumberOfFields(); i++ ) + { + MEDCoupling::MEDFileAnyTypeFieldMultiTS* field = fields->getFieldAtPos(i); + MEDCoupling::MEDFileFieldMultiTS * f = dynamic_cast(field); + _fields.push_back(f); + } } @@ -867,7 +870,8 @@ void MeshFormatWriter::linkFamilyToCells() int meshDimRelToMax = levs[iDim]; MEDCoupling::MCAuto< MEDCoupling::MEDCouplingMesh > mesh = _mesh->getMeshAtLevel( meshDimRelToMax); MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh0 = mesh->buildUnstructured(); - const MEDCoupling::DataArrayIdType * famIds = _mesh->getFamilyFieldAtLevel(meshDimRelToMax); + const MEDCoupling::DataArrayIdType * famIdsField = _mesh->getFamilyFieldAtLevel(meshDimRelToMax); + const MEDCoupling::DataArrayIdType * famIds = famIdsField->getDifferentValues(); const MEDCoupling::mcIdType * famID = famIds->begin(), *famIDEnd = famIds->end(); for (; famID < famIDEnd; ++famID) {