|Published on:||April 8th, 2019|
|With:||Eric Miller, Ted Harris, Tom Chadwick, Sina Ghods, & Alex Grishin|
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 firstname.lastname@example.org we would love to hear from you!
One way to really unleash the power of APDL is to become familiar, and ultimately fluent, with array parameters. The APDL student will quickly learn that array manipulation involves heavy use of the *V commands, which are used to operate on vectors (single columns of an array). These commands can be used to add two vectors together, find the standard deviation of a column of data, and so on. *V commands consist of what I like to refer to as “action” commands and “setting” commands. The action commands, such as *VOPER, *VFILL, and *VFUN * have their own default behaviors, but these defaults may be overridden by a preceding setting command, such as *VABS, *VLEN, or *VMASK.
*VMASK is one of the most useful, but one of the most difficult to understand, *V command. At its essence it is a setting command that directs the following action command to a “masking” array of true/false values. Only cells corresponding to “true” values in the masking array are considered for the array being operated on in the subsequent action command.
For example, a frequently used application of *VMASK is in the compression of an array—for instance to only include data for selected entities. The array to be compressed would consist of data for all entities, such as element numbers, x-locations for all nodes, etc. The masking array would consist of values indicating the select status for the entities of interest: 1 for selected, –1 for unselected, and 0 for not even in the model to begin with. Only array cells corresponding to a masking array value of 1 would be included in the compression operation, with those corresponding to a value or 0 or –1 being thrown out. Here is a slide from our APDL training class that I hope illustrates things a little better.
What we’ve learned so far is that the masking array contains a list of true/false (or not true) values to refer to when performing its vector operation. But actually, it’s much more general than 1, 0, and –1. What *VMASK does is include cells corresponding to all positive numbers in the masking array (not just +1) and exclude cells corresponding to all values less than or equal to zero in the masking array (not just 0 and -1), which broadens the possibilities for how *VMASK can be handy.
Everything I’ve used *VMASK for up to this point in my career has involved array compression, and I figured I’d be put out on a sweep meshed ice floe into a sea of CFD velocity streamlines (that’s what happens to old CAE engineers; you didn’t know that?) before I came up with anything else. However, I recently ran into a situation where I needed to add up just the positive numbers in an array. I was about to construct an algorithm that would test each individual number in the array to see if it was positive and, if so, add it to the total. It would’ve been cumbersome. Then I came up with a much less cumbersome approach: use the array as it’s own masking array and then perform the addition operation. Let’s look at an example.
Take the following array:
The sum of all values in the array is 1.5 whereas the sum of just the positive values is 11.5. What’s the most efficient way to have APDL calculate each?
In the case of summing all values in the array, it’s easy, just simply execute
which gives you
But what about summing just the positive values? That’s easy, just use SUM_EXMPL as its own masking array so that only the positive values are included in the operation.
Now why was I doing this? I had to create a macro to calculate total nodal loads for an unconstrained component in just the positive direction (to ignore the loads counteracting in the negative direction), and this was my approach. Feel free to download the macro: facelds.mac and try it out yourself.
So you have text output from some ANSYS analysis and you wish you could just do this:
cat lift.txt cop.txt drag.txt >> results.txt
and you are writing an ANSYS macro and want it to run on all platforms. The following macro will use APDL commands to join the files together.
Bonus: If you want to strip some lines off of the top or read less than all the lines, you can pass additional arguments to *sread:
There are times when you want to study the effects of varying parameters. If you have an existing MAPDL script that is parameterized, the following procedure will allow you to easily run many variations in an organized manner.
Let’s assume a parameterized MAPDL macro called build_solve that does something you want to simulate many times and has 2 variables called power and scale which are set with argument 1 and 2 respectively. Running this macro with the classic interface, with power=30 and scale=2.5 would look like this:
Next, create a MAPDL macro to launch all of the simulations. This script could be named control.mac. The first thing to do here is to create arrays of your parameters and assign values to them. This example will vary power and scale. Here are the arrays of values that will be passed to build_solve:
Most of the control.mac commands will be put inside of nested *do loops. There will be a *do loop for each of parameters being varied.
Next, use *cfopen to set up the arguments to be passed to build_solve. Each time through the *do loops will create a new run1.mac
One of the key features of this approach is to run anywhere and build directories below the working directory. Use the /inquire command to store the current directory name.
Use *cfopen to create a string that will be used for the directory name. By using the variables as part of the string, the directories will have unique names. A time or date stamp could also be included in this string. This macro is executed immediately to create the string dirnam for use in the commands subsequently.
Eventually, the resulting directory structure will look something like the image below. Each directory will contain a separate simulation with the arguments of power and scale set respectively.
The last *cfopen creates a windows batch file which will (when executed)
Create the new directory
Copy all of the macro files from the working directory into the new directory (including run1.mac)
Change into the new directory using CD
Launch ansys in batch mode, in this case using a gpu and 12 cpus, using the run1.mac input and outputting to f.out
Change back to the working directory (ready to do it all again)
The code for the windows batch file is:
COPY *.mac "%C\%S"
"C:\Program Files\ANSYS Inc\v150\ansys\bin\winx64\ansys150" -b -acc nvidia -np 12 -i run1.mac -o f.out
The last step is to run the windows batch file. /sys is used to make this system call. If the simulation is not well parallelized and you have enough licenses available, run the simulations in low priority mode immediately. This will launch all of your simulations in parallel:
/sys,start /b /low rfile.bat
If the model is well parallelized (in other words, it will use your system’s gpu/cpus/RAM efficiently) or you only have 1 license available, launch the batch files in high priority mode and use the /wait option which will insure that windows waits for the job to finish before launching the next simulation.
/sys,start /b /high /wait rfile.bat
You can download and view the examples control.mac and build_solve.mac from this zip file: build_solve-control-macros.zip
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 Templates for DM_R150_v1
ACT Templates for DX_R150_v1
Acoustics Extension R150_v42
Coupled Field Physics Extension_R150_v1
Design Modeler Utility_R150_v1
FE Info Extension_R150_v9
Follower Loads Extension_R150_v2
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)
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:
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.
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.
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.
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:
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
The F command is the same as the D command, except it defines forces instead of displacement. Know, it, use it.
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.
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.
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.
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.
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.
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.
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.
In two previous entries we introduced CFX Expression Language, CEL:
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.
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:
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.
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.
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:
– User Interfacing
– Program Flow
– Retrieving Database Information
– Arrays, Tables, and Strings
– Importing Data
– Writing Output to Files
– Menu Customization
At only $75.00 it is an investment that will pay for itself quickly. Even if you are an ANSYS Mechanical user, you can still benefit from knowing APDL, allowing you to add code snippets to your models. We have put some images below and you can also learn more and purchase your copy on Amazon.com. They can ship anywhere in the world.