Fem: modify taskpanelFemMaterial to support simple Fluid Material

This commit is contained in:
qingfengxia 2017-01-18 23:32:40 +00:00
parent 61fb3d429a
commit a378a16b27
4 changed files with 210 additions and 110 deletions

View File

@ -56,4 +56,5 @@ def makeFluidMaterial(name):
# FreeCAD.ActiveDocument.recompute()
return obj
makeFemMaterial = makeSolidMaterial # alias to be compatible for FemTest.py
# @}

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>396</width>
<height>790</height>
<height>834</height>
</rect>
</property>
<property name="windowTitle">
@ -15,7 +15,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="GroupQuantities_2">
<widget class="QGroupBox" name="groupBox_desc">
<property name="maximumSize">
<size>
<width>16777215</width>
@ -28,21 +28,14 @@
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="2">
<widget class="QRadioButton" name="radioButton">
<item row="1" column="1">
<widget class="QLabel" name="label_category">
<property name="text">
<string>Fluid</string>
<string/>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="radioButton_2">
<property name="text">
<string>Solid</string>
</property>
</widget>
</item>
<item row="0" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Category</string>
@ -74,7 +67,7 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_1">
<widget class="QGroupBox" name="groupBox_references">
<property name="title">
<string>References</string>
</property>
@ -128,7 +121,7 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="GroupQuantities_24">
<widget class="QGroupBox" name="groupBox_basic">
<property name="maximumSize">
<size>
<width>16777215</width>
@ -144,51 +137,24 @@
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_26">
<item row="3" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Name:</string>
<string>Density</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::InputField" name="input_fd_name">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>20</height>
</size>
</property>
<item row="2" column="0">
<widget class="QPushButton" name="pushButton_saveas">
<property name="text">
<string>steel</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="singleStep" stdset="0">
<double>2.000000000000000</double>
</property>
<property name="maximum" stdset="0">
<double>2000000000.000000000000000</double>
</property>
<property name="unit" stdset="0">
<string notr="true">Pa</string>
</property>
<property name="decimals" stdset="0">
<number>3</number>
</property>
<property name="value" stdset="0">
<double>0.000000000000000</double>
<string>save as name</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QLineEdit" name="edit_name"/>
</item>
<item row="3" column="1">
<widget class="Gui::InputField" name="input_fd_density">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -225,20 +191,13 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Density</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="GroupQuantities_4">
<widget class="QGroupBox" name="groupBox_mechanical">
<property name="maximumSize">
<size>
<width>16777215</width>
@ -342,7 +301,7 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="GroupQuantities_14">
<widget class="QGroupBox" name="groupBox_fluidic">
<property name="maximumSize">
<size>
<width>16777215</width>
@ -361,12 +320,12 @@
<item row="0" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Kinetic viscosity:</string>
<string>Kinematic viscosity:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::InputField" name="input_fd_kinetic_viscosity">
<widget class="Gui::InputField" name="input_fd_kinematic_viscosity">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -380,22 +339,22 @@
</size>
</property>
<property name="text">
<string>0.000001</string>
<string>0.000001 m^2/s</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="singleStep" stdset="0">
<double>2.000000000000000</double>
<double>0.000001000000000</double>
</property>
<property name="maximum" stdset="0">
<double>2000000000.000000000000000</double>
<double>1000.000000000000000</double>
</property>
<property name="unit" stdset="0">
<string notr="true">Pa</string>
<string notr="true">m^2/s</string>
</property>
<property name="decimals" stdset="0">
<number>3</number>
<number>6</number>
</property>
<property name="value" stdset="0">
<double>0.000000000000000</double>
@ -408,7 +367,7 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="GroupQuantities_5">
<widget class="QGroupBox" name="groupBox_thermal">
<property name="maximumSize">
<size>
<width>16777215</width>
@ -431,8 +390,45 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::InputField" name="input_fd_thermal_conductivity">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>20</height>
</size>
</property>
<property name="text">
<string>50 W/m/K</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="singleStep" stdset="0">
<double>2.000000000000000</double>
</property>
<property name="maximum" stdset="0">
<double>2000000000.000000000000000</double>
</property>
<property name="unit" stdset="0">
<string notr="true">W/m/K</string>
</property>
<property name="decimals" stdset="0">
<number>3</number>
</property>
<property name="value" stdset="0">
<double>0.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_13">
<widget class="QLabel" name="label_expansion_coefficient">
<property name="text">
<string>Expansion Coefficient:</string>
</property>
@ -519,8 +515,15 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::InputField" name="input_fd_thermal_conductivity">
<item row="3" column="0">
<widget class="QLabel" name="label_vol_expansion_coefficient">
<property name="text">
<string>Vol Expansion Coeff</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="Gui::InputField" name="input_fd_vol_expansion_coefficient">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -534,22 +537,22 @@
</size>
</property>
<property name="text">
<string>50 W/m/K</string>
<string>0.001 m/m/K</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="singleStep" stdset="0">
<double>2.000000000000000</double>
<double>0.001000000000000</double>
</property>
<property name="maximum" stdset="0">
<double>2000000000.000000000000000</double>
<double>1.000000000000000</double>
</property>
<property name="unit" stdset="0">
<string notr="true">W/m/K</string>
<string notr="true">m/m/K</string>
</property>
<property name="decimals" stdset="0">
<number>3</number>
<number>6</number>
</property>
<property name="value" stdset="0">
<double>0.000000000000000</double>
@ -562,7 +565,7 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="GroupQuantities_3">
<widget class="QGroupBox" name="groupBox_external">
<property name="maximumSize">
<size>
<width>16777215</width>

