proteus.mprans.SpatialTools module

This module adds functionality to proteus.SpatialTools module by enabling two-phase flow functionality such as converting shapes to moving rigid bodies, or adding wave absorption and generation zones.

Example

from proteus import Domain from proteus.mprans import SpatialTools as st import numpy as np

domain = Domain.PlanarStraightLineGraphDomain() tank = st.Tank2D(domain. dim=[4., 4.]) tank.setSponge(left=0.4) tank.setAbsorptionZones(left=true) shape = st.Rectangle(domain, dim=[0.5, 0.5], coords=[1., 1.]) shape.setRigidBody() shape2.rotate(np.pi/3.) shape2.BC.left.setNoSlip()

st.assembleDomain(domain)

class proteus.mprans.SpatialTools.ShapeRANS(domain, nd)[source]

Bases: proteus.SpatialTools.Shape

Base/super class of all shapes. Sets the boundary condition class to proteus.mprans.BoundaryConditions.BC_RANS.

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.
attachPointGauges(model_key, gauges, activeTime=None, sampleRate=0, fileName='point_gauges.csv')[source]

Attaches Point Gauges (in the Proteus/Gauges.py style) to the shape.

Parameters:
  • model_key (string) – Label of the model to use as a key for selecting particular gauges.
  • proteus Gauges.py PointGauges class for the remaining parameters. (See) –
attachLineGauges(model_key, gauges, activeTime=None, sampleRate=0, fileName='line_gauges.csv')[source]

Attaches Line Gauges (in the Proteus/Gauges.py style) to the shape.

Parameters:
  • model_key (string) – Label of the model to use as a key for selecting particular gauges.
  • proteus Gauges.py LineGauges class for the remaining parameters. (See) –
attachLineIntegralGauges(model_key, gauges, activeTime=None, sampleRate=0, fileName='line_integral_gauges.csv')[source]

Attaches Line Integral Gauges (in the Proteus/Gauges.py style).

Parameters:
  • model_key (string) – Label of the model to use as a key for selecting particular gauges.
  • proteus Gauges.py LineIntegralGauges class for the remaining parameters. (See) –
setRigidBody(holes=None)[source]

Makes the shape a rigid body

Parameters:holes (Optional[array_like]) – Used to set coordinates of hole inside the rigid body, so it does not get meshed. If not set, the hole coordinates will be the barycenter coordinates.
setTank()[source]

Sets tank boundary conditions (for moving domain).

setConstraints(free_x, free_r)[source]

Sets constraints on the Shape (for moving bodies)

Parameters:
  • free_x (array_like) – Translational constraints.
  • free_r (array_like) – Rotational constraints.
setMass(mass)[source]

Set mass of the shape and calculate density if volume is defined.

Parameters:mass (float) – mass of the body
setDensity(density)[source]

Set density and calculate mass is volume is defined.

Parameters:density (float) – Density of the shape
getInertia(vec=(0.0, 0.0, 1.0), pivot=None)[source]

Gives the inertia of the shape from an axis and a pivot

Parameters:
  • vec (array_like) – Vector around which the body rotates.
  • pivot (Optional[array_like]) – Pivotal point around which the body rotates. If not set, it will be the barycenter coordinates
Returns:

I – inertia of the mass

Return type:

float

Notes

The inertia is calculated relative to the coordinate system of the shape (self.coords_system). If the shape was not initialised with a position corresponding to its inertia tensor (e.g. shape was already rotated when initialised), set the coordinate system accordingly before calling this function

setRecordValues(filename=None, all_values=False, time=True, pos=False, rot=False, F=False, M=False, inertia=False, vel=False, acc=False)[source]

Sets the rigid body attributes that are to be recorded in a csv file during the simulation.

Parameters:
  • filename (Optional[string]) – Name of file, if not set, the file will be named as follows: ‘record_[shape.name].csv’
  • all_values (bool) – Set to True to record all values listed below.
  • time (bool) – Time of recorded row (default: True).
  • pos (bool) – Position of body (default: False. Set to True to record).
  • rot (bool) – Rotation of body (default: False. Set to True to record).
  • F (bool) – Forces applied on body (default: False. Set to True to record).
  • M (bool) – Moments applied on body (default: False. Set to True to record).
  • inertia (bool) – Inertia of body (default: False. Set to True to record).
  • vel (bool) – Velocity of body (default: False. Set to True to record).
  • acc (bool) – Acceleration of body (default: False. Set to True to record).
