2.1.3. Recompiling and Linking a User Subroutine


Note:  Before starting to recompile or link, you must set up your compile environment. For more information on the compiler compatibility with Ansys Chemkin libraries, see Compiler Compatibility.


Incorporating customized user subroutines into Ansys Chemkin shared objects requires the following basic steps, each of which are described in more detail below:

  1. On Windows platforms, set the environment variable FLEXLM_ARCH to:win64.

  2. Modify the user routine for the option of interest.

  3. Compile and update the user routine's static object-archive library.

  4. Link the user routine library into the target run-time shared-object library.

As an example, the following steps will incorporate a customized rate routine in cklib_user_routines.f, and/or a modified FUNCTION PRQFUN in premix_user_routines.f for the Premixed Laminar Flame Models, by recompiling the modified user routines and updating the object archive library required by the application program:

  1. On Windows systems, set the FLEXLM_ARCH environment variable.

  2. Locate the user routines' archive library file:

    For Windows/PC, this library is located at \lib\user_routines.lib.

    For UNIX, this library is located at /lib/user_routines.a.

  3. Back up the library file; for example, rename the existing user_routines.lib file (e.g. as installed_user_routines.lib), so that it does not get overwritten.

  4. Using the makefile available in the user_routines directory, the following will compile the changes made to the user routine files and create a new user_routines.lib. The command must be typed in an Intel FORTRAN command window (PC) or in a UNIX shell with the Intel FORTRAN environment, after using the cd command to reach the user_routines directory:

    For Windows/PC, use:

    nmake -i -f user_routines_pc.mak

    For UNIX, use:

    make -i -f user_routines_unix.mak


    Note:  If you copy instead of rename the original library, you will have to also explicitly delete the original file from the lib directory before make will build a new version.


  5. On Windows platforms, set the environment variable FLEXLM_ARCH to: win64.

  6. You must rebuild the target executable's shared-object library, thus linking the updated user routines’ library. The shared-object libraries are located in the bin directory (for example, PC: %CHEMKIN_BIN% ; UNIX: $CHEMKIN_BIN). In this example, you create the shared-object library associated with the PRQFUN routine in Table 2.1: Keyword and FORTRAN Code Relationships, to incorporate the modified routines cited in the previous step:

    For Windows/PC, the shared-object library consists of three files, premixdll.dll, premixdll.exp, and premixdll.lib.

    For UNIX platforms, the corresponding file is libpremix.so (for LINUX).

  7. Back up the shared-object library for the executable that you want to build. For example, rename the existing premixdll.* files (for example, as installed_premixdll.dll), so that they do not get overwritten.


    Note:  If you copy instead of rename the original library, you will have to also explicitly delete the original file from the bin directory before make will build a new version.


  8. Change directories to the drivers_cpp directory:

    For Windows/PC, use:

    cd ..\drivers_cpp

    For UNIX, use:

    cd ../drivers_cpp

  9. For the Reactor Model you are targeting, make a new shared-object library using the makefile located in the drivers_cpp directory:

    For Windows/PC, use:

    nmake -i -f drivers_cpp_pc.mak ..\bin\premixdll.dll

    which also creates a new premixdll.exp and premixdll.lib.

    For UNIX, use:

    make -i -f drivers_cpp_unix.mak ../bin/libpremix.so

Now you can launch the Ansys Chemkin interface and process your input files as usual with the modified run-time shared-object library for the associated Reactor Models (in this case the Premixed Burner-stabilized Flame and the Premixed Flame-speed Calculator). Remember to restore the backed-up shared-object library when you want to return to the as-installed functionality.


Note:  There are some features in the Reactor Models and Ansys Chemkin utilities that will be incompatible with the global replacement of species rates of production, such as sensitivity analysis and rate-of-production analysis. Such features will return zero values when user rate-routine programming is encountered.