CFXPost Macros
Hi everyone,
Many of you are probably familiar with the use of macros to postprocess CFX results and I need a little help to get me started. I have little experience with CFX but I'm slowly improving my skills! I'm actually trying to use the "Solution variables" available in CFXPost but I don't understand how to do it properly. To give you and idea, I've written a small macro to calculate the Reynolds number. The 6th line from the end starting with "!Reynolds =..." isn't working since the variables "Density" and "Dynamic Viscosity" are not recognized. Anyone know how I should do it? I would prefer not to create another user scalar variable since it wouldn't work for all the things I want to evaluate! Also, if you know where I could find good documentation on macros it would be of great help. Thanks a lot to you all! Felix _______________________________________ # Macro GUI begin # macro name = Reynolds tests # macro subroutine = losses # macro report file = losses.dat # macro parameter = Diameter [m] # type = float # default = 0.383 # Macro GUI end >variables Boundary Values = Conservative # Macro in pearl ! sub losses { ! ($dia)=@_; USER SCALAR VARIABLE:Rvar Recipe = Expression Expression = sqrt(x^2+y^2) User Units = m END USER SCALAR VARIABLE:ThetaVar Recipe = Expression Expression = atan2(y,x) User Units = END USER SCALAR VARIABLE:Vr Recipe = Expression Expression = Velocity u*cos(ThetaVar)+Velocity v*sin (ThetaVar) User Units = END USER SCALAR VARIABLE:Vm Recipe = Expression Expression = sqrt(Vr*Vr + Velocity w * Velocity w) User Units = END ! $Reynolds = $Density * ave("Vm", "Inlet") * $dia / $Dynamic Viscosity; ! open (MYFILE, ">Reynolds.dat"); ! print MYFILE "Reynolds number:\t\t$Reynolds\n"; ! print MYFILE "\n"; ! close (MYFILE); ! } # end subroutine 
Re: CFXPost Macros  Problem solved
Hi there,
I thought of something this morning and it seems like I've solved my problem. It might help someone to know how to do it. Although the variables "Density" and "Dynamic Viscosity" are constant in my problem, I do have to define where to evaluate them. So the problematic line should be written as follow (or in a similar way): ! $Reynolds = ave("Density", "Inlet") * ave("Vm", "Inlet") * $dia / ave("Dynamic Viscosity", "Inlet") ; I hope it will help someone! And again, if you know where I could find good documentation on macros, just let me know! Thanks Felix 
Re: CFXPost Macros
Hi Felix,
I think you have misunderstood how Perl interacts with Post. You should do all of your calculations in CEL, then use the evaluate() function to get the results of expression. Post variables are not otherwise available to the Perl interpreter as variables. Also, your expression should include call backs at specific locations to return a single value, as opposed to a variable. To write this as an expression, then use the 'evaluate()' function to get the value of your expression do the following : EXPRESSIONS: Reynolds Number = massFlowAve(Density)@Inlet * massFlowAve(Vm)@Inlet * $dia / massFlowAve(Dynamic Viscosity)@Inlet END !($ReynoldsNumber, $ReynoldsNumber_units)=evaluate('Reynolds Number'); Note that you could also calculate your hydraulic diameter as: InletDiameter = sqrt(4*area()@Inlet/pi) The other way Perl and Post interact is that the Perl interpreter will evaluate Perl scalars (which may be numbers or strings) before sending CCL to Post Engine. As a simple example, here is how you could make the averaging type an option in your macro. Add a header for the option: # macro parameter = Averaging type # type = list # list = massFlowAve, areaAve, ave # default = massFlowAve ... Dumpt this to the appropriate Perl variable, say $aveType, then write your expressions as: EXPRESSIONS: Reynolds Number = $aveType(Density)@Inlet * $aveType(Vm)@Inlet * $dia / $aveType(Dynamic Viscosity)@Inlet END In the above example, the Perl interpreter will replace $aveType with the string entered above before processing the expression in the engine. This is a simple example, but it should demonstrate how Post and Perl interact. Note that you should rarely use 'ave' as this is a simple arithmetic average of the nodal values. It is generally better to use mass or area weighted averaging. Which to use when is another topic. Regards, Robin 
Re: CFXPost Macros  Problem solved
Hi Felix,
I don't recommend doing it this way, althoug it will work. For more info on macros, have a look at the Tech Tips on the CFX Community Site. There is a very good tech tip from a few years ago name "Creating CFX Pist Macros" at http://wwwwaterloo.ansys.com/commun...AAF758934B6D1. You should find this useful. Regards, Robin 
Re: CFXPost Macros
Hi Robin,
Thanks a lot for your tips, I truly appreciate. I actually am working with an existing macro and trying to add a few components on it and you're absolutely right, the interaction between Perl and Post isn't completely clear for me. I will try your way of programming the macro right away but can you tell me why you don't recommend doing it my way? Thanks again, Felix 
Re: CFXPost Macros
Hi Felix,
If you write it as an expression, it will be available in Post as well. Also, it's generally easier to write the CEL expressions in Post. Regards, Robin 
Hi everyone! Please help me :(
I have a problem with this code : LIBRARY: CEL: EXPRESSIONS: S = 0.0815 [m] n = 6000 tStep = 0.005 [s] tTotal = 10 [s] Vinlet = (S/2) * (n*pi/30) * (sin(n*pi*t/30) + 0.5 * (1/3.2) * sin(n*pi*t/15 )) END END END But it did not work and have a error " ERROR The dimensions of the argument to function 'sin' are inconsistent with expected dimensions. Argument dimensions resolve to 's'; expected 'rad'. " Thank you very much in advance ! :) 
I answered your question in another post, please only post your question in one thread. Make the sin function dimensionless: sin(n*pi*t/30[s]), otherwise the argument dimension will resolve to [s] instead of [rad], just as the error message says.

