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:
■To link Adams Solver (run-time) routines, you must have a FORTRAN or C compiler.
■To link Adams View (design-time) routines, you must have a C compiler.
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 in the Installation Guide that comes with your Adams product for the type of compiler you need
(
https://simcompanion.hexagon.com/customers/s/article/Adams-Doc-2022-Release). 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:
■The solver subroutine is expected to be in FORTRAN.
■You must have the linkers from the FORTRAN compilers to create a library, even if the subroutine is in C.
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. Create a C file containing the function create_road. Use the parameters that are passed to and from the function.
4. Compile the two files using the appropriate compile flags (can be found by opening an advanced session):
■On Windows:
■From the Start button, point to Programs, point to Adams 2024.1, point to your template-based product (in this case, Adams Car), 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.
■Your template-based product displays the compile options.
■On Linux:
■At the prompt, enter adams2024_1 -c acar cr-acarprivate, and then press Enter.
■Press Enter again to select the default, which tells the compiler not to build debug libraries.
■Your template-based product displays the compile options.
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 Linux).
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.