1 // Copyright (C) 2011-2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SMESH_Homard_i.hxx"
21 #include "SMESH_Homard.hxx"
23 #include "SMESH_Gen_i.hxx"
24 #include "SMESH_PythonDump.hxx"
26 #include "SMESH_File.hxx"
28 #include "utilities.h"
29 #include "Basics_Utils.hxx"
30 #include "Basics_DirUtils.hxx"
31 #include "Utils_SINGLETON.hxx"
32 #include "Utils_CorbaException.hxx"
33 #include "SALOMEDS_Tool.hxx"
34 #include "SALOME_LifeCycleCORBA.hxx"
35 #include "SALOMEconfig.h"
37 // Have to be included before std headers
39 #include <structmember.h>
65 // C'est le ASSERT de SALOMELocalTrace/utilities.h dans KERNEL
67 #define VERIFICATION(condition) \
68 if (!(condition)){INTERRUPTION("CONDITION "<<#condition<<" NOT VERIFIED")}
69 #endif /* VERIFICATION */
71 // La gestion des repertoires
82 SMESHHOMARD::HOMARD_Gen_ptr SMESH_Gen_i::CreateHOMARD_ADAPT()
84 if (getenv("HOMARD_ROOT_DIR") == NULL) {
85 THROW_SALOME_CORBA_EXCEPTION("HOMARD_ROOT_DIR is not defined", SALOME::INTERNAL_ERROR);
88 std::string homard_exec = getenv("HOMARD_ROOT_DIR");
89 homard_exec += "/bin/salome/homard";
90 if (!SMESH_File(homard_exec).exists())
91 THROW_SALOME_CORBA_EXCEPTION("HOMARD module is not built", SALOME::INTERNAL_ERROR);
93 SMESHHOMARD_I::HOMARD_Gen_i* aHomardGen = new SMESHHOMARD_I::HOMARD_Gen_i();
94 SMESHHOMARD::HOMARD_Gen_var anObj = aHomardGen->_this();
98 namespace SMESHHOMARD_I
101 //=============================================================================
103 * standard constructor
105 //=============================================================================
106 HOMARD_Boundary_i::HOMARD_Boundary_i()
107 : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
109 MESSAGE("Default constructor, not for use");
112 //=============================================================================
114 * standard constructor
116 //=============================================================================
117 HOMARD_Boundary_i::HOMARD_Boundary_i(SMESHHOMARD::HOMARD_Gen_var engine)
118 : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
120 MESSAGE("HOMARD_Boundary_i");
122 myHomardBoundary = new SMESHHOMARDImpl::HOMARD_Boundary();
123 ASSERT(myHomardBoundary);
125 //=============================================================================
127 * standard destructor
129 //=============================================================================
130 HOMARD_Boundary_i::~HOMARD_Boundary_i()
133 //=============================================================================
134 //=============================================================================
136 //=============================================================================
137 //=============================================================================
138 void HOMARD_Boundary_i::SetName(const char* Name)
140 ASSERT(myHomardBoundary);
141 myHomardBoundary->SetName(Name);
143 //=============================================================================
144 char* HOMARD_Boundary_i::GetName()
146 ASSERT(myHomardBoundary);
147 return CORBA::string_dup(myHomardBoundary->GetName().c_str());
149 //=============================================================================
150 char* HOMARD_Boundary_i::GetDumpPython()
152 ASSERT(myHomardBoundary);
153 return CORBA::string_dup(myHomardBoundary->GetDumpPython().c_str());
155 //=============================================================================
156 //=============================================================================
158 //=============================================================================
159 //=============================================================================
160 void HOMARD_Boundary_i::SetType(CORBA::Long Type)
162 ASSERT(myHomardBoundary);
163 myHomardBoundary->SetType(Type);
165 //=============================================================================
166 CORBA::Long HOMARD_Boundary_i::GetType()
168 ASSERT(myHomardBoundary);
169 return CORBA::Long(myHomardBoundary->GetType());
171 //=============================================================================
172 void HOMARD_Boundary_i::SetMeshName(const char* MeshName)
174 ASSERT(myHomardBoundary);
175 myHomardBoundary->SetMeshName(MeshName);
177 //=============================================================================
178 char* HOMARD_Boundary_i::GetMeshName()
180 ASSERT(myHomardBoundary);
181 return CORBA::string_dup(myHomardBoundary->GetMeshName().c_str());
183 //=============================================================================
184 void HOMARD_Boundary_i::SetDataFile(const char* DataFile)
186 ASSERT(myHomardBoundary);
187 myHomardBoundary->SetDataFile(DataFile);
189 //=============================================================================
190 char* HOMARD_Boundary_i::GetDataFile()
192 ASSERT(myHomardBoundary);
193 return CORBA::string_dup(myHomardBoundary->GetDataFile().c_str());
195 //=============================================================================
196 void HOMARD_Boundary_i::SetCylinder(double X0, double X1, double X2, double X3, double X4, double X5, double X6)
198 ASSERT(myHomardBoundary);
199 myHomardBoundary->SetCylinder(X0, X1, X2, X3, X4, X5, X6);
201 //=============================================================================
202 void HOMARD_Boundary_i::SetSphere(double Xcentre, double Ycentre, double ZCentre, double rayon)
204 ASSERT(myHomardBoundary);
205 myHomardBoundary->SetSphere(Xcentre, Ycentre, ZCentre, rayon);
207 //=============================================================================
208 void HOMARD_Boundary_i::SetConeR(double Xcentre1, double Ycentre1, double Zcentre1, double Rayon1, double Xcentre2, double Ycentre2, double Zcentre2, double Rayon2)
210 ASSERT(myHomardBoundary);
211 myHomardBoundary->SetConeR(Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2);
213 //=============================================================================
214 void HOMARD_Boundary_i::SetConeA(double Xaxe, double Yaxe, double Zaxe, double Angle, double Xcentre, double Ycentre, double Zcentre)
216 ASSERT(myHomardBoundary);
217 myHomardBoundary->SetConeA(Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre);
219 //=============================================================================
220 void HOMARD_Boundary_i::SetTorus(double X0, double X1, double X2, double X3, double X4, double X5, double X6, double X7)
222 ASSERT(myHomardBoundary);
223 myHomardBoundary->SetTorus(X0, X1, X2, X3, X4, X5, X6, X7);
225 //=============================================================================
226 SMESHHOMARD::double_array* HOMARD_Boundary_i::GetCoords()
228 ASSERT(myHomardBoundary);
229 SMESHHOMARD::double_array_var aResult = new SMESHHOMARD::double_array();
230 std::vector<double> mesCoor = myHomardBoundary->GetCoords();
231 aResult->length(mesCoor .size());
232 std::vector<double>::const_iterator it;
234 for (it = mesCoor.begin(); it != mesCoor.end(); it++)
235 aResult[i++] = (*it);
236 return aResult._retn();
238 //=============================================================================
239 void HOMARD_Boundary_i::SetLimit(double Xincr, double Yincr, double Zincr)
241 ASSERT(myHomardBoundary);
242 myHomardBoundary->SetLimit(Xincr, Yincr, Zincr);
244 //=============================================================================
245 SMESHHOMARD::double_array* HOMARD_Boundary_i::GetLimit()
247 ASSERT(myHomardBoundary);
248 SMESHHOMARD::double_array_var aResult = new SMESHHOMARD::double_array();
249 std::vector<double> mesCoor = myHomardBoundary->GetLimit();
250 aResult->length(mesCoor .size());
251 std::vector<double>::const_iterator it;
253 for (it = mesCoor.begin(); it != mesCoor.end(); it++)
254 aResult[i++] = (*it);
255 return aResult._retn();
257 //=============================================================================
258 void HOMARD_Boundary_i::AddGroup(const char* Group)
260 ASSERT(myHomardBoundary);
261 myHomardBoundary->AddGroup(Group);
263 //=============================================================================
264 void HOMARD_Boundary_i::SetGroups(const SMESHHOMARD::ListGroupType& ListGroup)
266 ASSERT(myHomardBoundary);
267 std::list<std::string> ListString;
268 for (unsigned int i = 0; i < ListGroup.length(); i++) {
269 ListString.push_back(std::string(ListGroup[i]));
271 myHomardBoundary->SetGroups(ListString);
273 //=============================================================================
274 SMESHHOMARD::ListGroupType* HOMARD_Boundary_i::GetGroups()
276 ASSERT(myHomardBoundary);
277 const std::list<std::string>& ListString = myHomardBoundary->GetGroups();
278 SMESHHOMARD::ListGroupType_var aResult = new SMESHHOMARD::ListGroupType;
279 aResult->length(ListString.size());
280 std::list<std::string>::const_iterator it;
282 for (it = ListString.begin(); it != ListString.end(); it++)
284 aResult[i++] = CORBA::string_dup((*it).c_str());
286 return aResult._retn();
289 //=============================================================================
291 * standard constructor
293 //=============================================================================
294 HOMARD_Cas_i::HOMARD_Cas_i()
295 : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
297 MESSAGE("Default constructor, not for use");
301 //=============================================================================
303 * standard constructor
305 //=============================================================================
306 HOMARD_Cas_i::HOMARD_Cas_i(SMESHHOMARD::HOMARD_Gen_var engine)
307 : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
309 MESSAGE("HOMARD_Cas_i");
311 myHomardCas = new SMESHHOMARDImpl::HOMARD_Cas();
315 //=============================================================================
317 * standard destructor
319 //=============================================================================
320 HOMARD_Cas_i::~HOMARD_Cas_i()
323 //=============================================================================
324 char* HOMARD_Cas_i::GetDumpPython()
327 return CORBA::string_dup(myHomardCas->GetDumpPython().c_str());
329 //=============================================================================
330 //=============================================================================
332 //=============================================================================
333 //=============================================================================
334 void HOMARD_Cas_i::SetDirName(const char* NomDir)
338 // A. recuperation du nom; on ne fait rien si c'est le meme
339 char* oldrep = GetDirName();
340 if (strcmp(oldrep,NomDir) == 0) return;
341 MESSAGE ("SetDirName : passage de oldrep = "<< oldrep << " a NomDir = "<<NomDir);
342 // C. Changement/creation du repertoire
343 codret = myHomardCas->SetDirName(NomDir);
345 SALOME::ExceptionStruct es;
346 es.type = SALOME::BAD_PARAM;
349 text = "The directory for the case cannot be modified because some iterations are already defined.";
351 text = "The directory for the case cannot be reached.";
352 es.text = CORBA::string_dup(text.c_str());
353 throw SALOME::SALOME_Exception(es);
356 // D. En cas de reprise, deplacement du point de depart
357 HOMARD_Gen_i* aGenImpl = SMESH::DownCast<HOMARD_Gen_i*>(_gen_i);
358 HOMARD_Iteration_i* Iter0 = aGenImpl->GetIteration(0);
359 int state = Iter0->GetNumber();
360 if (state != 0) { // GetState()
361 MESSAGE ("etat : " << state);
362 // D.1. Nom local du repertoire de l'iteration de depart dans le repertoire actuel du cas
363 char* DirNameIter = Iter0->GetDirNameLoc();
364 MESSAGE ("SetDirName : nom actuel pour le repertoire de l iteration, DirNameIter = "<< DirNameIter);
365 // D.2. Recherche d'un nom local pour l'iteration de depart dans le futur repertoire du cas
366 char* nomDirIter = aGenImpl->CreateDirNameIter(NomDir, 0);
367 MESSAGE ("SetDirName : nom futur pour le repertoire de l iteration, nomDirIter = "<< nomDirIter);
368 // D.3. Creation du futur repertoire local pour l'iteration de depart
369 std::string nomDirIterTotal;
370 nomDirIterTotal = std::string(NomDir) + "/" + std::string(nomDirIter);
372 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
374 if (_mkdir(nomDirIterTotal.c_str()) != 0)
377 MESSAGE ("nomDirIterTotal : " << nomDirIterTotal);
378 SALOME::ExceptionStruct es;
379 es.type = SALOME::BAD_PARAM;
380 std::string text = "The directory for the starting iteration cannot be created.";
381 es.text = CORBA::string_dup(text.c_str());
382 throw SALOME::SALOME_Exception(es);
384 // D.4. Deplacement du contenu du repertoire
385 std::string oldnomDirIterTotal;
386 oldnomDirIterTotal = std::string(oldrep) + "/" + std::string(DirNameIter);
387 std::string commande = "mv " + std::string(oldnomDirIterTotal) + "/*" + " " + std::string(nomDirIterTotal);
388 codret = system(commande.c_str());
391 SALOME::ExceptionStruct es;
392 es.type = SALOME::BAD_PARAM;
393 std::string text = "The starting point for the case cannot be moved into the new directory.";
394 es.text = CORBA::string_dup(text.c_str());
395 throw SALOME::SALOME_Exception(es);
397 commande = "rm -rf " + std::string(oldnomDirIterTotal);
398 codret = system(commande.c_str());
401 SALOME::ExceptionStruct es;
402 es.type = SALOME::BAD_PARAM;
403 std::string text = "The starting point for the case cannot be deleted.";
404 es.text = CORBA::string_dup(text.c_str());
405 throw SALOME::SALOME_Exception(es);
407 // D.5. Memorisation du nom du repertoire de l'iteration
408 Iter0->SetDirNameLoc(nomDirIter);
411 //=============================================================================
412 char* HOMARD_Cas_i::GetDirName()
415 return CORBA::string_dup(myHomardCas->GetDirName().c_str());
417 //=============================================================================
418 void HOMARD_Cas_i::SetBoundingBox(const SMESHHOMARD::extrema& LesExtrema)
421 std::vector<double> VExtrema;
422 ASSERT(LesExtrema.length() == 10);
423 VExtrema.resize(LesExtrema.length());
424 for (int i = 0; i < (int)LesExtrema.length(); i++) {
425 VExtrema[i] = LesExtrema[i];
427 myHomardCas->SetBoundingBox(VExtrema);
429 //=============================================================================
430 SMESHHOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
433 SMESHHOMARD::extrema_var aResult = new SMESHHOMARD::extrema();
434 std::vector<double> LesExtremes = myHomardCas->GetBoundingBox();
435 ASSERT(LesExtremes.size() == 10);
437 for (unsigned int i = 0; i < LesExtremes.size(); i++) {
438 aResult[i] = LesExtremes[i];
440 return aResult._retn();
443 //=============================================================================
444 void HOMARD_Cas_i::AddGroup(const char* Group)
447 myHomardCas->AddGroup(Group);
449 //=============================================================================
450 void HOMARD_Cas_i::SetGroups(const SMESHHOMARD::ListGroupType& ListGroup)
453 std::list<std::string> ListString;
454 for (unsigned int i = 0; i < ListGroup.length(); i++)
456 ListString.push_back(std::string(ListGroup[i]));
458 myHomardCas->SetGroups(ListString);
460 //=============================================================================
461 SMESHHOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
464 const std::list<std::string>& ListString = myHomardCas->GetGroups();
465 SMESHHOMARD::ListGroupType_var aResult = new SMESHHOMARD::ListGroupType();
466 aResult->length(ListString.size());
467 std::list<std::string>::const_iterator it;
469 for (it = ListString.begin(); it != ListString.end(); it++) {
470 aResult[i++] = CORBA::string_dup((*it).c_str());
472 return aResult._retn();
475 //=============================================================================
476 void HOMARD_Cas_i::AddBoundary(const char* BoundaryName)
478 MESSAGE ("HOMARD_Cas_i::AddBoundary : BoundaryName = "<< BoundaryName);
479 const char * Group = "";
480 AddBoundaryGroup(BoundaryName, Group);
482 //=============================================================================
483 void HOMARD_Cas_i::AddBoundaryGroup(const char* BoundaryName, const char* Group)
485 MESSAGE ("HOMARD_Cas_i::AddBoundaryGroup : BoundaryName = "<< BoundaryName << ", Group = " << Group);
488 // A.1. Caractéristiques de la frontière à ajouter
489 SMESHHOMARD::HOMARD_Boundary_ptr myBoundary = _gen_i->GetBoundary(BoundaryName);
490 ASSERT(!CORBA::is_nil(myBoundary));
491 int BoundaryType = myBoundary->GetType();
492 MESSAGE (". BoundaryType = " << BoundaryType);
493 // A.2. La liste des frontiere+groupes
494 const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
495 std::list<std::string>::const_iterator it;
501 // B.1. Si on ajoute une frontière CAO, elle doit être la seule frontière
502 if (BoundaryType == -1)
504 for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++)
506 boun = (*it).c_str();
507 MESSAGE (".. Frontiere enregistrée : "<< boun);
508 if (*it != BoundaryName)
511 // On saute le nom du groupe
515 if (erreur != 0) { break; }
516 // B.2. Si on ajoute une frontière non CAO, il ne doit pas y avoir de frontière CAO
517 if (BoundaryType != -1)
519 for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++)
521 boun = (*it).c_str();
522 MESSAGE (".. Frontiere enregistrée : "<< boun);
523 SMESHHOMARD::HOMARD_Boundary_ptr myBoundary_0 = _gen_i->GetBoundary(boun);
524 int BoundaryType_0 = myBoundary_0->GetType();
525 MESSAGE (".. BoundaryType_0 = " << BoundaryType_0);
526 if (BoundaryType_0 == -1)
529 // On saute le nom du groupe
532 if (erreur != 0) { break; }
534 // B.3. Si on ajoute une frontière discrète, il ne doit pas y avoir d'autre frontière discrète
535 if (BoundaryType == 0)
537 for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++)
539 boun = (*it).c_str();
540 MESSAGE (".. Frontiere enregistrée : "<< boun);
541 if (boun != BoundaryName)
543 SMESHHOMARD::HOMARD_Boundary_ptr myBoundary_0 = _gen_i->GetBoundary(boun);
544 int BoundaryType_0 = myBoundary_0->GetType();
545 MESSAGE (".. BoundaryType_0 = " << BoundaryType_0);
546 if (BoundaryType_0 == 0)
550 // On saute le nom du groupe
553 if (erreur != 0) { break; }
555 // B.4. Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
556 for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++) {
557 MESSAGE (".. Frontiere : "<< *it);
558 // On saute le nom du groupe
561 // B.5. Le groupe est-il deja enregistre pour une frontiere de ce cas ?
562 for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++) {
563 boun = (*it).c_str();
565 MESSAGE (".. Groupe enregistré : "<< *it);
571 if (erreur != 0) { break; }
575 // F. Si aucune erreur, enregistrement du couple (frontiere,groupe) dans la reference du cas
578 myHomardCas->AddBoundaryGroup(BoundaryName, Group);
581 std::stringstream ss;
583 std::string str = ss.str();
585 texte = "Erreur numéro " + str + " pour la frontière à enregistrer : " + std::string(BoundaryName);
586 if (erreur == 1) { texte += "\nIl existe déjà la frontière "; }
587 else if (erreur == 2) { texte += "\nIl existe déjà la frontière CAO "; }
588 else if (erreur == 3) { texte += "\nIl existe déjà une frontière discrète : "; }
589 else if (erreur == 5) { texte += "\nLe groupe " + std::string(Group) + " est déjà enregistré pour la frontière "; }
590 texte += std::string(boun);
592 SALOME::ExceptionStruct es;
593 es.type = SALOME::BAD_PARAM;
595 texte += "\nInvalid AddBoundaryGroup";
598 es.text = CORBA::string_dup(texte.c_str());
599 throw SALOME::SALOME_Exception(es);
602 //=============================================================================
603 SMESHHOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
605 MESSAGE ("GetBoundaryGroup");
607 const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
608 SMESHHOMARD::ListBoundaryGroupType_var aResult = new SMESHHOMARD::ListBoundaryGroupType();
609 aResult->length(ListBoundaryGroup.size());
610 std::list<std::string>::const_iterator it;
612 for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++)
614 aResult[i++] = CORBA::string_dup((*it).c_str());
616 return aResult._retn();
618 //=============================================================================
619 void HOMARD_Cas_i::SupprBoundaryGroup()
621 MESSAGE ("SupprBoundaryGroup");
623 myHomardCas->SupprBoundaryGroup();
626 void HOMARD_Cas_i::AddIteration(const char* NomIteration)
629 myHomardCas->AddIteration(NomIteration);
632 //=============================================================================
634 * standard constructor
636 //=============================================================================
637 HOMARD_Iteration_i::HOMARD_Iteration_i()
639 MESSAGE("Default constructor, not for use");
642 //=============================================================================
644 * standard constructor
646 //=============================================================================
647 HOMARD_Iteration_i::HOMARD_Iteration_i(SMESHHOMARD::HOMARD_Gen_var engine)
649 MESSAGE("constructor");
651 myHomardIteration = new SMESHHOMARDImpl::HOMARD_Iteration();
652 ASSERT(myHomardIteration);
654 //=============================================================================
656 * standard destructor
658 //=============================================================================
659 HOMARD_Iteration_i::~HOMARD_Iteration_i()
662 //=============================================================================
663 void HOMARD_Iteration_i::SetName(const char* Name)
665 ASSERT(myHomardIteration);
666 myHomardIteration->SetName(Name);
668 //=============================================================================
669 char* HOMARD_Iteration_i::GetName()
671 ASSERT(myHomardIteration);
672 return CORBA::string_dup(myHomardIteration->GetName().c_str());
674 //=============================================================================
675 void HOMARD_Iteration_i::SetDirNameLoc(const char* NomDir)
677 ASSERT(myHomardIteration);
678 myHomardIteration->SetDirNameLoc(NomDir);
680 //=============================================================================
681 char* HOMARD_Iteration_i::GetDirNameLoc()
683 ASSERT(myHomardIteration);
684 return CORBA::string_dup(myHomardIteration->GetDirNameLoc().c_str());
686 //=============================================================================
687 char* HOMARD_Iteration_i::GetDirName()
689 ASSERT(myHomardIteration);
690 SMESHHOMARD::HOMARD_Cas_ptr caseiter = _gen_i->GetCase();
691 std::string dirnamecase = caseiter->GetDirName();
692 std::string dirname = dirnamecase + "/" + GetDirNameLoc();
693 return CORBA::string_dup(dirname.c_str());
695 //=============================================================================
696 void HOMARD_Iteration_i::SetNumber(CORBA::Long NumIter)
698 ASSERT(myHomardIteration);
699 myHomardIteration->SetNumber(NumIter);
701 //=============================================================================
702 CORBA::Long HOMARD_Iteration_i::GetNumber()
704 ASSERT(myHomardIteration);
705 return myHomardIteration->GetNumber();
707 //=============================================================================
708 void HOMARD_Iteration_i::SetState(CORBA::Long Etat)
710 ASSERT(myHomardIteration);
711 myHomardIteration->SetState(Etat);
713 //=============================================================================
714 CORBA::Long HOMARD_Iteration_i::GetState()
716 ASSERT(myHomardIteration);
717 return myHomardIteration->GetState();
719 //=============================================================================
720 void HOMARD_Iteration_i::SetMeshName(const char* NomMesh)
722 ASSERT(myHomardIteration);
723 myHomardIteration->SetMeshName(NomMesh);
725 //=============================================================================
726 char* HOMARD_Iteration_i::GetMeshName()
728 ASSERT(myHomardIteration);
729 return CORBA::string_dup(myHomardIteration->GetMeshName().c_str());
731 //=============================================================================
732 void HOMARD_Iteration_i::SetMeshFile(const char* MeshFile)
734 ASSERT(myHomardIteration);
735 myHomardIteration->SetMeshFile(MeshFile);
737 //=============================================================================
738 char* HOMARD_Iteration_i::GetMeshFile()
740 ASSERT(myHomardIteration);
741 return CORBA::string_dup(myHomardIteration->GetMeshFile().c_str());
743 //=============================================================================
744 void HOMARD_Iteration_i::SetLogFile(const char* LogFile)
746 ASSERT(myHomardIteration);
747 myHomardIteration->SetLogFile(LogFile);
749 //=============================================================================
750 char* HOMARD_Iteration_i::GetLogFile()
752 ASSERT(myHomardIteration);
753 return CORBA::string_dup(myHomardIteration->GetLogFile().c_str());
755 //=============================================================================
756 void HOMARD_Iteration_i::SetFileInfo(const char* FileInfo)
758 ASSERT(myHomardIteration);
759 myHomardIteration->SetFileInfo(FileInfo);
761 //=============================================================================
762 char* HOMARD_Iteration_i::GetFileInfo()
764 ASSERT(myHomardIteration);
765 return CORBA::string_dup(myHomardIteration->GetFileInfo().c_str());
767 //=============================================================================
768 void HOMARD_Iteration_i::SetInfoCompute(CORBA::Long MessInfo)
770 ASSERT(myHomardIteration);
771 myHomardIteration->SetInfoCompute(MessInfo);
773 //=============================================================================
774 CORBA::Long HOMARD_Iteration_i::GetInfoCompute()
776 ASSERT(myHomardIteration);
777 return myHomardIteration->GetInfoCompute();
780 //=============================================================================
782 * standard constructor
784 //=============================================================================
785 HOMARD_Gen_i::HOMARD_Gen_i() : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA()),
790 _PublishMeshOUT(false),
791 _KeepWorkingFiles(false),
793 _RemoveLogOnSuccess(false),
798 _CaseOnMedFile(true),
799 _SmeshMesh(SMESH::SMESH_Mesh::_nil()),
802 MESSAGE("constructor de HOMARD_Gen_i");
803 myHomard = new SMESHHOMARDImpl::HOMARD_Gen;
806 //=============================================================================
808 * standard destructor
810 //=============================================================================
811 HOMARD_Gen_i::~HOMARD_Gen_i()
813 MESSAGE ("HOMARD_Gen_i::~HOMARD_Gen_i()");
816 //=============================================================================
817 //=============================================================================
818 // Destruction des structures identifiees par leurs noms
819 //=============================================================================
820 //=============================================================================
821 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
823 MESSAGE ("DeleteBoundary : BoundaryName = " << BoundaryName);
824 SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[BoundaryName];
825 if (CORBA::is_nil(myBoundary)) {
826 SALOME::ExceptionStruct es;
827 es.type = SALOME::BAD_PARAM;
828 es.text = "Invalid boundary";
829 throw SALOME::SALOME_Exception(es);
832 // Boundaries should be deleted only after all cases deletion!!!
834 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
835 _mesBoundarys.erase(BoundaryName);
840 //=============================================================================
841 CORBA::Long HOMARD_Gen_i::DeleteIteration(int numIter)
843 MESSAGE ("DeleteIteration : numIter = " << numIter);
846 if (myIteration0 != NULL) {
852 if (myIteration1 != NULL) {
853 // Invalide Iteration
854 if (myIteration1->GetState() > 0) {
855 myIteration1->SetState(1);
856 if (!_KeepWorkingFiles) {
857 std::string nomDir = myIteration1->GetDirName();
858 std::string commande = "rm -rf " + nomDir;
859 if (numIter > 0 && !_KeepMedOUT) {
860 // Remove associated mesh file
861 std::string nomFichier = myIteration1->GetMeshFile();
862 commande = commande + ";rm -rf " + nomFichier;
864 MESSAGE ("commande = " << commande);
865 if ((system(commande.c_str())) != 0) {
866 SALOME::ExceptionStruct es;
867 es.type = SALOME::BAD_PARAM;
868 es.text = "The directory for the calculation cannot be cleared.";
869 throw SALOME::SALOME_Exception(es);
882 //=============================================================================
883 //=============================================================================
884 // Invalidation des structures identifiees par leurs noms
885 //=============================================================================
886 //=============================================================================
887 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
889 MESSAGE("InvalideBoundary : BoundaryName = " << BoundaryName);
890 SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[BoundaryName];
891 if (CORBA::is_nil(myBoundary)) {
892 SALOME::ExceptionStruct es;
893 es.type = SALOME::BAD_PARAM;
894 es.text = "Invalid boundary";
895 throw SALOME::SALOME_Exception(es);
898 SALOME::ExceptionStruct es;
899 es.type = SALOME::BAD_PARAM;
900 es.text = "No change is allowed in a boundary. Ask for evolution.";
901 throw SALOME::SALOME_Exception(es);
905 //=============================================================================
906 //=============================================================================
907 // Association de lien entre des structures identifiees par leurs noms
908 //=============================================================================
909 //=============================================================================
910 void HOMARD_Gen_i::AssociateCaseIter(int numIter, const char* labelIter)
912 MESSAGE("AssociateCaseIter : " << numIter << ", " << labelIter);
914 if (CORBA::is_nil(myCase)) {
915 SALOME::ExceptionStruct es;
916 es.type = SALOME::BAD_PARAM;
917 es.text = "Invalid case";
918 throw SALOME::SALOME_Exception(es);
922 if (myIteration0 == NULL) {
923 SALOME::ExceptionStruct es;
924 es.type = SALOME::BAD_PARAM;
925 es.text = "Invalid iteration";
926 throw SALOME::SALOME_Exception(es);
929 HOMARD_Cas_i* aCaseImpl = SMESH::DownCast<HOMARD_Cas_i*>(myCase);
930 aCaseImpl->AddIteration(myIteration0->GetName());
933 if (myIteration1 == NULL) {
934 SALOME::ExceptionStruct es;
935 es.type = SALOME::BAD_PARAM;
936 es.text = "Invalid iteration";
937 throw SALOME::SALOME_Exception(es);
940 HOMARD_Cas_i* aCaseImpl = SMESH::DownCast<HOMARD_Cas_i*>(myCase);
941 aCaseImpl->AddIteration(myIteration1->GetName());
945 //=============================================================================
946 //=============================================================================
947 // Recuperation des listes
948 //=============================================================================
949 //=============================================================================
950 SMESHHOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
952 MESSAGE("GetAllBoundarysName");
954 SMESHHOMARD::listeBoundarys_var ret = new SMESHHOMARD::listeBoundarys;
955 ret->length(_mesBoundarys.size());
956 std::map<std::string, SMESHHOMARD::HOMARD_Boundary_var>::const_iterator it;
958 for (it = _mesBoundarys.begin();
959 it != _mesBoundarys.end(); it++) {
960 ret[i++] = CORBA::string_dup((*it).first.c_str());
966 //=============================================================================
967 //=============================================================================
968 // Recuperation des structures identifiees par leurs noms
969 //=============================================================================
970 //=============================================================================
971 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
973 SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[nomBoundary];
974 ASSERT(!CORBA::is_nil(myBoundary));
975 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
977 //=============================================================================
978 SMESHHOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase()
980 ASSERT(!CORBA::is_nil(myCase));
981 return SMESHHOMARD::HOMARD_Cas::_duplicate(myCase);
983 //=============================================================================
984 HOMARD_Iteration_i* HOMARD_Gen_i::GetIteration(int numIter)
987 ASSERT(myIteration0);
991 ASSERT(myIteration1);
995 //=============================================================================
996 //=============================================================================
997 // Nouvelles structures
998 //=============================================================================
999 //=============================================================================
1000 SMESHHOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1002 SMESHHOMARD::HOMARD_Gen_var engine = POA_SMESHHOMARD::HOMARD_Gen::_this();
1003 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(engine);
1004 SMESHHOMARD::HOMARD_Cas_var aCase = SMESHHOMARD::HOMARD_Cas::_narrow(aServant->_this());
1005 return aCase._retn();
1007 //=============================================================================
1008 HOMARD_Iteration_i* HOMARD_Gen_i::newIteration()
1010 SMESHHOMARD::HOMARD_Gen_var engine = POA_SMESHHOMARD::HOMARD_Gen::_this();
1011 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(engine);
1014 //=============================================================================
1015 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1017 SMESHHOMARD::HOMARD_Gen_var engine = POA_SMESHHOMARD::HOMARD_Gen::_this();
1018 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(engine);
1019 SMESHHOMARD::HOMARD_Boundary_var aBoundary =
1020 SMESHHOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1021 return aBoundary._retn();
1024 //=============================================================================
1025 // Creation of a case
1026 // MeshName : name of the mesh
1027 // smeshMesh : correspondent mesh
1028 // theWorkingDir : path to working directory
1029 //=============================================================================
1030 SMESHHOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseOnMesh (const char* MeshName,
1031 SMESH::SMESH_Mesh_ptr smeshMesh,
1032 const char* theWorkingDir)
1034 INFOS("CreateCaseOnMesh");
1037 // A.1. Controle du nom :
1038 if (!myCase->_is_nil()) {
1042 // A.2. Controle du objet maillage
1043 if (CORBA::is_nil(smeshMesh)) {
1044 SALOME::ExceptionStruct es;
1045 es.type = SALOME::BAD_PARAM;
1046 es.text = "The mesh object is null.";
1047 throw SALOME::SALOME_Exception(es);
1049 MESSAGE("CreateCaseOnMesh : smeshMesh is not nil");
1051 // A.3. Write mesh object in a temporary file in the working directory
1052 std::string aTmpMeshFile = theWorkingDir;
1053 aTmpMeshFile = theWorkingDir;
1054 aTmpMeshFile += std::string("/") + std::string(MeshName) + "_saved_from_SMESH";
1055 _TmpMeshFile = aTmpMeshFile + ".med";
1056 SMESH_File aFile (_TmpMeshFile, false);
1057 for (int ii = 1; aFile.exists(); ii++) {
1058 _TmpMeshFile = aTmpMeshFile + std::string("_") + std::to_string(ii) + ".med";
1059 aFile = SMESH_File(_TmpMeshFile, false);
1061 const char* MeshFile = _TmpMeshFile.c_str();
1062 bool toOverwrite = true;
1063 bool toFindOutDim = true;
1065 // Prevent dump of ExportMED
1067 SMESH::TPythonDump pDump; // do not delete this line of code
1068 smeshMesh->ExportMED(MeshFile, false, -1, toOverwrite, toFindOutDim);
1071 // A.4. Controle du fichier du maillage
1072 med_idt medIdt = MEDfileOpen(MeshFile, MED_ACC_RDONLY);
1073 bool existeMeshFile = medIdt >= 0;
1074 if (existeMeshFile) MEDfileClose(medIdt);
1075 MESSAGE("CreateCaseOnMesh : existeMeshFile = " << existeMeshFile);
1076 if (!existeMeshFile) {
1077 SALOME::ExceptionStruct es;
1078 es.type = SALOME::BAD_PARAM;
1079 es.text = "The mesh file does not exist.";
1080 throw SALOME::SALOME_Exception(es);
1083 // B. Creation de l'objet cas
1085 _CaseOnMedFile = false;
1086 _SmeshMesh = SMESH::SMESH_Mesh::_duplicate(smeshMesh);
1088 // C. Caracteristiques du maillage
1089 if (existeMeshFile) {
1090 // Les valeurs extremes des coordonnées
1091 //MESSAGE ("CreateCaseOnMesh : Les valeurs extremes des coordonnées");
1092 std::vector<double> LesExtremes = GetBoundingBoxInMedFile(MeshFile);
1093 SMESHHOMARD::extrema_var aSeq = new SMESHHOMARD::extrema();
1094 if (LesExtremes.size() != 10) { return 0; }
1096 for (unsigned int i = 0; i < LesExtremes.size(); i++)
1097 aSeq[i] = LesExtremes[i];
1098 myCase->SetBoundingBox(aSeq);
1100 //MESSAGE ("CreateCaseOnMesh : Les groupes");
1101 std::set<std::string> LesGroupes = GetListeGroupesInMedFile(MeshFile);
1102 SMESHHOMARD::ListGroupType_var aSeqGroupe = new SMESHHOMARD::ListGroupType;
1103 aSeqGroupe->length(LesGroupes.size());
1104 std::set<std::string>::const_iterator it;
1106 for (it = LesGroupes.begin(); it != LesGroupes.end(); it++)
1107 aSeqGroupe[i++] = (*it).c_str();
1108 myCase->SetGroups(aSeqGroupe);
1111 // D. L'iteration initiale du cas
1112 MESSAGE ("CreateCaseOnMesh : iteration initiale du cas");
1113 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1114 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1115 MESSAGE("CreateCaseOnMesh : ==> NomIteration = " << MeshName);
1117 // D.2. Creation de l'iteration 0
1118 myIteration0 = newIteration();
1119 myIteration0->SetName(MeshName);
1120 AssociateCaseIter(0, "IterationHomard");
1122 // D.4. Maillage correspondant
1123 if (existeMeshFile) {
1124 myIteration0->SetMeshFile(MeshFile);
1126 myIteration0->SetMeshName(MeshName);
1127 myIteration0->SetNumber(0);
1128 myIteration0->SetState(0);
1130 // Only after full initialization of Iteration0
1131 myCase->SetDirName(theWorkingDir);
1133 return SMESHHOMARD::HOMARD_Cas::_duplicate(myCase);
1136 //=============================================================================
1137 // Creation of a case
1138 // MeshName : name of the mesh
1139 // MeshFile : med file
1140 // theWorkingDir : path to working directory
1141 //=============================================================================
1142 SMESHHOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* MeshName,
1143 const char* MeshFile,
1144 const char* theWorkingDir)
1146 INFOS("CreateCase : MeshName = " << MeshName << ", MeshFile = " << MeshFile);
1149 // A.1. Controle du nom :
1150 if (!myCase->_is_nil()) {
1154 // A.3. Controle du fichier du maillage
1155 med_idt medIdt = MEDfileOpen(MeshFile, MED_ACC_RDONLY);
1156 bool existeMeshFile = medIdt >= 0;
1157 if (existeMeshFile) MEDfileClose(medIdt);
1158 MESSAGE("CreateCase : existeMeshFile = " << existeMeshFile);
1159 if (!existeMeshFile) {
1160 SALOME::ExceptionStruct es;
1161 es.type = SALOME::BAD_PARAM;
1162 es.text = "The mesh file does not exist.";
1163 throw SALOME::SALOME_Exception(es);
1166 // B. Creation de l'objet cas
1168 _CaseOnMedFile = true;
1170 // C. Caracteristiques du maillage
1171 if (existeMeshFile) {
1172 // Les valeurs extremes des coordonnées
1173 //MESSAGE ("CreateCase : Les valeurs extremes des coordonnées");
1174 std::vector<double> LesExtremes = GetBoundingBoxInMedFile(MeshFile);
1175 SMESHHOMARD::extrema_var aSeq = new SMESHHOMARD::extrema();
1176 if (LesExtremes.size() != 10) { return 0; }
1178 for (unsigned int i = 0; i < LesExtremes.size(); i++)
1179 aSeq[i] = LesExtremes[i];
1180 myCase->SetBoundingBox(aSeq);
1182 //MESSAGE ("CreateCase : Les groupes");
1183 std::set<std::string> LesGroupes = GetListeGroupesInMedFile(MeshFile);
1184 SMESHHOMARD::ListGroupType_var aSeqGroupe = new SMESHHOMARD::ListGroupType;
1185 aSeqGroupe->length(LesGroupes.size());
1186 std::set<std::string>::const_iterator it;
1188 for (it = LesGroupes.begin(); it != LesGroupes.end(); it++)
1189 aSeqGroupe[i++] = (*it).c_str();
1190 myCase->SetGroups(aSeqGroupe);
1193 // D. L'iteration initiale du cas
1194 MESSAGE ("CreateCase : iteration initiale du cas");
1195 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1196 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1197 MESSAGE("CreateCas : ==> NomIteration = " << MeshName);
1199 // D.2. Creation de l'iteration
1200 myIteration0 = newIteration();
1201 myIteration0->SetName(MeshName);
1202 AssociateCaseIter(0, "IterationHomard");
1204 // D.4. Maillage correspondant
1205 if (existeMeshFile) {
1206 myIteration0->SetMeshFile(MeshFile);
1208 myIteration0->SetMeshName(MeshName);
1209 myIteration0->SetNumber(0);
1210 myIteration0->SetState(0);
1212 // Only after full initialization of Iteration0
1213 myCase->SetDirName(theWorkingDir);
1215 return SMESHHOMARD::HOMARD_Cas::_duplicate(myCase);
1218 //=============================================================================
1219 // Create Iteration1
1220 //=============================================================================
1221 HOMARD_Iteration_i* HOMARD_Gen_i::CreateIteration()
1223 if (myIteration0 == NULL) {
1224 SALOME::ExceptionStruct es;
1225 es.type = SALOME::BAD_PARAM;
1226 es.text = "The parent iteration is not defined.";
1227 throw SALOME::SALOME_Exception(es);
1230 if (CORBA::is_nil(myCase)) {
1231 SALOME::ExceptionStruct es;
1232 es.type = SALOME::BAD_PARAM;
1233 es.text = "Invalid case context";
1234 throw SALOME::SALOME_Exception(es);
1236 const char* nomDirCase = myCase->GetDirName();
1238 if (myIteration1 != NULL) {
1242 myIteration1 = newIteration();
1243 if (myIteration1 == NULL) {
1244 SALOME::ExceptionStruct es;
1245 es.type = SALOME::BAD_PARAM;
1246 es.text = "Unable to create the iteration 1";
1247 throw SALOME::SALOME_Exception(es);
1250 // Nom de l'iteration et du maillage
1251 myIteration1->SetName("Iter_1");
1252 myIteration1->SetMeshName("Iter_1");
1253 myIteration1->SetState(1);
1254 myIteration1->SetNumber(1);
1257 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase);
1258 myIteration1->SetDirNameLoc(nomDirIter);
1260 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1261 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1262 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1263 // situation la plus frequente.
1264 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1265 // le nombre d'iterations du cas permet d'eviter les collisions.
1267 if (nbitercase < 100) { jaux = 2; }
1268 else if (nbitercase < 1000) { jaux = 3; }
1269 else if (nbitercase < 10000) { jaux = 4; }
1270 else if (nbitercase < 100000) { jaux = 5; }
1272 std::ostringstream iaux;
1273 iaux << std::setw(jaux) << std::setfill('0') << nbitercase;
1274 std::stringstream MeshFile;
1275 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1276 myIteration1->SetMeshFile(MeshFile.str().c_str());
1278 // Association avec le cas
1279 std::string nomIterParent = myIteration0->GetName();
1280 std::string label = "IterationHomard_" + nomIterParent;
1281 AssociateCaseIter(1, label.c_str());
1283 return myIteration1;
1285 //=============================================================================
1286 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName,
1287 CORBA::Long BoundaryType)
1289 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName <<
1290 ", BoundaryType = " << BoundaryType);
1292 // Controle du nom :
1293 if ((_mesBoundarys).find(BoundaryName) != (_mesBoundarys).end()) {
1294 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1295 SALOME::ExceptionStruct es;
1296 es.type = SALOME::BAD_PARAM;
1297 es.text = "This boundary has already been defined";
1298 throw SALOME::SALOME_Exception(es);
1301 SMESHHOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1302 myBoundary->SetName(BoundaryName);
1303 myBoundary->SetType(BoundaryType);
1305 _mesBoundarys[BoundaryName] = myBoundary;
1307 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1309 //=============================================================================
1310 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCAO(const char* BoundaryName, const char* CAOFile)
1312 MESSAGE ("CreateBoundaryCAO : BoundaryName = " << BoundaryName << ", CAOFile = " << CAOFile);
1313 SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, -1);
1314 myBoundary->SetDataFile(CAOFile);
1316 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1318 //=============================================================================
1319 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1321 MESSAGE ("CreateBoundaryDi : BoundaryName = " << BoundaryName << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile);
1322 SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1323 myBoundary->SetDataFile(MeshFile);
1324 myBoundary->SetMeshName(MeshName);
1326 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1328 //=============================================================================
1329 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1330 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1331 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1332 CORBA::Double Rayon)
1334 MESSAGE ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName);
1336 SALOME::ExceptionStruct es;
1339 { es.text = "The radius must be positive.";
1341 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe);
1342 if (daux < 0.0000001)
1343 { es.text = "The axis must be a non 0 vector.";
1347 es.type = SALOME::BAD_PARAM;
1348 throw SALOME::SALOME_Exception(es);
1352 SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1);
1353 myBoundary->SetCylinder(Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon);
1355 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1357 //=============================================================================
1358 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1359 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1360 CORBA::Double Rayon)
1362 MESSAGE ("CreateBoundarySphere : BoundaryName = " << BoundaryName);
1364 SALOME::ExceptionStruct es;
1367 { es.text = "The radius must be positive.";
1371 es.type = SALOME::BAD_PARAM;
1372 throw SALOME::SALOME_Exception(es);
1376 SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2);
1377 myBoundary->SetSphere(Xcentre, Ycentre, Zcentre, Rayon);
1379 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1381 //=============================================================================
1382 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1383 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1384 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1386 MESSAGE ("CreateBoundaryConeA : BoundaryName = " << BoundaryName);
1388 SALOME::ExceptionStruct es;
1390 if (Angle <= 0.0 || Angle >= 90.0)
1391 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees.";
1393 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe);
1394 if (daux < 0.0000001)
1395 { es.text = "The axis must be a non 0 vector.";
1399 es.type = SALOME::BAD_PARAM;
1400 throw SALOME::SALOME_Exception(es);
1404 SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3);
1405 myBoundary->SetConeA(Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre);
1407 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1409 //=============================================================================
1410 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
1411 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
1412 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
1414 MESSAGE ("CreateBoundaryConeR : BoundaryName = " << BoundaryName);
1416 SALOME::ExceptionStruct es;
1418 if (Rayon1 < 0.0 || Rayon2 < 0.0)
1419 { es.text = "The radius must be positive.";
1421 double daux = fabs(Rayon2-Rayon1);
1422 if (daux < 0.0000001)
1423 { es.text = "The radius must be different.";
1425 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1);
1426 if (daux < 0.0000001)
1427 { es.text = "The centers must be different.";
1431 es.type = SALOME::BAD_PARAM;
1432 throw SALOME::SALOME_Exception(es);
1436 SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4);
1437 myBoundary->SetConeR(Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2);
1439 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1441 //=============================================================================
1442 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
1443 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1444 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1445 CORBA::Double RayonRev, CORBA::Double RayonPri)
1447 MESSAGE ("CreateBoundaryTorus : BoundaryName = " << BoundaryName);
1449 SALOME::ExceptionStruct es;
1451 if ((RayonRev <= 0.0) || (RayonPri <= 0.0))
1452 { es.text = "The radius must be positive.";
1454 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe);
1455 if (daux < 0.0000001)
1456 { es.text = "The axis must be a non 0 vector.";
1460 es.type = SALOME::BAD_PARAM;
1461 throw SALOME::SALOME_Exception(es);
1465 SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5);
1466 myBoundary->SetTorus(Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri);
1468 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1471 //=============================================================================
1472 //=============================================================================
1473 CORBA::Long HOMARD_Gen_i::Compute()
1479 // A.0. Create Iteration 1
1481 myIteration1->SetInfoCompute(_VerboseLevel);
1482 myIteration1->SetMeshName(_MeshNameOUT.c_str());
1483 myIteration1->SetMeshFile(_MeshFileOUT.c_str());
1484 if (_LogInFile) myIteration1->SetLogFile(_LogFile.c_str());
1486 // A.1. L'objet iteration
1487 ASSERT(myIteration1);
1489 // A.2. Controle de la possibilite d'agir
1490 // A.2.1. Etat de l'iteration
1491 int etat = myIteration1->GetState();
1492 MESSAGE ("etat = " << etat);
1493 // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
1495 SALOME::ExceptionStruct es;
1496 es.type = SALOME::BAD_PARAM;
1497 es.text = "This iteration is already computed.";
1498 throw SALOME::SALOME_Exception(es);
1501 // A.3. Numero de l'iteration
1502 // siterp1 : numero de l'iteration a traiter
1504 // siter: numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
1505 // Ou si information :
1507 int NumeIter = myIteration1->GetNumber();
1508 std::string siterp1;
1509 std::stringstream saux1;
1511 siterp1 = saux1.str();
1512 if (NumeIter < 10) { siterp1 = "0" + siterp1; }
1515 std::stringstream saux0;
1516 int iaux = max(0, NumeIter-1);
1518 siter = saux0.str();
1519 if (NumeIter < 11) { siter = "0" + siter; }
1522 ASSERT(!CORBA::is_nil(myCase));
1524 // B. Les répertoires
1525 // B.1. Le répertoire courant
1526 std::string nomDirWork = getenv("PWD");
1527 // B.2. Le sous-répertoire de l'iteration a traiter
1528 char* DirCompute = ComputeDirManagement();
1529 MESSAGE(". DirCompute = " << DirCompute);
1531 // C. Le fichier des messages
1532 // C.1. Le deroulement de l'execution de HOMARD
1533 std::string LogFile = myIteration1->GetLogFile();
1534 if (LogFile.empty()) {
1535 LogFile = DirCompute;
1536 LogFile += "/Liste." + siter + ".vers." + siterp1 + ".log";
1537 myIteration1->SetLogFile(LogFile.c_str());
1539 MESSAGE (". LogFile = " << LogFile);
1540 // C.2. Le bilan de l'analyse du maillage
1541 std::string FileInfo = DirCompute;
1542 FileInfo += "/apad." + siterp1 + ".bilan";
1543 myIteration1->SetFileInfo(FileInfo.c_str());
1545 // D. On passe dans le répertoire de l'iteration a calculer
1546 MESSAGE (". On passe dans DirCompute = " << DirCompute);
1549 // E. Les données de l'exécution HOMARD
1550 // E.1. L'objet du texte du fichier de configuration
1551 SMESHHOMARDImpl::HomardDriver* myDriver = new SMESHHOMARDImpl::HomardDriver(siter, siterp1);
1552 myDriver->TexteInit(DirCompute, LogFile, "English");
1554 // E.2. Le maillage associe a l'iteration
1555 const char* NomMesh = myIteration1->GetMeshName();
1556 MESSAGE (". NomMesh = " << NomMesh);
1557 const char* MeshFile = myIteration1->GetMeshFile();
1558 MESSAGE (". MeshFile = " << MeshFile);
1560 // E.3. Les données du traitement HOMARD
1562 myDriver->TexteMaillageHOMARD(DirCompute, siterp1, iaux);
1563 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
1564 codret = ComputeAdap(myDriver);
1566 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
1567 int BoundaryOption = DriverTexteBoundary(myDriver);
1569 // E.5. Ecriture du texte dans le fichier
1570 MESSAGE (". Ecriture du texte dans le fichier de configuration; codret = "<<codret);
1572 { myDriver->CreeFichier(); }
1576 int codretexec = 1789;
1578 codretexec = myDriver->ExecuteHomard();
1580 MESSAGE ("Erreur en executant HOMARD : " << codretexec);
1581 // En mode adaptation, on ajuste l'etat de l'iteration
1582 if (codretexec == 0) { myIteration1->SetState(2); }
1583 else { myIteration1->SetState(1); }
1586 // H. Gestion des resultats
1588 std::string Commentaire;
1589 // H.1. Le fichier des messages, dans tous les cas
1590 Commentaire = "log";
1591 Commentaire += " " + siterp1;
1593 // H.2. Si tout s'est bien passe :
1594 if (codretexec == 0) {
1595 // H.2.1. Le fichier de bilan
1596 Commentaire = "Summary";
1597 Commentaire += " " + siterp1;
1598 // H.2.2. Le fichier de maillage obtenu
1599 std::stringstream saux0;
1600 Commentaire = "Mesh";
1601 Commentaire += " " + siterp1;
1602 if (_PublishMeshOUT) PublishResultInSmesh(MeshFile);
1604 // H.3 Message d'erreur
1605 if (codretexec != 0) {
1606 std::string text = "";
1607 // Message d'erreur en cas de probleme en adaptation
1608 text = "Error during the adaptation.\n";
1609 bool stopvu = false;
1610 std::ifstream fichier(LogFile.c_str());
1611 if (fichier) { // ce test échoue si le fichier n'est pas ouvert
1612 std::string ligne; // variable contenant chaque ligne lue
1613 while (std::getline(fichier, ligne)) {
1615 if (stopvu) { text += ligne+ "\n"; }
1617 int position = ligne.find("===== HOMARD ===== STOP =====");
1618 if (position > 0) { stopvu = true; }
1622 text += "\n\nSee the file " + LogFile + "\n";
1624 SALOME::ExceptionStruct es;
1625 es.type = SALOME::BAD_PARAM;
1626 es.text = CORBA::string_dup(text.c_str());
1627 throw SALOME::SALOME_Exception(es);
1631 // I. Menage et retour dans le répertoire du cas
1634 MESSAGE (". On retourne dans nomDirWork = " << nomDirWork);
1635 CHDIR(nomDirWork.c_str());
1638 // J. Suivi de la frontière CAO
1640 if ((BoundaryOption % 5 == 0) && (codretexec == 0)) {
1641 MESSAGE ("Suivi de frontière CAO");
1642 codret = ComputeCAO();
1646 if (codretexec == 0) {
1650 // Delete log file, if required
1651 if (myIteration1 != NULL) {
1652 MESSAGE("myIteration1->GetLogFile() = " << myIteration1->GetLogFile());
1653 if (_LogInFile && _RemoveLogOnSuccess) {
1654 // Remove log file on success
1655 SMESH_File(myIteration1->GetLogFile(), false).remove();
1666 void HOMARD_Gen_i::DeleteCase()
1668 MESSAGE ("DeleteCase");
1669 if (myCase->_is_nil()) return;
1671 // Delete all boundaries
1672 _mesBoundarys.clear();
1674 // Delete iterations
1679 myCase = SMESHHOMARD::HOMARD_Cas::_nil();
1681 // Delete tmp mesh file
1682 if (!_CaseOnMedFile && !_TmpMeshFile.empty()) {
1683 SMESH_File aFile (_TmpMeshFile, false);
1684 if (aFile.exists()) aFile.remove();
1687 _SmeshMesh = SMESH::SMESH_Mesh::_nil();
1690 //=============================================================================
1691 // Calcul d'une iteration : partie spécifique à l'adaptation
1692 //=============================================================================
1693 CORBA::Long HOMARD_Gen_i::ComputeAdap(SMESHHOMARDImpl::HomardDriver* myDriver)
1695 MESSAGE ("ComputeAdap");
1700 // Numero de l'iteration
1702 std::stringstream saux0;
1703 saux0 << NumeIter-1;
1704 std::string siter = saux0.str();
1705 if (NumeIter < 11) { siter = "0" + siter; }
1707 // B. L'iteration parent
1708 ASSERT(myIteration0);
1710 // C. Le sous-répertoire de l'iteration precedente
1711 char* DirComputePa = ComputeDirPaManagement();
1712 MESSAGE(". DirComputePa = " << DirComputePa);
1714 // D. Les données de l'adaptation HOMARD
1715 // D.1. Le type de conformite
1716 MESSAGE (". ConfType = " << _ConfType);
1718 // D.3. Le maillage de depart
1719 const char* NomMeshParent = myIteration0->GetMeshName();
1720 MESSAGE (". NomMeshParent = " << NomMeshParent);
1721 const char* MeshFileParent = myIteration0->GetMeshFile();
1722 MESSAGE (". MeshFileParent = " << MeshFileParent);
1724 // D.4. Le maillage associe a l'iteration
1725 const char* MeshFile = myIteration1->GetMeshFile();
1726 MESSAGE (". MeshFile = " << MeshFile);
1727 FILE *file = fopen(MeshFile,"r");
1730 // CleanOption = 0 : report an error if output mesh file exists
1731 // CleanOption = 1 : destruction du répertoire d'execution
1732 int CleanOption = 1;
1733 if (CleanOption == 0) {
1734 SALOME::ExceptionStruct es;
1735 es.type = SALOME::BAD_PARAM;
1736 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
1737 es.text = CORBA::string_dup(text.c_str());
1738 throw SALOME::SALOME_Exception(es);
1741 std::string commande = "rm -f " + std::string(MeshFile);
1742 codret = system(commande.c_str());
1744 SALOME::ExceptionStruct es;
1745 es.type = SALOME::BAD_PARAM;
1746 es.text = "The mesh file cannot be deleted.";
1747 throw SALOME::SALOME_Exception(es);
1752 // E. Texte du fichier de configuration
1753 // E.1. Incontournables du texte
1754 myDriver->TexteAdap();
1756 myDriver->TexteMaillageHOMARD(DirComputePa, siter, iaux);
1757 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
1758 myDriver->TexteConfRaffDera(_ConfType);
1760 // E.6. Ajout des options avancees
1761 //myDriver->TexteAdvanced(NivMax, DiamMin, AdapInit, ExtraOutput);
1762 myDriver->TexteAdvanced(-1, -1.0, 0, 1);
1764 // E.7. Ajout des informations sur le deroulement de l'execution
1765 int MessInfo = myIteration1->GetInfoCompute();
1766 MESSAGE (". MessInfo = " << MessInfo);
1767 myDriver->TexteInfoCompute(MessInfo);
1771 //=============================================================================
1772 // Calcul d'une iteration : partie spécifique au suivi de frontière CAO
1773 //=============================================================================
1774 CORBA::Long HOMARD_Gen_i::ComputeCAO()
1776 MESSAGE ("ComputeCAO");
1781 // A.2. Le sous-répertoire de l'iteration en cours de traitement
1782 char* DirCompute = myIteration1->GetDirName();
1783 // A.3. Le maillage résultat de l'iteration en cours de traitement
1784 char* MeshFile = myIteration1->GetMeshFile();
1786 // B. Les données pour FrontTrack
1787 // B.1. Le maillage à modifier
1788 const std::string theInputMedFile = MeshFile;
1789 MESSAGE (". theInputMedFile = " << theInputMedFile);
1791 // B.2. Le maillage après modification : fichier identique
1792 const std::string theOutputMedFile = MeshFile;
1793 MESSAGE (". theOutputMedFile = " << theInputMedFile);
1795 // B.3. La liste des fichiers contenant les numéros des noeuds à bouger
1796 std::vector< std::string > theInputNodeFiles;
1797 MESSAGE (". DirCompute = " << DirCompute);
1798 std::basic_string<char>::size_type bilan;
1802 struct dirent *dirp;
1803 dp = opendir(DirCompute);
1804 while ((dirp = readdir(dp)) != NULL)
1806 std::string file_name(dirp->d_name);
1807 bilan = file_name.find("fr");
1808 if (bilan != string::npos)
1810 std::stringstream filename_total;
1811 filename_total << DirCompute << "/" << file_name;
1812 theInputNodeFiles.push_back(filename_total.str());
1817 HANDLE hFind = INVALID_HANDLE_VALUE;
1818 WIN32_FIND_DATA ffd;
1819 hFind = FindFirstFile(DirNameStart, &ffd);
1820 if (INVALID_HANDLE_VALUE != hFind) {
1821 while (FindNextFile(hFind, &ffd) != 0) {
1822 std::string file_name(ffd.cFileName);
1823 bilan = file_name.find("fr");
1824 if (bilan != string::npos)
1826 std::stringstream filename_total;
1827 filename_total << DirCompute << "/" << file_name;
1828 theInputNodeFiles.push_back(filename_total.str());
1835 for (int i = 0; i < icpt; i++)
1836 { MESSAGE (". theInputNodeFiles["<< i << "] = " << theInputNodeFiles[i]); }
1838 // B.4. Le fichier de la CAO
1839 SMESHHOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
1840 std::string BoundaryName = std::string((*ListBoundaryGroupType)[0]);
1841 MESSAGE (". BoundaryName = " << BoundaryName);
1842 SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[BoundaryName];
1843 const std::string theXaoFileName = myBoundary->GetDataFile();
1844 MESSAGE (". theXaoFileName = " << theXaoFileName);
1846 // C. Lancement des projections
1847 MESSAGE (". Lancement des projections");
1849 assert(Py_IsInitialized());
1850 PyGILState_STATE gstate;
1851 gstate = PyGILState_Ensure();
1852 PyRun_SimpleString("from FrontTrack import FrontTrack");
1853 // FrontTrack().track( fic_med_brut, fic_med_new, l_fr, xao_file )
1854 std::string pyCommand ("FrontTrack().track( \"");
1855 pyCommand += theInputMedFile + "\", \"" + theOutputMedFile + "\", [";
1856 for (int i = 0; i < icpt; i++) {
1857 if (i > 0) pyCommand += ", ";
1859 pyCommand += theInputNodeFiles[i];
1862 pyCommand += "], \"" + theXaoFileName + "\", False )";
1863 MESSAGE (". Lancement des projections: pyCommand = " << pyCommand);
1864 PyRun_SimpleString(pyCommand.c_str());
1865 PyGILState_Release(gstate);
1867 // D. Transfert des coordonnées modifiées dans le fichier historique de HOMARD
1868 // On lance une exécution spéciale de HOMARD en attendant
1869 // de savoir le faire avec MEDCoupling
1870 MESSAGE (". Transfert des coordonnées");
1871 codret = ComputeCAObis();
1875 //=============================================================================
1876 //=============================================================================
1877 // Transfert des coordonnées en suivi de frontière CAO
1878 //=============================================================================
1879 CORBA::Long HOMARD_Gen_i::ComputeCAObis()
1881 MESSAGE ("ComputeCAObis");
1886 // A.1. Controle de la possibilite d'agir
1887 // A.1.1. Etat de l'iteration
1888 int etat = myIteration1->GetState();
1889 MESSAGE ("etat = " << etat);
1890 // A.1.2. L'iteration doit être calculee
1892 SALOME::ExceptionStruct es;
1893 es.type = SALOME::BAD_PARAM;
1894 es.text = "This iteration is not computed.";
1895 throw SALOME::SALOME_Exception(es);
1898 // A.2. Numero de l'iteration
1899 // siterp1 : numero de l'iteration a traiter
1900 int NumeIter = myIteration1->GetNumber();
1901 std::string siterp1;
1902 std::stringstream saux1;
1904 siterp1 = saux1.str();
1905 if (NumeIter < 10) { siterp1 = "0" + siterp1; }
1906 MESSAGE ("siterp1 = "<<siterp1);
1909 ASSERT(!CORBA::is_nil(myCase));
1911 // A.4. Le sous-répertoire de l'iteration a traiter
1912 char* DirCompute = myIteration1->GetDirName();
1913 MESSAGE(". DirCompute = " << DirCompute);
1915 // C. Le fichier des messages
1916 std::string LogFile = DirCompute;
1917 LogFile += "/Liste." + siterp1 + ".maj_coords.log";
1918 MESSAGE (". LogFile = " << LogFile);
1919 myIteration1->SetFileInfo(LogFile.c_str());
1921 // D. On passe dans le répertoire de l'iteration a calculer
1922 MESSAGE (". On passe dans DirCompute = " << DirCompute);
1925 // E. Les données de l'exécution HOMARD
1926 // E.1. L'objet du texte du fichier de configuration
1927 SMESHHOMARDImpl::HomardDriver* myDriver = new SMESHHOMARDImpl::HomardDriver("", siterp1);
1928 myDriver->TexteInit(DirCompute, LogFile, "English");
1930 // E.2. Le maillage associe a l'iteration
1931 const char* NomMesh = myIteration1->GetMeshName();
1932 MESSAGE (". NomMesh = " << NomMesh);
1933 const char* MeshFile = myIteration1->GetMeshFile();
1934 MESSAGE (". MeshFile = " << MeshFile);
1936 // E.3. Les données du traitement HOMARD
1937 myDriver->TexteMajCoords(NumeIter);
1939 myDriver->TexteMaillageHOMARD(DirCompute, siterp1, iaux);
1940 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
1942 // E.4. Ecriture du texte dans le fichier
1943 MESSAGE (". Ecriture du texte dans le fichier de configuration; codret = "<<codret);
1944 if (codret == 0) myDriver->CreeFichier();
1948 int codretexec = 1789;
1950 codretexec = myDriver->ExecuteHomard();
1951 MESSAGE ("Erreur en executant HOMARD : " << codretexec);
1954 // G. Gestion des resultats
1956 // G.1. Le fichier des messages, dans tous les cas
1957 std::string Commentaire = "logmaj_coords";
1958 // G.2 Message d'erreur
1959 if (codretexec != 0) {
1960 std::string text = "\n\nSee the file " + LogFile + "\n";
1962 SALOME::ExceptionStruct es;
1963 es.type = SALOME::BAD_PARAM;
1964 es.text = CORBA::string_dup(text.c_str());
1965 throw SALOME::SALOME_Exception(es);
1967 // On force le succes pour pouvoir consulter le fichier log
1972 // H. Menage et retour dans le répertoire du cas
1973 if (codret == 0) { delete myDriver; }
1977 //=============================================================================
1978 // Creation d'un nom de sous-répertoire pour l'iteration au sein d'un répertoire parent
1979 // nomrep : nom du répertoire parent
1980 // num : le nom du sous-répertoire est sous la forme 'In', n est >= num
1981 //=============================================================================
1982 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num)
1984 MESSAGE ("CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
1985 // On verifie que le répertoire parent existe
1986 int codret = CHDIR(nomrep);
1988 SALOME::ExceptionStruct es;
1989 es.type = SALOME::BAD_PARAM;
1990 es.text = "The directory of the case does not exist.";
1991 throw SALOME::SALOME_Exception(es);
1993 std::string nomDirActuel = getenv("PWD");
1994 std::string DirName;
1995 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un répertoire inconnu
1996 bool a_chercher = true;
1997 while (a_chercher) {
1998 // On passe dans le répertoire parent
2001 // On recherche un nom sous la forme Iabc, avec abc representant le numero
2003 if (num < 100) { jaux = 2; }
2004 else if (num < 1000) { jaux = 3; }
2005 else if (num < 10000) { jaux = 4; }
2006 else if (num < 100000) { jaux = 5; }
2008 std::ostringstream iaux;
2009 iaux << std::setw(jaux) << std::setfill('0') << num;
2010 std::ostringstream DirNameA;
2011 DirNameA << "I" << iaux.str();
2012 // Si on ne pas peut entrer dans le répertoire, on doit verifier
2013 // que c'est bien un probleme d'absence
2014 if (CHDIR(DirNameA.str().c_str()) != 0)
2016 bool existe = false;
2019 struct dirent *dirp;
2020 dp = opendir(nomrep);
2021 while ((dirp = readdir(dp)) != NULL)
2023 std::string file_name(dirp->d_name);
2025 HANDLE hFind = INVALID_HANDLE_VALUE;
2026 WIN32_FIND_DATA ffd;
2027 hFind = FindFirstFile(nomrep, &ffd);
2028 if (INVALID_HANDLE_VALUE != hFind) {
2029 while (FindNextFile(hFind, &ffd) != 0) {
2030 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2031 std::string file_name(ffd.cFileName);
2033 if (file_name == DirNameA.str()) { existe = true; }
2042 DirName = DirNameA.str();
2050 MESSAGE ("==> DirName = " << DirName);
2051 MESSAGE (". On retourne dans nomDirActuel = " << nomDirActuel);
2052 CHDIR(nomDirActuel.c_str());
2053 return CORBA::string_dup(DirName.c_str());
2055 //=============================================================================
2056 // Calcul d'une iteration : gestion du répertoire de calcul
2057 //=============================================================================
2058 char* HOMARD_Gen_i::ComputeDirManagement()
2060 MESSAGE ("ComputeDirManagement : répertoires pour le calcul");
2062 //Si le sous-répertoire existe :
2063 // CleanOption = 0 : on sort en erreur si le répertoire n'est pas vide
2064 // CleanOption = 1 : on fait le menage du répertoire
2065 // CleanOption = -1 : on ne fait rien
2066 int CleanOption = 0;
2068 // B.2. Le répertoire du cas
2069 const char* nomDirCase = myCase->GetDirName();
2070 MESSAGE (". nomDirCase = " << nomDirCase);
2072 // B.3. Le sous-répertoire de l'iteration a calculer, puis le répertoire complet a creer
2073 // B.3.1. Le nom du sous-répertoire
2074 const char* nomDirIt = myIteration1->GetDirNameLoc();
2076 // B.3.2. Le nom complet du sous-répertoire
2077 std::stringstream DirCompute;
2078 DirCompute << nomDirCase << "/" << nomDirIt;
2079 MESSAGE (". DirCompute = " << DirCompute.str());
2081 // B.3.3. Si le sous-répertoire n'existe pas, on le cree
2082 if (CHDIR(DirCompute.str().c_str()) != 0)
2085 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2087 if (_mkdir(DirCompute.str().c_str()) != 0)
2090 // GERALD -- QMESSAGE BOX
2091 std::cerr << "Pb Creation du répertoire DirCompute = " << DirCompute.str() << std::endl;
2092 VERIFICATION("Pb a la creation du répertoire" == 0);
2097 // Le répertoire existe
2098 // On demande de faire le menage de son contenu :
2099 if (CleanOption == 1) {
2100 MESSAGE (". Menage du répertoire DirCompute = " << DirCompute.str());
2101 std::string commande = "rm -rf " + DirCompute.str()+"/*";
2102 int codret = system(commande.c_str());
2105 // GERALD -- QMESSAGE BOX
2106 std::cerr << ". Menage du répertoire de calcul" << DirCompute.str() << std::endl;
2107 VERIFICATION("Pb au menage du répertoire de calcul" == 0);
2110 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2112 if (CleanOption == 0) {
2115 struct dirent *dirp;
2116 dp = opendir(DirCompute.str().c_str());
2118 while ((dirp = readdir(dp)) != NULL && result)
2120 std::string file_name(dirp->d_name);
2121 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2125 HANDLE hFind = INVALID_HANDLE_VALUE;
2126 WIN32_FIND_DATA ffd;
2127 hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
2129 if (INVALID_HANDLE_VALUE != hFind) {
2130 while (FindNextFile(hFind, &ffd) != 0) {
2131 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2132 std::string file_name(ffd.cFileName);
2133 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2138 if (result == false)
2140 SALOME::ExceptionStruct es;
2141 es.type = SALOME::BAD_PARAM;
2142 std::string text = "Directory : " + DirCompute.str() + " is not empty";
2143 es.text = CORBA::string_dup(text.c_str());
2144 throw SALOME::SALOME_Exception(es);
2145 VERIFICATION("Directory is not empty" == 0);
2151 return CORBA::string_dup(DirCompute.str().c_str());
2153 //=============================================================================
2154 // Calcul d'une iteration : gestion du répertoire de calcul de l'iteration parent
2155 //=============================================================================
2156 char* HOMARD_Gen_i::ComputeDirPaManagement()
2158 MESSAGE ("ComputeDirPaManagement : répertoires pour le calcul");
2159 // Le répertoire du cas
2160 const char* nomDirCase = myCase->GetDirName();
2161 MESSAGE (". nomDirCase = " << nomDirCase);
2163 // Le sous-répertoire de l'iteration precedente
2165 const char* nomDirItPa = myIteration0->GetDirNameLoc();
2166 std::stringstream DirComputePa;
2167 DirComputePa << nomDirCase << "/" << nomDirItPa;
2168 MESSAGE(". nomDirItPa = " << nomDirItPa);
2169 MESSAGE(". DirComputePa = " << DirComputePa.str());
2171 return CORBA::string_dup(DirComputePa.str().c_str());
2174 //=============================================================================
2175 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
2176 // On ecrit dans l'ordre :
2177 // 1. la definition des frontieres
2178 // 2. les liens avec les groupes
2179 // 3. un entier resumant le type de comportement pour les frontieres
2180 //=============================================================================
2181 int HOMARD_Gen_i::DriverTexteBoundary(SMESHHOMARDImpl::HomardDriver* myDriver)
2183 MESSAGE ("... DriverTexteBoundary");
2184 // 1. Recuperation des frontieres
2185 std::list<std::string> ListeBoundaryTraitees;
2186 SMESHHOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2187 int numberOfitems = ListBoundaryGroupType->length();
2188 MESSAGE ("... number of string for Boundary+Group = " << numberOfitems);
2189 int BoundaryOption = 1;
2190 // 2. Parcours des frontieres pour ecrire leur description
2191 int NumBoundaryAnalytical = 0;
2192 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2194 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2195 MESSAGE ("... BoundaryName = " << BoundaryName);
2196 // 2.1. La frontiere a-t-elle deja ete ecrite ?
2197 // Cela arrive quand elle est liee a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
2199 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
2200 while (it != ListeBoundaryTraitees.end())
2202 MESSAGE ("..... BoundaryNameTraitee = " << *it);
2203 if (BoundaryName == *it) { A_faire = 0; }
2206 // 2.2. Ecriture de la frontiere
2209 // 2.2.1. Caracteristiques de la frontiere
2210 SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[BoundaryName];
2211 ASSERT(!CORBA::is_nil(myBoundary));
2212 int BoundaryType = myBoundary->GetType();
2213 MESSAGE ("... BoundaryType = " << BoundaryType);
2214 // 2.2.2. Ecriture selon le type
2215 // 2.2.2.1. Cas d une frontiere CAO
2216 if (BoundaryType == -1)
2218 // const char* CAOFile = myBoundary->GetDataFile();
2219 // MESSAGE (". CAOFile = " << CAOFile);
2220 if (BoundaryOption % 5 != 0) { BoundaryOption = BoundaryOption*5; }
2222 // 2.2.2.2. Cas d une frontiere discrete
2223 else if (BoundaryType == 0)
2225 const char* MeshName = myBoundary->GetMeshName();
2226 MESSAGE (". MeshName = " << MeshName);
2227 const char* MeshFile = myBoundary->GetDataFile();
2228 MESSAGE (". MeshFile = " << MeshFile);
2229 myDriver->TexteBoundaryDi(MeshName, MeshFile);
2230 if (BoundaryOption % 2 != 0) { BoundaryOption = BoundaryOption*2; }
2232 // 2.2.2.3. Cas d une frontiere analytique
2235 NumBoundaryAnalytical++;
2236 SMESHHOMARD::double_array* coor = myBoundary->GetCoords();
2237 if (BoundaryType == 1) // Cas d un cylindre
2239 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2240 if (BoundaryOption % 3 != 0) { BoundaryOption = BoundaryOption*3; }
2242 else if (BoundaryType == 2) // Cas d une sphere
2244 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
2245 if (BoundaryOption % 3 != 0) { BoundaryOption = BoundaryOption*3; }
2247 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
2249 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2250 if (BoundaryOption % 3 != 0) { BoundaryOption = BoundaryOption*3; }
2252 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
2254 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
2255 if (BoundaryOption % 3 != 0) { BoundaryOption = BoundaryOption*3; }
2257 else if (BoundaryType == 5) // Cas d un tore
2259 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
2260 if (BoundaryOption % 3 != 0) { BoundaryOption = BoundaryOption*3; }
2263 // 2.2.3. Memorisation du traitement
2264 ListeBoundaryTraitees.push_back(BoundaryName);
2267 // 3. Parcours des frontieres pour ecrire les liens avec les groupes
2268 NumBoundaryAnalytical = 0;
2269 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2271 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2272 MESSAGE ("... BoundaryName = " << BoundaryName);
2273 SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[BoundaryName];
2274 ASSERT(!CORBA::is_nil(myBoundary));
2275 int BoundaryType = myBoundary->GetType();
2276 MESSAGE ("... BoundaryType = " << BoundaryType);
2277 // 3.1. Recuperation du nom du groupe
2278 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
2279 MESSAGE ("... GroupName = " << GroupName);
2280 // 3.2. Cas d une frontiere CAO
2281 if (BoundaryType == -1)
2283 if (GroupName.size() > 0) { myDriver->TexteBoundaryCAOGr (GroupName); }
2285 // 3.3. Cas d une frontiere discrete
2286 else if (BoundaryType == 0)
2288 if (GroupName.size() > 0) { myDriver->TexteBoundaryDiGr (GroupName); }
2290 // 3.4. Cas d une frontiere analytique
2293 NumBoundaryAnalytical++;
2294 myDriver->TexteBoundaryAnGr (BoundaryName, NumBoundaryAnalytical, GroupName);
2297 // 4. Ecriture de l'option finale
2298 myDriver->TexteBoundaryOption(BoundaryOption);
2300 return BoundaryOption;
2302 //===========================================================================
2303 //===========================================================================
2305 //===========================================================================
2307 //===========================================================================
2308 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich)
2310 // Prevent dump of CreateMeshesFromMED
2311 SMESH::TPythonDump pDump; // do not delete this line of code
2313 MESSAGE("PublishResultInSmesh " << NomFich);
2314 if (CORBA::is_nil(SMESH_Gen_i::GetSMESHGen()->getStudyServant())) {
2315 SALOME::ExceptionStruct es;
2316 es.type = SALOME::BAD_PARAM;
2317 es.text = "Invalid study context";
2318 throw SALOME::SALOME_Exception(es);
2321 // Le module SMESH est-il actif ?
2322 SALOMEDS::SObject_var aSmeshSO =
2323 SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindComponent("SMESH");
2326 // Temporary suppressed depublication of mesh with the same name of file
2328 if (!CORBA::is_nil(aSmeshSO)) {
2329 // On verifie que le fichier n est pas deja publie
2330 SALOMEDS::ChildIterator_var aIter =
2331 SMESH_Gen_i::GetSMESHGen()->getStudyServant()->NewChildIterator(aSmeshSO);
2332 for (; aIter->More(); aIter->Next()) {
2333 SALOMEDS::SObject_var aSO = aIter->Value();
2334 SALOMEDS::GenericAttribute_var aGAttr;
2335 if (aSO->FindAttribute(aGAttr, "AttributeExternalFileDef")) {
2336 SALOMEDS::AttributeExternalFileDef_var anAttr =
2337 SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2338 CORBA::String_var value = anAttr->Value();
2339 if (strcmp((const char*)value, NomFich) == 0) {
2340 MESSAGE ("PublishResultInSmesh : le fichier " << NomFich << " est deja publie.");
2341 // Pour un fichier importe, on ne republie pas
2342 // Option = 0 : fichier issu d'une importation
2343 // Option = 1 : fichier issu d'une execution HOMARD
2344 if (Option == 0) { return; }
2345 // Pour un fichier calcule, on commence par faire la depublication
2347 MESSAGE("PublishResultInSmesh : depublication");
2348 if (aSO->FindAttribute(aGAttr, "AttributeName")) {
2349 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2350 CORBA::String_var value2 = anAttr2->Value();
2351 std::string MeshName = string(value2);
2352 MESSAGE("PublishResultInSmesh : depublication de " << MeshName);
2353 DeleteResultInSmesh(NomFich, MeshName);
2362 // On enregistre le fichier
2363 MESSAGE("Enregistrement du fichier");
2365 //SMESH::SMESH_Gen_var aSmeshEngine = this->retrieveSMESHInst();
2366 SMESH_Gen_i* aSmeshEngine = SMESH_Gen_i::GetSMESHGen();
2368 //ASSERT(!CORBA::is_nil(aSmeshEngine));
2369 aSmeshEngine->UpdateStudy();
2370 SMESH::DriverMED_ReadStatus theStatus;
2372 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
2373 SMESH::mesh_array* mesMaillages = aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
2374 if (CORBA::is_nil(aSmeshSO)) {
2375 aSmeshSO = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindComponent("SMESH");
2376 if (CORBA::is_nil(aSmeshSO)) return;
2379 for (int i = 0; i < (int)mesMaillages->length(); i++) {
2380 MESSAGE(". Mise a jour des attributs du maillage");
2381 SMESH::SMESH_Mesh_var monMaillage = (*mesMaillages)[i];
2382 SALOMEDS::SObject_var aSO = SALOMEDS::SObject::_narrow
2383 (SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindObjectIOR
2384 (SMESH_Gen_i::GetORB()->object_to_string(monMaillage)));
2385 SALOMEDS::StudyBuilder_var aStudyBuilder =
2386 SMESH_Gen_i::GetSMESHGen()->getStudyServant()->NewBuilder();
2387 SALOMEDS::GenericAttribute_var aGAttr =
2388 aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
2389 SALOMEDS::AttributeExternalFileDef_var anAttr =
2390 SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2391 anAttr->SetValue(NomFich);
2392 SALOMEDS::GenericAttribute_var aPixMap =
2393 aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap");
2394 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
2395 anAttr2->SetPixMap("mesh_tree_mesh.png");
2399 //=============================================================================
2400 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
2402 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich);
2403 if (CORBA::is_nil(SMESH_Gen_i::GetSMESHGen()->getStudyServant())) {
2404 SALOME::ExceptionStruct es;
2405 es.type = SALOME::BAD_PARAM;
2406 es.text = "Invalid study context";
2407 throw SALOME::SALOME_Exception(es);
2410 // Le module SMESH est-il actif ?
2411 SALOMEDS::SObject_var aSmeshSO =
2412 SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindComponent("SMESH");
2414 if (CORBA::is_nil(aSmeshSO)) return;
2415 // On verifie que le fichier est deja publie
2416 SALOMEDS::StudyBuilder_var myBuilder =
2417 SMESH_Gen_i::GetSMESHGen()->getStudyServant()->NewBuilder();
2418 SALOMEDS::ChildIterator_var aIter =
2419 SMESH_Gen_i::GetSMESHGen()->getStudyServant()->NewChildIterator(aSmeshSO);
2420 for (; aIter->More(); aIter->Next()) {
2421 SALOMEDS::SObject_var aSO = aIter->Value();
2422 SALOMEDS::GenericAttribute_var aGAttr;
2423 if (aSO->FindAttribute(aGAttr, "AttributeExternalFileDef")) {
2424 SALOMEDS::AttributeExternalFileDef_var anAttr =
2425 SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2426 CORBA::String_var value = anAttr->Value();
2427 if (strcmp((const char*)value, NomFich.c_str()) == 0) {
2428 if (aSO->FindAttribute(aGAttr, "AttributeName")) {
2429 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2430 CORBA::String_var value2 = anAttr2->Value();
2431 if (strcmp((const char*)value2, MeshName.c_str()) == 0) {
2432 myBuilder->RemoveObjectWithChildren(aSO);
2440 void HOMARD_Gen_i::PythonDump()
2442 MESSAGE ("Begin PythonDump");
2443 SMESH::TPythonDump pd;
2446 pd << "import SMESHHOMARD\n";
2447 //pd << "smeshhomard = " << SMESH_Gen_i::GetSMESHGen() << ".CreateHOMARD_ADAPT()\n";
2448 pd << "smeshhomard = " << SMESH_Gen_i::GetSMESHGen() << ".Adaptation(\"Uniform\")\n";
2451 if (_mesBoundarys.size() > 0) MESSAGE(". Creation of the boundaries");
2452 std::map<std::string, SMESHHOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2453 for (it_boundary = _mesBoundarys.begin();
2454 it_boundary != _mesBoundarys.end(); ++it_boundary) {
2455 SMESHHOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
2456 //MESSAGE ("PythonDump of boundary " << (*it_boundary).first <<
2457 // " : " << maBoundary->GetDumpPython());
2458 pd << maBoundary->GetDumpPython();
2462 ASSERT(!myCase->_is_nil());
2463 MESSAGE (". Creation of the case");
2465 if (_CaseOnMedFile) {
2466 pd << "smeshhomard.CreateCase(\"" << myIteration0->GetMeshName();
2467 pd << "\", \"" << myIteration0->GetMeshFile();
2468 pd << "\", \"" << myCase->GetDirName() << "\")\n";
2471 pd << "smeshhomard.CreateCaseOnMesh(\"" << myIteration0->GetMeshName();
2472 pd << "\", " << _SmeshMesh;
2473 pd << ".GetMesh(), \"" << myCase->GetDirName() << "\")\n";
2476 pd << myCase->GetDumpPython();
2479 pd << "smeshhomard.SetConfType(" << _ConfType << ")\n";
2480 pd << "smeshhomard.SetKeepMedOUT(" << (_KeepMedOUT ? "True" : "False") << ")\n";
2481 pd << "smeshhomard.SetPublishMeshOUT(" << (_PublishMeshOUT ? "True" : "False") << ")\n";
2482 pd << "smeshhomard.SetMeshNameOUT(\"" << _MeshNameOUT << "\")\n";
2483 pd << "smeshhomard.SetMeshFileOUT(\"" << _MeshFileOUT << "\")\n";
2485 pd << "smeshhomard.SetKeepWorkingFiles(" << (_KeepWorkingFiles ? "True" : "False") << ")\n";
2486 pd << "smeshhomard.SetLogInFile(" << (_LogInFile ? "True" : "False") << ")\n";
2487 if (_LogInFile) pd << "smeshhomard.SetLogFile(\"" << _LogFile << "\")\n";
2488 pd << "smeshhomard.SetRemoveLogOnSuccess(" << (_RemoveLogOnSuccess ? "True" : "False") << ")\n";
2489 pd << "smeshhomard.SetVerboseLevel(" << _VerboseLevel << ")\n";
2492 pd << "smeshhomard.Compute()\n";
2493 MESSAGE ("End PythonDump");
2496 void HOMARD_Gen_i::AddBoundary(const char* BoundaryName)
2498 MESSAGE("HOMARD_Gen_i::AddBoundary : BoundaryName = " << BoundaryName);
2499 if (myCase->_is_nil()) {
2500 SALOME::ExceptionStruct es;
2501 es.type = SALOME::BAD_PARAM;
2502 std::string text = "The input mesh must be defined before boundary addition";
2503 es.text = CORBA::string_dup(text.c_str());
2504 throw SALOME::SALOME_Exception(es);
2506 myCase->AddBoundary(BoundaryName);
2509 void HOMARD_Gen_i::AddBoundaryGroup(const char* BoundaryName, const char* Group)
2511 MESSAGE("HOMARD_Gen_i::AddBoundaryGroup : BoundaryName = " <<
2512 BoundaryName << ", Group = " << Group);
2513 if (myCase->_is_nil()) {
2514 SALOME::ExceptionStruct es;
2515 es.type = SALOME::BAD_PARAM;
2516 std::string text = "The input mesh must be defined before boundary group addition";
2517 es.text = CORBA::string_dup(text.c_str());
2518 throw SALOME::SALOME_Exception(es);
2520 myCase->AddBoundaryGroup(BoundaryName, Group);
2523 //===============================================================================
2525 //===============================================================================
2526 void HOMARD_Gen_i::SetConfType(CORBA::Long theConfType)
2528 _ConfType = theConfType;
2530 void HOMARD_Gen_i::SetKeepMedOUT(bool theKeepMedOUT)
2532 _KeepMedOUT = theKeepMedOUT;
2534 void HOMARD_Gen_i::SetPublishMeshOUT(bool thePublishMeshOUT)
2536 _PublishMeshOUT = thePublishMeshOUT;
2538 void HOMARD_Gen_i::SetKeepWorkingFiles(bool theKeepWorkingFiles)
2540 _KeepWorkingFiles = theKeepWorkingFiles;
2542 void HOMARD_Gen_i::SetLogInFile(bool theLogInFile)
2544 _LogInFile = theLogInFile;
2546 void HOMARD_Gen_i::SetRemoveLogOnSuccess(bool theRemoveLogOnSuccess)
2548 _RemoveLogOnSuccess = theRemoveLogOnSuccess;
2550 void HOMARD_Gen_i::SetVerboseLevel(CORBA::Long theVerboseLevel)
2552 _VerboseLevel = theVerboseLevel;
2554 void HOMARD_Gen_i::SetMeshNameOUT(const char* theMeshNameOUT)
2556 _MeshNameOUT = theMeshNameOUT;
2558 void HOMARD_Gen_i::SetMeshFileOUT(const char* theMeshFileOUT)
2560 _MeshFileOUT = theMeshFileOUT;
2562 void HOMARD_Gen_i::SetLogFile(const char* theLogFile)
2564 _LogFile = theLogFile;
2567 // =======================================================================
2568 std::set<std::string> GetListeGroupesInMedFile(const char * aFile)
2570 std::set<std::string> ListeGroupes;
2573 while (erreur == 0) {
2574 // Ouverture du fichier
2575 medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY);
2580 // Caracteristiques du maillage
2581 char meshname[MED_NAME_SIZE+1];
2582 med_int spacedim,meshdim;
2583 med_mesh_type meshtype;
2584 char descriptionription[MED_COMMENT_SIZE+1];
2585 char dtunit[MED_SNAME_SIZE+1];
2586 med_sorting_type sortingtype;
2588 med_axis_type axistype;
2589 int naxis = MEDmeshnAxis(medIdt,1);
2590 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
2591 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
2592 erreur = MEDmeshInfo(medIdt,
2607 if (erreur < 0) { break; }
2608 // Nombre de familles
2610 nfam = MEDnFamily(medIdt,meshname);
2615 // Lecture des caracteristiques des familles
2616 for (int i=0;i<nfam;i++) {
2617 // Lecture du nombre de groupes
2618 med_int ngro = MEDnFamilyGroup(medIdt,meshname,i+1);
2623 // Lecture de la famille
2624 else if (ngro > 0) {
2625 char familyname[MED_NAME_SIZE+1];
2627 char* gro = (char*) malloc(MED_LNAME_SIZE*ngro+1);
2628 erreur = MEDfamilyInfo(medIdt,
2638 // Lecture des groupes pour une famille de mailles
2640 for (int j=0;j<ngro;j++) {
2641 char str2[MED_LNAME_SIZE+1];
2642 strncpy(str2,gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
2643 str2[MED_LNAME_SIZE] = '\0';
2644 ListeGroupes.insert(std::string(str2));
2652 // Fermeture du fichier
2653 if (medIdt > 0) MEDfileClose(medIdt);
2655 return ListeGroupes;
2658 // =======================================================================
2659 // Le vecteur en retour contiendra les informations suivantes :
2660 // en position 0 et 1 Xmin, Xmax et en position 2 Dx si < 0 2D
2661 // en position 3 et 4 Ymin, Ymax et en position 5 Dy si < 0 2D
2662 // en position 6 et 7 Zmin, Zmax et en position 8 Dz si < 0 2D
2663 // 9 distance max dans le maillage
2664 // =======================================================================
2665 std::vector<double> GetBoundingBoxInMedFile(const char * aFile)
2667 std::vector<double> LesExtremes;
2670 while (erreur == 0) {
2671 // Ouverture du fichier
2672 medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY);
2677 //Nombre de maillage : on ne peut en lire qu'un seul
2678 med_int numberOfMeshes = MEDnMesh(medIdt);
2679 if (numberOfMeshes != 1) {
2683 // Caracteristiques du maillage
2684 char meshname[MED_NAME_SIZE+1];
2685 med_int spacedim,meshdim;
2686 med_mesh_type meshtype;
2687 char descriptionription[MED_COMMENT_SIZE+1];
2688 char dtunit[MED_SNAME_SIZE+1];
2689 med_sorting_type sortingtype;
2691 med_axis_type axistype;
2692 int naxis = MEDmeshnAxis(medIdt,1);
2693 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
2694 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
2695 erreur = MEDmeshInfo(medIdt,
2710 if (erreur < 0) { break; }
2714 med_int nnoe = MEDmeshnEntity(medIdt,
2730 med_float* coo = (med_float*) malloc(sizeof(med_float)*nnoe*spacedim);
2732 erreur = MEDmeshNodeCoordinateRd(medIdt,
2743 // Calcul des extremes
2744 med_float xmin,xmax,ymin,ymax,zmin,zmax;
2748 for (int i = 1; i < nnoe; i++) {
2749 xmin = std::min(xmin, coo[i]);
2750 xmax = std::max(xmax, coo[i]);
2756 for (int i = nnoe + 1; i < 2*nnoe; i++) {
2757 ymin = std::min(ymin,coo[i]);
2758 ymax = std::max(ymax,coo[i]);
2771 for (int i = 2*nnoe + 1; i < 3*nnoe; i++) {
2772 zmin = std::min(zmin,coo[i]);
2773 zmax = std::max(zmax,coo[i]);
2781 MESSAGE("_______________________________________");
2782 MESSAGE("xmin : " << xmin << " xmax : " << xmax);
2783 MESSAGE("ymin : " << ymin << " ymax : " << ymax);
2784 MESSAGE("zmin : " << zmin << " zmax : " << zmax);
2785 MESSAGE("_______________________________________");
2786 double epsilon = 1.e-6;
2787 LesExtremes.push_back(xmin);
2788 LesExtremes.push_back(xmax);
2789 LesExtremes.push_back(0);
2790 LesExtremes.push_back(ymin);
2791 LesExtremes.push_back(ymax);
2792 LesExtremes.push_back(0);
2793 LesExtremes.push_back(zmin);
2794 LesExtremes.push_back(zmax);
2795 LesExtremes.push_back(0);
2797 double max1 = std::max (LesExtremes[1] - LesExtremes[0], LesExtremes[4] - LesExtremes[3]);
2798 double max2 = std::max (max1 , LesExtremes[7] - LesExtremes[6]);
2799 LesExtremes.push_back(max2);
2801 // LesExtremes[0] = Xmini du maillage
2802 // LesExtremes[1] = Xmaxi du maillage
2803 // LesExtremes[2] = increment de progression en X
2804 // LesExtremes[3,4,5] : idem pour Y
2805 // LesExtremes[6,7,8] : idem pour Z
2806 // LesExtremes[9] = ecart maximal entre coordonnees
2807 // On fait un traitement pour dans le cas d'une coordonnee constante
2808 // inhiber ce cas en mettant un increment negatif
2810 double diff = LesExtremes[1] - LesExtremes[0];
2811 if (fabs(diff) > epsilon*max2) { LesExtremes[2] = diff/100.; }
2812 else { LesExtremes[2] = -1.; }
2814 diff = LesExtremes[4] - LesExtremes[3];
2815 if (fabs(diff) > epsilon*max2) { LesExtremes[5]=diff/100.; }
2816 else { LesExtremes[5] = -1.; }
2818 diff = LesExtremes[7] - LesExtremes[6];
2819 if (fabs(diff) > epsilon*max2) { LesExtremes[8]=diff/100.; }
2820 else { LesExtremes[8] = -1.; }
2822 MESSAGE ("_______________________________________");
2823 MESSAGE ("xmin : " << LesExtremes[0] << " xmax : " << LesExtremes[1] << " xincr : " << LesExtremes[2]);
2824 MESSAGE ("ymin : " << LesExtremes[3] << " ymax : " << LesExtremes[4] << " yincr : " << LesExtremes[5]);
2825 MESSAGE ("zmin : " << LesExtremes[6] << " zmax : " << LesExtremes[7] << " zincr : " << LesExtremes[8]);
2826 MESSAGE ("dmax : " << LesExtremes[9]);
2827 MESSAGE ("_______________________________________");
2832 // Fermeture du fichier
2833 if (medIdt > 0) MEDfileClose(medIdt);
2838 }; // namespace SMESHHOMARD_I