Files for ANSYS Webinar on External Connections

Here are the files for the webinar on External Connection from 10/14/2011.

Example XML File: sampleconfig2.xml

Example Python Script:  costcalc.py

Sample Input File: costcalc.inp

PDF Of PowerPoint: External_Connections_2011_10_14.pdf

You can find a recording of this webinar and all others at: padtincevents.webex.com

Importing and Exporting ANSYS Mechanical Loads as XML Files

I was futzing around with some loads the other day and noticed that, to my shock, that if you click on the value for a load and instead of typing a value in, click on the drop down menu and you will find that it has an Import and an Export on it.   I’m not sure when that became a capability, but I think it has been there for a while.  A quick check with the staff here at PADT and only a few knew about it.  Which makes it a great topic for The Focus.image

XML, Engineering Data, and Verbosity

The easiest way to check this out is to go into a model and insert a force into your model.  Go ahead and pick the geometry.  In the Details for the force, click on the magnitude cell and you will see a little drop-down menu triangle:

image

Click on that and you will see the menu:

image

Click on Export and give it a file name.  You will notice when you do this that it makes an XML file.  If you didn’t know it, ANSYS Mechanical uses a lot of XML.  In fact, they used to even store results in an XML file.  The good thing about XML files is that they kind of self-describe themselves and organize the data in them in a sort of object oriented way.  This makes them very easy to read and portable between programs. 

XML stands for eXtensible Markup Language and it is an expansion of HTML to handle data. Check out the Wikipedia article on the topic to learn more.  XML is hear to stay and if you don’t get it, you might struggle with some advanced stuff in a lot of areas, not just ANSYS.

The down side of XML is that it is very wordy – verbose.  It has lots of text in there that specifies relationships, names, ID’s, etc…  Tags out the wazoo.  For those of us that grew up feeding our simulation programs fixed format or comma delimited files where the first line specified all the constants and the rest was the data, this can be a bit annoying.  But it does make the data portable and “human readable”

Let’s take a look at the XML file from applying a load of 0.0 lbf to our model.  The best way to view an XML file is to doubleclick on it. Your browser will bring it up and show what is inside.   If you have Dreamweaver or some other HTML editor, that will work even better.

Here is our example:

   1: <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
1.5: <
ANSYS_EnggData>

   2:     <MaterialData/>

   3:     <ConvectionData/>

   4:     <LoadVariationData>

   5:           <MatML_Doc>

   6:               <LoadVariation>

   7:                     <BulkDetails>

   8:                         <Name>Force 2</Name>

   9:                         <Form>

  10:                               <Description/>

  11:                     </Form>

  12:                         <PropertyData property="pr1">

  13:                               <Data format="float">0.,0.</Data>

  14:                               <Qualifier>Force</Qualifier>

15: <ParameterValue format="float" parameter="pa1">
0.,1.</ParameterValue>

  16:                     </PropertyData>

  17:                 </BulkDetails>

  18:                     <Metadata>

  19:                         <ParameterDetails id="pa1">

  20:                               <Name>Time</Name>

  21:                     </ParameterDetails>

  22:                         <PropertyDetails id="pr1">

  23:                               <Name>Force</Name>

  24:                     </PropertyDetails>

  25:                 </Metadata>

  26:             </LoadVariation>

  27:         </MatML_Doc>

  28:     </LoadVariationData>

  29:     <BeamSectionData/>

  30: </ANSYS_EnggData>

The first thing you will notice is that the second tag (right after the XML version info) is <ANSYS_EnggData>.  That is because ANSYS already had a nice well defined format for putting tabular data into Workbench applications: EngineeringData.  So they just used the same format for loads.

The next thing you will notice is a lot of text to specify two value at two time points.  A lot of the data is just blank. There in case you need it.  To understand this let’s step back and look at tags in HTML.

A tag goes around some piece of information and describes what that information is.  Usually you have a starting tag which is the string with a less-than sign at the start and a greater-than sign at the back:

<tagString>

You then put in your information.  It could be data, text, more tags, whatever you want.  then when you are done, you close out the tag with the same string, but this time start with less-than followed by a forward slash. You still end with greater than:

</tagString>

You can nest these guys, with tags inside tags. This is how you get your object parent-child relationships.

So let’s look at our first couple of lines again, repeated here with the meat taken out (<…>) so we don’t have to scroll back and forth:

   1: <?xml version="1.0" encoding="UTF-8" standalone="no" ?><ANSYS_EnggData>

   2:     <MaterialData/>

   3:     <ConvectionData/>

   4:     <LoadVariationData>

   5:           <MatML_Doc>

   6:               <LoadVariation>

   7:                     <BulkDetails>

   8:                         <...>

   9:                     </BulkDetails>

  10:                     <Metadata>

  11:                         <...>                       

  12:                     </Metadata>

  13:             </LoadVariation>

  14:         </MatML_Doc>

  15:     </LoadVariationData>

  16:     <BeamSectionData/>

  17: </ANSYS_EnggData>

You will notice that a lot of the tags in our example end with a forward slash:

<tagString/>

This is an empty tag. It tells the program I got no data of this type. It does save some text compared to other market languages where you just have a blank start and end tag. 

So, our example starts and ends with <ANSYS_EnggData> and </ANSYS_EnggData>  Everything between in engineering data.  Then it says no material data and no convection data.  It does say it has load variation data.  We then find the LoadVariationData tag.  This is what we actually have in the file.  It then goes one step down and has a MatML_Doc tag.  This tells the program the format of the data being given is in the MatML schema.  more on that below.

Then we break the load into two parts: The BulkDetails where the actual data values are specified and the MetaData, which tells the program information it needs to know about the data.  Then everything has its end tag, you tell the program you don’t have BeamSectionData, and you finish up.

If you want to, you can not include all the empty tags.  the <tagString/> tags.  Mechanical reads the file just fine without them.   But you can’t get rid of anything else.

The MatML Language

MatML is “an extensible markup language (XML) developed especially for the interchange of materials information.”  You can read all about it at: http://www.matml.org/  History, examples, news, etc…  It is all there.   Like most standards, you can waste a lot of time saying what is good or bad about it.  But in the end, what matters is that everyone uses the same standard. (Of course, MatWeb doesn’t support this standard because they want you to pay for native format… grumble, grumble…).

Looking at the Data and MetaData

Let’s look at the heart of our file, the actual data we want.  In MatML they call it BulkDetails:

   1: <BulkDetails>

   2:     <Name>Force 2</Name>

   3:     <PropertyData property="pr1">

   4:         <Data format="float">0.,0.</Data>

   5:         <Qualifier>Force</Qualifier>

   6:         <ParameterValue format="float" parameter="pa1">0.,1.</ParameterValue>

   7:     </PropertyData>

   8: </BulkDetails>

The first thing we find is the name.  This is not the name that will be used in the tree.  It is the name that will show up in the library if you combine a bunch of XML files and the name that will show up in your detail view for magnitude.  So if you make your own load, give it something descriptive here so you can pick it out of the library but not so long that you can’t read it in the detail. Calling it F1 will just tick you off in six months when you try to reuse a load.

Next is the PropertyData tag.  It will always have the name “prn” as far as I can tell, where n is an integer starting at 1 and increasing for each property in the file.  If you change it, everything gets messed up – so always use pr1. 

Now the data.  You give it a format, float in most cases, then a comma delimited list.  That is it.

Then you tell the program that it is a Force with the Qualifier.

Last, you need to specify the parameters that your load will vary over.  Usually this is time.  Use <ParameterValue> to do this.  Notice how you specify a format and what the parameter is called, and this is always “pa1”  (or pan actually, where n starts at 1 and increases for each property in the file).

Now we have to tell the program some additional information about our data, which is called Meta Data.  For loads, the only thing that is supported is the definition of the type of load being specified:

   1: <Metadata>

   2:     <ParameterDetails id="pa1">

   3:         <Name>Time</Name>

   4:     </ParameterDetails>

   5:     <PropertyDetails id="pr1">

   6:         <Name>Force</Name>

   7:     </PropertyDetails>

   8: </Metadata>

Don’t worry too much about this formating stuff.  The best thing for you to do is make a load like the one you want in Mechanical, export it to XML, then modify the values inside as you see fit.  Much easier than understanding the schema… or even what a schema is.

Units

Please notice that there are no units anywhere.  Right now all of your values must be in SI units, and Mechanical will convert when it displays the values.  This is because Mechanical always stores values internally as SI.  So, if you make your own load files, make sure you convert to SI.

This is the single biggest potential for error… so mind your units!

Importing XML Load Files

The process of reading in the loads is a bit more complicated then simply pointing to a file.  This is because each file can hold more than one load. You should think of the XML file as a library.

To read the file go to your Magnitude, click on the drop-down menu icon and choose “Import…”  This brings up the “Import Load History Data” dialog:

image

Note that instead of picking a file you are given a Data Source area and a Load History Data to Import area.  the top Data Source is the file.  Click Add… and point to your XML file.  Once it reads that file in it will always remember the file and every time you open this dialog box, it will re-read it and update the Load History data to Import values.

image

 

You can see our sample file, tt4.xml, is the library Data Source and within it are two loads.  You use the radio button to choose the load you want to apply.  Click OK and you will notice that your Details for the load now lists that name as the Magnitude:

image

As you can imagine, you can put a ton of loads in one file, maybe all the loads for your project.  Then use the filter to find the load you want in a big file.  This is again a reminder of why it is important to specify a useful name when you create the load.

Formulas

The examples above deal with tabular data.  You can also store formulas in the file.  This looks a little different in the <BulkDetails> in that you specify format=”function> in the <Data> tag.  Here is an example:

   1: <MatML_Doc>

   2:     <LoadVariation>

   3:           <BulkDetails>

   4:               <Name>Force 2</Name>

   5:               <Form>

   6:                     <Description/>

   7:           </Form>

   8:               <PropertyData property="pr1">

   9:                     <Data AngleInDegrees="1" AngularVelocityInRPM="1" 

  10:                         TemperatureUnit="3" UnitSystem="4" format="function">

  11:                         <Domain LowerLimit="0." UpperLimit="-999.">

  12:                             time

  13:                         </Domain>

  14:                         <Domain LowerLimit="0." UpperLimit="-999.">

  15:                             1.2*sin(time/6)

  16:                         </Domain>

  17:               </Data>

  18:                     <Qualifier>Force</Qualifier>

  19:                     <ParameterValue format="float" parameter="pa1">

  20:                            0.,.1,.2,.3,.4,.5,.6,.7,.8,.9,

  21:                            1.0,1.1,1.2,1.3,1.4,1.5,1.6,

  22:                            1.7,1.8,1.9,2.0

  23:                     </ParameterValue>

  24:           </PropertyData>

  25:       </BulkDetails>

  26:           <Metadata>

  27:               <ParameterDetails id="pa1">

  28:                     <Name>Time</Name>

  29:           </ParameterDetails>

  30:               <PropertyDetails id="pr1">

  31:                     <Name>Force</Name>

  32:           </PropertyDetails>

  33:       </Metadata>

  34:   </LoadVariation>

  35: MatML_Doc>

A lot more complicated. The best way to make one of these is to do it interactively and export.

Generating XML Load Files

At first blush, the file looks complicated but a simple VBA script in excel or a python macro can build the file very quickly because most of the text is static, you are really just changing the data and parameter value values.  I was going to do such an example, but ran out of time.  If any of you have one or write one, please let us know so we can share.

Making Animated GIF’s of ANSYS Graphics for Fun and Profit

In last weeks article I included some animations of some plots from the examples.  While doing that I remembered that we have received a couple of questions recently about how to get result animations in a PowerPoint or a Website.  In this article we will talk about the tool I use and give some tips on making the process better. And, it give me an excuse to write about some software other than ANSYS, Inc.

Animated Gif Humor (14)Animated GIFs and Why we Need Them

As you know, an animation is simply a series of still images shown one right after another.  When we create Video on a computer we generally make something with 30 still frames shown every second.  Although the various formats for video have gotten much better, that is still a lot of pixels to send around. That makes a big file that may not be best for your web page or PowerPoint.  However, with modern high speed internet and fast computers, that is not the problem it used to be.  It is still a concern.

