Skip to content
Snippets Groups Projects
Commit 0bdcc7d6 authored by Jean-Baptiste Keck's avatar Jean-Baptiste Keck
Browse files

removed intro checkpoint

parent 27257f06
No related branches found
No related tags found
No related merge requests found
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
%% Cell type:markdown id: tags:
# HySoP: Hybrid Simulation with Particles
HySoP is a library dedicated to high performance flow simulation based on particle methods, on hybrid architectures with multiple compute devices including CPUs, GPUs and MICs.
The library is mainly written in Python (high level functionnalities) on the top of Fortran, C++ and OpenCL backends.
## How to use HySoP
The problem to be solved must be described using Python 2.7 language either interactively or in a python script.
If you are not at ease with this language, we strongly encourage you to check one of the numerous python tutorials available on the web. Try for example https://docs.python.org/2/tutorial/. A basic understanding of numpy may also be useful : http://www.numpy.org.
Numpy is the python package for scientific computing on which HySoP relies, especially for arrays handling.
Interactive session is very useful for tests, basic understanding of hysop functionnalities but real simulation must be executed by using a script.
## Quick start
In this quick introduction we will introduce the main data structures of HySoP.
%% Cell type:code id: tags:
``` python
# First we import HySoP and some types we will need for this tutorial
# We will also need Numpy.
import hysop
from hysop import Box, Field
import numpy as np
```
%% Cell type:markdown id: tags:
### Describing the physical domain
The first thing to do is to create a physical domain where the simulation will take place. At this time the only type of domain available are $n$-dimensional boxes. A box has an origin $X_0=(x_0,\cdots,x_{n-1})$ and a length $L=(L_0, \cdots, L_{n-1})$. By default a unit box will be returned $X_0 = (0,\cdots,0)$ and $L=(1,\cdots,1)$. A domain also provide information about its boundary conditions.
%% Cell type:code id: tags:
``` python
# The 2D default Box
domain = Box(dim=2)
print domain
```
%% Output
Box::d0 | 2D rectangular box domain:
*origin: [0. 0.]
*max_pos: [1. 1.]
*length: [1. 1.]
*left boundary conditions: [PERIODIC(1), PERIODIC(1)]
*right boundary conditions: [PERIODIC(1), PERIODIC(1)]
%% Cell type:code id: tags:
``` python
# A custom box
domain = Box(length=(2*np.pi, 2*np.pi))
print domain
```
%% Output
Box::d1 | 2D rectangular box domain:
*origin: [0. 0.]
*max_pos: [6.28318531 6.28318531]
*length: [6.28318531 6.28318531]
*left boundary conditions: [PERIODIC(1), PERIODIC(1)]
*right boundary conditions: [PERIODIC(1), PERIODIC(1)]
%% Cell type:markdown id: tags:
A Box, like many other types in HySoP, has a unique identifier called a tag that identifies any instance of the type uniquely. You can query object tags by using the $tag$ and $full\_tag$ attributes.
%% Cell type:code id: tags:
``` python
print 'domain.tag is {}'.format(domain.tag)
print 'domain.full_tag is {}.'.format(domain.full_tag)
```
%% Output
domain.tag is d1
domain.full_tag is Box::d1.
%% Cell type:markdown id: tags:
Of course, a Box has many other usefull attributes describing the physical domain:
%% Cell type:code id: tags:
``` python
for attr in ('dim','origin','length','periodicity'):
print 'domain.{} is {}.'.format(attr, getattr(domain, attr))
```
%% Output
domain.dim is 2.
domain.origin is [0. 0.].
domain.length is [6.28318531 6.28318531].
domain.periodicity is [ True True].
%% Cell type:markdown id: tags:
A full list of attributes along with their documentation can be retrieved by using the python help method:
%% Cell type:code id: tags:
``` python
help(Box) # or help(domain)
```
%% Output
Help on class Box in module hysop.domain.box:
class Box(BoxView, hysop.domain.domain.Domain)
| Box-shaped domain description.
|
| Method resolution order:
| Box
| BoxView
| hysop.domain.domain.DomainView
| hysop.tools.handle.TaggedObjectView
| hysop.domain.domain.Domain
| hysop.tools.handle.RegisteredObject
| hysop.tools.handle.TaggedObject
| __builtin__.object
|
| Methods defined here:
|
| view(self, topology_state)
| Return a view of this domain altered by some topology_state.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, length=None, origin=None, dim=None, lboundaries=None, rboundaries=None, **kwds)
| Create or get an existing Box from a dimension, length and origin with specified
| left and right boundary conditions.
|
| Parameters
| ----------
| length : array like of float, optional
| Box sides lengthes. Default = [1.0, ...]
| origin: array like of float, optional
| Position of the lowest point of the box. Default [0.0, ...]
| dim: int, optional
| Dimension of the box.
| lboundaries: array_like of BoundaryCondition
| Left boundary conditions.
| rboundaries: array_like of BoundaryCondition
| Right boundary conditions.
|
| Attributes
| ----------
| dim: int
| Dimension of the box.
| length : np.ndarray of HYSOP_REAL
| Box sides lengthes.
| origin: np.ndarray of HYSOP_REAL
| Position of the lowest point of the box.
| end: np.ndarray of HYSOP_REAL
| Position of the greatest point of the box.
| lboundaries: np.ndarray of BoundaryCondition
| Left boundary conditions.
| rboundaries: np.ndarray of BoundaryCondition
| Right boundary conditions.
| boundaries: tuple of np.ndarray of BoundaryCondition
| Left and right boundary conditions as a tuple.
| periodicity: np.ndarray of bool
| Numpy array mask, True is axis is periodic, else False.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset([])
|
| ----------------------------------------------------------------------
| Methods inherited from BoxView:
|
| long_description(self)
| Return a long description of this Box as a string.
|
| short_description(self)
| Return a short description of this Box as a string.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BoxView:
|
| boundaries
| Left and right boundary conditions as a tuple.
|
| end
| Position of the greatest point of the box.
|
| lboundaries
| Left boundary conditions.
|
| length
| Box sides lengthes.
|
| origin
| Position of the lowest point of the box.
|
| periodicity
| Numpy array mask, True is axis is periodic, else False.
|
| rboundaries
| Right boundary conditions.
|
| ----------------------------------------------------------------------
| Methods inherited from hysop.domain.domain.DomainView:
|
| __eq__(self, other)
|
| __hash__(self)
|
| __ne__(self, other)
|
| __str__(self)
| Equivalent to self.long_description()
|
| current_task(self)
| Get task number of the current mpi process.
|
| is_on_task(self, params)
| Test if the current process corresponds to param task.
|
| print_topologies(self)
| Print all topologies registered on the domain.
|
| task_on_proc(self, parent_rank)
| Get task identifier for a given mpi process (parent communicator rank).
|
| ----------------------------------------------------------------------
| Data descriptors inherited from hysop.domain.domain.DomainView:
|
| dim
| Return the dimension of the domain.
|
| domain
| Return the domain on which the view is on.
|
| frame
| Get symbolic frame associated to this domain.
|
| parent_comm
| Return the parent communicator used to create this domain.
|
| parent_rank
| Return the rank of the process in the parent communicator.
|
| proc_tasks
| Return mapping between mpi process rank and task identifier.
|
| registered_topologies
| Return the dictionary of all topologies already built on this domain,
| with topology ids as keys and :class:`~hysop.topology.topology.Topology` as values.
|
| task_comm
| Return the communicator that owns the current process.
| This is the sub-communicator which has been obtained by splitting.
| the parent communicator by colors (proc_tasks).
|
| task_rank
| Return the rank of the process in the task communicator.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from hysop.domain.domain.DomainView:
|
| __metaclass__ = <class 'abc.ABCMeta'>
| Metaclass for defining Abstract Base Classes (ABCs).
|
| Use this metaclass to create an ABC. An ABC can be subclassed
| directly, and then acts as a mix-in class. You can also register
| unrelated concrete classes (even built-in classes) and unrelated
| ABCs as 'virtual subclasses' -- these and their descendants will
| be considered subclasses of the registering ABC by the built-in
| issubclass() function, but the registering ABC won't show up in
| their MRO (Method Resolution Order) nor will method
| implementations defined by the registering ABC be callable (not
| even via super()).
|
| ----------------------------------------------------------------------
| Methods inherited from hysop.tools.handle.TaggedObjectView:
|
| __init__(self, obj_view=None, **kwds)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from hysop.tools.handle.TaggedObjectView:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| full_tag
| Unique tag of the underlying object view with cls information.
|
| id
| Unique id of the underlying object view.
|
| tag
| Unique tag of the underlying object view.
|
| ----------------------------------------------------------------------
| Methods inherited from hysop.domain.domain.Domain:
|
| register_topology(self, topo)
| Register a new topology on this domain.
| Do nothing if an equivalent topology is already
| in the list.
|
| remove_topology(self, topo)
| Remove a topology from the list of this domain.
| Do nothing if the topology does not exist in the list.
|
| ----------------------------------------------------------------------
| Methods inherited from hysop.tools.handle.RegisteredObject:
|
| __del__(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from hysop.tools.handle.RegisteredObject:
|
| obj_initialized
| Return the object initialization state.
%% Cell type:markdown id: tags:
### Creating variables
Now that we have a domain defined, we can define named continuous scalar and vector fields.
In HySoP, a continuous field is an abstract object which represents the usual vector field, in mathematical sense, i.e some function which associates a scalar or a vector to each point of the space.
Such objects are used as input and/or output variables for continuous operators and must be defined with at least:
* a name, compulsory (required for i/o).
* a domain: the physical domain of definition of the field.
The underlying datatype that will be used uppon discretization can also be specified.
By default Fields are set to datatype HYSOP_REAL wich will be either np.float32 (single precision floating point) or np.float64 (double precision floating point) depending on HySoP build configuration. There are no restrictions on the datatypes, for example all integer and complex datatypes can also be specified.
For a domain of dimension $n$, scalar fields $s: \mathbb{R}^n \rightarrow \mathbb{R}$ are defined like this:
%% Cell type:code id: tags:
``` python
from hysop.constants import HYSOP_REAL
print 'HYSOP_REAL is {}.\n'.format(HYSOP_REAL)
field0 = Field(name='F0', domain=domain)
field1 = Field(name='F1', domain=domain, dtype=np.int32)
print field0
print field1
```
%% Output
HYSOP_REAL is <type 'numpy.float64'>.
Field (id=139994599482576, tag=f7)
Field::f0
*name: F0
*pname: F0
*dim: 2
*nb_components: 1
*dtype: float64
*initial values: (0, 0)
*topology tags: []
Field (id=139994599331856, tag=f8)
Field::f1
*name: F1
*pname: F1
*dim: 2
*nb_components: 1
*dtype: int32
*initial values: (0, 0)
*topology tags: []
%% Cell type:markdown id: tags:
Vector fields are created using either the is_vector or the nb_components parameter. is_vector corresponds to specifying nb_components to the number of dimensions of the domain $f(x): \mathbb{R}^n \rightarrow \mathbb{R}^n$ while the more general nb_components parameter allows to specify $g(x): \mathbb{R}^n \rightarrow \mathbb{R}^m$.
%% Cell type:code id: tags:
``` python
field2 = Field(name='V0', domain=domain, is_vector=True)
field3 = Field(name='V1', domain=domain, nb_components=4)
print field2
print field3
```
%% Output
Field (id=139994598533968, tag=f9)
Field::f2
*name: V0
*pname: V0
*dim: 2
*nb_components: 2
*dtype: float64
*initial values: (0, 0)
*topology tags: []
Field (id=139994599539152, tag=f10)
Field::f3
*name: V1
*pname: V1
*dim: 2
*nb_components: 4
*dtype: float64
*initial values: (0, 0)
*topology tags: []
%% Cell type:markdown id: tags:
### Discrete Fields
Now that we have a domain and fields, we can discretize them.
First we chose the shape of discretization (number of points in each directions).
Here we will chose a 8x4 discretization shape.
%% Cell type:code id: tags:
``` python
npoints = (8,4)
field0.discretize(npoints)
```
%% Output
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-4-1829bf9e4cf2> in <module>()
AttributeError Traceback (most recent call last)
<ipython-input-12-1829bf9e4cf2> in <module>()
1 npoints = (8,4)
----> 2 field0.discretize(npoints)
NameError: name 'field0' is not defined
/home/keckj/Documents/hysop/hysop/fields/continuous_field.py in discretize(self, topology, topology_state)
260 """
261 from hysop.fields.discrete_field import DiscreteField
--> 262 topology_state = first_not_None(topology_state, topology.default_state())
263 check_instance(topology, Topology)
264 check_instance(topology_state, TopologyState)
AttributeError: 'tuple' object has no attribute 'default_state'
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment