Download presentation
Presentation is loading. Please wait.
Published byElijah Brown Modified over 8 years ago
1
WS2-1 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation WORKSHOP 2 EJECTOR MECHANISM
2
WS2-2 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation
3
WS2-3 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation Workshop Objective –Customize the motion input to the ejector mechanism using a subroutine. Create a subroutine that accepts different crank rates and on-times. Software Version –Adams 2013 Files Required –ejector.cmd
4
WS2-4 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation Suggested Exercise Steps 1.Investigate the model 2.Decide which type of subroutine to use 3.Locate an example MOTSUB 4.Customize the MOTSUB 5.Compile, link and verify the library file 6.Specify the library file 7.Alter element for a user subroutine 8.Modify MOTSUB to accept an input parameter
5
WS2-5 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation Step 1. Investigate the Model a.Open the model file ejector.cmd in Adams/View b.Either modify or get information on the motion crank_motion to view the currently prescribed displacement for the crank arm. c.Simulate the model with: End time = 1 second Number of steps = 200 d.Verify that the crank rotates as expected and the ‘pellet’ is ejected from the tube. e.Note: In the next step you will create a user subroutine that prescribes the motion of the crank arm. Before doing this, note that the motion displacement in Adams/View is in units of degrees. f.Export an Adams/Solver.adm file from Adams/View for this model. Find the corresponding MOTION statement in the file and note which units are used in the.adm file – circle the correct answer: Degrees Radians
6
WS2-6 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation Step 2. Decide Which Type of Subroutine to Use a.Locate the Adams documentation on your computer b.From the documentation main page find the Adams/Solver section and then go to: Welcome to Adams/Solver Subroutines → User-Written Subroutines c.In this workshop you will write a user subroutine that provides a value for a MOTION statement. Look at the list of user-written subroutines in the documentation and determine which type of subroutine is required for a user-written MOTION statement? ________________________. d.Similarly, using the documentation, determine which Adams elements are over-ridden by the following subroutines: REQSUB:____________________ VARSUB: ____________________ CNFSUB:_____________________ CFFSUB:_____________________ b
7
WS2-7 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation Step 3. Locate an Example MOTSUB The Adams/Solver documentation for each user-written element typically will provide both: A ‘stub’, or skeletal, subroutine implementation A link to an example file in your Adams/Solver installation a.Find the MOTSUB documentation location and note that there is a link at the bottom of the MOTSUB section that points to an example file named ‘motsub.f’. This example file will serve as the basis from which to start your own MOTSUB. b.To obtain an example MOTSUB, do the following: Locate the motsub.f file in your Adams installation. This file should be found in the /solver/usersubs/ directory of your top-level Adams installation. Copy this file to your working directory. You may need to change the file permissions on the local copy of this file to not be read-only. Open this file in a text editor
8
WS2-8 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation Step 4. Customize the MOTSUB The example MOTSUB found in the Adams/Solver/usersubs directory returns a value based on some simple mathematics. For this example, you will remove all of the computations in the subroutine and return a simple displacement value. a.Look through the motsub.f file and note the following important sections of the code: The SUBROUTINE MOTSUB( … at the beginning is the function prototype. This is very important and must be present. The variable declarations following the comment External variable definitions are similarly important and must not be altered. The variable declarations following the comment Local variables … are specific to the subroutine calculations. These variable declarations can be deleted if they will not be used in your specific calculations. It is not very obvious in this example, but the VALUE variable is being assigned a number before the RETURN statement is called. This is the section of the subroutine where you assign the calculated value to be passed back to Adams. The RETURN and END statements are required for all subroutines. b.Create subroutine logic that returns a displacement corresponding to a rate of 1 revolution per second for the motion, as in the original model. Remember that Adams/Solver expects any calculated angles to be expressed in radians, unless otherwise noted.
9
WS2-9 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation Step 4. Customize the MOTSUB (Cont.) c.For further extension later it will be useful to define two variables in your code like so: DOUBLE PRECISION PI, DTOR C C === Create variables for PI and degrees-to-radians: C PI = DACOS(-1.0D0) DTOR = PI/180.0D0 d.If you need a hint, look in the /completed directory for the file motsub1.f and have a look at how the displacement value is being calculated. e.Save your completed source code file and move on to the next step to compile and link the user library. IMPORTANT NOTE: Many Fortran compilers allow you to reference variables without first declaring them. This is a common source of error which can be difficult to debug. It is strongly recommended that you use the statement IMPLICIT NONE at the beginning of your subroutine. This tells the compiler that all variables used in the code have been declared as variables before being used.
10
WS2-10 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation Step 5. Compile, Link and Verify the Library File The compile/link process will be done on the command line for utmost flexibility. The compile process will indicate if there are errors in your source code, so be careful when looking at the compiling/linking output from this step. The compilation and linking are done in a single step via the adams2013 script on your system. To compile and link your source code, do the following: a.Open a shell prompt and change the directory to your working directory where the.f source file exists. b.Start the Adams command menu via: adams2013 (for Windows) adams2013 –c (for Linux) c.Specify that you want to create an Adams/Solver User-DLL (cr-user) d.Do not link in Debug mode (n) e.Enter your source file name (your_file.f) f.Hit Enter to indicate that you do not have any other source or compiled-object files g.Provide a name for your user library (for example: mysolver1.dll) NOTE: If you are running a 64-bit installation of Adams, the Adams start command is likely to be “adams2013_x64” on your system.
11
WS2-11 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation Step 5. Compile, Link and Verify the Library File (Cont.) h.The steps a-g on the previous page provide the files needed to the Adams startup script so that it can do the following two things: Compile any source files (*.f) that were specified and create an object (*.obj, *.o) file for each. Link all the object files (*.obj, *.o) together with the proper Adams/Solver libraries and create a valid shared library (*.dll, *.so) file. i.Because there are two distinct operations being performed in the above steps (compile and link), care must be taken to scrutinize the output messages from above. It is possible that the source files compile incorrectly yet the link stage issues a ‘successful link’ message! The following is a list of checks that should be done when compiling and linking: Scrutinize the compile/link output text. Make sure that there are not any unexplained warning/error messages reported. If you have provided source (*.f) files to the Adams script, a successful compile operation will produce an object file (*.obj or *.o) for each source file. A shared library file with the name that you specified for the last input is created upon success. Ensure that this file exists in the working directory.
12
WS2-12 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation Step 6. Specify Library File The start-up command for Adams/Solver must specify the name and location of your user- written subroutine. To do this in Adams/View: a.Adams/View has a ‘Solver Library’ setting in which to specify the library file name. Access this setting in Adams/View via: Settings → Solver → Solver Executable Under ‘Solver Library’, specify the library file name To do this in Adams/Solver: a.A typical start-up command (on the Windows platform) for standard Adams/Solver is the following: adams2013 ru-standard myscript.acf b.To start Adams/Solver and specify a user library, use: adams2013 ru-user mysolver1.dll myscript.acf c.You can verify the sequence of input parameters by stepping through the Adams start-up script one input at a time.
13
WS2-13 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation Step 7. Alter Element for a User Subroutine Modify the MOTION element in the model (crank_motion) so that it is using a user subroutine. a.If you chose to do this in Adams/Solver.adm file, this corresponds to specifying FUNCTION=USER(…) for the element. b. You can also do this in Adams/View: In the Joint Motion Dialog, use the drop down box for the Define Using field, and select Subroutine. After you have specified subroutine, then the User Parameters field specifies the additional data that can be passed in to the subroutine (the content within the parentheses of the USER(…) parameter). Does the subroutine, as written, currently require any input arguments? (yes/no) TIP: No input is required (yet) for our subroutine, but the User Parameters input field in Adams/View requires something. In our example, enter 0 as input. This value will not be used by the current subroutine. b
14
WS2-14 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation Step 7. Alter Element for a User Subroutine (Cont.) c.What would happen if you were to enter a longer list of input parameters in this field? Would the simulation still progress properly? _______________________________________________________________________ d.Re-run the last simulation within Adams/View. This new simulation should be using your user-written library. e.Verify the results of your simulation f.Do the results look the same as the initial simulation? (yes/no)
15
WS2-15 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation Step 8. Modify MOTSUB to accept an input parameter The MOTSUB currently specifies a fixed angular velocity of 1 revolution per second with Fortran code that looks similar to this: C === Calculate return value: VALUE = 360.0D0 * DTOR * TIME a.Change the subroutine code and model input such that the angular velocity, in degrees/second, is passed into the subroutine from the model file and subsequently used to specify the angular velocity in the MOTSUB. b.To specify the input value from the model file within your subroutine: Save your MOTSUB code to a new file, for example motsub2.f. Edit this new file so that your original source file is unchanged. Rename your Adams/View model to be ejector2 and export a.cmd file for this new model Create a new variable of type DOUBLE PRECISION in your Fortran file named ANG_VEL Assign the input value of PAR(1) to the ANG_VEL variable Modify the VALUE assignment to use the ANG_VEL variable
16
WS2-16 ADM703c, Workshop 2, February 2013 Copyright 2013 MSC.Software Corporation Step 8. Alter Element for a User Subroutine b.To specify the input value from the model file within your subroutine (continued): Add a user parameter value of ‘360.0’ to your Adams model file to specify the desired angular velocity of the MOTION element. Recompile the user library to reflect the code change. You may need to assign a new name to your user library (example: mysolver2.dll) during compilation/linking if Adams/View currently has your old library file loaded in memory and file sharing errors occur during library creation. (Or, select Hold License = No in Settings – Solver – Executable, which will make the solver to release the dll after each simulation has ended. Then you can re-compile your solver dll using the same name as before.) c.Re-run the model with your new user library d. If you change the User Parameter value from 360 to 720, and re-run the simulation does the angular velocity of the link increase as expected? (yes/no) e.If you had another variable in your source code named on_time, what would the Fortran code look like that assigns the 2 nd input value in the USER() list to on_time? ___________________________________________________________
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.