Skip to content
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

Combination of Subdomain and ConditionalDimension #2049

Closed
timrmac opened this issue Jan 23, 2023 · 1 comment · Fixed by #2050
Closed

Combination of Subdomain and ConditionalDimension #2049

timrmac opened this issue Jan 23, 2023 · 1 comment · Fixed by #2050
Assignees
Labels

Comments

@timrmac
Copy link

timrmac commented Jan 23, 2023

ConditionalDimension is setup to run within a Subdomain. The ConditionalDimension is a boolean mask within the Subdomain. Both work with functions separately. However, when combined produces strange values. A thread has been opened in DevitoCodes/#Development to discuss this error (https://devitocodes.slack.com/archives/C7JMLMSG0/p1674231704845469?thread_ts=1674231704.845469&cid=C7JMLMSG0). As pointed out by Fabio, the ConditionalDimension needs to reference the parent dimension of the subdomain, yi, instead of the full domain, y. However, this produces a python error which is not obvious.

Here is some code the reproduces the error:

from devito import *
shape = (10, 10)
grid = Grid(shape = shape)
x, y = grid.dimensions

sdf = Function(name='sdf', grid=grid)
sdf.data[:,5:] = 1
sdf.data[2:6,3:5]=1

condition = Lt(sdf, 1)
ci = ConditionalDimension(name='ci', condition=condition, parent=y)

class Middle(SubDomain):
    name = 'middle'
    def define(self, dimensions):
        return {x: x, y: ('middle', 2, 4)}
mid = Middle() 
my_grid = Grid(shape = shape, subdomains = (mid, ))

f = Function(name='f', grid=my_grid)
op3 = Operator(Eq(f, f + 10, implicit_dims=ci, subdomain = my_grid.subdomains['middle']))
op3.apply()
print('\noperator with conditional dimension and subdomain:')
print(f.data.T)

print(op3.ccode)
@FabioLuporini
Copy link
Contributor

I looked at what the compiler does currently, and it looks correct to me. It might instead be a user problem after all

class Middle(SubDomain):
    name = 'middle'
    def define(self, dimensions):
        return {x: x, y: ('middle', 2, 4)}
mid = Middle() 
my_grid = Grid(shape = shape, subdomains = (mid, ))

_, yi = mid.dimensions
condition = Lt(sdf, 1).subs(y, yi)
ci = ConditionalDimension(name='ci', condition=condition, parent=y)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants