Skip to content

Commit

Permalink
FEM: move setup simple box static and frequency example from unit tes…
Browse files Browse the repository at this point in the history
…ts to fem examples
  • Loading branch information
berndhahnebach committed Sep 26, 2019
1 parent ef72550 commit 3acb7d9
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 182 deletions.
1 change: 1 addition & 0 deletions src/Mod/Fem/CMakeLists.txt
Expand Up @@ -35,6 +35,7 @@ SET(FemCommands_SRCS

SET(FemExamples_SRCS
femexamples/__init__.py
femexamples/boxanalysis.py
femexamples/ccx_cantilever_std.py
femexamples/manager.py
femexamples/multimaterial_twoboxes.py
Expand Down
182 changes: 182 additions & 0 deletions src/Mod/Fem/femexamples/boxanalysis.py
@@ -0,0 +1,182 @@
# ***************************************************************************
# * 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_base(doc=None, solver="ccxtools"):
# setup box base model

if doc is None:
doc = init_doc()

# part
box_obj = doc.addObject("Part::Box", "Box")
box_obj.Height = box_obj.Width = box_obj.Length = 10
doc.recompute()

if FreeCAD.GuiUp:
import FreeCADGui
FreeCADGui.ActiveDocument.activeView().viewAxonometric()
FreeCADGui.SendMsgToActiveView("ViewFit")

# analysis
analysis = ObjectsFem.makeAnalysis(doc, "Analysis")

# 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"
material_object.Material = mat

# mesh
# from .meshes.mesh_canticcx_tetra10 import create_nodes, create_elements
from femtest.data.ccx.cube_mesh import create_nodes_cube as create_nodes
from femtest.data.ccx.cube_mesh import create_elements_cube 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


def setup_static(doc=None, solver="ccxtools"):
# setup box static, add a fixed, force and a pressure constraint

doc = setup_base(doc, solver)
box_obj = doc.Box
analysis = 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]
elif solver == "ccxtools":
solver_object = analysis.addObject(
ObjectsFem.makeSolverCalculixCcxTools(doc, "CalculiXccxTools")
)[0]
solver_object.WorkingDir = u""
elif solver == "elmer":
analysis.addObject(ObjectsFem.makeSolverElmer(doc, "SolverElmer"))
elif solver == "z88":
analysis.addObject(ObjectsFem.makeSolverZ88(doc, "SolverZ88"))
if solver == "calculix" or solver == "ccxtools":
solver_object.AnalysisType = "static"
solver_object.GeometricalNonlinearity = "linear"
solver_object.ThermoMechSteadyState = False
solver_object.MatrixSolverType = "default"
solver_object.IterationsControlParameterTimeUse = False

# fixed_constraint
fixed_constraint = analysis.addObject(
ObjectsFem.makeConstraintFixed(doc, name="FemConstraintFixed")
)[0]
fixed_constraint.References = [(box_obj, "Face1")]

# force_constraint
force_constraint = analysis.addObject(
ObjectsFem.makeConstraintForce(doc, name="FemConstraintForce")
)[0]
force_constraint.References = [(box_obj, "Face6")]
force_constraint.Force = 40000.0
force_constraint.Direction = (box_obj, ["Edge5"])
force_constraint.Reversed = True

# pressure_constraint
pressure_constraint = analysis.addObject(
ObjectsFem.makeConstraintPressure(doc, name="FemConstraintPressure")
)[0]
pressure_constraint.References = [(box_obj, "Face2")]
pressure_constraint.Pressure = 1000.0
pressure_constraint.Reversed = False

doc.recompute()
return doc


def setup_frequency(doc=None, solver="ccxtools"):
# setup box frequency, change solver attributes

doc = setup_base(doc, solver)
analysis = 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]
elif solver == "ccxtools":
solver_object = analysis.addObject(
ObjectsFem.makeSolverCalculixCcxTools(doc, "CalculiXccxTools")
)[0]
solver_object.WorkingDir = u""
if solver == "calculix" or solver == "ccxtools":
solver_object.AnalysisType = "frequency"
solver_object.GeometricalNonlinearity = "linear"
solver_object.ThermoMechSteadyState = False
solver_object.MatrixSolverType = "default"
solver_object.IterationsControlParameterTimeUse = False
solver_object.EigenmodesCount = 10
solver_object.EigenmodeHighLimit = 1000000.0
solver_object.EigenmodeLowLimit = 0.01

doc.recompute()
return doc


"""
from femexamples import boxanalysis as box
box.setup_base()
box.setup_static()
box.setup_frequency()
"""

0 comments on commit 3acb7d9

Please sign in to comment.