Skip to content

Commit fabe8b3

Browse files
Use new FourCIPP type converter
1 parent 67af518 commit fabe8b3

File tree

6 files changed

+24
-69
lines changed

6 files changed

+24
-69
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dynamic = ["version"]
3030

3131
[project.optional-dependencies]
3232
cubitpy = ["cubitpy@git+https://github.com/imcs-compsim/cubitpy.git@main"]
33-
fourc = ["fourcipp@git+https://github.com/4c-multiphysics/fourcipp.git@main"]
33+
fourc = ["fourcipp@git+https://github.com/davidrudlstorfer/fourcipp.git@add_type_converter"]
3434
dev = [
3535
"coverage-badge",
3636
"coverage",

src/meshpy/core/node.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,9 @@ def rotate(self, *args, **kwargs):
9696
def dump_to_list(self):
9797
"""Return a list with the legacy string representing this node."""
9898

99-
# TODO here a numpy data type is converted to a standard Python
100-
# data type. Once FourCIPP can handle non standard data types,
101-
# this should be removed.
10299
return {
103100
"id": self.i_global,
104-
"COORD": self.coordinates.tolist(),
101+
"COORD": self.coordinates,
105102
"data": {"type": "NODE"},
106103
}
107104

@@ -152,11 +149,8 @@ def dump_to_list(self):
152149
"""Return a list with the legacy string representing this control
153150
point."""
154151

155-
# TODO here a numpy data type is converted to a standard Python
156-
# data type. Once FourCIPP can handle non standard data types,
157-
# this should be removed.
158152
return {
159153
"id": self.i_global,
160-
"COORD": self.coordinates.tolist(),
154+
"COORD": self.coordinates,
161155
"data": {"type": "CP", "weight": self.weight},
162156
}

src/meshpy/core/nurbs_patch.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,9 @@ def get_ids_ctrlpts_surface(knot_span_u, knot_span_v):
214214
self.polynomial_orders[1] + 1
215215
)
216216

217-
# TODO here a numpy data type is converted to a standard Python
218-
# data type. Once FourCIPP can handle non standard data types,
219-
# this should be removed.
220217
patch_elements.append(
221218
{
222-
"id": int(self.i_global + j),
219+
"id": self.i_global + j,
223220
"cell": {
224221
"type": f"NURBS{num_cp_in_element}",
225222
"connectivity": connectivity,
@@ -318,12 +315,9 @@ def get_ids_ctrlpts_volume(knot_span_u, knot_span_v, knot_span_w):
318315
* (self.polynomial_orders[2] + 1)
319316
)
320317

321-
# TODO here a numpy data type is converted to a standard Python
322-
# data type. Once FourCIPP can handle non standard data types,
323-
# this should be removed.
324318
patch_elements.append(
325319
{
326-
"id": int(self.i_global + increment_ele),
320+
"id": self.i_global + increment_ele,
327321
"cell": {
328322
"type": f"NURBS{num_cp_in_element}",
329323
"connectivity": connectivity,

src/meshpy/four_c/element_beam.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,17 @@ def dump_to_list(self):
5151
# Check the material.
5252
self._check_material()
5353

54-
# TODO here a numpy data type is converted to a standard Python
55-
# data type. Once FourCIPP can handle non standard data types,
56-
# this should be removed.
5754
return {
5855
"id": self.i_global,
5956
"cell": {
6057
"type": "HERM2LINE3",
61-
"connectivity": [int(self.nodes[i].i_global) for i in [0, 2, 1]],
58+
"connectivity": [self.nodes[i].i_global for i in [0, 2, 1]],
6259
},
6360
"data": {
6461
"type": "BEAM3R",
6562
"MAT": self.material.i_global,
6663
"TRIADS": [
67-
float(item)
64+
item
6865
for i in [0, 2, 1]
6966
for item in self.nodes[i].rotation.get_rotation_vector()
7067
],
@@ -89,20 +86,17 @@ def dump_to_list(self):
8986
# Check the material.
9087
self._check_material()
9188

92-
# TODO here a numpy data type is converted to a standard Python
93-
# data type. Once FourCIPP can handle non standard data types,
94-
# this should be removed.
9589
return {
9690
"id": self.i_global,
9791
"cell": {
9892
"type": "LINE2",
99-
"connectivity": [int(self.nodes[i].i_global) for i in [0, 1]],
93+
"connectivity": [self.nodes[i].i_global for i in [0, 1]],
10094
},
10195
"data": {
10296
"type": "BEAM3R",
10397
"MAT": self.material.i_global,
10498
"TRIADS": [
105-
float(item)
99+
item
106100
for i in [0, 1]
107101
for item in self.nodes[i].rotation.get_rotation_vector()
108102
],
@@ -141,22 +135,19 @@ def dump_to_list(self):
141135
# Check the material.
142136
self._check_material()
143137

144-
# TODO here a numpy data type is converted to a standard Python
145-
# data type. Once FourCIPP can handle non standard data types,
146-
# this should be removed.
147138
return {
148139
"id": self.i_global,
149140
"cell": {
150141
"type": "LINE3",
151-
"connectivity": [int(self.nodes[i].i_global) for i in [0, 2, 1]],
142+
"connectivity": [self.nodes[i].i_global for i in [0, 2, 1]],
152143
},
153144
"data": {
154145
"type": "BEAM3K",
155146
"WK": 1 if self.weak else 0,
156147
"ROTVEC": 1 if self.rotvec else 0,
157148
"MAT": self.material.i_global,
158149
"TRIADS": [
159-
float(item)
150+
item
160151
for i in [0, 2, 1]
161152
for item in self.nodes[i].rotation.get_rotation_vector()
162153
],
@@ -210,14 +201,11 @@ def dump_to_list(self):
210201
"The rotations do not match the direction of the Euler Bernoulli beam!"
211202
)
212203

213-
# TODO here a numpy data type is converted to a standard Python
214-
# data type. Once FourCIPP can handle non standard data types,
215-
# this should be removed.
216204
return {
217205
"id": self.i_global,
218206
"cell": {
219207
"type": "LINE2",
220-
"connectivity": [int(self.nodes[i].i_global) for i in [0, 1]],
208+
"connectivity": [self.nodes[i].i_global for i in [0, 1]],
221209
},
222210
"data": {
223211
"type": "BEAM3EB",

src/meshpy/four_c/input_file.py

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ def add(self, object_to_add, **kwargs):
131131
self.add_mesh_to_input_file(mesh=object_to_add, **kwargs)
132132

133133
else:
134-
super().combine_sections(object_to_add, **kwargs)
134+
custom_converters = [(_Function, lambda obj: obj.i_global)]
135+
super().combine_sections(object_to_add, custom_converters=custom_converters)
135136

136137
def dump(
137138
self,
@@ -336,36 +337,10 @@ def _dump_mesh_items(section_name, data_list):
336337
elif hasattr(item, "dump_to_list"):
337338
list.append(item.dump_to_list())
338339
elif isinstance(item, _BoundaryCondition):
339-
# Here we need to convert the function objects to their
340-
# global index.
341-
342-
def convert_function_field(key, value):
343-
"""Convert function objects in boundary condititions to
344-
their global index.
345-
346-
TODO improve this approach
347-
"""
348-
349-
if key != "FUNCT":
350-
return value
351-
352-
if isinstance(value, _List):
353-
return [
354-
v.i_global if isinstance(v, _Function) else v
355-
for v in value
356-
]
357-
if isinstance(value, _Function):
358-
return value.i_global
359-
else:
360-
return value
361-
362340
list.append(
363341
{
364342
"E": item.geometry_set.i_global,
365-
**{
366-
key: convert_function_field(key, value)
367-
for key, value in item.data.items()
368-
},
343+
**item.data,
369344
}
370345
)
371346

@@ -374,11 +349,15 @@ def convert_function_field(key, value):
374349
else:
375350
raise TypeError(f"Could not dump {item}")
376351

352+
# If section already exists, retrieve from input file and
353+
# add newly. We always need to go through fourcipp to convert
354+
# the data types correctly.
377355
if section_name in self.sections:
378-
# If the section already exists, append the new data to it.
379-
self.sections[section_name].extend(list)
380-
else:
381-
self.add({section_name: list})
356+
existing_entries = self.pop(section_name)
357+
existing_entries.extend(list)
358+
list = existing_entries
359+
360+
self.add({section_name: list})
382361

383362
# Add sets from couplings and boundary conditions to a temp container.
384363
mesh.unlink_nodes()

tests/test_four_c_simulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ def test_four_c_simulation_dirichlet_boundary_to_neumann_boundary_with_all_value
920920
"VAL": [
921921
0,
922922
0,
923-
float(0.25 * np.sin(node.coordinates[0] * np.pi)),
923+
0.25 * np.sin(node.coordinates[0] * np.pi),
924924
0,
925925
0,
926926
0,

0 commit comments

Comments
 (0)