[FEM] Temperature constraints overhaul

- fix bug that changing constraint type in dialog lost flux value
- accept and not immediately save any changed value
- make the temperatures a PropertyTemperature to get rid of hacks
- also fix some too long code lines
This commit is contained in:
Uwe
2023-03-27 20:13:42 +02:00
parent e3e49230d8
commit 49acbb2c65
18 changed files with 176 additions and 137 deletions

View File

@@ -25,6 +25,8 @@ __title__ = "FreeCAD FEM calculix constraint initialtemperature"
__author__ = "Bernd Hahnebach"
__url__ = "https://www.freecadweb.org"
import FreeCAD
def get_analysis_types():
return ["thermomech"]
@@ -46,7 +48,12 @@ def write_constraint(f, femobj, inittemp_obj, ccxwriter):
# floats read from ccx should use {:.13G}, see comment in writer module
f.write("{},{:.13G}\n".format(ccxwriter.ccx_nall, inittemp_obj.initialTemperature))
f.write(
"{},{}\n".format(
ccxwriter.ccx_nall,
FreeCAD.Units.Quantity(inittemp_obj.initialTemperature.getValueAs("K"))
)
)
# Should only be one object in the analysis

View File

@@ -25,6 +25,8 @@ __title__ = "FreeCAD FEM calculix constraint temperature"
__author__ = "Bernd Hahnebach"
__url__ = "https://www.freecadweb.org"
import FreeCAD
def get_analysis_types():
return ["thermomech"]
@@ -68,12 +70,19 @@ def write_constraint(f, femobj, temp_obj, ccxwriter):
NumberOfNodes = len(femobj["Nodes"])
if temp_obj.ConstraintType == "Temperature":
f.write("*BOUNDARY\n")
f.write("{},11,11,{:.13G}\n".format(temp_obj.Name, temp_obj.Temperature))
f.write(
"{},11,11,{}\n".format(
temp_obj.Name, FreeCAD.Units.Quantity(temp_obj.Temperature.getValueAs("K"))
)
)
f.write("\n")
elif temp_obj.ConstraintType == "CFlux":
f.write("*CFLUX\n")
f.write("{},11,{:.13G}\n".format(
temp_obj.Name,
temp_obj.CFlux * 0.001 / NumberOfNodes
))
# CFLUX has to be specified in mW
f.write(
"{},11,{}\n".format(
temp_obj.Name,
FreeCAD.Units.Quantity(temp_obj.CFlux.getValueAs("mW")) / NumberOfNodes
)
)
f.write("\n")

View File

@@ -186,7 +186,7 @@ class DeformationWriter:
# temperature
tempObj = self.write.getSingleMember("Fem::ConstraintInitialTemperature")
if tempObj is not None:
refTemp = self.write.getFromUi(tempObj.initialTemperature, "K", "O")
refTemp = float(tempObj.initialTemperature.getValueAs("K"))
for name in bodies:
self.write.material(name, "Reference Temperature", refTemp)
# get the material data for all bodies

View File

@@ -402,7 +402,7 @@ class ElasticityWriter:
# temperature
tempObj = self.write.getSingleMember("Fem::ConstraintInitialTemperature")
if tempObj is not None:
refTemp = self.write.getFromUi(tempObj.initialTemperature, "K", "O")
refTemp = float(tempObj.initialTemperature.getValueAs("K"))
for name in bodies:
self.write.material(name, "Reference Temperature", refTemp)
# get the material data for all bodies

View File

@@ -126,7 +126,7 @@ class Flowwriter:
def handleFlowMaterial(self, bodies):
tempObj = self.write.getSingleMember("Fem::ConstraintInitialTemperature")
if tempObj is not None:
refTemp = self.write.getFromUi(tempObj.initialTemperature, "K", "O")
refTemp = float(tempObj.initialTemperature.getValueAs("K"))
for name in bodies:
self.write.material(name, "Reference Temperature", refTemp)
for obj in self.write.getMember("App::MaterialObject"):

View File

@@ -103,12 +103,10 @@ class Heatwriter:
if obj.References:
for name in obj.References[0][1]:
if obj.ConstraintType == "Temperature":
temp = self.write.getFromUi(obj.Temperature, "K", "O")
self.write.boundary(name, "Temperature", temp)
temperature = float(obj.Temperature.getValueAs("K"))
self.write.boundary(name, "Temperature", temperature)
elif obj.ConstraintType == "CFlux":
# the CFLUX property stores the value in µW
# but the unit system is not aware of µW, only of mW
flux = 0.001 * self.write.getFromUi(obj.CFlux, "mW", "M*L^2*T^-3")
flux = float(obj.CFlux.getValueAs("W"))
# CFLUX is the flux per mesh node
flux = flux / NumberOfNodes
self.write.boundary(name, "Temperature Load", flux)
@@ -128,12 +126,12 @@ class Heatwriter:
self.write.handled(obj)
def handleHeatInitial(self, bodies):
obj = self.write.getSingleMember("Fem::ConstraintInitialTemperature")
if obj is not None:
for name in bodies:
temp = self.write.getFromUi(obj.initialTemperature, "K", "O")
self.write.initial(name, "Temperature", temp)
self.write.handled(obj)
tempObj = self.write.getSingleMember("Fem::ConstraintInitialTemperature")
if tempObj is not None:
refTemp = float(tempObj.initialTemperature.getValueAs("K"))
for name in bodies:
self.write.initial(name, "Temperature", refTemp)
self.write.handled(tempObj)
def _outputHeatBodyForce(self, obj, name):
heatSource = self.write.getFromUi(obj.HeatSource, "W/kg", "L^2*T^-3")
@@ -165,7 +163,7 @@ class Heatwriter:
def handleHeatMaterial(self, bodies):
tempObj = self.write.getSingleMember("Fem::ConstraintInitialTemperature")
if tempObj is not None:
refTemp = self.write.getFromUi(tempObj.initialTemperature, "K", "O")
refTemp = float(tempObj.initialTemperature.getValueAs("K"))
for name in bodies:
self.write.material(name, "Reference Temperature", refTemp)
for obj in self.write.getMember("App::MaterialObject"):