Computational Grid (nsfds3.cpgrid)
Examples
The cpgrid package contains in particular :
build_mesh()
: Factory function to build a mesh grid from a given configuration
CartesianGrid
: Build cartesian grid
CurvilinearGrid
: Build curvilinear grid
Obstacle
: describes an obstacle with its faces
ObstacleSet
: Collection of Obstacle objects
TestCases
: Gather examples of obstacles arangments and curvilinear transformations
ComputationDomains
: Divide the grid into subdomains following the geometric configuration.
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 ofnsfds3.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
Divide the computation domain into subdomains.
from_cfg
(cfg)Build grid from configuration.
Get obstacles coordinates.
Build grid.
show
(**kwargs)Plot grid.
- property axis
Numerical axis.
- property paxis
Physical axis.
- 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
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.
- get_cuboids(mask, ax=-1, N=-1)[source]
Return a list of dictionnaries containing cuboid parameters.
- property is_valid
Report whether computation domains seem valid or not.
- 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 ofnsfds3.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 curvilinear grid.
show
(**kwargs)Plot 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
andnsfds3.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 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.
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.
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 Ocell(shape, stencil=11)[source]
Window arrangement.
_______________ | ||___|| | | | | | | |_____| | |___||___||___|
- static Ucell(shape, stencil=11)[source]
Bridge arrangement.
_____ _____ | | | | | |_____| | |___||___||___|
- nsfds3.cpgrid.build_mesh(cfg)[source]
Return Grid from
nsfds3.solver.CfgSetup
configuration.