From b099bfe29f33249f81ce784f5cacb660c4add911 Mon Sep 17 00:00:00 2001 From: azakir Date: Mon, 14 Dec 2020 11:51:43 +0100 Subject: [PATCH] reading constant size map --- src/SMESHGUI/MG_ADAPT.cxx | 88 ++++++++++++++++++++++----------------- src/SMESHGUI/MG_ADAPT.hxx | 2 + 2 files changed, 52 insertions(+), 38 deletions(-) diff --git a/src/SMESHGUI/MG_ADAPT.cxx b/src/SMESHGUI/MG_ADAPT.cxx index a89924ed7..9e3936606 100644 --- a/src/SMESHGUI/MG_ADAPT.cxx +++ b/src/SMESHGUI/MG_ADAPT.cxx @@ -730,16 +730,16 @@ std::string MgAdapt::getCommandToRun() cmd+= " --in "+ meshIn; meshFormatOutputMesh = getFileName()+".mesh"; cmd+= " --out "+ meshFormatOutputMesh; - if (useLocalMap) cmd+= " --sizemap "+ solFileIn; - else if (useBackgroundMap) + if (useLocalMap || useConstantValue) cmd+= " --sizemap "+ solFileIn; + else // (useBackgroundMap) { cmd+= " --background_mesh "+ sizeMapIn ; cmd+= " --background_sizemap "+ solFileIn; } - else - { - // constant value TODO - } + //~else + //~{ + //~// constant value TODO + //~} if (verbosityLevel != defaultVerboseLevel()) { @@ -1048,25 +1048,7 @@ void MgAdapt::convertMedFile(std::string& meshFormatMeshFileName, std::string& s meshFormatsizeMapFile = getFileName(); meshFormatsizeMapFile += ".mesh"; - MEDCoupling::MCAuto tmpMfd = MEDCoupling::MEDFileData::New(sizeMapFile); - MEDCoupling::MEDFileFields* tmpFields = tmpMfd->getFields(); - MEDCoupling::MEDFileAnyTypeFieldMultiTS* fts = tmpFields->getFieldWithName(fieldName); - MEDCoupling::MCAuto fts1 = dynamic_cast(fts); - MEDCoupling::MCAuto f = fts1->getTimeStep(timeStep, rank); - MEDCoupling::MCAuto tmFts = MEDCoupling::MEDFileFieldMultiTS::New(); - tmFts->pushBackTimeStep(f); - - MEDCoupling::MCAuto tmp_fields = MEDCoupling::MEDFileFields::New(); - tmp_fields->pushField(tmFts); - - - tmpMfd->setFields( tmp_fields ); - MeshFormatWriter tmpWriter; - tmpWriter.setMeshFileName(meshFormatsizeMapFile); - tmpWriter.setFieldFileNames( fieldFileNames); - tmpWriter.setMEDFileDS(tmpMfd); - tmpWriter.write(); - + buildBackGroundMeshAndSolFiles(fieldFileNames, meshFormatsizeMapFile); } else if(useLocalMap) @@ -1084,19 +1066,12 @@ void MgAdapt::convertMedFile(std::string& meshFormatMeshFileName, std::string& s else { - MEDCoupling::MEDCouplingMesh* mesh = fileMesh->getMeshAtLevel(1); // nodes mesh - MEDCoupling::MEDCouplingFieldDouble* fieldOnNodes=MEDCoupling::MEDCouplingFieldDouble::New(MEDCoupling::ON_NODES,MEDCoupling::NO_TIME); - fieldOnNodes->setName("MyScalarFieldOnNodeNoTime"); - fieldOnNodes->setMesh(mesh); - mesh->decrRef(); // no more need of mesh because mesh has been attached to fieldOnNodes - MEDCoupling::DataArrayDouble *array=MEDCoupling::DataArrayDouble::New(); - array->alloc(fieldOnNodes->getMesh()->getNumberOfNodes(),1);//Implicitly fieldOnNodes will be a 1 component field. - array->fillWithValue(constantValue); - fieldOnNodes->setArray(array); - array->decrRef(); - // fieldOnNodes is now usable - // ... - // fieldOnNodes is no more useful h + MEDCoupling::MCAuto mesh = fileMesh->getMeshAtLevel(1); // nodes mesh + MEDCoupling::MCAuto umesh = mesh->buildUnstructured(); // nodes mesh + int dim = umesh->getSpaceDimension(); + int version = sizeof(double) < 8 ? 1 : 2; + mcIdType nbNodes = umesh->getNumberOfNodes(); + buildConstantSizeMapSolFile(solFormatFieldFileName, dim, version, nbNodes); } @@ -1200,6 +1175,43 @@ void MgAdapt::restoreGroups(MEDCoupling::MEDFileMesh* fileMesh) const fileMesh->setGroupInfo(info); } + +void MgAdapt::buildConstantSizeMapSolFile(const std::string& solFormatFieldFileName, const int dim, const int version, const mcIdType nbNodes) const +{ + MeshFormat::Localizer loc; + MeshFormat::MeshFormatParser writer; + int fileId = writer.GmfOpenMesh( solFormatFieldFileName.c_str(), GmfWrite, version, dim); + int typTab[] = {GmfSca}; + writer.GmfSetKwd(fileId, MeshFormat::GmfSolAtVertices, (int)nbNodes, 1, typTab); + for (mcIdType i = 0; i& fieldFileNames, const std::string& meshFormatsizeMapFile) const +{ + MEDCoupling::MCAuto tmpMfd = MEDCoupling::MEDFileData::New(sizeMapFile); + MEDCoupling::MEDFileFields* tmpFields = tmpMfd->getFields(); + MEDCoupling::MEDFileAnyTypeFieldMultiTS* fts = tmpFields->getFieldWithName(fieldName); + MEDCoupling::MCAuto fts1 = dynamic_cast(fts); + MEDCoupling::MCAuto f = fts1->getTimeStep(timeStep, rank); + MEDCoupling::MCAuto tmFts = MEDCoupling::MEDFileFieldMultiTS::New(); + tmFts->pushBackTimeStep(f); + + MEDCoupling::MCAuto tmp_fields = MEDCoupling::MEDFileFields::New(); + tmp_fields->pushField(tmFts); + + + tmpMfd->setFields( tmp_fields ); + MeshFormatWriter tmpWriter; + tmpWriter.setMeshFileName(meshFormatsizeMapFile); + tmpWriter.setFieldFileNames( fieldFileNames); + tmpWriter.setMEDFileDS(tmpMfd); + tmpWriter.write(); +} // ======================================================================= med_idt MgAdapt::openMedFile(const std::string aFile) // ======================================================================= diff --git a/src/SMESHGUI/MG_ADAPT.hxx b/src/SMESHGUI/MG_ADAPT.hxx index 1854c931c..2ac1f7100 100644 --- a/src/SMESHGUI/MG_ADAPT.hxx +++ b/src/SMESHGUI/MG_ADAPT.hxx @@ -318,6 +318,8 @@ private : void storeGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh); void restoreGroupsAndFams(MEDCoupling::MEDFileMesh* fileMesh) const; void convertMeshFile(std::string& meshFormatIn, std::vector< std::string>& solFieldFileNames) const ; + void buildConstantSizeMapSolFile(const std::string& solFormatFieldFileName, const int dim, const int version, const mcIdType nbNodes) const; + void buildBackGroundMeshAndSolFiles(const std::vector& fieldFileNames, const std::string& meshFormatsizeMapFile) const; void getTimeStepInfos(std::string aFile, med_int& numdt, med_int& numit); Status addMessage(const std::string& msg, const bool isFatal = false); med_idt openMedFile(const std::string aFile) ; -- 2.39.2