From 9cbefbd905d053b1401eb497667050777b1a75a0 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Sat, 6 Aug 2016 21:46:38 +0200 Subject: [PATCH] FEM: materials: simplify input writing and add pre checks for material value keys --- src/Mod/Fem/FemInputWriterCcx.py | 78 +++++++------------ src/Mod/Fem/FemTools.py | 27 ++++++- src/Mod/Fem/test_files/ccx/cube_frequency.inp | 10 +-- src/Mod/Fem/test_files/ccx/cube_static.inp | 13 +--- .../Fem/test_files/ccx/spine_thermomech.inp | 5 +- 5 files changed, 56 insertions(+), 77 deletions(-) diff --git a/src/Mod/Fem/FemInputWriterCcx.py b/src/Mod/Fem/FemInputWriterCcx.py index 2d08724b3..9f02a4583 100644 --- a/src/Mod/Fem/FemInputWriterCcx.py +++ b/src/Mod/Fem/FemInputWriterCcx.py @@ -262,62 +262,44 @@ class FemInputWriterCcx(FemInputWriter.FemInputWriter): f.write('** Materials\n') f.write('** written by {} function\n'.format(sys._getframe().f_code.co_name)) f.write('** Young\'s modulus unit is MPa = N/mm2\n') - f.write('** Density\'s unit is t/mm^3\n') - f.write('** Thermal conductivity unit is kW/mm/K = t*mm/K*s^3\n') - f.write('** Specific Heat unit is kJ/t/K = mm^2/s^2/K\n') + if self.analysis_type == "frequency" or self.selfweight_objects: + f.write('** Density\'s unit is t/mm^3\n') + if self.analysis_type == "thermomech": + f.write('** Thermal conductivity unit is kW/mm/K = t*mm/K*s^3\n') + f.write('** Specific Heat unit is kJ/t/K = mm^2/s^2/K\n') for femobj in self.material_objects: # femobj --> dict, FreeCAD document object is femobj['Object'] mat_obj = femobj['Object'] - # get material properties - Currently in SI units: M/kg/s/Kelvin - YM_in_MPa = 1 - TC_in_WmK = 1 - TEC_in_mmK = 1 - SH_in_JkgK = 1 - PR = 1 - density_in_tonne_per_mm3 = 1 - try: - YM = FreeCAD.Units.Quantity(mat_obj.Material['YoungsModulus']) - YM_in_MPa = float(YM.getValueAs('MPa')) - except: - FreeCAD.Console.PrintError("No YoungsModulus defined for material: default used\n") - try: - PR = float(mat_obj.Material['PoissonRatio']) - except: - FreeCAD.Console.PrintError("No PoissonRatio defined for material: default used\n") - try: - TC = FreeCAD.Units.Quantity(mat_obj.Material['ThermalConductivity']) - TC_in_WmK = float(TC.getValueAs('W/m/K')) # SvdW: Add factor to force units to results' base units of t/mm/s/K - W/m/K results in no factor needed - except: - FreeCAD.Console.PrintError("No ThermalConductivity defined for material: default used\n") - try: - TEC = FreeCAD.Units.Quantity(mat_obj.Material['ThermalExpansionCoefficient']) - TEC_in_mmK = float(TEC.getValueAs('mm/mm/K')) - except: - FreeCAD.Console.PrintError("No ThermalExpansionCoefficient defined for material: default used\n") - try: - SH = FreeCAD.Units.Quantity(mat_obj.Material['SpecificHeat']) - SH_in_JkgK = float(SH.getValueAs('J/kg/K')) * 1e+06 # SvdW: Add factor to force units to results' base units of t/mm/s/K - except: - FreeCAD.Console.PrintError("No SpecificHeat defined for material: default used\n") mat_info_name = mat_obj.Material['Name'] mat_name = mat_obj.Name + # get material properties, Currently in SI units: M/kg/s/Kelvin + YM = FreeCAD.Units.Quantity(mat_obj.Material['YoungsModulus']) + YM_in_MPa = float(YM.getValueAs('MPa')) + PR = float(mat_obj.Material['PoissonRatio']) + if self.analysis_type == "frequency" or self.selfweight_objects: + density = FreeCAD.Units.Quantity(mat_obj.Material['Density']) + density_in_tonne_per_mm3 = float(density.getValueAs('t/mm^3')) + if self.analysis_type == "thermomech": + TC = FreeCAD.Units.Quantity(mat_obj.Material['ThermalConductivity']) + TC_in_WmK = float(TC.getValueAs('W/m/K')) # SvdW: Add factor to force units to results' base units of t/mm/s/K - W/m/K results in no factor needed + TEC = FreeCAD.Units.Quantity(mat_obj.Material['ThermalExpansionCoefficient']) + TEC_in_mmK = float(TEC.getValueAs('mm/mm/K')) + SH = FreeCAD.Units.Quantity(mat_obj.Material['SpecificHeat']) + SH_in_JkgK = float(SH.getValueAs('J/kg/K')) * 1e+06 # SvdW: Add factor to force units to results' base units of t/mm/s/K # write material properties - f.write('**FreeCAD material name: ' + mat_info_name + '\n') + f.write('** FreeCAD material name: ' + mat_info_name + '\n') f.write('*MATERIAL, NAME=' + mat_name + '\n') f.write('*ELASTIC \n') f.write('{0:.0f}, {1:.3f}\n'.format(YM_in_MPa, PR)) - try: - density = FreeCAD.Units.Quantity(mat_obj.Material['Density']) - density_in_tonne_per_mm3 = float(density.getValueAs('t/mm^3')) - except: - FreeCAD.Console.PrintError("No Density defined for material: default used\n") - f.write('*DENSITY \n') - f.write('{0:.3e}, \n'.format(density_in_tonne_per_mm3)) - f.write('*CONDUCTIVITY \n') - f.write('{0:.3f}, \n'.format(TC_in_WmK)) - f.write('*EXPANSION \n') - f.write('{0:.3e}, \n'.format(TEC_in_mmK)) - f.write('*SPECIFIC HEAT \n') - f.write('{0:.3e}, \n'.format(SH_in_JkgK)) + if self.analysis_type == "frequency" or self.selfweight_objects: + f.write('*DENSITY \n') + f.write('{0:.3e}, \n'.format(density_in_tonne_per_mm3)) + if self.analysis_type == "thermomech": + f.write('*CONDUCTIVITY \n') + f.write('{0:.3f}, \n'.format(TC_in_WmK)) + f.write('*EXPANSION \n') + f.write('{0:.3e}, \n'.format(TEC_in_mmK)) + f.write('*SPECIFIC HEAT \n') + f.write('{0:.3e}, \n'.format(SH_in_JkgK)) def write_femelementsets(self, f): f.write('\n***********************************************************\n') diff --git a/src/Mod/Fem/FemTools.py b/src/Mod/Fem/FemTools.py index 1e8c66da9..9de5680b2 100644 --- a/src/Mod/Fem/FemTools.py +++ b/src/Mod/Fem/FemTools.py @@ -321,6 +321,7 @@ class FemTools(QtCore.QRunnable, QtCore.QObject): message += "FEM mesh has no volume and no shell elements, either define a beam section or provide a FEM mesh with volume elements.\n" if self.mesh.FemMesh.VolumeCount == 0 and self.mesh.FemMesh.FaceCount == 0 and self.mesh.FemMesh.EdgeCount == 0: message += "FEM mesh has neither volume nor shell or edge elements. Provide a FEM mesh with elements!\n" + # materials if not self.materials: message += "No material object defined in the analysis\n" has_no_references = False @@ -329,17 +330,35 @@ class FemTools(QtCore.QRunnable, QtCore.QObject): if has_no_references is True: message += "More than one material has an empty references list (Only one empty references list is allowed!).\n" has_no_references = True + for m in self.materials: + mat_map = m['Object'].Material + if 'YoungsModulus' not in mat_map: + message += "No YoungsModulus defined for at least one material.\n" + if 'PoissonRatio' not in mat_map: + message += "No PoissonRatio defined for at least one material.\n" + if self.analysis_type == "frequency" or self.selfweight_constraints: + if 'Density' not in mat_map: + message += "No Density defined for at least one material.\n" + if self.analysis_type == "thermomech": + if 'ThermalConductivity' not in mat_map: + message += "Thermomechanical analysis: No ThermalConductivity defined for at least one material.\n" + if 'ThermalExpansionCoefficient' not in mat_map: + message += "Thermomechanical analysis: No ThermalExpansionCoefficient defined for at least one material.\n" + if 'SpecificHeat' not in mat_map: + message += "Thermomechanical analysis: No SpecificHeat defined for at least one material.\n" + # constraints if self.analysis_type == "static": if not (self.fixed_constraints or self.displacement_constraints): - message += "Neither a constraint fixed nor a contraint displacement defined in the static analysis\n" + message += "Static analysis: Neither constraint fixed nor constraint displacement defined.\n" if self.analysis_type == "static": if not (self.force_constraints or self.pressure_constraints or self.selfweight_constraints): - message += "Neither constraint force nor constraint pressure or a constraint selfweight defined in the static analysis\n" + message += "Static analysis: Neither constraint force nor constraint pressure or a constraint selfweight defined.\n" if self.analysis_type == "thermomech": if not self.initialtemperature_constraints: - message += "No initial temperature defined in the thermomechanical analysis\n" + message += "Thermomechanical analysis: No initial temperature defined.\n" if len(self.initialtemperature_constraints) > 1: - message += "Only one initial temperature is allowed in thermomechanical analysis\n" + message += "Thermomechanical analysis: Only one initial temperature is allowed.\n" + # beam sections and shell thicknesses if self.beam_sections: if self.shell_thicknesses: # this needs to be checked only once either here or in shell_thicknesses diff --git a/src/Mod/Fem/test_files/ccx/cube_frequency.inp b/src/Mod/Fem/test_files/ccx/cube_frequency.inp index 13d878f0c..d73be7173 100644 --- a/src/Mod/Fem/test_files/ccx/cube_frequency.inp +++ b/src/Mod/Fem/test_files/ccx/cube_frequency.inp @@ -469,20 +469,12 @@ Eall ** written by write_materials function ** Young's modulus unit is MPa = N/mm2 ** Density's unit is t/mm^3 -** Thermal conductivity unit is kW/mm/K = t*mm/K*s^3 -** Specific Heat unit is kJ/t/K = mm^2/s^2/K -**FreeCAD material name: Steel-Generic +** FreeCAD material name: Steel-Generic *MATERIAL, NAME=MechanicalMaterial *ELASTIC 200000, 0.300 *DENSITY 7.900e-09, -*CONDUCTIVITY -1.000, -*EXPANSION -1.000e+00, -*SPECIFIC HEAT -1.000e+00, *********************************************************** ** Sections diff --git a/src/Mod/Fem/test_files/ccx/cube_static.inp b/src/Mod/Fem/test_files/ccx/cube_static.inp index 2a1b1075c..da7c57152 100644 --- a/src/Mod/Fem/test_files/ccx/cube_static.inp +++ b/src/Mod/Fem/test_files/ccx/cube_static.inp @@ -468,21 +468,10 @@ Eall ** Materials ** written by write_materials function ** Young's modulus unit is MPa = N/mm2 -** Density's unit is t/mm^3 -** Thermal conductivity unit is kW/mm/K = t*mm/K*s^3 -** Specific Heat unit is kJ/t/K = mm^2/s^2/K -**FreeCAD material name: Steel-Generic +** FreeCAD material name: Steel-Generic *MATERIAL, NAME=MechanicalMaterial *ELASTIC 200000, 0.300 -*DENSITY -7.900e-09, -*CONDUCTIVITY -1.000, -*EXPANSION -1.000e+00, -*SPECIFIC HEAT -1.000e+00, *********************************************************** ** Sections diff --git a/src/Mod/Fem/test_files/ccx/spine_thermomech.inp b/src/Mod/Fem/test_files/ccx/spine_thermomech.inp index 7fa8715e7..a72e04979 100644 --- a/src/Mod/Fem/test_files/ccx/spine_thermomech.inp +++ b/src/Mod/Fem/test_files/ccx/spine_thermomech.inp @@ -98,15 +98,12 @@ Eall ** Materials ** written by write_materials function ** Young's modulus unit is MPa = N/mm2 -** Density's unit is t/mm^3 ** Thermal conductivity unit is kW/mm/K = t*mm/K*s^3 ** Specific Heat unit is kJ/t/K = mm^2/s^2/K -**FreeCAD material name: Steel-Generic +** FreeCAD material name: Steel-Generic *MATERIAL, NAME=MechanicalMaterial *ELASTIC 200000, 0.300 -*DENSITY -7.900e-09, *CONDUCTIVITY 43.270, *EXPANSION