4.4.1. Procedure

  1. Compile CoFluentUnit.idl to create the AAS_CORBA module using the IDL compiler from the 3rd party CORBA implementation.

    Refer to the documentation for your CORBA compiler for details about how to compile the IDL file.

    >omniidl -bpython -I%OMNIIDLLIB% "%AWP_ROOT182%\fluent\fluent18.2.0\addons\corba\win64\CoFluentUnit.idl"
    
  2. Create the client application, client_ex.py. This very simple example will perform the following tasks:

    • Prompt the user for the location of an aaS_FluentId.txt file with connection information a remote Fluent as a Server session.

    • Create a CORBA object that will be used to connect to the remote session.

    • Obtain a scheme controller object from the Fluent as a Server session.

    • Prompt the user for the name of a case file on the client machine to upload and read into Fluent.

    • Allow the user to interactively send TUI commands to the remote session until they indicate they are finished

    • Ask the user for the names of any files on the remote Fluent as a Server machine they would like to download. These could include graphics or xy plots, case/data files, etc.

    • Exit when no more files are requested. The remote Fluent as a Server session is left running.

    Following are the major code blocks of the example program with the use of the SDK interface methods highlighted. The complete code listing appears at the end of the example (Code Listing).

    1. Import AAS_CORBA and any other required modules.

      # client_ex.py
      # A simple example of a &pn091g client application
      import os
      import io
      import CORBA
      import AAS_CORBA    #import the AAS_CORBA module compiled from CoFluentUnit.idl
      
      from functools import partial
      
    2. Prompt the user for an aaS_FluentId.txt file that points to a Fluent as a Server session and extract the IOR string.

      # Request that the user supply an aaS_FluentId.txt file with connection
      # details for a Fluent session
      iorstring=''
      
      while iorstring=='':
          filename=str(raw_input('Please provide an aaS_FluentId.txt file:\n> '))
          try:
              filehdl=open(filename,'r')
          except IOError:
              print(filename+" doesn't appear to exist!")
              continue
          
          if filehdl.read(3)!="IOR":   #if the file doesn't begin with IOR
              print(filename+" doesn't appear to contain a valid IOR string!")
              continue
          else:
              filehdl.seek(0)
              iorstring=filehdl.read()
          filehdl.close()
    3. Instantiate the ORB, connect to the Fluent as a Server session, and get a scheme interface object using ICoFluentUnit.getSchemeControllerInstance().

      # Connect to the Fluent session and open the scheme interface
      print "\nConnecting to Fluent sesssion:\n" + iorstring +"\n"
      orb=CORBA.ORB_init()
      fluent_session=orb.string_to_object(iorstring)
      scheme_interface=fluent_session.getSchemeControllerInstance()
    4. Load a local case file into the remote Fluent as a Server session.

      • Ask the user for the name of a local case file and read it into a local buffer.

      • Use ICoFluentUnit.uploadFileFromBuffer() to upload it to the remote working directory.

      • Use ICoFluentSchemeController.loadCase() to instruct the remote session to read the case file.

      # Request the name of a local case file and upload it to the Fluent server
      # machine and read it into Fluent. For simplicity in this example we assume
      # here that it is a valid case file for the running session).
      casefile=''
      while not os.path.exists(casefile):
          casefile=str(raw_input('Please provide a case file to load:\n> '))
      
      with io.FileIO(casefile) as f:
          fn_remote=os.path.basename(f.name)
          print 'Uploading file ' + fn_remote + '\n'
          f_buf_r=io.BufferedReader(f)
          scheme_interface.uploadFileFromBuffer(fn_remote,f_buf_r.read())
          fluent_session.loadCase(fn_remote)
    5. Loop through TUI / aaS commands provided by the user and use ICoFluentSchemeController.doMenuCommandToString() to execute them on the remote Fluent session and return the output to the user.

      # Once the case file is loaded, the user may enter conventional TUI
      # commands to perform simulation, write files, etc
      while True:
          try:
              command=raw_input("Please enter a TUI command (END-COSIM to finish):\n> ")
          except:
              break
          if command=='END-COSIM':
              break
          output=scheme_interface.doMenuCommandToString(command)
          print output
      
    6. Prompt the user for the names of files created on the remote system and use ICoFluentSchemeController.downloadFileToBuffer() to download them to the client machine.

      # Ask the user for any remote files they would like to retrieve, download
      # them into a buffer and write them to local files
      files=scheme_interface.doMenuCommandToString('ls')
      for fn_retrieve in iter(partial(raw_input, 'Filename to retrieve (CR when done): '), ''):
          f_local=io.FileIO(fn_retrieve,'w')
          f_buf_w=io.BufferedWriter(f_local)
          f_buf_w.write(scheme_interface.downloadFileToBuffer(fn_retrieve))
          f_buf_w.flush()
          f_buf_w.close()
      
  3. Start a remote Fluent as a Server session and copy the resulting aaS_FluentId.txt file to a convenient location on the client machine. For this example, a remote 2D Fluent session is started on a Windows machine. For illustration purposes it is made interactive with the GUI displayed, but in general this is not necessary. (see Starting Fluent In Server Mode for details on starting Fluent as a Server sessions)

  4. Run the client application, client_ex.py

    C:\Example>python client_ex.py
    Please provide an aaS_FluentId.txt file:
    >
  5. Provide the path to the aaS_FluentId.txt file

    Please provide an aaS_FluentId.txt file:
    > h:\FLServer\aaS_FluentId.txt
    
    Connecting to Fluent sesssion:
    IOR:010000002000000049444c3a4141535f434f5242412f49436f466c75656e74556e69743a312e
    30000100000000000000680000000101027f0a00000031302e312e332e383300e8e21b0000001401
    0f005253546cd1854f8c660d000000000001000000010000007f020000000000000008000000016e
    2aa4004f4154010000001800000001762aa40100010001000000010001050901010000000000
    
    Please provide a case file to load:
    >
  6. Provide the local path to a case file. In this case we are loading a 2D airfoil case

    Please provide a case file to load:
    > airfoil.cas.gz
    Uploading file airfoil.cas.gz
    
    Please enter a TUI command (END-COSIM to finish):
    >

    The case is uploaded to the remote machine and read into Fluent

  7. Execute TUI commands to initialize the solution and iterate for up to 100 iterations. (some output has been omitted for clarity)

    Please enter a TUI command (END-COSIM to finish):
    > solve initialize hyb-initialization
    
    Initialize using the hybrid initialization method.
    
    Checking case topology...
    -this case has farfield bc
    -so it will be initialized with constant pressure
    
            iter            scalar-0
    
            1               1.000000e+00
            2               1.836666e-05
            3               1.327842e-06
            4               2.862682e-07
            5               9.451323e-07
            6               1.223471e-07
            7               2.501983e-07
            8               1.137657e-07
            9               4.959297e-08
            10              2.159624e-08
    hybrid initialization is done.
    Please enter a TUI command (END-COSIM to finish):
    > solve iterate 100
      iter continuity x-velocity y-velocity     energy        nut     time/iter
         1 1.0000e+00 1.7946e-03 1.6266e-03 4.2495e-04 3.9276e-04  0:00:17   99
         2 6.3481e-01 2.0332e-03 1.3184e-03 1.1530e-04 2.9259e-04  0:00:25   98
         3 3.7028e-01 1.1406e-03 7.6986e-04 1.6216e-04 3.3093e-04  0:00:24   97
         .
         .
         .
        76 1.1063e-03 1.1319e-06 3.2180e-07 4.3823e-07 1.4217e-05  0:00:03   24
        77 1.0552e-03 1.0725e-06 2.9931e-07 4.1631e-07 1.4760e-05  0:00:03   23
      iter continuity x-velocity y-velocity     energy        nut     time/iter
        78 1.0072e-03 1.0196e-06 2.8048e-07 3.9612e-07 1.5606e-05  0:00:03   22
    !   79 solution is converged
        79 9.6023e-04 9.6787e-07 2.6549e-07 3.7618e-07 1.6702e-05  0:00:03   21
    
    Please enter a TUI command (END-COSIM to finish):
    >
    
  8. Execute TUI commands to plot the pressure field, create an image file, and save the data file. Then enter END-COSIM to complete the simulation activities.

    Please enter a TUI command (END-COSIM to finish):
    > display views camera field 3 3
    
    Please enter a TUI command (END-COSIM to finish):
    > display views camera target 0 0 0
    
    Please enter a TUI command (END-COSIM to finish):
    > display set contours filled-contours? yes
    
    Please enter a TUI command (END-COSIM to finish):
    > display contour pressure , ,
    
    Please enter a TUI command (END-COSIM to finish):
    > display set picture driver png
    
    Please enter a TUI command (END-COSIM to finish):
    > display save-picture contour_pressure.png
    
    Please enter a TUI command (END-COSIM to finish):
    > file write-data airfoil.dat.gz
    
    Writing "| gzip -2cfv > \"airfoil.dat.gz\""...
     27.0%
    Done.
    
    Please enter a TUI command (END-COSIM to finish):
    > END-COSIM
    Filename to retrieve (CR when done):
  9. Retrieve the generated files from the remote machine and enter a Carriage Return when finished to exit.

    Filename to retrieve (CR when done): airfoil.dat.gz
    Filename to retrieve (CR when done): contour_pressure.png
    Filename to retrieve (CR when done): <CR>
    
    
  10. View the contour plot on the local machine


Release 18.2 - © ANSYS, Inc. All rights reserved.