The domains module : handle computation domain


Module domains provides three main objects:

  • Subdomain : dataclass for subdivisions of the computational domain

  • Obstacle : Subdomain subclass with custom boundary possibilities

  • Domain : Container for Subdomain objects


class fdgrid.domains.Domain(shape, data=None)[source]

Bases: object

Set of Subdomain objects.

Parameters
  • shape (Size of the domain. Must be a 2 elements tuple) –

  • data (list of Subdomain objects or coordinates) –

append(val, key=None)[source]

Append ‘val’ to the Domain object.

Parameters
  • val (The object to add to the instance.) – Must be a Subdomain object or a list/tuple of Subdomain objects

  • key (new key for val) –

autojoin(include_split=False)[source]

Automatically join domains that can be joined.

copy()[source]

Create copy of the instance.

static isjoinable(sub1, sub2, include_split=False)[source]

Check if sub1 and sub2 can be joined.

property ix

Return list of x coordinates.

property iz

Return list of z coordinates.

join(key1, key2, include_split=False, tag=None)[source]

Join key1 and key2 Subdomain objects.

keys()[source]

Return all keys of Domain instance.

mask()[source]

Create mask array of the domain.

periodic_bc(mask, axis)[source]

Arange subdomains to take into account periodic boundary condtions.

pop(n)[source]

Remove value of index n from the Domain object.

reset_keys()[source]

Reset all keys then attribute new ordered keys.

property rx

Return list of ranges (over Subdomain x coordinates).

property rz

Return list of ranges (over Subdomain z coordinates).

show(legend=False, fcolor='b', ecolor='y')[source]

Represent the Subdomains.

sort(inplace=False)[source]

Sort domains.

If inplace is True, Domain is sorted inplace. If inplace is False, return a new instance.

split(key, index, nbc=None, axis=None)[source]

Split ‘key’ subdomain.

Parameters
  • index (int|tuple|list) –

  • nbc (Only if index is a sequence. New bc for the domain defined by 'index') –

  • axis (0 or 1. Along which axis to split) –

steal(other, key, newkey=None)[source]

Steal key from other.

property sx

Return list of slices (over Subdomain x coordinates).

property sz

Return list of slices (over Subdomain z coordinates).

property xz

Return list of coordinates.

class fdgrid.domains.Obstacle(xz: tuple, bc: str = '....', key: str = '', axis: int = - 1, tag: str = '')[source]

Bases: fdgrid.domains.Subdomain

Obstacle object.

Parameters
  • xz (Coordinates of the Subdomain : left, bottom, right, top) –

  • bc (Boundary conditions. Must be a string of 4 characters among 'W|Z|V') –

  • key (Key of the subdomain. Optional) –

  • axis (0 or 1. The direction of the subdomain if relevant. Optional.) –

  • tag (str. The type of Subdomain. Optional) –

make_moving_bc(x, z, LOG=False)[source]

Construct moving boundaries.

set_moving_bc(*args)[source]

Set parameters for moving bc. For each moving bc of the obstacle, you can specify the parameters as a dictionnary containing the following optional keys :

Parameters
  • f (float, str) – frequency of the normal velocity.

  • A (float) – Amplitude of the normal velocity

  • phi (float) – Phase of the normal velocity

  • profile ({'sine', 'tukey'}) – Function for normal velocity profile construction

  • kwargs (dict) – optional arguments for profile

Note

profile argument can be:

  • ‘sine’ : sinus profile. kw: n - wavelength (default: 2 for half period)

  • ‘tukey’ : tapered cosine profile. kw: alpha - edge width (default: 0)

Examples

>>> obs1 = Obstacle([10, 10, 100, 100], 'VVWV')
>>> obs1.set_moving_bc({'f': 100, 'A': 2.1, 'profile': 'sine'},
                       {'f': 500, 'A': -1.5, 'profile': 'tukey'},
                       {'f': 500, 'A': 1.5 'profile': 'tukey', 'kwargs':{'alpha': 0.4}})
static sine(c, sc, **kwargs)[source]

Sine profile.

static tukey(_, sc, **kwargs)[source]

Tapered cosine profile.

class fdgrid.domains.Subdomain(xz: tuple, bc: str = '....', key: str = '', axis: int = - 1, tag: str = '')[source]

Bases: object

Subdivision of the computation domain.

Parameters
  • xz (list) – Coordinates of the Subdomain : left, bottom, right, top

  • bc (str) – Boundary conditions. Must be a string of 4 characters among ‘A|W|Z|P|R’

  • key (int, optional) – Key of the subdomain.

  • axis ({0, 1}, optional) – The direction of the subdomain if relevant.

  • tag (str, optional) – The type of Subdomain.

property axname

Returns “x” or “z” whether axis is 0 or 1. Return 2 if both.

property center

Returns the center of the Subdomain.

intersection(other)[source]

Return common border with another object.

split(index, nbc=None, axis=None)[source]

Split the subdomain into several new subdomains.

If index is integer, split into two Subdomain objects at ‘index’. If index is tuple/list (len(index) must be 2), split into 3 (or less) Subdomain objects.

Parameters
  • index ({int, tuple, list}) – Where to split the subdomain

  • nbc (str) – Only if index is a sequence. New bc for the domain defined by ‘index’

  • axis ({0, 1}) – Along which axis to split

touch(other)[source]

Return borders that touch the domain.