Computational Grid (nsfds3.cpgrid)

Examples

The cpgrid package contains in particular :

from nsfds3.cpgrid import CartesianGrid, CurvilinearGrid, TestCases

case = 'superimposed2'

# 2d Cartesian Grid
shape = 256, 256
bc = 'AWWW'
obstacles = getattr(TestCases, case)(shape)

mesh2d = CartesianGrid(shape=shape, bc=bc, obstacles=obstacles)
mesh2d.show(buffer=True, domains=False,
            kwargs_obstacles=dict(hatch='/', facecolor='r'),
            kwargs_buffer=dict(hatch='/', fill=True, facecolor='b', alpha=0.1)
            )


# 2d Curvilinear Grid
def func(x, y):
    v = y * (1 + 1000*x**2 + 0.02 * np.sin(4 * np.pi * x / x.min()))
    return x.copy(), v


shape = 256, 256
origin = 128, 128
steps = 1e-4, 1e-4
bc = 'PPWW'
obstacles = getattr(TestCases, case)(shape)

mesh2d = CurvilinearGrid(shape=shape, origin=origin, steps=steps, bc=bc,
                        obstacles=obstacles, curvilinear_func=func)
mesh2d.show(N=2, kwargs_obstacles=dict(hatch='/', facecolor='r'))


# 3d Cartesian Grid
shape = 256, 240, 220
bc = 'AWWAWW'
obstacles = getattr(TestCases, case)(shape)

mesh3d = CartesianGrid(shape=shape, bc=bc, obstacles=obstacles)

slices = [o + int(3*s/4) for o, s in zip(mesh3d.obstacles[0].origin, mesh3d.obstacles[0].size)][::-1]

mesh3d.show(buffer=True, domains=False, slices=slices,
            kwargs_obstacles=dict(hatch='/', facecolor='r', alpha=0.7))


# 3d Curvilinear Grid
def func(x, y, z):
    u = x.copy()
    v = y * (1 + 0.01 * np.sin(4 * np.pi * x / x.min())) - 0.0005 * np.sin(0.5 * np.pi * (x - x.min())/ x.min())
    w = z.copy() * (1 + 0.005 *  np.sin(4 * np.pi * x / x.min()))
    return u, v, w


shape = 256, 240, 220
steps = 1e-4, 1e-4, 1e-4
bc = 'AWWAWW'
obstacles = getattr(TestCases, case)(shape)

mesh3d = CurvilinearGrid(shape=shape, steps=steps, bc=bc,
                        obstacles=obstacles, curvilinear_func=func)

slices = [o + int(3*s/4) for o, s in zip(mesh3d.obstacles[0].origin, mesh3d.obstacles[0].size)][::-1]

mesh3d.show(buffer=True, domains=False, grid=True, slices=slices,
            kwargs_obstacles=dict(hatch='/', facecolor='r', alpha=0.7))
class nsfds3.cpgrid.CartesianGrid(shape, steps=None, origin=None, bc=None, obstacles=None, bz_n=20, bz_stretch_factor=2, bz_stretch_order=3, bz_filter_order=3.0, stencil=11, free=True)[source]

Build cartesian grid

Parameters:
  • shape (tuple) – Size of the domain. Must be a tuple with 2 or 3 int objects.

  • steps (tuple, optional) – Spatial steps. Must be a tuple with 2 or 3 float objects.

  • origin (tuple, optional) – Origin of the grid. Must be a tuple with 2 or 3 int objects.

  • bc ({'[APW][APW][APW][APW][[APW][APW]]'}, optional) – Boundary conditions. Must be a 4 or 6 characters string corresponding to left, right, front, back, bottom, and top boundaries, respectively. A stands for non reflecting boundary, W for non slip condition, and P for periodic boundary.

  • obstacles (list of nsfds3.cpgrid.Obstacle, optional) – List of nsfds3.cpgrid.Obstacle objects in the computation domain.

  • bz_n (int, optional) – Number of points of the absorbing area (only if ‘A’ in bc).

  • bz_stretch_factor (float, optional) – Factor reach at the end of the stretching zone

  • bz_stretch_order (float, optional) – Order of the streching function

  • stencil (int, optional) – Size of the finite difference stencil [obsolete].

Note

One can override make_grid() method to customize (x, y, z)

Attributes:
axis

Numerical axis.

paxis

Physical axis.

stretched_axis

Return a string specifying the axis that are not regularly spaced.

Methods

find_subdomains()

Divide the computation domain into subdomains.

from_cfg(cfg)

Build grid from configuration.

get_obstacles()

Get obstacles coordinates.

make_grid()

Build grid.

show(**kwargs)

Plot grid.

property axis

Numerical axis.

find_subdomains()[source]

Divide the computation domain into subdomains.

classmethod from_cfg(cfg)[source]

Build grid from configuration.

get_obstacles()[source]

