Skip to content

Commit b819baa

Browse files
author
Teseo Schneider
committed
added selections and contact
1 parent ebb84af commit b819baa

4 files changed

Lines changed: 205 additions & 216 deletions

File tree

polyfempy/Problem.py

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
import json
22
import types
33

4+
45
class Problem:
56
"""Generic problem problem, scalar or tensor depending on the pde. Warning, this problem needs to be used with the `set_pde` function in settings"""
67

7-
def __init__(self, rhs=None, exact=None):
8+
def __init__(self, rhs=None, exact=None, is_time_dependent=False):
89
self.rhs = rhs
10+
self.is_time_dependent = is_time_dependent
911
self.exact = exact
1012
self.dirichlet_boundary = []
1113
self.neumann_boundary = []
1214
self.pressure_boundary = []
1315

14-
self.dirichlet_boundary_lambda = []
15-
self.neumann_boundary_lambda = []
16-
self.pressure_boundary_lambda = []
16+
# self.dirichlet_boundary_lambda = []
17+
# self.neumann_boundary_lambda = []
18+
# self.pressure_boundary_lambda = []
1719

18-
def set_dirichlet_value(self, id, value, is_dirichlet_dim=None):
20+
def set_dirichlet_value(self, id, value, is_dirichlet_dim=None, linear_ramp_to=None):
1921
"""set the Dirichlet value value for the sideset id. Note the value must be a scalar, vector in 2D, or 3D depending on the problem. is_dirichlet_dim is a vector of boolean specifying which dimentions are fixed, only for vector-based problems."""
20-
self.add_dirichlet_value(id, value, is_dirichlet_dim)
22+
self.add_dirichlet_value(id, value, is_dirichlet_dim, linear_ramp_to)
2123

22-
def set_neumann_value(self, id, value):
24+
def set_neumann_value(self, id, value, linear_ramp_to=None):
2325
"""set the Neumann value value for the sideset id. Note the value must be a scalar, vector in 2D, or 3D depending on the problem"""
24-
self.add_neumann_value(id, value)
26+
self.add_neumann_value(id, value, linear_ramp_to)
2527

26-
def set_pressure_value(self, id, value):
28+
def set_pressure_value(self, id, value, linear_ramp_to=None):
2729
"""set the Pressure value value for the sideset id. Note the value must be a scalar"""
28-
self.add_pressure_value(id, value)
30+
self.add_pressure_value(id, value, linear_ramp_to)
2931

30-
def add_dirichlet_value(self, id, value, is_dirichlet_dim=None):
32+
def add_dirichlet_value(self, id, value, is_dirichlet_dim=None, linear_ramp_to=None):
3133
"""set the Dirichlet value value for the sideset id. Note the value must be a scalar, vector in 2D, or 3D depending on the problem. is_dirichlet_dim is a vector of boolean specifying which dimentions are fixed, only for vector-based problems."""
3234

3335
tmp = {}
@@ -38,50 +40,58 @@ def add_dirichlet_value(self, id, value, is_dirichlet_dim=None):
3840
assert(len(value) == len(is_dirichlet_dim))
3941
tmp["dimension"] = is_dirichlet_dim
4042

43+
if linear_ramp_to is not None:
44+
tmp["linear_ramp"] = {"to": linear_ramp_to}
45+
4146
if isinstance(value, types.LambdaType) or isinstance(value, types.FunctionType):
4247
pass
4348
# self.dirichlet_boundary_lambda.append(tmp)
4449
else:
4550
self.dirichlet_boundary.append(tmp)
4651

47-
def add_neumann_value(self, id, value):
52+
def add_neumann_value(self, id, value, linear_ramp_to=None):
4853
"""set the Neumann value value for the sideset id. Note the value must be a scalar, vector in 2D, or 3D depending on the problem"""
4954

5055
tmp = {}
5156
tmp["id"] = id
5257
tmp["value"] = value
5358

59+
if linear_ramp_to is not None:
60+
tmp["linear_ramp"] = {"to": linear_ramp_to}
61+
5462
if isinstance(value, types.LambdaType) or isinstance(value, types.FunctionType):
5563
pass
5664
# self.neumann_boundary_lambda.append(tmp)
5765
else:
5866
self.neumann_boundary.append(tmp)
5967

60-
def add_pressure_value(self, id, value):
68+
def add_pressure_value(self, id, value, linear_ramp_to=None):
6169
"""set the Pressure value value for the sideset id. Note the value must be a scalar"""
6270

6371
tmp = {}
6472
tmp["id"] = id
6573
tmp["value"] = value
6674

75+
if linear_ramp_to is not None:
76+
tmp["linear_ramp"] = {"to": linear_ramp_to}
77+
6778
if isinstance(value, types.LambdaType) or isinstance(value, types.FunctionType):
6879
pass
6980
# self.pressure_boundary_lambda.append(tmp)
7081
else:
7182
self.pressure_boundary.append(tmp)
7283