I see...:p
I got it ! Thank you ver much :) 
Hi Lance ! Please help me !
I am simulating for venturi tube But I don't know my simualtion setting is right or not ??? :( Escpecially in setting Solver Manager  Transient model ! Here is Command Editor : " &replace FLOW: Flow Analysis 1 ANALYSIS TYPE: Option = Transient EXTERNAL SOLVER COUPLING: Option = None END INITIAL TIME: Option = Automatic with Value Time = 0 [s] END TIME DURATION: Option = Time per run Time per run = 500 [s] END TIME STEPS: Option = Timesteps Timesteps = 1e005 [s] END END DOMAIN: Default Coord Frame = Coord 0 Domain Type = Fluid Location = part_1 BOUNDARY: Default Default Boundary Type = WALL Create Other Side = Off Interface Boundary = Off Location = wall part_1 BOUNDARY CONDITIONS: HEAT TRANSFER: Option = Adiabatic END MASS AND MOMENTUM: Option = No Slip Wall END WALL ROUGHNESS: Option = Smooth Wall END END END BOUNDARY: Inlet Boundary Type = INLET Interface Boundary = Off Location = inlet BOUNDARY CONDITIONS: FLOW REGIME: Option = Subsonic END HEAT TRANSFER: Option = Static Temperature Static Temperature = 298 [K] END MASS AND MOMENTUM: Normal Speed = Vinlet Option = Normal Speed END TURBULENCE: Option = Medium Intensity and Eddy Viscosity Ratio END END END BOUNDARY: Outlet Boundary Type = OUTLET Interface Boundary = Off Location = outlet BOUNDARY CONDITIONS: FLOW REGIME: Option = Subsonic END MASS AND MOMENTUM: Option = Average Static Pressure Pressure Profile Blend = 0.05 Relative Pressure = 0 [Pa] END PRESSURE AVERAGING: Option = Average Over Whole Outlet END END END DOMAIN MODELS: BUOYANCY MODEL: Option = Non Buoyant END DOMAIN MOTION: Option = Stationary END MESH DEFORMATION: Option = None END REFERENCE PRESSURE: Reference Pressure = 1 [atm] END END FLUID DEFINITION: Fluid 1 Material = Air at 25 C Option = Material Library MORPHOLOGY: Option = Continuous Fluid END END FLUID MODELS: COMBUSTION MODEL: Option = None END HEAT TRANSFER MODEL: Option = Thermal Energy END THERMAL RADIATION MODEL: Option = None END TURBULENCE MODEL: Option = k epsilon END TURBULENT WALL FUNCTIONS: Option = Scalable END END INITIALISATION: Option = Automatic INITIAL CONDITIONS: Velocity Type = Cartesian CARTESIAN VELOCITY COMPONENTS: Option = Automatic END STATIC PRESSURE: Option = Automatic END TEMPERATURE: Option = Automatic END TURBULENCE INITIAL CONDITIONS: Option = k and Epsilon EPSILON: Option = Automatic END K: Option = Automatic END END END END END OUTPUT CONTROL: RESULTS: File Compression Level = Default Option = Standard END END SOLUTION UNITS: Angle Units = [rad] Length Units = [m] Mass Units = [kg] Solid Angle Units = [sr] Temperature Units = [K] Time Units = [s] END SOLVER CONTROL: Turbulence Numerics = First Order ADVECTION SCHEME: Option = High Resolution END CONVERGENCE CONTROL: Maximum Number of Coefficient Loops = 3 Minimum Number of Coefficient Loops = 1 Timescale Control = Coefficient Loops END CONVERGENCE CRITERIA: Residual Target = 1.E4 Residual Type = RMS END TRANSIENT SCHEME: Option = Second Order Backward Euler TIMESTEP INITIALISATION: Option = Automatic END END END END " Thank you very much! 
I dont see how your post is related to CFX Macros, please dont hijack other (unrelated) threads! It seems that you will need to do a bunch of tutorials on transient simulations, with the current settings you will do 500[s]/1e005 [s] = 50 million time steps.

