MENG 421 Assignment 2

Solving Axial1 with Matlab and Ansys

MENG 421 -- Class assignments -- 1 2 3 4 5 6 8 9 10 11 12

In today's lesson you will run both Matlab and Ansys to solve the axially loaded bar described here. The purpose of this lesson is to learn
• how to copy class prototype files,
• how to edit files,
• how to run Matlab and Ansys,
• how to copy the results to the original file, and
• how to print the results.
By the second exam you will need to memorize the important parts of the Ansys code. We will discuss the code at the beginning of each laboratory.

First you will create Matlab and Ansys folders in the Win directory. Then you will copy the prototype files and run them. Check that the answers for Matlab and Ansys agree. Finally, print out the results, add a cover sheet describing what you did, and turn the package in at the next class meeting.

1. Four things to do each time you start Windows
Set the screen resolution, check the size of your stored files, clear the Recycle Bin, and clear the C:\WINDOWS\Temp folder.
Clearing the recycle bin and Temp folder will make more space and reduce the time other programs spend searching the Temp folder. You may also want to find something that is located in the Temp directory.

• Check the screen resolution:
Before starting Ansys, check that your screen is set to 1024x768 High Color (16 bit). If not, change it as you did in the previous lesson. Ansys might not run if the screen is wrong.

• Check the size of your stored files
• Using Explorer, locate the U drive icon. This is where you files are stored.
• Put the mouse pointer on the icon to the right of the plus symbol and click the left button.
• With the mouse pointer still on the icon, click the right (not the left) mouse button to get a menu.
• Left-click the menu item Properties.
• The Properties dialog box shows Used space. This is the size of your saved files.
• Anything over about 50MB will cost you \$.01/MB/day.
• You can easily delete files with Explorer, even Unix files.
• In Explorer, you can see your directories in the left pane and the files and folders in the right pane.
• You can delete files and folders in the right pane by clicking them and pressing Del. Alternatively, you can right-click a file to get a menu and pick Delete.
• If you are over your quota, make sure that you have programmed both Ansys and Netscape to put their large work files on C:\WINDOWS\Temp, not in your account.

• Clear the Recycle Bin
• Double-click the Recycle Bin icon on the desktop
• Click one of the files
• Type Ctrl-A to select all files in the Recycle Bin
• Press the Del key to delete all files there
• Click Yes to Confirm File Delete

• Clear the Temp folder
• Make sure that Ansys is not running
• Double-click the Temp shortcut you made last time to open the folder
• Click a file in the folder
• Type Ctrl-A to select all files in the Temp folder
• Hold Ctrl and click any folders to unselect them
• Press the Del key to delete all files there
• Click Yes to Confirm File Delete

2. Create the Matlab and Ansys folders.
Skip this section if you already have done this.
• Start Explorer if it is not already running. (Double-click the icon you made last time or right-click the Start button and pick Explore.)
• In the left pane, open the U drive by left-clicking the plus symbol if necessary.
• Open the Win folder by left-clicking the plus symbol.
• Left-click the folder icon between the minus and Win.
• Look at the address box at the top to see that U:\Win is identified.
• Move the mouse pointer to a blank area of the right pane.
• Right-click to get a menu and move down to New.
• Move right from New to get another menu and left-click Folder.
• Type the name Matlab and press Enter.
• In the right pane, right-drag the Matlab folder to a blank area and release the mouse button to get a menu.
• Left-click the menu item Copy.
• Right-click the new folder and pick Rename from the menu.
• Type the name Ansys and press Enter.
• You now have a Matlab and an Ansys folder.

3. Copy the Matlab file axial1.m to your directory Matlab
The easy way:
• Click here to show the file axial1.m.txt
• This is a TXT file so you have to change the name before saving it
• Press Ctrl-A to highlight all the file
• Click the File menu and pick Save As
• Change the Save As dialog box so it points to
`       U:\win\Matlab`
by clicking on the down-arrow at the end of the Save in: box. Then click the folder icons.
• In the Save as type field change to All files (*.*)
• In the File name field make the name axial1.m
• Click Save.
• Use Explorer to check that the file axial1a.m is present in your Matlab folder.

See the Copying Prototype Files for more information.

4. Copy the Ansys file axial1.a to your Ansys directory.
• Click here to show the file axial1.a.txt.
• Make a copy of this file as you just did in the pervious section
• Name it axial1.a
• Check that the file axial1.a is present in your Ansys folder.

See the Copying Prototype Files for more information.

5. Editing a Matlab File
In this section you will make three changes to your Matlab file axial1a.m
• Start Matlab.
• If Matlab shows more than one window, click the View Menu, move down to Desktop Layout and move right.
• Click Command Window Only.
• Find the Current Directory window on the tool bar.

