FEM: calculix writer, improve floats writing for femelement material

This commit is contained in:
Bernd Hahnebach
2021-07-14 09:58:37 +02:00
parent fef8689c48
commit e7efd877d8
26 changed files with 70 additions and 65 deletions

View File

@@ -31,6 +31,8 @@ import FreeCAD
def write_femelement_material(f, ccxwriter):
# floats read from ccx should use {:.13G}, see comment in writer module
# helper inside class method
def is_density_needed():
if ccxwriter.analysis_type == "frequency":
@@ -60,49 +62,52 @@ def write_femelement_material(f, ccxwriter):
mat_info_name = mat_obj.Material["Name"]
mat_name = mat_obj.Name
mat_label = mat_obj.Label
# get material properties of solid material, Currently in SI units: M/kg/s/Kelvin
if mat_obj.Category == "Solid":
YM = FreeCAD.Units.Quantity(mat_obj.Material["YoungsModulus"])
YM_in_MPa = float(YM.getValueAs("MPa"))
YM_in_MPa = YM.getValueAs("MPa").Value
PR = float(mat_obj.Material["PoissonRatio"])
if is_density_needed() is True:
density = FreeCAD.Units.Quantity(mat_obj.Material["Density"])
density_in_tonne_per_mm3 = float(density.getValueAs("t/mm^3"))
density_in_tonne_per_mm3 = density.getValueAs("t/mm^3").Value
if ccxwriter.analysis_type == "thermomech":
TC = FreeCAD.Units.Quantity(mat_obj.Material["ThermalConductivity"])
# SvdW: Add factor to force units to results base units
# of t/mm/s/K - W/m/K results in no factor needed
TC_in_WmK = float(TC.getValueAs("W/m/K"))
TC_in_WmK = TC.getValueAs("W/m/K").Value
SH = FreeCAD.Units.Quantity(mat_obj.Material["SpecificHeat"])
# SvdW: Add factor to force units to results base units of t/mm/s/K
SH_in_JkgK = float(SH.getValueAs("J/kg/K")) * 1e+06
# FIXME: why not get it directly in the units needed ?
SH_in_JkgK = SH.getValueAs("J/kg/K").Value * 1e+06
if mat_obj.Category == "Solid":
TEC = FreeCAD.Units.Quantity(mat_obj.Material["ThermalExpansionCoefficient"])
TEC_in_mmK = float(TEC.getValueAs("mm/mm/K"))
TEC_in_mmK = TEC.getValueAs("mm/mm/K").Value
elif mat_obj.Category == "Fluid":
DV = FreeCAD.Units.Quantity(mat_obj.Material["DynamicViscosity"])
DV_in_tmms = float(DV.getValueAs("t/mm/s"))
DV_in_tmms = DV.getValueAs("t/mm/s").Value
# write material properties
f.write("** FreeCAD material name: " + mat_info_name + "\n")
f.write("** " + mat_label + "\n")
f.write("*MATERIAL, NAME=" + mat_name + "\n")
f.write("** FreeCAD material name: {}\n".format(mat_info_name))
f.write("** {}\n".format(mat_label))
f.write("*MATERIAL, NAME={}\n".format(mat_name))
if mat_obj.Category == "Solid":
f.write("*ELASTIC\n")
f.write("{0:.13G}, {1:.3f}\n".format(YM_in_MPa, PR))
f.write("{:.13G},{:.13G}\n".format(YM_in_MPa, PR))
if is_density_needed() is True:
f.write("*DENSITY\n")
f.write("{0:.3e}\n".format(density_in_tonne_per_mm3))
f.write("{:.13G}\n".format(density_in_tonne_per_mm3))
if ccxwriter.analysis_type == "thermomech":
if mat_obj.Category == "Solid":
f.write("*CONDUCTIVITY\n")
f.write("{0:.3f}\n".format(TC_in_WmK))
f.write("{:.13G}\n".format(TC_in_WmK))
f.write("*EXPANSION\n")
f.write("{0:.3e}\n".format(TEC_in_mmK))
f.write("{:.13G}\n".format(TEC_in_mmK))
f.write("*SPECIFIC HEAT\n")
f.write("{0:.3e}\n".format(SH_in_JkgK))
f.write("{:.13G}\n".format(SH_in_JkgK))
elif mat_obj.Category == "Fluid":
f.write("*FLUID CONSTANTS\n")
f.write("{0:.3e}, {1:.3e}\n".format(SH_in_JkgK, DV_in_tmms))
f.write("{:.13G},{:.13G}\n".format(SH_in_JkgK, DV_in_tmms))
# nonlinear material properties
if ccxwriter.solver_obj.MaterialNonlinearity == "nonlinear":
@@ -114,11 +119,11 @@ def write_femelement_material(f, ccxwriter):
if nl_mat_obj.MaterialModelNonlinearity == "simple hardening":
f.write("*PLASTIC\n")
if nl_mat_obj.YieldPoint1:
f.write(nl_mat_obj.YieldPoint1 + "\n")
f.write("{}\n".format(nl_mat_obj.YieldPoint1))
if nl_mat_obj.YieldPoint2:
f.write(nl_mat_obj.YieldPoint2 + "\n")
f.write("{}\n".format(nl_mat_obj.YieldPoint2))
if nl_mat_obj.YieldPoint3:
f.write(nl_mat_obj.YieldPoint3 + "\n")
f.write("{}\n".format(nl_mat_obj.YieldPoint3))
f.write("\n")