setAbsorptionZones(flags, epsFact_solid, center, orientation, dragAlpha=497512.4378109453, dragBeta=0.0, porosity=1.0)[source]

Sets a region (given the local flag) to an absorption zone

Parameters:
  • flags (array_like, int) – Local flags of the region. Can be an integer or a list.
  • epsFact_solid (float) – Half of absorption zone (region) length (used for blending func).
  • center (array_like) – Coordinates of the center of the absorption zone.
  • orientation (array_like) – Orientation vector pointing TOWARDS incoming waves.
  • dragAlpha (Optional[float]) – Porous module parameter.
  • dragBeta (Optional[float]) – Porous module parameter.
  • porosity (Optional[float]) – Porous module parameter.
setGenerationZones(flags, epsFact_solid, center, orientation, waves, wind_speed=(0.0, 0.0, 0.0), dragAlpha=497512.4378109453, dragBeta=0.0, porosity=1.0, smoothing=0.0)[source]

Sets a region (given the local flag) to a generation zone

Parameters:
  • flags (array_like, int) – Local flags of the region. Can be an integer or a list.
  • epsFact_solid (float) – Half of absorption zone (region) length (used for blending func).
  • center (array_like) – Coordinates of the center of the absorption zone.
  • orientation (array_like) – Orientation vector pointing TOWARDS incoming waves.
  • waves (proteus.WaveTools) – Class instance of wave generated from proteus.WaveTools.
  • wind_speed (Optional[array_like]) – Speed of wind in generation zone (default is (0., 0., 0.))
  • dragAlpha (Optional[float]) – Porous module parameter.
  • dragBeta (Optional[float]) – Porous module parameter.
  • porosity (Optional[float]) – Porous module parameter.
setPorousZones(flags, dragAlpha=497512.4378109453, dragBeta=0.0, porosity=1.0)[source]

Sets a region (given the local flag) to a porous zone

Parameters:
  • flags (array_like, int) – Local flags of the region. Can be an integer or a list.
  • dragAlpha (Optional[float]) – Porous module parameter.
  • dragBeta (Optional[float]) – Porous module parameter.
  • porosity (Optional[float]) – Porous module parameter.
class proteus.mprans.SpatialTools.Tank3D(domain, dim=(0.0, 0.0, 0.0), coords=None, from_0=True)[source]

Bases: proteus.mprans.SpatialTools.ShapeRANS

Class to create a 3D tank (cuboidal shape).

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.
  • from_0 (Optional[bool]) – If True (default), the tank extends from the origin to postive x, y, z
count = 0[source]
setSponge(x_p=None, x_n=None, y_p=None, y_n=None)[source]

Set length of sponge layers of the tank (used for wave absorption or generation zones). (!) Sponge layers expand outwards.

Parameters:
  • x_p (Optional[float]) – length of sponge layer in +x direction.
  • x_n (Optional[float]) – length of sponge layer in -x direction.
  • y_p (Optional[float]) – length of sponge layer in +y direction.
  • y_n (Optional[float]) – length of sponge layer in -y direction.
setDimensions(dim)[source]

Set dimension of the tank

Parameters:dim (array_like) – dimensions of the tank (excluding sponge layers), array of length 3.
setAbsorptionZones(allSponge=False, y_n=False, y_p=False, x_n=False, x_p=False, dragAlpha=497512.4378109453, dragBeta=0.0, porosity=1.0)[source]

Sets regions (x+, x-, y+, y-) to absorption zones

Parameters:
  • allSponge (bool) – If True, all sponge layers are converted to absorption zones.
  • x_p (bool) – If True, x+ region is converted to absorption zone.
  • x_n (bool) – If True, x- region is converted to absorption zone.
  • y_p (bool) – If True, y+ region is converted to absorption zone.
  • y_n (bool) – If True, y- region is converted to absorption zone.
  • dragAlpha (Optional[float]) – Porous module parameter.
  • dragBeta (Optional[float]) – Porous module parameter.
  • porosity (Optional[float]) – Porous module parameter.
setGenerationZones(waves=None, wind_speed=(0.0, 0.0, 0.0), allSponge=False, y_n=False, y_p=False, x_n=False, x_p=False, dragAlpha=497512.4378109453, dragBeta=0.0, porosity=1.0, smoothing=0.0)[source]

