## Friday Flownex Tech Tips #15

Scripts can be very powerful additions to our network building toolbox. But we don’t need to have a degree in computer science to use them! The quick script makes integrating scripts into our network quite simple. In this tip we’ll go over how to set up a quick script in Flownex version 8.12.7.4334

## Example Problem

In this demo I’m going to model a small pipe that is horizontal and perpendicular to the flow of a much large duct. We’re going to use a script to utilize our own correlation for determining the convection heat transfer.

What I’d like to accomplish is to apply the Churchill-Bernstein correlation for cylinder in a cross-flow to calculated the Nusselt number and in turn the convection coefficient.

## Example Network

To build this network I’m just going to use a couple of pipe components and a composite heat transfer component. I’m assuming the cross-sectional area of the larger duct is not so impacted by the presence of the cross-pipe that we need to calculate any losses associated with it.

## Quick Script

Quick scripts are located in the components pane near the bottom. To add a quick script we’ll simply drag and drop the script onto the canvas. Notice the inputs available for the quick script, we get to choose when it executes, and then we’ll notice that there are some example inputs and results. Since this script is going to be used to apply a correlation during the solve we’ll want this script to execute during steady state.

To edit the script we’ll need to double click on the quick script component. Then we’ll need to define our inputs and results. In this case we’ve got quite a few inputs and results to define.

The most challenging part, in my opinion, is simply getting the correct syntax for C#. Luckily there are a myriad of resources online for C# syntax which makes things a bit easier. In the below image I’ve added the mathematical operations to calculate Re_D and Nu_D using the Churchill and Bernstein correlation.

## Connecting Script to Components

We’ll connect the script to our components using data transfer links. We’ll need to populate our script inputs with results from our network and then update the heat transfer input using the results from our script.

Once we’ve connected all of the data transfer links with the appropriate properties we ought to be able to solve!

## Materials, Composites & Scripting Updates in Ansys Mechanical 2021 R1 – Webinar

Composites provide new solutions for manufacturers looking for stronger, lighter and more cost-effective materials.

At the same time, they pose new modeling and manufacturing challenges because of the nature of the materials. With the right simulation tools, designers can account for residual stresses, predict performance, analyze reliability and potential failures, optimize construction, and export accurate information to manufacturing, all before a physical prototype is built.

Register Here

## All Things ANSYS 034 – Celebrating 25 Years of ANSYS Simulation: Changes In The Last Quarter Century & Where The Future Will Take Us

 Published on: April 8th, 2019 With: Eric Miller, Ted Harris, Tom Chadwick, Sina Ghods, & Alex Grishin Description: In this episode your host and Co-Founder of PADT, Eric Miller is joined by PADT’s Ted Harris, Tom Chadwick, Sina Ghods, and Alex Grishin, for a round-table discussion on their experience and history with simulation, including what has changed since they started using it and what they’re most impressed and excited by, followed by some prediction and discussion on what the future may hold for the world of numerical simulation. Thank you again for those of you who have made the past 25 years something to remember, and to those of you who have come to know PADT more recently, we look forward to what the next 25 will bring. If you have any questions, comments, or would like to suggest a topic for the next episode, shoot us an email at podcast@padtinc.com we would love to hear from you! Listen: Subscribe:

@ANSYS #ANSYS

## ANSYS, Inc. Unleashes New ACT Extensions for Version 15.0

If you haven’t noticed, ANSYS, Inc. has been making quite a few ACT extensions available for ANSYS 15.0 on the ANSYS Customer Portal. If you are not familiar with ACT (ANSYS Customization Toolkit) Extensions, please see our earlier blog entry, “There’s an Extension for That,” here.

As of this writing, there are 20 ACT extensions available for download from the Customer Portal for version 15.0. There is also a set of training files available from the same link.

Among the new additions is an extension allowing the use of Mechanical APDL User Programmable Features in the Mechanical editor. Previously this could only be done in MAPDL. You will still need to install the customization files as part of the ANSYS installation, and you will still need the proper versions of the FORTRAN compiler and Visual Studio. However, this extension unleashes a significant capability within the Workbench Mechanical tool that wasn’t there previously, access to UPF’s.