View File

@@ -436,9 +436,9 @@ Evolumes
** MechanicalMaterial
*MATERIAL, NAME=MechanicalMaterial
*ELASTIC
200000, 0.300
200000,0.3
*DENSITY
7.900e-09
7.9E-09
***********************************************************
** Sections

View File

@@ -481,7 +481,7 @@ Evolumes
** MechanicalMaterial
*MATERIAL, NAME=MechanicalMaterial
*ELASTIC
200000, 0.300
200000,0.3
***********************************************************
** Sections

View File

@@ -737,7 +737,7 @@ Evolumes
** MechanicalMaterial
*MATERIAL, NAME=MechanicalMaterial
*ELASTIC
210000, 0.300
210000,0.3
***********************************************************
** Sections

View File

@@ -351,7 +351,7 @@ Evolumes
** FemMaterial
*MATERIAL, NAME=FemMaterial
*ELASTIC
210000, 0.300
210000,0.3
***********************************************************
** Sections

View File

@@ -377,7 +377,7 @@ Evolumes
** FemMaterial
*MATERIAL, NAME=FemMaterial
*ELASTIC
210000, 0.300
210000,0.3
***********************************************************
** Sections

View File

@@ -351,7 +351,7 @@ Evolumes
** FemMaterial
*MATERIAL, NAME=FemMaterial
*ELASTIC
210000, 0.300
210000,0.3
***********************************************************
** Sections

View File

@@ -369,7 +369,7 @@ Evolumes
** FemMaterial
*MATERIAL, NAME=FemMaterial
*ELASTIC
210000, 0.300
210000,0.3
***********************************************************
** Sections

View File

@@ -18729,16 +18729,16 @@ Evolumes
** Steel_Scotty
*MATERIAL, NAME=Steel_Scotty
*ELASTIC
210000, 0.300
210000,0.3
*DENSITY
4.000e-09
4E-09
** FreeCAD material name: Steel_Std
** Steel_Std
*MATERIAL, NAME=Steel_Std
*ELASTIC
210000, 0.300
210000,0.3
*DENSITY
8.000e-09
8E-09
***********************************************************
** Sections

View File

@@ -38355,7 +38355,7 @@ Efaces
** MechanicalMaterial
*MATERIAL, NAME=MechanicalMaterial
*ELASTIC
72000, 0.300
72000,0.3
***********************************************************
** Sections

View File

@@ -5042,7 +5042,7 @@ Evolumes
** MechanicalMaterial
*MATERIAL, NAME=MechanicalMaterial
*ELASTIC
200000, 0.300
200000,0.3
***********************************************************
** Sections

View File

@@ -3393,7 +3393,7 @@ Evolumes
** Material
*MATERIAL, NAME=Material
*ELASTIC
210000, 0.300
210000,0.3
***********************************************************
** Sections

View File

@@ -2144,9 +2144,9 @@ Evolumes
** FemMaterial
*MATERIAL, NAME=FemMaterial
*ELASTIC
210000, 0.300
210000,0.3
*DENSITY
7.900e-09
7.9E-09
***********************************************************
** Sections

View File

@@ -18598,7 +18598,7 @@ Evolumes
** MechanicalMaterial
*MATERIAL, NAME=MechanicalMaterial
*ELASTIC
210000, 0.300
210000,0.3
***********************************************************
** Sections

View File

