devito icon indicating copy to clipboard operation
devito copied to clipboard

Combination of Subdomain and ConditionalDimension

Open timrmac opened this issue 1 year ago • 1 comments

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)

timrmac avatar Jan 23 '23 14:01 timrmac