Compile code based on CGAL

CGAL is an amazing computational geometry library that can make your programming life so much simpler and faster. Once you overcome the weird looking coding style becomes a powerful tool.

Here I’ll describe a few modifications that I make on the cgal generated CMakeList.txt that make my life a bit easier and make the files more portable.

In short, the steps are

1) For each project create a new folder and create a default CMakeList.txt file by running cgal_create_cmake_script

This is going to create a default CMakeList.txt file.

If the cgal installation is not on the search path then the cgal_create_cmake_script can be found under path/to/cgal-releases-CGAL-x.xx.x/Scripts/scripts/

To make the script easier to transfer between my CGAL projects I’m doing the following changes:

Selection_007

First I remove the default project name which is taken by the folder name.

Then I add a target name for the project and a target source.

Remove one statement create_single_source_cgal_program(…)

Finally, at the end of the file, I set the project and the executable.

To run cmake you need to create a file with the name ${TARGET}.cpp, in my case test1.cpp. Even an empty file its ok

Then run cmake (don’t forget the space dot) 

If you have to provide the cgal path then add the following option

 

If the configuration is successful you can run make after you have written some code into the file ${TARGET}.cpp

Those modifications allow to copy the same CMakeList.txt files to other projects and build them with a single modification just the very first line. In addition with a few other modifications that will be subject to another post you can add other libraries like deal.ii and OpenSceneGraph

Compile C++ projects with OpenSceneGraph

In this article I’ll show you how to compile an OpenSceneGraph (OSG) C++ project and open it with Qt creator under Ubuntu 13.10 or 13.04.

I’m going to assume that the OSG has been installed on a location known to your system. If you have problems installing the most stable release you can try the following three commands:

Make sure you have a recent version of cmake ( > 2.6)

First create an empty directory for the new OSG project, enter the directory and create an empty CMakeLists.txt file.

Copy the following lines into the empty file:

The only parameter that need to be changed for every project is the name_of_main_file.cpp, which should be given without the suffix *.cpp

Before running the cmake you need to create file name_of_main_file.cpp which can be empty.

You can run cmake from the command line but here I’ll do it from Qt creator.

From Qt creator choose File->Open File or Project

Go to the directory you just created and pick the CMakeLists.txt file

Selection_020

 

This will launch the cmake wizard. In the first step you define the build location. By default this directory is different than the one created above. It is ok to use the same directory if you don’t build the project for different configurations.

Click Next and on the next step click Run CMake to configure the project.

Selection_022

 

Now you can start editing the name_of_main_file.cpp to create you OSG scene.

Qt creator should be able to provide autocompletion and suggestions for all the OSG classes.

A guide to compile Parflow (Ubuntu only)

I assume that you already know what Parflow is, otherwise you would not read these lines.

Here I’m attempting to describe the steps but more importantly the tweeks one need to do under Ubuntu.

Before that, I should acknowledge this article which was my starting point.

1) Dependencies:

2) Installation of dependencies:

TCL:

There are two options here:

  •  install it from the repositories: This is easy as doing sudo apt-get install tcl-dev and sudo apt-get install tk-dev. However later during pftools configuration you will run into few troubles.
  •  Compile Tcl from source and decide yourself where to put this. pftools will search for the tcl.h and libtcl.* files in the directories ${dir}/include and ${dir}/lib where ${dir} is either the directory provided with the option –with-TCL=${dir} or the usr and usr/local if you run configure without the option –with-TCL

Here I took the first approach. So I’ll come back on the troubles later below.

MPI:

My recomendation is to get it from the repositories. If you are attempting to install it on a cluster there should be already somewhere where the libraries can find it. In my PC I had already installed it from the Ubuntu Software Center quite sometime ago. Doing so the mpi libraries will be installed somewhere that can be found and you dont have to provide any mpi paths.

HYPRE:

After you extract the files you should go into the directory ../hypre-2.9.0b/src (in my case that was 2.9 version) and run ./configure. By default hypre enables mpi so this will configure hypre so that the installation files be under ../hypre-2.9.0b/src/hypre. Although in general its good not to mix the builds with the code but we keep things simple here. If you dont want mpi you need to add the option –without-MPI. After successfull completion of configure you can build by typing make all install. After this is completed you should see two non-empty folders: an include and a lib under  ../hypre-2.9.0b/src/hypre. You can also check by running make check

SILO:

In a similar fashion extract the files, enter the directory and run $ ./configure   –disable-silex. I had never problems with that and after a succesfull configuration the make all install will put the libraries and include files under the directory where you extracted silo, for example ../silo-4.7.2.

3) Installation of Parflow

