-
Notifications
You must be signed in to change notification settings - Fork 222
/
test_constant.py
36 lines (28 loc) · 1 KB
/
test_constant.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np
from devito import Grid, Constant, Function, TimeFunction, Eq, solve, Operator
class TestConst(object):
"""
Class for testing Constant
"""
def test_const_change(self):
"""
Test that Constand.data can be set as required.
"""
n = 5
t = Constant(name='t', dtype=np.int32)
grid = Grid(shape=(2, 2))
x, y = grid.dimensions
f = TimeFunction(name='f', grid=grid, save=n+1)
f.data[:] = 0
eq = Eq(f.dt-1)
stencil = Eq(f.forward, solve(eq, f.forward))
op = Operator([stencil])
op.apply(time_m=0, time_M=n-1, dt=1)
check = Function(name='check', grid=grid)
eq_test = Eq(check, f[t, x, y])
op_test = Operator([eq_test])
for j in range(0, n+1):
t.data = j # Ensure constant is being updated correctly
op_test.apply(t=t)
assert(np.amax(check.data[:], axis=None) == j)
assert(np.amin(check.data[:], axis=None) == j)