The documentation states that it works with both versions 14.5 and 15.0 of ANSYS.
To get to the 15.0 ACT Extensions download area, login to the ANSYS Customer Portal and navigate through Downloads > Extension Library > 15.0. We urge you to browse the list of available extension available from the Customer Portal to see which might have benefits to your simulations.

Here is a list of all of the current extensions:

ACT Intro Training_R150_v1

ACT Introductory Training Materials

ACT Templates for DM_R150_v1

Templates for educational purpose; demonstrates most common scenarios of ACT-based development needs in DesignModeler

ACT Templates for DX_R150_v1

Templates for educational purpose; demonstrate integration of external optimizers

ACT Templates_R150_v1

Templates for educational purpose; cover most common ACT-based development needs

Acoustics Extension R150_v42

Expose 3D acoustics solver capabilities

Convection Extension_R150_v4

Expose convection with pilot node capability in steady-state and transient thermal analyses

Coupled Diffusion_R150_v3

Introduce coupled diffusion analysis (structural diffusion, thermal diffusion, and structural thermal diffusion) in both static and full transient analysis

Coupled Field Physics Extension_R150_v1

Expose piezoelectric, thermal-piezoelectric and thermal-structural solver capabilities

DDAM_R150_v2

Expose the Dynamic Design Analysis Method (DDAM) in Mechanical interface

Design Modeler Utility_R150_v1

Expose some useful functions in DM interface

Distributed Mass_R150_v2

Add distributed mass (rather than a point mass) to a surface as either “total mass” or “mass per unit area”

Enforced Motion_R150_v3

In Mode-Superposition Harmonic and Transient Analyses, allows applying base excitation (displacement or acceleration). Excitation can be either constant or frequency/time dependent

FE Info Extension_R150_v9

Expose node and element related information

Map temperature and pressure loads (from a CFD calculation) to a multi-step Mechanical analysis for transient one-way FSI. Includes CFD-Post macros

Create follower forces and moments to follow geometric deformation

Hydrostatic Fluid_R150_v5

Expose hydrostatic fluid elements in Mechanical

MATLAB_Optimizers_for_DX_R150_v1

Expose MATLAB optimization algorithms and user programs in the Optimization component of ANSYS DesignXplorer

MatChange_R150_v2

Change material ID to user specified value for the selected bodies

Offshore_R150_v4

Expose the MAPDL offshore features in Mechanical

Piezo Extension_R150_v8

Expose piezo-electric solver capabilities

UPF Extension_R150_v1

Allow for the use of User Programmable Features (UPF) within Workbench

## 20 APDL Commands Every ANSYS Mechanical User Should Know

One of the most powerful things about ANSYS Mechanical is the fact that it creates an input file that is sent to ANSYS Mechanical APDL (MAPDL) to solve. This is awesome because you as a user have complete and full access to the huge breadth and depth available in the MAPDL program.  MAPDL is a good old-fashioned command driven program that takes in text commands one line at a time and executes them. So to access all those features, you just need to enter in the commands you want.

For many older users this is not a problem because we grew up using the text commands. But new users did not get the chance to be exposed to the power of APDL (ANSYS Parametric Design Language) so getting access to those advanced capabilities can be tough.

In fact, I was in a room next to one of our support engineers while they were showing a customer how to change the elements that the solver would solve (Mechanical defaults to the most common formulation, but you can change them to whatever still makes sense) and the user had to admit he had never really used or even seen APDL commands before.

So, as a way to get ANSYS Mechanical users out there started down the road of loving APDL commands, we got together and came up with a list of 20 APDL commands that every user should know.  Well, actually, it is more than 20 because we grouped some of them together.  We are not going to give too much detail on their usage, the APDL help is fantastic and it explains everything.  In fact, if you use a copy of PeDAL you can get the help right there live as you type (yes, that was a plug for you to go out and plop down \$49 and buy PeDAL).

Also note that we are not getting in to how to script with APDL. It is a truly parametric command language in that you can replace most values in commands with parameters. It also has control logic, functions and other capabilities that you find in most scripting languages.  We will focus on actual commands you use to do things in the program here. If you want to learn more about how to program with APDL, you can purchase a copy of our “Introduction to the ANSYS Parametric Design Language” book. (another plug)

## Some APDL Basics