Extract the zip file. Lets say this is the directory $ ../parflow.693. Go to pfsimulator cd pfsimulator. Run the configure command with the following options if you want clm and mpi

./configure –prefix=${HOME}/Downloads/PARFLOW/parflow.693 –enable-timing –with-clm –with-silo=${HOME}/Downloads/PARFLOW/silo-4.7.2 –with-hypre=${HOME}/Downloads/PARFLOW/hypre-2.9.0b/src/hypre –with-amps=mpi1

To keep things a bit organized I had extracted all individual libraries under the directory ${HOME}/Downloads/PARFLOW/.  The configure step went pretty smoothly in every attempt I have made so far.

Next to build parflow run $ make install. Under ubuntu you might get errors at the very end of the building process related to gfortran and m libraries. This is probably a bug in the configuration process and you need to edit manually the Makefile.config under the config folder. If your current directory is the ../pfsimulator do the following: $ gedit config/Makefile.config. Search for a line that starts with LDLIBS    = $(LDLIBS_EXTRA)  (Note this is a very long line).

-edits required in Makefile.config

In this line you may see a gfortran m. Change those to -lgfortran -lm. Further right on the same line you may see two -l -l.  Those probably are the -ls that where missing. Anyway now delete them. Keep going right you may see some gfortran and m that they apart from their -ls i.e. -l gfortran -l m. Remove the spaces between them.

Save the file, cross fingers and rerun $ make install. (DO NOT RERUN .configure). If for any reason you need to rerun configure, the process will generate the buggy file and you need to edit again.

This hopefully will finish the installation of parflow successfully.

4) Installation of pftools

Enter the pftools directory. If you are under pfsimulator then do $ cd ../pftools. Run configure with the following options

$ ./configure –prefix=${HOME}/Downloads/PARFLOW/parflow.693 –with-silo=${HOME}/Downloads/PARFLOW/silo-4.7.2  –with-amps=mpi1.


Depending on the TCL installation the configuration might fail to find TCL even if the command tclsh works perfectly for you.

If configuration was succesfull ignore the following paragraph.

Force configure to find your TCL installation

To overcome this you would have to edit the configure file under the pftools directory. To understand what edits you need to do, lets first have a look to see what the scripts attempts to do:

Selection_002

 

Line 9263: The script will loop through the folders /usr and usr/local and attempt to find the file tcl.h under various locations. For example under usr/include (line 9266) or usr/include tcl8.4 (9270) etc. In my case tcl.h was under  /usr/lincude/tcl therefore I added an extra elseif statement which would make the configure script finding my location. My edits are highlighted in the red rectangle.

This will set the variables tcl_PREFIX = /usr and tcl_INCLUDES =-I${tcl_PREFIX}/include/tcl.

Next configure will attempt to find the tcl.so library. Below is the code in the configure script that does that

Selection_003

 

The code has already set tcl_PREFIX to a value depending where the tcl.h was found. Next will look into various folders under the ${tcl_PREFIX} to find the files with names libtcl8.4.so or libtcl.so etc. In my case the tcl.so was under the ackward folder /usr/lib/x86_64-linux-gnu. To force configure script find my tcl I added the lines in the red rectangle.

There is stil on final edit to make. Just right after the above else if statements end there is the following snippet

Selection_004

 

Note that this is how it looks like after I edited according to my needs. I just added the  x86_64-linux-gnu after the lib.

A footnote here: You need to be able to locate the folders that contain the tcl.h and tcl.so files. If you are new linux user like me you migh find it very hard to track down those files. Here are few options: i)locate file ii) whereis file iii) and the best of all apt-file search file (Note that you may need to install the apt-file tool first)

After those edits you should be able at least to complete successfully the configure step.

Next run $ make install.

If  make install failed during parflow building, then it is very likely that this make install will also fail. Hopefully for the very same reasons. Therefore follow the steps above. However make sure you are editing the correct file. Assuming you are into pftools folder, do

$ gedit config/Makefile.config 

and make the same edits.

Rerun make install and Voila!! You just finish a local parflow installation.

5) Test

To run parflow you need to have the environmental variable PARFLOW_DIR specified. There are quite a few options about this with the simplest being every time you open a terminal run

$ export PARFLOW_DIR=${HOME}/Downloads/PARFLOW/parflow.693.

You need of course to change the path according to your preferences.

Under the  ${PARFLOW_DIR}/test directory you can run a simple example such as

$ tclsh default_single.tcl 1 1 1

or try something more complicated under ${PARFLOW_DIR}/test/washita/tcl_scripts

$ tclsh Dist_Forcings.tcl

$ tclsh LW_Test.tcl