View File

@ -32,8 +32,8 @@ class _FemMaterial:
"The FEM Material object"
def __init__(self, obj):
obj.addProperty("App::PropertyLinkSubList", "References", "Material", "List of material shapes")
obj.addProperty("App::PropertyEnum", "Category", "Material", "Material type: fluid or solid")
obj.Category = ['Solid', 'Fluid']
obj.addProperty("App::PropertyEnumeration", "Category", "Material", "Material type: fluid or solid")
obj.Category = ['Solid', 'Fluid'] # used in TaskPanel
obj.Proxy = self
self.Type = "FemMaterial"

View File

@ -21,7 +21,7 @@
# ***************************************************************************
__title__ = "_TaskPanelFemMaterial"
__author__ = "Juergen Riegel, Bernd Hahnebach"
__author__ = "Juergen Riegel, Bernd Hahnebach, Qingfeng Xia"
__url__ = "http://www.freecadweb.org"
## @package TaskPanelFemMaterial
@ -52,16 +52,34 @@ class _TaskPanelFemMaterial:
self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Fem/TaskPanelFemMaterial.ui")
QtCore.QObject.connect(self.form.pushButton_MatWeb, QtCore.SIGNAL("clicked()"), self.goMatWeb)
QtCore.QObject.connect(self.form.pushButton_saveas, QtCore.SIGNAL("clicked()"), self.saveas_material)
QtCore.QObject.connect(self.form.cb_materials, QtCore.SIGNAL("activated(int)"), self.choose_material)
QtCore.QObject.connect(self.form.input_fd_young_modulus, QtCore.SIGNAL("valueChanged(double)"), self.ym_changed)
QtCore.QObject.connect(self.form.spinBox_poisson_ratio, QtCore.SIGNAL("valueChanged(double)"), self.pr_changed)
QtCore.QObject.connect(self.form.input_fd_density, QtCore.SIGNAL("valueChanged(double)"), self.density_changed)
QtCore.QObject.connect(self.form.pushButton_Reference, QtCore.SIGNAL("clicked()"), self.add_references)
QtCore.QObject.connect(self.form.rb_standard, QtCore.SIGNAL("toggled(bool)"), self.choose_selection_mode_standard)
QtCore.QObject.connect(self.form.rb_solid, QtCore.SIGNAL("toggled(bool)"), self.choose_selection_mode_solid)
# basic properties must be provided
QtCore.QObject.connect(self.form.input_fd_density, QtCore.SIGNAL("valueChanged(double)"), self.density_changed)
# mechanical properties
QtCore.QObject.connect(self.form.input_fd_young_modulus, QtCore.SIGNAL("valueChanged(double)"), self.ym_changed)
QtCore.QObject.connect(self.form.spinBox_poisson_ratio, QtCore.SIGNAL("valueChanged(double)"), self.pr_changed)
# thermal properties
QtCore.QObject.connect(self.form.input_fd_thermal_conductivity, QtCore.SIGNAL("valueChanged(double)"), self.tc_changed)
QtCore.QObject.connect(self.form.input_fd_expansion_coefficient, QtCore.SIGNAL("valueChanged(double)"), self.tec_changed)
QtCore.QObject.connect(self.form.input_fd_specific_heat, QtCore.SIGNAL("valueChanged(double)"), self.sh_changed)
# fluidic properties, only volumetric thermal expansion coeff makes sense
QtCore.QObject.connect(self.form.input_fd_kinematic_viscosity, QtCore.SIGNAL("valueChanged(double)"), self.kinematic_viscosity_changed)
QtCore.QObject.connect(self.form.input_fd_vol_expansion_coefficient, QtCore.SIGNAL("valueChanged(double)"), self.vtec_changed)
# hide some groupBox according to material category
self.form.label_category.setText(self.obj.Category)
if self.obj.Category == 'Fluid':
self.form.groupBox_mechanical.setVisible(0)
self.form.label_expansion_coefficient.setVisible(0)
self.form.input_fd_expansion_coefficient.setVisible(0)
else:
self.form.groupBox_fluidic.setVisible(0)
self.form.label_vol_expansion_coefficient.setVisible(0)
self.form.input_fd_vol_expansion_coefficient.setVisible(0)
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)
@ -141,15 +159,26 @@ class _TaskPanelFemMaterial:
webbrowser.open("http://matweb.com")
def check_material_keys(self):
if 'YoungsModulus' not in self.material:
print('YoungsModulus not found in material data of: ' + self.material['Name'])
self.material['YoungsModulus'] = '0 MPa'
if 'Density' not in self.material:
print('Density not found in material data of: ' + self.material['Name'])
self.material['Density'] = '0 kg/m^3'
if 'PoissonRatio' not in self.material:
print('PoissonRatio not found in material data of: ' + self.material['Name'])
self.material['PoissonRatio'] = '0'
if self.obj.Category == 'Solid':
# mechanical properties
if 'YoungsModulus' not in self.material:
print('YoungsModulus not found in material data of: ' + self.material['Name'])
self.material['YoungsModulus'] = '0 MPa'
if 'PoissonRatio' not in self.material:
print('PoissonRatio not found in material data of: ' + self.material['Name'])
self.material['PoissonRatio'] = '0'
if self.obj.Category == 'Fluid':
# Fluidic properties
if 'KinematicViscosity' not in self.material:
print('KinematicViscosity not found in material data of: ' + self.material['Name'])
self.material['KineticViscosity'] = '0 m^2/s'
if 'VolumetricThermalExpansionCoefficient' not in self.material:
print('VolumetricThermalExpansionCoefficient not found in material data of: ' + self.material['Name'])
self.material['VolumetricThermalExpansionCoefficient'] = '0 m/m/K'
# Thermal properties
if 'ThermalConductivity' not in self.material:
print('ThermalConductivity not found in material data of: ' + self.material['Name'])
self.material['ThermalConductivity'] = '0 W/m/K'
@ -159,6 +188,7 @@ class _TaskPanelFemMaterial:
if 'SpecificHeat' not in self.material:
print('SpecificHeat not found in material data of: ' + self.material['Name'])
self.material['SpecificHeat'] = '0 J/kg/K'
# Electromagnetic properties
def ym_changed(self, value):
# FreeCADs standard unit for stress is kPa
@ -226,6 +256,29 @@ class _TaskPanelFemMaterial:
material['SpecificHeat'] = unicode(value_in_J_per_kgK) + " J/kg/K"
self.material = material
################ fluidic #########################
def vtec_changed(self, value):
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 = value * 1e6 # To compensate for use of SI units
material['VolumetricThermalExpansionCoefficient'] = unicode(value_in_one_per_K) + " m/m/K"
self.material = material
def kinematic_viscosity_changed(self, value):
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 * 1e6 # To compensate for use of SI units
material['KinematicViscosity'] = unicode(value_in_m2_per_second) + " m^2/s"
self.material = material
def choose_material(self, index):
if index < 0:
return
@ -260,17 +313,31 @@ class _TaskPanelFemMaterial:
self.form.input_fd_young_modulus.setText("{} {}".format(ym_with_new_unit, ym_new_unit))
if 'PoissonRatio' in matmap:
self.form.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_with_new_unit = nu.getValueAs(nu_new_unit)
self.form.input_fd_kinematic_viscosity.setText("{} {}".format(nu_with_new_unit, nu_new_unit))
# For isotropic materials the volumetric thermal expansion coefficient is three times the linear coefficient:
if 'VolumetricThermalExpansionCoefficient' in matmap: # linear, only for solid
vtec_new_unit = "m/m/K"
vtec = FreeCAD.Units.Quantity(matmap['VolumetricThermalExpansionCoefficient'])
vtec_with_new_unit = vtec.getValueAs(vtec_new_unit)
self.form.input_fd_vol_expansion_coefficient.setText("{} {}".format(vtec_with_new_unit, vtec_new_unit))
if 'Density' in matmap:
density_new_unit = "kg/m^3"
density = FreeCAD.Units.Quantity(matmap['Density'])
density_with_new_unit = density.getValueAs(density_new_unit)
self.form.input_fd_density.setText("{} {}".format(density_with_new_unit, density_new_unit))
# thermal properties
if 'ThermalConductivity' in matmap:
tc_new_unit = "W/m/K"
tc = FreeCAD.Units.Quantity(matmap['ThermalConductivity'])
tc_with_new_unit = tc.getValueAs(tc_new_unit)
self.form.input_fd_thermal_conductivity.setText("{} {}".format(tc_with_new_unit, tc_new_unit))
if 'ThermalExpansionCoefficient' in matmap:
if 'ThermalExpansionCoefficient' in matmap: # linear, only for solid
tec_new_unit = "um/m/K"
tec = FreeCAD.Units.Quantity(matmap['ThermalExpansionCoefficient'])
tec_with_new_unit = tec.getValueAs(tec_new_unit)
@ -286,6 +353,49 @@ class _TaskPanelFemMaterial:
self.form.cb_materials.addItem(QtGui.QIcon(":/icons/help-browser.svg"), material_name, material_name)
self.materials[material_name] = material
def import_materials(self):
self.materials = {}
self.pathList = []
self.form.cb_materials.clear()
self.fem_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/General")
if self.obj.Category == 'Fluid':
self.import_fluid_materials()
else:
self.import_solid_materials()
def import_solid_materials(self):
use_built_in_materials = self.fem_prefs.GetBool("UseBuiltInMaterials", True)
if use_built_in_materials:
system_mat_dir = FreeCAD.getResourceDir() + "/Mod/Material/StandardMaterial"
self.add_mat_dir(system_mat_dir, ":/icons/freecad.svg")
use_mat_from_config_dir = self.fem_prefs.GetBool("UseMaterialsFromConfigDir", True)
if use_mat_from_config_dir:
user_mat_dirname = FreeCAD.getUserAppDataDir() + "Materials"
self.add_mat_dir(user_mat_dirname, ":/icons/preferences-general.svg")
use_mat_from_custom_dir = self.fem_prefs.GetBool("UseMaterialsFromCustomDir", True)
if use_mat_from_custom_dir:
custom_mat_dir = self.fem_prefs.GetString("CustomMaterialsDir", "")
self.add_mat_dir(custom_mat_dir, ":/icons/user.svg")
def import_fluid_materials(self):
#use_built_in_materials = self.fem_prefs.GetBool("UseBuiltInMaterials", True)
#if use_built_in_materials:
system_mat_dir = FreeCAD.getResourceDir() + "/Mod/Material/FluidMaterial"
self.add_mat_dir(system_mat_dir, ":/icons/freecad.svg")
use_mat_from_config_dir = self.fem_prefs.GetBool("UseMaterialsFromConfigDir", True)
if use_mat_from_config_dir:
user_mat_dirname = FreeCAD.getUserAppDataDir() + "Materials"
self.add_mat_dir(user_mat_dirname, ":/icons/preferences-general.svg")
use_mat_from_custom_dir = self.fem_prefs.GetBool("UseMaterialsFromCustomDir", True)
if use_mat_from_custom_dir:
custom_mat_dir = self.fem_prefs.GetString("CustomMaterialsDir", "")
self.add_mat_dir(custom_mat_dir, ":/icons/user.svg")
def add_mat_dir(self, mat_dir, icon):
import glob
import os
@ -303,26 +413,12 @@ class _TaskPanelFemMaterial:
for mat in material_name_list:
self.form.cb_materials.addItem(QtGui.QIcon(icon), mat[0], mat[1])
def import_materials(self):
self.materials = {}
self.pathList = []
self.form.cb_materials.clear()
self.fem_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/General")
use_built_in_materials = self.fem_prefs.GetBool("UseBuiltInMaterials", True)
if use_built_in_materials:
system_mat_dir = FreeCAD.getResourceDir() + "/Mod/Material/StandardMaterial"
self.add_mat_dir(system_mat_dir, ":/icons/freecad.svg")
use_mat_from_config_dir = self.fem_prefs.GetBool("UseMaterialsFromConfigDir", True)
if use_mat_from_config_dir:
user_mat_dirname = FreeCAD.getUserAppDataDir() + "Materials"
self.add_mat_dir(user_mat_dirname, ":/icons/preferences-general.svg")
use_mat_from_custom_dir = self.fem_prefs.GetBool("UseMaterialsFromCustomDir", True)
if use_mat_from_custom_dir:
custom_mat_dir = self.fem_prefs.GetString("CustomMaterialsDir", "")
self.add_mat_dir(custom_mat_dir, ":/icons/user.svg")
def saveas_material(self):
import Material
mat_file_extension = ".FCMat"
# overwritinig warning, save to customed dir, material name check
###################geometry reference selection #################
def references_list_right_clicked(self, QPos):
self.form.contextMenu = QtGui.QMenu()
menu_item = self.form.contextMenu.addAction("Remove Reference")