Fem: Add body heat source to CalculiX writer - fixes #11650

This commit is contained in:
marioalexis
2024-06-02 12:37:07 -03:00
parent 87a7bc1d81
commit d8f1ade17d
6 changed files with 118 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
#/***************************************************************************
# * Copyright (c) 2024 Mario Passaglia <mpassaglia[at]cbc.uba.ar> *
# * *
# * This file is part of FreeCAD. *
# * *
# * FreeCAD is free software: you can redistribute it and/or modify it *
# * under the terms of the GNU Lesser General Public License as *
# * published by the Free Software Foundation, either version 2.1 of the *
# * License, or (at your option) any later version. *
# * *
# * FreeCAD 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 *
# * Lesser General Public License for more details. *
# * *
# * You should have received a copy of the GNU Lesser General Public *
# * License along with FreeCAD. If not, see *
# * <https://www.gnu.org/licenses/>. *
# * *
# **************************************************************************
__title__ = "FreeCAD FEM calculix constraint body heat source"
__author__ = "Mario Passaglia"
__url__ = "https://www.freecad.org"
import FreeCAD
def get_analysis_types():
return ["thermomech"]
def get_sets_name():
return "constraints_bodyheatsource_element_sets"
def get_constraint_title():
return "Body Heat Source Constraints"
def get_before_write_meshdata_constraint():
return ""
def get_after_write_meshdata_constraint():
return ""
def get_before_write_constraint():
return ""
def get_after_write_constraint():
return ""
def write_meshdata_constraint(f, femobj, bodyheatsource_obj, ccxwriter):
f.write("*ELSET,ELSET={}\n".format(bodyheatsource_obj.Name))
if isinstance(femobj["FEMElements"], str):
f.write("{}\n".format(femobj["FEMElements"]))
else:
for e in femobj["FEMElements"]:
f.write("{},\n".format(e))
def write_constraint(f, femobj, bodyheatsource_obj, ccxwriter):
# floats read from ccx should use {:.13G}, see comment in writer module
# search referenced material
ref = bodyheatsource_obj.References
density = None
for mat in ccxwriter.member.mats_linear:
for mat_ref in mat["Object"].References:
if mat_ref[0] == ref[0][0]:
density = FreeCAD.Units.Quantity(mat["Object"].Material["Density"])
break
if not density:
# search material without references
for mat in ccxwriter.member.mats_linear:
if not mat["Object"].References:
density = FreeCAD.Units.Quantity(mat["Object"].Material["Density"])
# get some data from the bodyheatsource_obj (is in power per unit mass)
heat = FreeCAD.Units.Quantity(bodyheatsource_obj.HeatSource, "m^2/s^3") * density
# write to file
f.write("*DFLUX\n")
f.write(
"{},BF,{:.13G}\n".format(
bodyheatsource_obj.Name, heat.getValueAs("t/(mm*s^3)").Value
)
)
f.write("\n")

View File

@@ -36,6 +36,7 @@ import FreeCAD
from FreeCAD import Units
from . import write_constraint_centrif as con_centrif
from . import write_constraint_bodyheatsource as con_bodyheatsource
from . import write_constraint_contact as con_contact
from . import write_constraint_displacement as con_displacement
from . import write_constraint_fixed as con_fixed
@@ -160,6 +161,7 @@ class FemInputWriterCcx(writerbase.FemInputWriter):
# element sets constraints
self.write_constraints_meshsets(inpfile, self.member.cons_centrif, con_centrif)
self.write_constraints_meshsets(inpfile, self.member.cons_bodyheatsource, con_bodyheatsource)
# node sets
self.write_constraints_meshsets(inpfile, self.member.cons_fixed, con_fixed)
@@ -196,6 +198,7 @@ class FemInputWriterCcx(writerbase.FemInputWriter):
self.write_constraints_propdata(inpfile, self.member.cons_sectionprint, con_sectionprint)
self.write_constraints_propdata(inpfile, self.member.cons_selfweight, con_selfweight)
self.write_constraints_propdata(inpfile, self.member.cons_centrif, con_centrif)
self.write_constraints_propdata(inpfile, self.member.cons_bodyheatsource, con_bodyheatsource)
self.write_constraints_meshsets(inpfile, self.member.cons_force, con_force)
self.write_constraints_meshsets(inpfile, self.member.cons_pressure, con_pressure)
self.write_constraints_propdata(inpfile, self.member.cons_temperature, con_temperature)