• Click the button with three dots to the right.
• Steer to your Matlab directory.
• Check that the directory name shows in the box.
• Click the Open File button, the second one, with a curved arrow. Your Matlab file should show in the Open dialog box.
• Click your Matlab file and then click the Open button. This opens the editor with your file.
• Notice the red lines beginning with %. These lines are ignored by Matlab.
• Near the top of the code, find the line starting with p1. Change the force p1 from 1000 to 1200
• Move to about the middle of the code where it says Your name
• Put your name in the Matlab code
• Go to the bottom of the code where the solution to the original problem has been inserted.
• Delete the Matlab solution but put it into the clip board by left dragging through the data, and typing Ctrl-X.
• Click the Matlab Save icon or click the File menu and pick Save.
• Click the input area of Notepad and type Ctrl-V to paste the data you deleted.
• Later you will compare the original data in Notepad to the data you create.

6. Running Matlab
In this section you will do three things: run your m file with Matlab, copy the output from Matlab to the end of your m file, and print out the m file with your solution at the bottom.
• In the Matlab editor, move your mouse near the right end of the toolbar until the Tooltip shows Run.
• Click the Run button.
• In the Matlab editor, click the Run button near the right end of the toolbar.
• Move to the regular Matlab window and look at the right pane for your solution.
• Compare the output to what you pasted into Notepad to see what items you need to copy from the Matlab solution. Also check the the values are close to each other.
• Be sure your name and date appear in the solution.
• Check the alignment of the data and headings. You must use the correct format statement to make decimal points line up. See Matlab Help for more information.
• If you have to make changes in the editor, save and rerun your program.
• Drag through the Matlab solution and type Ctrl-C to copy to the clipboard.
• Go the editor, move to the bottom of your code, and type Ctrl-V to paste the results.
• You cannot now re-run your m file because it has the output data at the end.
• Add a % symbol to the beginning of each line of output so you can re-run the file.
• Save the file.
• Print the file from Notepad not from Matlab or the numbers won't line up.
• Close Matlab and the editor.

7. Making two Ansys shortcuts
In this section you will put two short cuts to Ansys on the desktop. One is used to configure Ansys the first time you run it while the second is used from then on.
• Make sure that you can see a portion of your desktop
• Click the Start menu
• Move up the menu to Programs and move right to get the Programs menu
• Move to the ANSYS 5.7 folder and move right to open it
• Move to interactive , press and hold the right button.
• While still holding the right button, drag the icon to your desktop
• Release the mouse button to get a menu
• Pick Copy from the menu
• Repeat the above directions to make a copy of Run Interactive Now
• Left-drag the new shortcuts to the Start menu so you can start them from there too.

8. Editing an Ansys File
In this section you will edit your Ansys file axial1a.a. Unlike Matlab, Ansys does not have a built-in editor. Therefore you must use something like Notepad.
• Click your Ansys folder in the left pane of Explorer to highlight it.
• Look for your Ansys file in the right pane of Explorer
• One way to edit an Ansys file is to drop its icon onto the Notepad shortcut. This method always works.
• Minimize all windows except Explorer.
• Move Explorer by dragging its header bar so that the Notepad shortcut is visible.
• Locate your Ansys file in Explorer.
• Left-drag the icon of your Ansys file and drop it on the Notepad shortcut on the desktop.
You can also drop the icon onto Notepad itself if it is running
• If you used this method, skip over to the next section.
• An alternative way to edit a file is to set up an association to Notepad. Then you only have to double-click an Ansys file to start up the editor. Unfortunately, you may have to set up this method each time you log in.
• Left-click your Ansys file
• Hold the Shift key while you right-click the a file
• In the menu that appears, left-click Open with
• In the Open With dialog box, click for a check mark in Always use this ...
• Scroll down to NOTEPAD and click it
• Click OK and Notepad will open with your file
• Now, at least for today, you can edit an Ansys file just by double-clicking it in Explorer.

9. Make the following changes to your Ansys file
• Put your name where it says Your name
• Add the date
• Change the load, p1 from 1000 to 1200
• Remove the solution at the end by left dragging through the data, and typing Ctrl-X. Paste into Notepad for comparison later.
• Look for the Ansys code:
` /output,Displ,txt,U:\win\Ansys\   !  displacements`
which will put the output in your U:\win\Ansys directory.
• Click the File menu and pick Save.

10. Running Ansys
In this section you will Start Ansys in configuration mode. Once you have configured Ansys, you can run it in its regular mode.

Ansys creates very large work files that you do not need. However, if Ansys puts the files in your own directory, you will soon be out of space. Fortunately, each Tech computer has a free storage area named C:\WINDOWS\Temp that can be used. You are not charged for this space, but you have no guarantee that files you place there will survive after you log out.

Change the Ansys workspace area with the following steps.

