FEM: code formating, flake8

This commit is contained in:
Bernd Hahnebach
2018-11-20 23:25:52 +01:00
committed by Yorik van Havre
parent 3ff1293201
commit bbcc6d0c34
32 changed files with 53 additions and 154 deletions

View File

@@ -30,14 +30,14 @@ __url__ = "http://www.freecadweb.org"
import FreeCAD
########## analysis objects ##########
# ********* analysis objects *********
def makeAnalysis(doc, name="Analysis"):
'''makeAnalysis(document, [name]): makes a Fem Analysis object'''
obj = doc.addObject("Fem::FemAnalysis", name)
return obj
########## constraint objects ##########
# ********* constraint objects *********
def makeConstraintBearing(doc, name="ConstraintBearing"):
'''makeConstraintBearing(document, [name]): makes a Fem ConstraintBearing object'''
obj = doc.addObject("Fem::ConstraintBearing", name)
@@ -177,7 +177,7 @@ def makeConstraintTransform(doc, name="ConstraintTransform"):
return obj
########## element definition objects ##########
# ********* element definition objects *********
def makeElementFluid1D(doc, name="ElementFluid1D"):
'''makeElementFluid1D(document, [name]): creates an 1D fluid element object to define 1D flow'''
obj = doc.addObject("Fem::FeaturePython", name)
@@ -234,7 +234,7 @@ def makeElementRotation1D(doc, name="ElementRotation1D"):
return obj
########## material objects ##########
# ********* material objects *********
def makeMaterialFluid(doc, name="FluidMaterial"):
'''makeMaterialFluid(document, [name]): makes a FEM Material for fluid'''
obj = doc.addObject("App::MaterialObjectPython", name)
@@ -271,7 +271,7 @@ def makeMaterialSolid(doc, name="MechanicalSolidMaterial"):
return obj
########## mesh objects ##########
# ********* mesh objects *********
def makeMeshBoundaryLayer(doc, base_mesh, name="MeshBoundaryLayer"):
'''makeMeshBoundaryLayer(document, base_mesh, [name]): creates a FEM mesh BoundaryLayer object to define boundary layer properties'''
obj = doc.addObject("Fem::FeaturePython", name)
@@ -350,7 +350,7 @@ def makeMeshResult(doc, name="FEMMeshResult"):
return obj
########## post processing objects ##########
# ********* post processing objects *********
def makeResultMechanical(doc, name="MechanicalResult"):
'''makeResultMechanical(document, [name]): creates an mechanical result object to hold FEM results'''
obj = doc.addObject('Fem::FemResultObjectPython', name)
@@ -362,7 +362,7 @@ def makeResultMechanical(doc, name="MechanicalResult"):
return obj
########## solver objects ##########
# ********* solver objects *********
def makeEquationElasticity(doc, base_solver):
'''makeEquationElasticity(document, base_solver): creates a FEM elasticity equation for a solver'''
obj = doc.SolverElmer.addObject(doc.SolverElmer.Proxy.createEquation(doc.SolverElmer.Document, 'Elasticity'))[0]

View File

