diff --git a/src/Mod/Fem/femsolver/elmer/writer.py b/src/Mod/Fem/femsolver/elmer/writer.py index a6c276cbc3..a046728736 100644 --- a/src/Mod/Fem/femsolver/elmer/writer.py +++ b/src/Mod/Fem/femsolver/elmer/writer.py @@ -1,6 +1,7 @@ # *************************************************************************** # * Copyright (c) 2017 Markus Hovorka * # * Copyright (c) 2020 Bernd Hahnebach * +# * Copyright (c) 2022 Uwe Stöhr * # * * # * This file is part of the FreeCAD CAx development system. * # * * @@ -23,7 +24,7 @@ # *************************************************************************** __title__ = "FreeCAD FEM solver Elmer writer" -__author__ = "Markus Hovorka" +__author__ = "Markus Hovorka, Uwe Stöhr" __url__ = "https://www.freecadweb.org" ## \addtogroup FEM @@ -1442,19 +1443,37 @@ class Writer(object): name, "Compressibility Model", m["CompressibilityModel"]) + def _outputInitialVelocity(self, obj, name): + # flow only makes sense for fluid material + if self._isBodyMaterialFluid(name): + if obj.VelocityXEnabled: + velocity = self._getFromUi(obj.VelocityX, "m/s", "L/T") + self._initial(name, "Velocity 1", velocity) + if obj.VelocityYEnabled: + velocity = self._getFromUi(obj.VelocityY, "m/s", "L/T") + self._initial(name, "Velocity 2", velocity) + if obj.VelocityZEnabled: + velocity = self._getFromUi(obj.VelocityZ, "m/s", "L/T") + self._initial(name, "Velocity 3", velocity) + def _handleFlowInitialVelocity(self, bodies): - obj = self._getSingleMember("Fem::ConstraintInitialFlowVelocity") - if obj is not None: - for name in bodies: - if obj.VelocityXEnabled: - velocity = self._getFromUi(obj.VelocityX, "m/s", "L/T") - self._initial(name, "Velocity 1", velocity) - if obj.VelocityYEnabled: - velocity = self._getFromUi(obj.VelocityY, "m/s", "L/T") - self._initial(name, "Velocity 2", velocity) - if obj.VelocityZEnabled: - velocity = self._getFromUi(obj.VelocityZ, "m/s", "L/T") - self._initial(name, "Velocity 3", velocity) + initialVelocities = self._getMember("Fem::ConstraintInitialFlowVelocity") + for obj in initialVelocities: + if obj.References: + for name in obj.References[0][1]: + self._outputInitialVelocity(obj, name) + self._handled(obj) + else: + # if there is only one initial velocity without a reference + # add it to all fluid bodies + if len(initialVelocities) == 1: + for name in bodies: + self._outputInitialVelocity(obj, name) + else: + raise WriteError( + "Several initial velocities found without reference to a body.\n" + "Please set a body for each initial velocity." + ) self._handled(obj) def _handleFlowBndConditions(self): diff --git a/src/Mod/Fem/femtaskpanels/task_constraint_initialflowvelocity.py b/src/Mod/Fem/femtaskpanels/task_constraint_initialflowvelocity.py index d30b0254eb..91fafc536a 100644 --- a/src/Mod/Fem/femtaskpanels/task_constraint_initialflowvelocity.py +++ b/src/Mod/Fem/femtaskpanels/task_constraint_initialflowvelocity.py @@ -34,6 +34,7 @@ import FreeCAD import FreeCADGui from FreeCAD import Units +from femguiutils import selection_widgets from femtools import femutils from femtools import membertools @@ -42,10 +43,23 @@ class _TaskPanel(object): def __init__(self, obj): self._obj = obj + self._paramWidget = FreeCADGui.PySideUic.loadUi( FreeCAD.getHomePath() + "Mod/Fem/Resources/ui/InitialFlowVelocity.ui") self._initParamWidget() - self.form = [self._paramWidget] + + # geometry selection widget + # start with Solid in list! + self._selectionWidget = selection_widgets.GeometryElementsSelection( + obj.References, + ["Solid", "Face"], + True, + False + ) + + # form made from param and selection widget + self.form = [self._paramWidget, self._selectionWidget] + analysis = obj.getParentGroup() self._mesh = None self._part = None @@ -69,6 +83,8 @@ class _TaskPanel(object): return True def accept(self): + if self._obj.References != self._selectionWidget.references: + self._obj.References = self._selectionWidget.references self._applyWidgetChanges() self._obj.Document.recompute() FreeCADGui.ActiveDocument.resetEdit()