Skip to content

Commit 5cf3dbc

Browse files
committed
simple test
1 parent 773239c commit 5cf3dbc

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

polyfempy/test/__init__.py

Whitespace-only changes.

polyfempy/test/test_pythonic.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import unittest
2+
3+
import numpy as np
4+
import polyfempy as pf
5+
6+
7+
class PythonicTest(unittest.TestCase):
8+
def test_run(self):
9+
n_pts = 3
10+
11+
extend = np.linspace(0, 1, n_pts)
12+
x, y = np.meshgrid(extend, extend, sparse=False, indexing='xy')
13+
pts = np.column_stack((x.ravel(), y.ravel()))
14+
15+
# Create connectivity
16+
faces = np.ndarray([(n_pts-1)**2, 4], dtype=np.int32)
17+
18+
index = 0
19+
for i in range(n_pts-1):
20+
for j in range(n_pts-1):
21+
faces[index, :] = np.array([
22+
j + i * n_pts,
23+
j+1 + i * n_pts,
24+
j+1 + (i+1) * n_pts,
25+
j + (i+1) * n_pts
26+
])
27+
index = index + 1
28+
29+
def sideset(p):
30+
if p[0] <= 0.001:
31+
return 4
32+
return 1
33+
34+
solver = pf.solve(
35+
vertices=pts,
36+
cells=faces,
37+
sidesets_func=sideset,
38+
diriclet_bc=[{"id": 4, "value": [0, 0]}],
39+
materials=[{"id": 0, "E": 2100, "nu": 0.3}],
40+
rhs=[0, 0.1],
41+
pde=pf.PDEs.LinearElasticity,
42+
discr_order=1
43+
)
44+
45+
log = solver.get_log()
46+
47+
# Get the solution
48+
pts, tris, el_id, bid, fun = solver.get_sampled_solution()
49+
assert(abs(np.linalg.norm(fun) - 0.03) < 1e-3)
50+
51+
52+
if __name__ == '__main__':
53+
unittest.main()

0 commit comments

Comments
 (0)