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

From Medusa: Coordinate Free Mehless Method implementation
Jump to: navigation, search
(Renamed the example file due to changes in the code.)
 
(One intermediate revision by one other user not shown)
Line 3: Line 3:
 
The idea of our examples is to present the functionality of the library in an accessible and incremental manner.  
 
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]].
 
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. <code>poisson_implicit_dirichlet_2D</code> and its corresponding
+
Each examples consists of a name, e.g. <code>poisson_dirichlet_2D</code> and its corresponding
* source code, e.g. <code>poisson_implicit_dirichlet_2D.cpp</code>
+
* source code, e.g. <code>poisson_dirichlet_2D.cpp</code>
* plot script, e.g. <code>poisson_implicit_dirichlet_2D.m</code>
+
* plot script, e.g. <code>poisson_dirichlet_2D.m</code>
 
Additional appropriately named input files might be present for more complicated examples and similarly named output files might be produced.  
 
Additional appropriately named input files might be present for more complicated examples and similarly named output files might be produced.  
 
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 examples and their plot scripts are intended to work out of the box,  so the reader can simply run the examples on their machine.
Line 11: Line 11:
 
they produce the figures the reader sees in the Examples category of this wiki.
 
they produce the figures the reader sees in the Examples category of this wiki.
  
Let us now illustrate the process of running an example <code>poisson_implicit_dirichlet_2D</code>.  
+
Let us now illustrate the process of running an example <code>poisson_dirichlet_2D</code>.  
  
 
First the example needs to be built (compiled). The building is done in the same <code>build/</code> directory
 
First the example needs to be built (compiled). The building is done in the same <code>build/</code> directory
 
where medusa was build. To build and run the example, simply execute
 
where medusa was build. To build and run the example, simply execute
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
make poisson_implicit_dirichlet_2D_run # builds and runs your example           
+
make poisson_dirichlet_2D_run # builds and runs your example           
 
</syntaxhighlight>
 
</syntaxhighlight>
 
to compile and run your example. On first compilation, the whole library might compile as well, if not compiled previously, so it might take longer than usual.
 
to compile and run your example. On first compilation, the whole library might compile as well, if not compiled previously, so it might take longer than usual.
Compiled binary used to run the example is placed next to the example source file. If only <code>make poisson_implicit_dirichlet_2D</code> (without _run) the
+
Compiled binary used to run the example is placed next to the example source file. If only <code>make poisson_dirichlet_2D</code> (without _run) the
 
example is built, but not run.
 
example is built, but not run.
  
Line 29: Line 29:
 
To run the built example again, go back to the initial folder where the source code for your example was, and run
 
To run the built example again, go back to the initial folder where the source code for your example was, and run
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
./poisson_implicit_dirichlet_2D
+
./poisson_dirichlet_2D
 
</syntaxhighlight>
 
</syntaxhighlight>
 
The output will be saved in the same folder as the binary and the source file.
 
The output will be saved in the same folder as the binary and the source file.
Line 43: Line 43:
 
Example command to be run from <code>poisson_equation</code> directory:
 
Example command to be run from <code>poisson_equation</code> directory:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
g++ -o poisson_implicit_dirichlet_2D poisson_implicit_dirichlet_2D.cpp -I ../../include -Wall -O3 -L ../../bin -lmedusa_standalone
+
g++ -o poisson_dirichlet_2D poisson_dirichlet_2D.cpp -I ../../include -Wall -O3 -L ../../bin -lmedusa_standalone
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
The compiled example can be run simply as
 
The compiled example can be run simply as
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
./poisson_implicit_dirichlet_2D
+
./poisson_dirichlet_2D
 
</syntaxhighlight>
 
</syntaxhighlight>
 
and plotted using the accompanying plot script.
 
and plotted using the accompanying plot script.
Line 54: Line 54:
  
 
Some more feature specific examples are found in the [http://e6.ijs.si/docs/ technical documentation] and in the unit tests.
 
Some more feature specific examples are found in the [http://e6.ijs.si/docs/ technical documentation] and in the unit tests.
 +
 +
Go back to [[Medusa#Examples|Examples]].

Latest revision as of 14:36, 2 March 2022

Go back to Examples.

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. poisson_dirichlet_2D and its corresponding

  • source code, e.g. poisson_dirichlet_2D.cpp
  • plot script, e.g. poisson_dirichlet_2D.m

Additional appropriately named input files might be present for more complicated examples and similarly named output files might be produced. 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 poisson_dirichlet_2D.

First the example needs to be built (compiled). The building is done in the same build/ directory where medusa was build. To build and run the example, simply execute

make poisson_dirichlet_2D_run  # builds and runs your example

to compile and run your example. On first compilation, the whole library might compile as well, if not compiled previously, so it might take longer than usual. Compiled binary used to run the example is placed next to the example source file. If only make poisson_dirichlet_2D (without _run) the example is built, but not run.

To build all examples, you can just run

make examples  # or "make examples_run" to also run them

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

./poisson_dirichlet_2D

The output will be saved in the same folder as the binary and the source file.

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

Standalone compilation

The examples can then be compiled manually using e.g. g++, provided that appropriate include and library paths are set and the medusa_standalone library is specified for linking.

Example command to be run from poisson_equation directory:

g++ -o poisson_dirichlet_2D poisson_dirichlet_2D.cpp -I ../../include -Wall -O3 -L ../../bin -lmedusa_standalone

The compiled example can be run simply as

./poisson_dirichlet_2D

and plotted using the accompanying plot script.


Some more feature specific examples are found in the technical documentation and in the unit tests.

Go back to Examples.