Skip to content

Commit

Permalink
FEM: material task panel, small code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
berndhahnebach authored Mar 16, 2021
1 parent 4bf8fd2 commit b9f4576
Showing 1 changed file with 19 additions and 33 deletions.
52 changes: 19 additions & 33 deletions src/Mod/Fem/femtaskpanels/task_material_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,15 @@ def check_material_keys(self):
self.material["SpecificHeat"] = "0 J/kg/K"
FreeCAD.Console.PrintMessage("\n")

def update_material_property(self, input_field, matProperty, qUnit, variation=0.001):
def update_material_property(self, inputfield_text, matProperty, qUnit, variation=0.001):
# print(inputfield_text)
# this update property works for all Gui::InputField widgets
if qUnit != "":
value = Units.Quantity(input_field.text()).getValueAs(qUnit)
value = Units.Quantity(inputfield_text).getValueAs(qUnit)
old_value = Units.Quantity(self.material[matProperty]).getValueAs(qUnit)
else:
# for example PoissonRatio
value = float(input_field.text())
value = float(inputfield_text)
old_value = float(self.material[matProperty])
if value:
if not (1 - variation < float(old_value) / value < 1 + variation):
Expand All @@ -540,40 +541,36 @@ def update_material_property(self, input_field, matProperty, qUnit, variation=0.
self.set_transient_material()
else:
pass # some check or default value set can be done here
# print(inputfield_text)

# mechanical input fields
def ym_changed(self):
# FreeCADs standard unit for stress is kPa for UnitsSchemeInternal, but MPa can be used
input_field = self.parameterWidget.input_fd_young_modulus
variation = 0.001
self.update_material_property(
input_field,
self.parameterWidget.input_fd_young_modulus.text(),
"YoungsModulus",
"kPa",
variation
)

def density_changed(self):
print(
"String read from density input field: {}"
.format(self.parameterWidget.input_fd_density.text())
)
# FreeCADs standard unit for density is kg/mm^3 for UnitsSchemeInternal
input_field = self.parameterWidget.input_fd_density
variation = 0.001
self.update_material_property(
input_field,
self.parameterWidget.input_fd_density.text(),
"Density",
"kg/m^3",
variation
)

def pr_changed(self):
value = self.parameterWidget.spinBox_poisson_ratio.value()
input_field = self.parameterWidget.spinBox_poisson_ratio
if value:
variation = 0.001
self.update_material_property(
input_field,
self.parameterWidget.spinBox_poisson_ratio.text(),
"PoissonRatio",
"",
variation
)
elif value == 0:
# PoissonRatio was set to 0.0 what is possible
Expand All @@ -587,50 +584,39 @@ def pr_changed(self):

# thermal input fields
def tc_changed(self):
input_field = self.parameterWidget.input_fd_thermal_conductivity
variation = 0.001
self.update_material_property(
input_field,
self.parameterWidget.input_fd_thermal_conductivity.text(),
"ThermalConductivity",
"W/m/K",
variation
)

def tec_changed(self):
input_field = self.parameterWidget.input_fd_expansion_coefficient
variation = 0.001
self.update_material_property(
input_field,
self.parameterWidget.input_fd_expansion_coefficient.text(),
"ThermalExpansionCoefficient",
"um/m/K",
variation
)

def sh_changed(self):
input_field = self.parameterWidget.input_fd_specific_heat
variation = 0.001
self.update_material_property(
input_field,
self.parameterWidget.input_fd_specific_heat.text(),
"SpecificHeat",
"J/kg/K",
variation
)

# fluidic input fields
def vtec_changed(self):
input_field = self.parameterWidget.input_fd_vol_expansion_coefficient
self.update_material_property(
input_field,
self.parameterWidget.input_fd_vol_expansion_coefficient.text(),
"VolumetricThermalExpansionCoefficient",
"m^3/m^3/K"
"m^3/m^3/K",
)

def kinematic_viscosity_changed(self):
input_field = self.parameterWidget.input_fd_kinematic_viscosity
self.update_material_property(
input_field,
self.parameterWidget.input_fd_kinematic_viscosity.text(),
"KinematicViscosity",
"m^2/s"
"m^2/s",
)

def set_mat_params_in_input_fields(self, matmap):
Expand Down

0 comments on commit b9f4576

Please sign in to comment.