What we really have to deal with is making sure that whatever we are using to present our animation can play it.  Can the persons web browser show it?  Can PowerPoint show it?  Although YouTube is a possibility more an more, you really want a portable format that you can imped in your document or site and that everyone can see.  If you research…  the only format that fits that bill is an animated GIF.

The gif format is compact, and because the early Netscape Navigator browser supported it, it became a default format.  Even Microsoft decided to support it.  So, as in some ways, it is the least common denominator that works for everyone.  Another cool thing is that the programs treat it as an image, not as a video or animation.  You copy and paste it, insert it, place it, edit its size just like you would any JPEG, PNG, or TIFF image.

You can learn about the format on wikipedia. But if the binary info that greats you on that page causes your eyes to glaze over, you only really need to know the following:

    1. It is a file format that supports multiple images all contained in one image file
    2. You can specify how long to play a given image (frame)
    3. It supports transparency
    4. It is a standard and all web browsers and PowerPoint will display it
    5. You can imbed it in a PowerPoint so you don’t have to worry about carrying your animation files around in a folder with your PowerPoint.
    6. It only supports 256 colors. This is the downside of GIF’s

Unfortunately non of the ANSYS products make an animated GIF file.  They generally make an AVI, which is the most common video file, but something that most people can’t display on their website or put in a PowerPoint.  So we need to convert the AVI to a GIF, or create a GIF from a series of images. 

There is one option we should mention, and that is creating an Adobe Flash file. This is a more modern and capable format but it has problems.  First and foremost, iPhones and iPads don’t display flash.  Second, to show a flash animation in PowerPoint you have to make sure a special flash player is installed.  So again, lowly GIF wins out.

GIF Movie Gear

I use a program called GIF Movie Gear. If you Google “AVI to GIF” you will find other tools. I picked this one because it had the features I wanted, it was cheap, and it works so far just fine. Over time, I have found it to be very robust as well.  It is from a company called Gamani, and you can download a trial version or purchase it for $29.95.  They have a nice website that lists all the features and offers some tutorials at: www.gamani.com

Once you have it installed check it out. If you have not tried similar tools in the past, go through the tutorial. It is worth the time. 

For the ANSYS user, here are the important features:

    1. It will import an AVI and break it into individual images (frames)
    2. You can crop and resize
    3. You can set the speed of the animation
    4. It is easy to use (important, since if you are like me you only need it once in a while)
    5. You can easily make a ping-pong animation (copy frames then reverse them)
    6. You can make an animation by reading in a series of images (important for MAPDL users that want to make a high quality animation)

There are a ton more features, but these are the ones that matter to us ANSYS types.

Building Animations from Images

If you are using Mechanical APDL (MAPDL) you can use the ANIM command to build an animation of your model as an AVI. The problem with this is that the AVI file format that ANSYS uses compresses the images to save space, and to do so it really reduces the quality of the image.  So instead, you can write your own animation macro and save a PNG file for each frame, then use GIF Movie Gear to make an animation.

To learn about how to make the images for your own animation, check out an old Focus article in Issue 49 from 2006, on page 6.  It talks about the program we used to use to make an AVI instead of a GIF, but it works the same.  You basically make a plot and save it as a PNG then modify your image and make the next one.  We use that macro in the examples below and put it here for you to use.  Take a good long look at it

You probably also want to reread (because I know you read it when we put it out) the more recent article on making pretty images from March of this year.

A Simple Example

To get the gist of how this all works, let’s build a simple tower model, put a pressure on the side, then animate it’s displacement.  Download this macro and run it in MAPDL.  If you look at the macro the last thing it does is make a contour plot of the total deflection (PLNSOL, U, SUM).  This is what we want to animate.

So we simply type: “agif_anm1,10”  into the command line to run the animation macro and it will make 10 PNG file. Look in your working directory and you will see twrexmp000.png through twrexmp009.png.  These are the frames.  Now on to making our GIF.

Start GIF Movie Gear and you will get the little start wizard:

image

Click on Insert Frames.  This opens a file selection dialog box. Shift-select the 10 frames we just made and click open:

image

You will now see the upper right corner of the first frame… Don’t panic.  this is the size of your image and the window is small.  Click the little zoom in icon (magnifying glass with a minus sign) until you see a couple of frames.  If you click the play icon, you will see your animation play very fast.  Not what we want. 

So the first thing we will do is change the animation speed by changing the duration of each frame. It is 0 by default.  Go to Animation->Timing and it will show your hyper animation again. At the bottom, change the 0 to a 20 and hit return:

image

That calmed things down a bit. Close that window.

At this point you can simply save your animation and be done: File->Save and give it a name.  And this is what you get:

Twr1

The Bloging software resizes it. Click on the image to get the full size version.

Changing the Size

That may not be the shape, size, or content you want.  To resize the image, use Animation->Resize:

image

Make sure that “Maintain aspect ratio” is checked.  If you don’t, your image can get distorted.  Then set the width or height to what you want.   I’ll use a width of 400.  Make sure the Bicubic is picked for your resizing.  The other method is slower to run but makes bad images unless you have only a few colors.  If you save this image you get the following:

Twr1_400w

Now, we may want to crop. We do that the same way: Animation->Crop. Now this is the only feature I don’t like. It shows the image in a small window. 

image

So click on the Zoom In icon till you can see your image and drag to where you want it and click OK. Save that and you get:

Twr1_cropped

Transparency

One of the coolest things about GIF files is that you can tell the display program to not show a certain color, to make your image transparent.  This is great for PowerPoints.  To do this you need to mark one of the colors in your animation as “transparent.”

Go to Animation->Properties then click on the Global Frame tab:

image

Click on Transparent and it will bring up your color Pallet.  click on the black background or the black color in the table and that will be the transparent color.  Now you need to set the bottom menu to “Restore to Background before drawing next frame”.  If you don’t do this you will see ghosting. 

Click OK. Save that and you get:

Twr1_trans

Not too exciting on this blog because the background is white.  But imagine we had some fancy background.  Copy and paste this into your corporate PowerPoint template and you will see:

image

Converting for AVI’s

What, you are not a gray haired throw back to a past time.  You use CDF Post or ANSYS Mechanical?  You can skip a lot of the first steps and just go straight from an AVI to an Animated GIF. 

Regardless of which tool you are using, you simply need to save an AVI to get started.  For ANSYS Mechanical you do that by using the animation viewer to get the animation you want then click on the “Export Video File” Icon.  Remember to make sure you have turned off the fancy Aero window stuff. 

To make a CFD animation read Clinton’s Article

Now that you have the AVI file you can make a GIF. Start GIF Movie Gear and click on Open File this time.  Choose the AVI and you will see all the frames in the AVI (zoom out if you need to).  If you like what you see, just do a File->Save As and save as a GIF. 

MechAnim1

Just like the animations made from images, you can adjust the size of the image, crop, and set animations.

One thing you may notice is the banding on the background. This is in the AVI due to compression in the AVI.  So if you are making animation we recommend you create a solid background (set in the project schematic->Tools->Options->Appearance) :

MechAnim2

And once you have done that, you can use transparency:

MechAnim2b

Other Things You Should Know

When setting transparencies above we talk about making sure it says: “Restore to Background before drawing next frame” If you don’t, this is what your animation will look like:

MechAnim2c

 

For debugging it is kid of a pain to place in PowerPoint then view as slide show.  A faster way to view an animated GIF is to RMB on it in the explorer and say Open With… and choose Internet Explorer.  You can also drag it into your browser.  Much faster.

The program has an Undo.  Use it.  Try stuff, save the file, look at it, then undo if you need to.

Another thing to be aware of is Ping-Pong.  If you remember our first animation of the deflected tower, it only goes to the max deflection then snaps back to the beginning. It would be much nicer if it went back.   You can do that by going to Animation->Rearrange Frames –>Ping-Pong Animation.

image

Now save and you have an “up and back” animation.  The original is on the left, the ping-pong is on the right.

Twr1_trans[3]Twr1_pp

This tool is also a great way to grab a single frame from an animation.  Say you have an animation and you need a picture, and you don’t want to go back in to the program to make it.  Simply read the AVI into this program, find the frame you want, then do a File->Save As. Pick your format and set “Save as Style” to Individual Image(s).  Then select the “Only selected frames(s)”

image

That is about it.  I hope this will help you make better presentations and cool web sites.

Do you have seizures yet?

Scroll1[6]

Animation_impeller

 

blower2_300

DiskCyclo_H3M1

drop1

 

SnowManCFD1

HSFLD241/242: Modeling Enclosed Liquids

This is a second attempt at this posting.  The first attempt got 60% of the way done, then I rebooted my machine before I saved the posting… Doh.  So let’s try this again:

imageimage

Every once in a while I feel the need to stop exploring all the new and cool stuff in the world of workbench and do a deep dive into something that involves names which are restricted to eight characters or less. Something that involves a script rather than a GUI click.  Something that requires you to look at a real equation, something with an integral sign in it:

image

I want to learn about something that uses comma delimited commands. 

So, up comes ANSYS Help, dive down into the release notes for Mechanical APDL and look for something obscure but useful.  New elements…  Aha!  HSFLD21 – now that is a name to make any I-only-use-the-GUI-and-manuals-with-equations-but-without-color-animations-make-me-nervous user cringe.  Hydrostatic.  I like that word.  It reads:

This 2-D hydrostatic fluid element models fluids that are fully enclosed by 2-D planar and axisymmetric solids. This element is well suited for modeling fluid-solid interaction with incompressible or compressible fluids under uniform pressure. It can be used in geometrically linear as well as nonlinear static and transient dynamic analyses.

Now I have something I can sink my teeth in.

The Basics on the HSFLD241 and HSFLD242

New at R13, these elements are used to model compressible or incompressible fluids that are surrounded by solids. The key assumption to be aware of is deserving of its own line:

The fluid volume has uniform pressure, temperature, and density without any gradients

So no sloshing, variation due to gravity, etc.. Take a look at FLUID80 if you want these things… maybe a future article topic.

HSFLD241 is the 2D and axisymetric version, and HSFLD242 is the 3D version.  If you look at the element pictures from the manual at the top of the posting you’ll see that they are a surface effect element with an extra node, called a pressure node.  You use ESURF to apply the element to the inside face of your enclosing volume, and you link all the faces that make up the volume by making them share a node (L or Q).  The fact that they all share the same node tells the solver that they make a volume. Besides sharing the node, they must share the same material and real number. 

When you use ESURF to make the elements, it automatically makes them a positive volume by the order it defines the face nodes with.  But sometimes you may want to create a negative volume inside your positive. Say you are modeling a tire (what this element was added for actually) and you will find that the pressure node is outside of the volume.  The calculated volume is not correct.  You need to subtract volume for the elements that are actually not in your volume. Here is a cross section to try and make more sense of it.

image

The purple parts are the fluid.  So this is not right. You need to go in and create negative elements on any faces that face away from the origin.  You do this in two steps:  Mesh using ESURF like you normally would, then grab the elements you want to turn into negative elements and issue the ESURF,pnode,REVERSE command.  This will turn those elements into negative volumes.  The key hear is to create your geometry in a way so that you can easily select faces that point away from the center of your volume. If you don’t, you will need to write a macro that loops through the elements, checks the vector from the face centroid to the center of you volume and if it facing out, swap the element normal. Not hard, just tedious.  In our example, the negative element will look like this (color changed for clarity):

image

DOF’s:

The elements have displacement (UX,UY and UX,UY,UZ) Degrees of Freedom on the face part of the element, the part that sits on your structural elements.  The pressure node has a DOF of HDSP or hydrostatic pressure by default, and both PRES and HDSP if you set KEYOPT(1) = 1.  This is so you can hook the node to other elements that have PRES DOF’s like the FLUID116.

Real Constants

For real properties you have the ability to specify a thickness (defaults to 1) on the 2D element so the program can calculate volume correctly. Both versions have a real constant of PREF, the reference pressure. Simple enough.

Material Properties

