underworld.swarm.layouts module¶
This module contains classes for populating swarms with particles across the domain.
Module Summary¶
classes:¶
underworld.swarm.layouts.ParticleLayoutAbstract |
Abstract class. |
underworld.swarm.layouts.PerCellSpaceFillerLayout |
This layout fills the domain with particles in a quasi-random pattern. |
underworld.swarm.layouts.GlobalSpaceFillerLayout |
This layout fills the domain with particles in a quasi-random pattern. |
underworld.swarm.layouts.PerCellGaussLayout |
This layout populates the domain with particles located at gauss locations within each element of the swarm’s associated finite element mesh. |
underworld.swarm.layouts.PerCellRandomLayout |
This layout fills the domain with particles in a random (per element) pattern. |
Module Details¶
classes:¶
-
class
underworld.swarm.layouts.
ParticleLayoutAbstract
(swarm, **kwargs)[source]¶ Bases:
underworld._stgermain.StgCompoundComponent
Abstract class. Children classes are responsible for populating swarms with particles, generally across the entire domain.
Parameters: swarm (underworld.swarm.Swarm) – The swarm this layout will act upon -
swarm
¶ Returns: Swarm this layout will act to fill with particlces. Return type: underworld.swarm.Swarm
-
-
class
underworld.swarm.layouts.
PerCellSpaceFillerLayout
(swarm, particlesPerCell, **kwargs)[source]¶ Bases:
underworld.swarm.layouts._PerCellMeshParticleLayout
This layout fills the domain with particles in a quasi-random pattern. It utilises sobol sequences to generate per element particle locations which are more uniform than that achieved by a purely random generator.
Parameters: - swarm (underworld.swarm.Swarm) – The swarm this layout will act upon
- particlesPerCell (int) – The number of particles per element that this layout will generate.
Example
>>> import underworld as uw >>> mesh = uw.mesh.FeMesh_Cartesian('Q1/dQ0', (1,1), (0.,0.), (1.,1.)) >>> swarm = uw.swarm.Swarm(mesh) >>> layout = uw.swarm.layouts.PerCellSpaceFillerLayout(swarm,particlesPerCell=4) >>> swarm.populate_using_layout(layout) >>> swarm.particleLocalCount 4 >>> swarm.particleCoordinates.data array([[ 0.5 , 0.5 ], [ 0.25 , 0.75 ], [ 0.75 , 0.25 ], [ 0.375, 0.625]])
-
class
underworld.swarm.layouts.
GlobalSpaceFillerLayout
(swarm, particlesPerCell, **kwargs)[source]¶ Bases:
underworld.swarm.layouts.ParticleLayoutAbstract
This layout fills the domain with particles in a quasi-random pattern. It utilises sobol sequences to generate global particle locations which are more uniform than that achieved by a purely random generator. This layout is mostly useful where populating particles across a rectangular domain.
Parameters: - swarm (underworld.swarm.Swarm) – The swarm this layout will act upon
- particlesPerCell (float) – The average number of particles per element that this layout will generate.
Example
>>> import underworld as uw >>> mesh = uw.mesh.FeMesh_Cartesian('Q1/dQ0', (1,1), (0.,0.), (1.,1.)) >>> swarm = uw.swarm.Swarm(mesh) >>> layout = uw.swarm.layouts.GlobalSpaceFillerLayout(swarm,particlesPerCell=4) >>> swarm.populate_using_layout(layout) >>> swarm.particleLocalCount 4 >>> swarm.particleCoordinates.data array([[ 0.5 , 0.5 ], [ 0.25 , 0.75 ], [ 0.75 , 0.25 ], [ 0.375, 0.625]])
-
class
underworld.swarm.layouts.
PerCellGaussLayout
(swarm, gaussPointCount, **kwargs)[source]¶ Bases:
underworld.swarm.layouts.ParticleLayoutAbstract
This layout populates the domain with particles located at gauss locations within each element of the swarm’s associated finite element mesh.
Parameters: - swarm (underworld.swarm.Swarm) – The swarm this layout will act upon
- gaussPointCount (int) – Per cell, the number of gauss points in each dimensional direction. Must take an int value between 1 and 5 inclusive.
Example
>>> import underworld as uw >>> # choose mesh to coincide with global element >>> mesh = uw.mesh.FeMesh_Cartesian('Q1/dQ0', (1,1), (-1.,-1.), (1.,1.)) >>> swarm = uw.swarm.Swarm(mesh) >>> layout = uw.swarm.layouts.PerCellGaussLayout(swarm,gaussPointCount=2) >>> swarm.populate_using_layout(layout) >>> swarm.particleLocalCount 4 >>> swarm.particleCoordinates.data array([[-0.57735027, -0.57735027], [ 0.57735027, -0.57735027], [-0.57735027, 0.57735027], [ 0.57735027, 0.57735027]]) >>> import math >>> # lets check one of these gauss points >>> ( swarm.particleCoordinates.data[3][0] - math.sqrt(1./3.) ) < 1.e-10 True
-
class
underworld.swarm.layouts.
PerCellRandomLayout
(swarm, particlesPerCell, seed=13, **kwargs)[source]¶ Bases:
underworld.swarm.layouts._PerCellMeshParticleLayout
This layout fills the domain with particles in a random (per element) pattern.
Parameters: - swarm (underworld.swarm.Swarm) – The swarm this layout will act upon
- particlesPerCell (int) – The number of particles per element that this layout will generate.
- seed (int) – Seed for random generator. Default is 13.
Example
>>> import underworld as uw >>> mesh = uw.mesh.FeMesh_Cartesian('Q1/dQ0', (1,1), (0.,0.), (1.,1.)) >>> swarm = uw.swarm.Swarm(mesh) >>> layout = uw.swarm.layouts.PerCellRandomLayout(swarm,particlesPerCell=4) >>> swarm.populate_using_layout(layout) >>> swarm.particleLocalCount 4 >>> swarm.particleCoordinates.data array([[ 0.24261743, 0.67115852], [ 0.16116546, 0.70790335], [ 0.73160516, 0.08792286], [ 0.71953113, 0.15966135]])