KADATH SPECTRAL SOLVER

Tutorial 1 : Basics

 Print Hello

Download the program starter.cpp in Kadath/tutorials and generate the executable using the instructions given on the website.

The code will not do anything related to Kadath but it will check you are able to link things properly.

Construct an Array

Arrays are constructed using templates. They can be of any dimension. For 1, 2 or 3 dimensions one can use direct constructors.

For arbitrary dimensions, one must pass the sizes of the array using the class Dim_array.

Various examples are given below

// 1d array of 4 integers
Array<int> onedint (4) ;

// 2d array of (8x4) doubles :
Array<double> twoddoubles (8, 4) ;

// Array of dimension 5 (of booleans), constructed by a Dim_array :
Dim_array dimensions(5) ;
 // The size of the various dimensions must be initialized
for (int i=0 ; i<5 ; i++)
       dimensions.set(i) = i+1 ;
Array<bool> multidbool (dimensions) ;

Using Arrays

Arrays are constructed uninitialized. They can be given a single value for the whole array or be accessed element by elements, using the set function.

If the dimension is arbitrary, they must be accessed via a class called Index.

The read only access is just the operator().

// 1d array 
for (int i=0 ; i<4 ; i++)
      onedint.set(i) = i ;
cout << onedint << endl ; // Print the whole Array`enter code here`

// 2d array, same value everywhere
 twoddoubles = 2.3 ;
// Printing one particular element
cout << twoddoubles(0, 2) << endl ;

// Array of dimension 5  :
Index pos(dimensions) ;
// By default it is affected to the first element
// Modify the index in dimension 2
pos.set(2) = 1 ;
cout << pos << endl ;
// pos now points at one particular element of the Array
multidbool = false ; // Everything is false
multidbool.set(pos) = true ; // but this one...

Looping on arrays

Indexes have a member function inc that increases the Index by one unit. It then returns TRUE if the result is still in the Array and FALSE if not (i.e. if one has reached the end of the Array). It is used extensively to loop on all the elements of an array.

// Sets the index to the first index
pos.set_start() ;
// Loop
do {
      if (multidbool(pos)) {
                 cout << "True value found at " << endl ;
                 cout << pos << endl ;
       }
     }
while (pos.inc()) ;