underworld.swarm.layouts module
This module contains classes for populating swarms with particles across the domain.
Classes
This layout populates the domain with particles located at gauss locations within each element of the swarm's associated finite element mesh. |
|
This layout fills the domain with particles in a random (per element) pattern. |
|
This layout fills the domain with particles in a quasi-random pattern. |
- class underworld.swarm.layouts.PerCellGaussLayout(self, swarm, gaussPointCount, **kwargs)[source]
Bases:
_ParticleLayoutAbstractThis 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(self, swarm, particlesPerCell, seed=13, **kwargs)[source]
Bases:
_PerCellMeshParticleLayoutThis 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]])
- class underworld.swarm.layouts.PerCellSpaceFillerLayout(self, swarm, particlesPerCell, **kwargs)[source]
Bases:
_PerCellMeshParticleLayoutThis 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]])