FEM: code formating

This commit is contained in:
Bernd Hahnebach
2021-06-09 08:01:55 +02:00
parent 0ad5a0f735
commit 1bea75d62b
3 changed files with 46 additions and 32 deletions

View File

@@ -1,7 +1,6 @@
# *************************************************************************** # ***************************************************************************
# * Copyright (c) 2019 Bernd Hahnebach <bernd@bimstatik.org> *
# * Copyright (c) 2020 Sudhanshu Dubey <sudhanshu.thethunder@gmail.com> *
# * Copyright (c) 2021 Tobias Vaara <t@vaara.se> * # * Copyright (c) 2021 Tobias Vaara <t@vaara.se> *
# * Copyright (c) 2021 Bernd Hahnebach <bernd@bimstatik.org> *
# * * # * *
# * This file is part of the FreeCAD CAx development system. * # * This file is part of the FreeCAD CAx development system. *
# * * # * *
@@ -44,23 +43,24 @@ import ObjectsFem
mesh_name = "Mesh" # needs to be Mesh to work with unit tests mesh_name = "Mesh" # needs to be Mesh to work with unit tests
# Example geometry input # Example geometry input
example_b = 1.5 # Width
b = 1.5 # Width example_h = 8 # Height
h = 8 # Height example_l = 1 # Length
l = 1 # Length
def addbox( def addbox(
docxx, height, width, length, docxx, height, width, length,
x, y, z, box_name): x, y, z, box_name):
box_obj = docxx.addObject('Part::Box', box_name) box_obj = docxx.addObject("Part::Box", box_name)
box_obj.Height = height box_obj.Height = height
box_obj.Width = width box_obj.Width = width
box_obj.Length = length box_obj.Length = length
box_obj.Placement = FreeCAD.Placement( box_obj.Placement = FreeCAD.Placement(
FreeCAD.Vector(x, y, z), FreeCAD.Vector(x, y, z),
FreeCAD.Rotation(0, 0, 0)) FreeCAD.Rotation(0, 0, 0)
)
return box_obj
def init_doc(doc=None): def init_doc(doc=None):
@@ -70,14 +70,15 @@ def init_doc(doc=None):
def get_information(): def get_information():
info = {"name": "Flexural Buckling Analysis", info = {
"meshtype": "solid", "name": "Flexural Buckling Analysis",
"meshelement": "Hexa8", "meshtype": "solid",
"constraints": ["force", "displacement"], "meshelement": "Hexa8",
"solvers": ["calculix"], "constraints": ["force", "displacement"],
"material": "solid", "solvers": ["calculix"],
"equation": "mechanical" "material": "solid",
} "equation": "mechanical"
}
return info return info
@@ -87,12 +88,8 @@ def setup_base(doc=None, solvertype="ccxtools"):
if doc is None: if doc is None:
doc = init_doc() doc = init_doc()
addbox(doc, h, b, l, 0, 0, 0, 'beam') geom_obj = addbox(doc, example_h, example_b, example_l, 0, 0, 0, "beam")
doc.recompute() doc.recompute()
geom_obj = doc.beam
if FreeCAD.GuiUp: if FreeCAD.GuiUp:
geom_obj.ViewObject.Document.activeView().viewAxonometric() geom_obj.ViewObject.Document.activeView().viewAxonometric()
geom_obj.ViewObject.Document.activeView().fitAll() geom_obj.ViewObject.Document.activeView().fitAll()
@@ -123,12 +120,11 @@ def setup_base(doc=None, solvertype="ccxtools"):
femmesh_obj.FemMesh = fem_mesh femmesh_obj.FemMesh = fem_mesh
femmesh_obj.Part = doc.beam femmesh_obj.Part = doc.beam
return doc return doc
def setup(doc=None, solvertype="ccxtools"): def setup(doc=None, solvertype="ccxtools"):
#setup # setup
doc = setup_base(doc, solvertype) doc = setup_base(doc, solvertype)
@@ -174,4 +170,3 @@ def setup(doc=None, solvertype="ccxtools"):
doc.recompute() doc.recompute()
return doc return doc

View File

@@ -880,7 +880,11 @@ class FemInputWriterCcx(writerbase.FemInputWriter):
def write_constraints_selfweight(self, f): def write_constraints_selfweight(self, f):
if not self.selfweight_objects: if not self.selfweight_objects:
return return
if not (self.analysis_type == "static" or self.analysis_type == "thermomech" or self.analysis_type == "buckling"): if not (
self.analysis_type == "static"
or self.analysis_type == "thermomech"
or self.analysis_type == "buckling"
):
return return
# write constraint to file # write constraint to file
@@ -914,7 +918,11 @@ class FemInputWriterCcx(writerbase.FemInputWriter):
def write_constraints_force(self, f, inpfile_split=None): def write_constraints_force(self, f, inpfile_split=None):
if not self.force_objects: if not self.force_objects:
return return
if not (self.analysis_type == "static" or self.analysis_type == "thermomech" or self.analysis_type == "buckling"): if not (
self.analysis_type == "static"
or self.analysis_type == "thermomech"
or self.analysis_type == "buckling"
):
return return
# check shape type of reference shape and get node loads # check shape type of reference shape and get node loads
@@ -963,7 +971,11 @@ class FemInputWriterCcx(writerbase.FemInputWriter):
def write_constraints_pressure(self, f, inpfile_split=None): def write_constraints_pressure(self, f, inpfile_split=None):
if not self.pressure_objects: if not self.pressure_objects:
return return
if not (self.analysis_type == "static" or self.analysis_type == "thermomech" or self.analysis_type == "buckling"): if not (
self.analysis_type == "static"
or self.analysis_type == "thermomech"
or self.analysis_type == "buckling"
):
return return
# get the faces and face numbers # get the faces and face numbers
@@ -1176,7 +1188,11 @@ class FemInputWriterCcx(writerbase.FemInputWriter):
if self.solver_obj.IterationsThermoMechMaximum: if self.solver_obj.IterationsThermoMechMaximum:
if self.analysis_type == "thermomech": if self.analysis_type == "thermomech":
step += ", INC=" + str(self.solver_obj.IterationsThermoMechMaximum) step += ", INC=" + str(self.solver_obj.IterationsThermoMechMaximum)
elif self.analysis_type == "static" or self.analysis_type == "frequency" or self.analysis_type == "buckling": elif (
self.analysis_type == "static"
or self.analysis_type == "frequency"
or self.analysis_type == "buckling"
):
# parameter is for thermomechanical analysis only, see ccx manual *STEP # parameter is for thermomechanical analysis only, see ccx manual *STEP
pass pass
# write step line # write step line
@@ -1230,7 +1246,11 @@ class FemInputWriterCcx(writerbase.FemInputWriter):
# Set time to 1 and ignore user inputs for steady state # Set time to 1 and ignore user inputs for steady state
self.solver_obj.TimeInitialStep = 1.0 self.solver_obj.TimeInitialStep = 1.0
self.solver_obj.TimeEnd = 1.0 self.solver_obj.TimeEnd = 1.0
elif self.analysis_type == "static" or self.analysis_type == "frequency" or self.analysis_type == "buckling": elif (
self.analysis_type == "static"
or self.analysis_type == "frequency"
or self.analysis_type == "buckling"
):
pass # not supported for static and frequency! pass # not supported for static and frequency!
# ANALYSIS parameter line # ANALYSIS parameter line
analysis_parameter = "" analysis_parameter = ""

View File

@@ -396,4 +396,3 @@ class _TaskPanel:
def select_buckling_analysis(self): def select_buckling_analysis(self):
self.select_analysis_type("buckling") self.select_analysis_type("buckling")