tutorial week 10 - internal bone...

13
AMME4981 Applied Biomedical Engineering AMME9981 Computational Biomedical Engineering Tutorial Week 10 Internal bone remodelling Introduction This tutorial will introduce the necessary steps to simulate internal bone remodelling of an implanted femur using ANSYS. You will learn to: Setup and export mesh data from Workbench Generate an APDL input file for use with ANSYS Classic Call a pre-compiled Fortran subroutine during solution Step 1: Prepare geometries for the femur and implant The preparation of a realistic implanted femur geometry was detailed in week 4’s tutorial. This involved the removal of the head and neck of the segmented femur in ScanIP using the 3D editing tools. After completing the steps detailed in week 4’s tutorial, you should end up with the following femur bone geometry. Export this geometry from ScanIP as an IGS file. The femoral component of the hip implant is available for download on the course website (FemoralImplant.IGS), under the tutorial content for week 4, shown below.

Upload: ngoanh

Post on 07-Mar-2018

215 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Tutorial Week 10 - Internal bone remodellingweb.aeromech.usyd.edu.au/AMME5981/Course_Documents... · Tutorial Week 10 Internal bone remodelling Introduction ... to a variety of formats,

AMME4981 Applied Biomedical Engineering AMME9981 Computational Biomedical Engineering

Tutorial Week 10 Internal bone remodelling

Introduction This tutorial will introduce the necessary steps to simulate internal bone remodelling of an implanted femur using ANSYS. You will learn to:

• Setup and export mesh data from Workbench • Generate an APDL input file for use with ANSYS Classic • Call a pre-compiled Fortran subroutine during solution

Step 1: Prepare geometries for the femur and implant The preparation of a realistic implanted femur geometry was detailed in week 4’s tutorial. This involved the removal of the head and neck of the segmented femur in ScanIP using the 3D editing tools. After completing the steps detailed in week 4’s tutorial, you should end up with the following femur bone geometry.

Export this geometry from ScanIP as an IGS file. The femoral component of the hip implant is available for download on the course website (FemoralImplant.IGS), under the tutorial content for week 4, shown below.

Page 2: Tutorial Week 10 - Internal bone remodellingweb.aeromech.usyd.edu.au/AMME5981/Course_Documents... · Tutorial Week 10 Internal bone remodelling Introduction ... to a variety of formats,

AMME4981 Applied Biomedical Engineering AMME9981 Computational Biomedical Engineering

Once you have both IGS geometries, they can be imported into Workbench. While it is possible to import geometries directly into ANSYS Classic, the CAD interfaces in Workbench are significantly more modern and work much better with external geometry files. Start a new Mechanical Model module in the Workbench project window. Double-click on geometry to open Design Modeler. Import both the femur and implant geometries. They should look something like this:

The process of aligning these two geometries is provided in the week 4 tutorial. This involves a simple body translation to move the implant into the correct position as shown.

Once correctly aligned, a cavity for the implant in the femur is required. Use the Boolean subtraction function provided in Design Modeler (Create > Boolean) to

Page 3: Tutorial Week 10 - Internal bone remodellingweb.aeromech.usyd.edu.au/AMME5981/Course_Documents... · Tutorial Week 10 Internal bone remodelling Introduction ... to a variety of formats,

AMME4981 Applied Biomedical Engineering AMME9981 Computational Biomedical Engineering

create this cavity. Remember to select the femur as the target body and the implant as the tool body, and ensure Preserve tool bodies is enabled (Yes).

Pay attention! At this point, the instructions deviate from week 4’s tutorial.

For this model, we are going to assume that the bone and implant are glued together. We could allow Workbench to apply the default bonded condition to the contact surfaces between these two geometries, but the simplest way to define this relationship is to form a single part. Do this by selecting both geometries in the tree outline, right-clicking and choosing Form New Part. For the mesh-savvy amongst you, forming a new part enforces a contiguous mesh between the implant and the bone. This means that the implant and bone will share the same nodes along their interface, effectively gluing the two bodies together, and negating the need for special contact conditions.

The result will be a single part containing two individual bodies. Don’t worry, separate material properties may still be assigned to these two bodies. Close the Design Modeler window, and it’s probably a good idea to save your project file at this point.