Get obstacles coordinates.

make_grid()[source]

Build grid.

property paxis

Physical axis.

show(**kwargs)[source]

Plot grid.

todo :
  • BC profiles

property stretched_axis

Return a string specifying the axis that are not regularly spaced.

class nsfds3.cpgrid.ComputationDomains(shape, obstacles=None, bc='WWWWWW', bz_n=20, stencil=11, free=True)[source]

Divide computation domain in several Subdomains based on obstacles in presence.

Parameters:
  • shape (tuple) – Size of the domain. Must be a tuple with 3 int objects.

  • obstacles (list of nsfds3.cpgrid.geometry.Obstacle, nsfds3.cpgrid.geometry.ObstacleSet, optional) – Obstacles in the computation domain.

  • bc ({'[APW][APW][APW][APW]'}, optional) – Boundary conditions. Must be a 4 or 6 characters string corresponding to left, right, front, back, bottom, and top boundaries, respectively.

  • bz_n (int, optional) – Size of the buffer zone

  • stencil (int, optional) – Size of the finite difference stencil.

  • free (bool, optional) – Free memory after the domains are found

Attributes:
is_valid

Report whether computation domains seem valid or not.

Methods

find_domains()

Split the domain in rectangular/cubic subdomains

get_cuboids(mask[, ax, N])

Return a list of dictionnaries containing cuboid parameters.

show([obstacles, domains, bounds, only_mesh])

Plot 3d representation of computation domain.

find_domains()[source]

Split the domain in rectangular/cubic subdomains

get_cuboids(mask, ax=-1, N=-1)[source]

Return a list of dictionnaries containing cuboid parameters.

Parameters:
  • mask (np.array) – Search cuboids in mask

  • ax (int, optional) – Direction of the search. Can be 0 (x), 1 (y), or other (center)

  • N (int, optional) – Fix one dimension of the output cuboids. Only for ax=0 or ax=1.

property is_valid

Report whether computation domains seem valid or not.

show(obstacles=True, domains=False, bounds=True, only_mesh=True, **kwargs)[source]

Plot 3d representation of computation domain.

class nsfds3.cpgrid.CurvilinearGrid(shape, steps=None, origin=None, bc=None, obstacles=None, curvfunc=None, bz_n=20, bz_stretch_factor=2, bz_stretch_order=3, bz_filter_order=3.0, stencil=11, free=True)[source]

Build curvilinear grid

Parameters:
  • shape (tuple) – Size of the domain. Must be a tuple with 2 or 3 int objects.

  • steps (tuple, optional) – Spatial steps. Must be a tuple with 2 or 3 float objects.

  • origin (tuple, optional) – Origin of the grid. Must be a tuple with 2 or 3 int objects.

  • bc ({'[APW][APW][APW][APW][[APW][APW]]'}, optional) – Boundary conditions. Must be a 4 or 6 characters string corresponding to left, right, front, back, bottom, and top boundaries, respectively. A stands for non reflecting boundary, W for non slip condition, and P for periodic boundary.

  • obstacles (list of nsfds3.cpgrid.Obstacle, optional) – List of nsfds3.cpgrid.Obstacle objects in the computation domain.

  • curvfunc (func) – Function to operate curvilinear transformation

  • bz_n (int, optional) – Number of points of the absorbing area (only if ‘A’ in bc).

  • bz_stretch_factor (float, optional) – Factor reach at the end of the stretching zone

  • bz_stretch_order (float, optional) – Order of the streching function

  • stencil (int, optional) – Size of the finite difference stencil (used by nsfds2).

Attributes:
axis

Numerical axis.

paxis

Physical axis.

stretched_axis

Return a string specifying the axis that are not regularly spaced.

Methods

check_metrics([rtol])

Check metrics.

find_subdomains()

Divide the computation domain into subdomains.

from_cfg(cfg)

Build grid from configuration.

get_obstacles()

Get obstacles coordinates.

make_grid()

Make curvilinear grid.

show(**kwargs)

Plot grid.

check_metrics(rtol=1e-08)[source]

Check metrics.

make_grid()[source]

Make curvilinear grid.

Note

(x, y, z) define numerical grid (u, v, w) define physical grid

class nsfds3.cpgrid.Obstacle(origin, size, env, bc=None, inner=False, tag=None)[source]

Specialization of Cuboid objects to describe an Obstacle. See nsfds3.cpgrid.geometry.Box and nsfds3.cpgrid.geometry.Cuboid for further details.

Attributes:
description

Return a brief description of the object.

indices

Return a set of all indexes contained in the Box.

Methods

center([transform, ax])

Return physical coordinates of the center of the box along ax.

contains(coordinate)

Report whether coordinate is in self.

count_reset()

Reset the count.

flatten(axis)

Return a flat version of the object.

from_slices(slices, env[, bc, inner, tag])

Instanciate Box from a list of slices.