APDL was developed back in the day of punch cards.  It was much easier to use than the other programs out there because the commands you entered didn’t have to be formatted in columns.  Instead arguments for commands are separated by commas.  Therefore, instead of defining a Node in your model as:

345   12.456    17.4567   0.0034

(note that the location of that decimal point is critical). You create a line as:

N,345,12.456,17.4567, 0.0034

Trust me, that was a big deal. But what you need to know now is that all APDL commands start with a keyword and are followed by arguments. The arguments are explained in the Command Reference in the help.  So the entry for creating a node looks like this:

The documentation is very consistent and you will quickly get the hang of how to get what you need out of it.  The layout is explained in the help:  // Command Reference // 3. Command Dictionary

Another key thing to know about commands in MAPDL is that most entities you create (not loads and boundary conditions) have an ID number. You refer to entities by their ID number.  This is a key concept that gets lost if you grew up using GUI’s.  So if you want to make a coordinate system and use it, you define an ID for it and then refer to that ID. Same thing goes for element definitions (Element Types), material properties, etc…  Remember this, it hangs up a lot of newer users.

To use MAPDL commands you simply enter each command on a line in a command object that you place in your model tree. We did a seminar on this very subject about two years ago that you can watch here.

The idea of entity selection is fundamental to APDL.  Above we point out that all entities have an ID.  You can interact with each entity by specifying its ID.  But when you have a lot of them, like nodes and elements, it would be a pain.  So APDL deals with this by letting you select entities of a given type and making them “selected” or “unselected”  Then when you execute commands, instead of specifying an ID, you can specify “ALL” and all of the selected entities are used for that command.  Sometimes we refer to entities as being selected, and sometimes we refer to them as “active.”  The basic concept is that any entity in ANSYS Mechanical APDL can be one of two states: active/selected or inactive/unselected.  inactive/unselected entities are not used by whatever command you might be executing.

If you want to see all of the APDL command that ANSYS Mechanical writes out, simply select the setup branch of your model tree and choose Tools->Write Input File.  You can view it in a text editor, or even better, in PeDAL.

One last important note before we go through our list of commands: the old GUI for MAPDL can be used to modify or create models as well as ANSYS Mechanical. Every action you take in the old GUI is converted into a command and stored in the jobname.log file.  Many users will carry out the actions they want in an interactive session, then save the commands they need from the log file.

Wait, one more thing:  Right now you need these commands. But at every release more and more of the solver is exposed in ANSYS Mechanical FUI and we end up using less and less APDL scripts.  So before you write a script, make sure that ANSYS Mechanical can’t already do what you want.

## The Commands

### 1. !

An exclamation point is a comment in APDL. Any characters to the right of one are ignored by the program. Use them often and add great comments to help you and others remember what the heck you were trying to do.

### 2. /PREP7 – /SOLU – /POST1 – FINISH

The MAPDL program consists of a collection of 10 processors (there were more, but they have been undocumented.) Commands only work in some processors, and most only in one.  If you enter in a preprocessor command when you are in the postprocessor, you will get an error.

When you create a command object in your ANSYS Mechanical model, it will be executed in either the Pre processor, the Solution processor, or in the Post processor.  Depending on where in the model tree you insert the command object.   If you need to go into another processor you can, you simply issue the proper command to change processors.  JUST REMEMBER TO GO BACK TO THE PROCESSOR YOU STARTED IN when you are done with your commands.

/PREP7 – goes to the pre processor. Use this to change elements, create things, or modify your mesh in any way.

/SOLU – goes to the solution processor.  Most of the time you will start there so you most often will use this command if you went into /PREP7 and need to get back. Modify loads, boundary conditions, and solver settings in this processor.

/POST1 – goes to the post processor. This is where you can play with your results, make your own plots, and do some very sophisticated post-processing.

FINISH – goes to the begin level. You will need to go there if you are going to play with file names.

### 3. TYPE – MAT – REAL – SECNUM

You only really need to know these commands if you will be making your own elements… but one of those things everyone should know because the assignment of element attributes is fundamental to the way APDL works…. so read on even if you don’t need to make your own elements.

Every element in your model is assigned properties that define the element.  When you define an element, instead of specifying all of its properties for each element, you create definitions and give them numbers, then assign the number to each element.  The simplest example are material properties. You define a set of material properties, give it a number, then assign that number to all the elements in your model that you want to solve with those properties.