Step 2: Generating the mesh in Workbench Now the material properties can be set up in the Mechanical Model module. Open Engineering Data and make two isotropic elastic materials: Bone and Implant. It doesn’t matter what Young’s modulus and Poisson’s ratio you specify in this section; they will just act as placeholders for the bone and implant mesh objects. A Young’s modulus of 1 for the bone and Young’s modulus of 2 for the implant will suffice.

Close Engineering Data and open the Model component. This will launch the Mechanical application window. First, assign the bone and implant materials to their respective bodies. The next thing to do is generate a mesh for the model. For this

Page 4: Tutorial Week 10 - Internal bone remodellingweb.aeromech.usyd.edu.au/AMME5981/Course_Documents... · Tutorial Week 10 Internal bone remodelling Introduction ... to a variety of formats,

AMME4981 Applied Biomedical Engineering AMME9981 Computational Biomedical Engineering

tutorial, it’s sufficient to just keep most of the default mesh settings. However, you should keep element mid-side nodes to generate quadratic (second-order) elements. Do this in the Advanced section of Mesh details, as shown below.

Although we should technically do a mesh convergence study to verify the accuracy of our finite element model, we’re going to skip this for the sake of brevity.

The last thing we need to do in the Mechanical application is to define a named selection for face on the neck of the femoral implant. Select the face and add it as a named selection as below. This will make it easier to apply forces using APDL.

Page 5: Tutorial Week 10 - Internal bone remodellingweb.aeromech.usyd.edu.au/AMME5981/Course_Documents... · Tutorial Week 10 Internal bone remodelling Introduction ... to a variety of formats,

AMME4981 Applied Biomedical Engineering AMME9981 Computational Biomedical Engineering

Step 3: Using FE Modeler to export the mesh Once the mesh and named selection have been generated, close the Mechanical application window. Insert an Finite Element Modeler module into the Workbench project window, and link the model component of the Mechanical Model module to it.

The FE Modeler module enables the export of mesh objects created in Workbench to a variety of formats, including to ANSYS Classic by creating an APDL input file. It will also translate the materials specified in Engineering Data and the Named Selections defined in the Mechanical application to their APDL analogues.

Before opening FE Modeler, ensure that the unit used for the model are in metres, not millimetres. You can do this by checking the Properties of the Assembly Mesh in the Outline pane. If you don’t see Outline and Properties panes, go to View > Outline and View > Properties in the project window.

Open FE Modeler by double-clicking the Model component. Ensure that the Target System is Mechanical APDL. You can check out the features of your mesh in the outline tree. If all the instructions have been followed correctly, all you need to do is click on Write Solver File. This writes all the mesh data to an APDL input file. You can preview the contents of this file under Generate Data. Name your input file “A3_mesh.inp” so it can be identified later.

Page 6: Tutorial Week 10 - Internal bone remodellingweb.aeromech.usyd.edu.au/AMME5981/Course_Documents... · Tutorial Week 10 Internal bone remodelling Introduction ... to a variety of formats,

AMME4981 Applied Biomedical Engineering AMME9981 Computational Biomedical Engineering

Step 4: Editing the generated APDL input file After saving the APDL input file from FE Modeler, close and save your Workbench project file. The remainder of this project will take you through the steps needed to create a solvable APDL input file.

APDL input files are just text files. You can open them in any text editor. The input file generated from FE Modeler contains the locations of all the nodes, and the definitions of all the elements from those nodes, and is therefore quite large for a text file. Use Notepad++, which is available on the PCLAB computers, to open this input file. Your input file will probably start off like this:

/PREP7 SHPP,OFF /NOPR ! ! COORDINATE SYSTEMS ! ! ! MATERIAL PROPERTIES ! /com, Materials <SECTION=MATERIALS> ! Origin Material Property ID - 23 MP,EX,1,1, ! Pa MP,NUXY,1,0.3, ! Origin Material Property ID - 25 MP,EX,2,2, ! Pa MP,NUXY,2,0.3, ! ! PHYSICAL PROPERTIES ! ! ! ELEMENT TYPES !/com, Element Types <SECTION=ELEMENTTYPES> et,1,MESH200 keyopt,1,1,9

Some of these commands will be explained later in this tutorial when you work with the template input file. The ! character denotes a comment, as does the /com command. Briefly, the above set of commands opens the pre-processing module (PREP7), sets up two materials (MP), with Young’s modulus (EX) and Poisson’s ratio (NUXY), and then specifies a type of element to use (ET), which is called MESH200. The Young’s modulus and Poisson’s ratio of the materials you specified in Engineering Data previously should be reflected in the MP commands. All we want in this input file is the definition of the nodes, elements, and the named selection, which is called a component in APDL. So either delete, or comment out the above selection of commands. You should end up with the nodal listing (list of node numbers and their co-ordinates):

