FEM: examples, move base setups in separate modules

This commit is contained in:
Bernd Hahnebach
2021-06-16 15:55:45 +02:00
parent cb1af60183
commit 6466aadbce
10 changed files with 202 additions and 149 deletions

View File

@@ -42,11 +42,13 @@ SET(FemCommands_SRCS
SET(FemExamples_SRCS
femexamples/__init__.py
femexamples/boxanalysis_base.py
femexamples/boxanalysis_static.py
femexamples/boxanalysis_frequency.py
femexamples/buckling_platebuckling.py
femexamples/buckling_lateraltorsionalbuckling.py
femexamples/ccx_buckling_flexuralbuckling.py
femexamples/ccx_cantilever_base.py
femexamples/ccx_cantilever_faceload.py
femexamples/ccx_cantilever_nodeload.py
femexamples/ccx_cantilever_hexa20faceload.py

View File

@@ -0,0 +1,80 @@
# ***************************************************************************
# * Copyright (c) 2019 Bernd Hahnebach <bernd@bimstatik.org> *
# * Copyright (c) 2020 Sudhanshu Dubey <sudhanshu.thethunder@gmail.com *
# * *
# * 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. *
# * *
# * This program 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 this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
import FreeCAD
import Fem
import ObjectsFem
from .manager import get_meshname
from .manager import init_doc
def setup_boxanalysisbase(doc=None, solvertype="ccxtools"):
# init FreeCAD document
if doc is None:
doc = init_doc()
# geometric objects
# object name is important in this base setup method
# all module which use this base setup, use the object name to find the object
geom_obj = doc.addObject("Part::Box", "Box")
geom_obj.Height = geom_obj.Width = geom_obj.Length = 10
doc.recompute()
if FreeCAD.GuiUp:
geom_obj.ViewObject.Document.activeView().viewAxonometric()
geom_obj.ViewObject.Document.activeView().fitAll()
# analysis
analysis = ObjectsFem.makeAnalysis(doc, "Analysis")
# material
material_obj = ObjectsFem.makeMaterialSolid(doc, "MechanicalMaterial")
mat = material_obj.Material
mat["Name"] = "Steel-Generic"
mat["YoungsModulus"] = "200000 MPa"
mat["PoissonRatio"] = "0.30"
mat["Density"] = "7900 kg/m^3"
material_obj.Material = mat
analysis.addObject(material_obj)
# mesh
from .meshes.mesh_boxanalysis_tetra10 import create_nodes, 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(ObjectsFem.makeMeshGmsh(doc, get_meshname()))[0]
femmesh_obj.FemMesh = fem_mesh
femmesh_obj.Part = geom_obj
femmesh_obj.SecondOrderLinear = False
femmesh_obj.CharacteristicLengthMin = "8.0 mm"
doc.recompute()
return doc

View File

@@ -29,11 +29,9 @@ setup()
"""
# import FreeCAD
import ObjectsFem
from .boxanalysis_static import setup_base
from .boxanalysis_base import setup_boxanalysisbase
def get_information():
@@ -51,7 +49,7 @@ def get_information():
def setup(doc=None, solvertype="ccxtools"):
# setup box frequency, change solver attributes
doc = setup_base(doc, solvertype)
doc = setup_boxanalysisbase(doc, solvertype)
analysis = doc.Analysis
# solver

View File

@@ -31,11 +31,9 @@ setup()
import FreeCAD
import Fem
import ObjectsFem
from .manager import get_meshname
from .manager import init_doc
from .boxanalysis_base import setup_boxanalysisbase
def get_information():
@@ -50,59 +48,10 @@ def get_information():
}
def setup_base(doc=None, solvertype="ccxtools"):
# init FreeCAD document
if doc is None:
doc = init_doc()
# geometric objects
# object name is important in this base setup method
# all module which use this base setup, use the object name to find the object
geom_obj = doc.addObject("Part::Box", "Box")
geom_obj.Height = geom_obj.Width = geom_obj.Length = 10
doc.recompute()
if FreeCAD.GuiUp:
geom_obj.ViewObject.Document.activeView().viewAxonometric()
geom_obj.ViewObject.Document.activeView().fitAll()
# analysis
analysis = ObjectsFem.makeAnalysis(doc, "Analysis")
# material
material_obj = ObjectsFem.makeMaterialSolid(doc, "MechanicalMaterial")
mat = material_obj.Material
mat["Name"] = "Steel-Generic"
mat["YoungsModulus"] = "200000 MPa"
mat["PoissonRatio"] = "0.30"
mat["Density"] = "7900 kg/m^3"
material_obj.Material = mat
analysis.addObject(material_obj)
# mesh
from .meshes.mesh_boxanalysis_tetra10 import create_nodes, 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(ObjectsFem.makeMeshGmsh(doc, get_meshname()))[0]
femmesh_obj.FemMesh = fem_mesh
femmesh_obj.Part = geom_obj
femmesh_obj.SecondOrderLinear = False
femmesh_obj.CharacteristicLengthMin = "8.0 mm"
doc.recompute()
return doc
def setup(doc=None, solvertype="ccxtools"):
# setup box static, add a fixed, force and a pressure constraint
doc = setup_base(doc, solvertype)
doc = setup_boxanalysisbase(doc, solvertype)
geom_obj = doc.Box
analysis = doc.Analysis

View File

@@ -0,0 +1,109 @@
# ***************************************************************************
# * Copyright (c) 2019 Bernd Hahnebach <bernd@bimstatik.org> *
# * Copyright (c) 2020 Sudhanshu Dubey <sudhanshu.thethunder@gmail.com *
# * *
# * 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. *
# * *
# * This program 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 this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
import FreeCAD
import Fem
import ObjectsFem
from .manager import get_meshname
from .manager import init_doc
def setup_cantileverbase(doc=None, solvertype="ccxtools"):
# init FreeCAD document
if doc is None:
doc = init_doc()
# geometric object
# object name is important in this base setup method
# all module which use this base setup, use the object name to find the object
geom_obj = doc.addObject("Part::Box", "Box")
geom_obj.Height = geom_obj.Width = 1000
geom_obj.Length = 8000
doc.recompute()
if FreeCAD.GuiUp:
geom_obj.ViewObject.Document.activeView().viewAxonometric()
geom_obj.ViewObject.Document.activeView().fitAll()
# analysis
analysis = ObjectsFem.makeAnalysis(doc, "Analysis")
# solver
if solvertype == "calculix":
solver_obj = ObjectsFem.makeSolverCalculix(doc, "SolverCalculiX")
elif solvertype == "ccxtools":
solver_obj = ObjectsFem.makeSolverCalculixCcxTools(doc, "CalculiXccxTools")
solver_obj.WorkingDir = u""
elif solvertype == "elmer":
solver_obj = ObjectsFem.makeSolverElmer(doc, "SolverElmer")
ObjectsFem.makeEquationElasticity(doc, solver_obj)
elif solvertype == "z88":
solver_obj = ObjectsFem.makeSolverZ88(doc, "SolverZ88")
else:
FreeCAD.Console.PrintWarning(
"Not known or not supported solver type: {}. "
"No solver object was created.\n".format(solvertype)
)
if solvertype == "calculix" or solvertype == "ccxtools":
solver_obj.SplitInputWriter = False
solver_obj.AnalysisType = "static"
solver_obj.GeometricalNonlinearity = "linear"
solver_obj.ThermoMechSteadyState = False
solver_obj.MatrixSolverType = "default"
solver_obj.IterationsControlParameterTimeUse = False
analysis.addObject(solver_obj)
# material
material_obj = ObjectsFem.makeMaterialSolid(doc, "FemMaterial")
mat = material_obj.Material
mat["Name"] = "CalculiX-Steel"
mat["YoungsModulus"] = "210000 MPa"
mat["PoissonRatio"] = "0.30"
mat["Density"] = "7900 kg/m^3"
material_obj.Material = mat
analysis.addObject(material_obj)
# constraint fixed
con_fixed = ObjectsFem.makeConstraintFixed(doc, "ConstraintFixed")
con_fixed.References = [(geom_obj, "Face1")]
analysis.addObject(con_fixed)
# mesh
from .meshes.mesh_canticcx_tetra10 import create_nodes, 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(ObjectsFem.makeMeshGmsh(doc, get_meshname()))[0]
femmesh_obj.FemMesh = fem_mesh
femmesh_obj.Part = geom_obj
femmesh_obj.SecondOrderLinear = False
doc.recompute()
return doc

View File

@@ -29,13 +29,9 @@ setup()
"""
import FreeCAD
import Fem
import ObjectsFem
from .manager import get_meshname
from .manager import init_doc
from .ccx_cantilever_base import setup_cantileverbase
def get_information():
@@ -50,84 +46,6 @@ def get_information():
}
def setup_cantileverbase(doc=None, solvertype="ccxtools"):
# init FreeCAD document
if doc is None:
doc = init_doc()
# geometric object
# object name is important in this base setup method
# all module which use this base setup, use the object name to find the object
geom_obj = doc.addObject("Part::Box", "Box")
geom_obj.Height = geom_obj.Width = 1000
geom_obj.Length = 8000
doc.recompute()
if FreeCAD.GuiUp:
geom_obj.ViewObject.Document.activeView().viewAxonometric()
geom_obj.ViewObject.Document.activeView().fitAll()
# analysis
analysis = ObjectsFem.makeAnalysis(doc, "Analysis")
# solver
if solvertype == "calculix":
solver_obj = ObjectsFem.makeSolverCalculix(doc, "SolverCalculiX")
elif solvertype == "ccxtools":
solver_obj = ObjectsFem.makeSolverCalculixCcxTools(doc, "CalculiXccxTools")
solver_obj.WorkingDir = u""
elif solvertype == "elmer":
solver_obj = ObjectsFem.makeSolverElmer(doc, "SolverElmer")
ObjectsFem.makeEquationElasticity(doc, solver_obj)
elif solvertype == "z88":
solver_obj = ObjectsFem.makeSolverZ88(doc, "SolverZ88")
else:
FreeCAD.Console.PrintWarning(
"Not known or not supported solver type: {}. "
"No solver object was created.\n".format(solvertype)
)
if solvertype == "calculix" or solvertype == "ccxtools":
solver_obj.SplitInputWriter = False
solver_obj.AnalysisType = "static"
solver_obj.GeometricalNonlinearity = "linear"
solver_obj.ThermoMechSteadyState = False
solver_obj.MatrixSolverType = "default"
solver_obj.IterationsControlParameterTimeUse = False
analysis.addObject(solver_obj)
# material
material_obj = ObjectsFem.makeMaterialSolid(doc, "FemMaterial")
mat = material_obj.Material
mat["Name"] = "CalculiX-Steel"
mat["YoungsModulus"] = "210000 MPa"
mat["PoissonRatio"] = "0.30"
mat["Density"] = "7900 kg/m^3"
material_obj.Material = mat
analysis.addObject(material_obj)
# constraint fixed
con_fixed = ObjectsFem.makeConstraintFixed(doc, "ConstraintFixed")
con_fixed.References = [(geom_obj, "Face1")]
analysis.addObject(con_fixed)
# mesh
from .meshes.mesh_canticcx_tetra10 import create_nodes, 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(ObjectsFem.makeMeshGmsh(doc, get_meshname()))[0]
femmesh_obj.FemMesh = fem_mesh
femmesh_obj.Part = geom_obj
femmesh_obj.SecondOrderLinear = False
doc.recompute()
return doc
def setup(doc=None, solvertype="ccxtools"):
# setup CalculiX cantilever, apply 9 MN on surface of front end face

View File

@@ -34,7 +34,6 @@ import FreeCAD
import Fem
from .ccx_cantilever_faceload import setup as setup_with_faceload
from .manager import get_meshname

View File

@@ -29,11 +29,9 @@ setup()
"""
# import FreeCAD
import ObjectsFem
from .ccx_cantilever_faceload import setup_cantileverbase
from .ccx_cantilever_base import setup_cantileverbase
def get_information():

View File

@@ -29,11 +29,9 @@ setup()
"""
# import FreeCAD
import ObjectsFem
from .ccx_cantilever_faceload import setup_cantileverbase
from .ccx_cantilever_base import setup_cantileverbase
def get_information():

View File

@@ -54,11 +54,13 @@ class FemExamples(QtGui.QWidget):
path = os.path.dirname(os.path.realpath(__file__))
files = [f for f in os.listdir(str(path))]
not_files = [
"__init__.py",
"__pycache__",
"boxanalysis_base.py",
"ccx_cantilever_base.py",
"examplesgui.py",
"manager.py",
"meshes",
"__init__.py",
"__pycache__",
]
files = [str(f) for f in files if f not in not_files]