Sets regions (x+, x-, y+, y-) to generation zones

Parameters:
  • waves (proteus.WaveTools) – Class instance of wave generated from proteus.WaveTools.
  • wind_speed (Optional[array_like]) – Speed of wind in generation zone (default is (0., 0., 0.))
  • allSponge (bool) – If True, all sponge layers are converted to generation zones.
  • x_p (bool) – If True, x+ region is converted to generation zone.
  • x_n (bool) – If True, x- region is converted to generation zone.
  • y_p (bool) – If True, y+ region is converted to generation zone.
  • y_n (bool) – If True, y- region is converted to generation zone.
  • dragAlpha (Optional[float]) – Porous module parameter.
  • dragBeta (Optional[float]) – Porous module parameter.
  • porosity (Optional[float]) – Porous module parameter.
class proteus.mprans.SpatialTools.Tank2D(domain, dim, coords=None, from_0=True)[source]

Bases: proteus.mprans.SpatialTools.ShapeRANS

Class to create a 2D tank (rectangular shape).

Parameters:
  • domain (proteus.Domain.D_base) – Domain class instance that hold all the geometrical informations and boundary conditions of the shape.
  • dim (array_like) – Dimensions of the tank (excluding sponge layers).
  • coords (Optional[array_like]) – Coordinates of the centroid of the shape.
  • from_0 (Optional[bool]) – If True (default), the tank extends from the origin to positive x, y, z
count = 0[source]
constructShape()[source]

Construct the geometry of the tank: segments, regions, etc.

Parameters:
  • frame (array_like) – An array of (x,y) coordinates in counterclockwise order to define the boundaries of the main (that is, excluding extensions such as sponge zones) shape. This can be generated with tank2DFrame or subclass specific methods.
  • frame_flags (array_like) – A corresponding array of boundary tags associated with each point in the frame. This can be generated with tank2DFrame or subclass specific methods.
setSponge(x_n=None, x_p=None)[source]

Set length of sponge layers of the tank (used for wave absorption or generation zones). (!) Sponge layers expand outwards.

Parameters:
  • x_p (Optional[float]) – length of sponge layer in +x direction.
  • x_n (Optional[float]) – length of sponge layer in -x direction.
setAbsorptionZones(x_n=False, x_p=False, dragAlpha=497512.4378109453, dragBeta=0.0, porosity=1.0)[source]

Sets regions (x+, x-) to absorption zones

Parameters:
  • allSponge (bool) – If True, all sponge layers are converted to absorption zones.
  • x_p (bool) – If True, x+ region is converted to absorption zone.
  • x_n (bool) – If True, x- region is converted to absorption zone.
  • dragAlpha (Optional[float]) – Porous module parameter.
  • dragBeta (Optional[float]) – Porous module parameter.
  • porosity (Optional[float]) – Porous module parameter.
setGenerationZones(waves=None, wind_speed=(0.0, 0.0, 0.0), x_n=False, x_p=False, dragAlpha=497512.4378109453, dragBeta=0.0, porosity=1.0, smoothing=0.0)[source]

Sets regions (x+, x-) to generation zones

Parameters:
  • waves (proteus.WaveTools) – Class instance of wave generated from proteus.WaveTools.
  • wind_speed (Optional[array_like]) – Speed of wind in generation zone (default is (0., 0., 0.))
  • allSponge (bool) – If True, all sponge layers are converted to generation zones.
  • x_p (bool) – If True, x+ region is converted to generation zone.
  • x_n (bool) – If True, x- region is converted to generation zone.
  • dragAlpha (Optional[float]) – Porous module parameter.
  • dragBeta (Optional[float]) – Porous module parameter.
  • porosity (Optional[float]) – Porous module parameter.
class proteus.mprans.SpatialTools.TankWithObstacles2D(domain, dim=(0.0, 0.0), obstacles=None, special_boundaries=None, full_circle=False, coords=None, from_0=True)[source]

Bases: proteus.mprans.SpatialTools.Tank2D

Class to create a 2D rectangular tank with obstacles built out of any wall.

An obstacle is defined by a contiguous list of points which start and end on the walls or corners of the tank.

This also covers special boundary conditions. To tag a segment with a unique boundary tag, add the starting vertex (in the counterclockwise format the shape is generated in) of the segment as a value in a dictionary element keyed to the name of the boundary tag.

