FEM: move setup thermomech example from unit tests to fem examples

This commit is contained in:
Bernd Hahnebach
2019-09-25 08:19:39 +02:00
parent e9e1c89929
commit 79dcd464b2
3 changed files with 155 additions and 133 deletions

View File

@@ -38,6 +38,7 @@ SET(FemExamples_SRCS
femexamples/ccx_cantilever_std.py
femexamples/manager.py
femexamples/rc_wall_2d.py
femexamples/thermomech_spine.py
)
SET(FemExampleMeshes_SRCS

View File

@@ -0,0 +1,150 @@
# ***************************************************************************
# * Copyright (c) 2019 Bernd Hahnebach <bernd@bimstatik.org> *
# * *
# * This file is part of the FreeCAD CAx development system. *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * 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 Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with FreeCAD; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
import FreeCAD
import ObjectsFem
import Fem
mesh_name = "Mesh" # needs to be Mesh to work with unit tests
def init_doc(doc=None):
if doc is None:
doc = FreeCAD.newDocument()
return doc
def setup(doc=None, solver="ccxtools"):
# setup model
if doc is None:
doc = init_doc()
# part
box_obj = doc.addObject("Part::Box", "Box")
box_obj.Height = 25.4
box_obj.Width = 25.4
box_obj.Length = 203.2
# analysis
analysis = ObjectsFem.makeAnalysis(doc, "Analysis")
# solver
# TODO How to pass multiple solver for one analysis in one doc
if solver == "calculix":
solver_object = analysis.addObject(
ObjectsFem.makeSolverCalculix(doc, "SolverCalculiX")
)[0]
solver_object.AnalysisType = "thermomech"
solver_object.GeometricalNonlinearity = "linear"
solver_object.ThermoMechSteadyState = True
solver_object.MatrixSolverType = "default"
solver_object.IterationsThermoMechMaximum = 2000
solver_object.IterationsControlParameterTimeUse = True
elif solver == "ccxtools":
solver_object = analysis.addObject(
ObjectsFem.makeSolverCalculixCcxTools(doc, "CalculiXccxTools")
)[0]
solver_object.AnalysisType = "thermomech"
solver_object.GeometricalNonlinearity = "linear"
solver_object.ThermoMechSteadyState = True
solver_object.MatrixSolverType = "default"
solver_object.IterationsThermoMechMaximum = 2000
solver_object.IterationsControlParameterTimeUse = True
solver_object.WorkingDir = u""
# should be possible with elmer too
# elif solver == "elmer":
# analysis.addObject(ObjectsFem.makeSolverElmer(doc, "SolverElmer"))
# material
material_object = analysis.addObject(
ObjectsFem.makeMaterialSolid(doc, "MechanicalMaterial")
)[0]
mat = material_object.Material
mat["Name"] = "Steel-Generic"
mat["YoungsModulus"] = "200000 MPa"
mat["PoissonRatio"] = "0.30"
mat["Density"] = "7900 kg/m^3"
mat["ThermalConductivity"] = "43.27 W/m/K" # SvdW: Change to Ansys model values
mat["ThermalExpansionCoefficient"] = "12 um/m/K"
mat["SpecificHeat"] = "500 J/kg/K" # SvdW: Change to Ansys model values
material_object.Material = mat
# fixed_constraint
fixed_constraint = analysis.addObject(
ObjectsFem.makeConstraintFixed(doc, "FemConstraintFixed")
)[0]
fixed_constraint.References = [(box_obj, "Face1")]
# initialtemperature_constraint
initialtemperature_constraint = analysis.addObject(
ObjectsFem.makeConstraintInitialTemperature(doc, "FemConstraintInitialTemperature")
)[0]
initialtemperature_constraint.initialTemperature = 300.0
# temperature_constraint
temperature_constraint = analysis.addObject(
ObjectsFem.makeConstraintTemperature(doc, "FemConstraintTemperature")
)[0]
temperature_constraint.References = [(box_obj, "Face1")]
temperature_constraint.Temperature = 310.93
# heatflux_constraint
heatflux_constraint = analysis.addObject(
ObjectsFem.makeConstraintHeatflux(doc, "FemConstraintHeatflux")
)[0]
heatflux_constraint.References = [
(box_obj, "Face3"),
(box_obj, "Face4"),
(box_obj, "Face5"),
(box_obj, "Face6")
]
heatflux_constraint.AmbientTemp = 255.3722
heatflux_constraint.FilmCoef = 5.678
# mesh
# from femexamples.meshes.mesh_canticcx_tetra10 import create_nodes, create_elements
from femtest.data.ccx.spine_mesh import create_nodes_spine as create_nodes
from femtest.data.ccx.spine_mesh import create_elements_spine as create_elements
fem_mesh = Fem.FemMesh()
control = create_nodes(fem_mesh)
if not control:
FreeCAD.Console.PrintError("Error on creating nodes.\n")
control = create_elements(fem_mesh)
if not control:
FreeCAD.Console.PrintError("Error on creating elements.\n")
femmesh_obj = analysis.addObject(
doc.addObject("Fem::FemMeshObject", mesh_name)
)[0]
femmesh_obj.FemMesh = fem_mesh
doc.recompute()
return doc
"""
from femexamples import thermomech_bar as thermo
thermo.setup()
"""

View File

@@ -595,140 +595,11 @@ class TestCcxTools(unittest.TestCase):
fcc_print("--------------- Start of FEM tests ---------------")
box = self.active_doc.addObject("Part::Box", "Box")
box.Height = 25.4
box.Width = 25.4
box.Length = 203.2
# set up the thermomech example
from femexamples.thermomech_spine import setup as thermomech
thermomech(self.active_doc, "ccxtools")
fcc_print("Checking FEM new analysis...")
analysis = ObjectsFem.makeAnalysis(
self.active_doc,
"Analysis"
)
self.assertTrue(
analysis,
"FemTest of new analysis failed"
)
fcc_print("Checking FEM new solver...")
solver_object = ObjectsFem.makeSolverCalculixCcxTools(
self.active_doc,
"CalculiX"
)
solver_object.AnalysisType = "thermomech"
solver_object.GeometricalNonlinearity = "linear"
solver_object.ThermoMechSteadyState = True
solver_object.MatrixSolverType = "default"
solver_object.IterationsThermoMechMaximum = 2000
solver_object.IterationsControlParameterTimeUse = True
self.assertTrue(
solver_object,
"FemTest of new solver failed"
)
analysis.addObject(solver_object)
fcc_print("Checking FEM new material...")
material_object = ObjectsFem.makeMaterialSolid(
self.active_doc,
"MechanicalMaterial"
)
mat = material_object.Material
mat["Name"] = "Steel-Generic"
mat["YoungsModulus"] = "200000 MPa"
mat["PoissonRatio"] = "0.30"
mat["Density"] = "7900 kg/m^3"
mat["ThermalConductivity"] = "43.27 W/m/K" # SvdW: Change to Ansys model values
mat["ThermalExpansionCoefficient"] = "12 um/m/K"
mat["SpecificHeat"] = "500 J/kg/K" # SvdW: Change to Ansys model values
material_object.Material = mat
self.assertTrue(
material_object,
"FemTest of new material failed"
)
analysis.addObject(material_object)
fcc_print("Checking FEM new fixed constraint...")
fixed_constraint = self.active_doc.addObject(
"Fem::ConstraintFixed",
"FemConstraintFixed"
)
fixed_constraint.References = [(box, "Face1")]
self.assertTrue(
fixed_constraint,
"FemTest of new fixed constraint failed"
)
analysis.addObject(fixed_constraint)
fcc_print("Checking FEM new initial temperature constraint...")
initialtemperature_constraint = self.active_doc.addObject(
"Fem::ConstraintInitialTemperature",
"FemConstraintInitialTemperature"
)
initialtemperature_constraint.initialTemperature = 300.0
self.assertTrue(
initialtemperature_constraint,
"FemTest of new initial temperature constraint failed"
)
analysis.addObject(initialtemperature_constraint)
fcc_print("Checking FEM new temperature constraint...")
temperature_constraint = self.active_doc.addObject(
"Fem::ConstraintTemperature",
"FemConstraintTemperature"
)
temperature_constraint.References = [(box, "Face1")]
temperature_constraint.Temperature = 310.93
self.assertTrue(
temperature_constraint,
"FemTest of new temperature constraint failed"
)
analysis.addObject(temperature_constraint)
fcc_print("Checking FEM new heatflux constraint...")
heatflux_constraint = self.active_doc.addObject(
"Fem::ConstraintHeatflux",
"FemConstraintHeatflux"
)
heatflux_constraint.References = [
(box, "Face3"),
(box, "Face4"),
(box, "Face5"),
(box, "Face6")
]
heatflux_constraint.AmbientTemp = 255.3722
heatflux_constraint.FilmCoef = 5.678
self.assertTrue(
heatflux_constraint,
"FemTest of new heatflux constraint failed"
)
analysis.addObject(heatflux_constraint)
fcc_print("Checking FEM new mesh...")
from ..data.ccx.spine_mesh import create_nodes_spine
from ..data.ccx.spine_mesh import create_elements_spine
mesh = Fem.FemMesh()
ret = create_nodes_spine(mesh)
self.assertTrue(
ret,
"Import of mesh nodes failed"
)
ret = create_elements_spine(mesh)
self.assertTrue(
ret,
"Import of mesh volumes failed"
)
mesh_object = self.active_doc.addObject(
"Fem::FemMeshObject",
self.mesh_name
)
mesh_object.FemMesh = mesh
self.assertTrue(
mesh,
"FemTest of new mesh failed"
)
analysis.addObject(mesh_object)
self.active_doc.recompute()
analysis = self.active_doc.Analysis
thermomech_analysis_dir = testtools.get_unit_test_tmp_dir(
self.temp_dir,