Skip to content

Commit

Permalink
[doc] Use Field.geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
holl- committed Mar 4, 2024
1 parent e426a4b commit 8611cf6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/Animations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
{
"cell_type": "code",
"source": [
"grid = flatten(CenteredGrid(x=12, y=10).elements).center\n",
"grid = flatten(CenteredGrid(x=12, y=10).geometry).center\n",
"direction = math.rotate_vector(vec(x=0, y=1), angle=math.linspace(0, 2*PI, batch(time=50)))\n",
"plot(PointCloud(grid, direction), animate='time')"
],
Expand Down
18 changes: 9 additions & 9 deletions docs/Billiards.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,20 @@
" rel_v = v.values - rename_dims(v.values, 'balls', 'others')\n",
" dist_dir = math.safe_div(dist, dist_norm)\n",
" projected_v = dist_dir.vector * rel_v.vector\n",
" has_impact = (projected_v < 0) & (dist_norm < 2 * v.elements.radius)\n",
" has_impact = (projected_v < 0) & (dist_norm < 2 * v.geometry.radius)\n",
" impulse = -(1 + elasticity) * .5 * projected_v * dist_dir\n",
" radius_sum = v.elements.radius + rename_dims(v.elements.radius, 'balls', 'others')\n",
" radius_sum = v.geometry.radius + rename_dims(v.geometry.radius, 'balls', 'others')\n",
" impact_time = math.safe_div(dist_norm - radius_sum, projected_v)\n",
" x_inc_contrib = math.sum(math.where(has_impact, math.minimum(impact_time - dt, 0) * impulse, 0), 'others')\n",
" v = v.with_elements(v.elements.shifted(x_inc_contrib))\n",
" v = v.with_elements(v.geometry.shifted(x_inc_contrib))\n",
" v += math.sum(math.where(has_impact, impulse, 0), 'others')\n",
" return advect.points(v, v, dt)\n",
"\n",
"# Simple animated test for physics_step\n",
"balls = Sphere(tensor([(0, .03), (.5, 0)], instance('balls'), channel(vector='x,y')), radius=.03)\n",
"ball_v = PointCloud(balls, tensor([(1., 0), (0, 0)], shape(balls)))\n",
"trj = iterate(physics_step, batch(t=20), ball_v, f_kwargs={'dt': .05})\n",
"plot(trj.elements, animate='t')"
"plot(trj.geometry, animate='t')"
],
"metadata": {
"colab": {
Expand Down Expand Up @@ -374,7 +374,7 @@
"source": [
"def loss_function(x0: Tensor, v0: Tensor, goal=vec(x=0.9, y=0.75), steps=1024):\n",
" triangle_balls = PointCloud(billiards_triangle()) * (0, 0)\n",
" controllable_ball = PointCloud(Sphere(expand(x0, instance(triangle_balls).with_size(1)), radius=triangle_balls.elements.radius)) * v0\n",
" controllable_ball = PointCloud(Sphere(expand(x0, instance(triangle_balls).with_size(1)), radius=triangle_balls.geometry.radius)) * v0\n",
" all_balls = controllable_ball & triangle_balls\n",
" trj = iterate(physics_step, batch(t=steps), all_balls, f_kwargs={'dt': 0.003})\n",
" return math.l2_loss(trj.t[-1].balls[-1] - goal), trj"
Expand Down Expand Up @@ -403,7 +403,7 @@
{
"cell_type": "code",
"source": [
"plot(loss_function(x0=vec(x=.1, y=.5), v0=vec(x=.3, y=0))[1].t[::16].elements, animate='t')"
"plot(loss_function(x0=vec(x=.1, y=.5), v0=vec(x=.3, y=0))[1].t[::16].geometry, animate='t')"
],
"metadata": {
"colab": {
Expand All @@ -423,7 +423,7 @@
"name": "stderr",
"text": [
"/usr/local/lib/python3.7/dist-packages/phi/field/_field_math.py:405: RuntimeWarning: concat() default implementation is slow on large dimensions (balls=11). Please implement __concat__()\n",
" elements = geom.concat([f.elements for f in fields], dim, sizes=[f.shape.get_size(dim) for f in fields])\n",
" elements = geom.concat([f.geometry for f in fields], dim, sizes=[f.shape.get_size(dim) for f in fields])\n",
"/usr/local/lib/python3.7/dist-packages/phi/field/_field_math.py:407: RuntimeWarning: concat() default implementation is slow on large dimensions (balls=11). Please implement __concat__()\n",
" colors = math.concat([math.expand(f.color, f.shape.only(dim)) for f in fields], dim)\n"
]
Expand Down Expand Up @@ -1199,7 +1199,7 @@
"name": "stderr",
"text": [
"/usr/local/lib/python3.7/dist-packages/phi/field/_field_math.py:405: RuntimeWarning: concat() default implementation is slow on large dimensions (balls=11). Please implement __concat__()\n",
" elements = geom.concat([f.elements for f in fields], dim, sizes=[f.shape.get_size(dim) for f in fields])\n",
" elements = geom.concat([f.geometry for f in fields], dim, sizes=[f.shape.get_size(dim) for f in fields])\n",
"/usr/local/lib/python3.7/dist-packages/phi/field/_field_math.py:407: RuntimeWarning: concat() default implementation is slow on large dimensions (balls=11). Please implement __concat__()\n",
" colors = math.concat([math.expand(f.color, f.shape.only(dim)) for f in fields], dim)\n",
"/usr/local/lib/python3.7/dist-packages/phi/math/_magic_ops.py:101: RuntimeWarning: expand() default implementation is slow on large shapes (alphaᵇ=1000). Please implement __expand__()\n",
Expand Down Expand Up @@ -1248,7 +1248,7 @@
" v0 -= learning_rate * dv0\n",
"final_loss, trj = loss_function(x0, v0)\n",
"print(f\"Final loss: {final_loss}\")\n",
"plot(vis.overlay(trj.t[::16].elements, vec(x=0.9, y=0.75)), animate='t')"
"plot(vis.overlay(trj.t[::16].geometry, vec(x=0.9, y=0.75)), animate='t')"
],
"metadata": {
"colab": {
Expand Down
4 changes: 2 additions & 2 deletions docs/Fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The most important sampled fields are
Important properties:

* `.values: Tensor` data that is used in sampling
* `.elements: Geometry` sample points as finite volumes
* `.geometry: Geometry` sample points as finite volumes
* `.points: Tensor` center points of `elements`
* `.extrapolation: Extrapolation` determines how values outside the region covered by `values` are determined.

Expand All @@ -49,7 +49,7 @@ They model `F(x)` as a function instead of from data.
[`CenteredGrid`](phi/field/#phi.field.CenteredGrid) stores values in a regular grid structure.
The grid values are stored in a `Tensor` whose spatial dimensions match the resolution of the grid.
The `bounds` property stores the physical size of the grid from which the cell size is derived.
`CenteredGrid.elements` is a `UniformGrid` matching the grid resolution.
`CenteredGrid.geometry` is a `UniformGrid` matching the grid resolution.

[`StaggeredGrid`](phi/field/#phi.field.StaggeredGrid)
stores vector fields in staggered form.
Expand Down

0 comments on commit 8611cf6

Please sign in to comment.