// HOMARD HOMARD : implementation of HOMARD idl descriptions // // Copyright (C) 2011-2020 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // Pilote l'ecriture du fichier xml pour lancer un schema YACS #include #ifndef WIN32 #include #endif #include #include "YACSDriver.hxx" #include "HOMARD.hxx" #include "Utils_SALOME_Exception.hxx" #include "utilities.h" //============================================================================= //============================================================================= YACSDriver::YACSDriver(const std::string XMLFile, const std::string DirName, const std::string LangueShort): _XMLFile( "" ), _DirName( "" ), _Texte( "" ), _Texte_parametres( "" ), _noeud_1( "CreateCase" ), _LangueShort( "" ), _bLu( false ) { MESSAGE("XMLFile = "<" ; _Texte += Meshfile ; _Texte += "\n" ; // } //=============================================================================== // Le repertoire de calcul // Le script de lancement //=============================================================================== void YACSDriver::Texte_Alternance_Calcul_HOMARD_Calcul( const std::string FileName ) { MESSAGE("Texte_Alternance_Calcul_HOMARD_Calcul, FileName : "<\n" ; INFOS("_LangueShort = "<<_LangueShort ); if ( _LangueShort == "fr" ) { motcle = "Etude_Initialisation" ; } else { motcle = "Study_Initialisation" ; } INFOS("motcle = "<\n" ; _Texte += " " + methode + "\n" ; // 4. Les inports // 4.1. Le nom de la zone _Texte += Texte_inport( "string", "ZoneName" ) ; TexteParametre( node, "ZoneName", "string", ZoneName ) ; // 4.2. Les valeurs numeriques // ATTENTION : les noms doivent etre les memes que dans Gen.xml, donc HOMARD_Gen.idl // 4.2.1. Decodage des valeurs // La chaine pythonStructure est de ce genre : // CreateZoneBox( "Zone_1", 0.144, 0.216, 0.096, 0.1464, 0.076, 0.12) std::string ligne = pythonStructure ; // On commence par ne garder que ce qui suit la premiere virgule ligne = GetStringInTexte( ligne, ",", 1 ); // On boucle pour isoler toutes les chaines dans les virgules std::string lignebis ; std::string x0, x1, x2, x3, x4, x5, x6, x7, x8 ; int iaux = 0 ; while ( ligne != lignebis ) { lignebis = GetStringInTexte ( ligne, ",", 0 ) ; // MESSAGE("lignebis = "< 10 ) && ( ZoneType < 14 ) ) { _Texte += Texte_inport( "double", "Umini" ) ; _Texte += Texte_inport( "double", "Umaxi" ) ; _Texte += Texte_inport( "double", "Vmini" ) ; _Texte += Texte_inport( "double", "Vmaxi" ) ; _Texte += Texte_inport( "long", "Orient" ) ; TexteParametre( node, "Umini", "double", x0 ) ; TexteParametre( node, "Umaxi", "double", x1 ) ; TexteParametre( node, "Vmini", "double", x2 ) ; TexteParametre( node, "Vmaxi", "double", x3 ) ; TexteParametre( node, "Orient", "int", x8 ) ; } // // 4.2.4. Cas du disque (31, 32, 33) ou du disque perce (61, 62, 63) else if ( ( ( ZoneType > 30 ) && ( ZoneType < 34 ) ) || ( ( ZoneType > 60 ) && ( ZoneType < 64 ) ) ) { _Texte += Texte_inport( "double", "Ucentre" ) ; _Texte += Texte_inport( "double", "Vcentre" ) ; _Texte += Texte_inport( "double", "Radius" ) ; TexteParametre( node, "Ucentre", "double", x0 ) ; TexteParametre( node, "Vcentre", "double", x1 ) ; TexteParametre( node, "Radius", "double", x2 ) ; if ( ZoneType > 60 ) { _Texte += Texte_inport( "double", "InternalRadius" ) ; TexteParametre( node, "InternalRadius", "double", x3 ) ; } _Texte += Texte_inport( "long", "Orient" ) ; TexteParametre( node, "Orient", "int", x8 ) ; } // // 4.2.5. Cas de la sphere (4) else if ( ZoneType == 4 ) { _Texte += Texte_inport( "double", "Xcentre" ) ; _Texte += Texte_inport( "double", "Ycentre" ) ; _Texte += Texte_inport( "double", "Zcentre" ) ; _Texte += Texte_inport( "double", "Radius" ) ; TexteParametre( node, "Xcentre", "double", x0 ) ; TexteParametre( node, "Ycentre", "double", x1 ) ; TexteParametre( node, "Zcentre", "double", x2 ) ; TexteParametre( node, "Radius", "double", x8 ) ; } // // 4.2.6. Cas du cylindre (5) ou du tuyau (7) else if ( ZoneType == 5 || ZoneType == 7 ) { _Texte += Texte_inport( "double", "Xcentre" ) ; _Texte += Texte_inport( "double", "Ycentre" ) ; _Texte += Texte_inport( "double", "Zcentre" ) ; _Texte += Texte_inport( "double", "Xaxis" ) ; _Texte += Texte_inport( "double", "Yaxis" ) ; _Texte += Texte_inport( "double", "Zaxis" ) ; _Texte += Texte_inport( "double", "Radius" ) ; _Texte += Texte_inport( "double", "Height" ) ; TexteParametre( node, "Xcentre", "double", x0 ) ; TexteParametre( node, "Ycentre", "double", x1 ) ; TexteParametre( node, "Zcentre", "double", x2 ) ; TexteParametre( node, "Xaxis", "double", x3 ) ; TexteParametre( node, "Yaxis", "double", x4 ) ; TexteParametre( node, "Zaxis", "double", x5 ) ; TexteParametre( node, "Radius", "double", x6 ) ; if ( ZoneType == 5 ) { TexteParametre( node, "Height", "double", x8 ) ; } else { _Texte += Texte_inport( "double", "InternalRadius" ) ; TexteParametre( node, "Height", "double", x7 ) ; TexteParametre( node, "InternalRadius", "double", x8 ) ; } } // // 4.2.7. Erreur else { VERIFICATION("Type de zone inconnu." == 0); } // // 5. La fin _Texte += " \n" ; _Texte += " \n" ; // return texte_control ; // } //=============================================================================== // La description des frontieres // BoundaryType : le type de la frontiere // pythonStructure : le python correspondant a la frontiere // methode : methode associee a la creation de la frontiere // BoundaryName : nom de la frontiere // MeshName : nom du maillage dans le cas d'une frontiere discrete // MeshFile : nom du fichier du maillage dans le cas d'une frontiere discrete //=============================================================================== std::string YACSDriver::Texte_Iter_1_Boundary( int BoundaryType, const std::string pythonStructure, const std::string methode, const std::string BoundaryName, const std::string MeshName, const std::string MeshFile ) { MESSAGE("Texte_Iter_1_Boundary, BoundaryType = "<\n" ; if ( _LangueShort == "fr" ) { motcle = "Etude_Initialisation" ; } else { motcle = "Study_Initialisation" ; } _Texte += " " + motcle + ".UpdateStudy\n" ; _Texte += " " + methode + "\n" ; // 4. Les inports // ATTENTION : les noms doivent etre les memes que dans Gen.xml, donc HOMARD_Gen.idl // 4.1. Le nom de la frontiere _Texte += Texte_inport( "string", "BoundaryName" ) ; TexteParametre( node, "BoundaryName", "string", BoundaryName ) ; // 4.2. Cas d une frontiere discrete if (BoundaryType == 0) { _Texte += Texte_inport( "string", "MeshName" ) ; TexteParametre( node, "MeshName", "string", MeshName ) ; _Texte += Texte_inport( "string", "FileName" ) ; TexteParametre( node, "FileName", "string", MeshFile ) ; } // 4.3. Cas d'une frontiere analytique : les valeurs numeriques else { // 4.3.1. Decodage des valeurs // La chaine pythonStructure est de ce genre : // CreateBoundaryCylinder('cyl_2', 17.5, -2.5, -12.5, -100., -75., -25., 50.) // CreateBoundaryDi("intersection", "PIQUAGE", "/scratch/D68518/Salome/script/sfr_2d_piquage.fr.med") std::string ligne = pythonStructure ; // On commence par ne garder que ce qui suit la premiere virgule ligne = GetStringInTexte( ligne, ",", 1 ); // On boucle pour isoler toutes les chaines dans les virgules std::string lignebis ; std::string x0, x1, x2, x3, x4, x5, x6, x7 ; int iaux = 0 ; while ( ligne != lignebis ) { lignebis = GetStringInTexte ( ligne, ",", 0 ) ; // MESSAGE("lignebis = "<\n" ; _Texte += " \n" ; // return texte_control ; // } //=============================================================================== // Fin du controle des enchainements de noeud dans le noeud Iter_1 //=============================================================================== std::string YACSDriver::Texte_Iter_1_control() { MESSAGE("Texte_Iter_1_control"); // std::string texte ; texte = Texte_control (_noeud_1, "CreateHypothesis", 1) ; texte += Texte_control ("CreateHypothesis", "Case_Options", 0) ; // return texte ; // } //=============================================================================== // Controle des enchainements de noeuds // noeud_1 : noeud de depart // noeud_2 : noeud d'arrivee // option : 0 : sans caractere de saut de ligne a la fin // 1 : avec caractere de saut de ligne a la fin //=============================================================================== std::string YACSDriver::Texte_control( const std::string noeud_1, const std::string noeud_2, int option ) { MESSAGE("Texte_control, noeud_1 = "< " ; texte += "" + noeud_1 + "" ; texte += " " + noeud_2 + "" ; texte += " " ; if ( option == 1 ) { texte += "\n" ; } return texte ; // } //=============================================================================== // Inport // inport_type : type de la donnee a importer // inport_nom : nom de la donnee a importer //=============================================================================== std::string YACSDriver::Texte_inport( const std::string inport_type, const std::string inport_nom ) { // MESSAGE("Texte_inport, inport_type = "< indice ) { int position = ligne.find_first_of( "." ) ; MESSAGE("\nposition : "<< position); if ( position > 0 ) { ligne_bis = ligne.substr( position ); MESSAGE("\nligne_bis : "<< ligne_bis); _Texte += concept + ligne_bis + "\n" ; } } cptr += 1 ; } // } //=============================================================================== // Manipulation des instructions python - 2 // pythonTexte : le texte des instructions python a manipuler // mot_cle : mot-cle dans les lignes a inserer // concept : nom du concept a inserer //=============================================================================== void YACSDriver::Texte_python_2( const std::string pythonTexte, const std::string mot_cle, const std::string concept ) { MESSAGE("Texte_python_2, pythonTexte\n"< 0 ) { int position = ligne.find_first_of( "." ) ; // MESSAGE("\nposition : "<< position); if ( position > 0 ) { ligne_bis = ligne.substr( position ); // MESSAGE("\nligne_bis : "<< ligne_bis); _Texte += concept + ligne_bis + "\n" ; } } } // } //=============================================================================== // Parametres de tests de convergence //=============================================================================== void YACSDriver::TexteAnalyse_Test_Convergence( int MaxIter, int MaxNode, int MaxElem ) { // // MESSAGE("TexteAnalyse_Test_Convergence"); std::string chaine ; std::ostringstream oss1; oss1 << MaxIter; chaine = oss1.str(); _Texte += "MaxIter = " + chaine + "\n" ; std::ostringstream oss2; oss2 << MaxNode; chaine = oss2.str(); _Texte += "MaxNode = " + chaine + "\n" ; std::ostringstream oss3; oss3 << MaxElem; chaine = oss3.str(); _Texte += "MaxElem = " + chaine + "\n" ; // } //=============================================================================== // Creation d'un parametre //=============================================================================== void YACSDriver::TexteParametre( const std::string node, const std::string port, const std::string type_value, const std::string value ) { // // MESSAGE("TexteParametre"); _Texte_parametres += " \n" ; _Texte_parametres += " " + node + "" ; _Texte_parametres += "" + port + "\n" ; _Texte_parametres += " <" + type_value + ">" + value + "\n" ; _Texte_parametres += " \n" ; // } //=============================================================================== // Ajout des parametres //=============================================================================== void YACSDriver::TexteAddParametres( ) { // MESSAGE("TexteAddParametres"); TexteAdd(_Texte_parametres) ; // } //=============================================================================== void YACSDriver::CreeFichier( ) { // MESSAGE("CreeFichier sur le fichier "<<_XMLFile); std::ofstream Fic(_XMLFile.c_str(), std::ios::out ) ; if (Fic.is_open() == true) { Fic << _Texte << std::endl ; } Fic.close() ; // } //=============================================================================== // REMARQUE : on devrait utiliser le GetStringInTexte de HOMARD_Gen_i mais je ne sais pas // comment l'appeler. ALors je clone. // Recuperation de la chaine de caracteres par rapport l'apparition d'un texte // ligne : la ligne a manipuler // texte : le texte a reperer // option : 0 : la chaine avant le texte // 1 : la chaine apres le texte // Si le texte est absent, on retourne la chaine totale //=============================================================================== std::string YACSDriver::GetStringInTexte( const std::string ligne, const std::string texte, int option ) { // MESSAGE("GetStringInTexte, recherche de '"<