Difference between revisions of "Philosophy of examples and how to run them"

From Medusa: Coordinate Free Mehless Method implementation
Jump to: navigation, search
Line 1: Line 1:
The essence of our examples is to present the functionality of the library in an accessible and digestible manner. The examples present different solutions to problems ranging in difficulty from the simple [[Poisson's equation]] to [[Fluid mechanics]]. Accompanying each example are Matlab scripts which were used to produce the figures the reader meets throughout this section, both the scripts and examples are made to work as is, so the reader can simply run the examples on their machine.
+
The idea of our examples is to present the functionality of the library in an accessible and incremental manner.  
 +
The examples present different solutions to problems ranging in difficulty from the simple [[Poisson's equation]] to more specific examples, such as [[Fluid mechanics]].
 +
Each examples consists of a name, e.g. `todo` and its corresponding
 +
* source code, e.g. `todo.cpp`
 +
* plot script, e.g. `todo.m`
 +
Additional appropriately named input files might be present for more complicated examples.
 +
The examples and their plot scripts are intended to work out of the box, so the reader can simply run the examples on their machine.
 +
The procedure for running examples is simple and the same for all examples. The accompanying plot scripts can be run with Matlab or octave and
 +
they produce the figures the reader sees in the Examples category of this wiki.
  
The building is done in the `build/` directory. When you are in the folder where your example is located, run
+
Let us now illustrate the process of running an example named `example`.
 +
 
 +
First the example needs to be built (compiled). The building is done in the `build/` directory. When you are in the folder where your example (and a `CMakeLists.txt` file where it is registered) is located, run
 
<syntaxhighlight>
 
<syntaxhighlight>
mkdir -p build  # creates the directory build, of it does not exist
+
mkdir -p build  # creates the directory build, if it does not exist
 
cd build        # goes to that directory
 
cd build        # goes to that directory
 
cmake ..        # creates Makefiles
 
cmake ..        # creates Makefiles
make example    # builds your example          
+
make example    # builds your example (substitute "example" with an actual example name)         
 
</syntaxhighlight>
 
</syntaxhighlight>
to compile your example. Note that you only have to run cmake once, after that
+
to compile your example. Note that you only have to run `cmake` once, after that
only make is sufficient. Compiled binaries are placed into `bin/` folder and libraries are placed into `lib/`
+
only make is sufficient. Compiled binary used to run the example is placed into `bin/` folder and libraries are placed into `lib/`
 
folder.
 
folder.
  
To build all examples target you can just run (after running cmake at least once)
+
To build all examples, you can just run (after running cmake at least once)
 
<syntaxhighlight>
 
<syntaxhighlight>
 
make all
 
make all
 
</syntaxhighlight>
 
</syntaxhighlight>
  
To run the built example, go back to the examples folder and run
+
To run the built example, go back to the initial folder where the source code for your example was, and run
 
<syntaxhighlight>
 
<syntaxhighlight>
 
./bin/example
 
./bin/example
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
The output will be saved WHERE??
  
TODO: kje so outputi, kje so plot skripte...
+
After, just run the corresponding plot script and you should see a figure, usually showing the solution.

Revision as of 15:00, 3 August 2018

The idea of our examples is to present the functionality of the library in an accessible and incremental manner. The examples present different solutions to problems ranging in difficulty from the simple Poisson's equation to more specific examples, such as Fluid mechanics. Each examples consists of a name, e.g. `todo` and its corresponding

  • source code, e.g. `todo.cpp`
  • plot script, e.g. `todo.m`

Additional appropriately named input files might be present for more complicated examples. The examples and their plot scripts are intended to work out of the box, so the reader can simply run the examples on their machine. The procedure for running examples is simple and the same for all examples. The accompanying plot scripts can be run with Matlab or octave and they produce the figures the reader sees in the Examples category of this wiki.

Let us now illustrate the process of running an example named `example`.

First the example needs to be built (compiled). The building is done in the `build/` directory. When you are in the folder where your example (and a `CMakeLists.txt` file where it is registered) is located, run

mkdir -p build  # creates the directory build, if it does not exist
cd build        # goes to that directory
cmake ..        # creates Makefiles
make example    # builds your example (substitute "example" with an actual example name)

to compile your example. Note that you only have to run `cmake` once, after that only make is sufficient. Compiled binary used to run the example is placed into `bin/` folder and libraries are placed into `lib/` folder.

To build all examples, you can just run (after running cmake at least once)

make all

To run the built example, go back to the initial folder where the source code for your example was, and run

./bin/example

The output will be saved WHERE??

After, just run the corresponding plot script and you should see a figure, usually showing the solution.