Skip to content

Commit 097bd4f

Browse files
committed
added 2d example
1 parent c593653 commit 097bd4f

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

polyfempy/Problems.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ def __init__(self):
8383

8484
def add_dirichlet_value(self, id, value, is_dirichlet_dim=None):
8585
"""add the Dirichlet value value for the sideset id. Note the value must be a vector in 2D or 3D depending on the problem. is_dirichlet_dim is a vector of boolean specifying which dimentions are fixed."""
86-
assert(len(value) == 3)
86+
assert(len(value) == 3 or len(value) == 2)
8787
tmp = {}
8888
tmp["id"] = id
8989
tmp["value"] = value
9090
if is_dirichlet_dim is not None:
91-
assert(len(is_dirichlet_dim) == 3)
91+
assert(len(is_dirichlet_dim) == 3 or len(is_dirichlet_dim) == 2)
9292
tmp["dimension"] = is_dirichlet_dim
9393

9494
self.dirichlet_boundary.append(tmp)

tests/plane_hole.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import unittest
2+
3+
import polyfempy as pf
4+
import utils
5+
import os
6+
7+
8+
class BendingTest(unittest.TestCase):
9+
def test_run(self):
10+
dir_path = os.path.dirname(os.path.realpath(__file__))
11+
mesh_path = os.path.join(dir_path, "../3rdparty/data/plane_hole.obj")
12+
13+
settings = pf.Settings()
14+
settings.discr_order = 1
15+
settings.normalize_mesh = True
16+
# settings.vismesh_rel_area = 0.1
17+
18+
19+
settings.set_material_params("E", 210000)
20+
settings.set_material_params("nu", 0.3)
21+
22+
23+
settings.tensor_formulation = pf.TensorFormulations.LinearElasticity
24+
25+
problem = pf.GenericTensor()
26+
problem.add_dirichlet_value(1, [0, 0], [True, False])
27+
problem.add_dirichlet_value(4, [0, 0], [False, True])
28+
29+
problem.add_neumann_value(3, [100, 0])
30+
31+
settings.set_problem(problem)
32+
33+
34+
solver = pf.Solver()
35+
36+
solver.settings(str(settings))
37+
solver.load_mesh(mesh_path)
38+
39+
solver.solve()
40+
41+
[pts, tets, disp] = solver.get_sampled_solution()
42+
vertices = pts + disp
43+
mises, _ = solver.get_sampled_mises_avg()
44+
45+
utils.plot(vertices, tets, mises)
46+
47+
48+
49+
if __name__ == '__main__':
50+
unittest.main()

tests/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
def plot(vertices, connectivity, function):
88
x = vertices[:,0]
99
y = vertices[:,1]
10-
z = vertices[:,2]
10+
11+
if vertices.shape[1] == 3:
12+
z = vertices[:,2]
13+
else:
14+
z = np.zeros(x.shape, dtype=x.dtype)
1115

1216
if connectivity.shape[1] == 3:
1317
f = connectivity

0 commit comments

Comments
 (0)