inner_indices([ax])

Return indices.

inner_slices([ax])

Return inner slices except along axis (int).

intersection(other)

Return intersection (point coordinate) between self and other.

intersects(other)

Report whether self intersects other.

issubset(other)

Report whether other contains self.

issuperset(other)

Report whether self contains other.

sort_vertices(values)

Sort vertices.

slice_from_edge

class nsfds3.cpgrid.ObstacleSet(shape, bc, subs=None, stencil=11)[source]

Specialization of BoxSet objects to describe a collection of Obstacle objects. See nsfds3.cpgrid.geometry.BoxSet for further details.

Note

ObstacleSet provides several useful sequences of faces :

  • periodic : faces located on a periodic boundary of the domain

  • colinear : faces that are colinear with other obstacle faces

  • covered : faces that are entirely covered by an obstacle

  • overlapped : faces that are partially overlapped by an obstacle

  • clamped : faces located on a boundary (not periodic) of the domain

  • bounded : faces that are bounded by at least one boundary of the domain

  • edged : faces that are located on a boundary of the domain and bounded by at least another one

  • free : free face

  • uncentered : faces that need an uncentered scheme

Methods

check_boxes()

Check that : - all boxes have same dimension and envelop, - there is not collistion between obstacles and bounds

flatten(axis[, index])

Return a flat version of the object.

get_obstacle_by_face(f)

Return the Obstacle object containing the face f.

get_obstacle_by_sid(sid)

Return Obstacle whose identity is sid.

is_out_of_bounds(obs)

Check if subdomain is out of bounds.

is_too_close(f1, f2)

Check if f1 and f2 locations are compatible with the stencil.

unflatten()

Return a volumic version of flattened object.

check_boxes()[source]

Check that : - all boxes have same dimension and envelop, - there is not collistion between obstacles and bounds

flatten(axis, index=0)[source]

Return a flat version of the object.

get_obstacle_by_face(f)[source]

Return the Obstacle object containing the face f.

get_obstacle_by_sid(sid)[source]

Return Obstacle whose identity is sid.

is_out_of_bounds(obs)[source]

Check if subdomain is out of bounds.

is_too_close(f1, f2)[source]

Check if f1 and f2 locations are compatible with the stencil.

unflatten()[source]

Return a volumic version of flattened object.

class nsfds3.cpgrid.TestCases[source]

Collection of obstacles arangments and curvilinear transformations.

Methods

Lcell(shape[, stencil])

L arrangement.

Ocell(shape[, stencil])

Window arrangement.

Tcell(shape[, stencil])

T arrangement.

Ucell(shape[, stencil])

Bridge arrangement.

base(shape[, stencil])

Base geometry.

curv_mountain(x, y)

Curvilinear function example.

edges(shape[, stencil])

All possible single edges...

empty(shape[, stencil])

Empty domain.

evolution_sine(time)

Sinusoïdal time evolution

overlapped1(shape[, stencil])

Two obstacles overlapped (one sides).

overlapped2(shape[, stencil])

Two obstacles overlapped (two sides).

single(shape[, stencil])

Single obstacle.

single_source(shape[, stencil])

Single obstacle with wall source.

superimposed1(shape[, stencil])

Two obstacles side to side.

superimposed2(shape[, stencil])

Two obstacles of different height side to side.

static Lcell(shape, stencil=11)[source]

L arrangement.

_____
|   |
|   |_____
|___||___|
static Ocell(shape, stencil=11)[source]

Window arrangement.

_______________
|   ||___||   |
|   |     |   |
|   |_____|   |
|___||___||___|
static Tcell(shape, stencil=11)[source]

T arrangement.

_________
|_______|
  |   |
  |___|
static Ucell(shape, stencil=11)[source]

Bridge arrangement.

_____     _____
|   |     |   |
|   |_____|   |
|___||___||___|
static base(shape, stencil=11)[source]

Base geometry.

static curv_mountain(x, y)[source]

Curvilinear function example.

static edges(shape, stencil=11)[source]

All possible single edges…

static empty(shape, stencil=11)[source]

Empty domain.

static evolution_sine(time)[source]

Sinusoïdal time evolution

static overlapped1(shape, stencil=11)[source]

Two obstacles overlapped (one sides).

static overlapped2(shape, stencil=11)[source]

Two obstacles overlapped (two sides).

static single(shape, stencil=11)[source]

Single obstacle.

static single_source(shape, stencil=11)[source]

Single obstacle with wall source.

_____
|   |
|___|
static superimposed1(shape, stencil=11)[source]

Two obstacles side to side.

__________
|   ||   |
|___||___|
static superimposed2(shape, stencil=11)[source]

Two obstacles of different height side to side.

__________
|   ||   |
|   ||___|
|___|
nsfds3.cpgrid.build_mesh(cfg)[source]

Return Grid from nsfds3.solver.CfgSetup configuration.