diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index 0649bfa59b..8c5e0fba52 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -172,6 +172,7 @@ SET(FemObjects_SRCS femobjects/constraint_electrostaticpotential.py femobjects/constraint_flowvelocity.py femobjects/constraint_initialflowvelocity.py + femobjects/constraint_initialpressure.py femobjects/constraint_sectionprint.py femobjects/constraint_selfweight.py femobjects/constraint_tie.py @@ -566,6 +567,7 @@ SET(FemGuiTaskPanels_SRCS femtaskpanels/task_constraint_electrostaticpotential.py femtaskpanels/task_constraint_flowvelocity.py femtaskpanels/task_constraint_initialflowvelocity.py + femtaskpanels/task_constraint_initialpressure.py femtaskpanels/task_constraint_sectionprint.py femtaskpanels/task_constraint_tie.py femtaskpanels/task_element_fluid1D.py @@ -603,6 +605,7 @@ SET(FemGuiViewProvider_SRCS femviewprovider/view_constraint_electrostaticpotential.py femviewprovider/view_constraint_flowvelocity.py femviewprovider/view_constraint_initialflowvelocity.py + femviewprovider/view_constraint_initialpressure.py femviewprovider/view_constraint_sectionprint.py femviewprovider/view_constraint_selfweight.py femviewprovider/view_constraint_tie.py diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index 9120c2fd65..68678bd9ee 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -394,6 +394,7 @@ SET(FemGuiPythonUI_SRCS Resources/ui/ElementRotation1D.ui Resources/ui/FlowVelocity.ui Resources/ui/InitialFlowVelocity.ui + Resources/ui/InitialPressure.ui Resources/ui/Material.ui Resources/ui/MaterialReinforcement.ui Resources/ui/MeshBoundaryLayer.ui diff --git a/src/Mod/Fem/Gui/Resources/Fem.qrc b/src/Mod/Fem/Gui/Resources/Fem.qrc index c09d211710..3a6a104b47 100755 --- a/src/Mod/Fem/Gui/Resources/Fem.qrc +++ b/src/Mod/Fem/Gui/Resources/Fem.qrc @@ -22,6 +22,7 @@ icons/FEM_ConstraintGear.svg icons/FEM_ConstraintHeatflux.svg icons/FEM_ConstraintInitialFlowVelocity.svg + icons/FEM_ConstraintInitialPressure.svg icons/FEM_ConstraintInitialTemperature.svg icons/FEM_ConstraintPlaneRotation.svg icons/FEM_ConstraintPressure.svg @@ -161,6 +162,7 @@ ui/ElementRotation1D.ui ui/FlowVelocity.ui ui/InitialFlowVelocity.ui + ui/InitialPressure.ui ui/Material.ui ui/MaterialReinforcement.ui ui/MeshBoundaryLayer.ui diff --git a/src/Mod/Fem/Gui/Resources/icons/FEM_ConstraintInitialPressure.svg b/src/Mod/Fem/Gui/Resources/icons/FEM_ConstraintInitialPressure.svg new file mode 100644 index 0000000000..0387e04512 --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/icons/FEM_ConstraintInitialPressure.svg @@ -0,0 +1,112 @@ + + + FEM_ConstraintInitialFlowVelocity + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + FEM_ConstraintInitialFlowVelocity + + + [bitacovir] + + + PartDesign_MoveTip + 12-02-2021 + http://www.freecadweb.org/wiki/index.php?title=Artwork + + + FreeCAD + + + + + + FreeCAD LGPL2+ + + + https://www.gnu.org/copyleft/lesser.html + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/Fem/Gui/Resources/ui/InitialPressure.ui b/src/Mod/Fem/Gui/Resources/ui/InitialPressure.ui new file mode 100644 index 0000000000..8bf1c8fee2 --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/ui/InitialPressure.ui @@ -0,0 +1,82 @@ + + + Form + + + + 0 + 0 + 350 + 40 + + + + Constraint Properties + + + + + + Pressure: + + + + + + + Qt::Horizontal + + + + 130 + 19 + + + + + + + + true + + + + 100 + 20 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + kPa + + + -1000000000000000000000.000000000000000 + + + 1000000000000000000000.000000000000000 + + + 50.000000000000000 + + + 100.000000000000000 + + + + + + + + Gui::QuantitySpinBox + QWidget +
Gui/QuantitySpinBox.h
+
+
+ + +
diff --git a/src/Mod/Fem/Gui/Workbench.cpp b/src/Mod/Fem/Gui/Workbench.cpp index 4d0428f34a..41690cedcb 100755 --- a/src/Mod/Fem/Gui/Workbench.cpp +++ b/src/Mod/Fem/Gui/Workbench.cpp @@ -144,6 +144,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const << "Separator" << "FEM_ConstraintForce" << "FEM_ConstraintPressure" + << "FEM_ConstraintInitialPressure" << "FEM_ConstraintCentrif" << "FEM_ConstraintSelfWeight"; @@ -272,6 +273,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const << "Separator" << "FEM_ConstraintForce" << "FEM_ConstraintPressure" + << "FEM_ConstraintInitialPressure" << "FEM_ConstraintCentrif" << "FEM_ConstraintSelfWeight"; diff --git a/src/Mod/Fem/ObjectsFem.py b/src/Mod/Fem/ObjectsFem.py index 5d9a8b51cd..fb9976e9e9 100644 --- a/src/Mod/Fem/ObjectsFem.py +++ b/src/Mod/Fem/ObjectsFem.py @@ -228,6 +228,21 @@ def makeConstraintInitialFlowVelocity( return obj +def makeConstraintInitialPressure( + doc, + name="ConstraintInitialPressure" +): + """makeConstraintInitialPressure(document, [name]): + makes a Fem ConstraintInitialPressure object""" + obj = doc.addObject("Fem::ConstraintPython", name) + from femobjects import constraint_initialpressure + constraint_initialpressure.ConstraintInitialPressure(obj) + if FreeCAD.GuiUp: + from femviewprovider import view_constraint_initialpressure + view_constraint_initialpressure.VPConstraintInitialPressure(obj.ViewObject) + return obj + + def makeConstraintInitialTemperature( doc, name="ConstraintInitialTemperature" diff --git a/src/Mod/Fem/femcommands/commands.py b/src/Mod/Fem/femcommands/commands.py index 581b81c02f..35f196e47f 100644 --- a/src/Mod/Fem/femcommands/commands.py +++ b/src/Mod/Fem/femcommands/commands.py @@ -258,6 +258,23 @@ class _ConstraintInitialFlowVelocity(CommandManager): self.do_activated = "add_obj_on_gui_set_edit" +class _ConstraintInitialPressure(CommandManager): + "The FEM_ConstraintInitialPressure command definition" + + def __init__(self): + super(_ConstraintInitialPressure, self).__init__() + self.menutext = Qt.QT_TRANSLATE_NOOP( + "FEM_ConstraintInitialPressure", + "Constraint initial pressure" + ) + self.tooltip = Qt.QT_TRANSLATE_NOOP( + "FEM_ConstraintInitialPressure", + "Creates a FEM constraint initial pressure" + ) + self.is_active = "with_analysis" + self.do_activated = "add_obj_on_gui_set_edit" + + class _ConstraintSectionPrint(CommandManager): "The FEM_ConstraintSectionPrint command definition" @@ -1104,6 +1121,10 @@ FreeCADGui.addCommand( "FEM_ConstraintInitialFlowVelocity", _ConstraintInitialFlowVelocity() ) +FreeCADGui.addCommand( + "FEM_ConstraintInitialPressure", + _ConstraintInitialPressure() +) FreeCADGui.addCommand( "FEM_ConstraintSectionPrint", _ConstraintSectionPrint() diff --git a/src/Mod/Fem/femobjects/constraint_initialpressure.py b/src/Mod/Fem/femobjects/constraint_initialpressure.py new file mode 100644 index 0000000000..bf31e2319f --- /dev/null +++ b/src/Mod/Fem/femobjects/constraint_initialpressure.py @@ -0,0 +1,56 @@ +# *************************************************************************** +# * Copyright (c) 2022 Uwe Stöhr * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +__title__ = "FreeCAD FEM constraint initial pressure document object" +__author__ = "Uwe Stöhr" +__url__ = "https://www.freecadweb.org" + +## @package constraint_initialpressure +# \ingroup FEM +# \brief constraint initial pressure object + +from . import base_fempythonobject + + +class ConstraintInitialPressure(base_fempythonobject.BaseFemPythonObject): + + Type = "Fem::ConstraintInitialPressure" + + def __init__(self, obj): + super(ConstraintInitialPressure, self).__init__(obj) + self.add_properties(obj) + + def onDocumentRestored(self, obj): + self.add_properties(obj) + + def add_properties(self, obj): + if not hasattr(obj, "Pressure"): + obj.addProperty( + "App::PropertyPressure", + "Pressure", + "Parameter", + "Initial Pressure" + ) + # App::PropertyPressure is in kPa and we initialize 1 bar + obj.Pressure = 100 + diff --git a/src/Mod/Fem/femsolver/elmer/writer.py b/src/Mod/Fem/femsolver/elmer/writer.py index cac80c19f2..e8ebfe7bb0 100644 --- a/src/Mod/Fem/femsolver/elmer/writer.py +++ b/src/Mod/Fem/femsolver/elmer/writer.py @@ -1302,6 +1302,7 @@ class Writer(object): if activeIn: self._handleFlowConstants() self._handleFlowBndConditions() + self._handleFlowInitialPressure(activeIn) self._handleFlowInitialVelocity(activeIn) # self._handleFlowInitial(activeIn) # self._handleFlowBodyForces(activeIn) @@ -1436,6 +1437,32 @@ class Writer(object): name, "Compressibility Model", m["CompressibilityModel"]) + def _outputInitialPressure(self, obj, name): + # initial pressure only makes sense for fluid material + if self._isBodyMaterialFluid(name): + pressure = float(obj.Pressure.getValueAs("Pa")) + self._initial(name, "Pressure", pressure) + + def _handleFlowInitialPressure(self, bodies): + initialPressures = self._getMember("Fem::ConstraintInitialPressure") + for obj in initialPressures: + if obj.References: + for name in obj.References[0][1]: + self._outputInitialPressure(obj, name) + self._handled(obj) + else: + # if there is only one initial velocity without a reference + # add it to all fluid bodies + if len(initialPressures) == 1: + for name in bodies: + self._outputInitialPressure(obj, name) + else: + raise WriteError( + "Several initial pressures found without reference to a body.\n" + "Please set a body for each initial pressure." + ) + self._handled(obj) + def _outputInitialVelocity(self, obj, name): # flow only makes sense for fluid material if self._isBodyMaterialFluid(name): diff --git a/src/Mod/Fem/femtaskpanels/task_constraint_initialpressure.py b/src/Mod/Fem/femtaskpanels/task_constraint_initialpressure.py new file mode 100644 index 0000000000..8b40115e82 --- /dev/null +++ b/src/Mod/Fem/femtaskpanels/task_constraint_initialpressure.py @@ -0,0 +1,118 @@ +# *************************************************************************** +# * Copyright (c) 2022 Uwe Stöhr * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +__title__ = "FreeCAD FEM constraint initial pressure task panel for the document object" +__author__ = "Uwe Stöhr" +__url__ = "https://www.freecadweb.org" + +## @package task_constraint_initialpressure +# \ingroup FEM +# \brief task panel for constraint initial pressure object + +import FreeCAD +import FreeCADGui +from femguiutils import selection_widgets + +from femtools import femutils +from femtools import membertools + + +class _TaskPanel(object): + + def __init__(self, obj): + self._obj = obj + + self._paramWidget = FreeCADGui.PySideUic.loadUi( + FreeCAD.getHomePath() + "Mod/Fem/Resources/ui/InitialPressure.ui") + self._initParamWidget() + + # 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 + if analysis is not None: + self._mesh = membertools.get_single_member(analysis, "Fem::FemMeshObject") + if self._mesh is not None: + self._part = femutils.get_part_to_mesh(self._mesh) + self._partVisible = None + self._meshVisible = None + + def open(self): + if self._mesh is not None and self._part is not None: + self._meshVisible = self._mesh.ViewObject.isVisible() + self._partVisible = self._part.ViewObject.isVisible() + self._mesh.ViewObject.hide() + self._part.ViewObject.show() + + def reject(self): + self._restoreVisibility() + FreeCADGui.ActiveDocument.resetEdit() + 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() + self._restoreVisibility() + return True + + def _restoreVisibility(self): + if self._mesh is not None and self._part is not None: + if self._meshVisible: + self._mesh.ViewObject.show() + else: + self._mesh.ViewObject.hide() + if self._partVisible: + self._part.ViewObject.show() + else: + self._part.ViewObject.hide() + + def _initParamWidget(self): + self._paramWidget.pressureQSB.setProperty( + 'value', self._obj.Pressure) + + def _applyWidgetChanges(self): + pressure = None + try: + pressure = self._paramWidget.pressureQSB.property('value') + except ValueError: + FreeCAD.Console.PrintMessage( + "Wrong input. Not recognised input: '{}' " + "Pressure has not been set.\n" + .format(self._paramWidget.pressureQSB.text()) + ) + if pressure is not None: + self._obj.Pressure = pressure diff --git a/src/Mod/Fem/femtest/app/test_object.py b/src/Mod/Fem/femtest/app/test_object.py index 1ec683da3e..db1ff559c9 100644 --- a/src/Mod/Fem/femtest/app/test_object.py +++ b/src/Mod/Fem/femtest/app/test_object.py @@ -213,6 +213,10 @@ class TestObjectType(unittest.TestCase): "Fem::ConstraintInitialFlowVelocity", type_of_obj(ObjectsFem.makeConstraintInitialFlowVelocity(doc)) ) + self.assertEqual( + "Fem::ConstraintInitialPressure", + type_of_obj(ObjectsFem.makeConstraintInitialPressure(doc)) + ) self.assertEqual( "Fem::ConstraintInitialTemperature", type_of_obj(ObjectsFem.makeConstraintInitialTemperature(doc)) @@ -434,6 +438,10 @@ class TestObjectType(unittest.TestCase): ObjectsFem.makeConstraintInitialFlowVelocity(doc), "Fem::ConstraintInitialFlowVelocity" )) + self.assertTrue(is_of_type( + ObjectsFem.makeConstraintInitialPressure(doc), + "Fem::ConstraintInitialPressure" + )) self.assertTrue(is_of_type( ObjectsFem.makeConstraintInitialTemperature(doc), "Fem::ConstraintInitialTemperature" @@ -820,6 +828,21 @@ class TestObjectType(unittest.TestCase): "Fem::ConstraintInitialFlowVelocity" )) + # ConstraintInitialPressure + constraint_initial_pressure = ObjectsFem.makeConstraintInitialPressure(doc) + self.assertTrue(is_derived_from( + constraint_initial_pressure, + "App::DocumentObject" + )) + self.assertTrue(is_derived_from( + constraint_initial_pressure, + "Fem::ConstraintPython" + )) + self.assertTrue(is_derived_from( + constraint_initial_pressure, + "Fem::ConstraintInitialPressure" + )) + # ConstraintInitialTemperature constraint_initial_temperature = ObjectsFem.makeConstraintInitialTemperature(doc) self.assertTrue(is_derived_from( @@ -1463,6 +1486,11 @@ class TestObjectType(unittest.TestCase): doc ).isDerivedFrom("Fem::ConstraintPython") ) + self.assertTrue( + ObjectsFem.makeConstraintInitialPressure( + doc + ).isDerivedFrom("Fem::ConstraintPython") + ) self.assertTrue( ObjectsFem.makeConstraintInitialTemperature( doc @@ -1678,6 +1706,7 @@ def create_all_fem_objects_doc( analysis.addObject(ObjectsFem.makeConstraintGear(doc)) analysis.addObject(ObjectsFem.makeConstraintHeatflux(doc)) analysis.addObject(ObjectsFem.makeConstraintInitialFlowVelocity(doc)) + analysis.addObject(ObjectsFem.makeConstraintInitialPressure(doc)) analysis.addObject(ObjectsFem.makeConstraintInitialTemperature(doc)) analysis.addObject(ObjectsFem.makeConstraintPlaneRotation(doc)) analysis.addObject(ObjectsFem.makeConstraintPressure(doc)) diff --git a/src/Mod/Fem/femviewprovider/view_constraint_initialpressure.py b/src/Mod/Fem/femviewprovider/view_constraint_initialpressure.py new file mode 100644 index 0000000000..2e29c930d7 --- /dev/null +++ b/src/Mod/Fem/femviewprovider/view_constraint_initialpressure.py @@ -0,0 +1,44 @@ +# *************************************************************************** +# * Copyright (c) 2022 Uwe Stöhr * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +__title__ = "FreeCAD FEM constraint initial pressure ViewProvider for the document object" +__author__ = "Uwe Stöhr" +__url__ = "https://www.freecadweb.org" + +## @package view_constraint_initialpressure +# \ingroup FEM +# \brief view provider for constraint initial pressure object + +from femtaskpanels import task_constraint_initialpressure +from . import view_base_femconstraint + + +class VPConstraintInitialPressure(view_base_femconstraint.VPBaseFemConstraint): + + def setEdit(self, vobj, mode=0): + view_base_femconstraint.VPBaseFemConstraint.setEdit( + self, + vobj, + mode, + task_constraint_initialpressure._TaskPanel + )