# proteus.SpatialTools module¶

Module creating predifined or custom shapes. Each shape needs a Domain as argument (from proteus.Domain). A Domain can contain any number of shapes. Boundary conditions objects are automatically created for each facet (3D) or segment (2D) defining the shape.

Classes:

• Shape: super class, regroups functions common to all shapes
• Cuboid: creates a 3D cuboid
• Rectangle: creates a 2D rectangle
• Custom: creates a custom shape from a given set vertices, facets, etc.

Example:

from proteus import Domain
from proteus import SpatialTools as st
import numpy as np
domain = Domain.PlanarStraightLineGraphDomain()
shape1 = st.Rectangle(domain, dim=[0.5, 0.5], coords=[1., 1.])
shape2 = st.Rectangle(domain. dim=[0.3, 0.2], coords=[3., 3.])
shape2.rotate(np.pi/3.)
shape2.BC_dict["left"].uOfXT = lambda x, t: 0.

st.assembleDomain(domain)

class proteus.SpatialTools.Shape(domain, nd=None, BC_class=None)[source]

Bases: object

Base/super class of all shapes.

Parameters: domain (proteus.Domain.D_base) – Domain class instance that hold all the geometrical informations and boundary conditions of the shape. nd (Optional[int]) – Number of dimensions of the shape. If not set, will take the number of dimensions of the domain. BC_class (Optional[proteus.BoundaryConditions.BC_Base]) – Class to use for boundary conditions (e.g. proteus.BoundaryConditions.BC_Base or proteus.BoundaryConditions.mprans.BC_RANS).
count_all = 0[source]
setPosition(coords)[source]

Set position with coords of the barycenter

Parameters: coords (array_like) – New set of coordinates for barycenter (list/array).
setBarycenter(barycenter)[source]

Set barycenter (center of mass) of the shape (!) this function does not move the shape

Parameters: barycenter (array_like) – Global coordinates of barycenter (list/array).
setRegions(regions, regionFlags=None)[source]

Sets new regions for the Shape

Parameters: regions (array_like) – Array of coordinates of regions. regionFlags (Optional[array_like]) – Array of flags.
setChildShape(shape, ind=0)[source]

Indicates that a shape is contained in this shape (this function or setParentShape is necessary for gmsh)

Parameters: shape (proteus.SpatialTools.Shape) – child of this shape ind (int) – parent (current) shape’s local index of volume (3D) or facet (2D) containing the child shape
setParentShape(shape, ind=0)[source]

Indicates that this shape is within another shape (this function or setChildShape is necessary for gmsh) Sets the shape within

Parameters: shape (proteus.SpatialTools.Shape) – the parent of this shape ind (int) – parent shape’s local index of volume (3D) or facet (2D) containing the child (current) shape
setHoles(holes, indice=None)[source]

Sets a ‘hole’ in the mesh. The region where the hole is defined will not be meshed.

Parameters: holes (array_like) – Array of coordinates of holes (list/array). indice (array_like) – Array of index of region where hole is (list/array). Only for gmsh
rotate(rot, axis=(0, 0, 1), pivot=None)[source]

Function to rotate Shape

Parameters: rot (float) – Angle of rotation (in radians). axis (Optional[array_like]) – Vector used for rotation. Not necessary for rotation in 2D. pivot (Optional[array_list]) – Point around which the shape will rotate. If not set, the barycenter will be the center of rotation.

Notes

Rotated attributes: - vertices - holes - regions - local coordinate system - boundary orientations - coords (if not None) - barycenter

translate(trans)[source]

Function to translate Shape

Parameters: trans (array_like) – Translation values.

Notes

Translated attributes: - vertices - regions - coords (if not None) - barycenters - holes

getPosition()[source]
Returns: barycenter – Current position of barycenter. array_like
getRotation()[source]
Returns: coords_system – Local coordinate system relative to global coordinate system. array_like
class proteus.SpatialTools.Cuboid(domain, dim=(0.0, 0.0, 0.0), coords=(0.0, 0.0, 0.0), barycenter=None)[source]

Class to create a 3D cuboid

Parameters: domain (proteus.Domain.D_base) – Domain class instance that hold all the geometrical informations and boundary conditions of the shape. dim (Optional[array_like]) – Dimensions of the cuboid. coords (Optional[array_like]) – Coordinates of the centroid of the shape. barycenter (Optional[array_like]) – Coordinates of the barycenter.
count = 0[source]
setDimensions(dim)[source]

Sets dimensions of the shape.

Parameters: dim (array_like) – New dimensions of the shape.
class proteus.SpatialTools.Sphere(domain, radius, coords=(0.0, 0.0, 0.0), barycenter=None, nSectors=10)[source]

Class to create a 3D cuboid

Parameters: domain (proteus.Domain.D_base) – Domain class instance that hold all the geometrical informations and boundary conditions of the shape. dim (Optional[array_like]) – Dimensions of the cuboid. coords (Optional[array_like]) – Coordinates of the centroid of the shape. barycenter (Optional[array_like]) – Coordinates of the barycenter.
count = 0[source]
constructShape()[source]

regualar nx,ny,nz cube packing with padding to boundary returns domain size and boundary flags

class proteus.SpatialTools.Rectangle(domain, dim=(0.0, 0.0), coords=(0.0, 0.0), barycenter=None)[source]

Class to create a rectangle

