From 5c0660dbdd748b881d3c6f87b62502e6936e8037 Mon Sep 17 00:00:00 2001 From: kgoao Date: Tue, 28 Feb 2017 11:50:13 +0100 Subject: [PATCH] FEM: 1DFlow, object modules --- src/Mod/Fem/App/CMakeLists.txt | 4 + src/Mod/Fem/CMakeLists.txt | 6 +- src/Mod/Fem/ObjectsFem.py | 11 + src/Mod/Fem/PyGui/TaskPanelFemFluidSection.ui | 890 ++++++++++++++++++ .../Fem/PyGui/_TaskPanelFemFluidSection.py | 382 ++++++++ .../Fem/PyGui/_ViewProviderFemFluidSection.py | 85 ++ .../Fem/PyObjects/_FemConstraintSelfWeight.py | 6 + src/Mod/Fem/PyObjects/_FemFluidSection.py | 122 +++ 8 files changed, 1505 insertions(+), 1 deletion(-) create mode 100644 src/Mod/Fem/PyGui/TaskPanelFemFluidSection.ui create mode 100644 src/Mod/Fem/PyGui/_TaskPanelFemFluidSection.py create mode 100644 src/Mod/Fem/PyGui/_ViewProviderFemFluidSection.py create mode 100644 src/Mod/Fem/PyObjects/_FemFluidSection.py diff --git a/src/Mod/Fem/App/CMakeLists.txt b/src/Mod/Fem/App/CMakeLists.txt index 72a40742c794..991e10a9fbb8 100644 --- a/src/Mod/Fem/App/CMakeLists.txt +++ b/src/Mod/Fem/App/CMakeLists.txt @@ -89,6 +89,7 @@ SET(FemObjectsScripts_SRCS PyObjects/__init__.py PyObjects/_FemBeamSection.py PyObjects/_FemConstraintSelfWeight.py + PyObjects/_FemFluidSection.py PyObjects/_FemMaterialMechanicalNonlinear.py PyObjects/_FemMeshGmsh.py PyObjects/_FemMeshGroup.py @@ -124,6 +125,7 @@ SET(FemGuiScripts_SRCS PyGui/_CommandSolverCalculix.py PyGui/_CommandSolverZ88.py PyGui/_TaskPanelFemBeamSection.py + PyGui/_TaskPanelFemFluidSection.py PyGui/_TaskPanelFemMeshGmsh.py PyGui/_TaskPanelFemMeshGroup.py PyGui/_TaskPanelFemMeshRegion.py @@ -133,6 +135,7 @@ SET(FemGuiScripts_SRCS PyGui/_TaskPanelShowResult.py PyGui/_ViewProviderFemBeamSection.py PyGui/_ViewProviderFemConstraintSelfWeight.py + PyGui/_ViewProviderFemFluidSection.py PyGui/_ViewProviderFemMaterialMechanicalNonlinear.py PyGui/_ViewProviderFemMeshGmsh.py PyGui/_ViewProviderFemMeshGroup.py @@ -143,6 +146,7 @@ SET(FemGuiScripts_SRCS PyGui/_ViewProviderFemSolverZ88.py PyGui/_ViewProviderFemMaterial.py PyGui/TaskPanelFemBeamSection.ui + PyGui/TaskPanelFemFluidSection.ui PyGui/TaskPanelFemMeshGmsh.ui PyGui/TaskPanelFemMeshGroup.ui PyGui/TaskPanelFemMeshRegion.ui diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index e9a878ae8e2e..061d8cb945fa 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -47,6 +47,7 @@ INSTALL( PyObjects/__init__.py PyObjects/_FemBeamSection.py PyObjects/_FemConstraintSelfWeight.py + PyObjects/_FemFluidSection.py PyObjects/_FemMaterialMechanicalNonlinear.py PyObjects/_FemMeshGmsh.py PyObjects/_FemMeshGroup.py @@ -85,6 +86,7 @@ INSTALL( PyGui/_CommandSolverCalculix.py PyGui/_CommandSolverZ88.py PyGui/_TaskPanelFemBeamSection.py + PyGui/_TaskPanelFemFluidSection.py PyGui/_TaskPanelFemMeshGmsh.py PyGui/_TaskPanelFemMeshGroup.py PyGui/_TaskPanelFemMeshRegion.py @@ -94,6 +96,7 @@ INSTALL( PyGui/_TaskPanelShowResult.py PyGui/_ViewProviderFemBeamSection.py PyGui/_ViewProviderFemConstraintSelfWeight.py + PyGui/_ViewProviderFemFluidSection.py PyGui/_ViewProviderFemMaterialMechanicalNonlinear.py PyGui/_ViewProviderFemMeshGmsh.py PyGui/_ViewProviderFemMeshGroup.py @@ -104,12 +107,13 @@ INSTALL( PyGui/_ViewProviderFemSolverZ88.py PyGui/_ViewProviderFemMaterial.py PyGui/TaskPanelFemBeamSection.ui + PyGui/TaskPanelFemFluidSection.ui + PyGui/TaskPanelFemMaterial.ui PyGui/TaskPanelFemMeshGmsh.ui PyGui/TaskPanelFemMeshGroup.ui PyGui/TaskPanelFemMeshRegion.ui PyGui/TaskPanelFemShellThickness.ui PyGui/TaskPanelFemSolverCalculix.ui - PyGui/TaskPanelFemMaterial.ui PyGui/TaskPanelShowResult.ui DESTINATION Mod/Fem/PyGui diff --git a/src/Mod/Fem/ObjectsFem.py b/src/Mod/Fem/ObjectsFem.py index 88ca0d2610d8..4e720cf6b93f 100644 --- a/src/Mod/Fem/ObjectsFem.py +++ b/src/Mod/Fem/ObjectsFem.py @@ -83,6 +83,17 @@ def makeBeamSection(sectiontype='Rectangular', width=10.0, height=25.0, name="Be return obj +def makeFemFluidSection(name="FluidSection"): + '''makeFemFluidSection([name]): creates an Fluid section object to define 1D flow''' + obj = FreeCAD.ActiveDocument.addObject("Fem::FeaturePython", name) + import PyObjects._FemFluidSection + PyObjects._FemFluidSection._FemFluidSection(obj) + if FreeCAD.GuiUp: + import PyGui._ViewProviderFemFluidSection + PyGui._ViewProviderFemFluidSection._ViewProviderFemFluidSection(obj.ViewObject) + return obj + + def makeShellThickness(thickness=20.0, name="ShellThickness"): '''makeShellThickness([thickness], [name]): creates an shellthickness object to define a plate thickness''' obj = FreeCAD.ActiveDocument.addObject("Fem::FeaturePython", name) diff --git a/src/Mod/Fem/PyGui/TaskPanelFemFluidSection.ui b/src/Mod/Fem/PyGui/TaskPanelFemFluidSection.ui new file mode 100644 index 000000000000..49700d9ae01c --- /dev/null +++ b/src/Mod/Fem/PyGui/TaskPanelFemFluidSection.ui @@ -0,0 +1,890 @@ + + + Form + + + + 0 + 0 + 590 + 653 + + + + Form + + + + + + + 16777215 + 1677215 + + + + Fluid Section Parameter + + + + + + + + + + + + 0 + + + + + + + Liquid Section Parameter + + + + + + + + + + 9 + + + + + + + + + Pipe Area + + + + + + + 0 mm^2 + + + mm^2 + + + + + + + + + + + Hydraulic Radius + + + + + + + 0 mm + + + mm + + + + + + + + + + + Manning Coefficient + + + + + + + 3 + + + 1.000000000000000 + + + 0.001000000000000 + + + + + + + + + + + + + + + Initial Area + + + + + + + 0 mm^2 + + + mm^2 + + + + + + + + + + + Enlarged Area + + + + + + + 0 mm^2 + + + mm^2 + + + + + + + + + + + + + + + Initial Area + + + + + + + 0 mm^2 + + + mm^2 + + + + + + + + + + + Contracted Area + + + + + + + 0 mm^2 + + + mm^2 + + + + + + + + + + + + + Inlet Pressure + + + true + + + + + + + + Pressure + + + + + + + true + + + + + + MPa + + + + + + + + + + + + Inlet Mass Flow Rate + + + true + + + + + + + + Mass flow rate + + + + + + + 1 kg/s + + + kg/s + + + + + + + + + + + + + + + + Outlet Pressure + + + true + + + + + + + + Pressure + + + + + + + + + + MPa + + + + + + + + + + + + + Outlet Mass Flow Rate + + + true + + + + + + + + Mass flow rate + + + + + + + 1 kg/s + + + kg/s + + + + + + + + + + + + + + + + + + Pipe Area + + + + + + + 0 mm^2 + + + mm^2 + + + + + + + + + + + Entrance Area + + + + + + + 0 mm^2 + + + mm^2 + + + + + + + + + + + + + + + Pipe Area + + + + + + + 0 mm^2 + + + mm^2 + + + + + + + + + + + Diaphragm Area + + + + + + + 0 mm^2 + + + mm^2 + + + + + + + + + + + + + + + Pipe Area + + + + + + + 0 mm^2 + + + mm^2 + + + + + + + + + + + Bend Radius/Pipe Diameter + + + + + + + 3 + + + 1.000000000000000 + + + 9999999.000000000000000 + + + 0.100000000000000 + + + + + + + + + + + Bend Angle + + + + + + + 3 + + + 360.000000000000000 + + + 1.000000000000000 + + + + + + + + + + + Head loss coefficient + + + + + + + 3 + + + 1.000000000000000 + + + 0.001000000000000 + + + + + + + + + + + + + + + Pipe Area + + + + + + + 0 mm^2 + + + mm^2 + + + + + + + + + + + Gate valve closing coefficient + + + + + + + 3 + + + 0.125000000000000 + + + 1.000000000000000 + + + 0.100000000000000 + + + + + + + + + + + + + + + Pump Characteristic + + + + + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + Flow rate [mm^3/s] + + + + + Head Loss[mm] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Pipe Area + + + + + + + 0 mm^2 + + + mm^2 + + + + + + + + + + + Hydraulic Radius + + + + + + + 0 mm + + + mm + + + + + + + + + + + Grain diameter + + + + + + + 0 mm + + + mm + + + + + + + + + + + Cross section form factor + + + + + + + 3 + + + 0.000000000000000 + + + 1.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + + + + + + + + + + + Gas Section Parameter + + + + + + + + + + + + + + Open Channel Section Parameter + + + + + + + + + + + + + + References + + + + + + Select an edge, click Add or Remove + + + + + + + + + Add + + + + + + + Remove + + + + + + + + + + + + + + + + Gui::InputField + QLineEdit +
Gui/InputField.h
+
+
+ + +
diff --git a/src/Mod/Fem/PyGui/_TaskPanelFemFluidSection.py b/src/Mod/Fem/PyGui/_TaskPanelFemFluidSection.py new file mode 100644 index 000000000000..2ab671f4ab81 --- /dev/null +++ b/src/Mod/Fem/PyGui/_TaskPanelFemFluidSection.py @@ -0,0 +1,382 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2016 - Ofentse Kgoa * +# * Based on the FemBeamSection by Bernd Hahnebach * +# * * +# * 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__ = "_TaskPanelFemFluidSection" +__author__ = "Ofentse Kgoa" +__url__ = "http://www.freecadweb.org" + +## @package TaskPanelFemFluidSection +# \ingroup FEM + +import FreeCAD +import FreeCADGui +from PySide import QtGui +from PySide import QtCore +import PyObjects._FemFluidSection + + +class _TaskPanelFemFluidSection: + '''The TaskPanel for editing References property of FemFluidSection objects''' + def __init__(self, obj): + FreeCADGui.Selection.clearSelection() + self.sel_server = None + self.obj = obj + + self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Fem/PyGui/TaskPanelFemFluidSection.ui") + QtCore.QObject.connect(self.form.btn_add, QtCore.SIGNAL("clicked()"), self.add_references) + QtCore.QObject.connect(self.form.btn_remove, QtCore.SIGNAL("clicked()"), self.remove_reference) + QtCore.QObject.connect(self.form.cb_section_type, QtCore.SIGNAL("activated(int)"), self.sectiontype_changed) + QtCore.QObject.connect(self.form.cb_liquid_section_type, QtCore.SIGNAL("activated(int)"), self.liquidsectiontype_changed) + QtCore.QObject.connect(self.form.if_manning_area, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.manning_area_changed) + QtCore.QObject.connect(self.form.if_manning_radius, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.manning_radius_changed) + QtCore.QObject.connect(self.form.sb_manning_coefficient, QtCore.SIGNAL("valueChanged(double)"), self.manning_coefficient_changed) + QtCore.QObject.connect(self.form.if_enlarge_area1, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.enlarge_area1_changed) + QtCore.QObject.connect(self.form.if_enlarge_area2, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.enlarge_area2_changed) + QtCore.QObject.connect(self.form.if_contract_area1, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.contract_area1_changed) + QtCore.QObject.connect(self.form.if_contract_area2, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.contract_area2_changed) + QtCore.QObject.connect(self.form.if_inletpressure, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.inlet_pressure_changed) + QtCore.QObject.connect(self.form.if_outletpressure, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.outlet_pressure_changed) + QtCore.QObject.connect(self.form.if_inletflowrate, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.inlet_flowrate_changed) + QtCore.QObject.connect(self.form.if_outletflowrate, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.outlet_flowrate_changed) + QtCore.QObject.connect(self.form.gb_inletpressure, QtCore.SIGNAL("clicked(bool)"), self.inlet_pressure_active) + QtCore.QObject.connect(self.form.gb_outletpressure, QtCore.SIGNAL("clicked(bool)"), self.outlet_pressure_active) + QtCore.QObject.connect(self.form.gb_inletflowrate, QtCore.SIGNAL("clicked(bool)"), self.inlet_flowrate_active) + QtCore.QObject.connect(self.form.gb_outletflowrate, QtCore.SIGNAL("clicked(bool)"), self.outlet_flowrate_active) + QtCore.QObject.connect(self.form.if_entrance_pipe_area, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.entrance_pipe_area_changed) + QtCore.QObject.connect(self.form.if_entrance_area, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.entrance_area_changed) + QtCore.QObject.connect(self.form.if_diaphragm_pipe_area, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.diaphragm_pipe_area_changed) + QtCore.QObject.connect(self.form.if_diaphragm_area, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.diaphragm_area_changed) + QtCore.QObject.connect(self.form.if_bend_pipe_area, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.bend_pipe_area_changed) + QtCore.QObject.connect(self.form.sb_bradius_pdiameter, QtCore.SIGNAL("valueChanged(double)"), self.bradius_pdiameter_changed) + QtCore.QObject.connect(self.form.sb_bend_angle, QtCore.SIGNAL("valueChanged(double)"), self.bend_angle_changed) + QtCore.QObject.connect(self.form.sb_bend_loss_coefficient, QtCore.SIGNAL("valueChanged(double)"), self.bend_loss_coefficient_changed) + QtCore.QObject.connect(self.form.if_gatevalve_pipe_area, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.gatevalve_pipe_area_changed) + QtCore.QObject.connect(self.form.sb_gatevalve_closing_coeff, QtCore.SIGNAL("valueChanged(double)"), self.gatevalve_closing_coeff_changed) + QtCore.QObject.connect(self.form.if_colebrooke_pipe_area, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.colebrooke_pipe_area_changed) + QtCore.QObject.connect(self.form.if_colebrooke_radius, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.colebrooke_radius_changed) + QtCore.QObject.connect(self.form.if_colebrooke_grain_diameter, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.colebrooke_grain_diameter_changed) + QtCore.QObject.connect(self.form.sb_colebrooke_form_factor, QtCore.SIGNAL("valueChanged(double)"), self.colebrooke_form_factor_changed) + QtCore.QObject.connect(self.form.tw_pump_characteristics, QtCore.SIGNAL("cellChanged(int, int)"), self.pump_characteristics_changed) + self.form.list_References.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) + self.form.list_References.connect(self.form.list_References, QtCore.SIGNAL("customContextMenuRequested(QPoint)"), self.references_list_right_clicked) + self.form.cb_section_type.addItems(PyObjects._FemFluidSection._FemFluidSection.known_fluid_types) + self.form.cb_liquid_section_type.addItems(PyObjects._FemFluidSection._FemFluidSection.known_liquid_types) + self.form.cb_gas_section_type.addItems(PyObjects._FemFluidSection._FemFluidSection.known_gas_types) + self.form.cb_channel_section_type.addItems(PyObjects._FemFluidSection._FemFluidSection.known_channel_types) + + self.get_fluidsection_props() + self.update() + + def accept(self): + self.set_fluidsection_props() + if self.sel_server: + FreeCADGui.Selection.removeObserver(self.sel_server) + FreeCADGui.ActiveDocument.resetEdit() + FreeCAD.ActiveDocument.recompute() + return True + + def reject(self): + if self.sel_server: + FreeCADGui.Selection.removeObserver(self.sel_server) + FreeCADGui.ActiveDocument.resetEdit() + return True + + def get_fluidsection_props(self): + self.references = [] + if self.obj.References: + self.tuplereferences = self.obj.References + self.get_references() + self.SectionType = self.obj.SectionType + self.LiquidSectionType = self.obj.LiquidSectionType + self.ManningArea = self.obj.ManningArea + self.ManningRadius = self.obj.ManningRadius + self.ManningCoefficient = self.obj.ManningCoefficient + self.EnlargeArea1 = self.obj.EnlargeArea1 + self.EnlargeArea2 = self.obj.EnlargeArea2 + self.ContractArea1 = self.obj.ContractArea1 + self.ContractArea2 = self.obj.ContractArea2 + self.OutletPressure = self.obj.OutletPressure + self.InletPressure = self.obj.InletPressure + self.OutletFlowRate = self.obj.OutletFlowRate + self.InletFlowRate = self.obj.InletFlowRate + self.OutletPressureActive = self.obj.OutletPressureActive + self.InletPressureActive = self.obj.InletPressureActive + self.OutletFlowRateActive = self.obj.OutletFlowRateActive + self.InletFlowRateActive = self.obj.InletFlowRateActive + self.EntrancePipeArea = self.obj.EntrancePipeArea + self.EntranceArea = self.obj.EntranceArea + self.DiaphragmPipeArea = self.obj.DiaphragmPipeArea + self.DiaphragmArea = self.obj.DiaphragmArea + self.BendPipeArea = self.obj.BendPipeArea + self.BendRadiusDiameter = self.obj.BendRadiusDiameter + self.BendAngle = self.obj.BendAngle + self.BendLossCoefficient = self.obj.BendLossCoefficient + self.GateValvePipeArea = self.obj.GateValvePipeArea + self.GateValveClosingCoeff = self.obj.GateValveClosingCoeff + self.ColebrookeArea = self.obj.ColebrookeArea + self.ColebrookeRadius = self.obj.ColebrookeRadius + self.ColebrookeGrainDiameter = self.obj.ColebrookeGrainDiameter + self.ColebrookeFormFactor = self.obj.ColebrookeFormFactor + self.PumpFlowRate = self.obj.PumpFlowRate + self.PumpHeadLoss = self.obj.PumpHeadLoss + + def set_fluidsection_props(self): + self.obj.References = self.references + self.obj.LiquidSectionType = self.LiquidSectionType + self.obj.SectionType = self.SectionType + self.obj.ManningArea = self.ManningArea + self.obj.ManningRadius = self.ManningRadius + self.obj.ManningCoefficient = self.ManningCoefficient + self.obj.EnlargeArea1 = self.EnlargeArea1 + self.obj.EnlargeArea2 = self.EnlargeArea2 + self.obj.ContractArea1 = self.ContractArea1 + self.obj.ContractArea2 = self.ContractArea2 + self.obj.OutletPressure = self.OutletPressure + self.obj.InletPressure = self.InletPressure + self.obj.OutletFlowRate = self.OutletFlowRate + self.obj.InletFlowRate = self.InletFlowRate + self.obj.OutletPressureActive = self.OutletPressureActive + self.obj.InletPressureActive = self.InletPressureActive + self.obj.OutletFlowRateActive = self.OutletFlowRateActive + self.obj.InletFlowRateActive = self.InletFlowRateActive + self.obj.EntrancePipeArea = self.EntrancePipeArea + self.obj.EntranceArea = self.EntranceArea + self.obj.DiaphragmPipeArea = self.DiaphragmPipeArea + self.obj.DiaphragmArea = self.DiaphragmArea + self.obj.BendPipeArea = self.BendPipeArea + self.obj.BendRadiusDiameter = self.BendRadiusDiameter + self.obj.BendAngle = self.BendAngle + self.obj.BendLossCoefficient = self.BendLossCoefficient + self.obj.GateValvePipeArea = self.GateValvePipeArea + self.obj.GateValveClosingCoeff = self.GateValveClosingCoeff + self.obj.ColebrookeArea = self.ColebrookeArea + self.obj.ColebrookeRadius = self.ColebrookeRadius + self.obj.ColebrookeGrainDiameter = self.ColebrookeGrainDiameter + self.obj.ColebrookeFormFactor = self.ColebrookeFormFactor + self.obj.PumpFlowRate = self.PumpFlowRate + self.obj.PumpHeadLoss = self.PumpHeadLoss + + def update(self): + 'fills the widgets' + index_sectiontype = self.form.cb_section_type.findText(self.SectionType) + self.form.cb_section_type.setCurrentIndex(index_sectiontype) + self.form.sw_section_type.setCurrentIndex(index_sectiontype) + index_liquidsectiontype = self.form.cb_liquid_section_type.findText(self.LiquidSectionType) + self.form.cb_liquid_section_type.setCurrentIndex(index_liquidsectiontype) + self.form.sw_liquid_section_type.setCurrentIndex(index_liquidsectiontype) + self.form.if_manning_area.setText(self.ManningArea.UserString) + self.form.if_manning_radius.setText(self.ManningRadius.UserString) + self.form.sb_manning_coefficient.setValue(self.ManningCoefficient) + self.form.if_enlarge_area1.setText(self.EnlargeArea1.UserString) + self.form.if_enlarge_area2.setText(self.EnlargeArea2.UserString) + self.form.if_contract_area1.setText(self.ContractArea1.UserString) + self.form.if_contract_area2.setText(self.ContractArea2.UserString) + self.form.if_inletpressure.setText(FreeCAD.Units.Quantity(1000 * self.InletPressure, FreeCAD.Units.Pressure).UserString) + self.form.if_outletpressure.setText(FreeCAD.Units.Quantity(1000 * self.OutletPressure, FreeCAD.Units.Pressure).UserString) + self.form.if_inletflowrate.setText(str(self.InletFlowRate)) + self.form.if_outletflowrate.setText(str(self.OutletFlowRate)) + self.form.gb_inletpressure.setChecked(self.InletPressureActive) + self.form.gb_outletpressure.setChecked(self.OutletPressureActive) + self.form.gb_inletflowrate.setChecked(self.InletFlowRateActive) + self.form.gb_outletflowrate.setChecked(self.OutletFlowRateActive) + self.form.if_entrance_pipe_area.setText(self.EntrancePipeArea.UserString) + self.form.if_entrance_area.setText(self.EntranceArea.UserString) + self.form.if_diaphragm_pipe_area.setText(self.DiaphragmPipeArea.UserString) + self.form.if_diaphragm_area.setText(self.DiaphragmArea.UserString) + self.form.if_bend_pipe_area.setText(self.BendPipeArea.UserString) + self.form.sb_bradius_pdiameter.setValue(self.BendRadiusDiameter) + self.form.sb_bend_angle.setValue(self.BendAngle) + self.form.sb_bend_loss_coefficient.setValue(self.BendLossCoefficient) + self.form.if_gatevalve_pipe_area.setText(self.GateValvePipeArea.UserString) + self.form.sb_gatevalve_closing_coeff.setValue(self.GateValveClosingCoeff) + self.form.if_colebrooke_pipe_area.setText(self.ColebrookeArea.UserString) + self.form.if_colebrooke_radius.setText(self.ColebrookeRadius.UserString) + self.form.if_colebrooke_grain_diameter.setText(self.ColebrookeGrainDiameter.UserString) + self.form.sb_colebrooke_form_factor.setValue(self.ColebrookeFormFactor) + for i in range(len(self.PumpFlowRate)): + self.form.tw_pump_characteristics.setItem(i,0,QtGui.QTableWidgetItem(str(self.PumpFlowRate[i]))) + self.form.tw_pump_characteristics.setItem(i,1,QtGui.QTableWidgetItem(str(self.PumpHeadLoss[i]))) + self.rebuild_list_References() + + def sectiontype_changed(self, index): + if index < 0: + return + self.form.cb_section_type.setCurrentIndex(index) + self.form.sw_section_type.setCurrentIndex(index) + self.SectionType = str(self.form.cb_section_type.itemText(index)) # form returns unicode + + def liquidsectiontype_changed(self, index): + if index < 0: + return + self.form.cb_liquid_section_type.setCurrentIndex(index) + self.form.sw_liquid_section_type.setCurrentIndex(index) + self.LiquidSectionType = str(self.form.cb_liquid_section_type.itemText(index)) # form returns unicode + + def manning_area_changed(self, base_quantity_value): + self.ManningArea = base_quantity_value + + def manning_radius_changed(self, base_quantity_value): + self.ManningRadius = base_quantity_value + + def manning_coefficient_changed(self, base_quantity_value): + self.ManningCoefficient = base_quantity_value + + def enlarge_area1_changed(self, base_quantity_value): + self.EnlargeArea1 = base_quantity_value + + def enlarge_area2_changed(self, base_quantity_value): + self.EnlargeArea2 = base_quantity_value + + def contract_area1_changed(self, base_quantity_value): + self.ContractArea1 = base_quantity_value + + def contract_area2_changed(self, base_quantity_value): + self.ContractArea2 = base_quantity_value + + def inlet_pressure_changed(self, base_quantity_value): + self.InletPressure = float(FreeCAD.Units.Quantity(base_quantity_value).getValueAs("MPa")) + + def outlet_pressure_changed(self, base_quantity_value): + self.OutletPressure = float(FreeCAD.Units.Quantity(base_quantity_value).getValueAs("MPa")) + + def inlet_flowrate_changed(self, base_quantity_value): + self.InletFlowRate = float(FreeCAD.Units.Quantity(base_quantity_value).getValueAs("kg/s")) + + def outlet_flowrate_changed(self, base_quantity_value): + self.OutletFlowRate = float(FreeCAD.Units.Quantity(base_quantity_value).getValueAs("kg/s")) + + def inlet_pressure_active(self, active): + self.InletPressureActive = active + + def outlet_pressure_active(self, active): + self.OutletPressureActive = active + + def inlet_flowrate_active(self, active): + self.InletFlowRateActive = active + + def outlet_flowrate_active(self, active): + self.OutletFlowRateActive = active + + def entrance_pipe_area_changed(self, base_quantity_value): + self.EntrancePipeArea = base_quantity_value + + def entrance_area_changed(self, base_quantity_value): + self.EntranceArea = base_quantity_value + + def diaphragm_pipe_area_changed(self, base_quantity_value): + self.DiaphragmPipeArea = base_quantity_value + + def diaphragm_area_changed(self, base_quantity_value): + self.DiaphragmArea = base_quantity_value + + def bend_pipe_area_changed(self, base_quantity_value): + self.BendPipeArea = base_quantity_value + + def bradius_pdiameter_changed(self, base_quantity_value): + self.BendRadiusDiameter = base_quantity_value + + def bend_angle_changed(self, base_quantity_value): + self.BendAngle = base_quantity_value + + def bend_loss_coefficient_changed(self, base_quantity_value): + self.BendLossCoefficient = base_quantity_value + + def gatevalve_pipe_area_changed(self, base_quantity_value): + self.GateValvePipeArea = base_quantity_value + + def gatevalve_closing_coeff_changed(self, base_quantity_value): + self.GateValveClosingCoeff = base_quantity_value + + def colebrooke_pipe_area_changed(self, base_quantity_value): + self.ColebrookeArea = base_quantity_value + + def colebrooke_radius_changed(self, base_quantity_value): + self.ColebrookeRadius = base_quantity_value + + def colebrooke_grain_diameter_changed(self, base_quantity_value): + self.ColebrookeGrainDiameter = base_quantity_value + + def colebrooke_form_factor_changed(self, base_quantity_value): + self.ColebrookeFormFactor = base_quantity_value + + def pump_characteristics_changed(self, row, column): + if column == 0: + self.PumpFlowRate[row] = float(self.form.tw_pump_characteristics.item(row, column).text()) + else: + self.PumpHeadLoss[row] = float(self.form.tw_pump_characteristics.item(row, column).text()) + + def get_references(self): + for ref in self.tuplereferences: + for elem in ref[1]: + self.references.append((ref[0], elem)) + + def references_list_right_clicked(self, QPos): + self.form.contextMenu = QtGui.QMenu() + menu_item = self.form.contextMenu.addAction("Remove Reference") + if not self.references: + menu_item.setDisabled(True) + self.form.connect(menu_item, QtCore.SIGNAL("triggered()"), self.remove_reference) + parentPosition = self.form.list_References.mapToGlobal(QtCore.QPoint(0, 0)) + self.form.contextMenu.move(parentPosition + QPos) + self.form.contextMenu.show() + + def remove_reference(self): + if not self.references: + return + currentItemName = str(self.form.list_References.currentItem().text()) + for ref in self.references: + refname_to_compare_listentry = ref[0].Name + ':' + ref[1] + if refname_to_compare_listentry == currentItemName: + self.references.remove(ref) + self.rebuild_list_References() + + def add_references(self): + '''Called if Button add_reference is triggered''' + # in constraints EditTaskPanel the selection is active as soon as the taskpanel is open + # here the addReference button EditTaskPanel has to be triggered to start selection mode + FreeCADGui.Selection.clearSelection() + # start SelectionObserver and parse the function to add the References to the widget + print_message = "Select Edges by single click on them to add them to the list" + import FemSelectionObserver + self.sel_server = FemSelectionObserver.FemSelectionObserver(self.selectionParser, print_message) + + def selectionParser(self, selection): + # print('selection: ', selection[0].Shape.ShapeType, ' ', selection[0].Name, ' ', selection[1]) + if hasattr(selection[0], "Shape"): + if selection[1]: + elt = selection[0].Shape.getElement(selection[1]) + if elt.ShapeType == 'Edge': + if selection not in self.references: + self.references.append(selection) + self.rebuild_list_References() + else: + FreeCAD.Console.PrintMessage(selection[0].Name + ' --> ' + selection[1] + ' is in reference list already!\n') + + def rebuild_list_References(self): + self.form.list_References.clear() + items = [] + for ref in self.references: + item_name = ref[0].Name + ':' + ref[1] + items.append(item_name) + for listItemName in sorted(items): + self.form.list_References.addItem(listItemName) diff --git a/src/Mod/Fem/PyGui/_ViewProviderFemFluidSection.py b/src/Mod/Fem/PyGui/_ViewProviderFemFluidSection.py new file mode 100644 index 000000000000..22d514a8dd9f --- /dev/null +++ b/src/Mod/Fem/PyGui/_ViewProviderFemFluidSection.py @@ -0,0 +1,85 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2016 - Ofentse Kgoa * +# * Based on the FemBeamSection by Bernd Hahnebach * +# * * +# * 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__ = "_ViewProviderFemFluidSection" +__author__ = "Ofentse Kgoa" +__url__ = "http://www.freecadweb.org" + +## @package ViewProviderFemFluidSection +# \ingroup FEM + +import FreeCAD +import FreeCADGui +from pivy import coin + + +class _ViewProviderFemFluidSection: + "A View Provider for the FemFluidSection object" + def __init__(self, vobj): + vobj.Proxy = self + + def getIcon(self): + return ":/icons/fem-fluid-section.svg" + + def attach(self, vobj): + self.ViewObject = vobj + self.Object = vobj.Object + self.standard = coin.SoGroup() + vobj.addDisplayMode(self.standard, "Standard") + + def getDisplayModes(self, obj): + return ["Standard"] + + def getDefaultDisplayMode(self): + return "Standard" + + def updateData(self, obj, prop): + return + + def onChanged(self, vobj, prop): + return + + def setEdit(self, vobj, mode=0): + import PyGui._TaskPanelFemFluidSection + taskd = PyGui._TaskPanelFemFluidSection._TaskPanelFemFluidSection(self.Object) + taskd.obj = vobj.Object + FreeCADGui.Control.showDialog(taskd) + return True + + def unsetEdit(self, vobj, mode=0): + FreeCADGui.Control.closeDialog() + return + + def doubleClicked(self, vobj): + doc = FreeCADGui.getDocument(vobj.Object.Document) + if not doc.getInEdit(): + doc.setEdit(vobj.Object.Name) + else: + FreeCAD.Console.PrintError('Active Task Dialog found! Please close this one first!\n') + return True + + def __getstate__(self): + return None + + def __setstate__(self, state): + return None diff --git a/src/Mod/Fem/PyObjects/_FemConstraintSelfWeight.py b/src/Mod/Fem/PyObjects/_FemConstraintSelfWeight.py index 28a5e2b649f9..e590dc8cd1fd 100644 --- a/src/Mod/Fem/PyObjects/_FemConstraintSelfWeight.py +++ b/src/Mod/Fem/PyObjects/_FemConstraintSelfWeight.py @@ -31,6 +31,12 @@ class _FemConstraintSelfWeight: "The FemConstraintSelfWeight object" def __init__(self, obj): + obj.addProperty("App::PropertyFloat", "Gravity_x", "Gravity", "set the gravity component in the x direction") + obj.addProperty("App::PropertyFloat", "Gravity_y", "Gravity", "set the gravity component in the y direction") + obj.addProperty("App::PropertyFloat", "Gravity_z", "Gravity", "set the gravity component in the z direction") + obj.Gravity_x = 0.0 + obj.Gravity_y = 0.0 + obj.Gravity_z = -1.0 obj.Proxy = self self.Type = "FemConstraintSelfWeight" diff --git a/src/Mod/Fem/PyObjects/_FemFluidSection.py b/src/Mod/Fem/PyObjects/_FemFluidSection.py new file mode 100644 index 000000000000..45432e41a220 --- /dev/null +++ b/src/Mod/Fem/PyObjects/_FemFluidSection.py @@ -0,0 +1,122 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2016 - Ofentse Kgoa * +# * Based on the FemBeamSection by Bernd Hahnebach * +# * * +# * 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__ = "_FemFluidSection" +__author__ = "Ofentse Kgoa" +__url__ = "http://www.freecadweb.org" + +## @package FemFluidSection +# \ingroup FEM + + +class _FemFluidSection: + "The FemFluidSection object" + + known_fluid_types = ['Liquid', 'Gas', 'Open Channel'] + known_liquid_types = ['PIPE MANNING', 'PIPE ENLARGEMENT', 'PIPE CONTRACTION', 'PIPE INLET', 'PIPE OUTLET', 'PIPE ENTRANCE', 'PIPE DIAPHRAGM', 'PIPE BEND', 'PIPE GATE VALVE', 'LIQUID PUMP', 'PIPE WHITE-COLEBROOK'] + known_gas_types = ['NONE'] + known_channel_types = ['NONE'] + + def __init__(self, obj): + obj.addProperty("App::PropertyLinkSubList", "References", "FluidSection", "List of fluid section shapes") + obj.addProperty("App::PropertyEnumeration", "SectionType", "FluidSection", "select fluid section type") + obj.addProperty("App::PropertyEnumeration", "LiquidSectionType", "LiquidSection", "select liquid section type") + obj.addProperty("App::PropertyArea", "ManningArea", "LiquidManning", "set area of the manning fluid section") + obj.addProperty("App::PropertyLength", "ManningRadius", "LiquidManning", "set hydraulic radius of manning fluid section") + obj.addProperty("App::PropertyFloat", "ManningCoefficient", "LiquidManning", "set coefficient of manning fluid section") + obj.addProperty("App::PropertyArea", "EnlargeArea1", "LiquidEnlargement", "set intial area of the enlargement fluid section") + obj.addProperty("App::PropertyArea", "EnlargeArea2", "LiquidEnlargement", "set enlarged area of enlargement fluid section") + obj.addProperty("App::PropertyArea", "ContractArea1", "LiquidContraction", "set intial area of the contraction fluid section") + obj.addProperty("App::PropertyArea", "ContractArea2", "LiquidContraction", "set contracted area of contraction fluid section") + obj.addProperty("App::PropertyFloat", "InletPressure", "LiquidInlet", "set inlet pressure for fluid section") + obj.addProperty("App::PropertyFloat", "OutletPressure", "LiquidOutlet", "set outlet pressure for fluid section") + obj.addProperty("App::PropertyFloat", "InletFlowRate", "LiquidInlet", "set inlet mass flow rate for fluid section") + obj.addProperty("App::PropertyFloat", "OutletFlowRate", "LiquidOutlet", "set outlet mass flow rate for fluid section") + obj.addProperty("App::PropertyBool", "InletPressureActive", "LiquidInlet", "activates or deactivates inlet pressure for fluid section") + obj.addProperty("App::PropertyBool", "OutletPressureActive", "LiquidOutlet", "activates or deactivates outlet pressure for fluid section") + obj.addProperty("App::PropertyBool", "InletFlowRateActive", "LiquidInlet", "activates or deactivates inlet flow rate for fluid section") + obj.addProperty("App::PropertyBool", "OutletFlowRateActive", "LiquidOutlet", "activates or deactivates outlet flow rate for fluid section") + obj.addProperty("App::PropertyArea", "EntrancePipeArea", "LiquidEntrance", "set the pipe area of the entrance fluid section") + obj.addProperty("App::PropertyArea", "EntranceArea", "LiquidEntrance", "set the entrance area of the entrance fluid section") + obj.addProperty("App::PropertyArea", "DiaphragmPipeArea", "LiquidDiaphragm", "set the pipe area of the diaphragm fluid section") + obj.addProperty("App::PropertyArea", "DiaphragmArea", "LiquidDiaphragm", "set the diaphragm area of the diaphragm fluid section") + obj.addProperty("App::PropertyArea", "BendPipeArea", "LiquidBend", "set pipe area of the bend fluid section") + obj.addProperty("App::PropertyFloat", "BendRadiusDiameter", "LiquidBend", "set ratio of bend radius over pipe diameter of the bend fluid section") + obj.addProperty("App::PropertyFloat", "BendAngle", "LiquidBend", "set bend angle of the bend fluid section") + obj.addProperty("App::PropertyFloat", "BendLossCoefficient", "LiquidBend", "set loss coefficient of the bend fluid section") + obj.addProperty("App::PropertyArea", "GateValvePipeArea", "LiquidGateValve", "set pipe area of the gate valve fluid section") + obj.addProperty("App::PropertyFloat", "GateValveClosingCoeff", "LiquidGateValve", "set closing coefficient of the gate valve fluid section") + obj.addProperty("App::PropertyFloatList", "PumpFlowRate", "LiquidPump", "set the pump characteristic flow rate of the pump fluid section") + obj.addProperty("App::PropertyFloatList", "PumpHeadLoss", "LiquidPump", "set the pump characteristic head loss of the pump fluid section") + obj.addProperty("App::PropertyArea", "ColebrookeArea", "LiquidColebrooke", "set pipe area of the colebrooke fluid section") + obj.addProperty("App::PropertyLength", "ColebrookeRadius", "LiquidColebrooke", "set hydraulic radius of the colebrooke fluid section") + obj.addProperty("App::PropertyLength", "ColebrookeGrainDiameter", "LiquidColebrooke", "set grain diameter of the colebrooke fluid section") + obj.addProperty("App::PropertyFloat", "ColebrookeFormFactor", "LiquidColebrooke", "set coefficient of the colebrooke fluid section") + obj.addProperty("App::PropertyEnumeration", "GasSectionType", "GasSection", "select gas section type") + obj.addProperty("App::PropertyEnumeration", "ChannelSectionType", "ChannelSection", "select channel section type") + + # set property default values + obj.SectionType = _FemFluidSection.known_fluid_types + obj.SectionType = 'Liquid' + obj.LiquidSectionType = _FemFluidSection.known_liquid_types + obj.LiquidSectionType = 'PIPE INLET' + obj.GasSectionType = _FemFluidSection.known_gas_types + obj.GasSectionType = 'NONE' + obj.ChannelSectionType = _FemFluidSection.known_channel_types + obj.ChannelSectionType = 'NONE' + obj.ManningArea = 10.0 + obj.ManningRadius = 1.0 + obj.ManningCoefficient = 0.0015 # has units of s/mm^(1/3) + obj.EnlargeArea1 = 10.0 + obj.EnlargeArea2 = 20.0 + obj.ContractArea1 = 20.0 + obj.ContractArea2 = 10.0 + obj.EntrancePipeArea = 20.0 + obj.EntranceArea = 20.0 + obj.DiaphragmPipeArea = 20.0 + obj.DiaphragmArea = 20.0 + obj.BendPipeArea = 20.0 + obj.BendRadiusDiameter = 1.0 + obj.BendAngle = 0.0 + obj.BendLossCoefficient = 0.0 + obj.GateValvePipeArea = 20.0 + obj.GateValveClosingCoeff = 0.125 + obj.PumpFlowRate = [0, 1.04e-04, 2.08e-4, 3.13e-4, 4.17e-4] + obj.PumpHeadLoss = [30, 29.17, 26.67, 23.33, 18.33] + obj.ColebrookeArea = 20.0 + obj.ColebrookeRadius = 1.0 + obj.ColebrookeGrainDiameter = 0.0025 + obj.ColebrookeFormFactor = 1.0 + obj.InletPressure = 1.0 + obj.OutletPressure = 1.0 + obj.InletFlowRate = 1.0 + obj.OutletFlowRate = 1.0 + obj.InletPressureActive = True + obj.OutletPressureActive = True + obj.InletFlowRateActive = False + obj.OutletFlowRateActive = False + obj.Proxy = self + self.Type = "FemFluidSection" + + def execute(self, obj): + return