Hi,
I have the same question as alac1407 at first. I set Expression: Boundary X Velocity sin(x)*cos(y)*exp(2*t) and the system showed the same error message as alac1407's to me. After I changed my Expression: Boundary X Velocity sin(x[m])*cos(y[m])*exp(2*t) and the system showed me another error message: Bad expression value 'Boundary X Velocity' detected in parameter 'U' in object '/FLOW:Flow Analysis 1/DOMAIN:Default Domain/BOUNDARY:Outlet1/BOUNDARY CONDITIONS/MASS AND MOMENTUM'. CEL error: Error at position 6. Units ([m]) are associated with a term that is not dimensionless. I have no idea how I could revise my expression here. Could anyone help me out? Thank you. 
Did you read the other threads as well?
Quote:
Also, I believe that you have put the name of the expression in the input box in cfxpre. See the tutorials on how to create expressions. 
Dear Lance,
When I use Boundary X Velocity sin(x)*cos(y)*exp(2*t), I got the error message: Bad expression value 'Boundary X Velocity' detected in parameter 'U' in object '/FLOW:Flow Analysis 1/DOMAIN:Default Domain/BOUNDARY:Outlet1/BOUNDARY CONDITIONS/MASS AND MOMENTUM'. CEL error: The dimensions of the argument to function 'sin' are inconsistent with expected dimensions. Argument dimensions resolve to 'm'; expected 'rad'. I am new to CFX so I am sorry to ask these stupid questions. I do not understand about what you said:have put the name of the expression in the input box in cfxpre. Do you think I use the wrong way to create expressions? Thank you for the response 
Quote:
sin(x/1[m]) and so on? 
Dear Lane,
It did not show the error message when I changed it to sin(x/1[m]). Another error message showed up: Expression resolves to invalid units ('dimensionless') in value set for parameter 'Relative Pressure' in object '/FLOW:Flow Analysis 1/DOMAIN:Default Domain/BOUNDARY:Inlet1/BOUNDARY CONDITIONS/MASS AND MOMENTUM'. Expected units: 'kg m^1 s^2'. Does this mean I need to give the units to my expressions? Thank you 
Well, if the solver wants an expression that has a unit, you better give it one, dont you think?
The solver have no way of knowing if you want your expression to be in [Pa], [Bar], [Psi], or [mmHg], etc. I strongly suggest to do a bunch of tutorials. 
Dear Lance,
Thank you for your response. I will check the tutorials. I appreciate your help. 
All times are GMT 4. The time now is 14:02. 