73-
74-
def set_velocity(self, id, value, is_dim_fixed=None):
84+
def set_velocity(self, id, value, is_dim_fixed=None, linear_ramp_to=None):
7585
"""set the velocity value for the sideset id. Note the value must be a vector in 2D or 3D depending on the problem"""
76-
self.add_dirichlet_value(id, value, is_dim_fixed)
86+
self.add_dirichlet_value(id, value, is_dim_fixed, linear_ramp_to)
7787

78-
def set_displacement(self, id, value, is_dim_fixed=None):
88+
def set_displacement(self, id, value, is_dim_fixed=None, linear_ramp_to=None):
7989
"""set the displacement value for the sideset id. Note the value must be a vector in 2D or 3D depending on the problem"""
80-
self.add_dirichlet_value(id, value, is_dim_fixed)
90+
self.add_dirichlet_value(id, value, is_dim_fixed, linear_ramp_to)
8191

82-
def set_force(self, id, value):
92+
def set_force(self, id, value, linear_ramp_to=None):
8393
"""set the force value for the sideset id. Note the value must be a vector in 2D or 3D depending on the problem"""
84-
self.add_neumann_value(id, value)
94+
self.add_neumann_value(id, value, linear_ramp_to)
8595

8696
def set_x_symmetric(self, id):
8797
"""x coorinate is fixed, y is allowed to move (Neumann)"""
@@ -108,8 +118,8 @@ def params(self):
108118
tmp = dict(
109119
(key, value)
110120
for (key, value) in self.__dict__.items())
111-
tmp.pop('dirichlet_boundary_lambda', None)
112-
tmp.pop('neumann_boundary_lambda', None)
113-
tmp.pop('pressure_boundary_lambda', None)
121+
# tmp.pop('dirichlet_boundary_lambda', None)
122+
# tmp.pop('neumann_boundary_lambda', None)
123+
# tmp.pop('pressure_boundary_lambda', None)
114124

115125
return tmp

polyfempy/Selection.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import json
2+
3+
4+
class Selection:
5+
"""Object used to select sideset and bodies"""
6+
7+
def __init__(self):
8+
self.body_ids = []
9+
self.boundary_sidesets = []
10+
11+
def select_body_with_sphere(self, id, center, radius):
12+
"""Select a body using a sphere"""
13+
self.body_ids.append({"id": id, "center": center, "radius": radius})
14+
15+
def select_body_with_box(self, id, box_min, box_max):
16+
"""Select a body using an axis-aligned box"""
17+
self.body_ids.append({"id": id, "box": [box_min, box_max]})
18+
19+
def select_body_with_axis_plane(self, id, axis, position):
20+
"""Select a body using an axis-aligned plane at position position, axis 1, 2, 3 is x, y, and z respectively. Use negative to flip axis (e.g., -1 is negative x axis)"""
21+
self.body_ids.append({"id": id, "position": position, "axis": axis})
22+
23+
def select_body_with_plane(self, id, normal, offset):
24+
"""Select a body using a generic plane with normal normal, the point on the plane is defined by normal*offset"""
25+
self.body_ids.append({"id": id, "normal": normal, "offset": offset})
26+
27+
def select_sideset_with_sphere(self, id, center, radius):
28+
"""Select a boundary sideset using a sphere"""
29+
self.boundary_sidesets.append(
30+
{"id": id, "center": center, "radius": radius})
31+
32+
def select_sideset_with_box(self, id, box_min, box_max):
33+
"""Select a boundary sideset using an axis-aligned box"""
34+
self.boundary_sidesets.append({"id": id, "box": [box_min, box_max]})
35+
36+
def select_sideset_with_axis_plane(self, id, axis, position):
37+
"""Select a boundary sideset using an axis-aligned plane at position position, axis 1, 2, 3 is x, y, and z respectively. Use negative to flip axis (e.g., -1 is negative x axis)"""
38+
self.boundary_sidesets.append(
39+
{"id": id, "position": position, "axis": axis})
40+
41+
def select_sideset_with_plane(self, id, normal, offset):
42+
"""Select a boundary sideset using a generic plane with normal normal, the point on the plane is defined by normal*offset"""
43+
self.boundary_sidesets.append(
44+
{"id": id, "normal": normal, "offset": offset})
45+
46+
def __str__(self):
47+
"""stringygied json description of this class, used to run the solver"""
48+
49+
tmp = dict(
50+
(key, value)
51+
for (key, value) in self.__dict__.items())
52+
53+
return json.dumps(tmp, sort_keys=True, indent=4)

0 commit comments

Comments
 (0)