nblock,3 (1i8,3e20.9e3) <nodes>

Page 7: Tutorial Week 10 - Internal bone remodellingweb.aeromech.usyd.edu.au/AMME5981/Course_Documents... · Tutorial Week 10 Internal bone remodelling Introduction ... to a variety of formats,

AMME4981 Applied Biomedical Engineering AMME9981 Computational Biomedical Engineering

and the element listing (list of element numbers, the material number, element type, and the nodes that are used to construct them):

eblock,19,solid,12307 (19i8) <elements>

and the component listing (component from the Named Selection, and the associated node numbers):

CMBLOCK,NECK ,NODE, 37 (8i10) <nodes>

Note that the CMBLOCK command, which is used to define the component, specifies 37 nodes. This is important later, when we apply forces on these nodes.

Then go to the very end of the input file (Ctrl+End), and delete the following unnecessary commands.

! ! BOUNDARY CONDITIONS ! ! ! LOADS ! ! ! Solution ! ! ! Turn output back on ! /GOPR ! FINI /GOPR

You can now save this input file. Step 5: Generating a solvable APDL input file Download the template APDL file from the course website, under the week 10 tutorial content, and open this in Notepad++. Most of the input file has been commented in-line, however some important commands will be detailed here. Full descriptions of each command and the associated options are detailed in ANSYS Help (under Mechanical APDL > Command Reference). To enable the set-up of model, /PREP7 command is issued to activate the pre-processing modules in ANSYS. After this, we can define the materials, mesh, and loads.

Page 8: Tutorial Week 10 - Internal bone remodellingweb.aeromech.usyd.edu.au/AMME5981/Course_Documents... · Tutorial Week 10 Internal bone remodelling Introduction ... to a variety of formats,

AMME4981 Applied Biomedical Engineering AMME9981 Computational Biomedical Engineering

et,1,SOLID187 defines element type number 1 as a SOLID187, which is a 10-node tetrahedral element (10 nodes means it has mid-side nodes and therefore has quadratic shape functions). This matches the type of mesh we defined in Step 2. Next we need to define the material properties of the femur bone (material number 1). As the Young’s modulus of the femur bone is going to change in response to a mechanical stimulus, TB,ELASTIC,1 is used to make a material table that can be used to define changing elastic material properties (i.e. Young’s modulus and Poisson’s ratio). In addition, we need a specify a user-defined field variable (UF01) that can be changed in this manner using a subroutine. In this example, UF01 is going to be the Young’s modulus, so the relationship between UF01 and the Young’s modulus in the material table is going to be perfectly linear (with a gradient of 1). We can make this happen by using the TBFIELD and TBDATA commands to define two points that will define a straight line. See the table below to see what this means. UF01 Young’s modulus (Pa) 1 1 1000000000000 1000000000000

This work-around allows us to directly change the Young’s modulus of the bone by changing UF01 using a Fortran subroutine. Note that the Poisson’s ratio will stay the same here. TB,STATE,,1 is another work-around in the APDL input that allows us to store custom data in the results. This defines a single state variable that we will use to store bone density, which will then be plotted after the model is solved. The implant is then given regular material properties using the MP command. You can change the numbers to give the implant a Young’s modulus (EX) and Poisson’s ratio (NUXY) of your own choosing. Next, it’s time to import the mesh you defined in the “A3_mesh.inp” APDL file. You can insert it using: /INPUT,A3_MESH,inp. This type of command can be used to input any APDL code into the file without having to copy and paste it over. Following this are commands that give an initial value to the UF01 field variable that was defined earlier. The femur bone elements need this for the first time-step (before any bone remodelling has occurred). In this example, we’ve assumed that the bone is completely homogeneous, and has a Young’s modulus of approximately 10.5 GPa. To fix the base of the femur, the nodes on the bottom face of the femur need to be selected. The following commands select these nodes, set their displacements in the

Page 9: Tutorial Week 10 - Internal bone remodellingweb.aeromech.usyd.edu.au/AMME5981/Course_Documents... · Tutorial Week 10 Internal bone remodelling Introduction ... to a variety of formats,