But you do not specify the ID’s when you create the elements, that would be a pain. Instead, you make the ID for each property type “active” and every element you create will be assigned the active ID’s.

The commands are self explanatory: Type sets the Element Type, MAT sets the material ID, REAL set the real constant number, and SECNUM sets the active section number.

So, if  you do the following:

type,4
real,2
mat,34
secnum,112
e,1,2,3,4,11,12,13,14

you get:

ELEM MAT TYP REL ESY SEC        NODES
1  34   4   2   0 112      1     2     3     4    11    12    13    14
2   3   4   4   0 200    101   102   103   104   111   112   113   114

### 4. ET

The MAPDL solver supports hundreds of elements.   ANSYS Mechanical picks the best element for whatever simulation you want to do from a general sense.  But that may not be the best for your model. In such cases, you can redefine the element definition that ANSYS Mechanical used.

Note: The new element must have the same topology. You can’t change a 4 noded shell into an 8 noded hex.  But if the node ordering is the same (the topology) then you can make that change using the ET command.

### 5. EMODIF

If you define a real constant, element type, or material ID in APDL and you want to change a bunch of elements to those new ID’s, you use EMODIF.  This is the fastest way to change an elements definition.

### 6. MP – MPDATA – MPTEMP –TB – TBDATA – TBTEMP

Probably the most commonly needed APDL command for ANSYS Mechanical users are the  basic material property commands. Linear properties are defined with MP command for a polynomial vs. temperature or MPDATA and MPTEMP for a piece-wise linear temperature response.  Nonlinear material properties are defined with the TB, TBDATA, and TBTEMP commands.

It is always a good idea to stick your material definitions in a text file so you 1) have a record of what you used, and 2) can reuse the material model on other simulation jobs.

### 7. R – RMODIF

If you define an elements formulation with options on the ET command, and the material properties on the material commands, where do you specify other stuff like shell thickness, contact parameters, or hourglass stiffness?  You put them in real constants.  If you are new to the MAPDL solver the idea of Real constants is a bit hard to get used to.

The official explanation is:

Data required for the calculation of the element matrices and load vectors, but which cannot be determined by other means, are input as real constants. Typical real constants include hourglass stiffness, contact parameters, stranded coil parameters, and plane thicknesses.

It really is a place to put stuff that has no other place.  R creates a real constant, and RMODIF can be used to change them.

### 8. NSEL – ESEL

As mentioned, selection logic is a huge part of how MAPDL works.  You never want to work on each object you want to view, change, load, etc… Instead you want to place entities of a given type into an “active” group and then operate on all “active” entities. (you can group them and give them names as well, see CM-CMSEL-CMDELE below to learn about components)

When accessing MAPDL from ANSYS Mechanical you are most often working with either nodes or elements.  NSEL and ESEL are used to manage what nodes and elements are active. These commands have a lot of options, so review the help.

### 9. NSLE – ESLN

You often select nodes and then need the elements attached to those nodes. Or you select elements and you need the nodes on those elements.  NSLE and ESLN do that.  NSLE selects all of the nodes on the currently active elements and ESLN does the opposite.

### 10. ALLSEL

A very common mistake for people writing little scripts in APDL for ANSYS Mechanical is they use selection logic to select things that they want to operate on, and then they don’t remember to reselect all the nodes and elements.  If you issue an NSEL and get say the nodes on the top of your part that you want to apply a load to. If you just stop there the solver will generate errors because those will be the only active nodes in the model.

ALLSEL fixes this. It simply makes everything active. It is a good idea to just stick it at the end of your scripts if you do any selecting.

### 11. CM – CMSEL

If you use ANSYS Mechanical you should be very familiar with the concept of Named Selections. These are groups of entities (nodes, elements, surfaces, edges, vertices) that you have put into a group so you can scope based on them rather than selecting each time. In ANSYS MAPDL these are called components and commands that work with them start with CM.

Any named selection you create for geometry in ANSYS Mechanical gets turned into a nodal component – all of the nodes that touch the geometry in the Named Selection get thrown into the component. You can also create your own node or element Named Selections and those also get created as components in MAPDL.

