[FEM] add initial pressure constraint (#7364)

* [FEM] add initial pressure constraint

- this is needed for fluids
This commit is contained in:
Uwe
2022-08-14 20:00:36 +02:00
committed by GitHub
parent 32d7663e46
commit 27f50ad131
13 changed files with 512 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -22,6 +22,7 @@
<file>icons/FEM_ConstraintGear.svg</file>
<file>icons/FEM_ConstraintHeatflux.svg</file>
<file>icons/FEM_ConstraintInitialFlowVelocity.svg</file>
<file>icons/FEM_ConstraintInitialPressure.svg</file>
<file>icons/FEM_ConstraintInitialTemperature.svg</file>
<file>icons/FEM_ConstraintPlaneRotation.svg</file>
<file>icons/FEM_ConstraintPressure.svg</file>
@@ -161,6 +162,7 @@
<file>ui/ElementRotation1D.ui</file>
<file>ui/FlowVelocity.ui</file>
<file>ui/InitialFlowVelocity.ui</file>
<file>ui/InitialPressure.ui</file>
<file>ui/Material.ui</file>
<file>ui/MaterialReinforcement.ui</file>
<file>ui/MeshBoundaryLayer.ui</file>

View File

@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg version="1.1" id="svg3052" height="64px" width="64px" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
<title id="title930">FEM_ConstraintInitialFlowVelocity</title>
<defs id="defs3054">
<linearGradient id="linearGradient1098">
<stop style="stop-color:#729fcf;stop-opacity:1" offset="0" id="stop1094" />
<stop style="stop-color:#204a87;stop-opacity:1" offset="1" id="stop1096" />
</linearGradient>
<linearGradient id="linearGradient4032">
<stop id="stop4034" offset="0" style="stop-color:#71b2f8;stop-opacity:1" />
<stop id="stop4036" offset="1" style="stop-color:#002795;stop-opacity:1" />
</linearGradient>
<radialGradient gradientTransform="matrix(1.6244669,-0.05136783,0.04345521,0.9993132,-102.99033,7.7040438)" r="19.467436" fy="81.869568" fx="148.88333" cy="81.869568" cx="148.88333" gradientUnits="userSpaceOnUse" id="radialGradient3705" xlink:href="#linearGradient3377" />
<linearGradient id="linearGradient3377">
<stop style="stop-color:#4bff54;stop-opacity:1" offset="0" id="stop3379" />
<stop style="stop-color:#00b800;stop-opacity:1" offset="1" id="stop3381" />
</linearGradient>
<radialGradient gradientTransform="matrix(0.87904684,0.2250379,-0.41709097,2.0016728,56.73751,-127.99883)" r="19.467436" fy="97.369568" fx="135.38333" cy="97.369568" cx="135.38333" gradientUnits="userSpaceOnUse" id="radialGradient3703" xlink:href="#linearGradient3206" />
<linearGradient id="linearGradient3199">
<stop style="stop-color:#faff2b;stop-opacity:1" offset="0" id="stop3201" />
<stop style="stop-color:#ffaa00;stop-opacity:1" offset="1" id="stop3203" />
</linearGradient>
<radialGradient gradientUnits="userSpaceOnUse" r="19.467436" fy="28.869568" fx="45.883327" cy="28.869568" cx="45.883327" id="radialGradient3692" xlink:href="#linearGradient3377" />
<linearGradient id="linearGradient3206">
<stop style="stop-color:#faff2b;stop-opacity:1" offset="0" id="stop3208" />
<stop style="stop-color:#ffaa00;stop-opacity:1" offset="1" id="stop3210" />
</linearGradient>
<radialGradient r="19.467436" fy="81.869568" fx="148.88333" cy="81.869568" cx="148.88333" gradientTransform="matrix(1.260164,-0.05136783,0.03370995,0.9993132,-43.139781,7.2044077)" gradientUnits="userSpaceOnUse" id="radialGradient4030" xlink:href="#linearGradient4032" />
<linearGradient id="linearGradient3836-0-6-92-4-6">
<stop id="stop3838-2-7-06-8-7" offset="0" style="stop-color:#a40000;stop-opacity:1" />
<stop id="stop3840-5-5-8-7-5" offset="1" style="stop-color:#ef2929;stop-opacity:1" />
</linearGradient>
<linearGradient id="linearGradient3836-0-6-92-4-6-5">
<stop id="stop3838-2-7-06-8-7-3" offset="0" style="stop-color:#a40000;stop-opacity:1" />
<stop id="stop3840-5-5-8-7-5-5" offset="1" style="stop-color:#ef2929;stop-opacity:1" />
</linearGradient>
<linearGradient xlink:href="#linearGradient1098" id="linearGradient1100" x1="148.3927" y1="8.0433396" x2="196.49864" y2="8.0433396" gradientUnits="userSpaceOnUse" gradientTransform="translate(-139.99194,4.6349894)" />
<linearGradient xlink:href="#linearGradient1098" id="linearGradient1160" gradientUnits="userSpaceOnUse" gradientTransform="matrix(0.73296217,0,0,0.67761034,-103.70058,3.8690963)" x1="148.3927" y1="8.0433396" x2="196.49864" y2="8.0433396" />
<linearGradient xlink:href="#linearGradient1098" id="linearGradient1197" gradientUnits="userSpaceOnUse" gradientTransform="matrix(0.73296217,0,0,0.67761034,-103.79758,18.91964)" x1="148.3927" y1="8.0433396" x2="196.49864" y2="8.0433396" />
<linearGradient xlink:href="#linearGradient1098" id="linearGradient1234" gradientUnits="userSpaceOnUse" gradientTransform="matrix(0.73296217,0,0,0.67761034,-103.82784,33.804395)" x1="148.3927" y1="8.0433396" x2="196.49864" y2="8.0433396" />
<linearGradient xlink:href="#linearGradient4079" id="linearGradient4175" gradientUnits="userSpaceOnUse" gradientTransform="translate(-108)" spreadMethod="reflect" x1="96.245674" y1="55.079586" x2="111.24567" y2="56.079586" />
<linearGradient id="linearGradient4079">
<stop style="stop-color:#fce94f;stop-opacity:1" offset="0" id="stop4081" />
<stop style="stop-color:#c4a000;stop-opacity:1" offset="1" id="stop4083" />
</linearGradient>
<linearGradient xlink:href="#linearGradient3094-7" id="linearGradient3092-0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-45,34.253048,123.74443)" x1="51.284271" y1="24.928932" x2="39.543564" y2="31.991449" />
<linearGradient id="linearGradient3094-7">
<stop id="stop3096-6" offset="0" style="stop-color:#204a87;stop-opacity:1" />
<stop id="stop3098-0" offset="1" style="stop-color:#729fcf;stop-opacity:1" />
</linearGradient>
</defs>
<metadata id="metadata3057">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>FEM_ConstraintInitialFlowVelocity</dc:title>
<dc:creator>
<cc:Agent>
<dc:title>[bitacovir]</dc:title>
</cc:Agent>
</dc:creator>
<dc:title>PartDesign_MoveTip</dc:title>
<dc:date>12-02-2021</dc:date>
<dc:relation>http://www.freecadweb.org/wiki/index.php?title=Artwork</dc:relation>
<dc:publisher>
<cc:Agent>
<dc:title>FreeCAD</dc:title>
</cc:Agent>
</dc:publisher>
<dc:identifier />
<dc:rights>
<cc:Agent>
<dc:title>FreeCAD LGPL2+</dc:title>
</cc:Agent>
</dc:rights>
<cc:license>https://www.gnu.org/copyleft/lesser.html</cc:license>
<dc:contributor>
<cc:Agent>
<dc:title />
</cc:Agent>
</dc:contributor>
<dc:subject>
<rdf:Bag />
</dc:subject>
</cc:Work>
</rdf:RDF>
</metadata>
<g id="layer1">
<path style="fill:none;stroke:#0b1521;stroke-width:6.7853;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="M 45.631517,58.646328 H 58.594551" id="path1262" />
<path style="fill:none;stroke:#0b1521;stroke-width:6.7853;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="m 52.497183,58.696306 c 0.04997,-0.199914 0,-16.043075 0,-16.043075" id="path1264" />
<path style="fill:none;stroke:#0b1521;stroke-width:6.7853;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="m 48.049103,43.202994 h 4.498058" id="path1266" />
<path id="path1262-3" d="M 45.631517,58.646328 H 58.594551" style="fill:none;stroke:#729fcf;stroke-width:3.39265;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path id="path1264-4" d="m 52.497183,58.696306 c 0.04997,-0.199914 0,-16.043075 0,-16.043075" style="fill:none;stroke:#729fcf;stroke-width:3.39265;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path id="path1266-2" d="m 48.049103,43.202994 h 4.498058" style="fill:none;stroke:#729fcf;stroke-width:3.39265;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<circle style="fill:#729fcf;fill-rule:evenodd;stroke:#0b1521;stroke-width:1.69632;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;paint-order:markers fill stroke" id="path1289" cx="51.480988" cy="31.725163" r="3.8874092" />
</g>
<g id="g4161" transform="matrix(1.1135738,0,0,1.111665,31.532939,-25.672159)" style="stroke-width:0.89878">
<path id="path4022" d="M -19.754325,38.079585 V 60.079585 C -19.754325,68.079585 6.245675,68.079585 6.245675,60.079585 V 38.079585 Z" style="fill:#fce94f;stroke:#204a87;stroke-width:1.79756;stroke-linecap:butt;stroke-linejoin:round;stroke-opacity:1" />
<path id="path4022-6" d="M -17.75433,43.779585 V 59.779585 C -17.754325,65.079585 4.24568,65.079585 4.24567,59.779585 V 43.779585 C 4.24568,47.079585 -17.754325,47.079585 -17.75433,43.779585 Z" style="fill:url(#linearGradient4175);fill-opacity:1;stroke:#fce94f;stroke-width:1.79756;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path id="path4044" d="M -15.754325,42.079585 V 64.079585" style="fill:#204a87;fill-opacity:1;stroke:#204a87;stroke-width:1.79756;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path id="path4044-2" d="M -7.75432,44.079585 V 66.079585" style="fill:#204a87;fill-opacity:1;stroke:#204a87;stroke-width:1.79756;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path id="path4044-9" d="M 3.24568,42.079585 V 64.079585" style="fill:none;stroke:#204a87;stroke-width:1.79756;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path transform="translate(-109.75434,22.079585)" d="M 116,16 C 116,19.313708 110.1797,22 103,22 C 95.820298,22 90,19.313708 90,16 C 90,12.686292 95.820298,10 103,10 C 110.1797,10 116,12.686292 116,16 Z" id="path3164" style="fill:#fce94f;fill-opacity:1;stroke:#204a87;stroke-width:1.79756;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none" />
<path transform="matrix(0.84615382,0,0,0.66666668,-93.90817,27.412918)" d="M 116,16 C 116,19.313708 110.1797,22 103,22 C 95.820298,22 90,19.313708 90,16 C 90,12.686292 95.820298,10 103,10 C 110.1797,10 116,12.686292 116,16 Z" id="path3164-3" style="fill:#fce94f;fill-opacity:1;stroke:#729fcf;stroke-width:2.39334;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none" />
<path id="path3952" d="M -5.754325,32.079585 L -15.754325,42.079585" style="fill:none;stroke:#204a87;stroke-width:1.79756;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path id="path3952-6" d="M 3.24568,34.079585 L -7.75432,44.079585" style="fill:none;stroke:#204a87;stroke-width:1.79756;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path id="path3952-7" d="M 5.91004,38.453288 L -15.754325,34.079585" style="fill:none;stroke:#204a87;stroke-width:1.79756;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
<path id="path3952-7-3" d="M 2.91004,41.453288 L -18.754325,37.079585" style="fill:none;stroke:#204a87;stroke-width:1.79756;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
<path id="path4042" d="M -19.754325,50.079585 C -19.754325,56.079585 6.24568,56.079585 6.24568,50.079585" style="fill:none;stroke:#204a87;stroke-width:1.79756;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<height>40</height>
</rect>
</property>
<property name="windowTitle">
<string>Constraint Properties</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="pressureLbl">
<property name="text">
<string>Pressure:</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>130</width>
<height>19</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Gui::QuantitySpinBox" name="pressureQSB">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>20</height>
</size>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="keyboardTracking">
<bool>true</bool>
</property>
<property name="unit" stdset="0">
<string notr="true">kPa</string>
</property>
<property name="minimum">
<double>-1000000000000000000000.000000000000000</double>
</property>
<property name="maximum">
<double>1000000000000000000000.000000000000000</double>
</property>
<property name="singleStep">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>100.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/QuantitySpinBox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -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";

View File

@@ -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"

View File

@@ -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()

View File

@@ -0,0 +1,56 @@
# ***************************************************************************
# * Copyright (c) 2022 Uwe Stöhr <uwestoehr@lyx.org> *
# * *
# * 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

View File

@@ -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):

View File

@@ -0,0 +1,118 @@
# ***************************************************************************
# * Copyright (c) 2022 Uwe Stöhr <uwestoehr@lyx.org> *
# * *
# * 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

View File

@@ -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))

View File

@@ -0,0 +1,44 @@
# ***************************************************************************
# * Copyright (c) 2022 Uwe Stöhr <uwestoehr@lyx.org> *
# * *
# * 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
)