FEM: task panels, improve units value handling

This commit is contained in:
Bernd Hahnebach
2021-08-17 21:31:25 +02:00
parent 6c977d8511
commit 40d29fe329
5 changed files with 30 additions and 34 deletions

View File

@@ -131,7 +131,8 @@ class _TaskPanel(object):
.format(self._paramWidget.potentialTxt.text())
)
if quantity is not None:
self._obj.Potential = float(quantity.getValueAs(unit))
self._obj.Potential = quantity.getValueAs(unit).Value
self._obj.PotentialConstant = self._paramWidget.potentialConstantBox.isChecked()
self._obj.ElectricInfinity = self._paramWidget.electricInfinityBox.isChecked()

View File

@@ -114,15 +114,15 @@ class _TaskPanel(object):
not self._paramWidget.velocityXBox.isChecked()
if self._obj.VelocityXEnabled:
quantity = Units.Quantity(self._paramWidget.velocityXTxt.text())
self._obj.VelocityX = float(quantity.getValueAs(unit))
self._obj.VelocityX = quantity.getValueAs(unit).Value
self._obj.VelocityYEnabled = \
not self._paramWidget.velocityYBox.isChecked()
if self._obj.VelocityYEnabled:
quantity = Units.Quantity(self._paramWidget.velocityYTxt.text())
self._obj.VelocityY = float(quantity.getValueAs(unit))
self._obj.VelocityY = quantity.getValueAs(unit).Value
self._obj.VelocityZEnabled = \
not self._paramWidget.velocityZBox.isChecked()
if self._obj.VelocityZEnabled:
quantity = Units.Quantity(self._paramWidget.velocityZTxt.text())
self._obj.VelocityZ = float(quantity.getValueAs(unit))
self._obj.VelocityZ = quantity.getValueAs(unit).Value
self._obj.NormalToBoundary = self._paramWidget.normalBox.isChecked()

View File

@@ -107,14 +107,14 @@ class _TaskPanel(object):
not self._paramWidget.velocityXBox.isChecked()
if self._obj.VelocityXEnabled:
quantity = Units.Quantity(self._paramWidget.velocityXTxt.text())
self._obj.VelocityX = float(quantity.getValueAs(unit))
self._obj.VelocityX = quantity.getValueAs(unit).Value
self._obj.VelocityYEnabled = \
not self._paramWidget.velocityYBox.isChecked()
if self._obj.VelocityYEnabled:
quantity = Units.Quantity(self._paramWidget.velocityYTxt.text())
self._obj.VelocityY = float(quantity.getValueAs(unit))
self._obj.VelocityY = quantity.getValueAs(unit).Value
self._obj.VelocityZEnabled = \
not self._paramWidget.velocityZBox.isChecked()
if self._obj.VelocityZEnabled:
quantity = Units.Quantity(self._paramWidget.velocityZTxt.text())
self._obj.VelocityZ = float(quantity.getValueAs(unit))
self._obj.VelocityZ = quantity.getValueAs(unit).Value

View File

@@ -36,6 +36,7 @@ from PySide import QtGui
import FreeCAD
import FreeCADGui
from FreeCAD import Units
from femguiutils import selection_widgets
from femobjects import element_fluid1D
@@ -422,24 +423,16 @@ class _TaskPanel:
self.ContractArea2 = base_quantity_value
def inlet_pressure_changed(self, base_quantity_value):
self.InletPressure = float(
FreeCAD.Units.Quantity(base_quantity_value).getValueAs("MPa")
)
self.InletPressure = Units.Quantity(base_quantity_value).getValueAs("MPa").Value
def outlet_pressure_changed(self, base_quantity_value):
self.OutletPressure = float(
FreeCAD.Units.Quantity(base_quantity_value).getValueAs("MPa")
)
self.OutletPressure = Units.Quantity(base_quantity_value).getValueAs("MPa").Value
def inlet_flowrate_changed(self, base_quantity_value):
self.InletFlowRate = float(
FreeCAD.Units.Quantity(base_quantity_value).getValueAs("kg/s")
)
self.InletFlowRate = Units.Quantity(base_quantity_value).getValueAs("kg/s").Value
def outlet_flowrate_changed(self, base_quantity_value):
self.OutletFlowRate = float(
FreeCAD.Units.Quantity(base_quantity_value).getValueAs("kg/s")
)
self.OutletFlowRate = Units.Quantity(base_quantity_value).getValueAs("kg/s").Value
def inlet_pressure_active(self, active):
self.InletPressureActive = active

View File