@@ -179,7 +179,7 @@ class _TaskPanelFemMaterial:
# check references, has to be after initialisation of selectionWidget
self.selectionWidget.has_equal_references_shape_types()
################ leave task panel #########################
# ********* leave task panel *********
def accept(self):
# print(self.material)
if self.selectionWidget.has_equal_references_shape_types():
@@ -200,7 +200,7 @@ class _TaskPanelFemMaterial:
FreeCADGui.Selection.removeObserver(self.selectionWidget.sel_server)
doc.resetEdit()
################ choose material #########################
# ********* choose material *********
def get_material_card(self, material):
for a_mat in self.materials:
unmatched_items = set(self.materials[a_mat].items()) ^ set(material.items())
@@ -240,7 +240,7 @@ class _TaskPanelFemMaterial:
self.parameterWidget.cb_materials.addItem(QtGui.QIcon(":/icons/help-browser.svg"), self.card_path, self.card_path)
self.set_transient_material()
################ how to edit a material #########################
# ********* how to edit a material *********
def edit_material(self):
# self.print_material_params()
import MaterialEditor
@@ -274,7 +274,7 @@ class _TaskPanelFemMaterial:
self.parameterWidget.input_fd_kinematic_viscosity.setReadOnly(True)
self.parameterWidget.input_fd_vol_expansion_coefficient.setReadOnly(True)
################ material parameter input fields #########################
# ********* material parameter input fields *********
def print_material_params(self, material=None):
if not material:
material = self.material
@@ -504,7 +504,7 @@ class _TaskPanelFemMaterial:
density_new_unit = "kg/m^3"
density = FreeCAD.Units.Quantity(matmap['Density'])
density_with_new_unit = density.getValueAs(density_new_unit)
#self.parameterWidget.input_fd_density.setText("{} {}".format(density_with_new_unit, density_new_unit))
# self.parameterWidget.input_fd_density.setText("{} {}".format(density_with_new_unit, density_new_unit))
q = FreeCAD.Units.Quantity("{} {}".format(density_with_new_unit, density_new_unit))
self.parameterWidget.input_fd_density.setText(q.UserString)
# thermal properties
@@ -527,7 +527,7 @@ class _TaskPanelFemMaterial:
q = FreeCAD.Units.Quantity("{} {}".format(sh_with_new_unit, sh_new_unit))
self.parameterWidget.input_fd_specific_heat.setText(q.UserString)
######################## material import and export ###################
# ********* material import and export *********
def print_materialsdict(self):
print('\n\n')
for mat_card in self.materials:
@@ -563,8 +563,8 @@ class _TaskPanelFemMaterial:
self.add_cards_from_a_dir(custom_mat_dir, ":/icons/user.svg")
def import_fluid_materials(self):
#use_built_in_materials = self.fem_prefs.GetBool("UseBuiltInMaterials", True)
#if use_built_in_materials:
# use_built_in_materials = self.fem_prefs.GetBool("UseBuiltInMaterials", True)
# if use_built_in_materials:
system_mat_dir = FreeCAD.getResourceDir() + "/Mod/Material/FluidMaterial"
self.add_cards_from_a_dir(system_mat_dir, ":/icons/freecad.svg")

View File

@@ -28,6 +28,7 @@ __url__ = "http://www.freecadweb.org"
# \ingroup FEM
# \brief FreeCAD FEM _ViewProviderFemMeshResult
class _ViewProviderFemMeshResult:
"A View Provider for the FemMeshResult object"
def __init__(self, vobj):

View File

@@ -35,7 +35,7 @@ import os
EIGENVALUE_OUTPUT_SECTION = " E I G E N V A L U E O U T P U T"
########## generic FreeCAD import and export methods ##########
# ********* generic FreeCAD import and export methods *********
if open.__module__ == '__builtin__':
# because we'll redefine open below (Python2)
pyopen = open
@@ -60,7 +60,7 @@ def insert(filename, docname):
import_dat(filename)
########## module specific methods ##########
# ********* module specific methods *********
def import_dat(filename, Analysis=None):
r = readResult(filename)
# print("Results {}".format(r))

View File

@@ -34,7 +34,7 @@ import FreeCAD
import os
########## generic FreeCAD import and export methods ##########
# ********* generic FreeCAD import and export methods *********
if open.__module__ == '__builtin__':
# because we'll redefine open below (Python2)
pyopen = open
@@ -59,7 +59,7 @@ def insert(filename, docname):
importFrd(filename)
########## module specific methods ##########
# ********* module specific methods *********
def importFrd(filename, analysis=None, result_name_prefix=None):
from . import importToolsFem
import ObjectsFem

View File