AMME4981 Applied Biomedical Engineering AMME9981 Computational Biomedical Engineering

X, Y, and Z directions to 0, and then re-select everything to prevent confusion with the following commands.

NSEL,S,LOC,Z,-445.9e-3 D,ALL,UX,0 D,ALL,UY,0 D,ALL,UZ,0 ALLSEL

Forces in the Z direction (FZ) can be applied onto the component/named selection that was defined from Workbench. Specify the name of the component (NECK) when issuing the F command. Forces can also be applied in the X (FX) and Y (FY) directions as well by issuing multiple commands. Note that the force is applied to each node, so we divide the total force by the number of nodes noted earlier in the component definition (37 nodes for the example given in Step 4).

The final part of the APDL input file specifies the solution settings.

antype,transient time,24 deltim,1 outres,all,all outres,svar,all solve finish save

These commands specify a transient analysis type (ANTYPE), which will terminate at time = 24 (TIME), in increments of 1 (DELTIM), and export all the results for all the time-steps (OUTRES), including the state variable (SVAR) which will contain the bone density data. SOLVE executes the solution. SAVE creates a .DB file that can be used to reopen the model in the ANSYS Classic GUI.

You may add your own post-processing commands to save the bone density plots automatically after it finishes solving (see Appendix). Once you have completed creating the APDL input file, save it with a different filename (e.g. A3_solve.inp)

Step 6: Solving using the pre-compiled USERFLD subroutine As described in the lecture, the APDL input is a high-level scripting language, which is interpreted line-by-line by the ANSYS program. In this tutorial, APDL input has been used to define the nodes and elements of the model, and set up the various boundary conditions and material properties.

To simulate the internal remodelling in the femur bone, a USERFLD subroutine needs to be run at the end of every time-step to update the bone density, and therefore, the Young’s modulus (which corresponded to the user-defined field, UF01 in the APDL file). These changes in Young’s modulus affect the mechanical stimulus experienced by the femur bone in the next time-step. The subroutine is written in

Page 10: Tutorial Week 10 - Internal bone remodellingweb.aeromech.usyd.edu.au/AMME5981/Course_Documents... · Tutorial Week 10 Internal bone remodelling Introduction ... to a variety of formats,

AMME4981 Applied Biomedical Engineering AMME9981 Computational Biomedical Engineering

Fortran, which is a lower-level programming language that needs to be compiled to an executable object before ANSYS can execute it.

Luckily in this tutorial, we can use a pre-compiled subroutine, which saves a lot of trouble. The commented source code and pre-compiled objects necessary to solve the model are downloadable from the course website. Please download this and examine the source code (USERFLD.F) to identify the steps and relationships used to translate the mechanical stimulus to a change in bone density and Young’s modulus. All the files should be placed in your working directory. It is ideal to make the working directory as a new folder on the Desktop if you are in the PCLAB.

The most efficient way of running ANSYS is using the batch interface. From the Windows Start Menu, open cmd.exe. Use the cd command to navigate to your working directory. An example navigating to the folder “assignment” on the Desktop is provided below.

cd C:\Users\your_unikey\Desktop\assignment

Before we run our APDL input file (A3_solve.inp), ANSYS needs to know if there is a subroutine we would like to use, and where it is located. Let’s assume you followed the instructions above and put all the pre-compiled files into the working directory (e.g. “assignment”). Use the following commands to set a temporary ANSYS environmental variable, and check that it has been set properly.

set ANS_USER_PATH=C:\Users\your_unikey\Desktop\assignment echo %ANS_USER_PATH%

Finally, it is time to run ANSYS.

“C:\Program Files\ANSYS Inc\v161\ansys\bin\winx64\ansys161.exe” –b –j A3 –i A3_solve.inp –o A3.out

-b means batch mode

-j specifies the job name (and the name of the files that get dumped in your working directory)

-i specifies the name of the APDL input file

-o specifies the name of an output file, from which you can monitor the status of your job and any errors or warnings that occur. On UNIX systems, there is a tool called tail, but on Windows, you can download a program called baretail.exe to watch the output file as new events get added to it.

Once the job has completed successfully, you can open the generated .db file by double-clicking on it, which will open the ANSYS Classic GUI.

Page 11: Tutorial Week 10 - Internal bone remodellingweb.aeromech.usyd.edu.au/AMME5981/Course_Documents... · Tutorial Week 10 Internal bone remodelling Introduction ... to a variety of formats,