@@ -427,8 +427,10 @@ class _TaskPanel:
)
self.material["YoungsModulus"] = "0 MPa"
if "PoissonRatio" in self.material:
# PoissonRatio does not have a unit, but it is checked it there is no value at all
# PoissonRatio does not have a unit, but it is checked if there is no value at all
try:
# next line with float() is ok
# a quantity of a empty string returns very small value, would be wrong here
float(self.material["PoissonRatio"])
except ValueError:
FreeCAD.Console.PrintMessage(
@@ -645,55 +647,55 @@ class _TaskPanel:
def set_mat_params_in_input_fields(self, matmap):
if "YoungsModulus" in matmap:
ym_new_unit = "MPa"
ym = FreeCAD.Units.Quantity(matmap["YoungsModulus"])
ym = Units.Quantity(matmap["YoungsModulus"])
ym_with_new_unit = ym.getValueAs(ym_new_unit)
q = FreeCAD.Units.Quantity("{} {}".format(ym_with_new_unit, ym_new_unit))
q = Units.Quantity("{} {}".format(ym_with_new_unit, ym_new_unit))
self.parameterWidget.input_fd_young_modulus.setText(q.UserString)
if "PoissonRatio" in matmap:
self.parameterWidget.spinBox_poisson_ratio.setValue(float(matmap["PoissonRatio"]))
# Fluidic properties
if "KinematicViscosity" in matmap:
nu_new_unit = "m^2/s"
nu = FreeCAD.Units.Quantity(matmap["KinematicViscosity"])
nu = Units.Quantity(matmap["KinematicViscosity"])
nu_with_new_unit = nu.getValueAs(nu_new_unit)
q = FreeCAD.Units.Quantity("{} {}".format(nu_with_new_unit, nu_new_unit))
q = Units.Quantity("{} {}".format(nu_with_new_unit, nu_new_unit))
self.parameterWidget.input_fd_kinematic_viscosity.setText(q.UserString)
# For isotropic materials and fluidic material
# use the volumetric thermal expansion coefficient
# is approximately three times the linear coefficient for solids
if "VolumetricThermalExpansionCoefficient" in matmap:
vtec_new_unit = "m^3/m^3/K"
vtec = FreeCAD.Units.Quantity(matmap["VolumetricThermalExpansionCoefficient"])
vtec = Units.Quantity(matmap["VolumetricThermalExpansionCoefficient"])
vtec_with_new_unit = vtec.getValueAs(vtec_new_unit)
q = FreeCAD.Units.Quantity("{} {}".format(vtec_with_new_unit, vtec_new_unit))
q = Units.Quantity("{} {}".format(vtec_with_new_unit, vtec_new_unit))
self.parameterWidget.input_fd_vol_expansion_coefficient.setText(q.UserString)
if "Density" in matmap:
density_new_unit = "kg/m^3"
density = FreeCAD.Units.Quantity(matmap["Density"])
density = Units.Quantity(matmap["Density"])
density_with_new_unit = density.getValueAs(density_new_unit)
# self.parameterWidget.input_fd_density.setText(
# "{} {}".format(density_with_new_unit, density_new_unit)
# )
q = FreeCAD.Units.Quantity("{} {}".format(density_with_new_unit, density_new_unit))
q = Units.Quantity("{} {}".format(density_with_new_unit, density_new_unit))
self.parameterWidget.input_fd_density.setText(q.UserString)
# thermal properties
if "ThermalConductivity" in matmap:
tc_new_unit = "W/m/K"
tc = FreeCAD.Units.Quantity(matmap["ThermalConductivity"])
tc = Units.Quantity(matmap["ThermalConductivity"])
tc_with_new_unit = tc.getValueAs(tc_new_unit)
q = FreeCAD.Units.Quantity("{} {}".format(tc_with_new_unit, tc_new_unit))
q = Units.Quantity("{} {}".format(tc_with_new_unit, tc_new_unit))
self.parameterWidget.input_fd_thermal_conductivity.setText(q.UserString)
if "ThermalExpansionCoefficient" in matmap: # linear, only for solid
tec_new_unit = "um/m/K"
tec = FreeCAD.Units.Quantity(matmap["ThermalExpansionCoefficient"])
tec = Units.Quantity(matmap["ThermalExpansionCoefficient"])
tec_with_new_unit = tec.getValueAs(tec_new_unit)
q = FreeCAD.Units.Quantity("{} {}".format(tec_with_new_unit, tec_new_unit))
q = Units.Quantity("{} {}".format(tec_with_new_unit, tec_new_unit))
self.parameterWidget.input_fd_expansion_coefficient.setText(q.UserString)
if "SpecificHeat" in matmap:
sh_new_unit = "J/kg/K"
sh = FreeCAD.Units.Quantity(matmap["SpecificHeat"])
sh = Units.Quantity(matmap["SpecificHeat"])
sh_with_new_unit = sh.getValueAs(sh_new_unit)
q = FreeCAD.Units.Quantity("{} {}".format(sh_with_new_unit, sh_new_unit))
q = Units.Quantity("{} {}".format(sh_with_new_unit, sh_new_unit))
self.parameterWidget.input_fd_specific_heat.setText(q.UserString)
# fill the combo box with cards **************************************************************