If you opt for an incompressible fluid, just specify a density and coefficient of thermal expansion for your material.  But if you are modeling a compressible fluid, you use a new material property table to specify the material properties:  TB,FLUID.  Within the FLUID model you have three options:  a model for liquids, a model for gases, or you can provide pressure-volume data. It is recommended that you read the theory manual on these three to understand the difference and how to use them, as well as the standard command information for the TB.

For TB,FLUID,,,,LIQUID the model is basically a squishy solid.  You give a bulk modulus, coefficient of thermal expansion, and an initial density over up to 20 temperatures. 

For TB,FLUID,,,,GAS you simply give a Density. The program then simply uses the Ideal Gas Law… you remember that from freshman physics? Or was it chemistry.  I kind of remember it… sort of:

image

If you have a compressible fluid that does not follow the idea gas law, then you can supply your own pressure vs. volume table with TB,FLUID,,,,PVDATA.

KEYOPT

KEYOPT(1) controls the DOF’s on the pressure node.  By default the uniform pressure for the solid is stored as HDSP.  If you set KEYOPT(1) to 1, then a PRES DOF is added and is set to be equal to HDSP.  This is so you can hook a FLUID116 up to it and flow out of your volume… more below.

KEYOPT(3) is used on the HSFLD241 element to say if it is Planer (0) or Axisymmetric (1)

Use KEYOPT(5) to turn on mass effects for the elements. Remember, this is a uniform mass. But if you have gravity or you are doing a modal analysis, you need this turned on.

Turn compressibility off by setting KEYOPT(1) to 1.

Other Basic Info

Give the manual page a read on the element.  There are a lot of output options besides the DOF solution. Stuff like Volume, Mass, and mass flow rate. 

Simple ExampleHSFLD_EXMP1

(Want to know how I made this animation… that will be next weeks article.
  I used a program called GIF Movie Gear, best $29.95 I’ve spent in a while…)

So, having waded through the boring bits, let’s build a model.  Our first example is simply a 2D hollow rectangle that we apply a pressure to. Here is the macro.  Take a look at the comments and follow the process.

   1: !Square Baloon Macro   - Example for HDSP241

   2: !

   3: ! Get in the begin level, clear the databse

   4: !   and go to the preprocessor

   5: finish

   6: /clear

   7: /prep7

   8: ! Define Dimensions as parameters

   9: wdth = 2

  10: hght = 4

  11: thk = .1

  12: ! Build two rectangles and subtract the inner one

  13: !  to make an enclosure

  14: blc4,(-1*wdth/2),0,wdth,hght

  15: blc4,(-1*wdth/2)+thk,thk,wdth-2*thk,hght-2*thk

  16: asba,1,2

  17: ! Make a component out of the inner lines - this is

  18: !  where we will put our HDSP elements

  19: lsel,s,,,5,8

  20: cm,l_insd,line

  21:  

  22: ! Define a 182 for the solid and 241 for the fluid

  23: et,1,182

  24: et,2,241

  25:  

  26: ! Sort of soft material for the enclosure wall

  27: mp,ex,1,10e5

  28: mp,nuxy,1,.3

  29: mp,dens,1,.001

  30:  

  31: ! Some fluid properties

  32: tb,fluid,2,,,,liquid   ! Liquid Properties

  33: tbdata,1,300000        ! Bulk Modulous

  34: tbdata,2,6.4e-4        ! Coeficient of thermal exp.

  35: tbdata,3,.001          ! Density

  36:  

  37: ! Mesh the enclosure wall

  38: type,1

  39: mat,1

  40: esize,thk/2

  41: amesh,all

  42:  

  43: ! Grab the inside nodes from the compenent and create

  44: !   the fluid mesh using esurf

  45: cmsel,s,l_insd

  46: nsll,s,1

  47: type,2

  48: mat,2

  49: n,999,0,2

  50: esurf,999  ! Tell esurf to make the "extra" node 999

  51:            ! That all the elements share

  52: allsel,all

  53:  

  54: ! Fix the bottom of the enclosure vertically

  55: !  And fix the bottom right corner tangentially

  56: !  to constrain the model

  57: nsel,s,loc,y,0

  58: d,all,uy

  59: nsel,r,loc,x,-1*wdth/2

  60: d,all,ux

  61: allsel

  62:  

  63: ! Specify an load of 100 psi as the internal pressure

  64: !  The model will ramp up to that load over the specified

  65: !  substeps

  66: d,999,hdsp,100

  67:  

  68: ! Set up Solve and Run

  69: /solu

  70: nlgeom,on

  71: nsubst,50,100,20

  72: outres,all,all   ! Don't forget to save substeps so you

  73:                  !   can animate them

  74: solve

  75: finish

  76:  

  77: ! Animate the resulting displacement

  78: /post1

  79: set,last

  80: /dscale,1,1

  81: plnsol,u,sum

  82: andata,0.5,,0,0,0,1,0,1

One key thing to note in the code is the ESURF command.  Notice how you specify the common node as the first argument in the command. This is pretty useful and avoids making you go through and specify.  You can download the macro here.

HSFLD_Piston1A More Complex Example

The help on this element is pretty cool, and it even includes an example of how to build a piston. Unfortunately it does not include the part that solves it.  So I’ve added that imagemade some other changes, including an animation and a short trip into POST26 to get pressure and volume of the fluid over time. The code is below.  The most obvious thing when looking at this animation is the funny triangle thingy.  that is a negative element that deals with the fact that the volume is changing over time.  It is not 100% accurate but basically says any fluid above the piston needs to be subtracted.  In the image on the right, the solid geometry mesh, you can imagine that your fluid volume can be anywhere inside the piston, from the top of the yellow line to the whole length of the green.  The red dot shows the bottom corner of the piston.  If you make an element from the red dot to the top and bottom of the yellow line, no mater where the piston goes you will subtract the volume of any part of the total volume that is above the piston.  I found that kind of slick and clever of the ANSYS developers.  It doesn’t plot so cool, but it gets the job done.

Here is the code:

   1: finish

   2: /clear

   3: /prep7

   4: ! Define element types

   5: et,1,182    !plane182

   6: keyopt,1,3,1    !axisymmetric option

   7: et,2,241    !hsfld241 

   8: keyopt,2,3,1 ! axi option

   9: ! Material properties for Steel

  10: mp,ex,1,2.0e5    !Young's Modulus in N/mm^2

  11: mp,nuxy,1,0.3    !Poisson's ratio

  12: mp,dens,1,7.7e-9!Density in ton/mm^3

  13:  

  14: ! Material properties for hydraulic fluid

  15: tb,fluid,2,,,,liquid

  16: tbdata,1,2000.0    !Bulk Modulus in N/mm^2

  17: tbdata,2,6.4e-4    !Coefficient of thermal expansion

  18: tbdata,3,8.42e-5!Density in ton/mm^3

  19: ! Nodes

  20: n,1,0.0,50.0    !pressure node

  21: ! Keypoints

  22: k, 1, 0.0,  0.0

  23: k, 2,25.0,  0.0

  24: k, 3,25.0,100.0

  25: k, 4,10.0,100.0

  26: k, 5,10.0, 95.0

  27: k, 6,20.0, 95.0

  28: k, 7,20.0,  5.0

  29: k, 8, 0.0,  5.0

  30: k, 9, 0.0, 80.0

  31: k,10,19.0, 80.0

  32: k,11,19.0, 85.0

  33: k,12, 3.5, 85.0

  34: k,13, 3.5,185.0

  35: k,14, 0.0,185.0

  36: ! Areas

  37: a,1,2,3,4,5,6,7,8

  38: a,9,10,11,12,13,14

  39: ! Planar elements

  40: type,1

  41: mat,1

  42: esize,2.5

  43: amesh,all

  44: ! Hydrostatic fluid elements--automatic generation

  45: type,2

  46: mat,2

  47: lsel,s,line,,6,9

  48: nsll,s,1

  49: esurf,1

  50: allsel,all

  51: ! Create the Negative volume element- needed to take into account

  52: ! the movement of the piston

  53: e,61,162,,1    !element with negative volume--nodes 61 and 162 swapped

  54: ! Symmetry boundary condition on pressure node   [REQUIRED]

  55: d,1,ux,0.0

  56: ! Symmetry boundary condition on planar mesh

  57: lsel,s,line,,8,14,6

  58: nsll,s,1

  59: d,all,ux,0.0

  60: allsel,all

  61: ! Fixed boundary condition on planar mesh

  62: lsel,s,line,,1

  63: nsll,s,1

  64: d,all,all,0.0

  65: allsel,all

  66:  

  67: ! Grab the nodes on top and apply a downward displacement 

  68: nsel,s,,,179

  69: nsel,a,,,219

  70: cm,ptop,node

  71: d,ptop,uy,-35

  72:  

  73: ! Run the model

  74: finish

  75: /solu

  76: nlgeom,on

  77: nsubst,200,500,10

  78: outres,all,all

  79: solve

  80:  

  81: ! Go to post 26 and get pressure and volume over time

  82: /post26

  83: numvar,200

  84: ESOL,2,180,1 ,NMISC,2,NMISC2_2 

  85: nsol,3,1,HDSP

  86: /grtyp,2

  87: plvar,2 ,3

  88:  

  89: !Animate the results

  90: /post1

  91: set,last

  92: /dscale,1,1

  93: /pnum,mat,1

  94: /number,1

  95: /edge,1,1

  96: !esel,u,,,eflp

  97: pldisp

  98: andata,0.1,,0,0,0,1,0,1

  99:  

Here is the graph of the results.  Not very exciting.

image

Download the Macro here.

Other things to know

OK, this was a lot more involved than planned, and there is still more to learn.  But I’ve got HR paperwork to fill out so we will wrap it up.

You should go through the verification problem for this element: VM209

