FEM: pep8, more code formatting

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

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