{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**This is a minimal test for population control**"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import underworld as uw\n",
"import underworld.visualisation as vis "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"mesh = uw.mesh.FeMesh_Cartesian()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def vanilla_swarm(mesh):\n",
" swarm = uw.swarm.Swarm(mesh)\n",
" swarm.populate_using_layout(uw.swarm.layouts.PerCellGaussLayout(swarm,4))\n",
" return swarm\n",
"def draw_swarm(mesh,swarm):\n",
" fig = vis.Figure()\n",
" fig.append( vis.objects.Points(swarm, colourBar=False, pointSize=4.))\n",
" fig.append( vis.objects.Mesh(mesh))\n",
" return fig.show()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# generated swarm\n",
"swarm = vanilla_swarm(mesh)\n",
"draw_swarm( mesh, swarm )"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"256"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"swarm.particleGlobalCount"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# test deleting particles limited by max\n",
"swarm = vanilla_swarm(mesh)\n",
"population_control = uw.swarm.PopulationControl(swarm,deleteThreshold=1.0,splitThreshold=1.0,maxDeletions=15,maxSplits=0)\n",
"population_control.repopulate()\n",
"if swarm.particleGlobalCount != 16:\n",
" raise RuntimeError(\"Incorrect number of particles deleted during population control\")\n",
"# test deleting particles limited by threshold\n",
"swarm = vanilla_swarm(mesh)\n",
"population_control = uw.swarm.PopulationControl(swarm,deleteThreshold=0.07,splitThreshold=1.0,maxDeletions=150,maxSplits=0)\n",
"population_control.repopulate()\n",
"if swarm.particleGlobalCount != 64:\n",
" raise RuntimeError(\"Incorrect number of particles deleted during population control\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# test splitting particles limited by max\n",
"swarm = vanilla_swarm(mesh)\n",
"population_control = uw.swarm.PopulationControl(swarm,deleteThreshold=0.,splitThreshold=0.,maxDeletions=0,maxSplits=9999)\n",
"population_control.repopulate()\n",
"if swarm.particleGlobalCount != 512:\n",
" raise RuntimeError(\"Incorrect number of particles deleted during population control\")\n",
"# test deleting particles limited by threshold\n",
"swarm = vanilla_swarm(mesh)\n",
"population_control = uw.swarm.PopulationControl(swarm,deleteThreshold=0.,splitThreshold=0.07,maxDeletions=0,maxSplits=9999)\n",
"population_control.repopulate()\n",
"if swarm.particleGlobalCount != 320:\n",
" raise RuntimeError(\"Incorrect number of particles deleted during population control\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# quick aggressive test\n",
"swarm = vanilla_swarm(mesh)\n",
"population_control = uw.swarm.PopulationControl(swarm,deleteThreshold=0.,splitThreshold=1.,maxDeletions=0,maxSplits=0, aggressive=True, particlesPerCell=40)\n",
"population_control.repopulate()\n",
"if swarm.particleGlobalCount != 640:\n",
" raise RuntimeError(\"Incorrect number of particles deleted during population control\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}