image image

  • You can connect different volumes with FLUID116 elements.  This allows some pretty fancy system modeling.  Add in some control elements and electromagnetics and you can really capture some complex systems.
  • Be very aware of the negative volume issues when modeling tires and such. 
  • After I started on this article I found out that we are in the middle of a project for a customer who is modeling an optical device that has a fluid core.  It is working very well for them. I wish I could show the model, but I would be shot by the customer.  I can say that we are getting much better results than when we modeled the volume with solids.
  • The FLUID80 is a solid fluid volume element that does take into account non-uniform pressure, mass, etc… Take a look at it if these guys don’t do what you need.
  • Can you do this in Workbench?  Sort of.  You should be able to write a macro that uses a component to create your hydrostatic elements and define the material properties.  You won’t be able to post process the results but you can at least set it up and bring back plots. (check out this presentation, slide 41)
  • Workbench Scripting: Using Forms in your Script

    Last week we had a very well attended Webinar on using Scripting with Workbench. We talked about how you can control projects, parameters, and material properties with python.  We also talked about how you can use python to drive data compliant applications by sending commands and/or parameters to it.  You can watch the webinar at:

    https://padtincevents.webex.com or click Here to download it and watch it with the WebEx player.

    Click on PADT ANSYS Webinar Series and then find the recording from August 11, 2011.

    Several attendees asked if we had an example of using python to bring up a GUI on top of workbench. We did not. This is how The Focus articles are born.

    The Basics

    In case you missed the webinar or didn’t follow some of it, here are the important points:

    • Workbench has IronPython built into it from the ground up
    • You can record whatever you do in the GUI to create scripts
    • You can read those scripts in to control Workbench
    • ANSYS uses IronPython because it talks to Windows programs
    • Get detailed info at www.python.org, www.ironpython.net, and www.ironpython.info

    Most of the examples below are derived from information I got at: http://www.ironpython.info/index.php/Contents#Windows_Forms

    We will be making a GUI for the famous Tower of Test application.  We will need a place to enter in the size of the tower, a pressure load. Then a simple table showing the results when we get them. And of course, buttons to cancel and execute.

    If you are already an experienced Windows programmer, this will be a slam dunk. If you are not, then you will need to make sure you learn your way around the MSDN .Net Class Library Reference:

    http://msdn.microsoft.com/en-US/library/ms229335(v=VS.80).aspx

    That is where you find properties and methods for the GUI.  We will be spending most of our time in System.Windows.Form.

    Why .NET?

    Right now, some of you might be asking “Why .NET?”  Python supports probably over a dozen different GUI’s.  I am using .NET for a few reasons:

    1. It is built into IronPython. No need to download a library and install it right
    2. It will have a consistent look and feel to Workbench
    3. More people know .NET than the other GUI libraries.

    If you are anit-microsoft, you can poke around and find a library that fits your needs.  The process will be the same.

    Crawl: Always Start with Hello World

    Anytime I try and learn a new language, I usually find a “Hello World” Example.  And, thanks to the internet I found one that only needed slight modification:

       1: import clr

       2: clr.AddReference('System.Windows.Forms')

       3:

       4: from System.Windows.Forms import Application, Form, Label

       5:

       6: form = Form(Text="Hello World Form")

       7: label = Label(Text="Hello World!")

       8:

       9: form.Controls.Add(label)

      10:

      11: Form.ShowDialog(form)

    So first, we access the huge number of Windows tools by importing clr.  Then, get a reference to Windows Forms.  Once that is done we need to import more from Windows Forms. This is a big tool box so it has lots of levels you have to dig through.  For this guy we need to be able to do the form itself (the window) and a label (text in the window).

    Now that we have our objects, we create a form with the title “Hello World Form” and a label with the text “Hello World!”  We then use the Add method to add the label control to the form. Last, we use the Show Dialog method to show the form.  TADA.

    To give it a try, copy and paste this into your own text editor and then go into Workbench and choose:

    File->Scripting->Open Command Window…

    Then paste in the script.  Or you can save it to a file and read it in. I like to paste so I can see my error messages as it goes.

    image

    Now you are a Workbench GUI programmer.  Put it on your resume!

    Walk: Add Some Controls to the Window

    Next we want to do a bit more than saying hello.

    The important thing I learned that I just didn’t’ get before is that you have to make a class out of your form and any functions that get called when the user clicks on a button or interacts in any way with the form.  You do this because Windows will then pass information about the form back to the event function.

    In the example below is like “Hello World” to start, then we make 4 text boxes with labels for the user to enter data into.  We then add an OK and a Cancel button.  The code is commented with an explanation of what is going on.  If something does not make sense, look it up in a python reference or ask someone who is a python programmer.

       1: # --  Bring in the .NET stuff, and reference Forms and drawing

       2: import clr

       3: clr.AddReference('System.Windows.Forms')

       4: clr.AddReference('System.Drawing')

       5:

       6: #   get the objects you need from forms and drawing

       7: from System.Windows.Forms import Form, Label, Button, TextBox

       8: from System.Drawing import Point, ContentAlignment

       9:

      10: #-- The way python works with events, you have to make a class out of your form.  

      11: #   Then the objects 

      12: #    you add are available in event functions.

      13: class TowerForm(Form):

      14:     def __init__(self):

      15: #-- First, make the form (self)

      16:         self.text="Tower Simulation Tool"

      17:         self.Height=500

      18:         self.Width=250

      19:

      20: #-- Create a Simple Text Label describing the tool

      21: #   it is not self.label because we are not going to access it in event functions

      22:         lbl1 = Label()

      23:         lbl1.Text = "This is the Tower of Test Tool. \n\

      24:             Please Enter values and click OK to run the \

      25:             model and get new results\n"

      26:         lbl1.Height = 50

      27:         lbl1.Width = 200

      28:

      29: #-- Create the Text Labels and text boxes to get Dimensions and Pressure

      30: #   We need to get to the textboxes so we will make them part of the class

      31: #

      32: #   some constants to make the positioning easier

      33:         x1 = 10

      34:         y1 = 80

      35:         w1 = 70

      36:         w2 = 80

      37:         x2 = x1 + w1 + 10

      38: #   Make the labels for the text boxes.  This is done in the Labe() call with 

      39: #   Name = Value arguments 

      40: #   instead of object.name = value to save space.  All in one line instead of 

      41: #   four lines.

      42: #     The alighment is done so that the labels are all right justified to line 

      43: #     up with the boxes. Set ContentAlignment.MiddleRight to mr to save space

      44:         mr = ContentAlignment.MiddleRight

      45:         lb_Length=Label(Text="Length", Width=w1,TextAlign=mr)

      46:         lb_Width  = Label(Text="Width",   Width = w1, TextAlign=mr)

      47:         lb_Height = Label(Text="Height",  Width = w1, TextAlign=mr)

      48:         lb_Press  = Label(Text="Pressure",Width = w1, TextAlign=mr)

      49:

      50: #   Make the text boxes. Note that these are put in the self. class. 

      51: #   We do this so that when the OK 

      52: #   button is pushed, we have access to the text boxes and therefore the values 

      53: #   typed within

      54:

      55:         self.tb_Length = TextBox(Width = w2)

      56:         self.tb_Width  = TextBox(Width = w2)

      57:         self.tb_Height = TextBox(Width = w2)

      58:         self.tb_Press  = TextBox(Width = w2)

      59:

      60: #   Specify the location for the label and the text boxes.  Move down by 

      61: #   30 after each line

      62:         lb_Length.Location = Point(x1,y1)

      63:         self.tb_Length.Location = Point(x2,y1)

      64:         y1 = y1 + 30

      65:         lb_Width.Location = Point(x1,y1)

      66:         self.tb_Width.Location = Point(x2,y1)

      67:         y1 = y1 + 30

      68:         lb_Height.Location = Point(x1,y1)

      69:         self.tb_Height.Location = Point(x2,y1)

      70:         y1 = y1 + 30

      71:         lb_Press.Location = Point(x1,y1)

      72:         self.tb_Press.Location = Point(x2,y1)

      73:

      74: #   Make an OK and a Cancel Button

      75:         okBut = Button(Text="OK", Width=50)

      76:         okBut.Location = Point(30,430)

      77: #       This is where you specify the funtion to be called when the button is clicked

      78: #       note that you call the function self.functionname.

      79:         okBut.Click += self.okButPressed

      80:

      81:         cancelBut = Button(Text="Cancel", Width=50)

      82:         cancelBut.Location = Point(110,430)

      83:         cancelBut.Click += self.cancelButPressed

      84:

      85: #   Put everything on the form (some sort of list and loop would make this easier)

      86:         self.Controls.Add(lbl1)

      87:         self.Controls.Add(lb_Length)

      88:         self.Controls.Add(self.tb_Length)

      89:         self.Controls.Add(lb_Width)

      90:         self.Controls.Add(self.tb_Width)

      91:         self.Controls.Add(lb_Height)

      92:         self.Controls.Add(self.tb_Height)

      93:         self.Controls.Add(lb_Press)

      94:         self.Controls.Add(self.tb_Press)

      95:         self.Controls.Add(okBut)

      96:         self.Controls.Add(cancelBut)

      97:

      98: #-- Now define the button event functions as part of the class

      99: #

     100: # Cancel simply closes the form down.  Nothing fancy

     101:     def cancelButPressed(self, sender, args ):

     102:         print 'Closing the Window... Bye...\n'

     103:         self.Close()

     104:

     105: # OK prints the values of the text boxes to the console

     106: #   This will be replaced with calls to workbench for the next step

     107:     def okButPressed(self, sender, args ):

     108:         print 'Values Entered:\n'

     109:         print '  Length: %s\n' %self.tb_Length.Text

     110:         print '   Width: %s\n' %self.tb_Width.Text

     111:         print '  Height: %s\n' %self.tb_Height.Text

     112:         print 'Pressure: %s\n' %self.tb_Press.Text

     113:         self.Close()

     114: #---------End of class definition

     115:

     116:

     117: # Instantiate the form and make the form visible

     118: print '=======================================\n'

     119: print 'Opening the Windows...\n'

     120: myForm = TowerForm()

     121: Form.ShowDialog(myForm)

     122:

    If you have not programmed a go dialog box in a while by hand, instead of using a WYSIWIG GUI builder, you can see why.  Lots of lines… lots of lines…
    Here is the file without the numbers in it so you can run it in Workbench:  TowerToolTextOnly.py

    imageRun:  Send Values to Workbench, Update Model, Get Results

    If you remember the previous article on Driving Workbench from Excel this will all look familiar.  If you don’t review the article, especially the part about getting parameters in and out of Workbench with Python.  To finish our example we will use the same basic code to:

    • Get the current values from Workbench and set our dialog to show those values
    • When the user hits OK:
      • Set the Workbench parameters to the current dialog box parameters
      • Update the model
      • Get the resulting deflection and display it.

    The code is shown below, with the bits added for the Workbench interaction highlighted.  Note that we also introduced the specification of font properties on a label.  Making it even more fancy.

       1: # --  Bring in the .NET stuff, and reference Forms and drawing

       2: import clr

       3: clr.AddReference('System.Windows.Forms')

       4: clr.AddReference('System.Drawing')

       5:

       6: #   get the objects you need from forms and drawing

       7: from System.Windows.Forms import Form, Label, Button, TextBox

       8: from System.Drawing import Point, ContentAlignment,

    Font, FontStyle, GraphicsUnit

       9:

      10: #-- The way python works with events, you have to make a class out of your form.  

      11: #   Then the objects 

      12: #    you add are available in event functions.

      13: class TowerForm(Form):

      14:     def __init__(self):

      15: #-- First, make the form (self)

      16:         self.text="Tower Simulation Tool"

      17:         self.Height=500

      18:         self.Width=250

      19:

      20: #-- Create a Simple Text Label describing the tool

      21: #   it is not self.label because we are not going to access it in event functions

      22:         lbl1 = Label()

      23:         lbl1.Text = "This is the Tower of Test Tool. \n\

      24:             Please Enter values and click OK to run the \

      25:             model and get new results\n"

      26:         lbl1.Height = 50

      27:         lbl1.Width = 200

      28:

      29: #-- Create the Text Labels and text boxes to get Dimensions and Pressure

      30: #   We need to get to the textboxes so we will make them part of the class

      31: #

      32: #   some constants to make the positioning easier

      33:         x1 = 10

      34:         y1 = 80

      35:         w1 = 70

      36:         w2 = 80

      37:         x2 = x1 + w1 + 10

      38: #   Make the labels for the text boxes.  This is done in the Labe() call with 

      39: #   Name = Value arguments 

      40: #   instead of object.name = value to save space.  All in one line instead of 

      41: #   four lines.

      42: #     The alighment is done so that the labels are all right justified to line 

      43: #     up with the boxes. Set ContentAlignment.MiddleRight to mr to save space

      44:         mr = ContentAlignment.MiddleRight

      45:         lb_Length=Label(Text="Length", Width=w1,TextAlign=mr)

      46:         lb_Width  = Label(Text="Width",   Width = w1, TextAlign=mr)

      47:         lb_Height = Label(Text="Height",  Width = w1, TextAlign=mr)

      48:         lb_Press  = Label(Text="Pressure",Width = w1, TextAlign=mr)

      49:

      50: #   Make a label to give status of the update in:

      51:

    self.updlbl = Label(Text=” “,Width=200, Height=100,\

      52:

    TextAlign=ContentAlignment.BottomCenter)

      53:

    self.updlbl.Location = Point(0,200)

      54:

    self.updlbl.Font = \

      55:

    Font(‘Verdana’,10, FontStyle.Bold, GraphicsUnit.Point,0)

      56:

      57: #   Make the text boxes. Note that these are put in the self. class. 

      58: #   We do this so that when the OK 

      59: #   button is pushed, we have access to the text boxes and therefore the values 

      60: #   typed within

      61:

      62:         self.tb_Length = TextBox(Width = w2)

      63:         self.tb_Width  = TextBox(Width = w2)

      64:         self.tb_Height = TextBox(Width = w2)

      65:         self.tb_Press  = TextBox(Width = w2)

      66:

      67: #   Specify the location for the label and the text boxes.  Move down by 

      68: #   30 after each line

      69:         lb_Length.Location = Point(x1,y1)

      70:         self.tb_Length.Location = Point(x2,y1)

      71:         y1 = y1 + 30

      72:         lb_Width.Location = Point(x1,y1)

      73:         self.tb_Width.Location = Point(x2,y1)

      74:         y1 = y1 + 30

      75:         lb_Height.Location = Point(x1,y1)

      76:         self.tb_Height.Location = Point(x2,y1)

      77:         y1 = y1 + 30

      78:         lb_Press.Location = Point(x1,y1)

      79:         self.tb_Press.Location = Point(x2,y1)

      80:

      81:         self.tb_Length.Text = Parameters.GetParameter(Name="P1").Expression

      82:         self.tb_Width.Text = Parameters.GetParameter(Name="P2").Expression

      83:         self.tb_Height.Text = Parameters.GetParameter(Name="P3").Expression

      84:         self.tb_Press.Text = Parameters.GetParameter(Name="P5").Expression

      85:

      86: #   Make an OK and a Cancel Button

      87:         okBut = Button(Text="OK", Width=50)

      88:         okBut.Location = Point(30,430)

      89: #       This is where you specify the funtion to be called when the button is clicked

      90: #       note that you call the function self.functionname.

      91:         okBut.Click += self.okButPressed

      92:

      93:         cancelBut = Button(Text="Cancel", Width=50)

      94:         cancelBut.Location = Point(110,430)

      95:         cancelBut.Click += self.cancelButPressed

      96:

      97: #   Put everything on the form (some sort of list and loop would make this easier)

      98:         self.Controls.Add(lbl1)

      99:         self.Controls.Add(lb_Length)

     100:         self.Controls.Add(self.tb_Length)

     101:         self.Controls.Add(lb_Width)

     102:         self.Controls.Add(self.tb_Width)

     103:         self.Controls.Add(lb_Height)

     104:         self.Controls.Add(self.tb_Height)

     105:         self.Controls.Add(lb_Press)

     106:         self.Controls.Add(self.tb_Press)

     107:

    self.Controls.Add(self.updlbl)

     108:         self.Controls.Add(okBut)

     109:         self.Controls.Add(cancelBut)

     110:

     111: #-- Now define the button event functions as part of the class

     112: #

     113: # Cancel simply closes the form down.  Nothing fancy

     114:     def cancelButPressed(self, sender, args ):

     115:         print 'Closing the Window... Bye...\n'

     116:         self.Close()

     117:

     118: # OK prints the values of the text boxes to the console

     119: #   This will be replaced with calls to workbench for the next step

     120:     def okButPressed(self, sender, args ):

     121:

     122: # In Workbench: Get objects for all the parameters you need access to

     123: #   Remember, it goes by parameter name, not the name you give them.

     124:

    lenParam = Parameters.GetParameter(Name=“P1”)

     125:

    widParam = Parameters.GetParameter(Name=“P2”)

     126:

    hgtParam = Parameters.GetParameter(Name=“P3”)

     127:

    prsParam = Parameters.GetParameter(Name=“P5”)

     128: # don't forget the resulting deflection output parameter:

     129:

    defParam = Parameters.GetParameter(Name=“P4”)

     130:

     131: # Now set the workbench values to the values from the dialog

     132:

    lenParam.Expression = self.tb_Length.Text

     133:

    widParam.Expression = self.tb_Width.Text

     134:

    hgtParam.Expression = self.tb_Height.Text

     135:

    prsParam.Expression = self.tb_Press.Text

     136:

    self.updlbl.Text = “Updating”

     137:

     138:

    Update()

     139:

    dflValue = defParam.Value.Value

     140:

    self.updlbl.Text = “Deflection is %s in\n” %dflValue

     141:

     142:

     143: #---------End of class definition

     144:

     145:

     146: # Instantiate the form and make the form visible

     147: print '=======================================\n'

     148: print 'Opening the Windows...\n'

     149: myForm = TowerForm()

     150: Form.ShowDialog(myForm)

     151:

     

    Next Steps and Suggestions

    And that in a nutshell is the basics of putting a GUI on Workbench.  By using the calls to Workbench, .NET or any other complaint application, you can script away and do what you want.

    Much more can be done.  You could have the solver you are running in update and create some plots, and then use python to find those plots (say search for any *.jpg files in the project director created after the OK button was pushed) and insert them into PowerPoint with text that you also gather.

    There really are no limitations.

    To learn more, try stuff.  Get to know the MSDN documentation to know what you can do to make a more professional GUI.  The Windows Forms part of ironpython.info is a great resource for this and points to MSDN as needed.

    There is a lot more you can do with ANSYS  Workbench and the various solvers.  And with each release, workbench will add and document more.

    If you write a cool application you can share, make sure you put it on XANSYS or send it to Sheldon at ANSYS.net.

    Using the ‘Identifier’ for Mechanical Post-Processing

    Wow, how time flies.  I wrote an article ~5 weeks ago where I discussed User Defined Results in ANSYS Mechanical.  One of the comments on that blog concerned being able to operate on results from multiple load steps, “e.g. stress in step 2 minus stress in step 1”.  I responded that yes you could, and then like an idiot stated I would have another article written in “a week or so” detailing how to do this.  My apologies Kjetil, I’m just now getting to this.  Please don’t cancel your membership in the “Doug Oatis B-Movie + ANSYS Trick Fan Club” (I’d hate to be the only member left, plus your dues are non-refundable).

    destroyed-hotel-room

    Do you know how exhausting it is to party like Motley Crue…by yourself?!?

     
    Anyways…back on topic.  The ‘identifier’ is a line available in the Details Window for any result item.
    pic1

     

    You can type in any kind of name in the cell to the right.  Note that you need to enter the name in before you evaluate the result item, or else you will see that the right cell is gray (meaning you cannot edit it).  If this happens, simply RMB on the result item in the tree and select ‘Clear Generated Data’.  That will empty the ‘bucket’ of that result item and let you edit the details of it (it WILL NOT clear out your result file…unless you RMB on ‘Solution’).

     

    pic2 pic3

    Identifier cell after result has been evaluated

    To fix, RMB and select ‘Clear Generated Data’

     
    The benefit to using the identifier is that you can then create a user-defined result and type in an expression using these identifiers.  Here’s the documentation section that discusses the available functions:
    pic4
    Lots of words…but pretty intuitive function definitions
     
    The thing to note up there is the order you define the function depends on if you’re operating off of scalars or vectors (I’ll explain below).  Let’s start out by first defining our UX and UY identifiers in our post-processing section:
     
    pic5 pic6
    X-Direction, Identifier = d_ux Y-Direction, Identifier = d_uy
     
    After I’ve defined both of these identifiers, I insert a User Defined Result.  Next, I just type in the expression I want it to evaluate:
    pic7 pic8
     
    Going back to the issue of scalars vs arrays, let’s say I wanted to add some type of constant to one of my user defined results.  In this case let’s assume I know that there’s an additional .5-in of rigid body motion that I want to plot.  To do this, I need to understand that the identifier d_ux represents an array of information (node vs displacement).  If I want to add a scalar (.5), I need to enter the expression d_ux+.5 (NOT .5+d_ux). 
     
    If I had multiple load-steps, I could scope a stress result to a specific time-point and then perform a similar operation.  That would give me the stress increase due to the load change in between load-steps.
    pic9 pic10 pic11
     
    The thing to watch out here is to make sure that you stay consistent in what you’re operating on.  Sure you can add stress and displacement together, but that’s not really going to get you anywhere.
     
    pic12 nobel-medal
    d_ux*10000+d_seqv…everyone knows that [in]+[psi]=[Oatis] For outstanding achievement in the field of flat-plate-with-hole-in-it analysis
     
    Also make sure that other details of identifiers you’re combining are consistent (e.g. coordinate system, integration option, etc).
     
    For all those MAPDL users, think of this as exposing most of the *voper command within the Mechanical interface.  The main difference is that you don’t have to worry about defining your array size, and it’s incredibly easy to get the data out (RMB > Export…rather than fighting your way through fortran or C formatters).
     
    Enjoy!

    CAE Market Fully Analyzed… Is that Cannibalism?

    Just saw a news article that a consulting company called 01 Consulting just did a study of the CAE market.  Unfortunately the report is $2,850 so, no matter how interested I am in the results I’m not going to buy one.

    However they did release an Executive Summary:

    http://www.01consulting.net/02_2011_MCAE_GLOBAL_Market_ES.html

    And in there they have a cool graph that shows relative size (by revenue):

    The size of MathWorks was shocking to me how big they are.  At their price point that is a lot of seats.  ANSYS dominates, with between 20% and 25% of the market. 

    The other thing they mention is continued double digit growth in the CAE segment.  Even in these times, people are getting the message that simulation pays back big. 

    ANSYS CFX Solver Manager Instructions for Linux

    Since PADT has been building the CUBE machines (www.CUBE-HVPC.com), we have developed a need for clear-cut instructions for running parallel benchmarks with ANSYS software tools on the CUBE machines (which come standard with the CentOS Linux 64-bit operating system).  The computational fluid dynamics (CFD) solver ANSYS CFX is one such tool.  I have summarized instructions here for starting the CFX Solver-Manager on a Linux machine, loading the *.def file, configuring it for a parallel run, and then running it.

    Step 1: Place the benchmark input file (*.def file) for CFX in /home/user.

    We’ll assume the benchmark file is the standard CFX airfoil benchmark:

    *.def file = “perf_Airfoil_R12_PADT.def”.

    Step 2: Start CFX on the command line: type “/ansys_inc/v121/CFX/bin/cfx5”.

    fig1

    Figure 1 – Command to launch CFX

    Step 3: Set the Working Directory / Start the Solver Manager

    a) The CFX Launcher will display based on the command entered in Step 2.

    b) Check that the “Working Directory” corresponds to /home/user (red rectangle in Figure 2).  If it is something different, select the folder icon contained in the red rectangle in Figure 2, and navigate to /home/user.

    c) Select the “CFX-Solver Manager” (black rectangle in Figure 2)

    fig2

    Figure 2 – Set the Working Directory and open the CFX-Solver Manager

    Step 4: Define Run

    a) Select “File – Define Run” (Figure 3)

    b) Check “Show Advanced Controls” (Figure 3)

    fig3

    Figure 3 – Define the Run

    Step 5: Read the *.def file

    a) Select the folder icon (Figure 4).

    b) Pick “perf_Airfoil_R12_PADT.def” (Figure 4).

    c) Select Open (Figure 4).

    fig4

    Figure 4 – Read the *.def file

    Step 6: Set the Run Mode

    a) Select the pull-down next the “Run Mode” (Figure 5).

    b) Pick “HP-MPI Local Parallel” (Figure 5).

    fig5

    Figure 5 – Set the Run Mode

    Step 7: Partitioner Settings

    a) Go to the “Partitioner” tab (Figure 6)

    b) Under “Partitioning Detail” select “Multidomain Option – Coupled Partitioning” (Figure 6)

    fig6

    Figure 6 – Partitioner Settings

    Step 8: Add partitions and Run

    a) Click the “plus” sign to add partitions (the number of partitions should be the same as the number of processors for the run) (Figure 7).

    b) Select “Start Run” (Figure 7).

    fig7

    Now, your job should start up and you will see the residuals/imbalances:

    fig8

    Figure 8  – CFX-Solver Manager with running job

    Happy solving…

    Workbench and Excel, Part 2: Driving Workbench From Excel with Python

    imageFor a couple of releases now you have been able to use the very common scripting language python to script applications that are considered Workbench native: the project page, Engineering Data, DesignXplorer, and the Parameter Manager.  This is pretty cool and something that we will cover in a future The Focus article.  But one thing that most people don’t know is that python also works well with Microsoft Excel.  So if it works with Excel and Workbench, you should be able to use it to connect the two. 

    Now before you get too excited, realize that ANSYS Mechanical, CFX, FLUENT, CFX Post and most other solvers and post processors that launch from Workbench are not workbench native applications, so they don’t speak python. So no, this is not a replacement for PADL or CCL.  They are called “data integrated” applications in that they share data through the Workbench interface, but they have their own software structure that is unique, and their own scripting language.

    So to take advantage of this python commonality you have to connect to one of the native applications, and the parameter manager makes the most sense.  And fortunately the kind technical people at ANSYS, Inc. have provided a great example in the help system to do just that. And in doing so they have cut the length of this article in half.

    ANSYS Documentation Example

    You can find the example under: Workbench //  Scripting Guide // Using Scripting in ANSYS Workbench // Usage Examples // Updating a Workbench Project and Parameters from Excel.  It is a very simple example, a cantilever beam, but it shows the basics and is a great place to start.

    image

    Read the manual page completely, especially the notes at the bottom.  They point out the key things you need to know.  The files you need are in the documentation, but you need to dig up the excel/workbench files and copy the python script and get rid of the line numbers.  I’ve put them all together in a zip file to make things easier:  

    There are a few things worth discussing on this example before we move on to something more complicated.

    How to Run It

    One thing the example leaves out is the details on how to run it.  To start, you need to copy all the files to one directory: the python script, the workbench database, the workbench files, the excel file.  Then (it does point this out) you need to set the working directory variable in the script to the directory with all the files.  Now it is time to run. To do this open up Workbench with a new project (or File->New if you already have Workbench open).  Now run the script with File->Scripting->Run Script File…

    image

    This will launch Excel and Workbench and add the command to execute the update script when you push the button.  So, what next?  Change the value for Bar Length or Load and press the button.  This should cause Workbench to update and the Maximum Deformation value to change to Updating… and then the new value when the run is done.  And that, in a nutshell, is the basics of making the two tools talk.

    How it Works

    The documentation does a pretty good job of explaining the details. The important take away is that you have to do a couple of key steps in any program that is going to do this sort of thing:

    1. Tell python to load the Excel stuff
    2. Set up the working directory, the routines all need absolute paths to work
    3. Grab cell’s from excel, grab params from Workbench, and set one to the other as needed
    4. Do an update
    5. Provide a mechanism to start the process (the button in this case)

    If you have these steps, you can make Excel and ANSYS talk.

    Where Things Run

    An important thing to get your head around is where the script is running, or more accurately, what process is reading and executing the script. The python interpreter is actually in the Workbench environment.  When you run the python script you are not running it in Excel or in the operating system.  It is running through a interpreter inside Workbench. 

    This is important because it controls what information is automatically available to the script as well as how you launch it.  In this example, you launch from Workbench and it starts up Excel, does stuff in Excel, and then assigns a python routine to the button. When the button is clicked, you are still running a python script in Workbench – it is just talking to Excel.

    Limitations in the Example

    There are two big limitations with this example when it comes to using it on a real problem. First, it is not general enough because you have to hard code in file names, directory locations, cell locations and strings. This is not a huge deal because if you are going to use an excel based simulation tool over and over, you only have to set it up once and go.

    The other problem is that the action to update the spreadsheet and model is assigned as an OLEObject to the button. Unfortunately this is only active when the script is running. Once it is done the click action is removed, and the button becomes useless… allowing for only one use of the button.  This is a significant issue.

    A More General and Complex (Sort Of) Example

    A common potential usage for this sort of tool would be to provide a user with an Excel based tool that they would use to design a part and see the results.  For this example we are going to use a very complicated tool for designing towers with a rectangular cross section.  The input variables are the length, width, and height of the tower as well as a pressure applied to one face.  The output variables are the deflection from the pressure and the first 10 natural frequencies. 

    Of course a real example would have more complex input and output values, and the spreadsheet would probably do a lot more calculations, perhaps even optimization.

    This example avoids the button problem by actually running Workbench from Excel by launching it from the command console and supplying the project file AND the python script as startup parameters to Workbench.  Workbench loads the project, runs the script, then exits.

    The Spreadsheet

    The spreadsheet is called TowerTool1 and it is a macro (xlsm) spreadsheet. You can download it here:

    image

    The sheet is not that different from the ANSYS provided example. It has cells for input and output parameters.  It also has a button to update the system.  The first thing that is different is that it uses named ranges for the input and output cells.  To see the names go to Formulas->Defined Names->Name Manager.  I used “Create from Selection” to automatically assign the text in Column B to the values in Column C an D for each row. 

    Also note the units. Because Workbench parameters (with the exception of Design Modeler parameters) are unit sensitive, you can specify the units in those columns and use them to do unit conversion as needed. In this example only the units on the Pressure are implemented to show how this is done.

    There is also a little Drop Down Yes/No choice for the user to decide if they want to save the project file or not when they are done running.

    The button is also different from the ANSYS example.  Instead of being assigned an action by the python script, it executes a very simple Visual Basic routine:

    Private Sub CommandButton1_Click()
       retval = Shell(“C:\Program Files\Ansys Inc\V130\Framework\bin\win64\runwb2 \
               
    -X -R updateWB2.py -F ExcelTower1.wbpj”, vbNormalFocus)
       End Sub

    The line uses the Shell function to execute a system level command in Windows.  The command it runs is the command line way to start Workbench.

    The –X says run interactive and exit when any given command line options are completed. 

    The –R gives a python script to be run, and this is our python script that is presented in detail below. 

    The –F specifies that project file to be executed.  As an aside, you could make this program more general by having a cell in the spreadsheet hold that file name and then substituting that value in the execution string.

    The ANSYS Model

    This extremely complex model can be found in the following archived project file:

    The model contains a DesignModeler solid, a static structural solution, and a modal analysis. The key aspect of the model are the parameters. 

    image

    The outline for the parameter manager looks like this:

    
    

    image

    The various parameters were set up in each system in the normal way, by clicking on the parameter box next to them for each value you want to supply or return.  The key thing to note here are the Names (P1-P15) for the parameters, because this is what our python script will use to change or retrieve values before and after the model update.

    The Script

    The actual script we are using is shown below.  Comments have been added to describe important steps.  You can download it, without the line numbers, here:

    Please don’t laugh too hard. I ran out of time to convert the code into something more concise using do loops and variables.  The whole thing could be made much more general if you know python better than I do.

       1: # IronPython imports to enable Excel interop,

       2: import clr

       3: clr.AddReference("Microsoft.Office.Interop.Excel")

       4: import Microsoft.Office.Interop.Excel as Excel

       5: from System.Runtime.InteropServices import Marshal

       6:  

       7: # import system things needed below

       8: from System.IO import Directory, Path

       9: from System import DateTime

      10:  

      11: # use the ANSYS function GetProjectDirectory to figure out what directory you are in

      12: # and set that to the current directory

      13: projDir = GetProjectDirectory()

      14: Directory.SetCurrentDirectory(projDir)

      15:  

      16: # Open up a log file to put useful information in

      17: logFile = open("TowerTool.log","w")

      18:  

      19: # Put a header in the log file

      20: logFile.write("================================================\n")

      21: logFile.write("Tower Tool Run Log File\n")

      22: logFile.write("================================================\n")

      23: logFile.write("Start time: " + DateTime.Now.ToString('yyyy-mm-dd hh:mm:ss') + "\n")

      24: logFile.write("Proj Dir: %s\n\n" % projDir)

      25:  

      26:  

      27: # Use the Excel GetActiveObject funtion to get the object for the excel session

      28: ex = Marshal.GetActiveObject("Excel.Application")

      29: # Make Excel visible

      30: ex.Visible = True

      31: # Define the active workbook and worksheet

      32: wb = ex.ActiveWorkbook

      33: ws = wb.ActiveSheet

      34:  

      35: # In Excel: Grab values for the cells that we want data from (input cells)

      36: length = ws.Range["Length"](1,1).Value2

      37: width = ws.Range["Width"](1,1).Value2

      38: height = ws.Range["Height"](1,1).Value2

      39: press = ws.Range["Pressure"](1,1).Value2

      40: upress =  ws.Range["Pressure"](1,2).Value2

      41:  

      42: # In Excel: See if the user wants to save the project after the update

      43: saveit = ws.Range["Save_Project"](1,1).Value2

      44:  

      45: # In Workbench: Grab the parameter objects for the input values

      46: lenParam = Parameters.GetParameter(Name="P1")

      47: widParam = Parameters.GetParameter(Name="P2")

      48: hgtParam = Parameters.GetParameter(Name="P3")

      49: prsParam = Parameters.GetParameter(Name="P5")

      50:  

      51: # In Workbench: Get the object for the deflection parameter vlue

      52: defParam = Parameters.GetParameter(Name="P4")

      53:  

      54: #In Workbench: Set the value of the input parameters in Workbench using the values 

      55: #   we got from Excel

      56: lenParam.Expression = length.ToString()

      57: widParam.Expression = width.ToString()

      58: hgtParam.Expression = height.ToString()

      59: prsParam.Expression = press.ToString() + " [" + upress + "]"

      60:  

      61: # Set the output values to "Calculating..." since they no longer match the input values

      62: ws.Range["Max_Bending_Distance"](1,1).Value2 = "Calculating..."

      63: ws.Range["Mode_1"](1,1).Value2 = "Calculating..."

      64: ws.Range["Mode_2"](1,1).Value2 = "Calculating..."

      65: ws.Range["Mode_3"](1,1).Value2 = "Calculating..."

      66: ws.Range["Mode_4"](1,1).Value2 = "Calculating..."

      67: ws.Range["Mode_5"](1,1).Value2 = "Calculating..."

      68: ws.Range["Mode_6"](1,1).Value2 = "Calculating..."

      69: ws.Range["Mode_7"](1,1).Value2 = "Calculating..."

      70: ws.Range["Mode_8"](1,1).Value2 = "Calculating..."

      71: ws.Range["Mode_9"](1,1).Value2 = "Calculating..."

      72: ws.Range["Mode_10"](1,1).Value2 = "Calculating..."

      73:  

      74: # Now let Workbench go to town and update the systems using the new parameter values

      75: logFile.write("Updating Project\n")

      76: Update()

      77:  

      78: # If asked for, save the project

      79:  

      80: if saveit == "Yes": 

      81:     logFile.write("Saving Project\n")

      82:     Save()

      83:  

      84: # Assign the value of the Excel deflection cell output deflection from Workbench 

      85: ws.Range["Max_Bending_Distance"](1,1).Value2 = defParam.Value.Value

      86:  

      87: # Now go through the value of each natural frequency in Workbench and 

      88: #   set the corresponding cell in Excel

      89: #    This could be made more general or at least more concise by using a do loop

      90: #    Also note that instead of getting the objects, then the values the two steps are 

      91: #    combined for these values

      92: ws.Range["Mode_1"](1,1).Value2 = Parameters.GetParameter(Name="P6").Value.Value

      93: ws.Range["Mode_2"](1,1).Value2 = Parameters.GetParameter(Name="P7").Value.Value

      94: ws.Range["Mode_3"](1,1).Value2 = Parameters.GetParameter(Name="P8").Value.Value

      95: ws.Range["Mode_4"](1,1).Value2 = Parameters.GetParameter(Name="P9").Value.Value

      96: ws.Range["Mode_5"](1,1).Value2 = Parameters.GetParameter(Name="P10").Value.Value

      97: ws.Range["Mode_6"](1,1).Value2 = Parameters.GetParameter(Name="P11").Value.Value

      98: ws.Range["Mode_7"](1,1).Value2 = Parameters.GetParameter(Name="P12").Value.Value

      99: ws.Range["Mode_8"](1,1).Value2 = Parameters.GetParameter(Name="P13").Value.Value

     100: ws.Range["Mode_9"](1,1).Value2 = Parameters.GetParameter(Name="P14").Value.Value

     101: ws.Range["Mode_10"](1,1).Value2 = Parameters.GetParameter(Name="P15").Value.Value

     102:  

     103: # Done!  Close the log file and move on 

     104: logFile.write("End time: " + DateTime.Now.ToString('yyyy-mm-dd hh:mm:ss') + "\n")

     105: logFile.close()

    Execution

    Execution is pretty simple.  When the user pushes  the Update system button the program goes off and launches Workbench with the script as input.  The script changes the parameters, updates the model, saves if asked for, updates the values in the spreadsheet, then Workbench exits.

    One key thing to know is the issue with working directories.  The Excel file needs to be in the same directory as the script and the project.  Sometimes Excel changes the working directory (say you opened a different spreadsheet).  If you get an error on execution that Workbench can’t find the project file, you just need to go back to Excel and do a Save As in of your file on top of itself.  That fixes the problem. More advanced users can use VBA to control directories.

    Resources

    The first resource for doing this type of work is the ANSYS Workbench->Scripting Guide in the online help. 

    ANSYS uses a flavor of python called IronPython. They have a great web site at:

     www.ironpython.info

    Specific info on the connection to Excel can be found at: http://www.ironpython.info/index.php/Interacting_with_Excel

    Thoughts and Suggestions

    Both examples presented are pretty simple, but they have the core of what you need to drive Workbench from Excel. It really is not that hard to do and can provide a nice interface for users who don’t know Workbench. 

    Some areas for improvement and suggestions for a real application are:

    • Use jScript in Workbench to add a button that runs a script that attaches to an open Excel file and update based on the current values in that Excel file. So instead of running Workbench in batch from Excel, pressing the button would update everything.  That seems to be a more effective way to do it. (maybe a quick article in the future if Matt help me figure out how to add a button quickly…)
    • Do more with VBA or Python in the Excel file to make you Excel based tool more sophisticated. 
    • There is no error checking in this example… very bad.  For a real world tool a lot more code should be added to check things and to capture errors from various functions.
    • As one can imagine, this can be extended to other programs.  A good example would be an optimization tool or another “calculating” tool like MathCAD or Matlab. 

    Dust In the Wind: Stress and Strain Results in Workbench Mechanical vs. Mechanical APDL

    Twice in the last week we’ve taken tech support calls in which the users questioned why their stress or strain results were being reported differently in Workbench Mechanical vs. the results from the same results file in /POST1 with ANSYS Mechanical APDL.  After answering those questions it was pretty obvious that a Focus blog entry was in order.  All we needed was a good, relevant example to demonstrate the issues and the explanation.

    dust5crop

    First glimpse of approaching dust storm.   All photos by the author.

    In case you missed it, the big story here in the Phoenix area this week was our monster haboob, or dust storm.  If you’re not familiar with the term haboob, Wikipedia explains it here:  http://en.wikipedia.org/wiki/Haboob.  In order to have a humongous dust storm, you’ve got to have wind. 

    dust_combin
    Stopped in a parking lot to take these pictures – the only camera I had was my phone.

     

    dust4

    About 3 minutes after this picture was taken the dust storm arrived.

    Wind tends to cause damage, but although our recent dust storm is estimated to have been 100 miles wide and up to 10,000 ft. high, we fortunately did not sustain much significant wind damage.  Things that do tend to get mangled, however, are deployed patio umbrellas and portable expanding sunshades.  These sunshades typically retract into a compact size and fit in a zip up carrying case.  Many of us have collections of damaged sun shades that still work via creative application of duct tape, wire, etc.  These inexpensive shades work great for keeping the sun off of us during birthday parties or other outdoor gatherings, but high winds tend to cause the metal members to bend and break, causing the shades to need some field engineering repair if not just a one way trip to the dumpster.

    Here is a solid geometry representation of a typical portion of the frame of a representative shade.  It consists of two rectangular hollow members, pinned to each other at the center, with pins at each end that in the full structure would be attached to additional components.

    image

    For simplicity, we fixed the pins on the right side to ground, while those on the left side have an upward bearing load applied to the upper pin and a downward bearing load applied to the lower pin.  These loads tend to cause the members to bend at the central pin.  The bearing loads in our example represent the effect of a strong gust of wind hitting the fabric canopy above the frame, with the load eventually reacting through the frame to stakes that attach the frame to the ground at the bottom.   The main thing to note here is that the applied load is large enough to cause significant plastic deformation, not unlike what one might experience in the real world when one of these structures is subjected to a very strong wind.

    image

    Workbench Mechanical, Coarse Mesh, Peak von Mises Stress is 79,219 psi

     

     

    image

    Same Results File in Mechanical APDL /POST1, Peak von Mises Stress is 83,873 psi

    The issue here is that for our initial run with a very coarse mesh, when we view the von Mises stress results in the Mechanical editor and then compare them with the von Mises stress results obtained from the same results file in /POST1 in Mechanical APDL, we notice there is a difference (79.2 ksi vs. 83.9 ksi).  Why is that?  It has to do with how stresses are calculated.  First let’s consider Mechanical APDL and /POST1.  The original graphics display system is known as Full graphics.  Fifteen or twenty years ago ANSYS, Inc. developed a newer graphics display system for MAPDL known as Powergraphics.  There are several differences between these two display systems which affect results quantities. 

    ANSYS Mechanical APDL uses PowerGraphics by default, which among other things only looks at results on the exterior surfaces of the model.  Full Graphics, on the other hand, includes interior elements in addition to the exterior surfaces when displaying results plots.  Another difference is that with Powergraphics we can vary the number of element facets displayed per element edge with the /efacet command.  The default is one facet per edge but for midside-noded elements we can increase that to two or four.  With Full Graphics we are stuck with one facet per element edge.  Workbench Mechanical uses an algorithm whose results tend to compare more favorably with full graphics, although it apparently displays with 2 facets per element edge.   Another option in MAPDL is to plot nodal (averaged) vs. element (unaveraged) stresses. 

    So, which of all these methods is the correct one?  I would consider them all to be correct, just different.  However, we can use the difference in results as guideline for our mesh density (as well as the presence of singularities). If there is a significant difference between PowerGraphics and Full Graphics results in MAPDL, this usually indicates the mesh is too coarse, at least in our region of interest.  As the mesh is refined, the difference between the two calculations should decrease.  In Workbench Mechanical 13.0, we can plot averaged and unaveraged stress and strain result plots.  The choice is made in the details view for a given plot.  A significant difference between these two quantities also indicates that mesh refinement is needed.  In our shade frame model, we can see that as the mesh is refined, the difference in von Mises stress results decreases, as shown in the table below.

    image

     

    A similar effect is seen with the von Mises plastic strain results:

    image

    Regarding the mesh densities used, the coarse mesh had an element size of at least 0.05 in. on the member hole at the high stress/strain location,  while the fine mesh had an element size of 0.025 on the same hole.  Another way to look at the mesh refinement is that the coarse model had 20 elements on the hole of interest while the fine mesh had 104 elements on the same hole.  Clearly the coarse mesh in this example was way too coarse for engineering purposes, but this was selected for this article to ensure the effect of different results calculation methods was significant and observable.

    So, the bottom line here is that if you see unacceptable differences in stress or strain results using different results calculation methods, it likely means that your mesh, at least in the area of interest, is too coarse.  Try adding mesh refinement and check the results again.  In Mechanical, you can try adding a Convergence item to a scoped result plot to at least partially automate this process.  Just be careful that you don’t include any singularities in your desired convergence region.

    If you were expecting a reference to the Kansas song, “Dust in the Wind,” well, I guess this is it.  Fortunately we don’t seem to have many lingering affects of the big dust storm.  The parking lot here at PADT has a thin layer of dirt that’s gradually disappearing.  Once we get a good rain it will all get washed away.

    Using User Defined Results in ANSYS Mechanical

    I first started contemplating this article several weeks ago, and I was planning on somehow working in a Jersey Shore reference.  But now that I’ve relocated to Colorado and am recovering from a climbing trip that was a bit above my ability, my creative juices are a little low (they were used up trying to improvise my way up an overhanging roof pitch).

    P1130671
    Hmm…I’m noticing there aren’t a lot of foot-holds to get me over there, prussik to the rescue!

    Anyways, User Defined results were first introduced in R12 to grant the user access to element table items. 

    pic1

    When you insert a user-defined result, you are required to fill in the ‘expression’ line in the details window. 

    pic3

    Just like Johnny 5, ANSYS needs input

    You can look up everything that’s available through the documentation, but we all know that no one reads the instructions.
    pic4

    Reading is boring…I’ll wait until the movie comes out, I hear it stars the guy who voiced Johnny 5

    There’s a much easier way to auto-populate the ‘expression’ line…the Worksheet view!  To access this, first click on the ‘Solution’ branch and then select ‘Worksheet’ (tab in R12, button in R12.1 and newer).  This will show you a list of all the user defined result expressions.  Find one you like, right-mouse-click on it and select ‘Create User Defined Result’. 

    pic5

                                                                   That’s more like it

    This will insert a ‘User Defined Result’, the only work you need to do is scope it to a body (if necessary).  The only ‘tricky’ part of this process is that you need to solve the model first before using the Worksheet view.  This is because before the model has been solved, Mechanical doesn’t know what is in the result file.  So if the worksheet view is blank or grayed out, it’s because you haven’t solved the model.

    So what’s the benefit of using the User Defined Results?  Say you wanted to look at total strain, kinetic energy, or reaction force contour plots…just to name a few.  In order to view any of those, you would either have to open the .rst file in MAPDL or use the User Defined Result.

    pic7
    Left = FX, Right = Total Strain
    Here’s a quick description of the ‘headers’ available on the Worksheet tab. 
    U Displacement
    S Stress
    EPTO Total Strain
    EPEL Elastic Strain
    EPPL Plastic Strain
    EPTT Thermal Strain
    ENFO Element Nodal Reaction Forces
    NDIR Nodal Orientation Values
    There are more headers that are listed in the documentation (I know, we all agreed that was boring).  However if you’re looking for items stored in the NMISC or SMISC (for ‘regular’ or contact elements), those are accessible provided you properly format the expression line.
     
    So now let’s go through an example where we actually use this functionality.  A customer called in asking how to calculate the volume of a part above a specified stress level.  Interesting question…
     
    First we create a user defined result and use the ‘VOLUME’ expression.  So we’re half-way there.  Next, we need to understand about how the results are stored for a result item in the ‘Solution’ branch.  Each contour plot is actually a vector in the form of element/node vs result.  You can see this for yourself by right-mouse-clicking on the item in the tree and selecting ‘export’.  So right now we have a vector defined of element vs volume.  Now we just need another listing of element vs stress. 
     
    When you create a stress result in Mechanical, the default behavior is to show the nodal-stress, which represent the average of the adjacent elements.  That’s not what we want.  If we look into the ‘Integration Point Results’ we see there are more options.  Element mean seems like it might work for us, but when we export it, we see that it’s still reporting stresses at the node, only now it’s using a different integration scheme.
    pic9 pic10
    Averaged Elemental Mean

    In order to access the average stress value of the element (not node), we need to use the User Defined Results.  We’ll ask to evaluate the expression seqv (von Mises) and set the integration option of using the elemental mean.

    pic11

    Now when we export that result item we get what we want…element vs stress:

    pic12

    Now we just need to export both vectors (volume and stress), then copy/paste/sort/sum and you’re done.  Don’t forget the most important step…billing for 4 hours of post-processing work.

    Long story short, all you MAPDL users who have been complaining about not being able to access element tables should take a look at the User Defined functions. 

    How To update ANSYS Release 13.0 to ANSYS Release 13.0 SP2 for 64-bit Linux

    Pre-Install Tasks

    · ANSYS Release 13.0 must already be installed on your machine

    · Time needed to complete update: 15-30 minutes

    Begin ANSYS 13.0 SP2 update procedure

    1. Login and download the appropriate Linux version update from the ANSYS Customer Portal.

    2. Save ANSYS130SP2_LINX54.tar to your install Desktop

    3. Extract the files root Desktop

    4. Open a Terminal window session and change directory to your Desktop then to the extracted folder on the desktop. In my example the folder is Save ANSYS130SP2_LINX54.tar_FILES

    5. After you have verified that you are in this folder type. ./INSTALL

    image

    7. Review the ANSYS Software License agreement and click I AGREE to continue.

    image

    8. Verify your installation directory and click Next.

    You must install into the ANSYS RELASE 13.0 SP2 into the same location as your original ANSYS RELEASE 13.0 location.

    image

    9. Select the components you would like to install. The installation GUI will by default have checked installed selected.

    You can choose to install fewer products to update but you would not be able to select products to add with the update package. You would need to install from the main ANSYS RELASE 13.0 media and then install the SP2 on top of that installation.

    image

    Please note the amount of disk space required for the update. Approximately 7.2 GB. You will need to make sure that your Linux machine has at least 7.3GB free and available.


    10. Verification screens – Dates

    image

    11. Installation screens – Various screens will scroll through as the installation manager extracts the package files. Screen shot of Extraction: Package 4 of 16

    image

    12. Installation screens – Various screens will scroll through as the installation manager extracts the package files. Screen shot of Extraction: Package 5 of 16

    image

    13. Installation screens – Various screens will scroll through as the installation manager extracts the package files. Screen shot of Extraction: Package 14 of 16

    image

    14. Completed update – Click Next to begin the ANSYS 13.0 Licensing Client Installation update

    image

    15. ANSYS 13.0 Licensing Client Installation – Begin verification

    image

    16. ANSYS 13.0 Licensing Client Installation – Configuration log and successful completion of ANSYS 13.0 Licensing Client update.

    image

    17. Click Finsh to end update installation script routine.

    As indicated in the note on the IMPORTANT note below. Please run the update for the ANSYS, Inc. License Manager SP2 update after completing this procedure. This download is also available through the ANSYS Customer Portal

    image

    Parallel Performance: ANSYS FLUENT R13 with Service Pack 2

    Recently, PADT has conducted some parallel benchmarks with our Linux cluster.  The model used for the tests is an ANSYS FLUENT *.cas file with 26.5 million cells and 6.5 million nodes.  The physics in this model are fairly simple; it is modeling external, steady airflow over an object.  Simulations of 10 iterations were conducted using as many as 144 processors over three 48-core systems (the machine names are “cs0”, “cs1”, and “cube48”, and are summarized in Table 1).  The first two machines in Table 1 (cs0 and cs1) are connected together via Infiniband, so they effectively form a 96-core machine.  Furthremore, the cs0 and cs1 machines are connected to cube48 via GigE network ports.  Each of the machines has two GigE network ports each which connect to a Gigabit switch to allow for trunking.

    Table 1 – Benchmark machine specifications

    Machine

    Processor Type

    Processor Count

    cs0

    2.3 GHz AMD Opteron 6176SE

    48

    cs1

    2.3 GHz AMD Opteron 6176SE

    48

    cube48

    2.2 GHz AMD Opteron 6176SE

    48
     
    Two versions of FLUENT were tested; the original version 13 (R13), and the new Service Pack 2 for version 13 (R13 SP2).  The results were scaled according to the one-processor solve time to compute the “speedup” (defined as the solve time on 1 processor divided by the solve time on “N” processors), and are presented in Figure 1 with a comparison to “Linear” or ideal speedup (ideal speedup implies that the speedup value is equal to the number of processors for a given processor count).

    image

    Figure 1 – Speedup vs. Processors with 6.5 million node ANSYS FLUENT model

    The first result in Figure 1 (blue curve) was obtained using as many as 48 processors on the cs0 machine before installing the Service Pack 2 for FLUENT version 13.  As illustrated in Figure 1, the speedup values of the blue result decrease as the number of processors increases.  The next result (green curve with triangles) was calculated using Service Pack 2 for ANSYS FLUENT version 13 on the cube48 machine using as many as 48 processors.  This result on cube48 presents perfect correspondence with Linear speedup, and even displays some values which are “super-linear”.  This behavior led us to suspect that the improvements in Service Pack 2 for ANSYS FLUENT version 13 were the primary cause of the increase in performance demonstrated by the cube48 speedup result.

    However, further testing of the cs0 and cs1 machine with Service Pack 2 for ANSYS FLUENT seems to suggest otherwise.  These data are represented by the red squares in Figure 1.  Runs were conducted on as many as 144 processors, which involved a distributed run using 48 processors on cs0, 48 processors on cs1, and 48 processors on cube48.  The general trend of this result is the same as that recorded on cs0 before installing Service Pack 2 for ANSYS FLUENT version 13, suggesting that some other effect (likely machine-related) is present.   Our current hypothesis is that the socket 2 processor (which handles the Infiniband UIO card hardware) is causing the slowdown, primarily because the Infiniband switch is present only on the cs0 + cs1  machine, and not on the cube48 machine.  This was suggested by the manufacturer of Infiniband switch (SuperMicro).  Testing to asses this problem is on-going.

    Retrieving Accurate PSD Reaction Forces in ANSYS Mechanical

    We just finished up a tech support call for a customer that wanted a way to get accurate reaction loads from a PSD run in ANSYS Mechanical. Alex Grishin took the call and provided a nice example to the customer, so we thought we would leverage that and share it with all of you.  Even if you are not in need of this particular function, it is a great example of using snippets.  If you are not familiar with this, check out our recent webinar on the subject.

    The reason why you have to do this is because doing an accurate PSD force calculation is not a simple thing.  The math is a bit complicated, because PSD responses are probabilities of results that loose sign.  And it is right now only available in Mechanical APDL (MAPDL).  This is not a problem because we can use an APDL command object to get the results from MAPDL and bring them back to ANSYS Mechanical.

    Three Simple Steps

    There are three very simple steps needed to get this done:

    1. Identify the geometry you want the reaction loads calculated on
      Do this by selecting a face, edge, or corner and create a named component.  You will use that named component to grab the nodes that sit on the piece of geometry and do an FSUM in MAPDL. In our example, we call the named selection react_area1.
    2. Tell the solver to store the required modal information
      Since ANSYS Mechanical doesn’t do reaction force calculations they save disk space by not storing the info needed for such calculations, but we need them.  So add a command object in your modal analysis environment that says save all my results (outres) and expand all my modes (mxpand):
          outres,all,all
          mxpand,,,,yes,,yes
    3. Calculate the reaction force
      Now we simply need to add a command object to the post processing branch that:
      • gets the PSD deflection results (set,3)
      • selects the named selection (cmsel),which is a nodal component in MAPDL,
      • gets the nodes attached (esln)
      • calculates the reaction load (fsum)
      • stores the results in parameters that we return to ANSYS Mechanical. (*get,my_).  Remember that anytime you create a MAPDL parameter in the post processor that starts with my_ it gets returned to ANSYS Mechanical. (well, that is the default, you can change the prefix)
      • select everything so that MAPDL can keep post processing like normal

      For our example, it looks like this:
         /post1
         set,3,1
         cmsel,s,react_area1
         esln
         fsum
         *get,my_fsumx,fsum,0,item,fx
         *get,my_fsumy,fsum,0,item,fy
         *get,my_fsumz,fsum,0,item,fz
         allsel

    The following figure shows the model tree for our example, and the returned parameters:

    image

    Nothing fancy, simple in fact: Make a component, store the required info in the result files, do an FSUM and bring back the results.

    You can download the example here.


    hat_beach1hat3imageimage

    That was a short article!  And no exciting pictures.  So… if you want to you could check out the travels of The PADT Hat around the world. 

    How to Get a Cool Grip on Your Data Center Cooling in Three Easy Steps!

    CUBE 96 Mini-ClusterOver the years I have learned to do more with less. When it comes to information systems world, you all know the equation is often much more with much less. One of my to-do’s over the years, umm that continued to get bumped down on the priorities list. It is the juggling act of making sure that the data center has enough cooling vs. power vs. yes again in AZ cooling. If you are an IT professional or even an Engineer you really don’t have time to attempt to try to convince someone, anyone that we need to speed more money. Even if you use the effective philosophy of Time, Money and Quality. After dealing recently “wish ware software vendors this past year” I added a fourth dimension to the above philosophy. It’s called Functionality; here is what Merriam Webster had to say about Functionality. The quality or state of being functional; especially: the set of functions or capabilities associated with computer software or hardware or an electronic device. http://www.merriam-webster.com/dictionary/functionality?show=0&t=1307146105

    1. Time – Try searching the internet for terms such as data center cooling calculator, data center cooling costs or how can I save money with our data center cooling? You will suddenly have millions of search queries at your beckon. From video blogs on data center cooling, white papers on optimizing IT strategy on data center cooling. It is endless 3 million plus hits on just one search term data center cooling calculator. Wow, Start researching my young padawon learner, fill out those lead generating white papers. Keep it simple…
    2. Money – I would prefer that we used or dollars on buying a server with a couple INTEL XEON ET-8870 processor. Or how about a QUAD based AMD FX-8130P processor server! I do not have any budget for a I am sure fabulous data center cost benefit crisis analysis.
    3. Quality – Can I even understand what the end-result document white paper will read. Will I look like even more of an idiot? This needs to be accurate information. I will have to do it myself or use a third party data center analysis.
    4. Functionality – Will our current air conditioners hold up this year? What about when we hit 120 degrees? Oh my do I need to add more cooling power?

    Wikipedia on British Thermal Unit (BTU) – http://en.wikipedia.org/wiki/British_thermal_unit

    So why I care about a BTU? Because approximately one "ton of cooling", which is a typical way people talk about cooling devices in the USA, is 12,000 BTU/h. This is the amount of power needed to melt one short ton of ice in 24 hours. Locked away in a climate controlled vault is one of my data centers. “Said such vault may or may not contain the following items on any given day.” After all this is a mobile compute server world these days.

    • 13 Servers
    • 174 Cores (Mix of Windows/Linux servers)
    • 2 – Network Routers
    • 3 – Network Switches
    • Phone System
    • Voice Mail System
    • 1 LCD 20” monitor/KVM

    Go Green in the Data Center! First, let’s get a “Cool Grip” on your data center…16,484.058 BTU/h

    A couple years ago one of the our ANSYS Mechanical Simulation Engineers named Jason Krantz told me about a watt meter device. A handy little watt meter monitoring device designed by P3 International KILL A WATT™. Over the years that little watt meter devices has become one of closest friends and ally in IT. Today, I was able to quickly asses (realistically about four hours of time) just how many Watts of power each one of our servers, network devices, etc. used. I tried to be as accurate as I could without having to take out a second mortgage. So I made sure and verified that one of our PHD FE Analyst or CFD Analysts had our servers at our near 100% CPU use.

    YOUTUBE VIDEO :: Check out this real-world example of a AMD Opteron 6174, 287 hour electrical cost usage test. The data shown in this video is of a server that has four AMD Opteron 6174 processors installed.

    AMD Opteron 6174 Electrical Cost Usage

    So, what is your magical number? Ours is 4,831 Watts

    Do you know how many watts of power your server room is using? could you even logically guess what that number is? Our magical number for server room #1 turned out to be 4,831 Watts. I do need to state that I was unable to take some of the devices offline. When that was the case I used data pulled from the actual technical documents of the device’s manufacture website.

    So what is your BTU/h number? Ours is 16,484.058 BTU/h? Oh and I don’t even like math? I know, I know, math was solved and perfected centuries ago. But how do I convert Watts into BTU?

    I used a 99 cent app that I bought off of the iTunes App store called “Convert Units”.

    • Step 1 – Convert Watts into BTU/m
    • Step 2 – Then multiplied by 60 to get that value into BTU/h.
    • Step 3 – Speak to your Operations Department, send an email, shout from the rooftops!! We need at least a two ton Air Conditioning unit for Server Room #1

    Now with the precious BTU/h value in hand. I was able to speak the same language as that of our Director of Operations & Facilities manager.

    I wish you all could have been there when I walked up to Scott and told him the news. The dialogue went something like this:

    “Scott I wanted to talk to you about server room #1’s cooling situation…(pause for dramatic expression). Almost immediately you could see Scott’s blood pressure rising. Scott’s brain quickly churning through mountains of Air Conditioning cooling information and data. I quickly calmed his anxiety and said these exact words. “Server Room #1’s BTU/h ratio is approximately 16,484.058 BTU/h.” It took Scott just a moment for this bit of information to register. I do believe that I actually heard the hallelujah chorus in the heavens. I could also see the peace that passes all understanding come across Scott’s face. It was if I could read his mind and he was thinking how is this non-operation/facilities type humanoid speaking my language? For Scott knew immediately that he had enough cooling power at this moment into to cool that data center down all summer long.

    DATA CENTER #1 – 274.7343 BTU/m*60 = 16,484.058 BTU/h

    How the heck are you making money today? Step out of the Box, Step Into a Cube Computers for CFD and FEA Simulation. http://www.cube-hvpc.com/