• Double-click the Ansys Interactive icon. Remember that you only use this icon once for each session. Use the Run Interactive Now icon if you have to restart Ansys later today.
• The second line of the Interactive dialog box shows the working directory.
• You want Ansys to use the C:\WINDOWS\Temp folder so it won't put its large work file in your account.
• If Ansys is not using the Temp directory, click the button to the right to get the Enter Working Directory dialog box.
• Steer to C:\WINDOWS\Temp and click the OK. This is the folder you cleared earlier.

• Click the Run button at the bottom to start Ansys in graphical mode.
• Click the File menu at the upper left and pick Read Input from to tell Ansys where your Axial1a.a file is.
• The Read File dialog box should show the C:\WINDOWS\Temp folder. If not, go back through the steps above.
• Steer to U:\win\Ansys where your Axial1a.a file is.
• Highlight your axial1a.a file by left clicking.
• Click OK to start running your program
• The yellow Information dialog box tells you that the solution is done.
• Click Close.
• There is no graphical output since this is a one-dimensional problem. Of course, the results have been written into files for you.
• To run another Ansys program, you have to first clear out the data from the previous one. To do this:
• Click the File menu
• Pick Clear & Start New
• Pick OK
• If necessary, you can make changes to your file and rerun Ansys as you did before.

11. Adding the output to your Ansys code
In this section you will copy the Ansys results to the bottom of your Ansys file in Notepad and then print the combination.
• In the left pane of Explorer left-click U:\Ansys to see your Ansys files.
• In Explorer, click the View menu and pick Refresh to see the new files
• Click the Modified bar to put the newest files at the top.
• The important results are in two files. The displacements are in the file Displ.txt and the forces and stresses are in the file Stress.txt because the lines:
```/output,Displ,txt,U:\win\Ansys\   !  displacements
/output,Stress,txt,U:\win\Ansys\  !  forces and stresses```
appear in the Ansys source code (axial1a.a)

Change to the alternate Output forms when running Ansys on the Mechanical Engineering Department computers to put the output in the D:\Ansys directory..

```/output,Displ,txt,D:\Ansys\   !  displacements
/output,Stress,txt,D:\Ansys\  !  forces and stresses```
• Make sure that a copy of Notepad is open with your Axial1a.a file.
• Double-click the file Displ.txt to open a second copy of Notepad with your data file.
• Look through the file to find the displacement with the heading
`       NODE    UX    UY`
• Compare to the original data you removed.
• Drag through the displacement data and press Ctrl-C to copy the data.
• Switch to the Notepad that has your Ansys file and scroll to the bottom.
• Press Ctrl-V to paste the displacement from your output.
• Double-click the file named Stress.txt to open a third copy of Notepad.
• Scroll down to the forces
`       NODE    FX`
• Copy these to your Ansys file.
• Go back to Stress.txt and scroll down to the stresses
`    ELEM   STR`
• Copy these values to your Ansys file.
• Check that the results agree with your Matlab version: axial1a.m
• Put an ! at the beginning of each line of your data so that Ansys won't try to interpret the lines as code.
• Make changes if necessary and rerun Ansys.
• Send your file to the printer.
• If you want to start up Ansys again today, use the other icon, Run Interactive Now.

12. Help
Extensive Ansys help is available by clicking the Help menu.

13. Closing Ansys
• Click the Quit button on the Toolbar dialog box near the upper-right corner.
• Click the circle next to Quit - No Save
• Click OK
• Remember, if you want to start up Ansys again, choose the Run Interactive Now icon.

14. Assignment
Make a cover sheet with a sketch describing the problem you solved with Matlab and Ansys. Attach the Matlab and Ansys solutions, and turn in the package before 4:30 PM Tuesday to my office please (not the Department office).

15. Checking Your Quota
• You need to watch the amount of files that are saved to your account.
• Ansys stores several very large work files that you do not need to keep.
• If you set up Ansys to put its work files in C:\WINDOWS\Temp you can ignore these files
• Otherwise, you must be sure to delete these work files before logging out.
• Of course, you can easily delete files with Explorer. Click the Modified bar at the top to put the latest files at the top.
• Before logging out, check the Properties dialog box as you did earlier to see that you have not exceeded your quota.

Prologue: Each assignment covers much material. You should go through the complete lesson several times until you understand it. You must know how to easily do the material covered in the exercises. In particular, you must understand all the changes you make and be able to write them out on an examination. That is, you do not need to know all the lines in your programs, only the ones you change and the overall structure of an Ansys program.

MENG 421 -- Ansys -- Lecture 1 -- Class assignments -- 1 2 3 4 5 6 8 9 10 11 12
Files: Ansys, Matlab

Revised: March 19, 2004 -- Copyright © 1997-2004 ARMiller