Merge pull request #453 from qingfengxia/fluidmaterial

add air and water Fluidmaterial to FemWorkbench
This commit is contained in:
wwmayer 2017-01-19 11:04:40 +01:00 committed by GitHub
commit 2a67c7f0ae
15 changed files with 475 additions and 74 deletions

View File

@ -68,7 +68,8 @@ SET(FemScripts_SRCS
_CommandConstraintSelfWeight.py
_CommandFEMMesh2Mesh.py
_CommandMaterialMechanicalNonlinear.py
_CommandMaterial.py
_CommandMaterialSolid.py
_CommandMaterialFluid.py
_CommandMeshGmshFromShape.py
_CommandMeshNetgenFromShape.py
_CommandMeshGroup.py

View File

@ -91,7 +91,8 @@ INSTALL(
FemMaterial.py
_FemMaterial.py
_ViewProviderFemMaterial.py
_CommandMaterial.py
_CommandMaterialSolid.py
_CommandMaterialFluid.py
_TaskPanelFemMaterial.py
TaskPanelFemMaterial.ui

View File

@ -31,15 +31,30 @@ import FreeCAD
import _FemMaterial
def makeFemMaterial(name):
'''makeFemMaterial(name): makes an FEM Material
def makeSolidMaterial(name):
'''makeSolidMaterial(name): makes an FEM Material for solid
'''
obj = FreeCAD.ActiveDocument.addObject("App::MaterialObjectPython", name)
_FemMaterial._FemMaterial(obj)
obj.Category = 'Solid'
if FreeCAD.GuiUp:
import _ViewProviderFemMaterial
_ViewProviderFemMaterial._ViewProviderFemMaterial(obj.ViewObject)
# FreeCAD.ActiveDocument.recompute()
return obj
def makeFluidMaterial(name):
'''makeFluidMaterial(name): makes an FEM Material for fluid
'''
obj = FreeCAD.ActiveDocument.addObject("App::MaterialObjectPython", name)
_FemMaterial._FemMaterial(obj)
obj.Category = 'Fluid'
if FreeCAD.GuiUp:
import _ViewProviderFemMaterial
_ViewProviderFemMaterial._ViewProviderFemMaterial(obj.ViewObject)
# FreeCAD.ActiveDocument.recompute()
return obj
makeFemMaterial = makeSolidMaterial # alias to be compatible for FemTest.py
# @}

View File

@ -74,7 +74,8 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
<< "Fem_MeshGroup"
//<< "Fem_CreateNodesSet"
<< "Separator"
<< "Fem_Material"
<< "Fem_MaterialSolid"
<< "Fem_MaterialFluid"
<< "Fem_MaterialMechanicalNonlinear"
<< "Fem_BeamSection"
<< "Fem_ShellThickness"
@ -147,7 +148,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const
<< "Fem_MeshGroup"
<< "Fem_CreateNodesSet"
<< "Separator"
<< "Fem_Material"
<< "Fem_MaterialSolid"
<< "Fem_MaterialFluid"
<< "Fem_MaterialMechanicalNonlinear"
<< "Fem_BeamSection"
<< "Fem_ShellThickness"

View File

@ -59,7 +59,8 @@ class FemWorkbench (Workbench):
import _CommandAnalysis
import _CommandShellThickness
import _CommandBeamSection
import _CommandMaterial
import _CommandMaterialSolid
import _CommandMaterialFluid
import _CommandMaterialMechanicalNonlinear
import _CommandSolverCalculix
import _CommandSolverZ88

216
src/Mod/Fem/TaskPanelFemMaterial.ui Normal file → Executable file
View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>370</width>
<height>700</height>
<width>396</width>
<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>
@ -26,6 +26,24 @@
<string>Material</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1">
<widget class="QLabel" name="label_category">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Category</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QComboBox" name="cb_materials">
<item>
@ -49,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>
@ -86,7 +104,7 @@
<item row="1" column="2">
<widget class="QRadioButton" name="rb_solid">
<property name="text">
<string>Solid</string>
<string>Body (3D)</string>
</property>
</widget>
</item>
@ -103,7 +121,7 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="GroupQuantities_4">
<widget class="QGroupBox" name="groupBox_basic">
<property name="maximumSize">
<size>
<width>16777215</width>
@ -111,7 +129,83 @@
</size>
</property>
<property name="title">
<string>Material Properties</string>
<string>Basic Properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_27">
<item>
<layout class="QFormLayout" name="formLayout_20">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="3" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Density</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="pushButton_saveas">
<property name="text">
<string>save as name</string>
</property>
</widget>
</item>
<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">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>20</height>
</size>
</property>
<property name="text">
<string>8000 kg/m^3</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">kg/m^3</string>
</property>
<property name="decimals" stdset="0">
<number>3</number>
</property>
<property name="value" stdset="0">
<double>0.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_mechanical">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>1677215</height>
</size>
</property>
<property name="title">
<string>Mechanical Properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
@ -201,15 +295,37 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_8">
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_fluidic">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>1677215</height>
</size>
</property>
<property name="title">
<string>Fluidic Properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
<item>
<layout class="QFormLayout" name="formLayout_10">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Density</string>
<string>Kinematic viscosity:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::InputField" name="input_fd_density">
<item row="0" column="1">
<widget class="Gui::InputField" name="input_fd_kinematic_viscosity">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -223,22 +339,22 @@
</size>
</property>
<property name="text">
<string>8000 kg/m^3</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">kg/m^3</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>
@ -251,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>
@ -259,7 +375,7 @@
</size>
</property>
<property name="title">
<string>Temperature-Dependant Material Properties</string>
<string>Thermal Properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
@ -274,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>
@ -362,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>
@ -377,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>
@ -405,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

@ -20,7 +20,7 @@
# * *
# ***************************************************************************
__title__ = "_CommandMaterial"
__title__ = "_CommandFluidMaterial"
__author__ = "Juergen Riegel, Bernd Hahnebach"
__url__ = "http://www.freecadweb.org"
@ -34,25 +34,25 @@ import FemGui
from PySide import QtCore
class _CommandMaterial(FemCommands):
"the Fem_Material command definition"
class _CommandMaterialFluid(FemCommands):
"the Fem_MaterialFluid command definition"
def __init__(self):
super(_CommandMaterial, self).__init__()
super(_CommandMaterialFluid, self).__init__()
self.resources = {'Pixmap': 'fem-material',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_Material", "FEM material"),
'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_MaterialFluid", "FEM material for Fluid"),
'Accel': "M, M",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_Material", "Creates a FEM material")}
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_MaterialFluid", "Creates a FEM material for Fluid")}
self.is_active = 'with_analysis'
def Activated(self):
femDoc = FemGui.getActiveAnalysis().Document
if FreeCAD.ActiveDocument is not femDoc:
FreeCADGui.setActiveDocument(femDoc)
FreeCAD.ActiveDocument.openTransaction("Create Material")
FreeCAD.ActiveDocument.openTransaction("Create Fluid Material")
FreeCADGui.addModule("FemMaterial")
FreeCADGui.doCommand("FemMaterial.makeFemMaterial('FemMaterial')")
FreeCADGui.doCommand("FemMaterial.makeFluidMaterial('FluidMaterial')")
FreeCADGui.doCommand("App.activeDocument()." + FemGui.getActiveAnalysis().Name + ".Member = App.activeDocument()." + FemGui.getActiveAnalysis().Name + ".Member + [App.ActiveDocument.ActiveObject]")
FreeCADGui.doCommand("Gui.activeDocument().setEdit(App.ActiveDocument.ActiveObject.Name)")
FreeCADGui.addCommand('Fem_Material', _CommandMaterial())
FreeCADGui.addCommand('Fem_MaterialFluid', _CommandMaterialFluid())

View File

@ -0,0 +1,58 @@
# ***************************************************************************
# * *
# * Copyright (c) 2013 - Juergen Riegel <FreeCAD@juergen-riegel.net> *
# * *
# * 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__ = "_CommandSolidMaterial"
__author__ = "Juergen Riegel, Bernd Hahnebach"
__url__ = "http://www.freecadweb.org"
## @package CommandMaterial
# \ingroup FEM
import FreeCAD
from FemCommands import FemCommands
import FreeCADGui
import FemGui
from PySide import QtCore
class _CommandMaterialSolid(FemCommands):
"the Fem_MaterialSolid command definition"
def __init__(self):
super(_CommandMaterialSolid, self).__init__()
self.resources = {'Pixmap': 'fem-material',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_MaterialSolid", "FEM material for solid"),
'Accel': "M, M",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_MaterialSolid", "Creates a FEM material for solid")}
self.is_active = 'with_analysis'
def Activated(self):
femDoc = FemGui.getActiveAnalysis().Document
if FreeCAD.ActiveDocument is not femDoc:
FreeCADGui.setActiveDocument(femDoc)
FreeCAD.ActiveDocument.openTransaction("Create Solid Material")
FreeCADGui.addModule("FemMaterial")
FreeCADGui.doCommand("FemMaterial.makeSolidMaterial('SolidMaterial')")
FreeCADGui.doCommand("App.activeDocument()." + FemGui.getActiveAnalysis().Name + ".Member = App.activeDocument()." + FemGui.getActiveAnalysis().Name + ".Member + [App.ActiveDocument.ActiveObject]")
FreeCADGui.doCommand("Gui.activeDocument().setEdit(App.ActiveDocument.ActiveObject.Name)")
FreeCADGui.addCommand('Fem_MaterialSolid', _CommandMaterialSolid())

View File

@ -32,6 +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::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
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
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")

View File

@ -27,6 +27,14 @@ SET (MaterialLib_Files
)
SOURCE_GROUP("MatLib" FILES ${MaterialLib_Files})
SET (FluidMaterial_Files
FluidMaterial/None.FCMat
FluidMaterial/Air.FCMat
FluidMaterial/Water.FCMat
FluidMaterial/Readme.txt
)
SOURCE_GROUP("MatLib" FILES ${FluidMaterial_Files})
ADD_CUSTOM_TARGET(Material ALL
SOURCES ${Material_SRCS} ${Material_QRC_SRCS}
)
@ -46,6 +54,9 @@ ENDIF (BUILD_GUI)
ADD_CUSTOM_TARGET(MaterialLib ALL
SOURCES ${MaterialLib_Files}
)
ADD_CUSTOM_TARGET(FluidMaterialLib ALL
SOURCES ${FluidMaterial_Files}
)
# When a target copies files to different output directories then apparently it always builds the project
# which is very annoying. So, the trick is to split this into two targets to avoid this behaviour.
@ -53,6 +64,10 @@ fc_target_copy_resource(MaterialLib
${CMAKE_SOURCE_DIR}/src/Mod/Material
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/Material
${MaterialLib_Files})
fc_target_copy_resource(FluidMaterialLib
${CMAKE_SOURCE_DIR}/src/Mod/Material
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/Material
${FluidMaterial_Files})
INSTALL(
FILES ${Material_SRCS} ${Material_QRC_SRCS}
@ -62,6 +77,8 @@ INSTALL(
INSTALL(
DIRECTORY
StandardMaterial
DIRECTORY
FluidMaterial
DESTINATION
${CMAKE_INSTALL_DATADIR}/Mod/Material
FILES_MATCHING PATTERN "*.FCMat*"

View File

@ -0,0 +1,15 @@
[FCMat]
Name = Air
Description = Standard air properties at 20 Degrees Celsius and 1 atm
MolarMass = 28.965
Density = 1.20 kg/m^3
DynamicViscosity = 1.80e-5 kg/m/s
KinematicViscosity = 1.511e-5 m^2/s
VolumetricThermalExpansionCoefficient = 3.43e-3 m/m/K
PrandtlNumber = 0.7
SpecificHeat = 1.005 J/kg/K
ThermalConductivity = 0.0257 W/m/K

View File

@ -0,0 +1,12 @@
[FCdMat]
Name = None
Description = None
Density = 0 kg/m^3
DynamicViscosity = 0 kg/m/s
KinematicViscosity = 0 m^2/s
VolumetricExpansionCoefficient = 0 m/m/K
SpecificHeat = 0 J/kg/K
ThermalConductivity = 0 W/m/K
ThermalExpansionCoefficient = 0 um/m/K

View File

@ -0,0 +1,7 @@
This is the FreeCAD simple fluid material library
data is taken from matweb
currently only water and air at the standard condition (20C and 1 atm) is prepared for testing
CSIR team is working on CfdFluidMaterial in CFD workbench to support more complex fluid material

View File

@ -0,0 +1,14 @@
[FCdMat]
Name = Water
Description = Standard distilled water properties at 20 Degrees Celsius and 1 atm
MolarMass = 18
Density = 998 kg/m^3
DynamicViscosity = 1.003e-3 kg/m/s
KinematicViscosity = 1.005 m^2/s
VolumetricExpansionCoefficient = 2.07e-4 m/m/K
SpecificHeat = 4.182 J/kg/K
ThermalConductivity = 0.591 W/m/K