This post is a table of contents to a series about ANSYS SpaceClaim. After over 31 years of CAD use, it has become difficult for me to learn new tools. In this series I will share my experience as I explore and learn how to use this fantastic tool.
Thirty-one. That is the number of years that I have been using CAD software. CADAM was the tool, 1985 was the year. As some of our engineers like to point out, they were not even born then.
Twenty-one. that is the number of years that I have been using SolidEdge. This classifies me as an old dog, a very old dog. As PADT has grown the amount of CAD I do has gone way down, but every once in a while I need to get in there and make some geometry happen. I’m usually in a hurry so I just pop in to SolidEdge and without really thinking, I get things done.
Then ANSYS, Inc. had to go and buy SpaceClaim. It rocks. It is not just another solid modeler, it is a better way to create, repair, and modify CAD. I watch our engineers and customers do some amazing things with it. I’m still faster in SolidEdge because I have more years of practice than they have been adults. But this voice in my head has been whispering “think how fast you would be in SpaceClaim if you took the time to learn it.” Then that other voice (I have several) would say “you’re too old to learn something new, stick with what you know. You might break your hip”
I had used SpaceClaim a bit when they created a version that worked with ANSYS Mechanical four or five years ago, but nothing serious. Last month I attended some webinars on R17 and saw how great the tool is, and had to accept that it was time. That other voice be damned – this old dog needs to get comfortable and learn this tool. And while I’m at it, it seemed like a good idea to bring some others along with me.
These posts will be a tutorial for others who want to learn SpaceClaim. Unlike those older tools, it does not require five days of structured training with workshops. The program comes with teaching material and tutorials. The goal is to guide the reader through the process, pointing out things I learned along the way, as I learn them.
A link to the table of contents is here.
The product I’m learning is ANSYS SpaceClaim Direct Modeler, a version of SpaceClaim that is built into the ANSYS simulation product suite. There is a stand alone SpaceClaim product but since most of our readers are ANSYS users, I’m going to stick with this version of the tool.
This is what you see when you start it up:
I’ve been using the same basic layout for 20 years, so this is a bit daunting for me. I like to start on a new program by getting to know what different areas of the user interface do. The “Welcome to ANSYS SCDM” kind of anticipates that and gives me some options.
Under “Getting Started” you will see a Quick Reference Card, Introduction, and Tutorials. Open up the Quick Reference and print it out. Don’t bother with it right now, but it will come in handy, especially if you are not going to use SpaceClaim every day.
The Introduction button is a video that gets you oriented with the GUI. Just what we need. It is a lot of information presented fast, so you are not going to learn everything the first viewing, but it will get you familiar with things.
Here I am watching the video. Notice how attentive I am.
Once that is done you should sort of know the basic lay of the land. Kind of like walking into a room and looking around. You know where the couch is, the window, and the shelf on one wall. Now it is time to explore the room.
It is kind of old school, but I like user guides. You can open the SpaceClaim User Guide from the Help line in the “Welcome” window. I leave it open and use it as a reference.
The best place to learn where things are in the interface is to look at the interface section in the manual. It has this great graphic:
The top bit is pretty standard, MS office like. You have your application menu, quick access toolbar, and Ribbon Bar. The Ribbon Bar is where all the operations sit. We used to call these commands but in an object oriented world, they are more properly referred to as operations – do something to objects, operate on them. I’ll come back and explore those later. Over on the left there are panels, the thing we need to explore first because they are a view into our model just like the graphics window.
The Structure Panel is key. This is where your model is shown in tree form, just like in most ANSYS products. In SpaceClaim your model is collection of objects, and they are shown in the tree in the order you added them. You can turn visibility on and off, select objects, and act on objects (using the right mouse button) using the tree. At this point I just had one solid, so pretty boring. I’m sure it will do more later.
Take a look at the bottom of the Structure Panel and you will find some tabs. These give access to Layers, Selection, Groups, and Views. All handy ways to organize and interact with your model. I felt like I needed to come back to these later when I had something to interact with.
TIP: If you are like me, you probably tried to drag these panels around and hosed up your interface. Go to File > SpaceClaim Options (button at the bottom) > Appearance and click the “Reset Docking Layout” button in the upper right of the window. Back to normal.
The options panel changes dynamically as you choose things from the ribbon. If you click on the Design > Line you get this:
And if you click on Pull you get this:
Keeps the clutter down and makes the commands much more capable.
Below that is the Properties Panel. If the Options panel is how you control an operation, then the Properties panel is how you view and control an object in your model. No point in exploring that till we have objects to play with. It does have an appearance tab as well, and this controls your graphics window.
At the bottom is the Status Bar. Now I’m a big believer in status bars, and SpaceClaim uses theirs well. It tells you what is going on and/or what to do next. It also has info on what you have selected and short cut icons for selection and graphics tools. Force yourself to read and use the status bar, big time saver.
The last area of the interface is the graphics window. It of course shows you your geometry, your model. In addition there are floating tools that show up in the graphics window based upon what you are doing. Grrr. #olddogproblem_1. I’m not a fan of these, cluttering up my graphics. But almost all modern interfaces work this way now and I will have to overcome my anger and learn to deal.
For most of the 30+ years that I’ve been doing this CAD thing, I’ve always started with the same object: A block with a hole in it. So that is what we will do next. I have to admit I’m a little nervous.
I’m nervous because I’m a history based guy. If you have used most CAD tools like SolidWorks or ANSYS DesignModeler you know what history based modeling is like. You make a sketch then you add or subtract material and it keeps track of your operations. SpaceClaim is not history based. You operate on objects and it doesn’t track the steps, it just modifies your objects. SolidEdge has done this for over ten years, but I never got up the nerve to learn how to use it. So here goes, new territory.
Things start the same way. But instead of a sketch you make some curves. The screen looks like this when you start:
The default plane is good enough, so I’ll make my curves on that. Under Design>Sketch click on the Rectangle icon then move your mouse on to the grid. You will notice it snaps to the grid. Click in the Upper Left and the Lower Right to make a rectangle then enter 25mm in to each text box, making a 25 x 25 square:
Next we want to make our block. In most tools you would find an extrude operation. But in SpaceClaim they have combined the huge multitude of operations into a few operation types, and then use context or options to give you the functionality you want. That is why the next thing we want to do is click on Pull on the Edit group.
But first, notice something important. If you look at the model tree you will notice that you have only one object in your design, Curves. When you click Pull it gets out of sketch mode and into 3D mode. It also automatically turns your curves into a surface. Look at the tree again.
This is typical of SpaceClaim and why it can be so efficient. It knows what you need to do and does it for you.
Move you mouse over your newly created surface and notice that it will show arrows. Move around and put it over a line, it shows what object will be selected if you click. Go to the inside of your surface and click. It selects the surface and shows you some options right there.
Drag your mouse over the popup menu and you can see that you can set options like add material, subtract material, turn off merging (it will make a separate solid instead of combining with any existing ones), pull both directions, get a ruler, or specify that you are going to pull up to something. For now, we are just going to take the default and pull up.
As you do this the program tells you how far you are pulling. You can type in a value if you want. I decided to be boring and I put in 25 mm. Geometry has been created, no one has been hurt, and I have not lost feeling in any limbs. Yay.
On the status bar, click on the little menu next to the magnifying glass and choose Zoom Extents. That centers the block. Whew. That makes me feel better.
Now for the hole. It is the same process except simpler than in most tools. Click on the circle tool in Sketch. The grid comes back and you can use that to sketch, or you can just click on the top of the block. Let’s do that. The grid snaps up there. To make the circle click in the middle of the grid and drag it out. Put 10 in for the diameter. A circle is born.
Now choose Pull from the Edit section. There is only a Solid now?
SpaceClaim went ahead and split that top surface into two surfaces. Saving a step again.
Click on the circle surface and drag it up and down. If you go up, it adds a cylinder, if you go down, it automatically subtracts. Go ahead and pull it down and through the block and let go. Done. Standard first part created. Use the File>Save command to save your awesome geometry.
That is it for the getting started part. In the next post we will use this geometry to explore SpaceClaim more, now that we have an object to work on. As you were building this you probably saw lots of options and input and maybe even played with some of it. This is just a first look at the power inside SpaceClaim.
Click here for Post 2 where the Pull command is explored.
In the last post of this series I illustrated how I handled the nested call structure of the procedural interface to ANSYS’ BinLib routines. If you recall, any time you need to extract some information from an ANSYS result file, you have to bracket the function call that extracts the information with a *Begin and *End set of function calls. These two functions setup and tear down internal structures needed by the FORTRAN library. I showed how I used RAII principles in C++ along with a stack data structure to manage this pairing implicitly. However, I have yet to actually read anything truly useful off of the result file! This post centers on the design of a set of C++ iterators that are responsible for actually reading data off of the file. By taking the time to write iterators, we expose the ANSYS RST library to many of the algorithms available within the standard template library (STL), and we also make our own job of writing custom algorithms that consume result file data much easier. So, I think the investment is worthwhile.
If you’ve programmed in C++ within the last 10 years, you’ve undoubtedly been exposed to the standard template library. The design of the library is really rather profound. This image represents the high level design of the library in a pictorial fashion:
On one hand, the library provides a set of generic container objects that provide a robust implementation of many of the classic data structures available within the field of computer science. The collection of containers includes things like arbitrarily sized contiguous arrays (vectors), linked lists, associative arrays, which are implemented as either binary trees or as a hash container, as well as many more. The set of containers alone make the STL quite valuable for most programmers.
On the other hand, the library provides a set of generic algorithms that encompass a whole suite of functionality defined in classic computer science. Sorting, searching, rearranging, merging, etc… are just a handful of the algorithms provided by the library. Furthermore, extreme care has been taken within the implementation of these algorithms such that an average programmer would hard pressed to produce something safer and more efficient on their own.
However, the real gem of the standard library are iterators. Iterators bridge the gap between generic containers on one side and the generic algorithms on the other side. Need to sort a vector of integers, or a double ended queue of strings? If so, you just call the same sort function and pass it a set of iterators. These iterators “know” how to traverse their parent container. (Remember containers are the data structures.)
So, what if we could write a series of iterators to access data from within an ANSYS result file? What would that buy us? Well, depending upon which concepts our iterators model, having them available would open up access to at least some of the STL suite of algorithms. That’s good. Furthermore, having iterators defined would open up the possibility of providing range objects. If we can provide range objects, then all of the sudden range based for loops are possible. These types of loops are more than just syntactic sugar. By encapsulating the bounds of iteration within a range, and by using iterators in general to perform the iteration, the burden of a correct implementation is placed on the iterators themselves. If you spend the time to get the iterator implementation correct, then any loop you write after that using either the iterators or better yet the range object will implicitly be correct from a loop construct standpoint. Range based for loops also make your code cleaner and easier to reason about locally.
Now for the downside… Iterators are kind of hard to write. The price for the flexibility they offer is paid for in the amount of code it takes to write them. Again, though, the idea is that you (or, better yet somebody else) writes these iterators once and then you have them available to use from that point forward.
Because of their flexibility, standard conformant iterators come in a number of different flavors. In fact, they are very much like an ice cream Sunday where you can pick and choose what features to mix in or add on top. This is great, but again it makes implementing them a bit of a chore. Here are some of the design decisions you have to answer when implementing an iterator:
|Decision||Options||Choice for RST Reader Iterators|
|Dereference Data Type||Anything you want||Special structs for each type of iterator.|
|Iteration Category||1. Forward iterator
2. Single pass iterator
3. Bidirectional iterator
4. Random access iterator
|Forward, Single Pass|
Iterators syntactically function much like pointers in C or C++. That is, like a pointer you can increment an iterator with the ++ operator, you can dereference an iterator with the * operator and you can compare two iterators for equality. We will talk more about incrementing and comparisons in a minute, but first let’s focus on dereferencing. One thing we have to decide is what type of data the client of our iterator will receive when they dereference it. My choice is to return a simple C++ structure with data members for each piece of data. For example, when we are iterating over the nodal geometry, the RST file contains the node number, the nodal coordinates and the nodal rotations. To represent this data, I create a structure like this:
I think this is pretty self-explanatory. Likewise, if we are iterating over the element geometry section of an RST file, there is quite a bit of useful information for each element. The structure I use in that case looks like this:
Again, pretty self-explanatory. So, when I’m building a node geometry iterator, I’m going to choose the NodalCoordinateData structure as my dereference type.
The next decision I have to make is what “kind” of iterator I’m going to create. That is, what types of “iteration” will it support? The C++ standard supports a variety of iterator categories. You may be wondering why anyone would ever care about an “iteration category”? Well, the reason is fundamental to the design of the STL. Remember that the primary reason iterators exist is to provide a bridge between generic containers and generic algorithms. However, any one particular algorithm may impose certain requirements on the underlying iterator for the algorithm to function appropriately.
Take the algorithm “sort” for example. There are, in fact, lots of different “sort” algorithms. The most efficient versions of the “sort” algorithm require that an iterator be able to jump around randomly in constant time within the container. If the iterator supports jumping around (a.k.a. random access) then you can use it within the most efficient sort algorithm. However, there are certain kinds of iterators that don’t support jumping around. Take a linked list container as an example. You cannot randomly jump around in a linked list in constant time. To get to item B from item A you have to follow the links, which means you have to jump from link to link to link, where each jump takes some amount of processing time. This means, for example, there is no easy way to cut a linked list exactly in half even if you know how many items in total are in the list. To cut it in half you have to start at the beginning and follow the links until you’ve followed size/2 number of links. At that point you are at the “center” of the list. However, with an array, you simply choose an index equal to size/2 and you automatically get to the center of the array in one step. Many sort algorithms, as an example, obtain their efficiency by effectively chopping the container into two equal pieces and recursively sorting the two pieces. You lose all that efficiency if you have to walk out to the center.
If you look at the “types” of iterators in the table above you will see that they build upon one another. That is, at the lowest level, I have to answer the question, can I just move forward one step? If I can’t even do that, then I’m not an iterator at all. After that, assuming I can move forward one step, can I only go through the range once, or can I go over the range multiple times? If I can only go over the range once, I’m a single pass iterator. Truthfully, the forward iterator concept and the single pass iterator concept form level 1A and 1B of the iterator hierarchy. The next higher level of functionality is a bidirectional iterator. This type of iterator can go forward and backwards one step in constant time. Think of a doubly linked list. With forward and backward links, I can go either direction one step in constant time. Finally, the most flexible iterator is the random access iterator. These are iterators that really are like raw pointers. With a pointer you can perform pointer arithmetic such that you can add an arbitrary offset to a base pointer and end up at some random location in a range. It’s up to you to make sure that you stay within bounds. Certain classes of iterators provide this level of functionality, namely those associated with vectors and deques.
So, the question is what type of iterator should we support? Perusing through the FORTRAN code shipped with ANSYS, there doesn’t appear to be an inherent limitation within the functions themselves that would preclude random access. But, my assumption is that the routines were designed to access the data sequentially. (At least, if I were the author of the functions that is what I would expect clients to do.) So, I don’t know how well they would be tested regarding jumping around. Furthermore, disk controllers and disk subsystems are most likely going to buffer the data as it is read, and they very likely perform best if the data access is sequential. So, even if it is possible to randomly jump around on the result file, I’m not sold on it being a good idea from a performance standpoint. Lastly, I explicitly want to keep all of the data on the disk, and not buffer large chunks of it into RAM within my library. So, I settled on expressing my iterators as single pass, forward iterators. These are fairly restrictive in nature, but I think they will serve the purpose of reading data off of the file quite nicely.
Regarding my choice to not buffer the data, let me pause for a minute and explain why I want to keep the data on the disk. First, in order to buffer the data from disk into RAM you have to read the data off of the disk one time to fill the buffer. So, that process automatically incurs one disk read. Therefore, if you only ever need to iterate over the data once, perhaps to load it into a more specialized data structure, buffering it first into an intermediate RAM storage will actually slow you down, and consume more RAM. The reason for this is that you would first iterate over the data stored on the disk and read it into an intermediate buffer. Then, you would let your client know the data is ready and they would iterate over your internal buffer to access the data. They might as well just read the data off the disk themselves! If the end user really wants to buffer the data, that’s totally fine. They can choose to do that themselves, but they shouldn’t have to pay for it if they don’t need it.
Finally, we are ready to implement the iterators themselves. To do this I rely on a very high quality open source library called Boost. Boost has within it a library called iterator_facade that takes care of supplying most all of the boilerplate code needed to create a conformant iterator. Using it has proven to be a real time saver. To define the actual iterator, you derive your iterator class from iterator_facade and pass it a few template parameters. One is the category defining the type of iterator you are creating. Here is the definition for the nodal geometry iterator:
You can see that there are a few private functions here that actually do all of the work. The function “increment” is responsible for moving the iterator forward one spot. The function “equal” is responsible for determining if two different iterators are in fact equal. And the function “dereference” is used to return the data associated with the current iteration spot. You will also notice that I locally buffer the single piece of data associated with the current location in the iteration space inside the iterator. This is stored in the pData member function. I also locally store the current index. Here are the implementations of the functions just mentioned:
First you can see that testing iterator equality is easy. All we do is just look to see if the two iterators are pointing to the same index. If they are, we define them as equal. (Note, an important nuance of this is that we don’t test to see if their buffered data is equal, just their index. This is important later on.) Likewise, increment is easy to understand as well. We just increase the index by one, and then buffer the new data off of disk into our local storage. Finally, dereference is easy too. All we do here is just return a reference to the local data store that holds this one node’s data. The only real work occurs in the readData() function. Inside that function you will see the actual call to the CResRdNode() function. We pass that function our current index and it populates an array of 6 doubles with data and returns the actual node number. After we have that, we simply parse out of that array of 6 doubles the coordinates and rotations, storing them in our local storage. That’s all there is to it. A little more work, but not bad.
With these handful of operations, the boost iterator_facade class can actually build up a fully conformant iterator will all the proper operator overloads, etc… It just works. Now that we have iterators, we need to provide a “begin” and “end” function just like the standard containers do. These functions should return iterators that point to the beginning of our data set and to one past the end of our data set. You may be thinking to yourself, wait a minute, how to we provide an “end” iterator without reading the whole set of nodes? The reality is, we just need to provide an iterator that “equality tests” to be equal to the end of our iteration space? What does that mean? Well, what it means is that we just need to provide an iterator that, when compared to another iterator which has walked all the way to the end, it passes the “equal” test. Look at the “equal” function above. What do two iterators need to have in common to be considered equal? They need to have the same index. So, the “end” iterator simply has an index equal to one past the end of the iteration space. We know how big our iteration space is because that is one of the pieces of metadata supplied by those ResRd*Begin functions. So, here are our begin/end functions to give us a pair of conformant iterators.
Notice, that the nodes_end() function creates a NodeIterator and passes it an index that is one past the maximum number of nodes that have coordinate data stored on file. You will also notice, that it does not have a second Boolean argument associated with it. I use that second argument to determine if I should immediately read data off of the disk when the iterator is constructed. For the begin iterator, I need to do that. For the end iterator, I don’t actually need to cache any data. In fact, no data for that node is defined on disk. I just need a sentinel iterator that is one past the iteration space.
So, there you have it. Iterators are defined that implicitly walk over the rst file pulling data off as needed and locally buffering one piece of it. These iterators are standard conformant and thus can be used with any STL algorithm that accepts a single pass, read only, forward iterator. They are efficient in time and storage. There is, though, one last thing that would be nice. That is to provide a range object so that we can have our cake and eat it too. That is, so we can write these C++11 range based for loops. Like this:
To do that we need a bit of template magic. Consider this template and type definition:
There is a bit of machinery that is going on here, but the concept is simple. I just want the compiler to stamp out a new type that has a “begin()” and “end()” member function that actually call my “nodes_begin()” and “nodes_end()” functions. That is what this template will do. I can also create a type that will call my “elements_begin()” and “elements_end()” function. Once I have those types, creating range objects suitable for C++11 range based for loops is a snap. You just make a function like this:
This function creates one of these special range types and passes in a pointer to our RST reader. When the compiler then sees this code:
It sees a range object as the return type of the “nodes()” function. That range object is compatible with the semantics of range based for loops, and therefore the compiler happily generates code for this construction.
Now, after all of this work, the client of the RST reader library can open a result file, select something of interest, and start looping over the items in that category; all in three lines of code. There is no need to understand the nuances of the binlib functions. But best of all, there is no appreciable performance hit for this abstraction. At the end of the day, we’re not computationally doing anything more than what a raw use of the binlib functions would perform. But, we’re adding a great deal of type safety, and, in my opinion, readability to the code. But, then again, I’m only slightly partial to C++. Your mileage may vary…
In the last post in this series I illustrated how you can interface C code with FORTRAN code so that it is possible to use the ANSYS, Inc. BinLib routines to read data off of an ANSYS result file within a C or C++ program. If you recall, the routines in BinLib are written in FORTRAN, and my solution was to use the interoperability features of the Intel FORTRAN compiler to create a shim library that sits between my C++ code and the BinLib code. In essence, I replicated all of the functions in the original BinLib library, but gave them a C interface. I call this library CBinLib.
You may remember from the last post that I wanted to add a more C++ friendly interface on top of the CBinLib functions. In particular, I showed this piece of code, and alluded to an explanation of how I made this happen. This post covers the first half of what it takes to make the code below possible.
What you see in the code above is the use of C++11 range based “for loops” to iterate over the nodes and elements stored on the result file. To accomplish this we need to create conformant STL style iterators and ranges that iterate over some space. I’ll describe the creation of those in a subsequent post. In this post, however, we have to tackle a different problem. The solution to the problem is hidden behind the “select” function call shown in the code above. In order to provide some context for the problem, let me first show you the calling sequence for the procedural interface to BinLib. This is how you would use BinLib if you were programming in FORTRAN or if you were directly using the CBinLib library described in the previous post. Here is the recommended calling sequence:
You can see the design pattern clearly in this skeleton code. You start by calling ResRdBegin, which gives you a bunch of useful data about the contents of the file in general. Then, if you want to read geometric data, you need to call ResRdGeomBegin, which gives you a little more useful metadata. After that, if you want to read the nodal coordinate data you call ResRdNodeBegin followed by a loop over nodes calling ResRdNode, which gives you the actual data about individual nodes, and then finally call ResRdNodeEnd. If at that point you are done with reading geometric data, you then call ResRdGeomEnd. And, if you are done with the file you call ResRdEnd.
Now, one thing jumps off the page immediately. It looks like it is important to pair up the *Begin and*End calls. In fact, if you peruse the ResRd.F FORTRAN file included with the ANSYS distribution you will see that in many of the *End functions, they release resources that were allocated and setup in the corresponding *Begin function.
So, if you forget to call the appropriate *End, you might leak resources. And, if you forget to call the appropriate *Begin, things might not be setup properly for you to iterate. Therefore, in either case, if you fail to call the right function, things are going to go badly for you.
This type of design pattern where you “construct” some scaffolding, do some work, and then “destruct” the scaffolding is ripe for abstracting away in a C++ type. In fact, one of the design principles of C++ known as RAII (Resource Acquisition Is Initialization) maps directly to this problem. Imagine that we create a class in which in the constructor of the class we call the corresponding *Begin function. Likewise, in the destructor of the class we call the corresponding *End function. Now, as long as we create an instance of the class before we begin iterating, and then hang onto that instance until we are done iterating, we will properly match up the *Begin, *End calls. All we have to do is create classes for each of these function pairs and then create an instance of that class before we start iterating. As long as that instance is still alive until we are finished iterating, we are good.
Ok, so abstracting the *Begin and *End function pairs away into classes is nice, but how does that actually help us? You would still have to create an instance of the class, hold onto it while you are iterating, and then destroy it when you are done. That sounds like more work than just calling the *Begin, *End directly. Well, at first glance it is, but let’s see if we can use the paradigm more intelligently. For the rest of this article, I’ll refer to these types of classes as BeginEnd classes, though I call them something different in the code.
First, what we really want is to fire and forget with these classes. That is, we want to eliminate the need to manually manage the lifetime of these BeginEnd classes. If I don’t accomplish this, then I’ve failed to reduce the complexity of the *Begin and *End requirements. So, what I would like to do is to create the appropriate BeginEnd class when I’m ready to extract a certain type of data off of the file, and then later on have it magically delete itself (and thus call the appropriate *End function) at the right time. Now, one more complication. You will notice that these *Begin and*End function pairs are nested. That is, I need to call ResRdGeomBegin before I call ResRdNodeBegin. So, not only do I want a solution that allows me to fire and forget, but I want a solution that manages this nesting.
Whenever you see nesting, you should think of a stack data structure. To increase the nesting level, you push an item onto the stack. To decrease the nesting level, you pop and item off of the stack. So, we’re going to maintain a stack of these BeginEnd classes. As an added benefit, when we introduce a container into the design space, we’ve introduced something that will control object lifetime for us. So, this stack is going to serve two functions for us. It’s going to ensure we call the *Begin’s and *End’s in the right nested order, and second, it’s going to maintain the BeginEnd object lifetimes for us implicitly.
To show some code, here is the prototype for my pure virtual class that serves as a base class for all of the BeginEnd classes. (In my code, I call these classes FileSection classes)
You can see that it is an interface class by noting the pure virtual function getLevel. You will also notice that this function returns a ResultFileSectionLevel. This is just an enum over file section types. I like to use an enum as opposed to relying on RTTI. Now, for each BeginEnd pair, I create an appropriate derived class from this base ResultFileSection class. Within the destructor of each of the derived classes I call the appropriate *End function. Finally, here is my stack data structure definition:
You can see that it is just a std::stack holding objects of the type SectionPtrT. A SectionPtrT is a std::unique_ptr for objects convertible to my base section class. This will enable the stack to hold polymorphic data, and the std::unique_ptr will manage the lifetime of the objects appropriately. That is, when we pop and object off of the stack, the std::unique_ptr will make sure to call delete, which will call the destructor. The destructor calls the appropriate *End function as we’ve mentioned before.
At this point, we’ve reduced our problem to managing items on a stack. We’re getting closer to making our lives easier, trust me! Let’s look at a couple of different functions to show how we pull these pieces together. The first function is called reduceToLevelOrBegin(level). See the code below:
The operation of this function is fairly straightforward, yet it serves an integral role in our BeginEnd management infrastructure. What this function does is it iteratively pops items off of our section stack until it either reaches the specified level, or it reaches the topmost ResRdBegin level. Again, through the magic of C++ polymorphism, when an item gets popped off of the stack, eventually its destructor is called and that in turn calls the appropriate *End function. So, what this function accomplishes is it puts us at a known level in the nested section hierarchy and, while doing so, ensures that any necessary *End functions are called appropriately to free resources on the FORTRAN side of things. Notice that all of that happens automatically because of the type system in C++. By popping items off of the stack, I implicitly clean up after myself.
The second function to consider is one of a family of similar functions. We will look at the function that prepares the result file reader to read element geometry data off of the file. Here it is:
You will notice that we start by reducing the nested level to either the “Geometry” level or the “Begin” level. Effectively what this does is unwind any nesting we have done previously. This is the machinery that makes “fire and forget” possible. That is, whenever in ages past that we requested something to be read off of the result file, we would have pushed onto the stack a series of objects to represent the level needed to read the data in question. Now that we wish to read something else, we unwind any previously existing nested Begin calls before doing so. That is, we clean up after ourselves only when we ask to read a different set of data. By waiting until we ask to read some new set of data to unwind the stack, we implicitly allow the lifetime of our BeginEnd classes to live beyond iteration.
At this point we have the stack in a known state; either it is at the Begin level or the Geometry level. So, we simply call the appropriate *Begin functions depending on what level we are at, and push the appropriate type of BeginEnd objects onto the stack to record our traversal for later cleanup. At this point, we are ready to begin iterating. I’ll describe the process of creating iterators in the next post. Clearly, there are lots of different select*** functions within my class. I have chosen to make all of them private and have a single select function that takes an enum descriptor of what to select and some additional information for specifying result data.
One last thing to note with this design. Closing the result file is easy. All that is required is that we simply fully unwind the stack. That will ensure all of the appropriate FORTRAN cleanup code is called in the right order. Here is the close function:
As you can see, cleanup is handled automatically. So, to summarize, we use a stack of polymorphic data to manage the BeginEnd function calls that are necessary in the FORTRAN interface. By doing this we ensure a level of safety in our class design. Also, this moves us one step closer to this code:
In the next post I will show how I created iterators and range objects to enable clean for loops like the ones shown above.
Recently, I’ve encountered the need to read the contents of ANSYS Mechanical result files (e.g. file.rst, file.rth) into a C++ application that I am writing for a client. Obviously, these files are stored in a proprietary binary format owned by ANSYS, Inc. Even if the format were published, it would be daunting to write a parser to handle it. Fortunately, however, ANSYS supplies a series of routines that are stored in a library called BinLib which allow a programmer to access the contents of a result file in a procedural way. That’s great! But, the catch is the routines are written in FORTRAN… I’ve been programming for a long time now, and I’ll be honest, I can’t quite stomach FORTRAN. Yes, the punch card days were before my time, but seriously, doesn’t a compiler have something better to do than gripe about what column I’m typing on… (Editor’s note: Matt does not understand the pure elegance of FORTRAN’s majestic simplicity. Any and all FORTRAN bashing is the personal opinion of Mr. Sutton and in no way reflects the opinion of PADT as a company or its owners. – EM)
So, the problem shifts from how to read an ANSYS result file to how to interface between C/C++ and FORTRAN. It turns out this is more complicated than it really should be, and that is almost exclusively because of the abomination known as CHARACTER(*) arrays. Ah, FORTRAN… You see, if weren’t for the shoddy character of CHARACTER(*) arrays the mapping between the basic data types in FORTRAN and C would be virtually one for one. And thus, the mechanics of function calls could fairly easily be made to be identical between the two languages. If the function call semantics were made identical, then sharing code between the two languages would be quite straightforward. Alas, because a CHARACTER array has a kind of implicit length associated with it, the compiler has to do some kind of magic within any function signature that passes one or more of these arrays. Some compilers hide parameters for the length and then tack them on to the end of the function call. Some stuff the hidden parameters right after the CHARACTER array in the call sequence. Some create a kind of structure that combines the length with the actual data into a special type. And then some compilers do who knows what… The point is, there is no convention among FORTRAN compilers for handling the function call semantics, so there is no clean interoperability between C and FORTRAN.
Fortunately, the Intel FORTRAN compiler has created this markup language for FORTRAN that functions as an interoperability framework that enables FORTRAN to speak C and vice versa. There are some limitations, however, which I won’t go into detail on here. If you are interested you can read about it in the Intel FORTRAN compiler manual. What I want to do is highlight an example of what this looks like and then describe how I used it to solve my problem. First, an example:
What you see in this image is code for the first function you would call if you want to read an ANSYS result file. There are a lot of arguments to this function, but in essence what you do is pass in the file name of the result file you wish to open (Fname), and if everything goes well, this function sends back a whole bunch of data about the contents of the file. Now, this function represents code that I have written, but it is a mirror image of the ANSYS routine stored in the binlib library.
I’ve highlighted some aspects of the code that constitute part of the interoperability markup. First of all, you’ll notice the markup BIND highlighted in red. This markup for the FORTRAN function tells the compiler that I want it to generate code that can be called from C and I want the name of the C function to be “CResRdBegin”. This is the first step towards making this function callable from C. Next, you will see highlighted in blue something that looks like a comment. This however, instructs the compiler to generate a stub in the exports library for this routine if you choose to compile it into a DLL. You won’t get a .lib file when compiling this as a .dll without this attribute. Finally, you see the ISO_C_BINDING and definition of the type of character data we can make interoperable. That is, instead of a CHARACTER(261) data type, we use an array of single CHARACTER(1) data. This more closely matches the layout of C, and allows the FORTRAN compiler to generate compatible code. There is a catch here, though, and that is in the Title parameter. ANSYS, Inc. defines this as an array of CHARACTER(80) data types. Unfortunately, the interoperability stuff from Intel doesn’t support arrays of CHARACTER(*) data types. So, we flatten it here into a single string. More on that in a minute.
You will notice too, that there are markups like (c_int), etc… that the compiler uses to explicitly map the FORTRAN data type to a C data type. This is just so that everything is explicitly called out, and there is no guesswork when it comes to calling the routine. Now, consider this bit of code:
First, I direct your attention to the big red circle. Here you see that all I am doing is collecting up a bunch of arguments and passing them on to the ANSYS, Inc. routine stored in BinLib.lib. You also should notice the naming convention. My FORTRAN function is named CResRdBegin, whereas the ANSYS, Inc. function is named ResRdBegin. I continue this pattern for all of the functions defined in the BinLib library. So, this function is nothing more than a wrapper around the corresponding binlib routine, but it is annotated and constrained to be interoperable with the C programming language. Once I compile this function with the FORTRAN compiler, the resulting code will be callable directly from C.
Now, there are a few more items that have to be straightened up. I direct your attention to the black arrow. Here, what I am doing is converting the passed in array of CHARACTER(1) data into a CHARACTER(*) data type. This is because the ANSYS, Inc. version of this function expects that data type. Also, the ANSYS, Inc. version needs to know the length of the file path string. This is stored in the variable ncFname. You can see that I compute this value using some intrinsics available within the compiler by searching for the C NULL character. (Remember that all C strings are null terminated and the intent is to call this function from C and pass in a C string.)
Finally, after the call to the base function is made, the strings representing the JobName and Title must be converted back to a form compatible with C. For the jobname, that is a fairly straightforward process. The only thing to note is how I append the C_NULL_CHAR to the end of the string so that it is a properly terminated C string.
For the Title variable, I have to do something different. Here I need to take the array of title strings and somehow represent that array as one string. My choice is to delimit each title string with a newline character in the final output string. So, there is a nested loop structure to build up the output string appropriately.
After all of this, we have a C function that we can call directly. Here is a function prototype for this particular function.
So, with this technique in place, it’s just a matter of wrapping the remaining 50 functions in binlib appropriately! Now, I was pleased with my return to the land of C, but I really wanted more. The architecture of the binlib routines is quite easy to follow and very well laid out; however, it is very, very procedural for my tastes. I’m writing my program in C++, so I would really like to hide as much of this procedural stuff as I can. Let’s say I want to read the nodes and elements off of a result file. Wouldn’t it be nice if my loops could look like this:
That is, I just do the following:
- Ask to open a file (First arrow)
- Tell the library I want to read nodal geometric data (Second arrow)
- Loop over all of the nodes on the RST file using C++11 range based for loops
- Repeat for elements
Isn’t that a lot cleaner? What if we could do it without buffering data and have it compile down to something very close to the original FORTRAN code in size and speed? Wouldn’t that be nice? I’ll show you how I approached it in Part 2.
So we have known for a long time that we can parameterize material properties in the Engineering Data screen. That works great if we want to adjust the modulus of a material to account for material irregularities. But what if you want to change the entire material of a part from steel to aluminum? Or if you have 5 different types of aluminum to choose, on several different parts, and you want to run a Design Study to see what combination of materials is the best? Well, then you do this. The process includes some extra bodies, some Named Selections, and a single command snippet.
The first thing to do is to add a small body to your model for each different material that you want to swap in and out, and assign your needed material to them. You’ll have to add the materials to your Engineering Data prior to this. For my example I added three cubes and just put Frictionless supports on three sides of each cube. This assures that they are constrained but not going to cause any stresses from thermal loads if you forget and import a thermal profile for “All Bodies”.
Next, you make a Named Selection for each cube, named Holder1, Holder2, etc. This allows us to later grab the correct material based on the number of the Holder.
You also make a Named selection for each group of bodies for which you want to swap the materials. Name these selections as MatSwap1, MatSwap2, etc.
The command snippet goes in the Environment Branch. (ex. Static Structural, Steady-State Thermal, etc.)
!############################################################################################################################### ! MATSWAP.MAC ! Created by Joe Woodward at PADT,Inc. ! Created on 2/12/2016 ! ! Usage: Create Named Selections, Holder1, Holder2, etc.,for BODIES using the materials that you want to use. ! Create Named Selections called MatSwap1, MatSwap2, etc. for the groups of BODIES for which you want to swap materials. ! Set ARG1 equal to the Holder number that has the material to give to MatSwap1. ! Set ARG2 equal to the Holder number that has the material to give to MatSwap2. ! And so on.... ! A value of 0 will not swap materials for that given group. ! ! Use as is. No Modification to this command snippet is necessary. !############################################################################################################################### /prep7 *CREATE,MATSWAP,MAC *if,arg1,NE,0,then *get,isthere,COMP,holder%arg1%,TYPE *get,swapgood,COMP,matswap%ARG2%,TYPE *if,isthere,eq,2,then esel,s,,,holder%arg1% *get,newmat,elem,ELNEXT(0),ATTR,MAT !swap material for Body 1 *if,swapgood,eq,2,then esel,s,,,matswap%ARG2% emodif,all,mat,newmat *else /COM,The Named Selection - MatSwap%ARG2% is not set to one or more bodies *endif *else /COM,The Named Selection Holder%ARG1% is not set to one or more bodies *endif *endif *END MATSWAP,ARG1,1 !Use material from Holder1 for Swap1 MATSWAP,ARG2,2 !Use material from Holder1 for Swap2 MATSWAP,ARG3,3 !Use material from Holder1 for Swap3 MATSWAP,ARG4,4 !Use material from Holder1 for Swap4 MATSWAP,ARG5,5 !Use material from Holder1 for Swap5 MATSWAP,ARG6,6 !Use material from Holder1 for Swap6 MATSWAP,ARG7,7 !Use material from Holder1 for Swap7 MATSWAP,ARG8,8 !Use material from Holder1 for Swap8 MATSWAP,ARG9,9 !Use material from Holder1 for Swap9 alls /solu
Now, each of the Arguments in the Command Snippet Details corresponds to the ‘MatSwap’ Name Selection of the same number. ARG1 controls the material assignment for all the bodies in the MatSwap1 name selection. The value of the argument is the number of the ‘Holder’ body with the material that you want to use. A value of zero leaves the material assignment alone and does not change the original material assignment for the bodies of that particular ‘MatSwap’ Named Selection. There is no limit on the number of ‘Holder’ bodies and materials that you can use, but there is a limit of nine ‘MatSwap’ groups that you can modify, because there are only nine ARG variables that you can parameterize in the Command Snippet details.
You can see how the deflection changes for the different material combinations. These three steps, holder bodies, Named Selections, and the command snippet above, will give you design study options that were not available before. Hopefully I’ll have an even simpler way in the future. Stay tuned.
The ANSYS 17.0 release improves the impact of driving design with simulation by a factor of 10. This 10x jump is across physics and delivers real step-change enhancements in how simulation is done or the improvements that can be realized in products.
Unless you were disconnected from the simulation world last week you should be aware of the fact that ANSYS, Inc released their latest version of the entire product suite. We wanted to let the initial announcement get out there and spread the word, then come back and talk a little about the details. This blog post is the start of a what should be a long line of discussions on how you can realize 10x impact from your investment in ANSYS tools.
As you may have noticed, the theme for this release is 10x. A 10x improvement in speed, efficiency, capability, and impact. Watch this short video to get an idea of what we are talking about.
Where is the Meat?
We are already seeing this type of improvement here at PADT and with our customers. There is some great stuff in this release that delivers some real game-changing efficiency and/or capability. That is fine and dandy, but how is this 10x achieved. There are a lot of little changes and enhancements, but they can mostly be summed up with the following four things:
Having the best in breed simulation tools is worth a lot, and the ANSYS suite leads in almost every physics. But real power comes when these products can easily work together. At ANSYS 17.0 almost all of the various tools that ANSYS, Inc. has written or acquired can be used together. Multiphysics simulation allows you to remove assumption and approximations and get a more accurate simulation of your products.
And Multiphysics is about more than doing bi-directional simulation, which ANSYS is very good at. It is about being able to transfer loads, properties, and even geometry between different software tools. It is about being able to look at your full design space across multiple physics and getting more accurate answers in less time. You can take heat loads generated in ANSYS HFSS and use them in ANSYS Mechanical or ANSYS FLUENT. You can take the temperatures from ANSYS FLUENT and use them with ANSYS SiWave. And you can run a full bidirectional fluid-solid model with all the bells and whistles and without the hassles of hooking together other packages.
To top it all off, the system level modeler ANSYS Simplorer has been improved and integrated further, allowing for true system level Multiphysics virtual prototyping of your entire system. One of the changes we are most excited about is full support for Modelica models – allowing you to stay in Simplorer to model your entire system.
Speed is always good, and we have come to expect 10%-30% increases in productivity at almost every release. A new feature here, a new module there. This time the developers went a lot further and across the product lines.
The closer integration of ANSYS SpaceClaim really delivers on a 10x or better speedup for geometry creation and cleanup when compared to other methods. We love SpaceClaim here at PADT and have been using it for some time. Version 17 is not only integrated tighter, it also introduces scripting that allows users to take processes they have automated in older and clunker interfaces into this new more powerful tool.
One of our other favorites is the new interface in ANSYS Fluent, just making things faster and easier. More capability in the ANSYS Customization Toolkit (ACT) also allows users to get 10x or better improvements in productivity. And for those who work with electronics, a host of ECAD geometry import tools are making that whole process an order of magnitude faster.
Many of the past releases have been focused on establishing underlying technology, integration, and adding features. This has all paid off and at 17.0 we are starting to see some industry specific workflows that get models done faster and produce more accurate results.
The workflow for semiconductor packaging, the Chip Package System or CPS, is the best example of this. Here is a video showing how power integrity, signal integrity, thermal modeling, and integration across tools:
A similar effort was released in Turbomachinary with improvements to advanced blade row simulation, meshing, and HPC performance.
A large portion of the improvements at 17.0 are made up of relatively small enhancements that add up to so big benefits. The largest development team in simulation has not been sitting around for a year, they have been hard at work adding and improving functionality. We will cover a lot of these in coming posts, but some of our favorites are:
- Improvements to distributed solving in ANSYS Mechanical that show good scaling on dozens of cores
- Enhancements to ACT allowing for greater automation in ANSYS Mechanical
- ACT is now available to automate your CFD processes
- Significant improvements in meshing robustness, accuracy and speed (If you are using that other CFD package because of meshing, its time to look at ANSYS Fluent again)
- Fracture mechanics
- ECAD import in electromagnetic, fluids, and mechanical products.
- A new solver in ANSYS Maxwell that solves more than 10x faster for transient runs
- ANSYS AIM just keeps getting more functions and easier to use
- A pile of SpaceClaim new and improved features that greatly speed up geometry repair and modification
- Improved rigid body dynamics in ANSYS Mechanical
And a ton more. It may take us all of the time we have before ANSYS 18.0 comes out before we have a chance to go over in The Focus all of the great new stuff. But we will be giving a try in the coming weeks and months. ANSYS, Inc. will be hosting some great webinars as well.
If you see something that interests you or something you would like to see that was not there, shoot us an email at email@example.com or call 480.813.4884.
Metal 3D printing involves a combination of complex interacting phenomena at a range of length and time scales. In this blog post, I discuss three of these that lie at the core of the laser fusion of metals: phase changes, residual stresses and solidification structure (see Figure 1). I describe each phenomenon briefly and then why understanding it matters. In future posts I will dive deeper into each one of these areas and review what work is being done to advance our understanding of them.
Phase changes describe the transition from one phase to another, as shown in Figure 2. All phases are present in the process of laser fusion of metals. Metal in powder form (solid) is heated by means of a laser beam with spot sizes on the order of tens of microns. The powder then melts to form a melt pool (liquid) and then solidifies to form a portion of a layer of the final part (solid). During this process, there is visible gas and smoke, some of which ionizes to plasma.
The transition from powder to melt pool to solid part, as shown in Figure 3, is the essence of this process and understanding this is of vital importance. For example, if the laser fluence is too high, defects such as balling or discontinuous welds are possible and for low laser fluence, a full melt may not be obtained and thus lead to voids. Selecting the right laser, material and build parameters is thus essential to optimize the size and depth of the liquid melt pool, which in turn governs the density and structure of the final part. Finally, and this is more true of high power lasers, excessive gas and plasma generation can interfere with the incident laser fluence to reduce its effectiveness.
Residual stresses are stresses that exist in a structure after it reaches equilibrium with its environment. In the laser metal fusion process, residual stresses arise due to two related mechanisms [Mercelis & Kruth, 2006]:
- Thermal Gradient: A steep temperature gradient develops during laser heating, with higher temperatures on the surface driving expansion against the cooler underlying layers and thereby introducing thermal stresses that could lead to plastic deformation.
- Volume Shrinkage: Shrinkage in volume in the laser metal fusion process occurs due to several reasons: shrinkage from a powder to a liquid, shrinkage as the liquid itself cools, shrinkage during phase transition from liquid to solid and final shrinkage as the solid itself cools. These shrinkage events occur to a greater extent at the top layer, and reduce as one goes to lower layers.
After cooling, these two mechanisms together have the effect of creating compressive stresses on the top layers of the part, and tensile stresses on the bottom layers as shown in Figure 4. Since parts are held down by supports, these stresses could have the effect of peeling off supports from the build plate, or breaking off the supports from the part itself as shown in Figure 4. Thus, managing residual stresses is essential to ensuring a built part stays secured on the base plate and also for minimizing the amount of supports needed. A range of strategies are employed to mitigate residual stresses including laser rastering strategies, heated build plates and post-process thermal stress-relieving.
Solidification structure refers to the material structure of the resulting part that arises due to the solidification of the metal from a molten state, as is accomplished in the laser fusion of metals. It is well known that the structure of a metal alloy strongly influences its properties and further, that solidification process history has a strong influence on this structure, as does any post processing such as a thermal exposure. The wide range of materials and processing equipment in the laser metal fusion process makes it challenging to develop a cohesive theory on the nature of structure for these metals, but one approach is to study this on four length scales as shown in Figure 5. As an example, I have summarized the current understanding of each of these structures specifically for Ti-6Al-4V, which is one of the more popular alloys used in metal additive manufacturing. Of greatest interest are the macro-, meso- and microstructure, all of which influence mechanical properties of the final part. Understanding the nature of this structure, and correlating it to measured properties is a key step in certifying these materials and structures for end-use application.
Phase changes, residual stresses and solidification structure are three areas where an understanding of the fundamentals is crucial to solve problems and explore new opportunities that can accelerate the adoption of metal additive manufacturing. Over the past decade, most of this work has been, and continues to be, experimental in nature. However, in the last few years, progress has been made in deriving this understanding through simulation, but significant challenges remain, making this an exciting area of research in additive manufacturing to watch in the coming years.
- Mercelis, P., & Kruth, J. (2006). Residual stresses in selective laser sintering and selective laser melting. Rapid Prototyping Journal, 12(5), 254-265.
- Simonelli, M., Tse, Y.Y., Tuck, C., (2012) Further Understanding of Ti-6Al-4V selective laser melting using texture analysis, SFF Symposium
- King, W. E. and Anderson, A. T. and Ferencz, R. M. and Hodge, N. E. and Kamath, C. and Khairallah, S. A. and Rubenchik, A. M., (2015) Laser powder bed fusion additive manufacturing of metals; physics, computational, and materials challenges, Applied Physics Reviews, 2, 041304
Vibration induced by vortices in off shore oil rigs are a significant area of concern, and understanding them is a major area of research. In this paper, PADT’s Clinton Smith, PhD, and Tyler Smith are joined by Lubeena Rahumathulla from ANSYS, Inc. to describe how they used ANSYS FLUENT to model this situation. Get the paper here: proceedings.asmedigitalcollection.asme.org/proceeding.aspx?articleid=2465497
The design of semi-submersible platforms for offshore oil and gas operations requires an iterative process between early-stage design, numerical simulation, measurements, and full-scale design. Early stage designs are evaluated using numerical simulations, which are typically validated using measurements of a scaled model tested in a wave tank. Full-scale semi-submersibles present a unique challenge, because of the sheer size of the structure. Since VIV measurements of full scale structures are not possible, numerical simulation plays an important role for evaluating vortex-induced vibration (VIV) effects in the appropriate physical regime. The quantification of error in numerical simulation results is limited to verification-type studies, in which the error is reduced by converging the solution on the computational grid. The importance of grid convergence studies in this field cannot be understated, since it is the only way to judge solution accuracy in the absence of measurement data at the full scale. In this paper, a method for a grid convergence study of vortex-induced vibration (VIV) of a model scale semi-submersible platform is presented, in which solutions are obtained using the ANSYS Fluent CFD solver. Five levels of grid refinement are used, with the finest mesh acting as the reference solution for the coarser four levels. Qualitative results of vorticity, pressure and Q-criterion (vortex identification) are presented. Quantitative results such as the nominal amplitude (A/D) of the sway motion are used for judging the convergence of the solution as the grid is refined.
In part 1 of this two-part post, I reviewed the challenges in the constitutive modeling of 3D printed parts using the Fused Deposition Modeling (FDM) process. In this second part, I discuss some of the approaches that may be used to enable analyses of FDM parts even in presence of these challenges. I present them below in increasing order of the detail captured by the model.
- Conservative Value: The simplest method is to represent the material with an isotropic material model using the most conservative value of the 3 directions specified in the material datasheet, such as the one from Stratasys shown below for ULTEM-9085 showing the lower of the two modulii selected. The conservative value can be selected based on the desired risk assessment (e.g. lower modulus if maximum deflection is the key concern). This simplification brings with it a few problems:
- The material property reported is only good for the specific build parameters, stacking and layer thickness used in the creation of the samples used to collect the data
- This gives no insight into build orientation or processing conditions that can be improved and as such has limited value to an anlayst seeking to use simulation to improve part design and performance
- Finally, in terms of failure prediction, the conservative value approach disregards inter-layer effects and defects described in the previous blog post and is not recommended to be used for this reason
- Orthotropic Properties: A significant improvement from an isotropic assumption is to develop a constitutive model with orthotropic properties, which has properties defined in all three directions. Solid mechanicians will recognize the equation below as the compliance matrix representation of the Hooke’s Law for an orthortropic material, with the strain matrix on the left equal to the compliance matrix by the stress matrix on the right. The large compliance matrix in the middle is composed of three elastic modulii (E), Poisson’s ratios (v) and shear modulii (G) that need to be determined experimentally.
Good agreement between numerical and experimental results can be achieved using orthotropic properties when the structures being modeled are simple rectangular structures with uniaxial loading states. In addition to require extensive testing to collect this data set (as shown in this 2007 Master’s thesis), this approach does have a few limitations. Like the isotropic assumption, it is only valid for the specific set of build parameters that were used to manufacture the test samples from which the data was initially obtained. Additionally, since the model has no explicit sense of layers and inter-layer effects, it is unlikely to perform well at stresses leading up to failure, especially for complex loading conditions. This was shown in a 2010 paper that demonstrated these limitations in the analysis of a bracket that itself was built in three different orientations. The authors concluded however that there was good agreement at low loads and deflections for all build directions, and that the margin of error as load increased varied across the three build orientations.
- Laminar Composite Theory: The FDM process results in structures that are very similar to laminar composites, with a stack of plies consisting of individual fibers/filaments laid down next to each other. The only difference is the absence of a matrix binder – in the FDM process, the filaments fuse with neighboring filaments to form a meso-structure. As shown in this 2014 project report, a laminar approach allows one to model different ply raster angles that are not possible with the orthotropic approach. This is exciting because it could expand insight into optimizing raster angles for optimum performance of a part, and in theory reduce the experimental datasets needed to develop models. At this time however, there is very limited data validating predicted values against experiments. ANSYS and other software that have been designed for composite modeling (see image below from ANSYS Composite PrepPost) can be used as starting points to explore this space.
- Hybrid Tool-path Composite Representation: One of the limitations of the above approach is that it does not model any of the details within the layer. As we saw in part 1 of this post, each layer is composed of tool-paths that leave behind voids and curvature errors that could be significant in simulation, particularly in failure modeling. Perhaps the most promising approach to modeling FDM parts is to explicitly link tool-path information in the build software to the analysis software. Coupling this with existing composite simulation is another potential idea that would help reduce computational expense. This is an idea I have captured below in the schematic that shows one possible way this could be done, using ANSYS Composite PrepPost as an example platform.
Discussion: At the present moment, the orthotropic approach is perhaps the most appropriate method for modeling parts since it is allows some level of build orientation optimization, as well as for meaningful design comparisons and comparison to bulk properties one may expect from alternative technologies such as injection molding. However, as the application of FDM in end-use parts increases, the demands on simulation are also likely to increase, one of which will involve representing these materials more accurately than continuum solids.
When Desktop Engineering needed a subject matter expert on Topological Optimization and its use to drive product development, they called on PADT’s Manoj Mahendran. The article “Your Optimization Software Respectfully Suggests a Revision” gives a great overview of how designs can be driven by the use of Topological Optimization. They also mention a few of the more common tools, and with Manoj’s help, discuss the importance of 3D Printing to the process. An important take away is how these tools can be used to suggest design changes to the designer.
As I showed in a prior blog post, Fused Deposition Modeling (FDM) is increasingly being used to make functional plastic parts in the aerospace industry. All functional parts have an expected performance that they must sustain during their lifetime. Ensuring this performance is attained is crucial for aerospace components, but important in all applications. Finite Element Analysis (FEA) is an important predictor of part performance in a wide range of indusrties, but this is not straightforward for the simulation of FDM parts due to difficulties in accurately representing the material behavior in a constitutive model. In part 1 of this article, I list some of the challenges in the development of constitutive models for FDM parts. In part 2, I will discuss possible approaches to addressing these challenges while developing constitutive models that offer some value to the analyst.
It helps to first take a look at the fundamental multi-scale structure of an FDM part. A 2002 paper by Li et. al. details the multi-scale structure of an FDM part as it is built up from individually deposited filaments all the way to a three-dimensional part as shown in the image below.
This multi-scale structure, and the deposition process inherent to FDM, make for 4 challenges that need to be accounted for in any constitutive modeling effort.
- Anisotropy: The first challenge is clear from the above image – FDM parts have different structure depending on which direction you look at the part from. Their layered structure is more akin to composites than traditional plastics from injection molding. For ULTEM-9085, which is one of the high temperature polymers available from Stratasys, the datasheets clearly show a difference in properties depending on the orientation the part was built in, as seen in the table below with some select mechanical properties.
- Toolpath Definition: In addition to the variation in material properties that arise from the layered approach in the FDM process, there is significant variation possible within a layer in terms of how toolpaths are defined: this is essentially the layout of how the filament is deposited. Specifically, there are at least 4 parameters in a layer as shown in the image below (filament width, raster to raster air gap, perimeter to raster air gap and the raster angle). I compiled data from two sources (Stratasys’ data sheet and a 2011 paper by Bagsik et al that show how for ULTEM 9085, the Ultimate Tensile Strength varies as a function of not just build orientation, but also as a function of the parameter settings – the yellow bars show the best condition the authors were able to achieve against the orange and gray bars that represent the default settings in the tool. The blue bar represents the value reported for injection molded ULTEM 9085.
- Layer Thickness: Most FDM tools offer a range of layer thicknesses, typical values ranging from 0.005″ to 0.013″. It is well known that thicker layers have greater strength than thinner ones. Thinner layers are generally used when finer feature detail or smoother surfaces are prioritized over out-of-plane strength of the part. In fact, Stratasys’s values above are specified for the default 0.010″ thickness layer only.
- Defects: Like all manufacturing processes, improper material and machine performance and setup and other conditions may lead to process defects, but those are not ones that constitutive models typically account for. Additionally and somewhat unique to 3D printing technologies, interactions of build sheet and support structures can also influence properties, though there is little understanding of how significant these are. There are additional defects that arise from purely geometric limitations of the FDM process, and may influence properties of parts, particularly relating to crack initiation and propagation. These were classified by Huang in a 2014 Ph.D. thesis as surface and internal defects.
- Surface defects include the staircase error shown below, but can also come from curve-approximation errors in the originating STL file.
- Internal defects include voids just inside the perimeter (at the contour-raster intersection) as well as within rasters. Voids around the perimeter occur either due to normal raster curvature or are attributable to raster discontinuities.
Thus, any constitutive model for FDM that is to accurately predict a part’s response needs to account for its anisotropy, be informed by the specifics of the process parameters that were involved in creating the part and ensure that geometric non-idealities are comprehended or shown to be insignificant. In my next blog post, I will describe a few ways these challenges can be addressed, along with the pros and cons of each approach.
I had a very cool music teacher back in 6th or 7th grade in the 1970’s in upstate New York. Today we’d probably say she was eclectic. In that class we listened to and discussed fairly recent songs in addition to general music studies. Two songs I remember in particular are ‘Hurdy Gurdy Man’ by Donovan and ‘Pinball Wizard’ by The Who. If you’re not familiar with Pinball Wizard, it’s from The Who’s rock opera Tommy, and is about a deaf, mute, blind young man who happens to be adept at the game of pinball. Yes, he is a Pinball Wizard. This sing popped into my head recently when we had some customer questions here at PADT regarding the pinball region concept as it pertains to ANSYS contact regions.
I’m not sure if the developers at ANSYS, Inc. had this song in mind when they came up with the nomenclature for the 17X (latest and greatest) series of contact elements in ANSYS, but regardless, you too can be a pinball wizard when it comes to understanding contact elements in ANSYS Mechanical and MAPDL.
Fans of this blog may remember one of my prior posts on contact regions in ANSYS that also had a musical theme (bringing to mind Peter Gabriel’s song “I Have the Touch”):
In this current entry we will go more in depth on the pinball region, also known as the pinball radius. The pinball region is involved with the distance from contact element to target element in a given contact region. Outside the pinball region, ANSYS doesn’t bother to check to see if the elements on opposite sides of the contact region are touching or not. The program assumes they are far away from each other and doesn’t worry about any additional calculations for the most part.
Here is an illustration. The gray elements on the left represent the contact body and the red elements on the right represent the target body (assuming asymmetric contact). Target elements outside the pinball radius will not be checked for contact. The contact and target elements actually ‘coat’ the underlying solid elements so they are shown as dashed lines slightly offset from the solid elements for the sake of visibility. Here the pinball radius is displayed as a dashed blue circle, centered on the contact elements, with a radius of 2X the depth of the underlying solid elements.
So, outside the pinball region, we know ANSYS doesn’t check to see if the contact and target are actually in contact. It just assumes they are far away and not in contact. What about what happens if the contact and target are inside the pinball region? The answer to that question depends on which contact type we have selected.
For frictionless contact (aka standard contact in MAPDL) and frictional contact, the program will then check to see if the contact and target are truly touching. If they are touching, the program will check to see if they are sliding or possibly separating. If they are touching and penetrating, the program will check to see if the penetration exceeds the allowable amount and will make adjustments, etc. In other words, for frictionless and frictional contact, if the contact and target elements are close enough to be inside the pinball region, the program will make all sorts of checks and adjustments to make sure the contact behavior is adequately captured.
The other scenario is for bonded and no separation contact. With these contact types, the program’s behavior when the contact and target elements are within the pinball region is different. For these types, as long as the contact and target are close enough to be within the pinball region, the program considers the contact region to be closed. So, for bonded and no separation, your contact and target elements do not need to be line on line touching in order for contact to be recognized. The contact and target pairs just need to be inside the pinball region. This can be good, in that it allows for some ‘slop’ in the geometry to be automatically ignored, but it also can have a downside if we have a curved surface touching a flat surface for example. In that case, more of the curved surface may be considered in contact than would be the case if the pinball region was smaller. This effect is shown in the image below. Reducing the pinball radius to an appropriate smaller amount would be the fix for eliminating this ‘overconstraint’ if desired.
There is a default value for the pinball region/radius. It can be changed if needed. We’ll add more details in a moment. First, why is it called the “pinball” region? I like to think it’s because when it’s visualized in the Mechanical window, it looks like a blue pinball from an actual pinball arcade game, but I’ll admit that the ANSYS terminology may predate the Mechanical interface. The image below shows what I mean. The blue balls are the different pinball radii for different contact regions.
Note that you don’t see the pinball region displayed as shown in the above image unless you have manually changed the pinball size in Mechanical. The pinball region can be changed in the Mechanical window in the details view for each contact region by changing Pinball Region from Program Controlled to Radius, like this:
In MAPDL, the pinball radius value can be changed by defining or editing the real constant labeled PINB.
By now you’re probably wondering what is the default value for the pinball radius? The good news is that it is intelligently decided by the program for each contact region. The default is always a scale factor on the depth of the underlying elements of each contact region. In the first pinball region image shown near the beginning of this article, the example plot shows the pinball region/radius as two times the depth of the underlying elements.
The table below summarizes the default pinball radius values for most circumstances for 2D and 3D solid element models. More detailed information is available in the ANSYS Help.
|Default Pinball Radius Values||Large Deflection Off|
|Large Deflection On
|Frictionless and Frictional||1* Underlying Element Depth||2*Underlying Element Depth|
|Bonded and No Seperation||0.25*Underlying Element Depth||0.5*Underlying Element Depth|
|Rigid-Flexible Contact: Typically the Default Values are Doubled|
Summing it all up: we have seen how the default values are calculated and also how to change them. We have seen what they look like as blue balls in a plot of contact regions in Mechanical if the pinball radius has been explicitly defined. We also discussed what the pinball radius does and how it’s different for frictionless/frictional contact and bonded/no separation contact.
You should be well on your way to becoming a pinball wizard at this point.
Does performing simulation in ANSYS make you think of certain songs, or are there songs you like to listen to while working away on your simulations an addition to The Who’s “Pinball Wizard” and Peter Gabriel’s “I Have the Touch”? If so, we’d love to hear about your song preferences in the comments below.
This video shows a really quick and easy way to extract a fluid domain from a structural model without having to do any Boolean subtract operations.
We have been talking a lot about ANSYS AIM lately. Mostly because we really like ANSYS AIM and we think a large number of engineers out there need to know more about it and understand it’s advantages. And the way we do that is through blog posts, emails, seminars, and training sessions. A new tool that we have started using are “Resource and Productivity Kits,” collections of information that users can download.
Earlier in the year we introduced several kits, including ANSYS Structural, ANSYS Fluids, and ANSYS ElectroMechanical. Now we are pleased to offer up a collection of useful information on ANSYS AIM. This kit includes:
- “Getting to know ANSYS AIM,” a video by PADT application engineer Manoj Mahendran
- “What I like about ANSYS AIM,” a video featuring insights on the tool
- Six ANSYS AIM demonstration videos, including simulations and a custom template demonstration
- Five slide decks that provide an overview of ANSYS AIM and describe its new features
- An exclusive whitepaper on effectively training product development engineers in simulation.
You can download the kit here.
Watch this blog for more useful content on AIM in the future.