def _createFvMesh( self ) :
        """
        Creates fvMesh
        """
        # Connect to SALOME
        import hybridFlu.pysalome

        import salome
        aStudyId = salome.myStudy._get_StudyId()

        # Generation of the mesh
        from hybridFlu.examples import test_create_smesh
        [ aMesh, GroupList ] = test_create_smesh.createMesh()

        from hybridFlu import smesh2foam
        self.ext_autoPtr_fvMesh = smesh2foam.execute( aMesh, self.run_time )
        
        return self.ext_autoPtr_fvMesh(), None
    def _createFvMesh( self ) :
        """
        Creates fvMesh
        """
        # Connect to SALOME
        import hybridFlu.pysalome

        import salome
        aStudyId = salome.myStudy._get_StudyId()

        # Generation of the mesh
        from hybridFlu.examples import test_create_smesh
        [ aMesh, GroupList ] = test_create_smesh.createMesh()

        # Restoring values for the "root" and OpenFOAM "case" directories
        import os, os.path
        a_path = str( self.run_time.path() )
        a_root_dir, a_case = os.path.split( a_path )

        print_d( "a_root_dir = \"%s\"" % a_root_dir )
        print_d( "a_case = \"%s\"" % a_case )

        import tempfile
        a_tmp_file = tempfile.NamedTemporaryFile()
        an_unv_file_name = a_tmp_file.name
        
        aMesh.ExportUNV( an_unv_file_name )

        if os.environ[ "WM_PROJECT_VERSION" ] < "1.5" :
            os.system( "unv2foam %s %s %s" %( a_root_dir, a_case, an_unv_file_name ))
            pass
        else :
            os.system( "unv2foam %s -case %s" %( an_unv_file_name, a_path ))
            pass

        a_fvMesh = ref.fvMesh( ref.IOobject( ref.word( "" ),
                                             self.run_time.caseConstant(),
                                             self.run_time,
                                             ref.IOobject.MUST_READ,
                                             ref.IOobject.NO_WRITE ) )
    
        return a_fvMesh, None
Exemplo n.º 3
0
    def _createFvMesh( self ) :
        """
        Creates fvMesh
        """
        # Connect to SALOME
        import hybridFlu.pysalome

        import salome
        aStudyId = salome.myStudy._get_StudyId()

        # Generation of the mesh
        from hybridFlu.examples import test_create_smesh
        [aMesh, GroupList] = test_create_smesh.createMesh()

        # load foam engine
        import FOAM
        from batchmode_salome import lcc
        aFOAM = lcc.FindOrLoadComponent("FactoryServer", "FOAM")

        aFOAM.OpenTransaction(aStudyId)

        # Restoring values for the "root" and OpenFOAM "case" directories
        import os, os.path   
        a_root_dir, a_case = os.path.split( str( self.run_time.path() ) )
        a_root_dir, a_solver = os.path.split( str( a_root_dir ) )

        import tempfile
        a_root_dir = tempfile.mkdtemp()

        print_d( "a_root_dir = \"%s\"" % a_root_dir )
        print_d( "a_solver = \"%s\"" % a_solver )
        print_d( "a_case = \"%s\"" % a_case )

        # It is necessary to create a solver instance (it does not matter what)
        icoFoam = aFOAM.AddSolver( aStudyId, FOAM.ST_Ico )
        icoFoam.SetName( a_solver )

        # It is necessary to create a case instance (it does not matter what)
        aCase = icoFoam.AddCase( a_case )
        #aCase.GenerateDictionaries()

        # set MESH
        aCase.SetMesh( aMesh.GetMesh(), False )

        # add boundary condition foam_inlet_F
        foam_inlet_F = aCase.AddBndCondition()
        foam_inlet_F.SetName( "inlet_F" )
        foam_inlet_F.SetBaseType( FOAM.BASETYPE_PATCH )
        foam_inlet_F.SetPhysicalType( FOAM.PHTYPE_INLET )
        foam_inlet_F.SetGroup( GroupList[ 0 ] )

        # add boundary condition foam_outlet_F1
        foam_outlet_F1 = aCase.AddBndCondition()
        foam_outlet_F1.SetName( "outlet_F1" )
        foam_outlet_F1.SetBaseType( FOAM.BASETYPE_PATCH )
        foam_outlet_F1.SetPhysicalType( FOAM.PHTYPE_OUTLET )
        foam_outlet_F1.SetGroup( GroupList[ 1 ] )

        # add boundary condition foam_outlet_F2
        foam_outlet_F2 = aCase.AddBndCondition()
        foam_outlet_F2.SetName( "outlet_F2" )
        foam_outlet_F2.SetBaseType( FOAM.BASETYPE_PATCH )
        foam_outlet_F2.SetPhysicalType( FOAM.PHTYPE_OUTLET )
        foam_outlet_F2.SetGroup( GroupList[ 2 ] )

        # add boundary condition foam_pipe
        foam_pipe = aCase.AddBndCondition()
        foam_pipe.SetName( "pipe" )
        foam_pipe.SetBaseType( FOAM.BASETYPE_WALL )
        foam_pipe.SetGroup( GroupList[ 3 ] )

        # ============
        # publish case
        aFOAM.PublishCase( salome.myStudy, aCase, aMesh.GetMesh(), GroupList )
        aFOAM.CommitTransaction( aStudyId )

        salome.sg.updateObjBrowser( 1 )
        # ============

        # creates case folder with all corresponding dictionaries 
        aFOAM.CreateCaseFolder( aCase, a_root_dir )

        # extracts only "constant" file structure 
        import shutil, os, os.path

        a_source = os.path.join( a_root_dir, a_solver, a_case )

        # removes the temporal "system" file structure 
        shutil.rmtree( os.path.join( a_source, str( self.run_time.caseSystem() ) ) )

        a_source = os.path.join( a_source, str( self.run_time.caseConstant() ) )
        print_d( "a_source = \"%s\"" % a_source )

        a_path = str( self.run_time.path() )
        a_destination = os.path.join( a_path, str( self.run_time.caseConstant() ) )
        print_d( "a_destination = \"%s\"" % a_destination )

        # moves the "constant" file structure to the proper location
        if os.path.exists( a_destination ) :
            shutil.rmtree( a_destination )
            pass
        shutil.copytree( a_source, a_destination )
        #shutil.move( a_source, a_destination )

        # removes the root of the temporal file structure
        shutil.rmtree( a_root_dir )

        # Read temporary mesh from file - done only so we can get the list of points, faces and cells
        a_fvMesh = fvMesh( IOobject( word( "" ),
                                     self.run_time.caseConstant(),
                                     self.run_time,
                                     IOobject.NO_READ,
                                     IOobject.NO_WRITE ) )

        return a_fvMesh, None