+ if (CORBA::is_nil(aSmeshSO))
+ {
+ return ;
+ };
+// On verifie que le fichier est deja publie
+ SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
+ SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aSmeshSO);
+ for (; aIter->More(); aIter->Next())
+ {
+ SALOMEDS::SObject_var aSO = aIter->Value();
+ SALOMEDS::GenericAttribute_var aGAttr;
+ if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
+ {
+ SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
+ CORBA::String_var value=anAttr->Value();
+ if (strcmp((const char*)value,NomFich.c_str()) == 0)
+ {
+ if (aSO->FindAttribute(aGAttr,"AttributeName"))
+ {
+ SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
+ CORBA::String_var value2=anAttr2->Value();
+ if (strcmp((const char*)value2,MeshName.c_str()) == 0)
+ {
+ myBuilder->RemoveObjectWithChildren( aSO ) ;
+ }
+ }
+ }
+ }
+ }
+ return ;
+}
+//=============================================================================
+void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
+{
+ MESSAGE( "PublishMeshIterInSmesh " << NomIter);
+ HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIter];
+
+ SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
+ if (CORBA::is_nil(myIteration))
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::BAD_PARAM;
+ es.text = "Invalid iterationStudy Object";
+ throw SALOME::SALOME_Exception(es);
+ return ;
+ };
+ const char* MeshFile = myIteration->GetMeshFile() ;
+ const char* MeshName = myIteration->GetMeshName() ;
+ CORBA::Long Option = -1 ;
+ int etat = myIteration->GetState();
+// Iteration initiale
+ if ( etat <= 0 ) { Option = 0 ; }
+// ou iteration calculee
+ else if ( etat == 2 ) { Option = 1 ; }
+// Publication effective apres menage eventuel
+ if ( Option >= 0 )
+ {
+ DeleteResultInSmesh(MeshFile, MeshName) ;
+ PublishResultInSmesh(MeshFile, Option) ;
+ }
+
+}
+//=============================================================================
+void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
+{
+// MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
+ HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIter];
+
+ SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
+ if (CORBA::is_nil(myIteration))
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::BAD_PARAM;
+ es.text = "Invalid iterationStudy Object";
+ throw SALOME::SALOME_Exception(es);
+ return ;
+ };
+
+ SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
+
+ aStudyBuilder->NewCommand();
+
+ SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
+// Pour les fichiers med, on affiche une icone de maillage
+// Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
+// Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
+ std::string icone ;
+ std::string ior = " " ;
+ if ( Commentaire[0] == 'M' )
+ { icone = "med.png" ; }
+ else
+ { icone = "texte_2.png" ; }
+ PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
+
+ aStudyBuilder->CommitCommand();
+}
+//
+//=============================================================================
+void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
+{
+// MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
+ HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
+
+ SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
+ if (CORBA::is_nil(myYACS))
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::BAD_PARAM;
+ es.text = "Invalid YACSStudy Object";
+ throw SALOME::SALOME_Exception(es);
+ return ;
+ };
+
+ SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
+
+ aStudyBuilder->NewCommand();
+
+ SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
+ std::string icone = "texte_2.png" ;
+ std::string ior = " " ;
+ PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
+
+ aStudyBuilder->CommitCommand();
+}
+//
+//=============================================================================
+//=============================================================================
+// YACS
+//=============================================================================
+//=============================================================================
+//=============================================================================
+// Creation d'un schema YACS
+// nomCas : nom du cas a traiter
+// FileName : nom du fichier contenant le script de lancement du calcul
+// DirName : le répertoire de lancement des calculs du schéma
+//=============================================================================
+HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
+{
+ MESSAGE ( "CreateYACSSchema : Schema YACS " << nomYACS );
+ MESSAGE ( ". nomCas : " << nomCas);
+ MESSAGE ( ". ScriptFile : " << ScriptFile);
+ MESSAGE ( ". DirName : " << DirName);
+ MESSAGE ( ". MeshFile : " << MeshFile);
+
+ // A. Controle du nom :
+ if ((myStudyContext._mesYACSs).find(nomYACS) != (myStudyContext._mesYACSs).end())
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::BAD_PARAM;
+ es.text = "This schema YACS has already been defined.";
+ throw SALOME::SALOME_Exception(es);
+ return 0;
+ }
+
+ // B. Creation de l'objet
+ HOMARD::HOMARD_YACS_var myYACS = newYACS();
+ if (CORBA::is_nil(myYACS))
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::BAD_PARAM;
+ es.text = "Unable to create the schema YACS";
+ throw SALOME::SALOME_Exception(es);
+ return 0;
+ };
+ myYACS->SetName( nomYACS ) ;
+
+ // C. Enregistrement
+ myStudyContext._mesYACSs[nomYACS] = myYACS;
+
+ SALOMEDS::SObject_var aSO;
+ SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myYACS, nomYACS);
+
+ PublishCaseUnderYACS(nomYACS, nomCas);
+
+ // D. Caracterisation
+ // D.1. Options
+ myYACS->SetDirName( DirName ) ;
+ myYACS->SetMeshFile( MeshFile ) ;
+ myYACS->SetScriptFile( ScriptFile ) ;
+ myYACS->SetCaseName( nomCas ) ;
+ // D.2. Defaut
+ int defaut_i ;
+ // D.2.1. Type constant
+ myYACS->SetType( 1 ) ;
+ // D.2.2. Convergence
+ defaut_i = GetYACSMaxIter() ;
+ myYACS->SetMaxIter( defaut_i ) ;
+ defaut_i = GetYACSMaxNode() ;
+ myYACS->SetMaxNode( defaut_i ) ;
+ defaut_i = GetYACSMaxElem() ;
+ myYACS->SetMaxElem( defaut_i ) ;
+ // D.3. Fichier de sauvegarde dans le répertoire du cas
+ HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
+ std::string dirnamecase = caseyacs->GetDirName() ;
+ std::string XMLFile ;
+ XMLFile = dirnamecase + "/schema.xml" ;
+ myYACS->SetXMLFile( XMLFile.c_str() ) ;
+
+ return HOMARD::HOMARD_YACS::_duplicate(myYACS);
+}
+//=============================================================================
+// Ecriture d'un schema YACS
+//=============================================================================
+CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
+{
+ MESSAGE ( "YACSWrite : Ecriture de " << nomYACS );
+// Le répertoire du cas
+ HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
+ ASSERT(!CORBA::is_nil(myYACS));
+// Le nom du fichier du schema
+ std::string XMLFile ;
+ XMLFile = myYACS->GetXMLFile() ;
+
+ int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
+
+ return codret ;
+}
+//=============================================================================
+// Ecriture d'un schema YACS sur un fichier donne
+//=============================================================================
+CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
+{
+ MESSAGE ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
+
+ // A. Prealable
+ int codret = 0;
+
+ // B. L'objet YACS
+ // B.1. L'objet
+ HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
+ ASSERT(!CORBA::is_nil(myYACS));
+ // B.2. Les caracteristiques
+ std::string DirName = myYACS->GetDirName() ;
+ std::string MeshFile = myYACS->GetMeshFile() ;
+ std::string ScriptFile = myYACS->GetScriptFile() ;
+ // B.3. Les caracteristiques de convergence
+ int MaxIter = myYACS->GetMaxIter() ;
+ int MaxNode = myYACS->GetMaxNode() ;
+ int MaxElem = myYACS->GetMaxElem() ;
+
+ // C. Le cas
+ // C.1. L'objet cas
+ const char* nomCas = myYACS->GetCaseName();
+ HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
+ ASSERT(!CORBA::is_nil(myCase));
+ // C.2. Les instructions python associees au cas
+ CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
+ std::string pythonCas = dumpCorbaCase.in();
+ MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
+
+ // D. Les iterations
+ // D.1. L'iteration initiale
+ HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
+ std::string Iter0Name = myCase->GetIter0Name() ;
+ MESSAGE (". Iter0Name = " << Iter0Name);
+ std::string MeshName = Iter0->GetMeshName();
+ MESSAGE (". MeshName = " << MeshName);
+ // D.2. L'iteration numero 1
+ HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
+ int numberOfIter = maListe->length();
+ if ( numberOfIter > 1 )
+ {
+ MESSAGE (". numberOfIter = " << numberOfIter);
+ SALOME::ExceptionStruct es ;
+ es.type = SALOME::BAD_PARAM;
+ std::string text = "Une seule iteration est permise." ;
+ es.text = CORBA::string_dup(text.c_str());
+ throw SALOME::SALOME_Exception(es);
+ return 0;
+ }
+ std::string Iter1Name = std::string((*maListe)[0]);
+ MESSAGE ("... Iter1Name = " << Iter1Name);
+ HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
+ // D.3. Les instructions python associees a l'iteration
+ CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
+ std::string pythonIter = dumpCorbaIter.in();
+ MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
+
+ // E. L'hypothese pour passer de l'iteration initiale a la suivante
+ // E.1. La structure
+ std::string nomHypo = Iter1->GetHypoName();
+ MESSAGE (". nomHypo = " << nomHypo);
+ HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
+ ASSERT(!CORBA::is_nil(myHypo));
+ // E.2. Les caracteristiques de l'adaptation
+ HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
+ ASSERT(ListTypes->length() == 3);
+ int TypeAdap = (*ListTypes)[0];
+// int TypeRaff = (*ListTypes)[1];
+// int TypeDera = (*ListTypes)[2];
+ // E.3. Les instructions python associees a l'hypothese
+ CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
+ std::string pythonHypo = dumpCorbaHypo.in();
+ MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
+
+ // F. Le fichier du schema de reference
+ // HOMARD_ROOT_DIR : répertoire ou se trouve le module HOMARD
+ std::string XMLFile_base ;
+ if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
+ else
+ {
+ SALOME::ExceptionStruct es ;
+ es.type = SALOME::BAD_PARAM;
+ std::string text = "HOMARD_ROOT_DIR est inconnu." ;
+ es.text = CORBA::string_dup(text.c_str());
+ throw SALOME::SALOME_Exception(es);
+ return 0;
+ }
+ XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
+// if ( _Langue ==
+ MESSAGE("XMLFile_base ="<<XMLFile_base);
+
+ // G. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
+ YACSDriver* myDriver = new YACSDriver(XMLFile, DirName, _LangueShort);
+ std::ifstream fichier( XMLFile_base.c_str() );
+ if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
+ {
+ // G.1. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
+ std::string ligne; // variable contenant chaque ligne lue
+ std::string mot_cle;
+ while ( std::getline( fichier, ligne ) )
+ {
+ // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
+ std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
+ ligne_bis >> mot_cle ;
+ // G.1.2. Le maillage initial
+ if ( mot_cle == "DataInit_MeshFile" )
+ { myDriver->Texte_DataInit_MeshFile(MeshFile); }
+ // G.1.3. Le script de lancement
+ else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
+ { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
+ // G.1.4. Les options du cas
+ else if ( mot_cle == "Iter_1_Case_Options" )
+ { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
+ // G.1.5. Execution de HOMARD : le répertoire du cas
+ else if ( mot_cle == "HOMARD_Exec_DirName" )
+ { myDriver->Texte_HOMARD_Exec_DirName(); }
+ // G.1.6. Execution de HOMARD : le nom du maillage
+ else if ( mot_cle == "HOMARD_Exec_MeshName" )
+ {
+ myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
+ std::string node ;
+ if ( _LangueShort == "fr" ) { node = "Boucle_de_convergence.Alternance_Calcul_HOMARD" ; }
+ else { node = "Convergence_Loop.Alternation_Computation_HOMARD" ; }
+ node += ".Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
+ myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
+ }
+ // G.1.7. Execution de HOMARD : les options de l'hypothese
+ else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
+ { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ; }
+ // G.1.8. Execution de HOMARD : les options de l'iteration
+ else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
+ { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ; }
+ // G.1.9. a. Creation eventuelles des zones et frontieres
+ // b. Enchainement
+ else if ( mot_cle == "Iter_1" )
+ {
+ std::string texte_control = "" ;
+ if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
+ texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
+ texte_control += myDriver->Texte_Iter_1_control() ;
+ myDriver->TexteAdd(texte_control);
+ }
+ // G.1.10. Les tests de convergence
+ else if ( mot_cle == "Analyse_Test_Convergence" )
+ { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
+ // G.1.11. Les parametres
+ else if ( mot_cle == "PARAMETRES" )
+ { myDriver->TexteAddParametres(); }
+ // G.1.n. La ligne est recopiee telle quelle
+ else { myDriver->TexteAdd(ligne); }
+ }
+ // G.2. Ecriture du texte dans le fichier
+ if ( codret == 0 )
+ { myDriver->CreeFichier(); }
+ }
+ else