Skip to content

Commit

Permalink
FEM: material task panel, make use of the new input field update method
Browse files Browse the repository at this point in the history
  • Loading branch information
qingfengxia authored and berndhahnebach committed May 22, 2020
1 parent 74f70b9 commit ee440be
Showing 1 changed file with 19 additions and 110 deletions.
129 changes: 19 additions & 110 deletions src/Mod/Fem/femviewprovider/view_material_common.py
Expand Up @@ -561,53 +561,23 @@ def update_material_property(self, input_field, matProperty, qUnit, variation=0.

# mechanical input fields
def ym_changed(self):
# FreeCADs standard unit for stress is kPa
value = self.parameterWidget.input_fd_young_modulus.property("rawValue")
old_ym = Units.Quantity(self.material["YoungsModulus"]).getValueAs("kPa")
# 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
if value:
if not (1 - variation < float(old_ym) / value < 1 + variation):
# YoungsModulus has changed
material = self.material
material["YoungsModulus"] = unicode(value) + " kPa"
self.material = material
if self.has_transient_mat is False:
self.add_transient_material()
else:
self.set_transient_material()
self.update_material_property(input_field, "YoungsModulus", "kPa", variation)

def density_changed(self):
# FreeCADs standard unit for density is kg/mm^3
value = self.parameterWidget.input_fd_density.property("rawValue")
old_density = Units.Quantity(self.material["Density"]).getValueAs("kg/m^3")
# FreeCADs standard unit for density is kg/mm^3 for UnitsSchemeInternal
input_field = self.parameterWidget.input_fd_density
variation = 0.001
if value:
if not (1 - variation < float(old_density) / value < 1 + variation):
# density has changed
material = self.material
value_in_kg_per_m3 = value * 1e9
# SvdW:Keep density in SI units for easier readability
material["Density"] = unicode(value_in_kg_per_m3) + " kg/m^3"
self.material = material
if self.has_transient_mat is False:
self.add_transient_material()
else:
self.set_transient_material()
self.update_material_property(input_field, "Density", "kg/m^3", variation)

def pr_changed(self):
value = self.parameterWidget.spinBox_poisson_ratio.value()
old_pr = Units.Quantity(self.material["PoissonRatio"])
variation = 0.001
input_field = self.parameterWidget.spinBox_poisson_ratio
if value:
if not (1 - variation < float(old_pr) / value < 1 + variation):
# PoissonRatio has changed
material = self.material
material["PoissonRatio"] = unicode(value)
self.material = material
if self.has_transient_mat is False:
self.add_transient_material()
else:
self.set_transient_material()
variation = 0.001
self.update_material_property(input_field, "PoissonRatio", "", variation)
elif value == 0:
# PoissonRatio was set to 0.0 what is possible
material = self.material
Expand All @@ -620,89 +590,28 @@ def pr_changed(self):

# thermal input fields
def tc_changed(self):
value = self.parameterWidget.input_fd_thermal_conductivity.property("rawValue")
old_tc = Units.Quantity(self.material["ThermalConductivity"]).getValueAs("W/m/K")
input_field = self.parameterWidget.input_fd_thermal_conductivity
variation = 0.001
if value:
if not (1 - variation < float(old_tc) / value < 1 + variation):
# ThermalConductivity has changed
material = self.material
value_in_W_per_mK = value * 1e-3 # To compensate for use of SI units
material["ThermalConductivity"] = unicode(value_in_W_per_mK) + " W/m/K"
self.material = material
if self.has_transient_mat is False:
self.add_transient_material()
else:
self.set_transient_material()
self.update_material_property(input_field, "ThermalConductivity", "W/m/K", variation)

def tec_changed(self):
value = self.parameterWidget.input_fd_expansion_coefficient.property("rawValue")
old_tec = Units.Quantity(
self.material["ThermalExpansionCoefficient"]
).getValueAs("um/m/K")
input_field = self.parameterWidget.input_fd_expansion_coefficient
variation = 0.001
if value:
if not (1 - variation < float(old_tec) / value < 1 + variation):
# ThermalExpansionCoefficient has changed
material = self.material
value_in_um_per_mK = value * 1e6 # To compensate for use of SI units
material["ThermalExpansionCoefficient"] = unicode(value_in_um_per_mK) + " um/m/K"
self.material = material
if self.has_transient_mat is False:
self.add_transient_material()
else:
self.set_transient_material()
self.update_material_property(input_field, "ThermalExpansionCoefficient", "um/m/K", variation)

def sh_changed(self):
value = self.parameterWidget.input_fd_specific_heat.property("rawValue")
old_sh = Units.Quantity(self.material["SpecificHeat"]).getValueAs("J/kg/K")
input_field = self.parameterWidget.input_fd_specific_heat
variation = 0.001
if value:
if not (1 - variation < float(old_sh) / value < 1 + variation):
# SpecificHeat has changed
material = self.material
value_in_J_per_kgK = value * 1e-6 # To compensate for use of SI units
material["SpecificHeat"] = unicode(value_in_J_per_kgK) + " J/kg/K"
self.material = material
if self.has_transient_mat is False:
self.add_transient_material()
else:
self.set_transient_material()
self.update_material_property(input_field, "SpecificHeat", "J/kg/K", variation)

# fluidic input fields
def vtec_changed(self):
value = self.parameterWidget.input_fd_vol_expansion_coefficient.property("rawValue")
old_vtec = Units.Quantity(
self.material["VolumetricThermalExpansionCoefficient"]
).getValueAs("m/m/K")
variation = 0.001
if value:
if not (1 - variation < float(old_vtec) / value < 1 + variation):
# VolumetricThermalExpansionCoefficient has changed
material = self.material
value_in_one_per_K = unicode(value) + " m^3/m^3/K"
material["VolumetricThermalExpansionCoefficient"] = value_in_one_per_K
self.material = material
if self.has_transient_mat is False:
self.add_transient_material()
else:
self.set_transient_material()
input_field = self.parameterWidget.input_fd_vol_expansion_coefficient
self.update_material_property(input_field, "VolumetricThermalExpansionCoefficient", "m^3/m^3/K")

def kinematic_viscosity_changed(self):
value = self.parameterWidget.input_fd_kinematic_viscosity.property("rawValue")
old_nu = Units.Quantity(self.material["KinematicViscosity"]).getValueAs("m^2/s")
variation = 0.000001
if value:
if not (1 - variation < float(old_nu) / value < 1 + variation):
# KinematicViscosity has changed
material = self.material
value_in_m2_per_second = value
material["KinematicViscosity"] = unicode(value_in_m2_per_second) + " m^2/s"
self.material = material
if self.has_transient_mat is False:
self.add_transient_material()
else:
self.set_transient_material()
input_field = self.parameterWidget.input_fd_kinematic_viscosity
self.update_material_property(input_field, "KinematicViscosity", "m^2/s")

def set_mat_params_in_input_fields(self, matmap):
if "YoungsModulus" in matmap:
Expand Down

0 comments on commit ee440be

Please sign in to comment.