On use of the Maxima CAS

Throughout Gkyl a large amount of Lua and C++ code is automatically pre-generated using the Maxima computer algebra system (CAS). Maxima is free and has a vast amount of features. For some of the calculations the use of a CAS is essential as the algebra, even though relatively easy, is very tedious, needing thousands of evaluations of various integrals etc.

A very pleasant front-end for Maxima is provided by the TeXmacs program. When Maxima is run through TeXmacs one can mix regular text (and equations) with Maxima interactions. Other front-ends to Maxima also exist, although I have not tested or used any of them.

A very comprehensive physics oriented tutorial is Maxima by Example by Edwin Woollett.

All Maxima code is checked into the gkyl/cas-scripts directory. To use the Maxima code in this directory you need to tell Maxima to find it. To do this, create the directory (if it does not exist already):

mkdir $HOME/.maxima

In this create or edit the file called “maxima-init.mac” and add the following lines to it:

file_search_maxima: append(file_search_maxima,
  ["PATH_TO_YOUR_GKYL/gkyl/cas-scripts/###.{lisp,mac}"]) $

Where “PATH_TO_YOUR_GKYL” is the full path to the location where your gkyl source lives. Start/restart Maxima. Once you do this, then the Maxima code in the cas-scripts directory can be loaded, for example as:

load("modal-basis")$
load("basis-precalc/basisSer1x1v")$

This will load the code to work with Modal basis functions and the serendipity basis sets in 1x1v into your Maxima session/code.

To make plots on Maxima, you can use the excellent draw2d package. To get this to work you need to install Gnuplot and set some paths properly. On a Mac, the maxima-init.mac file looks like:

load("draw")$
gnuplot_command: "/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot" $
set_plot_option([gnuplot_term, "qt"],
  [gnuplot_preamble, "set object rectangle from screen 0,0 to screen 1,1 behind fillcolor rgb 'white' fillstyle solid noborder"]
  )$

set_draw_defaults(terminal=qt,
  user_preamble="set object rectangle from screen 0,0 to screen 1,1 behind fillcolor rgb 'white' fillstyle solid noborder",
  nticks=200,
  line_width=2
 )$

file_search_maxima: append(file_search_maxima,
  ["PATH_TO_YOUR_GKYL/gkyl/cas-scripts/###.{lisp,mac}"]) $

Again, remember “PATH_TO_YOUR_GKYL” is the full path to the location where your gkyl source lives. On Linux or Windows you will need to experiment with paths and settings to get plots to work.