@@ -3622,7 +3622,7 @@ Evolumes
** FemMaterial
*MATERIAL, NAME=FemMaterial
*ELASTIC
210000, 0.300
210000,0.3
***********************************************************
** Sections

View File

@@ -10966,7 +10966,7 @@ Evolumes
** MechanicalMaterial
*MATERIAL, NAME=MechanicalMaterial
*ELASTIC
210000, 0.300
210000,0.3
***********************************************************
** Sections

View File

@@ -17029,9 +17029,9 @@ Evolumes
** MechanicalMaterial
*MATERIAL, NAME=MechanicalMaterial
*ELASTIC
200000, 0.300
200000,0.3
*DENSITY
7.900e-09
7.9E-09
***********************************************************
** Sections

View File

@@ -27614,17 +27614,17 @@ Evolumes
** FemMaterial1
*MATERIAL, NAME=FemMaterial1
*ELASTIC
32000, 0.170
32000,0.17
** FreeCAD material name: PLA
** FemMaterial2
*MATERIAL, NAME=FemMaterial2
*ELASTIC
3640, 0.360
3640,0.36
** FreeCAD material name: Steel-Generic
** FemMaterial3
*MATERIAL, NAME=FemMaterial3
*ELASTIC
200000, 0.300
200000,0.3
***********************************************************
** Sections

View File

@@ -2525,17 +2525,17 @@ Efaces
** FemMaterial1
*MATERIAL, NAME=FemMaterial1
*ELASTIC
32000, 0.170
32000,0.17
** FreeCAD material name: PLA
** FemMaterial2
*MATERIAL, NAME=FemMaterial2
*ELASTIC
3640, 0.360
3640,0.36
** FreeCAD material name: Steel-Generic
** FemMaterial3
*MATERIAL, NAME=FemMaterial3
*ELASTIC
200000, 0.300
200000,0.3
***********************************************************
** Sections

View File

@@ -1217,12 +1217,12 @@ Evolumes
** MechanicalMaterialLow
*MATERIAL, NAME=MechanicalMaterialLow
*ELASTIC
70000, 0.350
70000,0.35
** FreeCAD material name: Steel-Generic
** MechanicalMaterialUpp
*MATERIAL, NAME=MechanicalMaterialUpp
*ELASTIC
200000, 0.300
200000,0.3
***********************************************************
** Sections

View File

@@ -19992,7 +19992,7 @@ Evolumes
** Material_lin
*MATERIAL, NAME=Material_lin
*ELASTIC
210000, 0.300
210000,0.3
*PLASTIC
240.0, 0.0
270.0, 0.025

View File

@@ -2551,7 +2551,7 @@ Efaces
** FemMaterial
*MATERIAL, NAME=FemMaterial
*ELASTIC
200000, 0.300
200000,0.3
***********************************************************
** Sections

View File

@@ -2551,7 +2551,7 @@ Efaces
** FemMaterial
*MATERIAL, NAME=FemMaterial
*ELASTIC
200000, 0.300
200000,0.3
***********************************************************
** Sections

View File

@@ -8182,24 +8182,24 @@ Evolumes
** MaterialCopper
*MATERIAL, NAME=MaterialCopper
*ELASTIC
130000, 0.354
130000,0.354
*CONDUCTIVITY
200.000
200
*EXPANSION
2.000e-05
2E-05
*SPECIFIC HEAT
3.850e+08
385000000
** FreeCAD material name: Invar
** MaterialInvar
*MATERIAL, NAME=MaterialInvar
*ELASTIC
137000, 0.280
137000,0.28
*CONDUCTIVITY
13.000
13
*EXPANSION
1.200e-06
1.2E-06
*SPECIFIC HEAT
5.100e+08
510000000
***********************************************************
** Initial temperature constraint

View File

@@ -92,9 +92,9 @@ Eedges
** FluidMaterial
*MATERIAL, NAME=FluidMaterial
*DENSITY
9.980e-10
9.98E-10
*FLUID CONSTANTS
4.182e+06, 1.003e-09
4182000,1.003E-09
***********************************************************
** Sections

View File

@@ -113,13 +113,13 @@ Evolumes
** MechanicalMaterial
*MATERIAL, NAME=MechanicalMaterial
*ELASTIC
200000, 0.300
200000,0.3
*CONDUCTIVITY
43.270
43.27
*EXPANSION
1.200e-05
1.2E-05
*SPECIFIC HEAT
5.000e+08
500000000
***********************************************************
** Initial temperature constraint