pylbm.stencil.Stencil

class pylbm.stencil.Stencil(dico, need_validation=True)

Create the stencil of velocities used by the scheme(s).

The numbering of the velocities follows the convention for 1D and 2D.

Parameters
dicoa dictionary that contains the following key:value
  • dim : the value of the spatial dimension (1, 2 or 3)

  • schemesa list of dictionaries that contain

    the key:value velocities

[
    {
        'velocities': [...]
    },
    {
        'velocities': [...]
    },
    {
        'velocities': [...]
    },
    ...
]

Notes

The velocities for each schemes are defined as a Python list.

Examples

>>> s = Stencil({'dim': 1,
...              'schemes':[{'velocities': list(range(9))},],
...             })
>>> s
+---------------------+
| Stencil information |
+---------------------+
    - spatial dimension: 1
    - minimal velocity in each direction: [-4]
    - maximal velocity in each direction: [4]
    - information for each elementary stencil:
        stencil 0
            - number of velocities: 9
            - velocities
                (0: 0)
                (1: 1)
                (2: -1)
                (3: 2)
                (4: -2)
                (5: 3)
                (6: -3)
                (7: 4)
                (8: -4)
>>> s = Stencil({'dim': 2,
...              'schemes':[
                               {'velocities': list(range(9))},
...                            {'velocities': list(range(49))},
...                        ],
...            })
>>> s
+---------------------+
| Stencil information |
+---------------------+
    - spatial dimension: 2
    - minimal velocity in each direction: [-3 -3]
    - maximal velocity in each direction: [3 3]
    - information for each elementary stencil:
        stencil 0
            - number of velocities: 9
            - velocities
                (0: 0, 0)
                (1: 1, 0)
                (2: 0, 1)
                (3: -1, 0)
                (4: 0, -1)
                (5: 1, 1)
                (6: -1, 1)
                (7: -1, -1)
                (8: 1, -1)
        stencil 1
            - number of velocities: 49
            - velocities
                (0: 0, 0)
                (1: 1, 0)
                (2: 0, 1)
                (3: -1, 0)
                (4: 0, -1)
                (5: 1, 1)
                (6: -1, 1)
                (7: -1, -1)
                (8: 1, -1)
                (9: 2, 0)
                (10: 0, 2)
                (11: -2, 0)
                (12: 0, -2)
                (13: 2, 2)
                (14: -2, 2)
                (15: -2, -2)
                (16: 2, -2)
                (17: 2, 1)
                (18: 1, 2)
                (19: -1, 2)
                (20: -2, 1)
                (21: -2, -1)
                (22: -1, -2)
                (23: 1, -2)
                (24: 2, -1)
                (25: 3, 0)
                (26: 0, 3)
                (27: -3, 0)
                (28: 0, -3)
                (29: 3, 3)
                (30: -3, 3)
                (31: -3, -3)
                (32: 3, -3)
                (33: 3, 1)
                (34: 1, 3)
                (35: -1, 3)
                (36: -3, 1)
                (37: -3, -1)
                (38: -1, -3)
                (39: 1, -3)
                (40: 3, -1)
                (41: 3, 2)
                (42: 2, 3)
                (43: -2, 3)
                (44: -3, 2)
                (45: -3, -2)
                (46: -2, -3)
                (47: 2, -3)
                (48: 3, -2)

get the x component of the unique velocities

>>> s.uvx
array([ 0,  1,  0, -1,  0,  1, -1, -1,  1,  2,  0, -2,  0,  2, -2, -2,  2,
        2,  1, -1, -2, -2, -1,  1,  2,  3,  0, -3,  0,  3, -3, -3,  3,  3,
        1, -1, -3, -3, -1,  1,  3,  3,  2, -2, -3, -3, -2,  2,  3])

get the y component of the velocity for the second stencil

>>> s.vy[1]
array([ 0,  0,  1,  0, -1,  1,  1, -1, -1,  0,  2,  0, -2,  2,  2, -2, -2,
        1,  2,  2,  1, -1, -2, -2, -1,  0,  3,  0, -3,  3,  3, -3, -3,  1,
        3,  3,  1, -1, -3, -3, -1,  2,  3,  3,  2, -2, -3, -3, -2])
Attributes
dimint

the spatial dimension (1, 2 or 3).

unique_velocitiesNumPy array

array of all velocities involved in the stencils. Each unique velocity appeared only once.

uvxNumPy array

the x component of the unique velocities.

uvyNumPy array

the y component of the unique velocities.

uvzNumPy array

the z component of the unique velocities.

unumNumPy array

the numbering of the unique velocities.

vmaxint

the maximal velocity in norm for each spatial direction.

vminint

the minimal velocity in norm for each spatial direction.

vmax_fullint

the maximal velocity in norm for each spatial direction.

nstencilsint

the number of elementary stencils.

nvlist of integers

the number of velocities for each elementary stencil.

vlist of velocities

list of all the velocities for each elementary stencil.

vxNumPy array

vx[k] the x component of the velocities for the stencil k.

vyNumPy array

vy[k] the y component of the velocities for the stencil k.

vzNumPy array

vz[k] the z component of the velocities for the stencil k.

numNumPy array

num[k] the numbering of the velocities for the stencil k.

nv_ptrlist of integers

used to obtain the list of the velocities involved in a stencil. For instance, the list for the kth stencil is v[nv_ptr[k]:nv_ptr[k+1]]

unvtotint

the number of unique velocities involved in the stencils.

Methods

append()

clear()

copy()

count()

extend()

extract_dim(dico)

Extract the dimension from the dictionary

get_all_velocities(self[, scheme_id])

get all the velocities for all the stencils in one array

get_symmetric(self[, axis])

get the symmetric velocities.

index()

Raises ValueError if the value is not present.

insert()

L.insert(index, object) – insert object before index

is_symmetric(self)

check if all the velocities have their symmetric.

pop()

Raises IndexError if list is empty or index is out of range.

remove()

Raises ValueError if the value is not present.

reverse()

L.reverse() – reverse IN PLACE

sort()

visualize(self[, viewer_mod, k, …])

plot the velocities