You can use CM to create your own components in your APDL scripts.  You give it a name and operate away.  You can also select components with the CMSEL command.

### 12. *GET

This is the single most awesomely useful command in APDL.  It is a way to interrogate your model to find out all sorts of useful information: number of nodes, largest Z value for node position, if a node is selected, loads on a node, result information, etc…

Check out the help on the command. If you ever find yourself writing a script and going “if I only knew blah de blah blah about my model…” then you probably need to use *get.

### 13. CSYS – LOCAL – RSYS

Coordinate systems are very important in ANSYS Mechanical and ANSYS MAPDL.  In most cases you should create any coordinate systems you need in ANSYS Mechanical. They will be available to you in ANSYS MAPDL, but by default ANSYS Mechanical assigns a default ID. To use a coordinate system in MAPDL you should specify the coordinate system number in the details for a given coordinate system by changing “Coordinate System” from “Program Defined” to “Manual” and then specifying a number for “Coordinate System ID”

If you need to make a coordinate system in your APDL script, use the LOCAL command.

When you want to use a coordinate system, use CSYS to make a given coordinate system active.

Note: Coordinate system 0 is the global Cartesian system. If you change the active coordinate system make sure you set it back to the global system with CSYS,0

RSYS is like CSYS but for results. If you want to plot or list result information in a coordinate system other than the global Cartesian, use RSYS to make the coordinate system you want active.

### 14: NROTATE

One thing to be very aware of is that each node in a model has a rotation associated with it. By default, the UX, UY, and UZ degrees of freedom are oriented with the global Cartesian coordinate system. In ANSYS Mechanical, when you specify a load or a boundary condition as normal or tangent to a surface, the program actually rotates all of those nodes so a degree of freedom is normal to that surface.

If you need to do that yourself because you want to apply a load or boundary condition in a certain direction besides the global Cartesian, use NROTATE.  You basically select the nodes you want to rotate, specify the active coordinate system with CSYS, then issue NROTATE,ALL to rotate them.

Be careful though. You don’t want to screw with any rotations that ANSYS Mechanical specified.

### 15. D

The most common boundary condition is displacement, even for temperature.  To specify those in an ANSYS MAPDL script, use the D command.  Most people use nodal selection or components to apply displacements to multiple nodes.

In its simplest form you apply a single value for displacement to one node in one degree of freedom.  But you can specify multiple nodes, multiple degrees of freedom, and more powerfully, the value for deflection can be a table. Learn about tables here.

### 16. F

The F command is the same as the D command, except it defines forces instead of displacement.  Know, it, use it.

### 17. SF – SFE

If you need to apply a pressure load, you use either SF to apply to nodes ore SFE to apply to elements. It works a lot like the D and F commands.

### 18. /OUTPUT

When the ANSYS MAPDL solver is solving away it writes bits and pieces of information to a file called jobename.out, where jobname is the name of your solver job.  Sometimes you may want to write out specific information, say list the stresses for all the currently selected nodes, to a file. use /OUTPUT,filename to redirect output to a file. When you are done specify /OUTPUT with no options and it will go back to the standard output.

### 19. /SHOW

ANSYS MAPDL has some very sophisticated plotting capabilities.  There are a ton of command and options used to setup and create a plot, but the most important is /SHOW,png.  This tells ANSYS MAPDL that all plots from now on will be written in PNG format to a file. Read all about how to use this command, and how to control your plots, here.

### 20. ETABLE

The ANSYS MAPDL solver solves for a lot of values. The more complex the element you are using, the more the number of values you can store.  But how do you get access to the more obscure ones? ETABLE.  Issue 38 of The Focus from 2005 goes in to some of the things you can do with ETABLE.

## Where to go From Here

This is certainly not the definitive list.  Ask 20 ANSYS MAPDL users what APDL commands all ANSYS Mechanical users should know, and you might get five or six in common. But based on the support calls we get and the scripts we write, this 20 are the most common that we use.

Command help is your friend here.  Use it a lot.

The other thing you should do is open up ANSYS MAPDL interactively and play with these commands. See what happens when you execute them.

## CFX Expression Language–Part 5: Using CEL for Solution Monitoring

In four previous entries we introduced CFX Expression Language, CEL:

After a break to teach some ANSYS classes in beautiful northern Utah we’re back to conclude our series on CFX Expression Language.

In our fifth and final installment on CEL we will discuss the use of CEL in monitoring items of interest while the CFX solution is progressing. Back in the first installment in this series, we showed how to create expressions for results quantities in CFD Post. By creating expressions in similar fashion for results quantities in CFX Pre, we can use these expressions to monitor items during solution.

Here is an example. In CFX Pre we have defined three expressions which are really extracting and operating on results data.

forceX1 = resulting force on one face of the structure
forceX2 =resulting force on another face of the structure
fdiffx = the difference between these two values or the net force acting on the structure

This shows these three expressions in the CFX Pre outline tree:

Still within CFX Pre, click on Insert > Solver > Output Control. That will add an Output Control tab on the left side of the CFX Pre window. Click on the Monitor tab, expand Monitor Points and Expressions, and then click on the button near the right of the window below that to add a monitor point:

Set the Option to Expression and in the Expression Value box left click then right click to select from your list of defined expressions:

The CFX Pre tree will now have one or more Monitor Points listed under Output Control:

When we initiate the solution, these user-defined monitor points will be available for real time display in addition to the normal Momentum and Mass and Turbulent kinetic energy monitors. All we need to do is click on the User Points tab during solution to view our expressions as monitors. In the example shown below, Monitor 1 is forceX1, Monitor 2 is forceX2, and Monitor 3 is fdiffx, the difference between the first two quantities. These could have been renamed during their definition to make it easier to understand the monitor plot. Here is a snapshot of the quantities being monitored during the solution:

So, as we have seen in the last 5 CFX Expression Language blog entries, CEL exposes a lot of powerful capability to CFX users (and to Fluent users within CFD Post). In this case we have seen how to add additional items to monitor during the solution process. The advantages of this are to help us determine on the fly if the solution is progressing as expected and to give us an idea of the values of certain results quantities before the solution is fully completed.

We certainly hope you now have a better understanding for how CEL can be used to increase the capabilities and useful information available from CFX and CFD Post.

## CFX Expression Language–Part 4: Applying Ramped and Stepped Boundary Conditions Using CEL

In three previous entries we introduced CFX Expression Language, CEL:

In this fourth installment we will demonstrate the use of CEL to apply ramped or stepped boundary conditions. In certain circumstances we might want to ramp a load rather than apply it all at once. For example, convergence difficulties can sometimes arise when a fast rotation rate is applied initially in rotating machinery simulations. Starting off with a smaller value of load and ramping it to the final value can aid in convergence in these circumstances.

Note that the rate of load application can be manually changed during the solution in the solver manager, but why not take advantage of CEL and do it automatically? As we will see, this is fairly easy to do.

The ability to ramp a load makes use of a built-in CEL variable labeled “aiturn”, which is the accumulated value of the iteration number. If we assign an expression for the number of iterations we want, we can then create a combined expression for the ramped load:

In the above list of expressions, Flow999 is our desired full amount of flow at the end of ramping. Iter is defined to have a value of 100. Both of those are names that we picked. We then defined expression flowapplied, which is the value of Flow999 times the built-in expression aitern (the current solver iteration number) divided by the total number of iterations desired for the ramping, Iter. Once aitern = 100, then the value of flowapplied will equal Flo999 or 9.99 ft/sec in this case.

Here is a plot of the expression flowapplied for values of aitern between 0 and 100. The plot is in m/s but the peak works out to be 9.99 ft/sec.

As we have seen in prior entries in this series, we plug in the expression name for the input in the appropriate field. In this case, the name of the expression flowapplied is entered in the Normal Speed field in the Inlet boundary details.

After solution, we can verify that at the end of the solution the applied inlet velocity had reached the full value of 9.99 ft/sec. in CFD Post:

The next step might be rerun the solution while maintaining a constant value of the applied load for an extended period of time. This can be accomplished by modifying the expression which defines the load so that it has some additional values:

In the above expression we have added a step() function, which can either be typed in or added by right clicking, Functions > CEL > step. This causes the ramped load to peak at the value of Flow999 when aitern reaches the previously defined value of Iter at 100, then drop to zero after that. This happens because if Iter-aitern is greater than one, step=1, but if Iter-aitern is less than one, step=0. Here is the resulting plot in CFX Pre:

That’s not quite what we want, but if we tweak the expression a bit more, we can get it to ramp to the full value then remain constant.

Now we have another term involving the step() function, but with the expression names inside the step function reversed. This means that once aitern exceeds the value of Iter, the first term becomes zero and the second term takes over with a constant value of the load equal to Flow999, as shown here:

By using similar expressions involving time, we can create a load history that turns off and on at desired time points.

Hopefully by now you’re starting to see the value of CEL. We are just scratching the surface here, but once you start using it you will find that CEL has a lot of potential powerful uses. In the next installment we’ll cover some additional capabilities available in CEL.

## CFX Expression Language–Part 3: Applying Boundary Conditions Using CEL

In two previous entries we introduced CFX Expression Language, CEL:

Part 1: Accessing CFD Simulation Information in CFX (and FLUENT)

Part 2: Augmenting Material Property Assignments in ANSYS CFX

In this third installment we will see how to use CEL to apply boundary conditions as equations rather than constant values. For example, if a non-constant velocity profile can be defined as an equation, we can use CEL to define as well as apply the profile.

Let’s look at an example in which the velocity profile is a function of y coordinate:

u(y) = 6 * Umax * y / H * (1 – y/H) (m/s)

Using the procedure we learned in part 1 of this series, in CFX Pre we have defined expressions for H and Umax. We then defined the equation for the velocity profile as Uprofile:

Next we go to the Plot tab within the Expressions editor to verify that our velocity profile matches expectations:

To use our new expression in CFX Pre, we just enter the expression name in the appropriate field when defining the inlet velocity:

Finally, this velocity plot from CFD Post shows that indeed our desired velocity profile was applied at the inlet.

Hopefully this demonstrates how easy it can be to use CFX Expressions to define non-constant boundary conditions. In the next part of the series, we will look at using expressions to ramp or step apply loads.

## CFX Expression Language – Part 2: Augmenting Material Property Assignments in ANSYS CFX

In a previous entry we introduced CFX Expression Language, CEL.  You can view that post here

Before we get started, there are some key things to remember:

1. Expressions can be easily created by right-clicking in the Expressions tab after double clicking on Expressions in the CFX Pre object tree.
2. Expressions and their contents are case sensitive.

In this next part of the series, we’ll show how to use CEL to augment your material property definitions in CFX. If material properties are constants then their input is straightforward. However, if the properties are defined as equations, we can use CEL to input those equations in CFX.

For example, if viscosity is defined as a function of shear strain rate, we need to define viscosity using an equation that captures that relationship, such as

m = K * gn-1

Below are shown two ways in which that equation can be captured using CFX Expression Language, visc1 and visc2. The second equation, visc2, is more flexible in that we have defined the constant terms as expressions themselves.

It’s always a good idea to verify the input. Most expressions can be easily plotted by clicking on the Plot tab in the Details view. Here is a plot of the viscosity vs. shear strain rates between 0 and 1, as calculated by expression visc2:

Similarly, the Evaluate tab can be used to evaluate the expression for desired values of the inputs.

So, we have defined an expression for a material property, viscosity in this case. How do we get CFX to use that expression? In the material property input, we click on the expression icon to the right of the particular material property we are defining, then enter the name of the expression, as shown here for expression visc2:

Summing it up, we can use CFX Expression Language to define material property equations for non-constant material values. In the next installment we will look at how to use CEL to define changing boundary conditions, such as a ramped load.

## CFX Expression Language – Part 1: Accessing CFD Simulation Information in CFX (and FLUENT)

This week we are presenting an introduction to CFX Expression Language. If you’re not familiar with CFX, it is one of the two CFD tools available from ANSYS, Inc., the other being Fluent. CFX has been part of the ANSYS family of engineering tools since 2003. It is relatively easy to use and can be run stand-alone or tightly integrated with other ANSYS products within ANSYS Workbench. We have some general information on CFX available at this link.

CFX Expression Language, or CEL, is the scripting language that allows us to define inputs as variables, capture outputs as variables, and perform operations on those variables. Through the use of CEL we can be more efficient in our CFD runs and better capture results that we need. With CEL we can access and manipulate information without needing to recompile code or access separate routines besides the main CFX applications.

