From 3fdd7dc2607acfa31ffe0a207e65f24d5014c259 Mon Sep 17 00:00:00 2001 From: Sudhanshu Dubey Date: Mon, 22 Jun 2020 13:08:49 +0200 Subject: [PATCH] FEM: examples, ccx_cantilever_std separated into 4 examples --- src/Mod/Fem/CMakeLists.txt | 5 +- ...ever_std.py => ccx_cantilever_faceload.py} | 73 +------------------ .../ccx_cantilever_hexa20faceload.py | 65 +++++++++++++++++ .../femexamples/ccx_cantilever_nodeload.py | 69 ++++++++++++++++++ .../ccx_cantilever_prescribeddisplacement.py | 64 ++++++++++++++++ src/Mod/Fem/femexamples/manager.py | 13 ++-- 6 files changed, 212 insertions(+), 77 deletions(-) rename src/Mod/Fem/femexamples/{ccx_cantilever_std.py => ccx_cantilever_faceload.py} (69%) create mode 100644 src/Mod/Fem/femexamples/ccx_cantilever_hexa20faceload.py create mode 100644 src/Mod/Fem/femexamples/ccx_cantilever_nodeload.py create mode 100644 src/Mod/Fem/femexamples/ccx_cantilever_prescribeddisplacement.py diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index 06143578db..241704926e 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -44,7 +44,10 @@ SET(FemExamples_SRCS femexamples/__init__.py femexamples/boxanalysis_static.py femexamples/boxanalysis_frequency.py - femexamples/ccx_cantilever_std.py + femexamples/ccx_cantilever_faceload.py + femexamples/ccx_cantilever_nodeload.py + femexamples/ccx_cantilever_hexa20faceload.py + femexamples/ccx_cantilever_prescribeddisplacement.py femexamples/constraint_contact_shell_shell.py femexamples/constraint_contact_solid_solid.py femexamples/constraint_tie.py diff --git a/src/Mod/Fem/femexamples/ccx_cantilever_std.py b/src/Mod/Fem/femexamples/ccx_cantilever_faceload.py similarity index 69% rename from src/Mod/Fem/femexamples/ccx_cantilever_std.py rename to src/Mod/Fem/femexamples/ccx_cantilever_faceload.py index 3d8ea7d1bf..bcacbfb6ed 100644 --- a/src/Mod/Fem/femexamples/ccx_cantilever_std.py +++ b/src/Mod/Fem/femexamples/ccx_cantilever_faceload.py @@ -23,13 +23,9 @@ # to run the example use: """ -from femexamples import ccx_cantilever_std as canti +from femexamples import ccx_cantilever_faceload as canti -canti.setup_cantileverbase() -canti.setup_cantileverfaceload() -canti.setup_cantilevernodeload() -canti.setup_cantileverprescribeddisplacement() -canti.setup_cantileverhexa20faceload() +canti.setup() """ @@ -125,7 +121,7 @@ def setup_cantileverbase(doc=None, solvertype="ccxtools"): return doc -def setup_cantileverfaceload(doc=None, solvertype="ccxtools"): +def setup(doc=None, solvertype="ccxtools"): # setup CalculiX cantilever, apply 9 MN on surface of front end face doc = setup_cantileverbase(doc, solvertype) @@ -141,66 +137,3 @@ def setup_cantileverfaceload(doc=None, solvertype="ccxtools"): doc.recompute() return doc - - -def setup_cantilevernodeload(doc=None, solvertype="ccxtools"): - # setup CalculiX cantilever, apply 9 MN on the 4 nodes of the front end face - - doc = setup_cantileverbase(doc, solvertype) - - # force_constraint - force_constraint = doc.Analysis.addObject( - ObjectsFem.makeConstraintForce(doc, name="ConstraintForce") - )[0] - # should be possible in one tuple too - force_constraint.References = [ - (doc.Box, "Vertex5"), - (doc.Box, "Vertex6"), - (doc.Box, "Vertex7"), - (doc.Box, "Vertex8") - ] - force_constraint.Force = 9000000.0 - force_constraint.Direction = (doc.Box, ["Edge5"]) - force_constraint.Reversed = True - - doc.recompute() - return doc - - -def setup_cantileverprescribeddisplacement(doc=None, solvertype="ccxtools"): - # setup CalculiX cantilever - # apply a prescribed displacement of 250 mm in -z on the front end face - - doc = setup_cantileverbase(doc, solvertype) - - # displacement_constraint - displacement_constraint = doc.Analysis.addObject( - ObjectsFem.makeConstraintDisplacement(doc, name="ConstraintDisplacmentPrescribed") - )[0] - displacement_constraint.References = [(doc.Box, "Face2")] - displacement_constraint.zFix = False - displacement_constraint.zFree = False - displacement_constraint.zDisplacement = -250.0 - - doc.recompute() - return doc - - -def setup_cantileverhexa20faceload(doc=None, solvertype="ccxtools"): - doc = setup_cantileverfaceload(doc, solvertype) - - # load the hexa20 mesh - from .meshes.mesh_canticcx_hexa20 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") - - # overwrite mesh with the hexa20 mesh - doc.getObject(mesh_name).FemMesh = fem_mesh - - doc.recompute() - return doc diff --git a/src/Mod/Fem/femexamples/ccx_cantilever_hexa20faceload.py b/src/Mod/Fem/femexamples/ccx_cantilever_hexa20faceload.py new file mode 100644 index 0000000000..1dd4fa2d7f --- /dev/null +++ b/src/Mod/Fem/femexamples/ccx_cantilever_hexa20faceload.py @@ -0,0 +1,65 @@ +# *************************************************************************** +# * Copyright (c) 2019 Bernd Hahnebach * +# * Copyright (c) 2020 Sudhanshu Dubey * +# * * +# * 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 * +# * * +# *************************************************************************** + +# to run the example use: +""" +from femexamples import ccx_cantilever_hexa20faceload as canti + +canti.setup() + +""" + +import FreeCAD + +import Fem + +from . import ccx_cantilever_faceload as faceload + +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, solvertype="ccxtools"): + doc = faceload.setup(doc, solvertype) + + # load the hexa20 mesh + from .meshes.mesh_canticcx_hexa20 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") + + # overwrite mesh with the hexa20 mesh + doc.getObject(mesh_name).FemMesh = fem_mesh + + doc.recompute() + return doc diff --git a/src/Mod/Fem/femexamples/ccx_cantilever_nodeload.py b/src/Mod/Fem/femexamples/ccx_cantilever_nodeload.py new file mode 100644 index 0000000000..d65532136a --- /dev/null +++ b/src/Mod/Fem/femexamples/ccx_cantilever_nodeload.py @@ -0,0 +1,69 @@ +# *************************************************************************** +# * Copyright (c) 2019 Bernd Hahnebach * +# * Copyright (c) 2020 Sudhanshu Dubey * +# * * +# * 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 * +# * * +# *************************************************************************** + +# to run the example use: +""" +from femexamples import ccx_cantilever_nodeload as canti + +canti.setup() + +""" + +import FreeCAD + +import ObjectsFem + +from .ccx_cantilever_faceload import setup_cantileverbase + +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, solvertype="ccxtools"): + # setup CalculiX cantilever, apply 9 MN on the 4 nodes of the front end face + + doc = setup_cantileverbase(doc, solvertype) + + # force_constraint + force_constraint = doc.Analysis.addObject( + ObjectsFem.makeConstraintForce(doc, name="ConstraintForce") + )[0] + # should be possible in one tuple too + force_constraint.References = [ + (doc.Box, "Vertex5"), + (doc.Box, "Vertex6"), + (doc.Box, "Vertex7"), + (doc.Box, "Vertex8") + ] + force_constraint.Force = 9000000.0 + force_constraint.Direction = (doc.Box, ["Edge5"]) + force_constraint.Reversed = True + + doc.recompute() + return doc diff --git a/src/Mod/Fem/femexamples/ccx_cantilever_prescribeddisplacement.py b/src/Mod/Fem/femexamples/ccx_cantilever_prescribeddisplacement.py new file mode 100644 index 0000000000..72c50d1737 --- /dev/null +++ b/src/Mod/Fem/femexamples/ccx_cantilever_prescribeddisplacement.py @@ -0,0 +1,64 @@ +# *************************************************************************** +# * Copyright (c) 2019 Bernd Hahnebach * +# * Copyright (c) 2020 Sudhanshu Dubey * +# * * +# * 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 * +# * * +# *************************************************************************** + +# to run the example use: +""" +from femexamples import ccx_cantilever_prescribeddisplacement as canti + +canti.setup() + +""" + +import FreeCAD + +import ObjectsFem + +from .ccx_cantilever_faceload import setup_cantileverbase + +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, solvertype="ccxtools"): + # setup CalculiX cantilever + # apply a prescribed displacement of 250 mm in -z on the front end face + + doc = setup_cantileverbase(doc, solvertype) + + # displacement_constraint + displacement_constraint = doc.Analysis.addObject( + ObjectsFem.makeConstraintDisplacement(doc, name="ConstraintDisplacmentPrescribed") + )[0] + displacement_constraint.References = [(doc.Box, "Face2")] + displacement_constraint.zFix = False + displacement_constraint.zFree = False + displacement_constraint.zDisplacement = -250.0 + + doc.recompute() + return doc diff --git a/src/Mod/Fem/femexamples/manager.py b/src/Mod/Fem/femexamples/manager.py index f52e526265..a552cc085a 100644 --- a/src/Mod/Fem/femexamples/manager.py +++ b/src/Mod/Fem/femexamples/manager.py @@ -32,7 +32,7 @@ doc = run_boxanalysisfrequency() doc = run_ccx_cantileverfaceload() doc = run_ccx_cantilevernodeload() doc = run_ccx_cantileverprescribeddisplacement() -doc = setup_cantileverhexa20faceload() +doc = run_ccx_cantilever_hexa20faceload() doc = run_constraint_contact_shell_shell() doc = run_constraint_contact_solid_solid() doc = run_constraint_tie() @@ -130,7 +130,7 @@ def run_boxanalysisfrequency(solver=None, base_name=None): def run_ccx_cantileverfaceload(solver=None, base_name=None): - from .ccx_cantilever_std import setup_cantileverfaceload as setup + from .ccx_cantilever_faceload import setup doc = setup() if base_name is None: @@ -145,7 +145,7 @@ def run_ccx_cantileverfaceload(solver=None, base_name=None): def run_ccx_cantilevernodeload(solver=None, base_name=None): - from .ccx_cantilever_std import setup_cantilevernodeload as setup + from .ccx_cantilever_nodeload import setup doc = setup() if base_name is None: @@ -160,7 +160,7 @@ def run_ccx_cantilevernodeload(solver=None, base_name=None): def run_ccx_cantileverprescribeddisplacement(solver=None, base_name=None): - from .ccx_cantilever_std import setup_cantileverprescribeddisplacement as setup + from .ccx_cantilever_prescribeddisplacement import setup doc = setup() if base_name is None: @@ -173,9 +173,9 @@ def run_ccx_cantileverprescribeddisplacement(solver=None, base_name=None): return doc -def setup_cantileverhexa20faceload(solver=None, base_name=None): +def run_ccx_cantilever_hexa20faceload(solver=None, base_name=None): - from .ccx_cantilever_std import setup_cantileverhexa20faceload as setup + from .ccx_cantilever_hexa20faceload import setup doc = setup() if base_name is None: @@ -329,6 +329,7 @@ def run_all(): run_ccx_cantileverfaceload() run_ccx_cantilevernodeload() run_ccx_cantileverprescribeddisplacement() + run_ccx_cantilever_hexa20faceload() run_constraint_contact_shell_shell() run_constraint_contact_solid_solid() run_constraint_tie()