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"
29 //#include "FrontTrack.hxx"
31 #include "utilities.h"
32 #include "Basics_Utils.hxx"
33 #include "Basics_DirUtils.hxx"
34 #include "Utils_SINGLETON.hxx"
35 #include "Utils_CorbaException.hxx"
36 #include "SALOMEDS_Tool.hxx"
37 #include "SALOME_LifeCycleCORBA.hxx"
38 #include "SALOMEconfig.h"
66 SMESHHOMARD::HOMARD_Gen_ptr SMESH_Gen_i::CreateHOMARD_ADAPT()
68 SMESHHOMARD_I::HOMARD_Gen_i* aHomardGen = new SMESHHOMARD_I::HOMARD_Gen_i();
69 SMESHHOMARD::HOMARD_Gen_var anObj = aHomardGen->_this();
73 namespace SMESHHOMARD_I
76 //=============================================================================
78 * standard constructor
80 //=============================================================================
81 HOMARD_Boundary_i::HOMARD_Boundary_i()
82 : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
84 MESSAGE("Default constructor, not for use");
87 //=============================================================================
89 * standard constructor
91 //=============================================================================
92 HOMARD_Boundary_i::HOMARD_Boundary_i(SMESHHOMARD::HOMARD_Gen_var engine)
93 : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
95 MESSAGE("HOMARD_Boundary_i");
97 myHomardBoundary = new SMESHHOMARDImpl::HOMARD_Boundary();
98 ASSERT(myHomardBoundary);
100 //=============================================================================
102 * standard destructor
104 //=============================================================================
105 HOMARD_Boundary_i::~HOMARD_Boundary_i()
108 //=============================================================================
109 //=============================================================================
111 //=============================================================================
112 //=============================================================================
113 void HOMARD_Boundary_i::SetName(const char* Name)
115 ASSERT(myHomardBoundary);
116 myHomardBoundary->SetName(Name);
118 //=============================================================================
119 char* HOMARD_Boundary_i::GetName()
121 ASSERT(myHomardBoundary);
122 return CORBA::string_dup(myHomardBoundary->GetName().c_str());
124 //=============================================================================
125 char* HOMARD_Boundary_i::GetDumpPython()
127 ASSERT(myHomardBoundary);
128 return CORBA::string_dup(myHomardBoundary->GetDumpPython().c_str());
130 //=============================================================================
131 //=============================================================================
133 //=============================================================================
134 //=============================================================================
135 void HOMARD_Boundary_i::SetType(CORBA::Long Type)
137 ASSERT(myHomardBoundary);
138 myHomardBoundary->SetType(Type);
140 //=============================================================================
141 CORBA::Long HOMARD_Boundary_i::GetType()
143 ASSERT(myHomardBoundary);
144 return CORBA::Long(myHomardBoundary->GetType());
146 //=============================================================================
147 void HOMARD_Boundary_i::SetMeshName(const char* MeshName)
149 ASSERT(myHomardBoundary);
150 myHomardBoundary->SetMeshName(MeshName);
152 //=============================================================================
153 char* HOMARD_Boundary_i::GetMeshName()
155 ASSERT(myHomardBoundary);
156 return CORBA::string_dup(myHomardBoundary->GetMeshName().c_str());
158 //=============================================================================
159 void HOMARD_Boundary_i::SetDataFile(const char* DataFile)
161 ASSERT(myHomardBoundary);
162 myHomardBoundary->SetDataFile(DataFile);
164 //=============================================================================
165 char* HOMARD_Boundary_i::GetDataFile()
167 ASSERT(myHomardBoundary);
168 return CORBA::string_dup(myHomardBoundary->GetDataFile().c_str());
170 //=============================================================================
171 void HOMARD_Boundary_i::SetCylinder(double X0, double X1, double X2, double X3, double X4, double X5, double X6)
173 ASSERT(myHomardBoundary);
174 myHomardBoundary->SetCylinder(X0, X1, X2, X3, X4, X5, X6);
176 //=============================================================================
177 void HOMARD_Boundary_i::SetSphere(double Xcentre, double Ycentre, double ZCentre, double rayon)
179 ASSERT(myHomardBoundary);
180 myHomardBoundary->SetSphere(Xcentre, Ycentre, ZCentre, rayon);
182 //=============================================================================
183 void HOMARD_Boundary_i::SetConeR(double Xcentre1, double Ycentre1, double Zcentre1, double Rayon1, double Xcentre2, double Ycentre2, double Zcentre2, double Rayon2)
185 ASSERT(myHomardBoundary);
186 myHomardBoundary->SetConeR(Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2);
188 //=============================================================================
189 void HOMARD_Boundary_i::SetConeA(double Xaxe, double Yaxe, double Zaxe, double Angle, double Xcentre, double Ycentre, double Zcentre)
191 ASSERT(myHomardBoundary);
192 myHomardBoundary->SetConeA(Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre);
194 //=============================================================================
195 void HOMARD_Boundary_i::SetTorus(double X0, double X1, double X2, double X3, double X4, double X5, double X6, double X7)
197 ASSERT(myHomardBoundary);
198 myHomardBoundary->SetTorus(X0, X1, X2, X3, X4, X5, X6, X7);
200 //=============================================================================
201 SMESHHOMARD::double_array* HOMARD_Boundary_i::GetCoords()
203 ASSERT(myHomardBoundary);
204 SMESHHOMARD::double_array_var aResult = new SMESHHOMARD::double_array();
205 std::vector<double> mesCoor = myHomardBoundary->GetCoords();
206 aResult->length(mesCoor .size());
207 std::vector<double>::const_iterator it;
209 for (it = mesCoor.begin(); it != mesCoor.end(); it++)
210 aResult[i++] = (*it);
211 return aResult._retn();
213 //=============================================================================
214 void HOMARD_Boundary_i::SetLimit(double Xincr, double Yincr, double Zincr)
216 ASSERT(myHomardBoundary);
217 myHomardBoundary->SetLimit(Xincr, Yincr, Zincr);
219 //=============================================================================
220 SMESHHOMARD::double_array* HOMARD_Boundary_i::GetLimit()
222 ASSERT(myHomardBoundary);
223 SMESHHOMARD::double_array_var aResult = new SMESHHOMARD::double_array();
224 std::vector<double> mesCoor = myHomardBoundary->GetLimit();
225 aResult->length(mesCoor .size());
226 std::vector<double>::const_iterator it;
228 for (it = mesCoor.begin(); it != mesCoor.end(); it++)
229 aResult[i++] = (*it);
230 return aResult._retn();
232 //=============================================================================
233 void HOMARD_Boundary_i::AddGroup(const char* Group)
235 ASSERT(myHomardBoundary);
236 myHomardBoundary->AddGroup(Group);
238 //=============================================================================
239 void HOMARD_Boundary_i::SetGroups(const SMESHHOMARD::ListGroupType& ListGroup)
241 ASSERT(myHomardBoundary);
242 std::list<std::string> ListString;
243 for (unsigned int i = 0; i < ListGroup.length(); i++) {
244 ListString.push_back(std::string(ListGroup[i]));
246 myHomardBoundary->SetGroups(ListString);
248 //=============================================================================
249 SMESHHOMARD::ListGroupType* HOMARD_Boundary_i::GetGroups()
251 ASSERT(myHomardBoundary);
252 const std::list<std::string>& ListString = myHomardBoundary->GetGroups();
253 SMESHHOMARD::ListGroupType_var aResult = new SMESHHOMARD::ListGroupType;
254 aResult->length(ListString.size());
255 std::list<std::string>::const_iterator it;
257 for (it = ListString.begin(); it != ListString.end(); it++)
259 aResult[i++] = CORBA::string_dup((*it).c_str());
261 return aResult._retn();
263 //=============================================================================
264 //=============================================================================
265 // Liens avec les autres structures
266 //=============================================================================
267 //=============================================================================
268 void HOMARD_Boundary_i::SetCaseCreation(const char* NomCaseCreation)
270 ASSERT(myHomardBoundary);
271 myHomardBoundary->SetCaseCreation(NomCaseCreation);
273 //=============================================================================
274 char* HOMARD_Boundary_i::GetCaseCreation()
276 ASSERT(myHomardBoundary);
277 return CORBA::string_dup(myHomardBoundary->GetCaseCreation().c_str());
280 //=============================================================================
282 * standard constructor
284 //=============================================================================
285 HOMARD_Cas_i::HOMARD_Cas_i()
286 : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
288 MESSAGE("Default constructor, not for use");
292 //=============================================================================
294 * standard constructor
296 //=============================================================================
297 HOMARD_Cas_i::HOMARD_Cas_i(SMESHHOMARD::HOMARD_Gen_var engine)
298 : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
300 MESSAGE("HOMARD_Cas_i");
302 myHomardCas = new SMESHHOMARDImpl::HOMARD_Cas();
304 myHomardCas->SetName("Case_1");
307 //=============================================================================
309 * standard destructor
311 //=============================================================================
312 HOMARD_Cas_i::~HOMARD_Cas_i()
315 //=============================================================================
316 //=============================================================================
318 //=============================================================================
319 //=============================================================================
320 char* HOMARD_Cas_i::GetName()
323 return CORBA::string_dup(myHomardCas->GetName().c_str());
325 //=============================================================================
326 char* HOMARD_Cas_i::GetDumpPython()
329 return CORBA::string_dup(myHomardCas->GetDumpPython().c_str());
331 //=============================================================================
332 //=============================================================================
334 //=============================================================================
335 //=============================================================================
336 void HOMARD_Cas_i::SetDirName(const char* NomDir)
340 // A. recuperation du nom; on ne fait rien si c'est le meme
341 char* oldrep = GetDirName();
342 if (strcmp(oldrep,NomDir) == 0) return;
343 MESSAGE ("SetDirName : passage de oldrep = "<< oldrep << " a NomDir = "<<NomDir);
344 // C. Changement/creation du repertoire
345 codret = myHomardCas->SetDirName(NomDir);
347 SALOME::ExceptionStruct es;
348 es.type = SALOME::BAD_PARAM;
351 text = "The directory for the case cannot be modified because some iterations are already defined.";
353 text = "The directory for the case cannot be reached.";
354 es.text = CORBA::string_dup(text.c_str());
355 throw SALOME::SALOME_Exception(es);
357 // D. En cas de reprise, deplacement du point de depart
358 SMESHHOMARD::HOMARD_Iteration_ptr Iter0 = _gen_i->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 = _gen_i->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::SetConfType(CORBA::Long ConfType)
421 //VERIFICATION((ConfType>=-2) && (ConfType<=3));
422 myHomardCas->SetConfType(ConfType);
424 //=============================================================================
425 CORBA::Long HOMARD_Cas_i::GetConfType()
428 return myHomardCas->GetConfType();
430 //=============================================================================
431 void HOMARD_Cas_i::SetBoundingBox(const SMESHHOMARD::extrema& LesExtrema)
434 std::vector<double> VExtrema;
435 ASSERT(LesExtrema.length() == 10);
436 VExtrema.resize(LesExtrema.length());
437 for (int i = 0; i < (int)LesExtrema.length(); i++) {
438 VExtrema[i] = LesExtrema[i];
440 myHomardCas->SetBoundingBox(VExtrema);
442 //=============================================================================
443 SMESHHOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
446 SMESHHOMARD::extrema_var aResult = new SMESHHOMARD::extrema();
447 std::vector<double> LesExtremes = myHomardCas->GetBoundingBox();
448 ASSERT(LesExtremes.size() == 10);
450 for (int i = 0; i < (int)LesExtremes.size(); i++) {
451 aResult[i] = LesExtremes[i];
453 return aResult._retn();
456 //=============================================================================
457 void HOMARD_Cas_i::AddGroup(const char* Group)
460 myHomardCas->AddGroup(Group);
462 //=============================================================================
463 void HOMARD_Cas_i::SetGroups(const SMESHHOMARD::ListGroupType& ListGroup)
466 std::list<std::string> ListString;
467 for (int i = 0; i < ListGroup.length(); i++)
469 ListString.push_back(std::string(ListGroup[i]));
471 myHomardCas->SetGroups(ListString);
473 //=============================================================================
474 SMESHHOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
477 const std::list<std::string>& ListString = myHomardCas->GetGroups();
478 SMESHHOMARD::ListGroupType_var aResult = new SMESHHOMARD::ListGroupType();
479 aResult->length(ListString.size());
480 std::list<std::string>::const_iterator it;
482 for (it = ListString.begin(); it != ListString.end(); it++) {
483 aResult[i++] = CORBA::string_dup((*it).c_str());
485 return aResult._retn();
488 //=============================================================================
489 void HOMARD_Cas_i::AddBoundary(const char* BoundaryName)
491 MESSAGE ("HOMARD_Cas_i::AddBoundary : BoundaryName = "<< BoundaryName);
492 const char * Group = "";
493 AddBoundaryGroup(BoundaryName, Group);
495 //=============================================================================
496 void HOMARD_Cas_i::AddBoundaryGroup(const char* BoundaryName, const char* Group)
498 MESSAGE ("HOMARD_Cas_i::AddBoundaryGroup : BoundaryName = "<< BoundaryName << ", Group = " << Group);
501 // A.1. Caractéristiques de la frontière à ajouter
502 SMESHHOMARD::HOMARD_Boundary_ptr myBoundary = _gen_i->GetBoundary(BoundaryName);
503 ASSERT(!CORBA::is_nil(myBoundary));
504 int BoundaryType = myBoundary->GetType();
505 MESSAGE (". BoundaryType = " << BoundaryType);
506 // A.2. La liste des frontiere+groupes
507 const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
508 std::list<std::string>::const_iterator it;
514 // B.1. Si on ajoute une frontière CAO, elle doit être la seule frontière
515 if (BoundaryType == -1)
517 for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++)
519 boun = (*it).c_str();
520 MESSAGE (".. Frontiere enregistrée : "<< boun);
521 if (*it != BoundaryName)
524 // On saute le nom du groupe
528 if (erreur != 0) { break; }
529 // B.2. Si on ajoute une frontière non CAO, il ne doit pas y avoir de frontière CAO
530 if (BoundaryType != -1)
532 for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++)
534 boun = (*it).c_str();
535 MESSAGE (".. Frontiere enregistrée : "<< boun);
536 SMESHHOMARD::HOMARD_Boundary_ptr myBoundary_0 = _gen_i->GetBoundary(boun);
537 int BoundaryType_0 = myBoundary_0->GetType();
538 MESSAGE (".. BoundaryType_0 = " << BoundaryType_0);
539 if (BoundaryType_0 == -1)
542 // On saute le nom du groupe
545 if (erreur != 0) { break; }
547 // B.3. Si on ajoute une frontière discrète, il ne doit pas y avoir d'autre frontière discrète
548 if (BoundaryType == 0)
550 for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++)
552 boun = (*it).c_str();
553 MESSAGE (".. Frontiere enregistrée : "<< boun);
554 if (boun != BoundaryName)
556 SMESHHOMARD::HOMARD_Boundary_ptr myBoundary_0 = _gen_i->GetBoundary(boun);
557 int BoundaryType_0 = myBoundary_0->GetType();
558 MESSAGE (".. BoundaryType_0 = " << BoundaryType_0);
559 if (BoundaryType_0 == 0)
563 // On saute le nom du groupe
566 if (erreur != 0) { break; }
568 // B.4. Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
569 for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++) {
570 MESSAGE (".. Frontiere : "<< *it);
571 // On saute le nom du groupe
574 // B.5. Le groupe est-il deja enregistre pour une frontiere de ce cas ?
575 for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++) {
576 boun = (*it).c_str();
578 MESSAGE (".. Groupe enregistré : "<< *it);
584 if (erreur != 0) { break; }
588 // F. Si aucune erreur, enregistrement du couple (frontiere,groupe) dans la reference du cas
591 myHomardCas->AddBoundaryGroup(BoundaryName, Group);
594 std::stringstream ss;
596 std::string str = ss.str();
598 texte = "Erreur numéro " + str + " pour la frontière à enregistrer : " + std::string(BoundaryName);
599 if (erreur == 1) { texte += "\nIl existe déjà la frontière "; }
600 else if (erreur == 2) { texte += "\nIl existe déjà la frontière CAO "; }
601 else if (erreur == 3) { texte += "\nIl existe déjà une frontière discrète : "; }
602 else if (erreur == 5) { texte += "\nLe groupe " + std::string(Group) + " est déjà enregistré pour la frontière "; }
603 texte += std::string(boun);
605 SALOME::ExceptionStruct es;
606 es.type = SALOME::BAD_PARAM;
608 texte += "\nInvalid AddBoundaryGroup";
611 es.text = CORBA::string_dup(texte.c_str());
612 throw SALOME::SALOME_Exception(es);
615 //=============================================================================
616 SMESHHOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
618 MESSAGE ("GetBoundaryGroup");
620 const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
621 SMESHHOMARD::ListBoundaryGroupType_var aResult = new SMESHHOMARD::ListBoundaryGroupType();
622 aResult->length(ListBoundaryGroup.size());
623 std::list<std::string>::const_iterator it;
625 for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++)
627 aResult[i++] = CORBA::string_dup((*it).c_str());
629 return aResult._retn();
631 //=============================================================================
632 void HOMARD_Cas_i::SupprBoundaryGroup()
634 MESSAGE ("SupprBoundaryGroup");
636 myHomardCas->SupprBoundaryGroup();
639 void HOMARD_Cas_i::AddIteration(const char* NomIteration)
642 myHomardCas->AddIteration(NomIteration);
645 //=============================================================================
647 * standard constructor
649 //=============================================================================
650 HOMARD_Hypothesis_i::HOMARD_Hypothesis_i()
651 : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
653 MESSAGE("Default constructor, not for use");
657 //=============================================================================
659 * standard constructor
661 //=============================================================================
662 HOMARD_Hypothesis_i::HOMARD_Hypothesis_i(SMESHHOMARD::HOMARD_Gen_var engine)
663 : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
665 MESSAGE("standard constructor");
667 myHomardHypothesis = new SMESHHOMARDImpl::HOMARD_Hypothesis();
668 ASSERT(myHomardHypothesis);
670 // SetUnifRefinUnRef(1)
673 myHomardHypothesis->SetAdapType(-1);
674 myHomardHypothesis->SetRefinTypeDera(RefinType, UnRefType);
677 myHomardHypothesis->SetName("Hypo_1");
680 //=============================================================================
682 * standard destructor
684 //=============================================================================
685 HOMARD_Hypothesis_i::~HOMARD_Hypothesis_i()
689 //=============================================================================
690 void HOMARD_Hypothesis_i::SetExtraOutput(CORBA::Long ExtraOutput)
692 ASSERT(myHomardHypothesis);
693 myHomardHypothesis->SetExtraOutput(ExtraOutput);
695 //=============================================================================
696 CORBA::Long HOMARD_Hypothesis_i::GetExtraOutput()
698 ASSERT(myHomardHypothesis);
699 return myHomardHypothesis->GetExtraOutput();
702 //=============================================================================
703 //=============================================================================
704 // Liens avec les autres structures
705 //=============================================================================
706 //=============================================================================
707 void HOMARD_Hypothesis_i::LinkIteration(const char* NomIteration)
709 ASSERT(myHomardHypothesis);
710 myHomardHypothesis->LinkIteration(NomIteration);
712 //=============================================================================
713 void HOMARD_Hypothesis_i::UnLinkIteration(const char* NomIteration)
715 ASSERT(myHomardHypothesis);
716 myHomardHypothesis->UnLinkIteration(NomIteration);
719 //=============================================================================
721 * standard constructor
723 //=============================================================================
724 HOMARD_Iteration_i::HOMARD_Iteration_i()
725 : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
727 MESSAGE("Default constructor, not for use");
730 //=============================================================================
732 * standard constructor
734 //=============================================================================
735 HOMARD_Iteration_i::HOMARD_Iteration_i(SMESHHOMARD::HOMARD_Gen_var engine)
736 : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
738 MESSAGE("constructor");
740 myHomardIteration = new SMESHHOMARDImpl::HOMARD_Iteration();
741 ASSERT(myHomardIteration);
743 //=============================================================================
745 * standard destructor
747 //=============================================================================
748 HOMARD_Iteration_i::~HOMARD_Iteration_i()
751 //=============================================================================
752 void HOMARD_Iteration_i::SetName(const char* Name)
754 ASSERT(myHomardIteration);
755 myHomardIteration->SetName(Name);
757 //=============================================================================
758 char* HOMARD_Iteration_i::GetName()
760 ASSERT(myHomardIteration);
761 return CORBA::string_dup(myHomardIteration->GetName().c_str());
763 //=============================================================================
764 void HOMARD_Iteration_i::SetDirNameLoc(const char* NomDir)
766 ASSERT(myHomardIteration);
767 myHomardIteration->SetDirNameLoc(NomDir);
769 //=============================================================================
770 char* HOMARD_Iteration_i::GetDirNameLoc()
772 ASSERT(myHomardIteration);
773 return CORBA::string_dup(myHomardIteration->GetDirNameLoc().c_str());
775 //=============================================================================
776 char* HOMARD_Iteration_i::GetDirName()
778 ASSERT(myHomardIteration);
779 SMESHHOMARD::HOMARD_Cas_ptr caseiter = _gen_i->GetCase();
780 std::string dirnamecase = caseiter->GetDirName();
781 std::string dirname = dirnamecase + "/" + GetDirNameLoc();
782 return CORBA::string_dup(dirname.c_str());
784 //=============================================================================
785 void HOMARD_Iteration_i::SetNumber(CORBA::Long NumIter)
787 ASSERT(myHomardIteration);
788 myHomardIteration->SetNumber(NumIter);
790 //=============================================================================
791 CORBA::Long HOMARD_Iteration_i::GetNumber()
793 ASSERT(myHomardIteration);
794 return myHomardIteration->GetNumber();
796 //=============================================================================
797 void HOMARD_Iteration_i::SetState(CORBA::Long Etat)
799 ASSERT(myHomardIteration);
800 myHomardIteration->SetState(Etat);
802 //=============================================================================
803 CORBA::Long HOMARD_Iteration_i::GetState()
805 ASSERT(myHomardIteration);
806 return myHomardIteration->GetState();
808 //=============================================================================
809 void HOMARD_Iteration_i::SetMeshName(const char* NomMesh)
811 ASSERT(myHomardIteration);
812 myHomardIteration->SetMeshName(NomMesh);
814 //=============================================================================
815 char* HOMARD_Iteration_i::GetMeshName()
817 ASSERT(myHomardIteration);
818 return CORBA::string_dup(myHomardIteration->GetMeshName().c_str());
820 //=============================================================================
821 void HOMARD_Iteration_i::SetMeshFile(const char* MeshFile)
823 ASSERT(myHomardIteration);
824 myHomardIteration->SetMeshFile(MeshFile);
826 //=============================================================================
827 char* HOMARD_Iteration_i::GetMeshFile()
829 ASSERT(myHomardIteration);
830 return CORBA::string_dup(myHomardIteration->GetMeshFile().c_str());
832 //=============================================================================
833 void HOMARD_Iteration_i::SetLogFile(const char* LogFile)
835 ASSERT(myHomardIteration);
836 myHomardIteration->SetLogFile(LogFile);
838 //=============================================================================
839 char* HOMARD_Iteration_i::GetLogFile()
841 ASSERT(myHomardIteration);
842 return CORBA::string_dup(myHomardIteration->GetLogFile().c_str());
844 //=============================================================================
845 void HOMARD_Iteration_i::SetFileInfo(const char* FileInfo)
847 ASSERT(myHomardIteration);
848 myHomardIteration->SetFileInfo(FileInfo);
850 //=============================================================================
851 char* HOMARD_Iteration_i::GetFileInfo()
853 ASSERT(myHomardIteration);
854 return CORBA::string_dup(myHomardIteration->GetFileInfo().c_str());
856 //=============================================================================
857 //=============================================================================
858 // Liens avec les autres iterations
859 //=============================================================================
860 //=============================================================================
861 void HOMARD_Iteration_i::LinkNextIteration(const char* NomIteration)
863 ASSERT(myHomardIteration);
864 myHomardIteration->LinkNextIteration(NomIteration);
866 //=============================================================================
867 void HOMARD_Iteration_i::UnLinkNextIteration(const char* NomIteration)
869 ASSERT(myHomardIteration);
870 myHomardIteration->UnLinkNextIteration(NomIteration);
872 //=============================================================================
873 void HOMARD_Iteration_i::SetIterParentName(const char* NomIterParent)
875 ASSERT(myHomardIteration);
876 myHomardIteration->SetIterParentName(NomIterParent);
878 //=============================================================================
879 char* HOMARD_Iteration_i::GetIterParentName()
881 ASSERT(myHomardIteration);
882 return CORBA::string_dup(myHomardIteration->GetIterParentName().c_str());
885 //=============================================================================
886 //=============================================================================
887 // Liens avec les autres structures
888 //=============================================================================
889 //=============================================================================
890 void HOMARD_Iteration_i::SetCaseName(const char* NomCas)
892 ASSERT(myHomardIteration);
893 myHomardIteration->SetCaseName(NomCas);
895 //=============================================================================
896 char* HOMARD_Iteration_i::GetCaseName()
898 ASSERT(myHomardIteration);
899 return CORBA::string_dup(myHomardIteration->GetCaseName().c_str());
901 //=============================================================================
902 void HOMARD_Iteration_i::SetHypoName(const char* NomHypo)
904 ASSERT(myHomardIteration);
905 myHomardIteration->SetHypoName(NomHypo);
907 //=============================================================================
908 //=============================================================================
910 //=============================================================================
911 //=============================================================================
912 void HOMARD_Iteration_i::SetInfoCompute(CORBA::Long MessInfo)
914 ASSERT(myHomardIteration);
915 myHomardIteration->SetInfoCompute(MessInfo);
917 //=============================================================================
918 CORBA::Long HOMARD_Iteration_i::GetInfoCompute()
920 ASSERT(myHomardIteration);
921 return myHomardIteration->GetInfoCompute();
924 //=============================================================================
926 * standard constructor
928 //=============================================================================
929 HOMARD_Gen_i::HOMARD_Gen_i() : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA()),
931 _PublishMeshOUT(false),
932 _KeepWorkingFiles(false),
934 _RemoveLogOnSuccess(false),
939 _CaseOnMedFile(true),
940 _SmeshMesh(SMESH::SMESH_Mesh::_nil()),
943 MESSAGE("constructor de HOMARD_Gen_i");
944 myHomard = new SMESHHOMARDImpl::HOMARD_Gen;
947 //=============================================================================
949 * standard destructor
951 //=============================================================================
952 HOMARD_Gen_i::~HOMARD_Gen_i()
954 if (!myCase->_is_nil()) {
959 //=============================================================================
960 //=============================================================================
961 // Destruction des structures identifiees par leurs noms
962 //=============================================================================
963 //=============================================================================
964 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
966 MESSAGE ("DeleteBoundary : BoundaryName = " << BoundaryName);
967 SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[BoundaryName];
968 if (CORBA::is_nil(myBoundary)) {
969 SALOME::ExceptionStruct es;
970 es.type = SALOME::BAD_PARAM;
971 es.text = "Invalid boundary";
972 throw SALOME::SALOME_Exception(es);
975 // Boundaries should be deleted only after all cases deletion!!!
977 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
978 _mesBoundarys.erase(BoundaryName);
983 //=============================================================================
984 CORBA::Long HOMARD_Gen_i::DeleteCase()
986 MESSAGE ("DeleteCase");
987 if (!CORBA::is_nil(myCase)) {
989 if (DeleteIteration(0) != 0) return 2;
991 myCase = SMESHHOMARD::HOMARD_Cas::_nil();
996 //=============================================================================
997 CORBA::Long HOMARD_Gen_i::DeleteIteration(int numIter)
999 MESSAGE ("DeleteIteration : numIter = " << numIter);
1002 myIteration0 = SMESHHOMARD::HOMARD_Iteration::_nil();
1005 if (!CORBA::is_nil(myIteration1)) {
1006 if (CORBA::is_nil(myIteration0)) {
1007 SALOME::ExceptionStruct es;
1008 es.type = SALOME::BAD_PARAM;
1009 es.text = "Invalid iteration 0";
1010 throw SALOME::SALOME_Exception(es);
1013 // Invalide Iteration
1014 if (myIteration1->GetState() > 0) {
1015 myIteration1->SetState(1);
1016 if (!_KeepWorkingFiles) {
1017 std::string nomDir = myIteration1->GetDirName();
1018 std::string commande = "rm -rf " + nomDir;
1019 if (numIter > 0 && !_KeepMedOUT) {
1020 // Remove associated mesh file
1021 std::string nomFichier = myIteration1->GetMeshFile();
1022 commande = commande + ";rm -rf " + nomFichier;
1024 MESSAGE ("commande = " << commande);
1025 if ((system(commande.c_str())) != 0) {
1026 SALOME::ExceptionStruct es;
1027 es.type = SALOME::BAD_PARAM;
1028 es.text = "The directory for the calculation cannot be cleared.";
1029 throw SALOME::SALOME_Exception(es);
1034 // Unlink from the parent iteration and from the hypothesis
1035 myIteration0->UnLinkNextIteration("Iter_1");
1036 ASSERT(!CORBA::is_nil(myHypothesis));
1037 myHypothesis->UnLinkIteration("Iter_1");
1038 myIteration1 = SMESHHOMARD::HOMARD_Iteration::_nil();
1045 //=============================================================================
1046 //=============================================================================
1047 // Invalidation des structures identifiees par leurs noms
1048 //=============================================================================
1049 //=============================================================================
1050 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
1052 MESSAGE("InvalideBoundary : BoundaryName = " << BoundaryName);
1053 SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[BoundaryName];
1054 if (CORBA::is_nil(myBoundary)) {
1055 SALOME::ExceptionStruct es;
1056 es.type = SALOME::BAD_PARAM;
1057 es.text = "Invalid boundary";
1058 throw SALOME::SALOME_Exception(es);
1061 SALOME::ExceptionStruct es;
1062 es.type = SALOME::BAD_PARAM;
1063 es.text = "No change is allowed in a boundary. Ask for evolution.";
1064 throw SALOME::SALOME_Exception(es);
1068 //=============================================================================
1069 //=============================================================================
1070 // Association de lien entre des structures identifiees par leurs noms
1071 //=============================================================================
1072 //=============================================================================
1073 void HOMARD_Gen_i::AssociateCaseIter(int numIter, const char* labelIter)
1075 MESSAGE("AssociateCaseIter : " << numIter << ", " << labelIter);
1077 if (CORBA::is_nil(myCase)) {
1078 SALOME::ExceptionStruct es;
1079 es.type = SALOME::BAD_PARAM;
1080 es.text = "Invalid case";
1081 throw SALOME::SALOME_Exception(es);
1084 SMESHHOMARD::HOMARD_Iteration_var myIteration;
1085 if (numIter == 0) myIteration = myIteration0;
1086 else myIteration = myIteration1;
1087 if (CORBA::is_nil(myIteration)) {
1088 SALOME::ExceptionStruct es;
1089 es.type = SALOME::BAD_PARAM;
1090 es.text = "Invalid iteration";
1091 throw SALOME::SALOME_Exception(es);
1094 myCase->AddIteration(myIteration->GetName());
1095 myIteration->SetCaseName("Case_1");
1098 //=============================================================================
1099 //=============================================================================
1100 // Recuperation des listes
1101 //=============================================================================
1102 //=============================================================================
1103 SMESHHOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
1105 MESSAGE("GetAllBoundarysName");
1107 SMESHHOMARD::listeBoundarys_var ret = new SMESHHOMARD::listeBoundarys;
1108 ret->length(_mesBoundarys.size());
1109 std::map<std::string, SMESHHOMARD::HOMARD_Boundary_var>::const_iterator it;
1111 for (it = _mesBoundarys.begin();
1112 it != _mesBoundarys.end(); it++) {
1113 ret[i++] = CORBA::string_dup((*it).first.c_str());
1119 //=============================================================================
1120 //=============================================================================
1121 // Recuperation des structures identifiees par leurs noms
1122 //=============================================================================
1123 //=============================================================================
1124 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
1126 SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[nomBoundary];
1127 ASSERT(!CORBA::is_nil(myBoundary));
1128 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1130 //=============================================================================
1131 SMESHHOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase()
1133 ASSERT(!CORBA::is_nil(myCase));
1134 return SMESHHOMARD::HOMARD_Cas::_duplicate(myCase);
1136 //=============================================================================
1137 SMESHHOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(int numIter)
1140 ASSERT(!CORBA::is_nil(myIteration0));
1141 return SMESHHOMARD::HOMARD_Iteration::_duplicate(myIteration0);
1144 ASSERT(!CORBA::is_nil(myIteration1));
1145 return SMESHHOMARD::HOMARD_Iteration::_duplicate(myIteration1);
1148 //=============================================================================
1149 //=============================================================================
1150 // Nouvelles structures
1151 //=============================================================================
1152 //=============================================================================
1153 SMESHHOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1155 SMESHHOMARD::HOMARD_Gen_var engine = POA_SMESHHOMARD::HOMARD_Gen::_this();
1156 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(engine);
1157 SMESHHOMARD::HOMARD_Cas_var aCase = SMESHHOMARD::HOMARD_Cas::_narrow(aServant->_this());
1158 return aCase._retn();
1160 //=============================================================================
1161 SMESHHOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1163 SMESHHOMARD::HOMARD_Gen_var engine = POA_SMESHHOMARD::HOMARD_Gen::_this();
1164 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(engine);
1165 SMESHHOMARD::HOMARD_Iteration_var aIter =
1166 SMESHHOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1167 return aIter._retn();
1169 //=============================================================================
1170 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1172 SMESHHOMARD::HOMARD_Gen_var engine = POA_SMESHHOMARD::HOMARD_Gen::_this();
1173 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(engine);
1174 SMESHHOMARD::HOMARD_Boundary_var aBoundary =
1175 SMESHHOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1176 return aBoundary._retn();
1179 //=============================================================================
1180 //=============================================================================
1181 // Creation des structures identifiees par leurs noms
1182 //=============================================================================
1183 //=============================================================================
1185 //=============================================================================
1186 // Creation of a case
1187 // MeshName : name of the mesh
1188 // smeshMesh : correspondent mesh
1189 // theWorkingDir : path to working directory
1190 //=============================================================================
1191 SMESHHOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseOnMesh (const char* MeshName,
1192 SMESH::SMESH_Mesh_ptr smeshMesh,
1193 const char* theWorkingDir)
1195 INFOS("CreateCaseOnMesh");
1198 // A.1. Controle du nom :
1199 if (!myCase->_is_nil()) {
1203 // A.2. Controle du objet maillage
1204 if (CORBA::is_nil(smeshMesh)) {
1205 SALOME::ExceptionStruct es;
1206 es.type = SALOME::BAD_PARAM;
1207 es.text = "The mesh object is null.";
1208 throw SALOME::SALOME_Exception(es);
1210 MESSAGE("CreateCaseOnMesh : smeshMesh is not nil");
1212 // A.3. Write mesh object in a temporary file in the working directory
1213 std::string aTmpMeshFile = theWorkingDir;
1214 aTmpMeshFile = theWorkingDir;
1215 aTmpMeshFile += std::string("/") + std::string(MeshName) + "_saved_from_SMESH";
1216 _TmpMeshFile = aTmpMeshFile + ".med";
1217 SMESH_File aFile (_TmpMeshFile, false);
1218 for (int ii = 1; aFile.exists(); ii++) {
1219 _TmpMeshFile = aTmpMeshFile + std::string("_") + std::to_string(ii) + ".med";
1220 aFile = SMESH_File(_TmpMeshFile, false);
1222 const char* MeshFile = _TmpMeshFile.c_str();
1223 bool toOverwrite = true;
1224 bool toFindOutDim = true;
1226 // Prevent dump of ExportMED
1228 SMESH::TPythonDump pDump; // do not delete this line of code
1229 smeshMesh->ExportMED(MeshFile, false, -1, toOverwrite, toFindOutDim);
1232 // A.4. Controle du fichier du maillage
1233 med_idt medIdt = MEDfileOpen(MeshFile, MED_ACC_RDONLY);
1234 bool existeMeshFile = medIdt >= 0;
1235 if (existeMeshFile) MEDfileClose(medIdt);
1236 MESSAGE("CreateCaseOnMesh : existeMeshFile = " << existeMeshFile);
1237 if (!existeMeshFile) {
1238 SALOME::ExceptionStruct es;
1239 es.type = SALOME::BAD_PARAM;
1240 es.text = "The mesh file does not exist.";
1241 throw SALOME::SALOME_Exception(es);
1244 // B. Creation de l'objet cas
1246 _CaseOnMedFile = false;
1247 _SmeshMesh = SMESH::SMESH_Mesh::_duplicate(smeshMesh);
1249 // C. Caracteristiques du maillage
1250 if (existeMeshFile) {
1251 // Les valeurs extremes des coordonnées
1252 //MESSAGE ("CreateCaseOnMesh : Les valeurs extremes des coordonnées");
1253 std::vector<double> LesExtremes = GetBoundingBoxInMedFile(MeshFile);
1254 SMESHHOMARD::extrema_var aSeq = new SMESHHOMARD::extrema();
1255 if (LesExtremes.size() != 10) { return 0; }
1257 for (int i = 0; i < LesExtremes.size(); i++)
1258 aSeq[i] = LesExtremes[i];
1259 myCase->SetBoundingBox(aSeq);
1261 //MESSAGE ("CreateCaseOnMesh : Les groupes");
1262 std::set<std::string> LesGroupes = GetListeGroupesInMedFile(MeshFile);
1263 SMESHHOMARD::ListGroupType_var aSeqGroupe = new SMESHHOMARD::ListGroupType;
1264 aSeqGroupe->length(LesGroupes.size());
1265 std::set<std::string>::const_iterator it;
1267 for (it = LesGroupes.begin(); it != LesGroupes.end(); it++)
1268 aSeqGroupe[i++] = (*it).c_str();
1269 myCase->SetGroups(aSeqGroupe);
1272 // D. L'iteration initiale du cas
1273 MESSAGE ("CreateCaseOnMesh : iteration initiale du cas");
1274 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1275 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1276 MESSAGE("CreateCaseOnMesh : ==> NomIteration = " << MeshName);
1278 // D.2. Creation de l'iteration 0
1279 myIteration0 = newIteration();
1280 myIteration0->SetName(MeshName);
1281 AssociateCaseIter(0, "IterationHomard");
1283 // D.4. Maillage correspondant
1284 if (existeMeshFile) {
1285 myIteration0->SetMeshFile(MeshFile);
1287 myIteration0->SetMeshName(MeshName);
1288 myIteration0->SetNumber(0);
1289 myIteration0->SetState(0);
1291 // Only after full initialization of Iteration0
1292 myCase->SetDirName(theWorkingDir);
1294 return SMESHHOMARD::HOMARD_Cas::_duplicate(myCase);
1297 //=============================================================================
1298 // Creation of a case
1299 // MeshName : name of the mesh
1300 // MeshFile : med file
1301 // theWorkingDir : path to working directory
1302 //=============================================================================
1303 SMESHHOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* MeshName,
1304 const char* MeshFile,
1305 const char* theWorkingDir)
1307 INFOS("CreateCase : MeshName = " << MeshName << ", MeshFile = " << MeshFile);
1310 // A.1. Controle du nom :
1311 if (!myCase->_is_nil()) {
1315 // A.3. Controle du fichier du maillage
1316 med_idt medIdt = MEDfileOpen(MeshFile, MED_ACC_RDONLY);
1317 bool existeMeshFile = medIdt >= 0;
1318 if (existeMeshFile) MEDfileClose(medIdt);
1319 MESSAGE("CreateCase : existeMeshFile = " << existeMeshFile);
1320 if (!existeMeshFile) {
1321 SALOME::ExceptionStruct es;
1322 es.type = SALOME::BAD_PARAM;
1323 es.text = "The mesh file does not exist.";
1324 throw SALOME::SALOME_Exception(es);
1327 // B. Creation de l'objet cas
1329 _CaseOnMedFile = true;
1331 // C. Caracteristiques du maillage
1332 if (existeMeshFile) {
1333 // Les valeurs extremes des coordonnées
1334 //MESSAGE ("CreateCase : Les valeurs extremes des coordonnées");
1335 std::vector<double> LesExtremes = GetBoundingBoxInMedFile(MeshFile);
1336 SMESHHOMARD::extrema_var aSeq = new SMESHHOMARD::extrema();
1337 if (LesExtremes.size() != 10) { return 0; }
1339 for (int i = 0; i < LesExtremes.size(); i++)
1340 aSeq[i] = LesExtremes[i];
1341 myCase->SetBoundingBox(aSeq);
1343 //MESSAGE ("CreateCase : Les groupes");
1344 std::set<std::string> LesGroupes = GetListeGroupesInMedFile(MeshFile);
1345 SMESHHOMARD::ListGroupType_var aSeqGroupe = new SMESHHOMARD::ListGroupType;
1346 aSeqGroupe->length(LesGroupes.size());
1347 std::set<std::string>::const_iterator it;
1349 for (it = LesGroupes.begin(); it != LesGroupes.end(); it++)
1350 aSeqGroupe[i++] = (*it).c_str();
1351 myCase->SetGroups(aSeqGroupe);
1354 // D. L'iteration initiale du cas
1355 MESSAGE ("CreateCase : iteration initiale du cas");
1356 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1357 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1358 MESSAGE("CreateCas : ==> NomIteration = " << MeshName);
1360 // D.2. Creation de l'iteration
1361 myIteration0 = newIteration();
1362 myIteration0->SetName(MeshName);
1363 AssociateCaseIter(0, "IterationHomard");
1365 // D.4. Maillage correspondant
1366 if (existeMeshFile) {
1367 myIteration0->SetMeshFile(MeshFile);
1369 myIteration0->SetMeshName(MeshName);
1370 myIteration0->SetNumber(0);
1371 myIteration0->SetState(0);
1373 // Only after full initialization of Iteration0
1374 myCase->SetDirName(theWorkingDir);
1376 return SMESHHOMARD::HOMARD_Cas::_duplicate(myCase);
1379 //=============================================================================
1380 // Create Iteration1
1381 //=============================================================================
1382 SMESHHOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration()
1384 if (CORBA::is_nil(myIteration0)) {
1385 SALOME::ExceptionStruct es;
1386 es.type = SALOME::BAD_PARAM;
1387 es.text = "The parent iteration is not defined.";
1388 throw SALOME::SALOME_Exception(es);
1391 if (CORBA::is_nil(myCase)) {
1392 SALOME::ExceptionStruct es;
1393 es.type = SALOME::BAD_PARAM;
1394 es.text = "Invalid case context";
1395 throw SALOME::SALOME_Exception(es);
1397 const char* nomDirCase = myCase->GetDirName();
1399 if (!myIteration1->_is_nil()) {
1403 myIteration1 = newIteration();
1404 if (CORBA::is_nil(myIteration1)) {
1405 SALOME::ExceptionStruct es;
1406 es.type = SALOME::BAD_PARAM;
1407 es.text = "Unable to create the iteration 1";
1408 throw SALOME::SALOME_Exception(es);
1411 // Nom de l'iteration et du maillage
1412 myIteration1->SetName("Iter_1");
1413 myIteration1->SetMeshName("Iter_1");
1414 myIteration1->SetState(1);
1415 myIteration1->SetNumber(1);
1417 int nbitercase = 1; //myCase->GetNumberofIter()
1418 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase);
1419 myIteration1->SetDirNameLoc(nomDirIter);
1421 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1422 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1423 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1424 // situation la plus frequente.
1425 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1426 // le nombre d'iterations du cas permet d'eviter les collisions.
1428 if (nbitercase < 100) { jaux = 2; }
1429 else if (nbitercase < 1000) { jaux = 3; }
1430 else if (nbitercase < 10000) { jaux = 4; }
1431 else if (nbitercase < 100000) { jaux = 5; }
1433 std::ostringstream iaux;
1434 iaux << std::setw(jaux) << std::setfill('0') << nbitercase;
1435 std::stringstream MeshFile;
1436 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1437 myIteration1->SetMeshFile(MeshFile.str().c_str());
1439 // Association avec le cas
1440 std::string nomIterParent = myIteration0->GetName();
1441 std::string label = "IterationHomard_" + nomIterParent;
1442 AssociateCaseIter(1, label.c_str());
1444 // Lien avec l'iteration precedente
1445 myIteration0->LinkNextIteration("Iter_1");
1446 myIteration1->SetIterParentName(nomIterParent.c_str());
1448 // Associate hypothesis
1449 if (CORBA::is_nil(myHypothesis)) {
1450 SMESHHOMARD::HOMARD_Gen_var engine = POA_SMESHHOMARD::HOMARD_Gen::_this();
1451 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(engine);
1452 myHypothesis = SMESHHOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1453 if (CORBA::is_nil(myHypothesis)) {
1454 SALOME::ExceptionStruct es;
1455 es.type = SALOME::BAD_PARAM;
1456 es.text = "Unable to create the hypothesis";
1457 throw SALOME::SALOME_Exception(es);
1459 //myHypothesis->SetNivMax(-1);
1460 //myHypothesis->SetDiamMin(-1.0);
1461 //myHypothesis->SetAdapInit(0);
1462 //myHypothesis->SetExtraOutput(1);
1464 myIteration1->SetHypoName("Hypo_1");
1465 myHypothesis->LinkIteration("Iter_1");
1467 return SMESHHOMARD::HOMARD_Iteration::_duplicate(myIteration1);
1469 //=============================================================================
1470 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName,
1471 CORBA::Long BoundaryType)
1473 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName <<
1474 ", BoundaryType = " << BoundaryType);
1476 // Controle du nom :
1477 if ((_mesBoundarys).find(BoundaryName) != (_mesBoundarys).end()) {
1478 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1479 SALOME::ExceptionStruct es;
1480 es.type = SALOME::BAD_PARAM;
1481 es.text = "This boundary has already been defined";
1482 throw SALOME::SALOME_Exception(es);
1485 SMESHHOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1486 myBoundary->SetName(BoundaryName);
1487 myBoundary->SetType(BoundaryType);
1489 _mesBoundarys[BoundaryName] = myBoundary;
1491 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1493 //=============================================================================
1494 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCAO(const char* BoundaryName, const char* CAOFile)
1496 MESSAGE ("CreateBoundaryCAO : BoundaryName = " << BoundaryName << ", CAOFile = " << CAOFile);
1497 SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, -1);
1498 myBoundary->SetDataFile(CAOFile);
1500 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1502 //=============================================================================
1503 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1505 MESSAGE ("CreateBoundaryDi : BoundaryName = " << BoundaryName << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile);
1506 SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1507 myBoundary->SetDataFile(MeshFile);
1508 myBoundary->SetMeshName(MeshName);
1510 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1512 //=============================================================================
1513 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1514 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1515 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1516 CORBA::Double Rayon)
1518 MESSAGE ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName);
1520 SALOME::ExceptionStruct es;
1523 { es.text = "The radius must be positive.";
1525 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe);
1526 if (daux < 0.0000001)
1527 { es.text = "The axis must be a non 0 vector.";
1531 es.type = SALOME::BAD_PARAM;
1532 throw SALOME::SALOME_Exception(es);
1536 SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1);
1537 myBoundary->SetCylinder(Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon);
1539 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1541 //=============================================================================
1542 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1543 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1544 CORBA::Double Rayon)
1546 MESSAGE ("CreateBoundarySphere : BoundaryName = " << BoundaryName);
1548 SALOME::ExceptionStruct es;
1551 { es.text = "The radius must be positive.";
1555 es.type = SALOME::BAD_PARAM;
1556 throw SALOME::SALOME_Exception(es);
1560 SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2);
1561 myBoundary->SetSphere(Xcentre, Ycentre, Zcentre, Rayon);
1563 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1565 //=============================================================================
1566 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1567 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1568 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1570 MESSAGE ("CreateBoundaryConeA : BoundaryName = " << BoundaryName);
1572 SALOME::ExceptionStruct es;
1574 if (Angle <= 0.0 || Angle >= 90.0)
1575 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees.";
1577 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe);
1578 if (daux < 0.0000001)
1579 { es.text = "The axis must be a non 0 vector.";
1583 es.type = SALOME::BAD_PARAM;
1584 throw SALOME::SALOME_Exception(es);
1588 SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3);
1589 myBoundary->SetConeA(Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre);
1591 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1593 //=============================================================================
1594 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
1595 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
1596 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
1598 MESSAGE ("CreateBoundaryConeR : BoundaryName = " << BoundaryName);
1600 SALOME::ExceptionStruct es;
1602 if (Rayon1 < 0.0 || Rayon2 < 0.0)
1603 { es.text = "The radius must be positive.";
1605 double daux = fabs(Rayon2-Rayon1);
1606 if (daux < 0.0000001)
1607 { es.text = "The radius must be different.";
1609 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1);
1610 if (daux < 0.0000001)
1611 { es.text = "The centers must be different.";
1615 es.type = SALOME::BAD_PARAM;
1616 throw SALOME::SALOME_Exception(es);
1620 SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4);
1621 myBoundary->SetConeR(Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2);
1623 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1625 //=============================================================================
1626 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
1627 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1628 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1629 CORBA::Double RayonRev, CORBA::Double RayonPri)
1631 MESSAGE ("CreateBoundaryTorus : BoundaryName = " << BoundaryName);
1633 SALOME::ExceptionStruct es;
1635 if ((RayonRev <= 0.0) || (RayonPri <= 0.0))
1636 { es.text = "The radius must be positive.";
1638 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe);
1639 if (daux < 0.0000001)
1640 { es.text = "The axis must be a non 0 vector.";
1644 es.type = SALOME::BAD_PARAM;
1645 throw SALOME::SALOME_Exception(es);
1649 SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5);
1650 myBoundary->SetTorus(Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri);
1652 return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1655 //=============================================================================
1656 //=============================================================================
1657 CORBA::Long HOMARD_Gen_i::Compute()
1663 // A.0. Create Iteration 1
1664 myIteration1 = CreateIteration();
1665 myIteration1->SetInfoCompute(_VerboseLevel);
1666 myIteration1->SetMeshName(_MeshNameOUT.c_str());
1667 myIteration1->SetMeshFile(_MeshFileOUT.c_str());
1668 if (_LogInFile) myIteration1->SetLogFile(_LogFile.c_str());
1670 // A.1. L'objet iteration
1671 ASSERT(!CORBA::is_nil(myIteration1));
1673 // A.2. Controle de la possibilite d'agir
1674 // A.2.1. Etat de l'iteration
1675 int etat = myIteration1->GetState();
1676 MESSAGE ("etat = " << etat);
1677 // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
1679 SALOME::ExceptionStruct es;
1680 es.type = SALOME::BAD_PARAM;
1681 es.text = "This iteration is already computed.";
1682 throw SALOME::SALOME_Exception(es);
1685 // A.3. Numero de l'iteration
1686 // siterp1 : numero de l'iteration a traiter
1688 // siter: numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
1689 // Ou si information :
1691 int NumeIter = myIteration1->GetNumber();
1692 std::string siterp1;
1693 std::stringstream saux1;
1695 siterp1 = saux1.str();
1696 if (NumeIter < 10) { siterp1 = "0" + siterp1; }
1699 std::stringstream saux0;
1700 int iaux = max(0, NumeIter-1);
1702 siter = saux0.str();
1703 if (NumeIter < 11) { siter = "0" + siter; }
1706 ASSERT(!CORBA::is_nil(myCase));
1708 // B. Les répertoires
1709 // B.1. Le répertoire courant
1710 std::string nomDirWork = getenv("PWD");
1711 // B.2. Le sous-répertoire de l'iteration a traiter
1712 char* DirCompute = ComputeDirManagement(myCase, myIteration1);
1713 MESSAGE(". DirCompute = " << DirCompute);
1715 // C. Le fichier des messages
1716 // C.1. Le deroulement de l'execution de HOMARD
1717 std::string LogFile = myIteration1->GetLogFile();
1718 if (LogFile.empty()) {
1719 LogFile = DirCompute;
1720 LogFile += "/Liste." + siter + ".vers." + siterp1 + ".log";
1721 myIteration1->SetLogFile(LogFile.c_str());
1723 MESSAGE (". LogFile = " << LogFile);
1724 // C.2. Le bilan de l'analyse du maillage
1725 std::string FileInfo = DirCompute;
1726 FileInfo += "/apad." + siterp1 + ".bilan";
1727 myIteration1->SetFileInfo(FileInfo.c_str());
1729 // D. On passe dans le répertoire de l'iteration a calculer
1730 MESSAGE (". On passe dans DirCompute = " << DirCompute);
1733 // E. Les données de l'exécution HOMARD
1734 // E.1. L'objet du texte du fichier de configuration
1735 SMESHHOMARDImpl::HomardDriver* myDriver = new SMESHHOMARDImpl::HomardDriver(siter, siterp1);
1736 myDriver->TexteInit(DirCompute, LogFile, "English");
1738 // E.2. Le maillage associe a l'iteration
1739 const char* NomMesh = myIteration1->GetMeshName();
1740 MESSAGE (". NomMesh = " << NomMesh);
1741 const char* MeshFile = myIteration1->GetMeshFile();
1742 MESSAGE (". MeshFile = " << MeshFile);
1744 // E.3. Les données du traitement HOMARD
1746 myDriver->TexteMaillageHOMARD(DirCompute, siterp1, iaux);
1747 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
1748 codret = ComputeAdap(myCase, myIteration1, myDriver);
1750 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
1751 int BoundaryOption = DriverTexteBoundary(myCase, myDriver);
1753 // E.5. Ecriture du texte dans le fichier
1754 MESSAGE (". Ecriture du texte dans le fichier de configuration; codret = "<<codret);
1756 { myDriver->CreeFichier(); }
1760 int codretexec = 1789;
1762 codretexec = myDriver->ExecuteHomard();
1764 MESSAGE ("Erreur en executant HOMARD : " << codretexec);
1765 // En mode adaptation, on ajuste l'etat de l'iteration
1766 if (codretexec == 0) { myIteration1->SetState(2); }
1767 else { myIteration1->SetState(1); }
1770 // H. Gestion des resultats
1772 std::string Commentaire;
1773 // H.1. Le fichier des messages, dans tous les cas
1774 Commentaire = "log";
1775 Commentaire += " " + siterp1;
1777 // H.2. Si tout s'est bien passe :
1778 if (codretexec == 0) {
1779 // H.2.1. Le fichier de bilan
1780 Commentaire = "Summary";
1781 Commentaire += " " + siterp1;
1782 // H.2.2. Le fichier de maillage obtenu
1783 std::stringstream saux0;
1784 Commentaire = "Mesh";
1785 Commentaire += " " + siterp1;
1786 if (_PublishMeshOUT) PublishResultInSmesh(MeshFile, 1);
1788 // H.3 Message d'erreur
1789 if (codretexec != 0) {
1790 std::string text = "";
1791 // Message d'erreur en cas de probleme en adaptation
1792 text = "Error during the adaptation.\n";
1793 bool stopvu = false;
1794 std::ifstream fichier(LogFile.c_str());
1795 if (fichier) { // ce test échoue si le fichier n'est pas ouvert
1796 std::string ligne; // variable contenant chaque ligne lue
1797 while (std::getline(fichier, ligne)) {
1799 if (stopvu) { text += ligne+ "\n"; }
1801 int position = ligne.find("===== HOMARD ===== STOP =====");
1802 if (position > 0) { stopvu = true; }
1806 text += "\n\nSee the file " + LogFile + "\n";
1808 SALOME::ExceptionStruct es;
1809 es.type = SALOME::BAD_PARAM;
1810 es.text = CORBA::string_dup(text.c_str());
1811 throw SALOME::SALOME_Exception(es);
1815 // I. Menage et retour dans le répertoire du cas
1818 MESSAGE (". On retourne dans nomDirWork = " << nomDirWork);
1819 CHDIR(nomDirWork.c_str());
1822 // J. Suivi de la frontière CAO
1824 if ((BoundaryOption % 5 == 0) && (codretexec == 0)) {
1825 MESSAGE ("Suivi de frontière CAO");
1826 codret = ComputeCAO(myCase, myIteration1);
1830 if (codretexec == 0) {
1841 void HOMARD_Gen_i::CleanCase()
1843 // Delete log file, if required
1844 MESSAGE("myIteration1->GetLogFile() = " << myIteration1->GetLogFile());
1845 if (_LogInFile && _RemoveLogOnSuccess) {
1846 // Remove log file on success
1847 SMESH_File(myIteration1->GetLogFile(), false).remove();
1850 // Delete all boundaries
1851 std::map<std::string, SMESHHOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
1852 for (it_boundary = _mesBoundarys.begin();
1853 it_boundary != _mesBoundarys.end(); ++it_boundary) {
1854 DeleteBoundary((*it_boundary).first.c_str());
1860 // Delete hypothesis
1861 // Hypothesis should be deleted only after iteration deletion
1862 myHypothesis = SMESHHOMARD::HOMARD_Hypothesis::_nil();
1867 // Delete tmp mesh file
1868 if (!_CaseOnMedFile && !_TmpMeshFile.empty()) {
1869 SMESH_File aFile (_TmpMeshFile, false);
1870 if (aFile.exists()) aFile.remove();
1872 _SmeshMesh = SMESH::SMESH_Mesh::_nil();
1875 //=============================================================================
1876 // Calcul d'une iteration : partie spécifique à l'adaptation
1877 //=============================================================================
1878 CORBA::Long HOMARD_Gen_i::ComputeAdap(SMESHHOMARD::HOMARD_Cas_var myCase,
1879 SMESHHOMARD::HOMARD_Iteration_var myIteration,
1880 SMESHHOMARDImpl::HomardDriver* myDriver)
1882 MESSAGE ("ComputeAdap");
1887 // Numero de l'iteration
1888 int NumeIter = myIteration->GetNumber();
1889 std::stringstream saux0;
1890 saux0 << NumeIter-1;
1891 std::string siter = saux0.str();
1892 if (NumeIter < 11) { siter = "0" + siter; }
1894 // A.2. On verifie qu il y a une hypothese (erreur improbable);
1895 ASSERT(!CORBA::is_nil(myHypothesis));
1897 // B. L'iteration parent
1898 //const char* nomIterationParent = myIteration->GetIterParentName();
1899 SMESHHOMARD::HOMARD_Iteration_var myIterationParent = myIteration0;
1900 ASSERT(!CORBA::is_nil(myIterationParent));
1901 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
1902 //if (myIterationParent->GetState() == 1) {
1903 // int codret = Compute(nomIterationParent);
1904 // if (codret != 0) VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
1907 // C. Le sous-répertoire de l'iteration precedente
1908 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
1909 MESSAGE(". DirComputePa = " << DirComputePa);
1911 // D. Les données de l'adaptation HOMARD
1912 // D.1. Le type de conformite
1913 int ConfType = myCase->GetConfType();
1914 MESSAGE (". ConfType = " << ConfType);
1916 // D.3. Le maillage de depart
1917 const char* NomMeshParent = myIterationParent->GetMeshName();
1918 MESSAGE (". NomMeshParent = " << NomMeshParent);
1919 const char* MeshFileParent = myIterationParent->GetMeshFile();
1920 MESSAGE (". MeshFileParent = " << MeshFileParent);
1922 // D.4. Le maillage associe a l'iteration
1923 const char* MeshFile = myIteration->GetMeshFile();
1924 MESSAGE (". MeshFile = " << MeshFile);
1925 FILE *file = fopen(MeshFile,"r");
1928 // CleanOption = 0 : report an error if output mesh file exists
1929 // CleanOption = 1 : destruction du répertoire d'execution
1930 int CleanOption = 1;
1931 if (CleanOption == 0) {
1932 SALOME::ExceptionStruct es;
1933 es.type = SALOME::BAD_PARAM;
1934 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
1935 es.text = CORBA::string_dup(text.c_str());
1936 throw SALOME::SALOME_Exception(es);
1939 std::string commande = "rm -f " + std::string(MeshFile);
1940 codret = system(commande.c_str());
1942 SALOME::ExceptionStruct es;
1943 es.type = SALOME::BAD_PARAM;
1944 es.text = "The mesh file cannot be deleted.";
1945 throw SALOME::SALOME_Exception(es);
1950 // D.5. Les types de raffinement et de deraffinement
1951 // Les appels corba sont lourds, il vaut mieux les grouper
1952 //SMESHHOMARD::listeTypes* ListTypes = myHypothesis->GetAdapRefinUnRef();
1953 //ASSERT(ListTypes->length() == 3);
1954 int TypeAdap = -1; // HomardHypothesis->GetAdapType()
1955 int TypeRaff = 1; // HomardHypothesis->GetRefinType()
1956 int TypeDera = 0; // HomardHypothesis->GetUnRefType()
1958 // E. Texte du fichier de configuration
1959 // E.1. Incontournables du texte
1960 myDriver->TexteAdap();
1962 myDriver->TexteMaillageHOMARD(DirComputePa, siter, iaux);
1963 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
1964 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
1966 // E.6. Ajout des options avancees
1967 //int NivMax = myHypo->GetNivMax();
1968 //MESSAGE (". NivMax = " << NivMax);
1969 //double DiamMin = myHypo->GetDiamMin();
1970 //MESSAGE (". DiamMin = " << DiamMin);
1971 //int AdapInit = myHypo->GetAdapInit();
1972 //MESSAGE (". AdapInit = " << AdapInit);
1973 //int ExtraOutput = myHypo->GetExtraOutput();
1974 //MESSAGE (". ExtraOutput = " << ExtraOutput);
1975 //myDriver->TexteAdvanced(NivMax, DiamMin, AdapInit, ExtraOutput);
1976 myDriver->TexteAdvanced(-1, -1.0, 0, 1);
1978 // E.7. Ajout des informations sur le deroulement de l'execution
1979 int MessInfo = myIteration->GetInfoCompute();
1980 MESSAGE (". MessInfo = " << MessInfo);
1981 myDriver->TexteInfoCompute(MessInfo);
1985 //=============================================================================
1986 // Calcul d'une iteration : partie spécifique au suivi de frontière CAO
1987 //=============================================================================
1988 CORBA::Long HOMARD_Gen_i::ComputeCAO(SMESHHOMARD::HOMARD_Cas_var myCase,
1989 SMESHHOMARD::HOMARD_Iteration_var myIteration)
1991 MESSAGE ("ComputeCAO");
1996 // A.2. Le sous-répertoire de l'iteration en cours de traitement
1997 char* DirCompute = myIteration->GetDirName();
1998 // A.3. Le maillage résultat de l'iteration en cours de traitement
1999 char* MeshFile = myIteration->GetMeshFile();
2001 // B. Les données pour FrontTrack
2002 // B.1. Le maillage à modifier
2003 const std::string theInputMedFile = MeshFile;
2004 MESSAGE (". theInputMedFile = " << theInputMedFile);
2006 // B.2. Le maillage après modification : fichier identique
2007 const std::string theOutputMedFile = MeshFile;
2008 MESSAGE (". theOutputMedFile = " << theInputMedFile);
2010 // B.3. La liste des fichiers contenant les numéros des noeuds à bouger
2011 std::vector< std::string > theInputNodeFiles;
2012 MESSAGE (". DirCompute = " << DirCompute);
2013 std::basic_string<char>::size_type bilan;
2017 struct dirent *dirp;
2018 dp = opendir(DirCompute);
2019 while ((dirp = readdir(dp)) != NULL)
2021 std::string file_name(dirp->d_name);
2022 bilan = file_name.find("fr");
2023 if (bilan != string::npos)
2025 std::stringstream filename_total;
2026 filename_total << DirCompute << "/" << file_name;
2027 theInputNodeFiles.push_back(filename_total.str());
2032 HANDLE hFind = INVALID_HANDLE_VALUE;
2033 WIN32_FIND_DATA ffd;
2034 hFind = FindFirstFile(DirNameStart, &ffd);
2035 if (INVALID_HANDLE_VALUE != hFind) {
2036 while (FindNextFile(hFind, &ffd) != 0) {
2037 std::string file_name(ffd.cFileName);
2038 bilan = file_name.find("fr");
2039 if (bilan != string::npos)
2041 std::stringstream filename_total;
2042 filename_total << DirCompute << "/" << file_name;
2043 theInputNodeFiles.push_back(filename_total.str());
2050 for (int i = 0; i < icpt; i++)
2051 { MESSAGE (". theInputNodeFiles["<< i << "] = " << theInputNodeFiles[i]); }
2053 // B.4. Le fichier de la CAO
2054 SMESHHOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2055 std::string BoundaryName = std::string((*ListBoundaryGroupType)[0]);
2056 MESSAGE (". BoundaryName = " << BoundaryName);
2057 SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[BoundaryName];
2058 const std::string theXaoFileName = myBoundary->GetDataFile();
2059 MESSAGE (". theXaoFileName = " << theXaoFileName);
2061 // B.5. Parallélisme
2062 //bool theIsParallel = false;
2064 // C. Lancement des projections
2065 MESSAGE (". Lancement des projections");
2067 //FrontTrack* myFrontTrack = new FrontTrack();
2068 //myFrontTrack->track(theInputMedFile, theOutputMedFile, theInputNodeFiles, theXaoFileName, theIsParallel);
2070 // D. Transfert des coordonnées modifiées dans le fichier historique de HOMARD
2071 // On lance une exécution spéciale de HOMARD en attendant de savoir le faire avec MEDCoupling
2072 MESSAGE (". Transfert des coordonnées");
2073 codret = ComputeCAObis(myIteration);
2077 //=============================================================================
2078 //=============================================================================
2079 // Transfert des coordonnées en suivi de frontière CAO
2080 //=============================================================================
2081 CORBA::Long HOMARD_Gen_i::ComputeCAObis(SMESHHOMARD::HOMARD_Iteration_var myIteration)
2083 MESSAGE ("ComputeCAObis");
2088 // A.1. Controle de la possibilite d'agir
2089 // A.1.1. Etat de l'iteration
2090 int etat = myIteration->GetState();
2091 MESSAGE ("etat = " << etat);
2092 // A.1.2. L'iteration doit être calculee
2094 SALOME::ExceptionStruct es;
2095 es.type = SALOME::BAD_PARAM;
2096 es.text = "This iteration is not computed.";
2097 throw SALOME::SALOME_Exception(es);
2100 // A.2. Numero de l'iteration
2101 // siterp1 : numero de l'iteration a traiter
2102 int NumeIter = myIteration->GetNumber();
2103 std::string siterp1;
2104 std::stringstream saux1;
2106 siterp1 = saux1.str();
2107 if (NumeIter < 10) { siterp1 = "0" + siterp1; }
2108 MESSAGE ("siterp1 = "<<siterp1);
2111 ASSERT(!CORBA::is_nil(myCase));
2113 // A.4. Le sous-répertoire de l'iteration a traiter
2114 char* DirCompute = myIteration->GetDirName();
2115 MESSAGE(". DirCompute = " << DirCompute);
2117 // C. Le fichier des messages
2118 std::string LogFile = DirCompute;
2119 LogFile += "/Liste." + siterp1 + ".maj_coords.log";
2120 MESSAGE (". LogFile = " << LogFile);
2121 myIteration->SetFileInfo(LogFile.c_str());
2123 // D. On passe dans le répertoire de l'iteration a calculer
2124 MESSAGE (". On passe dans DirCompute = " << DirCompute);
2127 // E. Les données de l'exécution HOMARD
2128 // E.1. L'objet du texte du fichier de configuration
2129 SMESHHOMARDImpl::HomardDriver* myDriver = new SMESHHOMARDImpl::HomardDriver("", siterp1);
2130 myDriver->TexteInit(DirCompute, LogFile, "English");
2132 // E.2. Le maillage associe a l'iteration
2133 const char* NomMesh = myIteration->GetMeshName();
2134 MESSAGE (". NomMesh = " << NomMesh);
2135 const char* MeshFile = myIteration->GetMeshFile();
2136 MESSAGE (". MeshFile = " << MeshFile);
2138 // E.3. Les données du traitement HOMARD
2139 myDriver->TexteMajCoords(NumeIter);
2141 myDriver->TexteMaillageHOMARD(DirCompute, siterp1, iaux);
2142 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2144 // E.4. Ecriture du texte dans le fichier
2145 MESSAGE (". Ecriture du texte dans le fichier de configuration; codret = "<<codret);
2146 if (codret == 0) myDriver->CreeFichier();
2150 int codretexec = 1789;
2152 codretexec = myDriver->ExecuteHomard();
2153 MESSAGE ("Erreur en executant HOMARD : " << codretexec);
2156 // G. Gestion des resultats
2158 // G.1. Le fichier des messages, dans tous les cas
2159 std::string Commentaire = "logmaj_coords";
2160 // G.2 Message d'erreur
2161 if (codretexec != 0) {
2162 std::string text = "\n\nSee the file " + LogFile + "\n";
2164 SALOME::ExceptionStruct es;
2165 es.type = SALOME::BAD_PARAM;
2166 es.text = CORBA::string_dup(text.c_str());
2167 throw SALOME::SALOME_Exception(es);
2169 // On force le succes pour pouvoir consulter le fichier log
2174 // H. Menage et retour dans le répertoire du cas
2175 if (codret == 0) { delete myDriver; }
2179 //=============================================================================
2180 // Creation d'un nom de sous-répertoire pour l'iteration au sein d'un répertoire parent
2181 // nomrep : nom du répertoire parent
2182 // num : le nom du sous-répertoire est sous la forme 'In', n est >= num
2183 //=============================================================================
2184 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num)
2186 MESSAGE ("CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2187 // On verifie que le répertoire parent existe
2188 int codret = CHDIR(nomrep);
2190 SALOME::ExceptionStruct es;
2191 es.type = SALOME::BAD_PARAM;
2192 es.text = "The directory of the case does not exist.";
2193 throw SALOME::SALOME_Exception(es);
2195 std::string nomDirActuel = getenv("PWD");
2196 std::string DirName;
2197 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un répertoire inconnu
2198 bool a_chercher = true;
2199 while (a_chercher) {
2200 // On passe dans le répertoire parent
2203 // On recherche un nom sous la forme Iabc, avec abc representant le numero
2205 if (num < 100) { jaux = 2; }
2206 else if (num < 1000) { jaux = 3; }
2207 else if (num < 10000) { jaux = 4; }
2208 else if (num < 100000) { jaux = 5; }
2210 std::ostringstream iaux;
2211 iaux << std::setw(jaux) << std::setfill('0') << num;
2212 std::ostringstream DirNameA;
2213 DirNameA << "I" << iaux.str();
2214 // Si on ne pas peut entrer dans le répertoire, on doit verifier
2215 // que c'est bien un probleme d'absence
2216 if (CHDIR(DirNameA.str().c_str()) != 0)
2218 bool existe = false;
2221 struct dirent *dirp;
2222 dp = opendir(nomrep);
2223 while ((dirp = readdir(dp)) != NULL)
2225 std::string file_name(dirp->d_name);
2227 HANDLE hFind = INVALID_HANDLE_VALUE;
2228 WIN32_FIND_DATA ffd;
2229 hFind = FindFirstFile(nomrep, &ffd);
2230 if (INVALID_HANDLE_VALUE != hFind) {
2231 while (FindNextFile(hFind, &ffd) != 0) {
2232 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2233 std::string file_name(ffd.cFileName);
2235 if (file_name == DirNameA.str()) { existe = true; }
2244 DirName = DirNameA.str();
2252 MESSAGE ("==> DirName = " << DirName);
2253 MESSAGE (". On retourne dans nomDirActuel = " << nomDirActuel);
2254 CHDIR(nomDirActuel.c_str());
2255 return CORBA::string_dup(DirName.c_str());
2257 //=============================================================================
2258 // Calcul d'une iteration : gestion du répertoire de calcul
2259 //=============================================================================
2260 char* HOMARD_Gen_i::ComputeDirManagement(SMESHHOMARD::HOMARD_Cas_var myCase,
2261 SMESHHOMARD::HOMARD_Iteration_var myIteration)
2263 MESSAGE ("ComputeDirManagement : répertoires pour le calcul");
2265 //Si le sous-répertoire existe :
2266 // CleanOption = 0 : on sort en erreur si le répertoire n'est pas vide
2267 // CleanOption = 1 : on fait le menage du répertoire
2268 // CleanOption = -1 : on ne fait rien
2269 int CleanOption = 0;
2271 // B.2. Le répertoire du cas
2272 const char* nomDirCase = myCase->GetDirName();
2273 MESSAGE (". nomDirCase = " << nomDirCase);
2275 // B.3. Le sous-répertoire de l'iteration a calculer, puis le répertoire complet a creer
2276 // B.3.1. Le nom du sous-répertoire
2277 const char* nomDirIt = myIteration->GetDirNameLoc();
2279 // B.3.2. Le nom complet du sous-répertoire
2280 std::stringstream DirCompute;
2281 DirCompute << nomDirCase << "/" << nomDirIt;
2282 MESSAGE (". DirCompute = " << DirCompute.str());
2284 // B.3.3. Si le sous-répertoire n'existe pas, on le cree
2285 if (CHDIR(DirCompute.str().c_str()) != 0)
2288 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2290 if (_mkdir(DirCompute.str().c_str()) != 0)
2293 // GERALD -- QMESSAGE BOX
2294 std::cerr << "Pb Creation du répertoire DirCompute = " << DirCompute.str() << std::endl;
2295 VERIFICATION("Pb a la creation du répertoire" == 0);
2300 // Le répertoire existe
2301 // On demande de faire le menage de son contenu :
2302 if (CleanOption == 1) {
2303 MESSAGE (". Menage du répertoire DirCompute = " << DirCompute.str());
2304 std::string commande = "rm -rf " + DirCompute.str()+"/*";
2305 int codret = system(commande.c_str());
2308 // GERALD -- QMESSAGE BOX
2309 std::cerr << ". Menage du répertoire de calcul" << DirCompute.str() << std::endl;
2310 VERIFICATION("Pb au menage du répertoire de calcul" == 0);
2313 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2315 if (CleanOption == 0) {
2318 struct dirent *dirp;
2319 dp = opendir(DirCompute.str().c_str());
2321 while ((dirp = readdir(dp)) != NULL && result)
2323 std::string file_name(dirp->d_name);
2324 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2328 HANDLE hFind = INVALID_HANDLE_VALUE;
2329 WIN32_FIND_DATA ffd;
2330 hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
2332 if (INVALID_HANDLE_VALUE != hFind) {
2333 while (FindNextFile(hFind, &ffd) != 0) {
2334 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2335 std::string file_name(ffd.cFileName);
2336 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2341 if (result == false)
2343 SALOME::ExceptionStruct es;
2344 es.type = SALOME::BAD_PARAM;
2345 std::string text = "Directory : " + DirCompute.str() + " is not empty";
2346 es.text = CORBA::string_dup(text.c_str());
2347 throw SALOME::SALOME_Exception(es);
2348 VERIFICATION("Directory is not empty" == 0);
2354 return CORBA::string_dup(DirCompute.str().c_str());
2356 //=============================================================================
2357 // Calcul d'une iteration : gestion du répertoire de calcul de l'iteration parent
2358 //=============================================================================
2359 char* HOMARD_Gen_i::ComputeDirPaManagement(SMESHHOMARD::HOMARD_Cas_var myCase, SMESHHOMARD::HOMARD_Iteration_var myIteration)
2361 MESSAGE ("ComputeDirPaManagement : répertoires pour le calcul");
2362 // Le répertoire du cas
2363 const char* nomDirCase = myCase->GetDirName();
2364 MESSAGE (". nomDirCase = " << nomDirCase);
2366 // Le sous-répertoire de l'iteration precedente
2368 SMESHHOMARD::HOMARD_Iteration_var myIterationParent = myIteration0;
2369 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2370 std::stringstream DirComputePa;
2371 DirComputePa << nomDirCase << "/" << nomDirItPa;
2372 MESSAGE(". nomDirItPa = " << nomDirItPa);
2373 MESSAGE(". DirComputePa = " << DirComputePa.str());
2375 return CORBA::string_dup(DirComputePa.str().c_str());
2378 //=============================================================================
2379 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
2380 // On ecrit dans l'ordre :
2381 // 1. la definition des frontieres
2382 // 2. les liens avec les groupes
2383 // 3. un entier resumant le type de comportement pour les frontieres
2384 //=============================================================================
2385 int HOMARD_Gen_i::DriverTexteBoundary(SMESHHOMARD::HOMARD_Cas_var myCase, SMESHHOMARDImpl::HomardDriver* myDriver)
2387 MESSAGE ("... DriverTexteBoundary");
2388 // 1. Recuperation des frontieres
2389 std::list<std::string> ListeBoundaryTraitees;
2390 SMESHHOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2391 int numberOfitems = ListBoundaryGroupType->length();
2392 MESSAGE ("... number of string for Boundary+Group = " << numberOfitems);
2393 int BoundaryOption = 1;
2394 // 2. Parcours des frontieres pour ecrire leur description
2395 int NumBoundaryAnalytical = 0;
2396 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2398 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2399 MESSAGE ("... BoundaryName = " << BoundaryName);
2400 // 2.1. La frontiere a-t-elle deja ete ecrite ?
2401 // Cela arrive quand elle est liee a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
2403 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
2404 while (it != ListeBoundaryTraitees.end())
2406 MESSAGE ("..... BoundaryNameTraitee = " << *it);
2407 if (BoundaryName == *it) { A_faire = 0; }
2410 // 2.2. Ecriture de la frontiere
2413 // 2.2.1. Caracteristiques de la frontiere
2414 SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[BoundaryName];
2415 ASSERT(!CORBA::is_nil(myBoundary));
2416 int BoundaryType = myBoundary->GetType();
2417 MESSAGE ("... BoundaryType = " << BoundaryType);
2418 // 2.2.2. Ecriture selon le type
2419 // 2.2.2.1. Cas d une frontiere CAO
2420 if (BoundaryType == -1)
2422 // const char* CAOFile = myBoundary->GetDataFile();
2423 // MESSAGE (". CAOFile = " << CAOFile);
2424 if (BoundaryOption % 5 != 0) { BoundaryOption = BoundaryOption*5; }
2426 // 2.2.2.2. Cas d une frontiere discrete
2427 else if (BoundaryType == 0)
2429 const char* MeshName = myBoundary->GetMeshName();
2430 MESSAGE (". MeshName = " << MeshName);
2431 const char* MeshFile = myBoundary->GetDataFile();
2432 MESSAGE (". MeshFile = " << MeshFile);
2433 myDriver->TexteBoundaryDi(MeshName, MeshFile);
2434 if (BoundaryOption % 2 != 0) { BoundaryOption = BoundaryOption*2; }
2436 // 2.2.2.3. Cas d une frontiere analytique
2439 NumBoundaryAnalytical++;
2440 SMESHHOMARD::double_array* coor = myBoundary->GetCoords();
2441 if (BoundaryType == 1) // Cas d un cylindre
2443 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2444 if (BoundaryOption % 3 != 0) { BoundaryOption = BoundaryOption*3; }
2446 else if (BoundaryType == 2) // Cas d une sphere
2448 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
2449 if (BoundaryOption % 3 != 0) { BoundaryOption = BoundaryOption*3; }
2451 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
2453 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2454 if (BoundaryOption % 3 != 0) { BoundaryOption = BoundaryOption*3; }
2456 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
2458 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
2459 if (BoundaryOption % 3 != 0) { BoundaryOption = BoundaryOption*3; }
2461 else if (BoundaryType == 5) // Cas d un tore
2463 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
2464 if (BoundaryOption % 3 != 0) { BoundaryOption = BoundaryOption*3; }
2467 // 2.2.3. Memorisation du traitement
2468 ListeBoundaryTraitees.push_back(BoundaryName);
2471 // 3. Parcours des frontieres pour ecrire les liens avec les groupes
2472 NumBoundaryAnalytical = 0;
2473 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2475 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2476 MESSAGE ("... BoundaryName = " << BoundaryName);
2477 SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[BoundaryName];
2478 ASSERT(!CORBA::is_nil(myBoundary));
2479 int BoundaryType = myBoundary->GetType();
2480 MESSAGE ("... BoundaryType = " << BoundaryType);
2481 // 3.1. Recuperation du nom du groupe
2482 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
2483 MESSAGE ("... GroupName = " << GroupName);
2484 // 3.2. Cas d une frontiere CAO
2485 if (BoundaryType == -1)
2487 if (GroupName.size() > 0) { myDriver->TexteBoundaryCAOGr (GroupName); }
2489 // 3.3. Cas d une frontiere discrete
2490 else if (BoundaryType == 0)
2492 if (GroupName.size() > 0) { myDriver->TexteBoundaryDiGr (GroupName); }
2494 // 3.4. Cas d une frontiere analytique
2497 NumBoundaryAnalytical++;
2498 myDriver->TexteBoundaryAnGr (BoundaryName, NumBoundaryAnalytical, GroupName);
2501 // 4. Ecriture de l'option finale
2502 myDriver->TexteBoundaryOption(BoundaryOption);
2504 return BoundaryOption;
2506 //===========================================================================
2507 //===========================================================================
2509 //===========================================================================
2511 // Option = 0 : fichier issu d'une importation
2512 // Option = 1 : fichier issu d'une execution HOMARD
2513 //===========================================================================
2514 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
2516 // Prevent dump of CreateMeshesFromMED
2517 SMESH::TPythonDump pDump; // do not delete this line of code
2519 MESSAGE("PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
2520 if (CORBA::is_nil(SMESH_Gen_i::GetSMESHGen()->getStudyServant())) {
2521 SALOME::ExceptionStruct es;
2522 es.type = SALOME::BAD_PARAM;
2523 es.text = "Invalid study context";
2524 throw SALOME::SALOME_Exception(es);
2527 // Le module SMESH est-il actif ?
2528 SALOMEDS::SObject_var aSmeshSO =
2529 SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindComponent("SMESH");
2532 // Temporary suppressed depublication of mesh with the same name of file
2534 if (!CORBA::is_nil(aSmeshSO)) {
2535 // On verifie que le fichier n est pas deja publie
2536 SALOMEDS::ChildIterator_var aIter =
2537 SMESH_Gen_i::GetSMESHGen()->getStudyServant()->NewChildIterator(aSmeshSO);
2538 for (; aIter->More(); aIter->Next()) {
2539 SALOMEDS::SObject_var aSO = aIter->Value();
2540 SALOMEDS::GenericAttribute_var aGAttr;
2541 if (aSO->FindAttribute(aGAttr, "AttributeExternalFileDef")) {
2542 SALOMEDS::AttributeExternalFileDef_var anAttr =
2543 SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2544 CORBA::String_var value = anAttr->Value();
2545 if (strcmp((const char*)value, NomFich) == 0) {
2546 MESSAGE ("PublishResultInSmesh : le fichier " << NomFich << " est deja publie.");
2547 // Pour un fichier importe, on ne republie pas
2548 if (Option == 0) { return; }
2549 // Pour un fichier calcule, on commence par faire la depublication
2551 MESSAGE("PublishResultInSmesh : depublication");
2552 if (aSO->FindAttribute(aGAttr, "AttributeName")) {
2553 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2554 CORBA::String_var value2 = anAttr2->Value();
2555 std::string MeshName = string(value2);
2556 MESSAGE("PublishResultInSmesh : depublication de " << MeshName);
2557 DeleteResultInSmesh(NomFich, MeshName);
2566 // On enregistre le fichier
2567 MESSAGE("Enregistrement du fichier");
2569 //SMESH::SMESH_Gen_var aSmeshEngine = this->retrieveSMESHInst();
2570 SMESH_Gen_i* aSmeshEngine = SMESH_Gen_i::GetSMESHGen();
2572 //ASSERT(!CORBA::is_nil(aSmeshEngine));
2573 aSmeshEngine->UpdateStudy();
2574 SMESH::DriverMED_ReadStatus theStatus;
2576 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
2577 SMESH::mesh_array* mesMaillages = aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
2578 if (CORBA::is_nil(aSmeshSO)) {
2579 aSmeshSO = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindComponent("SMESH");
2580 if (CORBA::is_nil(aSmeshSO)) return;
2583 for (int i = 0; i < (int)mesMaillages->length(); i++) {
2584 MESSAGE(". Mise a jour des attributs du maillage");
2585 SMESH::SMESH_Mesh_var monMaillage = (*mesMaillages)[i];
2586 SALOMEDS::SObject_var aSO = SALOMEDS::SObject::_narrow
2587 (SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindObjectIOR
2588 (SMESH_Gen_i::GetORB()->object_to_string(monMaillage)));
2589 SALOMEDS::StudyBuilder_var aStudyBuilder =
2590 SMESH_Gen_i::GetSMESHGen()->getStudyServant()->NewBuilder();
2591 SALOMEDS::GenericAttribute_var aGAttr =
2592 aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
2593 SALOMEDS::AttributeExternalFileDef_var anAttr =
2594 SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2595 anAttr->SetValue(NomFich);
2596 SALOMEDS::GenericAttribute_var aPixMap =
2597 aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap");
2598 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
2600 if (Option == 0) { icone = "mesh_tree_importedmesh.png"; }
2601 else { icone = "mesh_tree_mesh.png"; }
2602 anAttr2->SetPixMap(icone);
2606 //=============================================================================
2607 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
2609 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich);
2610 if (CORBA::is_nil(SMESH_Gen_i::GetSMESHGen()->getStudyServant())) {
2611 SALOME::ExceptionStruct es;
2612 es.type = SALOME::BAD_PARAM;
2613 es.text = "Invalid study context";
2614 throw SALOME::SALOME_Exception(es);
2617 // Le module SMESH est-il actif ?
2618 SALOMEDS::SObject_var aSmeshSO =
2619 SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindComponent("SMESH");
2621 if (CORBA::is_nil(aSmeshSO)) return;
2622 // On verifie que le fichier est deja publie
2623 SALOMEDS::StudyBuilder_var myBuilder =
2624 SMESH_Gen_i::GetSMESHGen()->getStudyServant()->NewBuilder();
2625 SALOMEDS::ChildIterator_var aIter =
2626 SMESH_Gen_i::GetSMESHGen()->getStudyServant()->NewChildIterator(aSmeshSO);
2627 for (; aIter->More(); aIter->Next()) {
2628 SALOMEDS::SObject_var aSO = aIter->Value();
2629 SALOMEDS::GenericAttribute_var aGAttr;
2630 if (aSO->FindAttribute(aGAttr, "AttributeExternalFileDef")) {
2631 SALOMEDS::AttributeExternalFileDef_var anAttr =
2632 SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2633 CORBA::String_var value = anAttr->Value();
2634 if (strcmp((const char*)value, NomFich.c_str()) == 0) {
2635 if (aSO->FindAttribute(aGAttr, "AttributeName")) {
2636 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2637 CORBA::String_var value2 = anAttr2->Value();
2638 if (strcmp((const char*)value2, MeshName.c_str()) == 0) {
2639 myBuilder->RemoveObjectWithChildren(aSO);
2647 void HOMARD_Gen_i::PythonDump()
2649 MESSAGE ("Begin PythonDump");
2650 SMESH::TPythonDump pd;
2653 pd << "import SMESHHOMARD\n";
2654 //pd << "smeshhomard = " << SMESH_Gen_i::GetSMESHGen() << ".CreateHOMARD_ADAPT()\n";
2655 pd << "smeshhomard = " << SMESH_Gen_i::GetSMESHGen() << ".Adaptation(\"Uniform\")\n";
2658 if (_mesBoundarys.size() > 0) MESSAGE(". Creation of the boundaries");
2659 std::map<std::string, SMESHHOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2660 for (it_boundary = _mesBoundarys.begin();
2661 it_boundary != _mesBoundarys.end(); ++it_boundary) {
2662 SMESHHOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
2663 pd << maBoundary->GetDumpPython();
2667 ASSERT(!myCase->_is_nil());
2668 MESSAGE (". Creation of the case");
2670 if (_CaseOnMedFile) {
2671 pd << "Case_1 = smeshhomard.CreateCase(\"" << myIteration0->GetMeshName();
2672 pd << "\", \"" << myIteration0->GetMeshFile();
2673 pd << "\", \"" << myCase->GetDirName() << "\")\n";
2676 pd << "Case_1 = smeshhomard.CreateCaseOnMesh(\"" << myIteration0->GetMeshName();
2677 pd << "\", " << _SmeshMesh;
2678 pd << ".GetMesh(), \"" << myCase->GetDirName() << "\")\n";
2681 pd << myCase->GetDumpPython();
2684 pd << "smeshhomard.SetKeepMedOUT(" << (_KeepMedOUT ? "True" : "False") << ")\n";
2685 pd << "smeshhomard.SetPublishMeshOUT(" << (_PublishMeshOUT ? "True" : "False") << ")\n";
2686 pd << "smeshhomard.SetMeshNameOUT(\"" << _MeshNameOUT << "\")\n";
2687 pd << "smeshhomard.SetMeshFileOUT(\"" << _MeshFileOUT << "\")\n";
2689 pd << "smeshhomard.SetKeepWorkingFiles(" << (_KeepWorkingFiles ? "True" : "False") << ")\n";
2690 pd << "smeshhomard.SetLogInFile(" << (_LogInFile ? "True" : "False") << ")\n";
2691 if (_LogInFile) pd << "smeshhomard.SetLogFile(\"" << _LogFile << "\")\n";
2692 pd << "smeshhomard.SetRemoveLogOnSuccess(" << (_RemoveLogOnSuccess ? "True" : "False") << ")\n";
2693 pd << "smeshhomard.SetVerboseLevel(" << _VerboseLevel << ")\n";
2696 pd << "smeshhomard.Compute()\n";
2697 MESSAGE ("End PythonDump");
2700 //===============================================================================
2702 //===============================================================================
2703 void HOMARD_Gen_i::SetKeepMedOUT(bool theKeepMedOUT)
2705 _KeepMedOUT = theKeepMedOUT;
2707 void HOMARD_Gen_i::SetPublishMeshOUT(bool thePublishMeshOUT)
2709 _PublishMeshOUT = thePublishMeshOUT;
2711 void HOMARD_Gen_i::SetKeepWorkingFiles(bool theKeepWorkingFiles)
2713 _KeepWorkingFiles = theKeepWorkingFiles;
2715 void HOMARD_Gen_i::SetLogInFile(bool theLogInFile)
2717 _LogInFile = theLogInFile;
2719 void HOMARD_Gen_i::SetRemoveLogOnSuccess(bool theRemoveLogOnSuccess)
2721 _RemoveLogOnSuccess = theRemoveLogOnSuccess;
2723 void HOMARD_Gen_i::SetVerboseLevel(CORBA::Long theVerboseLevel)
2725 _VerboseLevel = theVerboseLevel;
2727 void HOMARD_Gen_i::SetMeshNameOUT(const char* theMeshNameOUT)
2729 _MeshNameOUT = theMeshNameOUT;
2731 void HOMARD_Gen_i::SetMeshFileOUT(const char* theMeshFileOUT)
2733 _MeshFileOUT = theMeshFileOUT;
2735 void HOMARD_Gen_i::SetLogFile(const char* theLogFile)
2737 _LogFile = theLogFile;
2740 // =======================================================================
2741 std::set<std::string> GetListeGroupesInMedFile(const char * aFile)
2743 std::set<std::string> ListeGroupes;
2746 while (erreur == 0) {
2747 // Ouverture du fichier
2748 medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY);
2753 // Caracteristiques du maillage
2754 char meshname[MED_NAME_SIZE+1];
2755 med_int spacedim,meshdim;
2756 med_mesh_type meshtype;
2757 char descriptionription[MED_COMMENT_SIZE+1];
2758 char dtunit[MED_SNAME_SIZE+1];
2759 med_sorting_type sortingtype;
2761 med_axis_type axistype;
2762 int naxis = MEDmeshnAxis(medIdt,1);
2763 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
2764 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
2765 erreur = MEDmeshInfo(medIdt,
2780 if (erreur < 0) { break; }
2781 // Nombre de familles
2783 nfam = MEDnFamily(medIdt,meshname);
2788 // Lecture des caracteristiques des familles
2789 for (int i=0;i<nfam;i++) {
2790 // Lecture du nombre de groupes
2791 med_int ngro = MEDnFamilyGroup(medIdt,meshname,i+1);
2796 // Lecture de la famille
2797 else if (ngro > 0) {
2798 char familyname[MED_NAME_SIZE+1];
2800 char* gro = (char*) malloc(MED_LNAME_SIZE*ngro+1);
2801 erreur = MEDfamilyInfo(medIdt,
2811 // Lecture des groupes pour une famille de mailles
2813 for (int j=0;j<ngro;j++) {
2814 char str2[MED_LNAME_SIZE+1];
2815 strncpy(str2,gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
2816 str2[MED_LNAME_SIZE] = '\0';
2817 ListeGroupes.insert(std::string(str2));
2825 // Fermeture du fichier
2826 if (medIdt > 0) MEDfileClose(medIdt);
2828 return ListeGroupes;
2831 // =======================================================================
2832 // Le vecteur en retour contiendra les informations suivantes :
2833 // en position 0 et 1 Xmin, Xmax et en position 2 Dx si < 0 2D
2834 // en position 3 et 4 Ymin, Ymax et en position 5 Dy si < 0 2D
2835 // en position 6 et 7 Zmin, Zmax et en position 8 Dz si < 0 2D
2836 // 9 distance max dans le maillage
2837 // =======================================================================
2838 std::vector<double> GetBoundingBoxInMedFile(const char * aFile)
2840 std::vector<double> LesExtremes;
2843 while (erreur == 0) {
2844 // Ouverture du fichier
2845 medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY);
2850 //Nombre de maillage : on ne peut en lire qu'un seul
2851 med_int numberOfMeshes = MEDnMesh(medIdt);
2852 if (numberOfMeshes != 1) {
2856 // Caracteristiques du maillage
2857 char meshname[MED_NAME_SIZE+1];
2858 med_int spacedim,meshdim;
2859 med_mesh_type meshtype;
2860 char descriptionription[MED_COMMENT_SIZE+1];
2861 char dtunit[MED_SNAME_SIZE+1];
2862 med_sorting_type sortingtype;
2864 med_axis_type axistype;
2865 int naxis = MEDmeshnAxis(medIdt,1);
2866 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
2867 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
2868 erreur = MEDmeshInfo(medIdt,
2883 if (erreur < 0) { break; }
2887 med_int nnoe = MEDmeshnEntity(medIdt,
2903 med_float* coo = (med_float*) malloc(sizeof(med_float)*nnoe*spacedim);
2905 erreur = MEDmeshNodeCoordinateRd(medIdt,
2916 // Calcul des extremes
2917 med_float xmin,xmax,ymin,ymax,zmin,zmax;
2921 for (int i = 1; i < nnoe; i++) {
2922 xmin = std::min(xmin, coo[i]);
2923 xmax = std::max(xmax, coo[i]);
2929 for (int i = nnoe + 1; i < 2*nnoe; i++) {
2930 ymin = std::min(ymin,coo[i]);
2931 ymax = std::max(ymax,coo[i]);
2944 for (int i = 2*nnoe + 1; i < 3*nnoe; i++) {
2945 zmin = std::min(zmin,coo[i]);
2946 zmax = std::max(zmax,coo[i]);
2954 MESSAGE("_______________________________________");
2955 MESSAGE("xmin : " << xmin << " xmax : " << xmax);
2956 MESSAGE("ymin : " << ymin << " ymax : " << ymax);
2957 MESSAGE("zmin : " << zmin << " zmax : " << zmax);
2958 MESSAGE("_______________________________________");
2959 double epsilon = 1.e-6;
2960 LesExtremes.push_back(xmin);
2961 LesExtremes.push_back(xmax);
2962 LesExtremes.push_back(0);
2963 LesExtremes.push_back(ymin);
2964 LesExtremes.push_back(ymax);
2965 LesExtremes.push_back(0);
2966 LesExtremes.push_back(zmin);
2967 LesExtremes.push_back(zmax);
2968 LesExtremes.push_back(0);
2970 double max1 = std::max (LesExtremes[1] - LesExtremes[0], LesExtremes[4] - LesExtremes[3]);
2971 double max2 = std::max (max1 , LesExtremes[7] - LesExtremes[6]);
2972 LesExtremes.push_back(max2);
2974 // LesExtremes[0] = Xmini du maillage
2975 // LesExtremes[1] = Xmaxi du maillage
2976 // LesExtremes[2] = increment de progression en X
2977 // LesExtremes[3,4,5] : idem pour Y
2978 // LesExtremes[6,7,8] : idem pour Z
2979 // LesExtremes[9] = ecart maximal entre coordonnees
2980 // On fait un traitement pour dans le cas d'une coordonnee constante
2981 // inhiber ce cas en mettant un increment negatif
2983 double diff = LesExtremes[1] - LesExtremes[0];
2984 if (fabs(diff) > epsilon*max2) { LesExtremes[2] = diff/100.; }
2985 else { LesExtremes[2] = -1.; }
2987 diff = LesExtremes[4] - LesExtremes[3];
2988 if (fabs(diff) > epsilon*max2) { LesExtremes[5]=diff/100.; }
2989 else { LesExtremes[5] = -1.; }
2991 diff = LesExtremes[7] - LesExtremes[6];
2992 if (fabs(diff) > epsilon*max2) { LesExtremes[8]=diff/100.; }
2993 else { LesExtremes[8] = -1.; }
2995 MESSAGE ("_______________________________________");
2996 MESSAGE ("xmin : " << LesExtremes[0] << " xmax : " << LesExtremes[1] << " xincr : " << LesExtremes[2]);
2997 MESSAGE ("ymin : " << LesExtremes[3] << " ymax : " << LesExtremes[4] << " yincr : " << LesExtremes[5]);
2998 MESSAGE ("zmin : " << LesExtremes[6] << " zmax : " << LesExtremes[7] << " zincr : " << LesExtremes[8]);
2999 MESSAGE ("dmax : " << LesExtremes[9]);
3000 MESSAGE ("_______________________________________");
3005 // Fermeture du fichier
3006 if (medIdt > 0) MEDfileClose(medIdt);
3011 }; // namespace SMESHHOMARD_I