Chi-Tech
|
Wherever you like, create a folder that will contain your application.
Now create an empty source file
In the folder you just created create a text file called CMakeLists.txt
We need to specify a few values to be included in the CMakeLists.txt
file.
Downstream.cmake
.The set(TARGET test_app)
line sets the name of the eventual executable to be used. You can use any name other than test
. The include
statement allows you to connect to all the resources connected to Chi-Tech, including lua, PETSc, etc. Make sure that this environment variable is set. You will have to find the location where you compiled Chi-Tech in order to properly specify the location of Downstream.cmake
. Once this is properly specified, the cmake-variable CHI_LIBS
will be defined and the necessary include-files will be usable. The line file (GLOB_RECURSE SOURCES "*.cc")
adds all .cc
files, in the current directory, to the list of sources to compile. To specify specific source-file names use set(SOURCES "test.cc")
. Alternatively cmake functionality can be googled to determine how to add sub-directories.
This code is the minimum needed to have everything available in Chi-Tech. The basic namespace access is provided via #include "chi_runtime.h"
MPI initialization and PETSc initialization is handled via the call to chi::Initialize()
.
Finally all MPI and PETSc related items are destroyed via the call to chi::Finalize()
.
Well, we should probably state here that you should make sure ChiTech compiled. This can be done by running the test cases. If all is well then proceed to make build directory (TestApp/build
) for this app.
Next execute cmake from this directory, giving it the directory-location of the CMakeLists.txt created in step 2.
If all is well here then simply run make:
For this section we refer to the section above where we created a test application.
Purely for categorization, create a lua
folder in the TestApp
folder
Let us pretend that we will have a status update message that we want to be printed from a lua call. Create a file called testapp_statusmess.cc
with the following contents:
In preparation for adding many more sources to the lua
folder, edit the CMakeLists.txt file as follows:
This will allow any .cc
file in the lua
folder to be compiled with the project. The line
recursively searches through the specified folder and pumps any filenames ending with .cc into the variable MORE_SOURCES
. This variable gets added to the manually specified SOURCES
variable using the line
Modify your test.cc
source file to be
Notice here that we firstly included the header file for the ChiConsole
object. This is the object that allows us to connect to the lua state.
Next we obtained a reference to the console through
We then setup the variable L
, which is needed by the macro file ChiMacros/lua_register_macro.h
.
This macro file exposes numerous lua macros, one of which is the RegisterFunction(x)
macro where we will supply the x
as the function call we defined earlier: