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

Update stencil2coo kernels for shifts > 1 #442

Merged
merged 5 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions psydac/linalg/kernels/stencil2coo_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def stencil2coo_1d_C(A:'T[:,:]', data:'T[:]', rows:'int64[:]', cols:'int64[:]',
for j1 in range(ncl1):
value = A[i1+pp1,j1]
if abs(value) == 0.0:continue
J = ((I//cm1)*dm1+j1-dp1)%nc1
J = ((I*dm1//cm1)+j1-dp1)%nc1
rows[nnz] = I
cols[nnz] = J
data[nnz] = value
Expand All @@ -38,7 +38,7 @@ def stencil2coo_1d_F(A:'T[:,:]', data:'T[:]', rows:'int64[:]', cols:'int64[:]',
for j1 in range(ncl1):
value = A[i1+pp1,j1]
if abs(value) == 0.0:continue
J = ((I//cm1)*dm1+j1-dp1)%nc1
J = ((I*dm1//cm1)+j1-dp1)%nc1
rows[nnz] = I
cols[nnz] = J
data[nnz] = value
Expand Down
44 changes: 44 additions & 0 deletions psydac/linalg/tests/test_stencil_matrix.py
max-models marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3154,6 +3154,50 @@ def test_stencil_matrix_2d_parallel_backend_dot(dtype, n1, n2, p1, p2, sh1, sh2,
assert (M + M).backend is M.backend
assert (2 * M).backend is M.backend

@pytest.mark.parametrize('dtype', [float])#, complex])
@pytest.mark.parametrize('n1', [4,6,10])
@pytest.mark.parametrize('p1', [3,4])
@pytest.mark.parametrize('s1', [1,2,3])
def test_stencil_matrix_1d_toarray(dtype, n1, p1, s1, P1=True):
max-models marked this conversation as resolved.
Show resolved Hide resolved
npts = [n1]
pads = [p1]
shifts = [s1]
ndim = len(npts)

# Create domain decomposition
D = DomainDecomposition(npts, periods=[P1])

# Partition the points
global_starts, global_ends = compute_global_starts_ends(D, npts, pads)
cart = CartDecomposition(D, npts, global_starts, global_ends, pads=pads, shifts=shifts)

# Create a vector space V and a matrix M from V to V
V = StencilVectorSpace(cart, dtype=dtype)
M = StencilMatrix(V, V)

sub = 1
diag = 2
sup = 3

M[:,-1] = sub
M[:,0] = diag
M[:,1] = sup

M_toarray = M.toarray()

# Create equivalent matrix with numpy
n = np.prod(npts)

matrix = np.identity(n) * diag
matrix[np.arange(1, n), np.arange(n-1)] = sub
matrix[np.arange(n-1), np.arange(1, n)] = sup

# Fill the first and last element of the secondary diagonals
matrix[0, n-1] = sub
matrix[n-1, 0] = sup

assert np.allclose(M.toarray(), matrix)

# ===============================================================================
# SCRIPT FUNCTIONALITY
# ===============================================================================
Expand Down