|
| 1 | +# SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 | + |
| 3 | +#/*************************************************************************** |
| 4 | +# * Copyright (c) 2024 Mario Passaglia <mpassaglia[at]cbc.uba.ar> * |
| 5 | +# * * |
| 6 | +# * This file is part of FreeCAD. * |
| 7 | +# * * |
| 8 | +# * FreeCAD is free software: you can redistribute it and/or modify it * |
| 9 | +# * under the terms of the GNU Lesser General Public License as * |
| 10 | +# * published by the Free Software Foundation, either version 2.1 of the * |
| 11 | +# * License, or (at your option) any later version. * |
| 12 | +# * * |
| 13 | +# * FreeCAD is distributed in the hope that it will be useful, but * |
| 14 | +# * WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 15 | +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 16 | +# * Lesser General Public License for more details. * |
| 17 | +# * * |
| 18 | +# * You should have received a copy of the GNU Lesser General Public * |
| 19 | +# * License along with FreeCAD. If not, see * |
| 20 | +# * <https://www.gnu.org/licenses/>. * |
| 21 | +# * * |
| 22 | +# ************************************************************************** |
| 23 | + |
| 24 | +__title__ = "FreeCAD FEM calculix constraint body heat source" |
| 25 | +__author__ = "Mario Passaglia" |
| 26 | +__url__ = "https://www.freecad.org" |
| 27 | + |
| 28 | + |
| 29 | +import FreeCAD |
| 30 | + |
| 31 | + |
| 32 | +def get_analysis_types(): |
| 33 | + return ["thermomech"] |
| 34 | + |
| 35 | + |
| 36 | +def get_sets_name(): |
| 37 | + return "constraints_bodyheatsource_element_sets" |
| 38 | + |
| 39 | + |
| 40 | +def get_constraint_title(): |
| 41 | + return "Body Heat Source Constraints" |
| 42 | + |
| 43 | + |
| 44 | +def get_before_write_meshdata_constraint(): |
| 45 | + return "" |
| 46 | + |
| 47 | + |
| 48 | +def get_after_write_meshdata_constraint(): |
| 49 | + return "" |
| 50 | + |
| 51 | + |
| 52 | +def get_before_write_constraint(): |
| 53 | + return "" |
| 54 | + |
| 55 | + |
| 56 | +def get_after_write_constraint(): |
| 57 | + return "" |
| 58 | + |
| 59 | + |
| 60 | +def write_meshdata_constraint(f, femobj, bodyheatsource_obj, ccxwriter): |
| 61 | + f.write("*ELSET,ELSET={}\n".format(bodyheatsource_obj.Name)) |
| 62 | + if isinstance(femobj["FEMElements"], str): |
| 63 | + f.write("{}\n".format(femobj["FEMElements"])) |
| 64 | + else: |
| 65 | + for e in femobj["FEMElements"]: |
| 66 | + f.write("{},\n".format(e)) |
| 67 | + |
| 68 | + |
| 69 | +def write_constraint(f, femobj, bodyheatsource_obj, ccxwriter): |
| 70 | + |
| 71 | + # floats read from ccx should use {:.13G}, see comment in writer module |
| 72 | + # search referenced material |
| 73 | + ref = bodyheatsource_obj.References |
| 74 | + density = None |
| 75 | + for mat in ccxwriter.member.mats_linear: |
| 76 | + for mat_ref in mat["Object"].References: |
| 77 | + if mat_ref[0] == ref[0]: |
| 78 | + density = FreeCAD.Units.Quantity(mat["Object"].Material["Density"]) |
| 79 | + break |
| 80 | + |
| 81 | + if not density: |
| 82 | + # search material without references |
| 83 | + for mat in ccxwriter.member.mats_linear: |
| 84 | + if not mat["Object"].References: |
| 85 | + density = FreeCAD.Units.Quantity(mat["Object"].Material["Density"]) |
| 86 | + |
| 87 | + # get some data from the bodyheatsource_obj (is in power per unit mass) |
| 88 | + heat = FreeCAD.Units.Quantity(bodyheatsource_obj.HeatSource, "m^2/s^3") * density |
| 89 | + # write to file |
| 90 | + f.write("*DFLUX\n") |
| 91 | + f.write( |
| 92 | + "{},BF,{:.13G}\n".format( |
| 93 | + bodyheatsource_obj.Name, heat.getValueAs("t/(mm*s^3)").Value |
| 94 | + ) |
| 95 | + ) |
| 96 | + f.write("\n") |
0 commit comments