Created
August 9, 2019 04:54
-
-
Save jmansour/44de4b2e091f2235289e23785bcc3809 to your computer and use it in GitHub Desktop.
UW28 blog post demo1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"The closest particle has index [[1]] and coord [[[ 0.4 0.4]]].\n" | |
] | |
} | |
], | |
"source": [ | |
"import underworld as uw\n", | |
"import numpy as np\n", | |
"mesh = uw.mesh.FeMesh_Cartesian(maxCoord=(2.,1.))\n", | |
"swarm = uw.swarm.Swarm(mesh)\n", | |
"# add some particles at known locations\n", | |
"part_coords = [(0.1,0.1),\n", | |
" (0.4,0.4),\n", | |
" (0.9,0.9),\n", | |
" (1.0,0.1),\n", | |
" (1.9,0.1)]\n", | |
"swarm.add_particles_with_coordinates( np.array(part_coords) )\n", | |
"# let's create a variable to record the particles local index\n", | |
"index_var = swarm.add_variable('int',1)\n", | |
"index_var.data[:,0] = np.arange(swarm.particleLocalCount)\n", | |
"# now evaluate in the centre of the domain\n", | |
"result = index_var.evaluate( (0.5,0.5) )\n", | |
"# we expect the 1th particle (counting starts from 0) with coord (0.4,0.4)\n", | |
"# to be the closest particle.. let's check\n", | |
"print(\"The closest particle has index {} and coord {}.\".format(result,swarm.data[result]))" | |
] | |
} | |
], | |
"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.5.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment