-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
examples: Boundary reconstruction #1926
base: master
Are you sure you want to change the base?
Changes from all commits
77aec6c
4feee17
e3d57c1
67d3f34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from math import sin, floor | ||
from math import sin, floor, prod | ||
|
||
import numpy as np | ||
import pytest | ||
|
@@ -53,6 +53,18 @@ def time_points(grid, ranges, npoints, name='points', nt=10): | |
return points | ||
|
||
|
||
def time_grid_points(grid, name='points', nt=10): | ||
"""Create a SparseTimeFunction field with coordinates | ||
filled in by all grid points""" | ||
npoints = prod(grid.shape) | ||
a = SparseTimeFunction(name=name, grid=grid, npoint=npoints, nt=nt) | ||
dims = tuple([np.linspace(0., 1., d) for d in grid.shape]) | ||
for i in range(len(grid.shape)): | ||
a.coordinates.data[:,i] = np.meshgrid(*dims)[i].flatten() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can probably compute meshgrid only once before the for loop |
||
|
||
return a | ||
|
||
|
||
def a(shape=(11, 11)): | ||
grid = Grid(shape=shape) | ||
a = Function(name='a', grid=grid) | ||
|
@@ -417,6 +429,31 @@ def test_inject_time_shift(shape, coords, result, npoints=19): | |
assert np.allclose(a.data[indices], result, rtol=1.e-5) | ||
|
||
|
||
@pytest.mark.parametrize('shape, result, increment', [ | ||
((10, 10), 1., False), | ||
((10, 10), 5., True), | ||
((10, 10, 10), 1., False), | ||
((10, 10, 10), 5., True) | ||
]) | ||
def test_inject_time_increment(shape, result, increment): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for attaching tests to this PR! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be worth having another test to check that increment=False specified on SparseFunction with non-grid-aligned points is caught and handled appropriately? |
||
"""Test the increment option in the SparseTimeFunction's | ||
injection method. The increment=False option is | ||
expected to work only at points located on the grid, | ||
where no interpolation needed. | ||
""" | ||
a = unit_box_time(shape=shape) | ||
a.data[:] = 0. | ||
p = time_grid_points(a.grid, name='points', nt=10) | ||
|
||
expr = p.inject(a, Float(1.), increment=increment) | ||
|
||
Operator(expr)(a=a) | ||
|
||
assert np.allclose(a.data, result*np.ones(a.grid.shape), rtol=1.e-5) | ||
|
||
|
||
|
||
|
||
@pytest.mark.parametrize('shape, coords, result', [ | ||
((11, 11), [(.05, .95), (.45, .45)], 1.), | ||
((11, 11, 11), [(.05, .95), (.45, .45), (.45, .45)], 0.5) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you picking
idx_subs[0]
? should you not traverse the whole list ofidx_subs
like in theincrement
case?Could you do something like:
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because I thought in this case very specifically to apply boundary conditions, not source injection, for example. The `
increment=False
option as I suggested should not be used for off-grid points.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this is true for your case, the generic case is still a standard potentially off the grid point injection without increment. So there is two option
The first case is definitely easier and should still work for your case and would boil down to what @FabioLuporini wrote earlier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the first option is not possible for the case
increment = False
. Because even if the point is exactly on the grid, interpolation coefficients equal to zero will vanish the fields at points that should not be vanished. Which is not the case for injecting the source (whenincrement = True
), for example, since accumulating zeros does not change the field at the other points involved in the interpolation.The way I see it, we are left with the second option that @mloubout suggested, or use subdomains that are under development in another PR if I'm not mistaken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed good point I missed that gotta think about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mloubout prodding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting back here since been looking into sparse, I think that the "best" way to go for
increment=Flase
is to do whatinterpolation
does i.esum
and do the standardsum += inject(expr)
field = sum
This would cover the off-the-grid case as well