From: jfa Date: Fri, 17 Dec 2021 15:39:40 +0000 (+0300) Subject: Debug, example X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=67d70c9621db146d6d8380d2c163ea1d49d49eef;p=modules%2Fsmesh.git Debug, example --- diff --git a/doc/salome/examples/CMakeLists.txt b/doc/salome/examples/CMakeLists.txt index df54d5a08..d327b91a8 100644 --- a/doc/salome/examples/CMakeLists.txt +++ b/doc/salome/examples/CMakeLists.txt @@ -42,7 +42,7 @@ SALOME_INSTALL_SCRIPTS("${EXAMPLES_TESTS}" ${SALOME_INSTALL_DOC}/examples/SMESH) SET(TEST_INSTALL_DIRECTORY ${SALOME_INSTALL_SCRIPT_SCRIPTS}/test) INSTALL(FILES ${GOOD_TESTS} ${BAD_TESTS} ${SESSION_FREE_TESTS} DESTINATION ${TEST_INSTALL_DIRECTORY}) -INSTALL(FILES Mesh_tri.med DESTINATION ${TEST_INSTALL_DIRECTORY}) +INSTALL(FILES Mesh_tri.med test_homard_adapt.med DESTINATION ${TEST_INSTALL_DIRECTORY}) INSTALL(FILES CTestTestfileInstall.cmake DESTINATION ${TEST_INSTALL_DIRECTORY} diff --git a/doc/salome/examples/test_homard_adapt.med b/doc/salome/examples/test_homard_adapt.med new file mode 100644 index 000000000..1dae05c2a Binary files /dev/null and b/doc/salome/examples/test_homard_adapt.med differ diff --git a/doc/salome/examples/test_homard_adapt.py b/doc/salome/examples/test_homard_adapt.py new file mode 100644 index 000000000..5c445659e --- /dev/null +++ b/doc/salome/examples/test_homard_adapt.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 + + + +import salome +salome.salome_init() + +import SMESH, SALOMEDS +from salome.smesh import smeshBuilder +import SMESHHOMARD + +smesh = smeshBuilder.New() + +import os, inspect, tempfile, shutil + +data_dir = os.path.dirname(inspect.getfile(lambda: None)) +working_dir = tempfile.mkdtemp() + +input_med = os.path.join (data_dir, "test_homard_adapt.med") +output_med_1 = os.path.join (working_dir, "test_1.00_Uniform_R_01.med") +output_med_2 = os.path.join (working_dir, "test_1.00_Uniform_R_02.med") +log_file_1 = os.path.join (working_dir, "test_1.00_Uniform_R_01.med.log") +log_file_2 = os.path.join (working_dir, "test_1.00_Uniform_R_02.med.log") + +# Case 1: input: med file +# output: med file, log file, published mesh +if os.path.isfile(output_med_1): + os.remove(output_med_1) +if os.path.isfile(log_file_1): + os.remove(log_file_1) + +smeshhomard = smesh.Adaptation("Uniform") +Case_1 = smeshhomard.CreateCase("MAILL", input_med, working_dir) +Case_1.SetConfType(0) +smeshhomard.SetKeepMedOUT(True) +smeshhomard.SetPublishMeshOUT(True) +smeshhomard.SetMeshNameOUT("MAILL_Uniform_R_01") +smeshhomard.SetMeshFileOUT(output_med_1) +smeshhomard.SetKeepWorkingFiles(False) +smeshhomard.SetLogInFile(True) +smeshhomard.SetLogFile(log_file_1) +smeshhomard.SetRemoveLogOnSuccess(False) +smeshhomard.SetVerboseLevel(3) +smeshhomard.Compute() + +if os.path.isfile(output_med_1): + os.remove(output_med_1) +else: + print("Test Uniform refinement Case 1: Error: no output med file") + assert(False) + +if os.path.isfile(log_file_1): + os.remove(log_file_1) +else: + print("Test Uniform refinement Case 1: Error: no log file") + assert(False) + +# Case 2: input: mesh, boundaries +# output: published mesh +if os.path.isfile(output_med_2): + os.remove(output_med_2) +if os.path.isfile(log_file_2): + os.remove(log_file_2) + +# prepare input mesh +([MAILL], status) = smesh.CreateMeshesFromMED( input_med ) + +#smeshhomard = smesh.Adaptation("Uniform") +Boun_1 = smeshhomard.CreateBoundaryCylinder("Boun_1", 0.5, 0.5, 0.5, 0, 0, 1, 0.25) +Case_1 = smeshhomard.CreateCaseOnMesh("MAILL", MAILL.GetMesh(), working_dir) +Case_1.SetConfType(0) +Case_1.AddBoundaryGroup("Boun_1", "BORD_EXT") +Case_1.AddBoundaryGroup("Boun_1", "MOITIE1") +smeshhomard.SetKeepMedOUT(False) +smeshhomard.SetPublishMeshOUT(True) +smeshhomard.SetMeshNameOUT("MAILL_Uniform_R_02") +smeshhomard.SetMeshFileOUT(output_med_2) +smeshhomard.SetKeepWorkingFiles(False) +smeshhomard.SetLogInFile(True) +smeshhomard.SetLogFile(log_file_2) +smeshhomard.SetRemoveLogOnSuccess(True) +smeshhomard.SetVerboseLevel(0) +smeshhomard.Compute() + +if os.path.isfile(output_med_2): + print("Test Uniform refinement Case 2: Error: output med file has not been removed") + assert(False) + +if os.path.isfile(log_file_2): + print("Test Uniform refinement Case 2: Error: log file has not been removed") + assert(False) + +shutil.rmtree(working_dir) + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser() diff --git a/doc/salome/examples/tests.set b/doc/salome/examples/tests.set index 4e392b19d..33086566a 100644 --- a/doc/salome/examples/tests.set +++ b/doc/salome/examples/tests.set @@ -46,6 +46,7 @@ SET(BAD_TESTS test_smeshplugin_mg_tetra_parallele.py test_smeshplugins.py MGAdaptTests_without_session.py + test_homard_adapt.py blocFissure_01_without_session.py blocFissure_02_without_session.py blocFissure_03_without_session.py diff --git a/src/SMESH/SMESH_Homard.cxx b/src/SMESH/SMESH_Homard.cxx index f4516343d..f9567d554 100644 --- a/src/SMESH/SMESH_Homard.cxx +++ b/src/SMESH/SMESH_Homard.cxx @@ -1182,20 +1182,19 @@ HomardDriver::HomardDriver(const std::string siter, const std::string siterp1): _Texte( "" ), _bLu( false ) { MESSAGE("siter = "< _HOMARD_Exec ="<<_HOMARD_Exec) ; -// + // _siter = siter ; _siterp1 = siterp1 ; } diff --git a/src/SMESHGUI/SMESHGUI_HomardAdaptDlg.cxx b/src/SMESHGUI/SMESHGUI_HomardAdaptDlg.cxx index 27674b988..40fe30e26 100644 --- a/src/SMESHGUI/SMESHGUI_HomardAdaptDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_HomardAdaptDlg.cxx @@ -99,7 +99,6 @@ SMESHGUI_HomardAdaptDlg::SMESHGUI_HomardAdaptDlg(SMESHHOMARD::HOMARD_Gen_ptr myH myAdvOpt->removeLogOnSuccessCheck ->setText (tr( "REMOVE_LOG_ON_SUCCESS" )); myAdvOpt->keepWorkingFilesCheck ->setText (tr( "KEEP_WORKING_FILES" )); - // disable // TODO??? myAdvOpt->logInFileCheck->setChecked(true); myAdvOpt->removeLogOnSuccessCheck->setChecked(false); @@ -151,7 +150,6 @@ SMESHGUI_HomardAdaptDlg::SMESHGUI_HomardAdaptDlg(SMESHHOMARD::HOMARD_Gen_ptr myH l->addLayout( btnLayout ); // dialog name and size - /* resize(600, 1150); QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); sizePolicy.setHorizontalStretch(0); @@ -160,9 +158,8 @@ SMESHGUI_HomardAdaptDlg::SMESHGUI_HomardAdaptDlg(SMESHHOMARD::HOMARD_Gen_ptr myH setSizePolicy(sizePolicy); setMinimumSize(QSize(600, 320)); setSizeIncrement(QSize(1, 1)); - setBaseSize(QSize(600, 320)); + setBaseSize(QSize(600, 600)); setAutoFillBackground(true); - */ SetBoundaryNo(); InitConnect(); @@ -216,7 +213,6 @@ void SMESHGUI_HomardAdaptDlg::InitConnect() connect( buttonHelp, SIGNAL(pressed()), this, SLOT(PushOnHelp())); connect(myArgs, SIGNAL(updateSelection()), this, SLOT(updateSelection())); - connect(myArgs, SIGNAL(toExportMED(const char*)), this, SLOT(exportMED(const char*))); } //================================================================================= @@ -383,8 +379,6 @@ bool SMESHGUI_HomardAdaptDlg::PushOnApply() if (!CheckCase(true)) return false; - MESSAGE("PushOnApply: *** aaajfa *** 12"); - // Create boundaries if (myArgs->RBBoundaryCAO->isChecked()) { QString monBoundaryCAOName = myArgs->CBBoundaryCAO->currentText(); @@ -415,7 +409,6 @@ bool SMESHGUI_HomardAdaptDlg::PushOnApply() } } } - MESSAGE("PushOnApply: *** aaajfa *** 13"); // Output MED and MESH parameters myHomardGen->SetKeepMedOUT(myArgs->myOutMedFileChk->isChecked()); @@ -475,7 +468,6 @@ bool SMESHGUI_HomardAdaptDlg::PushOnApply() MESSAGE("myHomardGen->SetLogFile(" << anOutLog.toStdString().c_str() << ")"); myHomardGen->SetLogFile(anOutLog.toStdString().c_str()); } - MESSAGE("PushOnApply: *** aaajfa *** 14"); // Compute and publish bool isSuccess = true; @@ -487,7 +479,6 @@ bool SMESHGUI_HomardAdaptDlg::PushOnApply() QObject::tr(CORBA::string_dup(S_ex.details.text)) ); isSuccess = false; } - MESSAGE("PushOnApply: *** aaajfa *** 15"); // Update Object Browser if (isSuccess) { @@ -507,7 +498,6 @@ bool SMESHGUI_HomardAdaptDlg::PushOnApply() myAdvOpt->workingDirectoryLineEdit->setReadOnly(false); myAdvOpt->workingDirectoryPushButton->setEnabled(true); - MESSAGE("PushOnApply: *** aaajfa *** THE END"); return isSuccess; } @@ -1051,7 +1041,7 @@ void SMESHGUI_HomardAdaptArguments::setupUi(QWidget *CreateCase) argumentsLayout->setColumnStretch( 1, 5 ); argumentsLayout->setRowStretch( 4, 5 ); - mySelectInMedFileButton->setText(QString()); + //mySelectInMedFileButton->setText(QString()); CBBoundaryD->setText(QApplication::translate("CreateCase", "Discrete boundary", nullptr)); CBBoundaryA->setText(QApplication::translate("CreateCase", "Analytical boundary", nullptr)); PBBoundaryCAOEdit->setText(QApplication::translate("CreateCase", "Edit", nullptr)); diff --git a/src/SMESHGUI/SMESHGUI_HomardUtils.cxx b/src/SMESHGUI/SMESHGUI_HomardUtils.cxx index 6d18e19b4..30361c9ce 100644 --- a/src/SMESHGUI/SMESHGUI_HomardUtils.cxx +++ b/src/SMESHGUI/SMESHGUI_HomardUtils.cxx @@ -364,18 +364,19 @@ QString SMESH_HOMARD_QT_COMMUN::PushNomFichier(bool avertir, QString TypeFichier if ( TypeFichier == "med" ) { filtre = QString("Med") ; } else if ( TypeFichier == "py" ) { filtre = QString("Python") ; } else { filtre = TypeFichier ; } -// + // if ( TypeFichier != "" ) { filtre += QString(" files (*.") + TypeFichier + QString(");;") ; } -// + // filtre += QString("all (*) ") ; -// + // // B. Selection - int nbSel = SMESH_HOMARD_UTILS::IObjectCount() ; -// MESSAGE("nbSel ="< +#include "SMESH_Gen_i.hxx" #include "SMESH_PythonDump.hxx" +#include "SMESH_File.hxx" + +// TODO? //#include "FrontTrack.hxx" #include "utilities.h" @@ -933,7 +936,9 @@ HOMARD_Gen_i::HOMARD_Gen_i() : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA()), _MeshNameOUT(""), _MeshFileOUT(""), _LogFile(""), - _CaseOnMedFile(true) + _CaseOnMedFile(true), + _SmeshMesh(SMESH::SMESH_Mesh::_nil()), + _TmpMeshFile("") { MESSAGE("constructor de HOMARD_Gen_i"); myHomard = new SMESHHOMARDImpl::HOMARD_Gen; @@ -946,6 +951,9 @@ HOMARD_Gen_i::HOMARD_Gen_i() : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA()), //============================================================================= HOMARD_Gen_i::~HOMARD_Gen_i() { + if (!myCase->_is_nil()) { + CleanCase(); + } } //============================================================================= @@ -1202,9 +1210,16 @@ SMESHHOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseOnMesh (const char* MeshName MESSAGE("CreateCaseOnMesh : smeshMesh is not nil"); // A.3. Write mesh object in a temporary file in the working directory - std::string aTmpMeshFile (theWorkingDir); - aTmpMeshFile += std::string("/") + std::string(MeshName) + "_saved_from_SMESH.med"; // TODO: unique - const char* MeshFile = aTmpMeshFile.c_str(); + std::string aTmpMeshFile = theWorkingDir; + aTmpMeshFile = theWorkingDir; + aTmpMeshFile += std::string("/") + std::string(MeshName) + "_saved_from_SMESH"; + _TmpMeshFile = aTmpMeshFile + ".med"; + SMESH_File aFile (_TmpMeshFile, false); + for (int ii = 1; aFile.exists(); ii++) { + _TmpMeshFile = aTmpMeshFile + std::string("_") + std::to_string(ii) + ".med"; + aFile = SMESH_File(_TmpMeshFile, false); + } + const char* MeshFile = _TmpMeshFile.c_str(); bool toOverwrite = true; bool toFindOutDim = true; @@ -1816,13 +1831,6 @@ CORBA::Long HOMARD_Gen_i::Compute() // Python Dump PythonDump(); - // Delete log file, if required - MESSAGE("myIteration1->GetLogFile() = " << myIteration1->GetLogFile()); - if (_LogInFile && _RemoveLogOnSuccess) { - // Remove log file on success - // TODO: QFile(myIteration->GetLogFile()).remove(); - } - // Clean all data CleanCase(); } @@ -1832,6 +1840,13 @@ CORBA::Long HOMARD_Gen_i::Compute() void HOMARD_Gen_i::CleanCase() { + // Delete log file, if required + MESSAGE("myIteration1->GetLogFile() = " << myIteration1->GetLogFile()); + if (_LogInFile && _RemoveLogOnSuccess) { + // Remove log file on success + SMESH_File(myIteration1->GetLogFile(), false).remove(); + } + // Delete all boundaries std::map::const_iterator it_boundary; for (it_boundary = _mesBoundarys.begin(); @@ -1848,6 +1863,13 @@ void HOMARD_Gen_i::CleanCase() // Delete case DeleteCase(); + + // Delete tmp mesh file + if (!_CaseOnMedFile && !_TmpMeshFile.empty()) { + SMESH_File aFile (_TmpMeshFile, false); + if (aFile.exists()) aFile.remove(); + } + _SmeshMesh = SMESH::SMESH_Mesh::_nil(); } //============================================================================= @@ -2041,6 +2063,7 @@ CORBA::Long HOMARD_Gen_i::ComputeCAO(SMESHHOMARD::HOMARD_Cas_var myCase, // C. Lancement des projections MESSAGE (". Lancement des projections"); + // TODO? //FrontTrack* myFrontTrack = new FrontTrack(); //myFrontTrack->track(theInputMedFile, theOutputMedFile, theInputNodeFiles, theXaoFileName, theIsParallel); @@ -2505,6 +2528,9 @@ void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option) SALOMEDS::SObject_var aSmeshSO = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindComponent("SMESH"); // + // TODO? + // Temporary suppressed depublication of mesh with the same name of file + /* if (!CORBA::is_nil(aSmeshSO)) { // On verifie que le fichier n est pas deja publie SALOMEDS::ChildIterator_var aIter = @@ -2535,27 +2561,24 @@ void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option) } } } + */ // On enregistre le fichier MESSAGE("Enregistrement du fichier"); // //SMESH::SMESH_Gen_var aSmeshEngine = this->retrieveSMESHInst(); SMESH_Gen_i* aSmeshEngine = SMESH_Gen_i::GetSMESHGen(); - MESSAGE(" *** aaajfa *** !!! 1"); // //ASSERT(!CORBA::is_nil(aSmeshEngine)); aSmeshEngine->UpdateStudy(); SMESH::DriverMED_ReadStatus theStatus; // On met a jour les attributs AttributeExternalFileDef et AttributePixMap - MESSAGE(" *** aaajfa *** !!! 2"); SMESH::mesh_array* mesMaillages = aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus); - MESSAGE(" *** aaajfa *** !!! 3"); if (CORBA::is_nil(aSmeshSO)) { aSmeshSO = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindComponent("SMESH"); if (CORBA::is_nil(aSmeshSO)) return; } - MESSAGE(" *** aaajfa *** !!! 4"); for (int i = 0; i < (int)mesMaillages->length(); i++) { MESSAGE(". Mise a jour des attributs du maillage"); @@ -2578,7 +2601,6 @@ void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option) else { icone = "mesh_tree_mesh.png"; } anAttr2->SetPixMap(icone); } - MESSAGE(" *** aaajfa *** !!! 5"); } //============================================================================= @@ -2629,7 +2651,8 @@ void HOMARD_Gen_i::PythonDump() // SMESH_Homard pd << "import SMESHHOMARD\n"; - pd << "smeshhomard = " << SMESH_Gen_i::GetSMESHGen() << ".CreateHOMARD_ADAPT()\n"; + //pd << "smeshhomard = " << SMESH_Gen_i::GetSMESHGen() << ".CreateHOMARD_ADAPT()\n"; + pd << "smeshhomard = " << SMESH_Gen_i::GetSMESHGen() << ".Adaptation(\"Uniform\")\n"; // Boundaries if (_mesBoundarys.size() > 0) MESSAGE(". Creation of the boundaries"); @@ -2652,21 +2675,21 @@ void HOMARD_Gen_i::PythonDump() else { pd << "Case_1 = smeshhomard.CreateCaseOnMesh(\"" << myIteration0->GetMeshName(); pd << "\", " << _SmeshMesh; - pd << ", \"" << myCase->GetDirName() << "\")\n"; + pd << ".GetMesh(), \"" << myCase->GetDirName() << "\")\n"; } pd << myCase->GetDumpPython(); // Preferences - pd << "smeshhomard.SetKeepMedOUT(" << _KeepMedOUT << ")\n"; - pd << "smeshhomard.SetPublishMeshOUT(" << _PublishMeshOUT << ")\n"; + pd << "smeshhomard.SetKeepMedOUT(" << (_KeepMedOUT ? "True" : "False") << ")\n"; + pd << "smeshhomard.SetPublishMeshOUT(" << (_PublishMeshOUT ? "True" : "False") << ")\n"; pd << "smeshhomard.SetMeshNameOUT(\"" << _MeshNameOUT << "\")\n"; pd << "smeshhomard.SetMeshFileOUT(\"" << _MeshFileOUT << "\")\n"; - pd << "smeshhomard.SetKeepWorkingFiles(" << _KeepWorkingFiles << ")\n"; - pd << "smeshhomard.SetLogInFile(" << _LogInFile << ")\n"; + pd << "smeshhomard.SetKeepWorkingFiles(" << (_KeepWorkingFiles ? "True" : "False") << ")\n"; + pd << "smeshhomard.SetLogInFile(" << (_LogInFile ? "True" : "False") << ")\n"; if (_LogInFile) pd << "smeshhomard.SetLogFile(\"" << _LogFile << "\")\n"; - pd << "smeshhomard.SetRemoveLogOnSuccess(" << _RemoveLogOnSuccess << ")\n"; + pd << "smeshhomard.SetRemoveLogOnSuccess(" << (_RemoveLogOnSuccess ? "True" : "False") << ")\n"; pd << "smeshhomard.SetVerboseLevel(" << _VerboseLevel << ")\n"; // Compute diff --git a/src/SMESH_I/SMESH_Homard_i.hxx b/src/SMESH_I/SMESH_Homard_i.hxx index 3f08b4d2f..ba025e057 100644 --- a/src/SMESH_I/SMESH_Homard_i.hxx +++ b/src/SMESH_I/SMESH_Homard_i.hxx @@ -342,6 +342,7 @@ private: // Input data type bool _CaseOnMedFile; SMESH::SMESH_Mesh_var _SmeshMesh; + std::string _TmpMeshFile; }; SMESH_I_EXPORT std::vector GetBoundingBoxInMedFile(const char * aFile);