# 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 wxmaxima program. This provides a “document based” interface to Maxima and one can mix regular text (and equations) with Maxima interactions.

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/3d packages. Chapter 4 of this manual describes the draw packages. To get plotting 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. ## Note to developers on maximum default available memory with sbcl LISP compiler¶ Depending on which LISP compiler Maxima is using, by default, the compiler may not be able to claim/use all of the RAM on your computer. To change this a developer needs to edit the “maxima” executable themselves. On MacOS go to the following directory (assuming you have installed Maxima in your Applications): cd /Applications/Maxima.app/Contents/Resources/opt/bin  Once in this directory, with your favorite text editor, open up the file maxima. Search for the specific LISP compiler being used. For example, the most common LISP compiler amongst the Gkeyll development team is sbcl. You should see a conditional statement like: elif [ "$MAXIMA_LISP" = "sbcl" ]; then


within the conditional add:

MAXIMA_LISP_OPTIONS+="--dynamic-space-size 100000"


or a larger number depending on the size of your RAM.