AMME4981 Applied Biomedical Engineering AMME9981 Computational Biomedical Engineering

Step 7: Post-processing the results in ANSYS Classic

Various toolbars and windows are highlighted:

• Yellow: Top Menu, contains options for most of the commands used in ANSYS

• Green: Scripting Bar, allowing for the entry of APDL commands • Red: Main Menu, contains all the options and steps for modelling • Blue: Graphics Window, the graphical display • Orange: Viewing Tools, used for changing the view in the graphics window

First, load the generated results for the first time-step. To do this use either:

• Main Menu > General Postproc > Read Results > First Set • Enter the following APDL commands into the Scripting bar

/POST1 set,,1

Since we are interested in the response of the femur bone, select just the bone elements.

• Select > Entities. Elements > By Attributes > Material num. Enter “1”. • esel,s,mat,,1

Plot some results, and use the viewing tools (orange) to move the model around.

• Main Menu > General Postproc > Plot Results > Nodal Solution > Stress > von Mises stress

• plnsol,s,eqv

Page 12: Tutorial Week 10 - Internal bone remodellingweb.aeromech.usyd.edu.au/AMME5981/Course_Documents... · Tutorial Week 10 Internal bone remodelling Introduction ... to a variety of formats,

AMME4981 Applied Biomedical Engineering AMME9981 Computational Biomedical Engineering

Sometimes contour limits don’t show enough of the distribution, so you can change them.

• PlotCtrls > Style > Contours > Uniform Contours > User specified • /cont,,10,0,,1e6

/replot

For the example /cont command, 10 is the number of contour levels, 0 is the minimum level, and 1e6 is the maximum level.

Any results over the maximum contour level will show up as grey. If you find this disconcerting, you can change it to red.

• PlotCtrls > Style > Colors > Contour Colors > Color above contours • /color,smax,red

To plot bone density, which was stored as state variable, use the following command.

• plnsol,svar,1

You can use the same contour controls to show which parts of the bone remodel the most. Keep in mind that the first time-step shows no remodelling, as the bone starts off as a homogeneous 1800 kg/m3. Bone density data is available for all remaining time-steps. A more advanced subroutine would include greyscale data from CT scans to create an initially inhomogeneous femur bone.

Once you are done with the current time-step, move to the next one and so on.

• Main Menu > General Postproc > Read Results > Next Set • Enter the following APDL commands into the Scripting bar

set,,2

Appendix: Saving plots in ANSYS Classic/APDL You can use the ANSYS Classic GUI and/or APDL commands to export images of your model.

With ANSYS Classic GUI, use the Viewing tools on the right to position the model ideally in the graphics window. Then redirect the plot to a file as follows:

• PlotCtrls > Redirect Plots > To PNG File.

You can change the settings for background colour and resolution here, and upon “Apply”, it will write a .png image to your working directory (filename is based on the jobname).

The fastest way to export a lot of plots is to use APDL commands. You can also use APDL to orient the model in your graphics window. For example, “zoom extents” (fit model to the window) and view along the x axis.

Page 13: Tutorial Week 10 - Internal bone remodellingweb.aeromech.usyd.edu.au/AMME5981/Course_Documents... · Tutorial Week 10 Internal bone remodelling Introduction ... to a variety of formats,

AMME4981 Applied Biomedical Engineering AMME9981 Computational Biomedical Engineering

/AUTO,1 ! Set zoom /VIEW,,1,0,0 ! Set camera orientation (x,y,z) /REPLOT ! Refresh view

Export some PNGs.

/GFILE,1200 ! Set image res TIFF,COMP,1 ! Set PNG compression PNGR,ORIENT,HORIZONTAL ! Set orientation PNGR,COLOR,2 ! Set colour PNGR,TMOD,0 ! Set line strokes /SHOW,PNG,,0 ! Start PNG export PLNSOL,SVAR,1 ! First density plot *DO,i,2,24 ! Loop from 2 to 24 set,,i ! Change time-step /replot ! Refresh plot *ENDDO ! End loop /SHOW,CLOSE ! Stop PNG export

Add this set of commands to some of the initial post-processing commands (/POST1 and the contour controls) and you can then put it in the solvable APDL input file. Alternatively, just save it in a text file, and read it in through the Classic GUI.

• File > Read Input From…