(!) Warning: If each of the four corners of the rectangular tank is inside an obstacle or a vertex for an obstacle, then the tank’s region is defined in a pseudorandom manner, which may make it unreliable when dealing with holes caused by other shapes. (!) Warning: Obstacle boundary tags are keyed to whichever edge they started from. If this is undesirable, it may be manually overriden by applying special boundary conditions to affected segments.

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.
  • obstacles (Optional[array_like]) – A list of lists of (x,y) coordinates. Each (x,y) coordinate is a length and height relative to the x-,y- corner of the tank. Each list of coordinates is an obstacle defined by points connected in the order of their index. The list of lists gives all such obstacles in a counterclockwise manner of which they should be appended, starting from the (x-,y-) corner.
  • special_boundaries (Optional[mapping]) – A dictionary of lists of vertices keyed to boundary names. The vertices listed will be given the boundary name they are keyed to, overriding any other designation they would be given. If this is a distinct boundary name, the segment starting from the vertex will be assigned the same boundary tag.
  • full_circle (Optional[bool]) – A boolean tag to check if the final obstacle ends on the same edge that the first obstacle starts on. Default is False.
  • coords (Optional[array_like]) – Coordinates of the centroid of the shape.
  • from_0 (Optional[bool]) – If True (default), the tank extends from the origin to positive x, y, z
setAbsorptionZones(x_n=False, x_p=False, dragAlpha=497512.4378109453, dragBeta=0.0, porosity=1.0)[source]

Sets regions (x+, x-) to absorption zones

Parameters:
  • allSponge (bool) – If True, all sponge layers are converted to absorption zones.
  • x_p (bool) – If True, x+ region is converted to absorption zone.
  • x_n (bool) – If True, x- region is converted to absorption zone.
  • dragAlpha (Optional[float]) – Porous module parameter.
  • dragBeta (Optional[float]) – Porous module parameter.
  • porosity (Optional[float]) – Porous module parameter.
setGenerationZones(waves=None, wind_speed=(0.0, 0.0, 0.0), x_n=False, x_p=False, dragAlpha=497512.4378109453, dragBeta=0.0, porosity=1.0, smoothing=0.0)[source]

Sets regions (x+, x-) to generation zones

Parameters:
  • waves (proteus.WaveTools) – Class instance of wave generated from proteus.WaveTools.
  • wind_speed (Optional[array_like]) – Speed of wind in generation zone (default is (0., 0., 0.))
  • allSponge (bool) – If True, all sponge layers are converted to generation zones.
  • x_p (bool) – If True, x+ region is converted to generation zone.
  • x_n (bool) – If True, x- region is converted to generation zone.
  • dragAlpha (Optional[float]) – Porous module parameter.
  • dragBeta (Optional[float]) – Porous module parameter.
  • porosity (Optional[float]) – Porous module parameter.
class proteus.mprans.SpatialTools.RigidBody(shape, cfl_target=0.9, dt_init=0.001)[source]

Bases: proteus.AuxiliaryVariables.AV_base

Auxiliary variable used to calculate attributes of an associated shape class instance acting as a rigid body. To set a shape as a rigid body, use shape.setRigidBody(). The class instance is created automatically when shape.setRigidBody() has been called and after calling assembleDomain().

Parameters:
  • shape (proteus.mprans.SpatialTools.Shape_RANS) – Class instance of the shape associated to the rigid body calculations.
  • cfl_target (Optional[float]) – UNUSED (to implement), sets the maximum displacement of the body allowed per time step.
  • dt_init (float) – first time step of the simulation.
attachModel(model, ar)[source]

Attaches model to auxiliary variable

calculate_init()[source]

Function called at the very beginning of the simulation by proteus.

calculate()[source]

Function called at each time step by proteus.

step(dt)[source]

Step for rigid body calculations in Python

Parameters:dt (float) – time step
recordValues()[source]

Records values of rigid body attributes at each time step in a csv file.

proteus.mprans.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.mprans.SpatialTools.assembleAuxiliaryVariables(domain)[source]

Adds the auxiliary variables to the domain.

Parameters:domain (proteus.Domain.D_base) – Domain class instance that hold all the geometrical informations and boundary conditions of the shape.

Notes

Should be called after assembleGeometry

proteus.mprans.SpatialTools.get_unit_vector(vector)[source]