FEM: pep8, more code formatting

This commit is contained in:
Bernd Hahnebach
2023-04-04 00:14:28 +02:00
committed by wwmayer
parent 4fe41c5372
commit 8ea5d9bac1
16 changed files with 44 additions and 42 deletions

View File

@@ -34,7 +34,6 @@ import FreeCADGui
from FreeCAD import Qt
from .manager import CommandManager
from femsolver import settings
from femtools.femutils import expandParentObject
from femtools.femutils import is_of_type
from femsolver.settings import get_default_solver
@@ -72,7 +71,8 @@ class _Analysis(CommandManager):
FreeCAD.ActiveDocument.commitTransaction()
if get_default_solver() != "None":
FreeCAD.ActiveDocument.openTransaction("Create default solver")
FreeCADGui.doCommand("ObjectsFem.makeSolver{}(FreeCAD.ActiveDocument)"
FreeCADGui.doCommand(
"ObjectsFem.makeSolver{}(FreeCAD.ActiveDocument)"
.format(get_default_solver())
)
FreeCADGui.doCommand(

View File

@@ -23,11 +23,8 @@
import sys
import FreeCAD
from FreeCAD import Placement
from FreeCAD import Rotation
from FreeCAD import Vector
import Draft
import ObjectsFem
import Part
import Sketcher

View File

@@ -182,7 +182,9 @@ def setup(doc=None, solvertype="elmer"):
# constraint inlet velocity
FlowVelocity_Inlet = ObjectsFem.makeConstraintFlowVelocity(doc, "FlowVelocity_Inlet")
FlowVelocity_Inlet.References = [(BooleanFragments, "Edge5")]
FlowVelocity_Inlet.VelocityXFormula = "Variable Coordinate 2; Real MATC \"10*(tx+50e-3)*(50e-3-tx)\""
FlowVelocity_Inlet.VelocityXFormula = (
"Variable Coordinate 2; Real MATC \"10*(tx+50e-3)*(50e-3-tx)\""
)
FlowVelocity_Inlet.VelocityXUnspecified = False
FlowVelocity_Inlet.VelocityXHasFormula = True
FlowVelocity_Inlet.VelocityYUnspecified = False

View File

@@ -188,7 +188,9 @@ def setup(doc=None, solvertype="elmer"):
# constraint inlet velocity
FlowVelocity_Inlet = ObjectsFem.makeConstraintFlowVelocity(doc, "FlowVelocity_Inlet")
FlowVelocity_Inlet.References = [(BooleanFragments, "Edge5")]
FlowVelocity_Inlet.VelocityXFormula = "Variable Coordinate 2; Real MATC \"10*(tx+50e-3)*(50e-3-tx)\""
FlowVelocity_Inlet.VelocityXFormula = (
"Variable Coordinate 2; Real MATC \"10*(tx+50e-3)*(50e-3-tx)\""
)
FlowVelocity_Inlet.VelocityXUnspecified = False
FlowVelocity_Inlet.VelocityXHasFormula = True
FlowVelocity_Inlet.VelocityYUnspecified = False

View File

@@ -85,8 +85,8 @@ def setup(doc=None, solvertype="elmer"):
# solver
if solvertype == "elmer":
solver_obj = ObjectsFem.makeSolverElmer(doc, "SolverElmer")
equation_electrostatic = ObjectsFem.makeEquationElectrostatic(doc, solver_obj)
equation_heat = ObjectsFem.makeEquationHeat(doc, solver_obj)
ObjectsFem.makeEquationElectrostatic(doc, solver_obj)
ObjectsFem.makeEquationHeat(doc, solver_obj)
equation_flux_potential = ObjectsFem.makeEquationFlux(doc, solver_obj)
equation_flux_temperature = ObjectsFem.makeEquationFlux(doc, solver_obj)
else:

View File

@@ -23,8 +23,6 @@
import sys
import FreeCAD
from FreeCAD import Placement
from FreeCAD import Rotation
from FreeCAD import Vector
import Draft

View File

@@ -23,8 +23,6 @@
import sys
import FreeCAD
from FreeCAD import Rotation
from FreeCAD import Vector
import Fem
import ObjectsFem

View File

@@ -25,7 +25,7 @@ __title__ = "FreeCAD FEM calculix constraint initialtemperature"
__author__ = "Bernd Hahnebach"
__url__ = "https://www.freecadweb.org"
import FreeCAD
from FreeCAD import Units
def get_analysis_types():
@@ -48,12 +48,10 @@ def write_constraint(f, femobj, inittemp_obj, ccxwriter):
# floats read from ccx should use {:.13G}, see comment in writer module
f.write(
"{},{}\n".format(
ccxwriter.ccx_nall,
FreeCAD.Units.Quantity(inittemp_obj.initialTemperature.getValueAs("K"))
)
)
f.write("{},{}\n".format(
ccxwriter.ccx_nall,
Units.Quantity(inittemp_obj.initialTemperature.getValueAs("K"))
))
# Should only be one object in the analysis

View File

@@ -26,8 +26,6 @@ __author__ = "Bernd Hahnebach"
__url__ = "https://www.freecadweb.org"
def write_femelement_matgeosets(f, ccxwriter):
# write mat_geo_sets to file

View File

@@ -95,7 +95,10 @@ class Heatwriter:
i = -1
for obj in self.write.getMember("Fem::ConstraintTemperature"):
i = i + 1
femobjects = membertools.get_several_member(self.write.analysis, "Fem::ConstraintTemperature")
femobjects = membertools.get_several_member(
self.write.analysis,
"Fem::ConstraintTemperature"
)
femobjects[i]["Nodes"] = meshtools.get_femnodes_by_femobj_with_references(
self.write.getSingleMember("Fem::FemMeshObject").FemMesh,
femobjects[i]

View File

@@ -107,7 +107,7 @@ class MgDyn2Dwriter:
def handleMagnetodynamic2DMaterial(self, bodies):
# check that all bodies have a set material
for name in bodies:
if self.write.getBodyMaterial(name) == None:
if self.write.getBodyMaterial(name) is None:
raise general_writer.WriteError(
"The body {} is not referenced in any material.\n\n".format(name)
)

View File

@@ -132,7 +132,7 @@ class MgDynwriter:
def handleMagnetodynamicMaterial(self, bodies):
# check that all bodies have a set material
for name in bodies:
if self.write.getBodyMaterial(name) == None:
if self.write.getBodyMaterial(name) is None:
raise general_writer.WriteError(
"The body {} is not referenced in any material.\n\n".format(name)
)
@@ -219,7 +219,7 @@ class MgDynwriter:
# check for PotentialEnabled not Potential since PotentialEnabled was
# added later and only with this the imaginary property is available
if obj.PotentialEnabled:
# output only if potential is enabled and needed
# output only if potential is enabled and needed
potential = float(obj.Potential.getValueAs("V"))
self.write.bodyForce(name, "Electric Potential", round(potential, 6))
# imaginary is only needed for harmonic equation

View File

@@ -354,8 +354,10 @@ class Results(run.Results):
def _finishTimeResults(self, time, counter):
# we purposely use the decimal dot in the label
self.solver.ElmerTimeResults[counter].Label\
= self.solver.Name + "_" + str(time) + "_" + "Result"
self.solver.ElmerTimeResults[counter].Label = (
"{}_{}_Result"
.format(self.solver.Name, time)
)
self.solver.ElmerTimeResults[counter].ViewObject.OnTopWhenSelected = True
self.analysis.addObject(self.solver.ElmerTimeResults[counter])
# to assure the user sees something, set the default to Surface

View File

@@ -322,10 +322,13 @@ class Writer(object):
self._updateSimulation(self.solver)
# output the equation parameters
# first check what equations we have
hasHeat = False
for equation in self.solver.Group:
if femutils.is_of_type(equation, "Fem::EquationElmerHeat"):
hasHeat = True
# hasHeat ist not used, thus commented ATM
# hasHeat = False
# for equation in self.solver.Group:
# if femutils.is_of_type(equation, "Fem::EquationElmerHeat"):
# hasHeat = True
self._simulation("Coordinate System", self.solver.CoordinateSystem)
self._simulation("Coordinate Mapping", (1, 2, 3))
# Elmer uses SI base units, but our mesh is in mm, therefore we must tell
@@ -615,7 +618,7 @@ class Writer(object):
else:
activeIn = self.getAllBodies()
# Magnetodynamic2D cannot handle all coordinate sysytems
if self.solver.CoordinateSystem in _COORDS_NON_MAGNETO_2D :
if self.solver.CoordinateSystem in _COORDS_NON_MAGNETO_2D:
raise WriteError(
"The coordinate setting '{}'\n is not "
"supported by the equation 'Magnetodynamic2D'.\n\n"
@@ -737,7 +740,7 @@ class Writer(object):
for obj in self.getMember("App::MaterialObject"):
m = obj.Material
# fluid material always has KinematicViscosity defined
if not "KinematicViscosity" in m:
if "KinematicViscosity" not in m:
return True
return False

View File

@@ -73,13 +73,15 @@ class _TaskPanel(object):
self._meshVisible = None
# start with vector inputs hidden if no vector is set
if self._obj.AV_re_1_Disabled and \
self._obj.AV_re_2_Disabled and \
self._obj.AV_re_3_Disabled and \
self._obj.AV_im_Disabled and \
self._obj.AV_im_1_Disabled and \
self._obj.AV_im_2_Disabled and \
self._obj.AV_im_3_Disabled:
if (
self._obj.AV_re_1_Disabled
and self._obj.AV_re_2_Disabled
and self._obj.AV_re_3_Disabled
and self._obj.AV_im_Disabled
and self._obj.AV_im_1_Disabled
and self._obj.AV_im_2_Disabled
and self._obj.AV_im_3_Disabled
):
self._vectorField_visibility(False)
self._paramWidget.vectorFieldBox.setChecked(False)
QtCore.QObject.connect(

View File

@@ -34,7 +34,6 @@ from PySide import QtCore
import FreeCAD
import FreeCADGui
from FreeCAD import Units
from femguiutils import selection_widgets
from femtools import femutils