Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
cbfce836
Commit
cbfce836
authored
Apr 27, 2022
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Improve example 1 and prepare next section
parent
cfe1c1ff
No related branches found
No related tags found
1 merge request
!145
git subrepo clone git@gitlab.com:OlMon/org-themes.git packages/org-themes
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/userdoc.org
+65
-39
65 additions, 39 deletions
doc/userdoc.org
with
65 additions
and
39 deletions
doc/userdoc.org
+
65
−
39
View file @
cbfce836
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
* Introduction
* Introduction
~pugs~[fn:pugs-def] is a general purpose solver collection
designed
to
~pugs~[fn:pugs-def] is a general purpose solver collection
built
to
approximate solutions of partial differential equations. It is mainly
approximate solutions of partial differential equations. It is mainly
(but not only) designed to deal with hyperbolic problems using
(but not only) designed to deal with hyperbolic problems using
finite-volume methods.
finite-volume methods.
...
@@ -42,7 +42,7 @@ assembled together through a high-level language (a DSL[fn:DSL-def]
...
@@ -42,7 +42,7 @@ assembled together through a high-level language (a DSL[fn:DSL-def]
close to the mathematics) to build more complex solvers. This approach
close to the mathematics) to build more complex solvers. This approach
is inspired by the success of [[http://freefem.org][FreeFEM]], which use a similar approach.
is inspired by the success of [[http://freefem.org][FreeFEM]], which use a similar approach.
Before detailing the leading concepts and choices we have made to
Before detailing the leading concepts and choices
that
we have made to
develop ~pugs~, we give a simple example that should illustrate the
develop ~pugs~, we give a simple example that should illustrate the
capabilities of the code.
capabilities of the code.
...
@@ -58,7 +58,7 @@ mesh nodes according to a user defined vector field $T: \mathbb{R}^2
...
@@ -58,7 +58,7 @@ mesh nodes according to a user defined vector field $T: \mathbb{R}^2
import writer;
import writer;
let pi:R, pi = acos(-1);
let pi:R, pi = acos(-1);
let theta:R^2 -> R, x -> 0.5*pi*(x[0]
+1)*(
x[0]-1)*(x[1]
+1)*(
x[1]-1);
let theta:R^2 -> R, x -> 0.5*pi*(x[0]
*
x[0]-1)*(x[1]
*
x[1]-1);
let M:R^2 -> R^2x2, x -> (cos(theta(x)), -sin(theta(x)),
let M:R^2 -> R^2x2, x -> (cos(theta(x)), -sin(theta(x)),
sin(theta(x)), cos(theta(x)));
sin(theta(x)), cos(theta(x)));
let T: R^2 -> R^2, x -> x + M(x)*x;
let T: R^2 -> R^2, x -> x + M(x)*x;
...
@@ -68,25 +68,31 @@ mesh nodes according to a user defined vector field $T: \mathbb{R}^2
...
@@ -68,25 +68,31 @@ mesh nodes according to a user defined vector field $T: \mathbb{R}^2
write_mesh(gnuplot_writer("transformed", 0), m);
write_mesh(gnuplot_writer("transformed", 0), m);
#+END_SRC
#+END_SRC
The example is quite easy to read
:
The example is quite easy to read
.
-
f
irst, some *modules* are loaded: the ~mesh~ module, which contains
-
F
irst, some *modules* are loaded: the ~mesh~ module, which contains
some
some
mesh manipulation functions. The ~math~ module
which
provides a
mesh manipulation functions. The ~math~ module provides a
set of
set of
classical mathematical functions ($\sin$, $\cos$,
classical mathematical functions ($\sin$, $\cos$,
...). The ~writer~
...). The ~writer~
module is used to save meshes or discrete functions
module is used to save meshes or discrete functions
to files using
to files using
various formats.
various formats.
- The second block of data defines variables of different kind
- The second block of data defines variables of different kind
- ~pi~ is a real value that is initialized by an approximation of $\pi$.
- ~pi~ is a real value that is initialized by an approximation of $\pi$.
- ~theta~ is the real value function $\theta$ defined by
- ~theta~ is the real value function $\theta$ defined by
$$\theta: \mathbb{R}^2 \to \mathbb{R},\quad\mathbf{x} \mapsto \frac{\pi}{2} (x_0+1)(x_0-1)(x_1+1)(x_1-1) $$
\begin{equation*}
\theta: \mathbb{R}^2 \to \mathbb{R},\quad\mathbf{x} \mapsto
\frac{\pi}{2} (x_0^2-1)(x_1^2-1)
\end{equation*}
- ~M~ is the $\mathbb{R}^{2\times2}$ matrix field $M$ defined by
- ~M~ is the $\mathbb{R}^{2\times2}$ matrix field $M$ defined by
$$M: \mathbb{R}^2 \to \mathbb{R}^{2\times2},\quad\mathbf{x} \mapsto \begin{pmatrix}
\begin{equation*}
M: \mathbb{R}^2 \to \mathbb{R}^{2\times2},\quad\mathbf{x} \mapsto
\begin{pmatrix}
\cos(\theta(\mathbf{x})) & -\sin(\theta(\mathbf{x})) \\
\cos(\theta(\mathbf{x})) & -\sin(\theta(\mathbf{x})) \\
\sin(\theta(\mathbf{x})) & \cos(\theta(\mathbf{x}))
\sin(\theta(\mathbf{x})) & \cos(\theta(\mathbf{x}))
\end{pmatrix}$$
\end{pmatrix}
\end{equation*}
- ~T~ is the vector field $T$ defined by
- ~T~ is the vector field $T$ defined by
$$
\begin{equation*}
T: \mathbb{R}^2 \to \mathbb{R}^2, \quad\mathbf{x} \mapsto (I+M(\mathbf{x}))\mathbf{x}
T: \mathbb{R}^2 \to \mathbb{R}^2, \quad\mathbf{x} \mapsto (I+M(\mathbf{x}))\mathbf{x}
$$
\end{equation*}
- Finally ~m~ is defined as the uniform Cartesian mesh grid of
- Finally ~m~ is defined as the uniform Cartesian mesh grid of
$]-1,1[^2$. The last argument: ~(20,20)~ sets the number of cells in
$]-1,1[^2$. The last argument: ~(20,20)~ sets the number of cells in
each direction: $20$.
each direction: $20$.
...
@@ -95,7 +101,7 @@ The example is quite easy to read:
...
@@ -95,7 +101,7 @@ The example is quite easy to read:
variable ~m~, the old one was not modified in the process. It is
variable ~m~, the old one was not modified in the process. It is
important to already have in mind that the ~pugs~ language *does not
important to already have in mind that the ~pugs~ language *does not
allow* the modifications of values of *non-basic* types. This is
allow* the modifications of values of *non-basic* types. This is
discussed in the section [[
basic
s]].
discussed in the section [[
variable-type
s]].
- Finally, the last block consists in saving the obtained mesh in a
- Finally, the last block consists in saving the obtained mesh in a
~gnuplot~ file. The result is shown on Figure [[fig:intro-example]].
~gnuplot~ file. The result is shown on Figure [[fig:intro-example]].
...
@@ -117,31 +123,51 @@ The example is quite easy to read:
...
@@ -117,31 +123,51 @@ The example is quite easy to read:
#+ATTR_HTML: :width 300px;
#+ATTR_HTML: :width 300px;
#+RESULTS: intro-transform-mesh-img
#+RESULTS: intro-transform-mesh-img
* Basics<<basics>>
Even if this first example is very simple, some key aspects can
already be discussed.
- There is no predefined constant in ~pugs~. Here a value is provided
for ~pi~.
- There are two kinds of variable in ~pugs~: variables of basic types
and variable of high-level types. This two kinds of variable behave
almost the same but one must know their differences to understand
better the underlying mechanisms and choices that we made. See
[[variable-types]] for details.
- Also, there are two types of function: *user-defined* functions and
*builtin* functions. In this example, ~theta~, ~M~ and ~T~ are user-defined
functions. All other functions (~cos~, ~cartesian2dMesh~,...) are
builtin functions and are generally defined when importing a
module. These functions behave similarly, one should refer to
[[functions]] for details.
- The language does not allow low-level manipulations of high-level
type variables. This means that for instance, one cannot modify a
specific cell value of a piecewise constant function. This allows to
write algorithms (within the pugs language) that can be executed in
parallel naturally. Observe that the resulting mesh of the previous
does not depend on the number of ~MPI~ processes nor on the number of
threads used while running ~pugs~.
** Hello world!
* Language
** Variables
*** Types<<variable-types>>
**** Basic types
**** High-level types
*** Life time
** Statements
** Functions<<functions>>
*** User-defined functions
*** Builtin functions
*** Python
#+BEGIN_SRC python :exports both :results output
print ("hellow orld!")
#+END_SRC
*** Pugs
In this simple example, one defines the function $f:\mathbb{R} \to \mathbb{R}, x \mapsto 2\sin(x)$
#+NAME: hello-world
#+BEGIN_SRC pugs :exports both :results output
import math;
let f: R -> R, x -> 2*sin(x);
cout << "Hello world!\n";
cout << "f(12) = " << f(12) << "\n";
#+END_SRC
Then one prints ~Hello world!~ and the evaluation of $f$ at position $12$.
#+RESULTS: hello-world
* The end
#+BEGIN_SRC python :exports both :results output
print ("hello world!")
#+END_SRC
[fn:pugs-def] ~pugs~: Parallel Unstructured Grid Solvers
[fn:pugs-def] ~pugs~: Parallel Unstructured Grid Solvers
[fn:MPI-def] ~MPI~: Message Passing Interface
[fn:MPI-def] ~MPI~: Message Passing Interface
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment