# 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:

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:

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.

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):

## 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:

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 Example

(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.

# A 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 made 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.

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

• 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)