+ // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
+ DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
+
+ // E.6. Ajout des options avancees
+ int Pyram = myCase->GetPyram();
+ MESSAGE ( ". Pyram = " << Pyram );
+ int NivMax = myHypo->GetNivMax();
+ MESSAGE ( ". NivMax = " << NivMax );
+ double DiamMin = myHypo->GetDiamMin() ;
+ MESSAGE ( ". DiamMin = " << DiamMin );
+ int AdapInit = myHypo->GetAdapInit();
+ MESSAGE ( ". AdapInit = " << AdapInit );
+ int ExtraOutput = myHypo->GetExtraOutput();
+ MESSAGE ( ". ExtraOutput = " << ExtraOutput );
+ myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, ExtraOutput);
+
+ // E.7. Ajout des informations sur le deroulement de l'execution
+ int MessInfo = myIteration->GetInfoCompute();
+ MESSAGE ( ". MessInfo = " << MessInfo );
+ myDriver->TexteInfoCompute(MessInfo);
+
+ return codret ;
+}
+//=============================================================================
+// Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
+// nomrep : nom du repertoire parent
+// num : le nom du sous-repertoire est sous la forme 'In', n est >= num
+//=============================================================================
+char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
+{
+ MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
+ // On verifie que le repertoire parent existe
+ int codret = CHDIR(nomrep) ;
+ if ( codret != 0 )
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::BAD_PARAM;
+ es.text = "The directory of the case does not exist.";
+ throw SALOME::SALOME_Exception(es);
+ return 0;
+ };
+ std::string nomDirActuel = getenv("PWD") ;
+ std::string DirName ;
+ // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
+ bool a_chercher = true ;
+ while ( a_chercher )
+ {
+ // On passe dans le repertoire parent
+
+ CHDIR(nomrep);
+ // On recherche un nom sous la forme Iabc, avec abc representant le numero
+ int jaux ;
+ if ( num < 100 ) { jaux = 2 ; }
+ else if ( num < 1000 ) { jaux = 3 ; }
+ else if ( num < 10000 ) { jaux = 4 ; }
+ else if ( num < 100000 ) { jaux = 5 ; }
+ else { jaux = 9 ; }
+ std::ostringstream iaux ;
+ iaux << std::setw(jaux) << std::setfill('0') << num ;
+ std::ostringstream DirNameA ;
+ DirNameA << "I" << iaux.str();
+ // Si on ne pas peut entrer dans le repertoire, on doit verifier
+ // que c'est bien un probleme d'absence
+ if ( CHDIR(DirNameA.str().c_str()) != 0 )
+ {
+ bool existe = false ;
+#ifndef WIN32
+ DIR *dp;
+ struct dirent *dirp;
+ dp = opendir(nomrep);
+ while ( (dirp = readdir(dp)) != NULL )
+ {
+ std::string file_name(dirp->d_name);
+#else
+ HANDLE hFind = INVALID_HANDLE_VALUE;
+ WIN32_FIND_DATA ffd;
+ hFind = FindFirstFile(nomrep, &ffd);
+ if (INVALID_HANDLE_VALUE != hFind) {
+ while (FindNextFile(hFind, &ffd) != 0) {
+ if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
+ std::string file_name(ffd.cFileName);
+#endif
+ if ( file_name == DirNameA.str() ) { existe = true ; }
+ }
+#ifndef WIN32
+ closedir(dp);
+#else
+ FindClose(hFind);
+#endif
+ if ( !existe )
+ {
+ DirName = DirNameA.str() ;
+ a_chercher = false ;
+ break ;
+ }
+ }
+ num += 1;
+ }
+
+ MESSAGE ( "==> DirName = " << DirName);
+ MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
+ CHDIR(nomDirActuel.c_str());
+ return CORBA::string_dup( DirName.c_str() );
+}
+//=============================================================================
+// Calcul d'une iteration : gestion du repertoire de calcul
+// Si le sous-repertoire existe :
+// etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
+// etatMenage = 1 : on fait le menage du repertoire
+// etatMenage = -1 : on ne fait rien
+//=============================================================================
+char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
+{
+ MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
+ // B.2. Le repertoire du cas
+ const char* nomDirCase = myCase->GetDirName();
+ MESSAGE ( ". nomDirCase = " << nomDirCase );
+
+ // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
+ // B.3.1. Le nom du sous-repertoire
+ const char* nomDirIt = myIteration->GetDirNameLoc();
+
+ // B.3.2. Le nom complet du sous-repertoire
+ std::stringstream DirCompute ;
+ DirCompute << nomDirCase << "/" << nomDirIt;
+ MESSAGE (". DirCompute = " << DirCompute.str() );
+
+ // B.3.3. Si le sous-repertoire n'existe pas, on le cree
+ if (CHDIR(DirCompute.str().c_str()) != 0)
+ {
+#ifndef WIN32
+ if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
+#else
+ if (_mkdir(DirCompute.str().c_str()) != 0)
+#endif
+ {
+ // GERALD -- QMESSAGE BOX
+ std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
+ VERIFICATION("Pb a la creation du repertoire" == 0);
+ }
+ }
+ else
+ {
+// Le repertoire existe
+// On demande de faire le menage de son contenu :
+ if (etatMenage == 1)
+ {
+ MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
+ std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
+ int codret = system(commande.c_str());
+ if (codret != 0)
+ {
+ // GERALD -- QMESSAGE BOX
+ std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
+ VERIFICATION("Pb au menage du repertoire de calcul" == 0);
+ }
+ }
+// On n'a pas demande de faire le menage de son contenu : on sort en erreur :
+ else
+ {
+ if (etatMenage == 0)
+ {
+#ifndef WIN32
+ DIR *dp;
+ struct dirent *dirp;
+ dp = opendir(DirCompute.str().c_str());
+ bool result = true;
+ while ((dirp = readdir(dp)) != NULL && result )
+ {
+ std::string file_name(dirp->d_name);
+ result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
+ }
+ closedir(dp);
+#else
+ HANDLE hFind = INVALID_HANDLE_VALUE;
+ WIN32_FIND_DATA ffd;
+ hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
+ bool result = true;
+ if (INVALID_HANDLE_VALUE != hFind) {
+ while (FindNextFile(hFind, &ffd) != 0) {
+ if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
+ std::string file_name(ffd.cFileName);
+ result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
+ }
+ }
+ FindClose(hFind);
+#endif
+ if ( result == false)
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::BAD_PARAM;
+ std::string text = "Directory : " + DirCompute.str() + " is not empty";
+ es.text = CORBA::string_dup(text.c_str());
+ throw SALOME::SALOME_Exception(es);
+ VERIFICATION("Directory is not empty" == 0);
+ }
+ }
+ }
+ }
+
+ return CORBA::string_dup( DirCompute.str().c_str() );
+}
+//=============================================================================
+// Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
+//=============================================================================
+char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
+{
+ MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
+ // Le repertoire du cas
+ const char* nomDirCase = myCase->GetDirName();
+ MESSAGE ( ". nomDirCase = " << nomDirCase );
+
+ // Le sous-repertoire de l'iteration precedente
+
+ const char* nomIterationParent = myIteration->GetIterParentName();
+ HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
+ const char* nomDirItPa = myIterationParent->GetDirNameLoc();
+ std::stringstream DirComputePa ;
+ DirComputePa << nomDirCase << "/" << nomDirItPa;
+ MESSAGE( ". nomDirItPa = " << nomDirItPa);
+ MESSAGE( ". DirComputePa = " << DirComputePa.str() );
+
+ return CORBA::string_dup( DirComputePa.str().c_str() );
+}
+//=============================================================================
+// Calcul d'une iteration : ecriture des zones dans le fichier de configuration
+//=============================================================================
+void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
+{
+ MESSAGE ( "... DriverTexteZone" );
+ HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
+ int numberOfZonesx2 = ListZone->length();
+ int NumZone ;
+
+ for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
+ {
+ std::string ZoneName = std::string((*ListZone)[iaux]);
+ MESSAGE ( "... ZoneName = " << ZoneName);
+ HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
+ ASSERT(!CORBA::is_nil(myZone));
+
+ int ZoneType = myZone->GetType();
+ std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
+ int TypeUse = atoi( TypeUsestr.c_str() );
+ MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
+ NumZone = iaux/2 + 1 ;
+ HOMARD::double_array* zone = myZone->GetCoords();
+ if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
+ { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
+ else if ( ZoneType == 4 ) // Cas d une sphere
+ { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
+ else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
+ { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
+ else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
+ { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
+ else { VERIFICATION("ZoneType est incorrect." == 0) ; }
+ iaux += 1 ;
+ }
+ return ;
+}
+//=============================================================================
+// Calcul d'une iteration : ecriture des champs dans le fichier de configuration
+//=============================================================================
+void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
+{
+ MESSAGE ( "... DriverTexteField" );
+// Le fichier du champ
+ char* FieldFile = myIteration->GetFieldFile();
+ MESSAGE ( ". FieldFile = " << FieldFile );
+ if (strlen(FieldFile) == 0)
+ {
+ // GERALD -- QMESSAGE BOX
+ std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
+ VERIFICATION("The file for the field is not given." == 0);
+ }
+// Les caracteristiques d'instants du champ de pilotage
+ int TimeStep = myIteration->GetTimeStep();
+ MESSAGE( ". TimeStep = " << TimeStep );
+ int Rank = myIteration->GetRank();
+ MESSAGE( ". Rank = " << Rank );
+// Les informations sur les champs
+ HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
+// Le nom
+ const char* FieldName = aInfosHypo->FieldName;
+// Les seuils
+ int TypeThR = aInfosHypo->TypeThR;
+ double ThreshR = aInfosHypo->ThreshR;
+ int TypeThC = aInfosHypo->TypeThC;
+ double ThreshC = aInfosHypo->ThreshC;
+// Saut entre mailles ou non ?
+ int UsField = aInfosHypo->UsField;
+ MESSAGE( ". UsField = " << UsField );
+// L'usage des composantes
+ int UsCmpI = aInfosHypo->UsCmpI;
+ MESSAGE( ". UsCmpI = " << UsCmpI );
+//
+ myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
+//
+// Les composantes
+ HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
+ int numberOfCompos = mescompo->length();
+ MESSAGE( ". numberOfCompos = " << numberOfCompos );
+ for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
+ {
+ std::string nomCompo = std::string((*mescompo)[NumeComp]);
+ MESSAGE( "... nomCompo = " << nomCompo );
+ myDriver->TexteCompo(NumeComp, nomCompo);
+ }
+ return ;
+}
+//=============================================================================
+// Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
+// On ecrit dans l'ordre :
+// 1. la definition des frontieres
+// 2. les liens avec les groupes
+// 3. un entier resumant le type de comportement pour les frontieres
+//=============================================================================
+void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
+{
+ MESSAGE ( "... DriverTexteBoundary" );
+ // 1. Recuperation des frontieres