3.1.2. Requirements for Writing a C++ Program

C prototypes are required for calling the Ansys Chemkin FORTRAN subroutines from C or C++. To call Chemkin FORTRAN subroutines from C or C++ requires an interface consisting of the file include\chemkin.h (PC) or include/chemkin.h (UNIX), containing the C++/FORTRAN prototype for some commonly required utilities.

3.1.2.1. Declare Variable Types

A variable must be explicitly typed; in general, the sample programs use a variable name initial character indicative of its type, that is,

int iSpeciesCount;
double dRho;
int iLensym = 16;
char *sSpeciesName = new char [ iLensym + 1 ];

The character-string length of a chemical species name is usually 16, plus one additional character for a character-string terminator.

3.1.2.2. Allocate Arrays

Arrays specific to a mechanism Linking File may be allocated by an estimate of its requirements, but with C++ it is possible to determine the requirements first, that is, if the Linking File has been opened (see Open the Linking File ).

CKLEN (iLinkCK,iLeniCK,iLenrCK,iLencCK,iFlag);
int *iICKwrk = new int [ iLeniCK ];
double *dRCKwrk = new double [ iLenrCK ];
int iLensym = 16;
char *sCCKwrk = new char [ iLencCK*iLensym + 1 ];

3.1.2.3. Open the Linking File

An interface to the FORTRAN OPEN is used to allow FORTRAN READ of the Linking File: iFlag will be non-zero on return if there was an error.

int iLinkCK=25;
int iFlag=0;
CCOPEN ((char *)"chem.asc", (char *)"FORMATTED", (char *)"OLD", iLinkCK,
iFlag);

3.1.2.4. Initialize the Linking File Data

Messages from the subroutine will be sent to a screen or window by assigning output to stdout.

int iLout=stdout;
int iFlag=0;
CKINIT(iLeniCK,iLenrCK,iLencCK,iLinkCK,iLout,iICKwrk,dRCKwrk,sCCKWRK,iFlag);

3.1.2.5. Obtain or Manipulate Data

After the Linking File data has been stored into the Ansys Chemkin work arrays, they are the means by which further information about the mechanism is obtained, or data manipulation facilitated.

CKINDX (iICKwrk,dRCKwrk,iElementCount,iSpeciesCount,iReactionCount,iCpfitCount);

where iElementCount is the ELEMENTS count of the mechanism, iSpeciesCount is the SPECIES count, iReactionCount is the REACTIONS count, and iCpFitCount is the number of C p polynomial coefficients for the species.

CKWT (iICKwrk,dRCKwrk,dMolecularWeights);

where double *dMolecularWeights = new double [iSpeciesCount];

CKXTY (X,ICKWRK,RCKWRK,Y)

converts double X[0..iSpeciesCount-1] mole fractions to double Y[0..iSpeciesCount-1] mass fractions for the iSpeciesCount species.

3.1.2.6. Compile and Link

The Ansys Chemkin installation file /include/chemkin_make_unix.inc (\include\chemkin_make_pc.inc for PC), defines make (nmake) macros for required compile and link flags, and library names and locations. A user makefile can set a few additional macros to compile and link a program; the user macro, CKROOT for example, must be defined as the root location of Chemkin.

If CKROOT is not defined as an environment variable already, the Ansys Chemkin make file will use its own CKROOT definition. All the other directories (include, bin, etc.) are referenced using a relative path based on CKROOT.

There are two general scenarios about how CKROOT has to be set:

  1. The first is that the entire Ansys Chemkin file structure is intact when you try to rebuild some DLL or executable. Even if you are not working in the original Chemkin installation, as long as all the other Chemkin directories (bin, include, etc.) are under the same parent directory as the build directory, you do not need to set CKROOT. The make file will use the default setting of '..' and you can use commit a make with the command

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

    Please note that the definition of CKROOT as '..' enables the use of "..\bin\premixdll.dll" as the target. If you have defined CKROOT as "c:\progra~1\ANSY~1\v242\reaction\chemkinpro.win64", you have to use "c:\progra~1\ANSY~1\v242\reaction\chemkinpro.win64\bin\premixdll.dll" as target instead.

  2. If you have installed the sample directories in a separate location, when you try to rebuild the samples, you must set up your Ansys Chemkin environment. See Ansys Chemkin Windows Environment Section 4.1 or Chemkin Linux Environment Section 4.2 of the Chemkin Getting Started Guide (depending on whether you are using a Windows or Linux platform).