Also note that since CEL can be used in CFD Post, it is useful for postprocessing FLUENT solutions in addition to CFX, since CFD Post is common to both CFX and FLUENT. There are some things to be aware of regarding FLUENT In CFD Post. This link in to the ANSYS 14.5 Help system explains it:

// User’s Guide :: 0 // 7. CFD-Post File Menu // 7.15. File Types Used and Produced by CFD-Post // 7.15.10. Limitations with FLUENT Files

If you are a user of APDL, ANSYS Parametric Design Language, what I have written above about CEL should look familiar. One difference, though, is that while Mechanical APDL is dimensionless, CFX is not. Therefore, CEL definitions contain units where appropriate.

CEL is typically used in CFX-Pre and CFD-Post. A handy editor is available to assist in the definition of the expressions. Most of the activity is enabled by right clicking.

Virtually any quantity in CFX that requires a value input can make use of CEL, including boundary conditions and material properties. CEL can also be used to access and enhance results information. Expressions defined in CEL can be used in design point studies in ANSYS Workbench, either as input or output parameters.

So, what kind of things can you do in an expression? In addition to accessing simulation information and storing it as a variable, you can manipulate values using operators such as add, subtract, multiply, divide, and raise to a power. You can also use built-in functions such as sine, cosine, tangent and other trig functions, exponent, log, square root, absolute value, minimum, maximum, etc.

There are many predefined values, including some common CFD constants such as pi, the universal gas constant, and Avogadro’s number. The available options are different in CFX pre vs. CFD Post, with relevant choices for each.

In CFX Pre, expressions are accessed by double clicking on Expressions in the tree. That takes you to the expression editor, as shown here:

Notice how units are defined for each expression, but they can be mixed if desired.

Regarding CFD Post, the example below shows three expressions defined in CFD Post. The expressions within the box are user-defined. The other expressions listed are setup automatically.

The values for forceX1 and forceX2 are calculated by extracting X-direction forces on two different surfaces. The surface names were defined in ANSYS Meshing in this case, as Named Selections. The value fdiffx is calculated by subtracting forceX1 from forceX2. The resulting value, fdiffx, has been specified as an output parameter in Workbench; hence the P-> symbol next to the name.

New expressions are created by right-clicking in the Expressions tab. The new expression value is given a name, then the definition is input, typically by right clicking and selecting from the menus of available quantities, like this:

The location of application for an expression can also be selected by right clicking:

So we’ve got our variables defined using CEL. Now what? Here are some things we can do with CEL variables:

1. Use them as inputs such as material properties or boundary condition values in CFX. If we are running multiple cases, it is typically much easier to define quantities that we want to vary this way. The values can then be changes in the Expression Window, or if defined as a parameter in Workbench, in the parameters view as part of a parameter study.

2. Use them for reporting results quantities of interest, such as forces at a desired location.

3. Use them as input or output parameters in a design point study or design optimization.

Hopefully this brief introduction gives you a glimpse at the power of CEL. In a future article we will look at using CEL for more advanced functionality, such as applying ramped or time varying boundary conditions, using IF statements, and monitoring expression values during solution.

## Introduction to the ANSYS Parametric Design Language (APDL) Book Now Available on Amazon!

PADT’s popular “ANSYS Customization with the ANSYS Parametric Design Language Guide” Has been updated and reformatted as a book and published as “Introduction to the ANSYS Parametric Design Language”  in both softcover and Kindle formats.

This book started life as a class that PADT taught for many years. Then over time people asked if they could buy the notes.  And then they asked for a real book.  The bulk of the content came from Jeff Strain with input from most of our technical staff.  Much of the editing and new content was done by Susanna Young and Eric Miller.

Here is the Description from Amazon.com:

The definitive guide to the ANSYS Parametric Design Language (APDL), the command language for the ANSYS Mechanical APDL product from ANSYS, Inc. PADT has converted their popular “Introduction to APDL” class into a guide so that users can teach themselves the APDL language at their own pace. Its 12 chapters include reference information, examples, tips and hints, and eight workshops. Topics covered include:
– Parameters
– User Interfacing
– Program Flow
– Retrieving Database Information
– Arrays, Tables, and Strings
– Importing Data
– Writing Output to Files