Fem: Add support for 2D geometries to SectionPrint

This commit is contained in:
marioalexis
2025-11-04 18:43:09 -03:00
committed by Max Wilfinger
parent c8b757bd3c
commit 009acd186b
4 changed files with 16 additions and 48 deletions

View File

@@ -423,51 +423,11 @@ class MeshSetsGetter:
femobj["TieMasterFaces"] = result[-1:]
def get_constraints_sectionprint_faces(self):
if not self.member.cons_sectionprint:
return
# TODO: use meshtools to get the surfaces
# see constraint contact or constraint tie
for femobj in self.member.cons_sectionprint:
# femobj --> dict, FreeCAD document object is femobj["Object"]
sectionprint_obj = femobj["Object"]
if len(sectionprint_obj.References) > 1:
FreeCAD.Console.PrintError(
"Only one reference shape allowed for a section print "
"but {} found: {}\n".format(
len(sectionprint_obj.References), sectionprint_obj.References
)
)
for o, elem_tup in sectionprint_obj.References:
for elem in elem_tup:
# there should only be one reference for each section print object
# in the gui this is checked
ref_shape = o.Shape.getElement(elem)
if ref_shape.ShapeType == "Face":
v = self.mesh_object.FemMesh.getccxVolumesByFace(ref_shape)
if len(v) > 0:
femobj["SectionPrintFaces"] = v
# volume elements found
FreeCAD.Console.PrintLog(
"{}, surface {}, {} touching volume elements found\n".format(
sectionprint_obj.Label, sectionprint_obj.Name, len(v)
)
)
else:
# no volume elements found, shell elements not allowed
FreeCAD.Console.PrintError(
"{}, surface {}, Error: "
"No volume elements found!\n".format(
sectionprint_obj.Label, sectionprint_obj.Name
)
)
else:
# in Gui only Faces can be added
FreeCAD.Console.PrintError(
"Wrong reference shape type for {} "
"Only Faces are allowed, but a {} was found.\n".format(
sectionprint_obj.Name, ref_shape.ShapeType
)
)
obj = femobj["Object"]
result = self._get_ccx_elements(obj)
femobj["SectionPrintFaces"] = result
def get_constraints_heatflux_faces(self):
for femobj in self.member.cons_heatflux:

View File

@@ -57,7 +57,7 @@ class ConstraintSectionPrint(base_fempythonobject.BaseFemPythonObject):
name="Variable",
group="Constraint Section Print",
doc="Set facial variable",
value=["Section Force", "Heat Flux", "Drag Stress"],
value=["Section Force", "Heat Flux", "Drag Stress", "Electric Flux"],
)
)

View File

@@ -56,8 +56,14 @@ def get_after_write_constraint():
def write_meshdata_constraint(f, femobj, sectionprint_obj, ccxwriter):
f.write(f"*SURFACE, NAME=SECTIONFACE{sectionprint_obj.Name}\n")
for i in femobj["SectionPrintFaces"]:
f.write(f"{i[0]},S{i[1]}\n")
for refs, surf, is_sub_el in femobj["SectionPrintFaces"]:
if is_sub_el:
for elem, fno in surf:
f.write(f"{elem},S{fno}\n")
else:
for elem in surf:
f.write(f"{elem},S2\n")
def write_constraint(f, femobj, sectionprint_obj, ccxwriter):
@@ -71,6 +77,8 @@ def write_constraint(f, femobj, sectionprint_obj, ccxwriter):
key = "FLUX"
elif variable == "Drag Stress":
key = "DRAG"
elif variable == "Electric Flux":
key = "FLUX"
f.write(
"*SECTION PRINT, SURFACE=SECTIONFACE{}, NAME=SECTIONPRINT{}\n".format(

View File

@@ -63,7 +63,7 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
# geometry selection widget
self.selectionWidget = selection_widgets.GeometryElementsSelection(
obj.References, ["Face"], False, False
obj.References, ["Edge", "Face"], False, False
)
# form made from param and selection widget