The polylib library, for which
the
source code and header file can be found
here, is a usefull
library when doing
the exercises from the book. For example it can calculate the location
of the Gauss-Lobatto-Legendre quadrature points and weights and the
value of different polynomials in these points. You have to download
the polylib.c and polylib.h files to the same directory where your code
is. After I did
this I compiled using the
command:
g++ -c polylib.c
which makes an object file (polylib.o) that
is ready for final compilation. Before the final compilation you also
have to make your code into an object file, in my case for the first
exercise this was done using the command:
g++ -c exercise1.cpp
The
final compilation can now be done using:
g++ exercise1 exercise1.o
polylib.o
which creates the executable exercise1. To run this just type exercise1
and enter (of course in the right directory). Be sure to include
polylib.h (together with, for instance, iostream, stdio.h and math.h).
When you now use line:
using namespace polylib;
in your code you can
use the functions from polylib (also don't forget:
using
namespace std;
for the
cout
command). The functions of
polylib.c are documented
here
and
those of
polylib.h
here.
It
is expected that the (vector) variables are defined as pointers.
Make sure that you allocate enough
memoryspace to the different pointervariables because strange
things can happen when this is not the case.
Making use of the different functions of polylib is rather
straightforward. If you take a look at the documentation of
polylib.c you see that for example the Gauss-Lobatto-Legendre (GLL)
zero's and weights can be determined by using the function zwglj and
inserting
alpha=beta=0
.
As can be seen in
a define statement in the
documentation of polylib.h this can also be done via the function
zwgll
(which automatically states
alpha=beta=0
). The
function
zwgll
expects
as arguments a double precision pointer, call it
z
,
which it fills with
the GLL
points, another double precision pointer
w
which it fills with the GLL weights
and an integer,
np
, the number of integration
points. It is not
necessary to declare the functions. So a line of code filling pointers
z
and
w
can look like this:
zwgll(z, w, np);
A code using this function can be found
here, it is my
solution to exercise 1 from chapter 2 of the book. Here you can already
take a look at how
the pointers are defined and how you allocate memoryspace to them. This
is however properly explained in
exercise 1.