Salome HOME
Nouvelles icones
[modules/homard.git] / src / HOMARD_I / HOMARD_Cas_i.cxx
index 8e456ec36919fc497a87ba4a5e79c8ff896ea23f..b44f36b7c9334e38c738c11731748565818dbf24 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2011-2013  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
@@ -33,6 +33,7 @@
 
 #include "utilities.h"
 #include <vector>
+#include <sys/stat.h>
 
 //=============================================================================
 /*!
@@ -85,12 +86,12 @@ char* HOMARD_Cas_i::GetName()
   return CORBA::string_dup( myHomardCas->GetName().c_str() );
 }
 //=============================================================================
-CORBA::Long  HOMARD_Cas_i::Delete()
+CORBA::Long  HOMARD_Cas_i::Delete( CORBA::Long Option )
 {
   ASSERT( myHomardCas );
   char* CaseName = GetName() ;
-  MESSAGE ( "Delete : destruction du cas " << CaseName );
-  return _gen_i->DeleteCase(CaseName) ;
+  MESSAGE ( "Delete : destruction du cas " << CaseName << ", Option = " << Option );
+  return _gen_i->DeleteCase(CaseName, Option) ;
 }
 //=============================================================================
 char* HOMARD_Cas_i::GetDumpPython()
@@ -116,7 +117,73 @@ bool HOMARD_Cas_i::Restore( const std::string& stream )
 void HOMARD_Cas_i::SetDirName( const char* NomDir )
 {
   ASSERT( myHomardCas );
-  myHomardCas->SetDirName( NomDir );
+  int codret ;
+  // A. recuperation du nom ; on ne fait rien si c'est le meme
+  char* oldrep = GetDirName() ;
+  MESSAGE ( "SetDirName : passage de oldrep = "<< oldrep << " a NomDir = "<<NomDir);
+  if ( oldrep == NomDir ) { return ; }
+  // B. Changement/creation du repertoire
+  codret = myHomardCas->SetDirName( NomDir );
+  if ( codret != 0 )
+  {
+    SALOME::ExceptionStruct es;
+    es.type = SALOME::BAD_PARAM;
+    std::string text ;
+    if ( codret == 1 ) { text = "The directory for the case cannot be modified because some iterations are already defined." ; }
+    else               { text = "The directory for the case cannot be reached." ; }
+    es.text = CORBA::string_dup(text.c_str());
+    throw SALOME::SALOME_Exception(es);
+  }
+  // C. En cas de reprise, deplacement du point de depart
+  if ( GetState() != 0 )
+  {
+    MESSAGE ( "etat : " << GetState() ) ;
+    // C.1. Nom local du repertoire de l'iteration de depart dans le repertoire actuel du cas
+    HOMARD::HOMARD_Iteration_ptr Iter = GetIter0() ;
+    char* DirNameIter = Iter->GetDirNameLoc() ;
+    MESSAGE ( "SetDirName : nom actuel pour le repertoire de l iteration, DirNameIter = "<< DirNameIter);
+    // C.2. Recherche d'un nom local pour l'iteration de depart dans le futur repertoire du cas
+    char* nomDirIter = _gen_i->CreateDirNameIter(NomDir, 0 );
+    MESSAGE ( "SetDirName : nom futur pour le repertoire de l iteration, nomDirIter = "<< nomDirIter);
+    // C.3. Creation du futur repertoire local pour l'iteration de depart
+    std::string nomDirIterTotal ;
+    nomDirIterTotal = std::string(NomDir) + "/" + std::string(nomDirIter) ;
+    if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
+    {
+      MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
+      SALOME::ExceptionStruct es;
+      es.type = SALOME::BAD_PARAM;
+      std::string text = "The directory for the starting iteration cannot be created." ;
+      es.text = CORBA::string_dup(text.c_str());
+      throw SALOME::SALOME_Exception(es);
+    }
+    // C.4. Deplacement du contenu du repertoire
+    std::string oldnomDirIterTotal ;
+    oldnomDirIterTotal = std::string(oldrep) + "/" + std::string(DirNameIter) ;
+    std::string commande = "mv " + std::string(oldnomDirIterTotal) + "/*" + " " + std::string(nomDirIterTotal) ;
+    codret = system(commande.c_str()) ;
+    if ( codret != 0 )
+    {
+      SALOME::ExceptionStruct es;
+      es.type = SALOME::BAD_PARAM;
+      std::string text = "The starting point for the case cannot be moved into the new directory." ;
+      es.text = CORBA::string_dup(text.c_str());
+      throw SALOME::SALOME_Exception(es);
+    }
+    commande = "rm -rf " + std::string(oldnomDirIterTotal) ;
+    codret = system(commande.c_str()) ;
+    if ( codret != 0 )
+    {
+      SALOME::ExceptionStruct es;
+      es.type = SALOME::BAD_PARAM;
+      std::string text = "The starting point for the case cannot be deleted." ;
+      es.text = CORBA::string_dup(text.c_str());
+      throw SALOME::SALOME_Exception(es);
+    }
+    // C.5. Memorisation du nom du repertoire de l'iteration
+    Iter->SetDirNameLoc(nomDirIter) ;
+  }
+  return ;
 }
 //=============================================================================
 char* HOMARD_Cas_i::GetDirName()
@@ -125,10 +192,20 @@ char* HOMARD_Cas_i::GetDirName()
   return CORBA::string_dup( myHomardCas->GetDirName().c_str() );
 }
 //=============================================================================
-CORBA::Long HOMARD_Cas_i::GetNumber()
+CORBA::Long HOMARD_Cas_i::GetState()
 {
   ASSERT( myHomardCas );
-  return myHomardCas->GetNumber();
+// Nom de l'iteration initiale
+  char* Iter0Name = GetIter0Name() ;
+  HOMARD::HOMARD_Iteration_ptr Iter = _gen_i->GetIteration(Iter0Name) ;
+  int state = Iter->GetNumber() ;
+  return state ;
+}
+//=============================================================================
+CORBA::Long HOMARD_Cas_i::GetNumberofIter()
+{
+  ASSERT( myHomardCas );
+  return myHomardCas->GetNumberofIter();
 }
 //=============================================================================
 void HOMARD_Cas_i::SetConfType( CORBA::Long ConfType )
@@ -153,7 +230,6 @@ void HOMARD_Cas_i::SetBoundingBox( const HOMARD::extrema& LesExtrema )
   {
     VExtrema[i] = LesExtrema[i];
   }
-
   myHomardCas->SetBoundingBox( VExtrema );
 }
 //=============================================================================
@@ -185,7 +261,6 @@ void HOMARD_Cas_i::SetGroups( const HOMARD::ListGroupType& ListGroup )
   {
     ListString.push_back(std::string(ListGroup[i]));
   }
-
   myHomardCas->SetGroups( ListString );
 }
 //=============================================================================
@@ -259,6 +334,27 @@ CORBA::Long HOMARD_Cas_i::GetPyram()
   return myHomardCas->GetPyram();
 }
 //=============================================================================
+void HOMARD_Cas_i::MeshInfo(CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
+{
+  MESSAGE ( "MeshInfo : information sur le maillage initial du cas" );
+  ASSERT( myHomardCas );
+//
+// Nom de l'iteration
+  char* IterName = GetIter0Name() ;
+  CORBA::Long etatMenage = -1 ;
+  CORBA::Long modeHOMARD = 7 ;
+  CORBA::Long Option1 = 1 ;
+  CORBA::Long Option2 = 1 ;
+  if ( Qual != 0 ) { modeHOMARD = modeHOMARD*5 ; }
+  if ( Diam != 0 ) { modeHOMARD = modeHOMARD*19 ; }
+  if ( Conn != 0 ) { modeHOMARD = modeHOMARD*11 ; }
+  if ( Tail != 0 ) { modeHOMARD = modeHOMARD*13 ; }
+  if ( Inte != 0 ) { modeHOMARD = modeHOMARD*3 ; }
+  CORBA::Long codret = _gen_i->Compute(IterName, etatMenage, modeHOMARD, Option1, Option2) ;
+  MESSAGE ( "MeshInfo : codret = " << codret );
+  return ;
+}
+//=============================================================================
 //=============================================================================
 // Liens avec les autres structures
 //=============================================================================
@@ -271,7 +367,7 @@ char* HOMARD_Cas_i::GetIter0Name()
 //=============================================================================
 HOMARD::HOMARD_Iteration_ptr HOMARD_Cas_i::GetIter0()
 {
-// Nom de l'iteration parent
+// Nom de l'iteration initiale
   char* Iter0Name = GetIter0Name() ;
   MESSAGE ( "GetIter0 : Iter0Name      = " << Iter0Name );
   return _gen_i->GetIteration(Iter0Name) ;
@@ -320,3 +416,26 @@ void HOMARD_Cas_i::AddIteration( const char* NomIteration )
   ASSERT( myHomardCas );
   myHomardCas->AddIteration( NomIteration );
 }
+//=============================================================================
+//=============================================================================
+// YACS
+//=============================================================================
+//=============================================================================
+//=============================================================================
+// 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
+// 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 )
+{
+// Nom du cas
+  const char* CaseName = GetName() ;
+  MESSAGE ( "CreateYACSSchema : Schema YACS pour le cas " << YACSName);
+  MESSAGE ( "nomCas     : " << CaseName);
+  MESSAGE ( "ScriptFile : " << ScriptFile);
+  MESSAGE ( "DirName    : " << DirName);
+  MESSAGE ( "MeshFile   : " << MeshFile);
+  return _gen_i->CreateYACSSchema(YACSName, CaseName, ScriptFile, DirName, MeshFile) ;
+}