@@ -19,7 +19,6 @@
# * USA *
# * *
# ***************************************************************************
from __future__ import print_function
__title__ = "FreeCAD Fenics mesh reader and writer"
__author__ = "Johannes Hartung"
@@ -42,7 +41,7 @@ from . import writeFenicsXDMF
# Template copied from importZ88Mesh.py. Thanks Bernd!
########## generic FreeCAD import and export methods ##########
# ********* generic FreeCAD import and export methods *********
if open.__module__ == '__builtin__':
# because we'll redefine open below (Python2)
pyopen = open
@@ -163,6 +162,7 @@ def export(objectslist, fileString):
writeFenicsXDMF.write_fenics_mesh_xdmf(obj, fileString)
# ********* module specific methods *********
def import_fenics_mesh(filename, analysis=None):
'''insert a FreeCAD FEM Mesh object in the ActiveDocument
'''

View File

@@ -33,7 +33,7 @@ import FreeCAD
import os
########## generic FreeCAD import and export methods ##########
# ********* generic FreeCAD import and export methods *********
if open.__module__ == '__builtin__':
# because we'll redefine open below (Python2)
pyopen = open
@@ -58,7 +58,7 @@ def insert(filename, docname):
import_inp(filename)
########## module specific methods ##########
# ********* module specific methods *********
def import_inp(filename):
"create imported objects in FreeCAD, currently only FemMesh"

View File

@@ -35,7 +35,7 @@ import FreeCAD
import Fem
########## generic FreeCAD import and export methods ##########
# ********* generic FreeCAD import and export methods *********
if open.__module__ == '__builtin__':
# because we'll redefine open below (Python2)
pyopen = open
@@ -80,7 +80,7 @@ def export(objectslist, filename):
return
########## module specific methods ##########
# ********* module specific methods *********
def importVtk(filename, object_name=None, object_type=None):
if not object_type:
vtkinout_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/InOutVtk")

View File

@@ -36,7 +36,7 @@ import os
Debug = False
########## generic FreeCAD import and export methods ##########
# ********* generic FreeCAD import and export methods *********
if open.__module__ == '__builtin__':
# because we'll redefine open below (Python2)
pyopen = open
@@ -79,7 +79,7 @@ def export(objectslist, filename):
f.close()
########## module specific methods ##########
# ********* module specific methods *********
def write(fem_mesh, filename):
'''directly write a FemMesh to a Z88 mesh file format
fem_mesh: a FemMesh'''

View File

