Ansys Assistant will be unavailable on the Learning Forum starting January 30. An upgraded version is coming soon. We apologize for any inconvenience and appreciate your patience. Stay tuned for updates.
Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

Fluent TUI for HPC cluster

    • climomichael
      Subscriber

      Hi there!

      I have been working for Ansys for some time now but am new to Fluent and to the Fluent TUI. For my master thesis I need to run some transient simulations on a tube and use a plane in that transient simulation as a time dependent boundary condition in a new simulation. The journal script I have sofar is:

      ; --- Load steady-state case and data ---
      /file/read-case FFF2.cas
      /file/read-data FFF2.dat

      ; --- Turn off autosave completely ---
      /file/auto-save/data-frequency 0
      /file/auto-save/case-frequency if-case-is-modified

      ; --- Set transient solver ---
      /define/models/steady no

      ; --- Create plane surface at x = 2.1 ---
      /surface/plane-surface output_plane1 yz-plane 2.1

      ; --- Add automatic export at each timestep ---
      ;/solve/execute-commands/add-edit per_time_step no 1 time-step "To ensure the data is stored each time-step"
      ;/file/export/cdat-for-cfd-post-&-ensi plane_out/CFD_1_%t output_plane1 () () velocity-magnitude turb-diss-rate turb-kinetic-energy () yes

      /solve/execute-commands/add-edit per_time_step no 1 time-step "To ensure the data is stored each time-step"
      /file/write-profile OP_Prof_1_%t output_plane1 () velocity-magnitude turb-diss-rate turb-kinetic-energy ()

      ; --- Run transient ---
      /solve/set/transient-controls/fixed-user-specified yes
      /solve/set/transient-controls/time-step-size 2e-5
      /solve/set/transient-controls/number-of-time-steps 10
      /solve/set/transient-controls/max-iterations-per-time-step 50
      /solve/set/p-v-coupling 22
      /solve/dual-time-iterate

      ; --- Save final case/data ---
      /file/write-case-data /vast.mnt/home/20202458/HPC1/Zaida3/Tube_In_2/plane_out/final_1.cas 

      exit yes

      This runs but the line for the write-profile only makes one file instead of making a file every time step. I have been working on this for some time now but cannot seem to find the right way to do so. I tried solving it as cdat files, and that seems to work in this manner, but that does not as well for usage in boundary conditions. 

      I would greatly appreciate some help on this topic!
      Thank you in advance

      Kind regards,

      Michael

    • Rob
      Forum Moderator

      Are you trying to write a profile at every time step? What data are you trying to extract? 

      Overall the journal looks OK, but as you're reading a case and data that implies you can open that locally? If so, why not set up all of the functions locally and then send the completed case & data to the cluster? I use TUI commands when I need to, but the GUI is much easier. 

    • climomichael
      Subscriber

      Hi Rob,

      Thank you for the quick reply. I am indeed trying to write a profile every time-step, this should include: velocity-magnitude, turb-diss-rate, turb-kinetic-energy. 

      I can indeed load in the case and data, but I am unsure if the GUI captures a way to save the profile per time-step. I can save it per time step but then the surface is averaged (via report definitions), or I can save the surface for one time-step (via profile). But in the profile tab I cannot add that is saves it every time step. Or have I missed an essential part?



       

    • Rob
      Forum Moderator

      Profile might not retain a unique ID so it may overwrite. Have a look at the options in /file/export and check the ASCII bits.   You're correct in needing the TUI commands to set things up in Execute Commands, but you can use the TUI commands in the GUI panels to do some of this as opposed to running a journal. It's easier to test too! 

      For info, %t appends time step to a file, %i the iteration number and %f the flow time. The latter can struggle with very small time steps as the step size can be too small for the number syntax in the file name. 

    • m.a.climo
      Subscriber

      Yeah, I also thought it was that at first that why I added the %t, this works because I get the file OP_Prof_1_0000 but nothing after that. Ah yes the command window is indeed perfect to test! I am using it all the time and its so handy, however I can only save it for one time step there. I can use the /file/export and this worked:
      /file/export/cdat-for-cfd-post-&-ensi plane_out/CFD_1_%t output_plane1 () () velocity-magnitude turb-diss-rate turb-kinetic-energy () yes


      But then it becomes harder to read into another case as a boundary condition, or is that possible with ascii (or something else from that menu)?
      These are the options there:

      ascii fieldview-unstruct

      cdat-for-cfd-post-&-ensight              fieldview-unstruct-data

      cgns                                                 fieldview-unstruct-mesh

      ensight-dvs-surfaces                       fieldview-unstruct-surfaces

      ensight-dvs-volume                         icemcfd-for-icepak

      ensight-gold                                     nastran

      ensight-gold-parallel-surfaces         settings/

      ensight-gold-parallel-volume           system-coupling-definition-file-settings/

      fieldview                                          tecplot

      fieldview-data




    • m.a.climo
      Subscriber

      Ah but is the ascii file is simular to the file profile creates? In that way it should maybe be able with these lines:
      ; --- Add automatic export at each timestep ---
      /solve/execute-commands/add-edit per_time_step no 1 time-step "To ensure the data is stored each time-step"
      /file/export/ascii CFD_1_%t output_plane1 () () velocity-magnitude turb-diss-rate turb-kinetic-energy () yes

    • Rob
      Forum Moderator

      Should be, just make sure you don't save in binary.  I'd typically set up the data export via the GUI to check the format etc, and then set the Execute Command in the GUI to trigger the TUI command to save the data. If you journal everything you won't know if it went wrong until you're on the cluster. 

    • climomichael
      Subscriber

      Hi Rob, 

      I appreciate the help so far and got it to work because of it! I now have the ASCII files, which I reordered via MATLAB to become a .prof file. Now I have these per time step, and I need to load this into another transient simulation. I am a trying to load in the data per time step but I am not succeeding with this. What I saw in another post is that the execute-commands can be used to perform this but I don't seem to get it to work. Do you by any chance have an example script on how to do this or some further tips? I am a bit confused by the execute-command in general, it makes a command that is called up every time step, but how to know which commands it should do or to specify this?

      I truly appreciate the time you take to think along! 
      Kind regards,
      Michael


      If someone needs it, here is the MATLAB code:

      % This script is used to convert the ASCII output data into .prof data such
      % that it can be read into the simulation again.

      % Create output folder
      out_folder = 'BC_JUNCTION';
      if ~exist(out_folder, 'dir')
          mkdir(out_folder);
      end

      % Number of time steps
      time_steps  = 2000;

      for i = 1:time_steps
          print(i)
          if i < 10
              file_name = ['BC_INLET_-000', num2str(i)];
              out_file  = ['BC-000', num2str(i), '.prof'];
          elseif i < 100
              file_name = ['BC_INLET_-00', num2str(i)];
              out_file  = ['BC-00', num2str(i), '.prof'];
          elseif i < 1000
              file_name = ['BC_INLET_-0', num2str(i)];
              out_file  = ['BC-0', num2str(i), '.prof'];
          else
              file_name = ['BC_INLET_-', num2str(i)];
              out_file  = ['BC-', num2str(i), '.prof'];
          end
          
          % Prepend folder to output file
          out_file = fullfile(out_folder, out_file);

          % Read ASCII data
          raw = readmatrix(file_name);
          x   = raw(:,2);
          y   = raw(:,3);
          z   = raw(:,4);
          vel = raw(:,5);
          k   = raw(:,6);
          eps = raw(:,7);
          npts = length(x);

          % Open output file
          fid = fopen(out_file, 'wt');
          fprintf(fid, '((bc_i_plane point %d)\n', npts);
          varnames = {'x', 'y', 'z', 'velocity-magnitude', 'turb-kinetic-energy', 'turb-diss-rate'};
          
          for ii = 1:length(varnames)
              fprintf(fid, '(%s\n', varnames{ii});
              for iii = 1:npts
                  switch varnames{ii}
                      case 'x'
                          fprintf(fid, '%.9f\n', x(iii));
                      case 'y'
                          fprintf(fid, '%.13f\n', y(iii));
                      case 'z'
                          fprintf(fid, '%.11f\n', z(iii));
                      case 'velocity-magnitude'
                          fprintf(fid, '%.5f\n', vel(iii));
                      case 'turb-kinetic-energy'
                          fprintf(fid, '%.5f\n', k(iii));
                      case 'turb-diss-rate'
                          fprintf(fid, '%.5f\n', eps(iii));
                  end        
              end
              fprintf(fid, ')\n');
          end

          fprintf(fid, ')\n\n');
          fclose(fid);
      end 



    • Rob
      Forum Moderator

      Thanks for posting the code, that's something we can't do, so much appreciated. 

      I wouldn't update the profile every time step as you'll shock the solver every time and that may not be good. An update every 5-10 time steps may be more suitable and will reduce your solver down time too. Assuming the profile has time step appended to the label, or worst case flow time, then you can read the profile and see if %t or %f work in TUI commands (look them up in the File bits of the manual). You may then need to reapply the profile, but again the %t or %f flag may work. Otherwise it's journal time and the journal has a repeating section for profile read, profile set up iterate, profile read.... etc. I've used AWK scripts to build the journal based on the files in a folder, but I'd expect Python to be equally capable. 

       

    • climomichael
      Subscriber

      Hi, 

      I got a way in which it works for me. In this way i first solved the steady state solution and then calculated that with different time steps by manually making time steps and loading in profile data. This is the journal file I have now:

      ;Load case & data
      /file/read-case T_Junk_SS1.cas
      /file/read-data T_Junk_SS1.dat

      ;Set trans solver
      /solve/set/number-of-iterations 200
      /solve/set/p-v-coupling 22
      /solve/iterate

      /define/models/unsteady-1st-order yes
      /solve/set/transient-controls/fixed-user-specified yes
      /solve/set/transient-controls/time-step-size 2e-5
      /solve/set/transient-controls/max-iterations-per-time-step 200
      /solve/set/p-v-coupling 22
      /surface/plane-surface plane_output_t yz-plane 0

      ;; helper function for zero padding
      (define (zero-pad n width)
        (let ((s (number->string n)))
          (if (< (string-length s) width)
              (string-append (make-string (- width (string-length s)) #\0) s)
              s)))

      (define nsteps 2000)

      (do ((i 1 (+ i 1)))
          ((> i nsteps) (format #t "Done~%"))
        (let* ((numstr (zero-pad i 4)) ; "0001", "0002", etc.
               (fname (string-append
                       "..."
                       numstr))
               (plane-data-file (string-append "..."
                                               numstr)))
          
          (format #t "Reading profile: ~a~%" fname)

          ;; load profile
          (ti-menu-load-string (string-append "/file/read-profile " fname))

          ;; set BC
          (ti-menu-load-string "/define/boundary-conditions/velocity-inlet inlet_t no no yes yes yes no bc_i_plane velocity-magnitude no 0 yes yes no bc_i_plane turb-kinetic-energy yes no bc_i_plane turb-diss-rate")

          ;; run one timestep
          (ti-menu-load-string "/solve/dual-time-iterate 1")

          ;; save plane data (one file per timestep)
      (ti-menu-load-string (string-append "/file/export/ascii " plane-data-file " plane_output_t () no velocity-magnitude pressure () no no ascii"))))

      Hopefully, this is useful for someone else as well. Feel free to use it. 

Viewing 9 reply threads
  • You must be logged in to reply to this topic.
[bingo_chatbox]