Ansys Products

Ansys Products

Discuss installation & licensing of our Ansys Teaching and Research products

Problem with Perl & CEL Scripting with Loop in CFX-Post

    • Dr Fatima Razavi, PhD in MEC ENG
      Subscriber

      Hello,

      I have been attempting to automate the export of simulated data from ANSYS CFX using a Perl script and CEL (CFX Expression Language). The code is relatively simple: I'm trying to iterate over 120 timesteps with a difference of 100 between each timestep. For each iteration, I load the corresponding timestep and save the data on a specific plane to a separate CSV file.

      I have successfully tested the script for 3 timesteps individually, and it works well. However, when I attempt to implement a loop to iterate over all 120 timesteps, I encounter errors that I have been unable to resolve. These errors seem to be preventing the script from executing correctly.

      I would greatly appreciate your assistance in troubleshooting and resolving these errors. If needed, I can provide you with the Perl script, the CEL expressions, or any specific error messages that I'm receiving.

      Thank you for your help. My email address is: dr.fatemeh.razavi@gmail.com

      #THIS ONE WORKS
      # Session file started:  2023/06/22 12:37:39
      # CFX-21.2
       
      # To avoid unnecessary file pre-processing and modifications, include
      # COMMAND FILE at the top of your session file.
      # If it is not included, the file is assumed to be older and will be
      # modified for backward compatibility.
      COMMAND FILE:
        CFX Post Version = 21.2
      END
       
       
      PLANE:Plane 1
        Apply Instancing Transform = On
        Apply Texture = Off
        Blend Texture = On
        Bound Radius = 0.5 [m]
        Colour = 0.75, 0.75, 0.75
        Colour Map = Default Colour Map
        Colour Mode = Variable
        Colour Scale = Logarithmic
        Colour Variable = Ragweed.Averaged Volume Fraction
        Colour Variable Boundary Values = Conservative
        Culling Mode = No Culling
        Direction 1 Bound = 1.0 [m]
        Direction 1 Orientation = 0 [degree]
        Direction 1 Points = 10
        Direction 2 Bound = 1.0 [m]
        Direction 2 Points = 10
        Domain List = /DOMAIN GROUP:All Domains
        Draw Contours = Off
        Draw Faces = On
        Draw Lines = Off
        Instancing Transform = /DEFAULT INSTANCE TRANSFORM:Default Transform
        Invert Plane Bound = Off
        Lighting = On
        Line Colour = 0, 0, 0
        Line Colour Mode = Default
        Line Width = 1
        Max = 0.0
        Min = 0.0
        Normal = 1 , 0 , 0
        Number of Contours = 11
        Option = XY Plane
        Plane Bound = None
        Plane Type = Slice
        Point = 0 [m], 0 [m], 0 [m]
        Point 1 = 0 [m], 0 [m], 0 [m]
        Point 2 = 1 [m], 0 [m], 0 [m]
        Point 3 = 0 [m], 1 [m], 0 [m]
        Range = Global
        Render Edge Angle = 0 [degree]
        Specular Lighting = On
        Surface Drawing = Smooth Shading
        Texture Angle = 0
        Texture Direction = 0 , 1 , 0
        Texture File =
        Texture Material = Metal
        Texture Position = 0 , 0
        Texture Scale = 1
        Texture Type = Predefined
        Tile Texture = Off
        Transform Texture = Off
        Transparency = 0.0
        X = 0.0 [m]
        Y = 0.0 [m]
        Z = 1.6 [m]
        OBJECT VIEW TRANSFORM:
          Apply Reflection = Off
          Apply Rotation = Off
          Apply Scale = Off
          Apply Translation = Off
          Principal Axis = Z
          Reflection Plane Option = XY Plane
          Rotation Angle = 0.0 [degree]
          Rotation Axis From = 0 [m], 0 [m], 0 [m]
          Rotation Axis To = 0 [m], 0 [m], 0 [m]
          Rotation Axis Type = Principal Axis
          Scale Vector = 1 , 1 , 1
          Translation Vector = 0 [m], 0 [m], 0 [m]
          X = 0.0 [m]
          Y = 0.0 [m]
          Z = 0.0 [m]
        END
      END
       
      # Sending visibility action from ViewUtilities
      >show /PLANE:Plane 1, view=/VIEW:View 1
       
      ##################
      > load timestep=30888
       
      EXPORT:
        ANSYS Export Data = Element Heat Flux
        ANSYS File Format = ANSYS
        ANSYS Reference Temperature = 0.0 [K]
        ANSYS Specify Reference Temperature = Off
        ANSYS Supplemental HTC = 0.0 [W m^-2 K^-1]
        Additional Variable List =
        BC Profile Type = Inlet Velocity
        CSV Type = CSV
        Case Name = Case 2nd3min7ms
        Export Connectivity = Off
        Export Coord Frame = Global
        Export File = E:/Fatemeh (Live Runs)/BEST CFD Runs/2023-06-05-Transient-\
      8Diff-4PartInj-FansSQ-0TO180-7ms/2023-06-05-ExhaustsOnWall-8SwirrlDiffON-\
      4Aerosolizers-FansFwBw7msSynchronized-FansSQ_003/CSV Files/303.csv
        Export Geometry = On
        Export Location Aliases =
        Export Node Numbers = Off
        Export Null Data = On
        Export Type = Generic
        Export Units System = Current
        Export Variable Type = Current
        External Export Data = None
        Include File Information = Off
        Include Header = On
        Location = CeilingWall
        Location List = /PLANE:Plane 1
        Null Token = null
        Overwrite = On
        Precision = 8
        Separator = ", "
        Spatial Variables = X,Y,Z
        Variable List = Ragweed.Averaged Volume Fraction
        Vector Brackets = ()
        Vector Display = Scalar
      END
      >export
      ################################
      ################################
      ################################
      #This one does not work as I added the loop in Perl and it gives me many warnings and errors
      # Session file started:  2023/06/20 11:37:01
      # CFX-21.2
       
      # To avoid unnecessary file pre-processing and modifications, include
      # COMMAND FILE at the top of your session file.
      # If it is not included, the file is assumed to be older and will be
      # modified for backward compatibility.
      COMMAND FILE:
        CFX Post Version = 21.2
      END
       
      # Session file stopped:  2023/06/20 11:37:15
       
      # Session file started:  2023/06/20 11:37:39
      # CFX-21.2
       
      # To avoid unnecessary file pre-processing and modifications, include
      # COMMAND FILE at the top of your session file.
      # If it is not included, the file is assumed to be older and will be
      # modified for backward compatibility.
      COMMAND FILE:
        CFX Post Version = 21.2
      END
       
      PLANE:Plane 1
        Apply Instancing Transform = On
        Apply Texture = Off
        Blend Texture = On
        Bound Radius = 0.5 [m]
        Colour = 0.75, 0.75, 0.75
        Colour Map = Default Colour Map
        Colour Mode = Variable
        Colour Scale = Logarithmic
        Colour Variable = Ragweed.Averaged Volume Fraction
        Colour Variable Boundary Values = Conservative
        Culling Mode = No Culling
        Direction 1 Bound = 1.0 [m]
        Direction 1 Orientation = 0 [degree]
        Direction 1 Points = 10
        Direction 2 Bound = 1.0 [m]
        Direction 2 Points = 10
        Domain List = /DOMAIN GROUP:All Domains
        Draw Contours = Off
        Draw Faces = On
        Draw Lines = Off
        Instancing Transform = /DEFAULT INSTANCE TRANSFORM:Default Transform
        Invert Plane Bound = Off
        Lighting = On
        Line Colour = 0, 0, 0
        Line Colour Mode = Default
        Line Width = 1
        Max = 0.0
        Min = 0.0
        Normal = 1 , 0 , 0
        Number of Contours = 11
        Option = XY Plane
        Plane Bound = None
        Plane Type = Slice
        Point = 0 [m], 0 [m], 0 [m]
        Point 1 = 0 [m], 0 [m], 0 [m]
        Point 2 = 1 [m], 0 [m], 0 [m]
        Point 3 = 0 [m], 1 [m], 0 [m]
        Range = Global
        Render Edge Angle = 0 [degree]
        Specular Lighting = On
        Surface Drawing = Smooth Shading
        Texture Angle = 0
        Texture Direction = 0 , 1 , 0
        Texture File =
        Texture Material = Metal
        Texture Position = 0 , 0
        Texture Scale = 1
        Texture Type = Predefined
        Tile Texture = Off
        Transform Texture = Off
        Transparency = 0.0
        X = 0.0 [m]
        Y = 0.0 [m]
        Z = 1.6 [m]
        OBJECT VIEW TRANSFORM:
          Apply Reflection = Off
          Apply Rotation = Off
          Apply Scale = Off
          Apply Translation = Off
          Principal Axis = Z
          Reflection Plane Option = XY Plane
          Rotation Angle = 0.0 [degree]
          Rotation Axis From = 0 [m], 0 [m], 0 [m]
          Rotation Axis To = 0 [m], 0 [m], 0 [m]
          Rotation Axis Type = Principal Axis
          Scale Vector = 1 , 1 , 1
          Translation Vector = 0 [m], 0 [m], 0 [m]
          X = 0.0 [m]
          Y = 0.0 [m]
          Z = 0.0 [m]
        END
      END
       
      # Sending visibility action from ViewUtilities
      >show /PLANE:Plane 1, view=/VIEW:View 1
       
      ##################
       
      # Specify the starting timestep and the number of iterations
       no warnings 'redefine';
       use strict;
       
       my $startTimestep = 24588;
       my $numIterations = 5;  # Adjust the number of iterations as needed
       
      # Loop to load timesteps with a difference of 100
       for (my $i = 0; $i < $numIterations; $i++) {
         my $timestep = $startTimestep + ($i * 100);
       > load timestep = $timestep
       
         EXPORT:
           ANSYS Export Data = Element Heat Flux
           ANSYS File Format = ANSYS
           ANSYS Reference Temperature = 0.0 [K]
           ANSYS Specify Reference Temperature = Off
           ANSYS Supplemental HTC = 0.0 [W m^-2 K^-1]
           Additional Variable List =
       BC Profile Type = Inlet Velocity
           CSV Type = CSV
           Case Name = Case 2nd3min7ms
       
           Export Connectivity = Off
           Export Coord Frame = Global
          # Generate the CSV file path
           Export File = E:/Fatemeh (Live Runs)/BEST CFD Runs/2023-06-05-Transient-\
      8Diff-4PartInj-FansSQ-0TO180-7ms/2023-06-05-ExhaustsOnWall-8SwirrlDiffON-\
      4Aerosolizers-FansFwBw7msSynchronized-FansSQ_003/CSV Files/$timestep.csv"
           Export Geometry = On
           Export Location Aliases =
           Export Node Numbers = Off
           Export Null Data = On
           Export Type = Generic
           Export Units System = Curren
           Export Variable Type = Current
           External Export Data = None
           Include File Information = Off
           Include Header = On
           Location = CeilingWall
           Location List = /PLANE:Plane 1
           Null Token = null
           Overwrite = On
           Precision = 8
           Separator = ", "
           Spatial Variables = X,Y,Z
           Variable List = Ragweed.Averaged Volume Fraction
           Vector Brackets = ()
           Vector Display = Scalar
         END
       
         >export
       }

      ################################
      ################################
      SAMPLE ERRORS AND WARNINGS
      Variable "$timestep" is not imported at (eval 189) line 11.
      Variable "$timestep" is not imported at (eval 189) line 24.
      Use of uninitialized value $CUEPost::startTimestep in concatenation (.) or string at (eval 193) line 5.
      Use of uninitialized value $CUEPost::numIterations in concatenation (.) or string at (eval 193) line 6.
      Use of uninitialized value $CUEPost::i in concatenation (.) or string at (eval 193) line 7.
      Use of uninitialized value $CUEPost::i in concatenation (.) or string at (eval 193) line 7.
      Use of uninitialized value $CUEPost::numIterations in concatenation (.) or string at (eval 193) line 7.
      Use of uninitialized value $CUEPost::i in concatenation (.) or string at (eval 193) line 7.
      Variable "$startTimestep" is not imported at (eval 217) line 7.
      Variable "$numIterations" is not imported at (eval 217) line 8.
      Variable "$i" is not imported at (eval 217) line 9.
      Variable "$i" is not imported at (eval 217) line 9.
      Variable "$numIterations" is not imported at (eval 217) line 9.
      Variable "$i" is not imported at (eval 217) line 9.
      Variable "$timestep" is not imported at (eval 217) line 10.
      Variable "$startTimestep" is not imported at (eval 217) line 10.
      Variable "$i" is not imported at (eval 217) line 10.
      Variable "$timestep" is not imported at (eval 217) line 11.
      Variable "$timestep" is not imported at (eval 217) line 24.
      Variable "$i" is not imported at (eval 221) line 9.
      Variable "$i" is not imported at (eval 221) line 9.
      Variable "$i" is not imported at (eval 221) line 9.
      Variable "$timestep" is not imported at (eval 221) line 10.
      Variable "$i" is not imported at (eval 221) line 10.
      Variable "$timestep" is not imported at (eval 221) line 11.
      Variable "$timestep" is not imported at (eval 221) line 24.


    • rosa bella
      Subscriber

      I've been checking this blog on a frequent basis and I'm amazed at 2048! Very fascinating stuff, particularly the final section. 

Viewing 1 reply thread
  • You must be logged in to reply to this topic.