@@ -35,7 +35,7 @@ import os
Debug = False
########## generic FreeCAD import and export methods ##########
# ********* generic FreeCAD import and export methods *********
if open.__module__ == '__builtin__':
# because we'll redefine open below (Python2)
pyopen = open
@@ -60,7 +60,7 @@ def insert(filename, docname):
import_z88_disp(filename)
########## module specific methods ##########
# ********* module specific methods *********
def import_z88_disp(filename, analysis=None, result_name_prefix=None):
'''insert a FreeCAD FEM mechanical result object in the ActiveDocument
pure usage:

View File

@@ -398,7 +398,7 @@ class GmshTools():
else:
setting['hfar'] = setting['thickness'] # set a value for safety, it may works as background mesh cell size
# from face name -> face id is done in geo file write up
#TODO: fan angle setup is not implemented yet
# TODO: fan angle setup is not implemented yet
if self.dimension == '2':
setting['EdgesList'] = belem_list
elif self.dimension == '3':
@@ -425,7 +425,7 @@ class GmshTools():
v = item[k]
if k in set(['EdgesList', 'FacesList']):
# the element name of FreeCAD which starts with 1 (example: 'Face1'), same as Gmsh
#el_id = int(el[4:]) # FIXME: strip `face` or `edge` prefix
# el_id = int(el[4:]) # FIXME: strip `face` or `edge` prefix
ele_nodes = (''.join((str(el[4:]) + ', ') for el in v)).rstrip(', ')
line = prefix + '.' + str(k) + ' = {' + ele_nodes + ' };\n'
geo.write(line)

View File

@@ -27,6 +27,7 @@ __url__ = "http://www.freecadweb.org"
## \addtogroup FEM
# @{
class Proxy(object):
BaseType = "Fem::ConstraintPython"

View File

@@ -28,7 +28,6 @@ __url__ = "http://www.freecadweb.org"
# \ingroup FEM
# \brief FreeCAD FEM constraint initial flow velocity object
from . import FemConstraint

View File

@@ -28,6 +28,7 @@ __url__ = "http://www.freecadweb.org"
# \ingroup FEM
# \brief FreeCAD FEM constraint self weight object
class _FemConstraintSelfWeight:
"The FemConstraintSelfWeight object"
def __init__(self, obj):

View File

@@ -29,6 +29,7 @@ __url__ = "http://www.freecadweb.org"
# \ingroup FEM
# \brief FreeCAD FEM _FemElementFluid1D
class _FemElementFluid1D:
"The FemElementFluid1D object"

View File

@@ -28,6 +28,7 @@ __url__ = "http://www.freecadweb.org"
# \ingroup FEM
# \brief FreeCAD FEM element geometry 1D object
class _FemElementGeometry1D:
"The FemElementGeometry1D object"

View File

@@ -28,6 +28,7 @@ __url__ = "https://www.freecadweb.org"
# \ingroup FEM
# \brief FreeCAD FEM element geometry 2D object
class _FemElementGeometry2D:
"The FemElementGeometry2D object"
def __init__(self, obj):

View File

@@ -28,6 +28,7 @@ __url__ = "https://www.freecadweb.org"
# \ingroup FEM
# \brief FreeCAD FEM element rotation 1D object
class _FemElementRotation1D:
"The FemElementRotation1D object"

View File

@@ -28,6 +28,7 @@ __url__ = "http://www.freecadweb.org"
# \ingroup FEM
# \brief FEM material
class _FemMaterial:
"The FEM Material object"
def __init__(self, obj):

View File

@@ -28,6 +28,7 @@ __url__ = "http://www.freecadweb.org"
# \ingroup FEM
# \brief FEM nonlinear mechanical material object
class _FemMaterialMechanicalNonlinear:
"The FemMaterialMechanicalNonlinear object"
def __init__(self, obj):

View File

@@ -28,6 +28,7 @@ __url__ = "http://www.freecadweb.org"
# \ingroup FEM
# \brief FEM mesh boundary layer object
class _FemMeshBoundaryLayer:
"The FemMeshBoundaryLayer object"
def __init__(self, obj):

View File

@@ -28,6 +28,7 @@ __url__ = "http://www.freecadweb.org"
# \ingroup FEM
# \brief FreeCAD FEM _FemMeshGmsh
class _FemMeshGmsh():
"""A Fem::FemMeshObject python type, add Gmsh specific properties
"""

View File

@@ -28,6 +28,7 @@ __url__ = "http://www.freecadweb.org"
# \ingroup FEM
# \brief FreeCAD FEM _FemMeshGroup
class _FemMeshGroup:
"The FemMeshGroup object"
def __init__(self, obj):

View File

@@ -28,6 +28,7 @@ __url__ = "http://www.freecadweb.org"
# \ingroup FEM
# \brief FreeCAD FEM _FemMeshRegion
class _FemMeshRegion:
"The FemMeshRegion object"
def __init__(self, obj):

View File

@@ -28,6 +28,7 @@ __url__ = "http://www.freecadweb.org"
# \ingroup FEM
# \brief FreeCAD FEM _FemMeshResult
class _FemMeshResult():
"""The Fem::FemMeshObject's Proxy python type, add Result specific object type
"""

View File

@@ -28,6 +28,7 @@ __url__ = "http://www.freecadweb.org"
# \ingroup FEM
# \brief FreeCAD DocumentObject class to hold mechanical results in FEM workbench
class _FemResultMechanical():
"""The Fem::_FemResultMechanical's Proxy python type, add result specific properties
"""

View File

@@ -308,8 +308,8 @@ class Writer(object):
if activeIn:
self._handleElectrostaticConstants()
self._handleElectrostaticBndConditions()
#self._handleElectrostaticInitial(activeIn)
#self._handleElectrostaticBodyForces(activeIn)
# self._handleElectrostaticInitial(activeIn)
# self._handleElectrostaticBodyForces(activeIn)
self._handleElectrostaticMaterial(activeIn)
def _getElectrostaticSolver(self, equation):
@@ -319,7 +319,7 @@ class Writer(object):
s["Variable"] = self._getUniqueVarName("Potential")
s["Variable DOFs"] = 1
s["Calculate Electric Field"] = equation.CalculateElectricField
#s["Calculate Electric Flux"] = equation.CalculateElectricFlux
# s["Calculate Electric Flux"] = equation.CalculateElectricFlux
s["Calculate Electric Energy"] = equation.CalculateElectricEnergy
s["Calculate Surface Charge"] = equation.CalculateSurfaceCharge
s["Displace mesh"] = False
@@ -552,15 +552,15 @@ class Writer(object):
self._handleFlowConstants()
self._handleFlowBndConditions()
self._handleFlowInitialVelocity(activeIn)
#self._handleFlowInitial(activeIn)
#self._handleFlowBodyForces(activeIn)
# self._handleFlowInitial(activeIn)
# self._handleFlowBodyForces(activeIn)
self._handleFlowMaterial(activeIn)
self._handleFlowEquation(activeIn)
def _getFlowSolver(self, equation):
s = self._createNonlinearSolver(equation)
s["Equation"] = "Navier-Stokes"
#s["Equation"] = equation.Name
# s["Equation"] = equation.Name
s["Procedure"] = sifio.FileAttr("FlowSolve/FlowSolver")
s["Exec Solver"] = "Always"
s["Stabilize"] = equation.Stabilize

View File

@@ -26,6 +26,7 @@ __url__ = "http://www.freecadweb.org"
## \addtogroup FEM
# @{
def notify(signal, *args):
for slot in signal:
slot(*args)

View File

@@ -1,29 +0,0 @@
# ***************************************************************************
# * *
# * Copyright (c) 2017 - Bernd Hahnebach <bernd@bimstatik.org> *
# * *
# * 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 *
# * *
# ***************************************************************************
__title__ = "Fem test cases"
__author__ = "Bernd Hahnebach"
__url__ = "http://www.freecadweb.org"
## @package test_files
# \ingroup Fem
# \brief Fem test cases

View File

@@ -1,29 +0,0 @@
# ***************************************************************************
# * *
# * Copyright (c) 2017 - Bernd Hahnebach <bernd@bimstatik.org> *
# * *
# * 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 *
# * *
# ***************************************************************************
__title__ = "Fem ccx test cases"
__author__ = "Bernd Hahnebach"
__url__ = "http://www.freecadweb.org"
## @package ccx
# \ingroup Fem
# \brief Fem ccx test cases

View File

@@ -1,29 +0,0 @@
# ***************************************************************************
# * *
# * Copyright (c) 2017 - Bernd Hahnebach <bernd@bimstatik.org> *
# * *
# * 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 *
# * *
# ***************************************************************************
__title__ = "Fem ccx test cases"
__author__ = "Bernd Hahnebach"
__url__ = "http://www.freecadweb.org"
## @package ccx
# \ingroup Fem
# \brief Fem ccx test cases

View File

@@ -1,29 +0,0 @@
# ***************************************************************************
# * *
# * Copyright (c) 2017 - Bernd Hahnebach <bernd@bimstatik.org> *
# * *
# * 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 *
# * *
# ***************************************************************************
__title__ = "Fem test cases"
__author__ = "Bernd Hahnebach"
__url__ = "http://www.freecadweb.org"
## @package test_files
# \ingroup Fem
# \brief Fem test cases