Customizing Your Product > Introducing Adams/View Libraries

www.kxcad.net Home > CAE Index > MSC Software Index > Adams MD R2 Index


Your Ad Here

Introducing Adams/View Libraries
Libraries let you use your user-written subroutines and compiled functions. User-written subroutines and compiled functions let you tailor your template-based product to your needs and go beyond the functions you can define using macros. For more on compiled functions, see Compiled Functions in the guide, Using the Adams/View Function Builder.
You will find subroutines most helpful when the operations to be performed are heavily recursive or require file input or output.
To use your custom subroutines and functions, you create an Adams/View library. An Adams/View library extends the functionality of your template-based product during the design phase and during plotting. Using an Adams/View library, you can create compiled functions in C and use them in an Adams/View expression just as you would use standard, built-in Adams/View functions.
You register the user-written functions by calling a subroutine built into Adams/View. You must place this subroutine call in the registration subroutine supplied in source-code form in Adams/View. To automate tasks, you can write a custom Adams/View library in C. As an example, you might want to create a wavefront file that given a number of macro parameters, such as road width, length, and color, can be used to define a road graphic. In such an example, you would create a C file that when combined with some macro-wrapping code can be set up to pass parameters from the macro to your custom C routine. The following example shows five parameters (road_width, road_length, color, shell_file, error_flag) being passed to a routine named create_a_road:
variable set variable_name = $_self.generate_road &
  integer_value = (eval(create_a_road("$road_width", "road_length", "color",   "shell_file", "error_flag" )))
If successful, this execution results in the generation of a wavefront file based on the input parameter contained in shell_file (as an example, my_road.obj).
In this case, you call a function (create_a_road) in your Adams/View library. You can set up this code to return a Boolean flag, such as 0 if it failed and 1 if it was successfully executed. You can check this flag to see if the operation was successful or not, and take action based on the result.
After you check the error flag, you can execute a read Wavefront file in the macro, specifying the shell_file file as generated by the Adams/View library:
file wavefront read &
    file_name = (eval($_self_shell_file)) &
    port_name = $assembly_ground
Learn more about Adams/View libraries:
Requirements for Creating Custom Libraries
To be able to create Adams/View or Adams/Solver libraries, you must meet the following requirements:
You can input C or FORTRAN source files to create Adams/Solver user libraries and only C source files to create Adams/View user libraries. You must compile these subroutines before linking them with an Adams product. See the hardware and software specifications that come with your Adams product for the type of compiler you need (http://www.mscsoftware.com/support/prod_support/adams/?Q=135&Z=144&Y=174). Also refer to your compiler documentation for details.
Therefore, you can write an Adams/Solver routine in FORTRAN or C, but keep in mind that:
If the solver subroutine is written in C, you must make it emulate a FORTRAN subroutine, as specified in Knowledge Base Article 8384, at http://support.adams.com/kb/faq.asp?ID=kb8384.dasp. If you write an Adams/Solver routine in C, it requires a FORTRAN header, and also requires a FORTRAN compiler (linker).
Creating and Using Adams/View Libraries
An Adams/View library is a custom piece of C code that you can use to extend the functionality of the interface. See a simple example to automatically create a Wavefront file based on a number of input parameters from a macro.
Modifying vc_init_usr_c
You can find the file vc_init_usr.c in the distribution of Adams, under /aview/usersubs. This file provides an interface between Adams/View and user-defined functions. For this example, you'll assume that a user-defined function, named create_road, is going to be used. Following the instructions in vc_init_usr.c, you would do the following:
1.
Copy vc_init_usr.c and mdi_c.h to your local working directory.
2.
Modify vc_init_usr.c to suit your function (create_road). The file includes help inside comment blocks.
3.
4.
From the Start button, point to Programs, point to MSC.Software, point to MD R2 Adams, point to your template-based product (in this case, ACar), and then select Advanced.
At the prompt, enter cr-acarprivate, and then press Enter.
Press Enter again to select the default, which tells the compiler not to build debug libraries.
At the prompt, enter mdi -c acar cr-acarprivate, and then press Enter.
Press Enter again to select the default, which tells the compiler not to build debug libraries.
5.
To end this session, type Exit, and then press Enter.
6.
Once the files have been compiled, repeat this process, this time specifying the two object files that were compiled. If everything is successful, you will now have a .dll file (.so on UNIX).
Using the Custom Adams/View Library
For the custom Adams/View library to be automatically loaded, see the notes for organizing your custom code. Once you've loaded the library into your template-based product, you should be able to reference your custom function. You can reference your function using the Function Builder or macro code.
Your Ad Here