Skip to content

Commit

Permalink
Closes #82 (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanbsu authored Apr 4, 2024
1 parent c729167 commit 4209c01
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/pymgm_test/mgm2d/mgm2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def __init__(self, Lh=None, x=None, domArea=None, hasConstNullspace=None, verbos
self.polyDegT = 0
self.transferOp = 'RBF'
self.verbose = 1
self.coarsening_factor = 4

if Lh is not None and x is not None and domArea is not None and hasConstNullspace is not None and verbose is not None:
self.obj = self.constructor(Lh, x, domArea, hasConstNullspace, verbose)
Expand Down
4 changes: 3 additions & 1 deletion test/sqrpoisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ def squarepoissond(n):

# Make up a solution
uexact = np.sin(np.pi * x[:, 0] ** 2) * np.cos(np.pi * x[:, 1] ** 2)
uexact = uexact.reshape((-1, 1))
# Compute the right hand side for this solution
fh = Lh @ uexact
fh = Lh.dot(uexact)
fh = fh.reshape((-1, 1))

# The domain is a square with side length 2 so the area (or volume) is 4
vol = 4
Expand Down
Binary file added test/sqrpoisson_data/sqrpoisson_Lh.mat
Binary file not shown.
Binary file added test/sqrpoisson_data/sqrpoisson_uexact.mat
Binary file not shown.
Binary file added test/sqrpoisson_data/sqrpoisson_vol.mat
Binary file not shown.
Binary file added test/sqrpoisson_data/sqrpoisson_x.mat
Binary file not shown.
24 changes: 24 additions & 0 deletions test/test_squarepoisson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from sqrpoisson import squarepoissond
import os
import numpy as np
import scipy as sp
import pytest

def construct_file_path(folder_name, file_name):
# Construct the file path dynamically based on the current working directory
if os.path.basename(os.getcwd()) != 'test':
return os.path.join(os.getcwd(), 'test', folder_name, file_name)
else:
return os.path.join(folder_name, file_name)

def test_squarepoisson():
expected_Lh = sp.io.loadmat(construct_file_path('sqrpoisson_data', 'sqrpoisson_Lh.mat'))['Lh'].toarray()
expected_x = sp.io.loadmat(construct_file_path('sqrpoisson_data', 'sqrpoisson_x.mat'))['x']
expected_vol = sp.io.loadmat(construct_file_path('sqrpoisson_data', 'sqrpoisson_vol.mat'))['vol']
expected_uexact = sp.io.loadmat(construct_file_path('sqrpoisson_data', 'sqrpoisson_uexact.mat'))['uexact']
Lh, x, vol, fh, uexact = squarepoissond(50)

assert np.allclose(Lh.toarray(), expected_Lh)
assert np.allclose(x, expected_x)
assert np.allclose(vol, expected_vol)
assert np.allclose(uexact, expected_uexact)

0 comments on commit 4209c01

Please sign in to comment.