Parameters: domain (proteus.Domain.D_base) – Domain class instance that hold all the geometrical informations and boundary conditions of the shape. dim (Optional[array_like]) – Dimensions of the cuboid. coords (Optional[array_like]) – Coordinates of the centroid of the shape. barycenter (Optional[array_like]) – Coordinates of the barycenter.
count = 0[source]
setDimensions(dim)[source]

Set dimensions of the shape

Parameters: dim – new dimensions (list/array)
class proteus.SpatialTools.Cylinder(domain, radius, height, nPoints, coords=(0.0, 0.0, 0.0), barycenter=None)[source]

Class to create a cylinder.

Parameters: domain (proteus.Domain.D_base) – Domain class instance that hold all the geometrical informations and boundary conditions of the shape. radius (float) – radius of cylinder. height (float) – height of cylinder. nPoints (int) – number of points to discretize circles of cylinder. coords (Optional[array_like]) – Coordinates of the centroid of the shape. barycenter (Optional[array_like]) – Coordinates of the barycenter.
count = 0[source]
constructShape()[source]
class proteus.SpatialTools.Circle(domain, radius, coords, barycenter, nPoints)[source]

Class to create a circular shape.

Parameters: domain (proteus.Domain.D_base) – Domain class instance that hold all the geometrical informations and boundary conditions of the shape. radius – Radius of the circular shape. coords (Optional[array_like]) – Coordinates of the centroid of the shape.
count = 0[source]
class proteus.SpatialTools.CustomShape(domain, barycenter=None, vertices=None, vertexFlags=None, segments=None, segmentFlags=None, facets=None, facetFlags=None, holes=None, holes_ind=None, regions=None, regionFlags=None, volumes=None, boundaryTags=None, boundaryOrientations=None)[source]

Class to create a custom 2D or 3D shape

Parameters: domain (proteus.Domain.D_base) – Domain class instance that hold all the geometrical informations and boundary conditions of the shape. barycenter (Optional[array_like]) – Coordinates of the barycenter. vertices (array_like) – Array of vertex coordinates. vertexFlags (array_like) – Array of vertex flags (used for boundary conditions) segments (array_like) – Array of segments (each defined by indice of 2 vertex). segmentFlags (array_like) – Array of segment flags (used for boundary conditions) facetss (array_like) – Array of facets (defined by clockwise or counterclockwise loop of vertices). facetFlags (array_like) – Array of facet flags (used for boundary conditions) vertices – Array of region coordinates. regionFlags (array_like) – Array of region flags (used for boundary conditions) volumes (array_like) – Surface loops describing volumes (used for gmsh) holes (array_like) – Array of holes coordinates (unmeshed regions; for triangle/tetgen only) holes – Array of holes index (volume or facet; unmeshed regions; for gmsh only) boundaryTags (dict) – Dictionary of flags (int) as keys, and tags (e.g. string) for BC. boundaryOrientations (Optional[array_like]) – Array of orientation of boundaries. Can be used for BC.
count = 0[source]
class proteus.SpatialTools.ShapeSTL(domain, filename)[source]

Class to extract geometrical information from STL file

Parameters: domain (proteus.Domain.D_base) – Domain class instance that hold all the geometrical informations and boundary conditions of the shape. filename (string) – Name of the stl file.
count = 0[source]
proteus.SpatialTools.getInfoFromSTL(filename)[source]

Extracts information from STL file and converts it to a Proteus friendly format. Duplicate vertices and segments are removed during the process, so the shape is ready for meshing.

Parameters: filename (name of STL file) – vertices (array_like) – Array of vertices that define STL shape (duplicates removed) facets (array_like) – Array of facets (loops of 3 vertices) facetnormals (array_like) – normal vertors of each facet
proteus.SpatialTools.unique_rows(arr)[source]
class proteus.SpatialTools.BCContainer(BC_dict)[source]

Bases: object

Creates a class from a dictionary (keys become class variable names)

proteus.SpatialTools.rotation2D(points, rot, pivot=(0.0, 0.0))[source]

Rotates a set of points/vertices/vectors around a pivotal point in 2D.

Parameters: points (array_like) – Array of point coordinates to rotate. rot (float) – Angle of rotation. pivot (array_like) – Pivotal point around which the set of points will be rotated. points_rot – Rotated set of points. array_like
proteus.SpatialTools.rotation3D(points, rot, axis=(0.0, 0.0, 1.0), pivot=(0.0, 0.0, 0.0))[source]

Rotates a set of points/vertices/vectors around a pivotal point in 3D.

Parameters: points (array_like) – Array of point coordinates to rotate. rot (float) – Angle of rotation. axis (array_like) – Axis of rotation. pivot (array_like) – Pivotal point around which the set of points will be rotated. points_rot – Rotated set of points. array_like
proteus.SpatialTools.assembleDomain(domain)[source]

This function sets up everything needed for the domain, meshing, and AuxiliaryVariables calculations (if any). It should always be called after defining and manipulating all the shapes to be attached to the domain.

Parameters: domain (proteus.Domain.D_base) – Domain class instance that hold all the geometrical informations and boundary conditions of the shape.
proteus.SpatialTools.getGmshPhysicalGroups(geofile)[source]
proteus.SpatialTools.extrude2Dto3D(extrusion, vertices, segments, facets, regions=None)[source]

Extrude 2D geometry attributes in 3D

Parameters: extrusion (array_like) – value of the extrusion (e.g. [1.4, 0., 0.]) vertices (array_like) – list of vertices of the 2D shape segments (array_like) – list of segments of the 2D shape facets (array_like) – list of facets of the 2D shape regions (array_like) – list of regions of the 2D shape