]> SALOME platform Git repositories - modules/homard.git/blobdiff - src/HOMARD_I/HOMARD_Cas_i.cxx
Salome HOME
Copyright update 2022
[modules/homard.git] / src / HOMARD_I / HOMARD_Cas_i.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 0ba88c2..7c212c5
@@ -1,9 +1,9 @@
-// Copyright (C) 2011-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2011-2022  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.
+// 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
@@ -16,6 +16,7 @@
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 // Remarques :
 // L'ordre de description des fonctions est le meme dans tous les fichiers
 // HOMARD_aaaa.idl, HOMARD_aaaa.hxx, HOMARD_aaaa.cxx, HOMARD_aaaa_i.hxx, HOMARD_aaaa_i.cxx :
 #include <vector>
 #include <sys/stat.h>
 
+#ifdef WIN32
+#include <direct.h>
+#endif
+
 //=============================================================================
 /*!
  *  standard constructor
@@ -121,17 +126,21 @@ void HOMARD_Cas_i::SetDirName( const char* NomDir )
   int codret ;
   // A. recuperation du nom ; on ne fait rien si c'est le meme
   char* oldrep = GetDirName() ;
-  if ( oldrep == NomDir ) { return ; }
+  if ( strcmp(oldrep,NomDir) == 0 )
+  {
+   return ;
+  }
   MESSAGE ( "SetDirName : passage de oldrep = "<< oldrep << " a NomDir = "<<NomDir);
   // B. controle de l'usage du repertoire
-  char* casename = _gen_i->VerifieDir(NomDir) ;
-  if ( std::string(casename).size() > 0 )
+  char* CaseName = GetName() ;
+  char* casenamedir = _gen_i->VerifieDir(NomDir) ;
+  if ( ( std::string(casenamedir).size() > 0 ) & ( strcmp(CaseName,casenamedir)!=0 ) )
   {
-    INFOS ( "Le repertoire " << NomDir << " est deja utilise pour le cas "<< casename );
+    INFOS ( "Le repertoire " << NomDir << " est deja utilise pour le cas "<< casenamedir );
     SALOME::ExceptionStruct es;
     es.type = SALOME::BAD_PARAM;
     std::string text ;
-    text = "The directory " + std::string(NomDir) + " is already used for the case " + std::string(casename) ;
+    text = "The directory " + std::string(NomDir) + " is already used for the case " + std::string(casenamedir) ;
     es.text = CORBA::string_dup(text.c_str());
     throw SALOME::SALOME_Exception(es);
   }
@@ -161,7 +170,11 @@ void HOMARD_Cas_i::SetDirName( const char* NomDir )
     // D.3. Creation du futur repertoire local pour l'iteration de depart
     std::string nomDirIterTotal ;
     nomDirIterTotal = std::string(NomDir) + "/" + std::string(nomDirIter) ;
+#ifndef WIN32
     if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
+#else
+    if (_mkdir(nomDirIterTotal.c_str()) != 0)
+#endif
     {
       MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
       SALOME::ExceptionStruct es;
@@ -224,6 +237,7 @@ CORBA::Long HOMARD_Cas_i::GetNumberofIter()
 void HOMARD_Cas_i::SetConfType( CORBA::Long ConfType )
 {
   ASSERT( myHomardCas );
+//   VERIFICATION( (ConfType>=-2) && (ConfType<=3) );
   myHomardCas->SetConfType( ConfType );
 }
 //=============================================================================
@@ -233,6 +247,19 @@ CORBA::Long HOMARD_Cas_i::GetConfType()
   return myHomardCas->GetConfType();
 }
 //=============================================================================
+void HOMARD_Cas_i::SetExtType( CORBA::Long ExtType )
+{
+  ASSERT( myHomardCas );
+//   VERIFICATION( (ExtType>=0) && (ExtType<=2) );
+  myHomardCas->SetExtType( ExtType );
+}
+//=============================================================================
+CORBA::Long HOMARD_Cas_i::GetExtType()
+{
+  ASSERT( myHomardCas );
+  return myHomardCas->GetExtType();
+}
+//=============================================================================
 void HOMARD_Cas_i::SetBoundingBox( const HOMARD::extrema& LesExtrema )
 {
   ASSERT( myHomardCas );
@@ -292,46 +319,140 @@ HOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
   return aResult._retn();
 }
 //=============================================================================
+void HOMARD_Cas_i::AddBoundary(const char* BoundaryName)
+{
+  MESSAGE ("HOMARD_Cas_i::AddBoundary : BoundaryName = "<< BoundaryName );
+  const char * Group = "" ;
+  AddBoundaryGroup( BoundaryName, Group) ;
+}
+//=============================================================================
 void HOMARD_Cas_i::AddBoundaryGroup( const char* BoundaryName, const char* Group)
 {
-  MESSAGE ("AddBoundaryGroup : BoundaryName = "<< BoundaryName << ", Group = " << Group );
+  MESSAGE ("HOMARD_Cas_i::AddBoundaryGroup : BoundaryName = "<< BoundaryName << ", Group = " << Group );
   ASSERT( myHomardCas );
-  // A. La liste des frontiere+groupes
+  // A. Préalables
+  // A.1. Caractéristiques de la frontière à ajouter
+  HOMARD::HOMARD_Boundary_ptr myBoundary = _gen_i->GetBoundary(BoundaryName) ;
+  ASSERT(!CORBA::is_nil(myBoundary));
+  int BoundaryType = myBoundary->GetType();
+  MESSAGE ( ". BoundaryType = " << BoundaryType );
+  // A.2. La liste des frontiere+groupes
   const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
   std::list<std::string>::const_iterator it;
-  // B. La frontiere
-  // B.1. La frontiere est-elle deja enregistree pour ce cas ?
-  bool existe = false ;
-  for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
+  // B. Controles
+  const char * boun ;
+  int erreur = 0 ;
+  while ( erreur == 0 )
   {
-//     MESSAGE ("..  Frontiere : "<< *it );
-    if ( *it == BoundaryName ) { existe = true ; }
-    it++ ;
-  }
-  // B.2. Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
-  if ( !existe )
-  {
-    char* CaseName = GetName() ;
-    MESSAGE ( "AddBoundaryGroup : insertion de la frontiere dans l'arbre de " << CaseName );
-    _gen_i->PublishBoundaryUnderCase(CaseName, BoundaryName) ;
+  // B.1. Si on ajoute une frontière CAO, elle doit être la seule frontière
+    if ( BoundaryType == -1 )
+    {
+      for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
+      {
+        boun = (*it).c_str() ;
+        MESSAGE ("..  Frontiere enregistrée : "<< boun );
+        if ( *it != BoundaryName )
+        { erreur = 1 ;
+          break ; }
+        // On saute le nom du groupe
+        it++ ;
+      }
+    }
+    if ( erreur != 0 ) { break ; }
+  // B.2. Si on ajoute une frontière non CAO, il ne doit pas y avoir de frontière CAO
+    if ( BoundaryType != -1 )
+    {
+      for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
+      {
+        boun = (*it).c_str() ;
+        MESSAGE ("..  Frontiere enregistrée : "<< boun );
+        HOMARD::HOMARD_Boundary_ptr myBoundary_0 = _gen_i->GetBoundary(boun) ;
+        int BoundaryType_0 = myBoundary_0->GetType();
+        MESSAGE ( ".. BoundaryType_0 = " << BoundaryType_0 );
+        if ( BoundaryType_0 == -1 )
+        { erreur = 2 ;
+          break ; }
+        // On saute le nom du groupe
+        it++ ;
+      }
+      if ( erreur != 0 ) { break ; }
+    }
+  // B.3. Si on ajoute une frontière discrète, il ne doit pas y avoir d'autre frontière discrète
+    if ( BoundaryType == 0 )
+    {
+      for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
+      {
+        boun = (*it).c_str() ;
+        MESSAGE ("..  Frontiere enregistrée : "<< boun );
+        if ( boun != BoundaryName )
+        {
+          HOMARD::HOMARD_Boundary_ptr myBoundary_0 = _gen_i->GetBoundary(boun) ;
+          int BoundaryType_0 = myBoundary_0->GetType();
+          MESSAGE ( ".. BoundaryType_0 = " << BoundaryType_0 );
+          if ( BoundaryType_0 == 0 )
+          { erreur = 3 ;
+            break ; }
+        }
+        // On saute le nom du groupe
+        it++ ;
+      }
+      if ( erreur != 0 ) { break ; }
+    }
+  // B.4. Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
+    bool existe = false ;
+    for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
+    {
+      MESSAGE ("..  Frontiere : "<< *it );
+      if ( *it == BoundaryName ) { existe = true ; }
+      // On saute le nom du groupe
+      it++ ;
+    }
+    if ( !existe )
+    {
+      char* CaseName = GetName() ;
+      MESSAGE ( "AddBoundaryGroup : insertion de la frontiere dans l'arbre de " << CaseName );
+      _gen_i->PublishBoundaryUnderCase(CaseName, BoundaryName) ;
+    }
+  // B.5. Le groupe est-il deja enregistre pour une frontiere de ce cas ?
+    for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
+    {
+      boun = (*it).c_str() ;
+      it++ ;
+      MESSAGE ("..  Groupe enregistré : "<< *it );
+      if ( *it == Group )
+      { erreur = 5 ;
+        break ; }
+    }
+    if ( erreur != 0 ) { break ; }
+    //
+    break ;
   }
-  // C. Le groupe est-il deja enregistre pour une frontiere de ce cas ?
-  for ( it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++ )
+  // F. Si aucune erreur, enregistrement du couple (frontiere,groupe) dans la reference du cas
+  //    Sinon, arrêt
+  if ( erreur == 0 )
+  { myHomardCas->AddBoundaryGroup( BoundaryName, Group ); }
+  else
   {
-    std::string boun = *it ;
-    it++ ;
-//     MESSAGE ("..  Group : "<< *it );
-    if ( *it == Group )
-    { INFOS ("Le groupe " << Group << " est deja associe a la frontiere " << boun) ;
-      SALOME::ExceptionStruct es;
-      es.type = SALOME::BAD_PARAM;
-      es.text = "Invalid AddBoundaryGroup";
-      throw SALOME::SALOME_Exception(es);
-      return ;
-    }
+    std::stringstream ss;
+    ss << erreur;
+    std::string str = ss.str();
+    std::string texte ;
+    texte = "Erreur numéro " + str + " pour la frontière à enregistrer : " + std::string(BoundaryName) ;
+    if ( erreur == 1 ) { texte += "\nIl existe déjà la frontière " ; }
+    else if ( erreur == 2 ) { texte += "\nIl existe déjà la frontière CAO " ; }
+    else if ( erreur == 3 ) { texte += "\nIl existe déjà une frontière discrète : " ; }
+    else if ( erreur == 5 ) { texte += "\nLe groupe " + std::string(Group) + " est déjà enregistré pour la frontière " ; }
+    texte += std::string(boun) ;
+    //
+    SALOME::ExceptionStruct es;
+    es.type = SALOME::BAD_PARAM;
+#ifdef _DEBUG_
+    texte += "\nInvalid AddBoundaryGroup";
+#endif
+    INFOS(texte) ;
+    es.text = CORBA::string_dup(texte.c_str());
+    throw SALOME::SALOME_Exception(es);
   }
-  // D. Enregistrement du couple (frontiere,groupe) dans la reference du cas
-  myHomardCas->AddBoundaryGroup( BoundaryName, Group );
 }
 //=============================================================================
 HOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
@@ -350,6 +471,13 @@ HOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
   return aResult._retn();
 }
 //=============================================================================
+void HOMARD_Cas_i::SupprBoundaryGroup()
+{
+  MESSAGE ("SupprBoundaryGroup");
+  ASSERT(myHomardCas );
+  myHomardCas->SupprBoundaryGroup();
+}
+//=============================================================================
 void HOMARD_Cas_i::SetPyram( CORBA::Long Pyram )
 {
   MESSAGE ("SetPyram, Pyram = " << Pyram );
@@ -455,7 +583,7 @@ void HOMARD_Cas_i::AddIteration( const char* NomIteration )
 // Creation d'un schema YACS
 // YACSName : nom du schema
 // ScriptFile : nom du fichier contenant le script de lancement du calcul
-// DirName : le repertoire de lancement des calculs du schéma
+// DirName : le repertoire de lancement des calculs du sch?ma
 // MeshFile : nom du fichier contenant le maillage pour le premier calcul
 //=============================================================================
 HOMARD::HOMARD_YACS_ptr HOMARD_Cas_i::CreateYACSSchema( const char* YACSName, const char* ScriptFile, const char* DirName, const char* MeshFile )