FEM: python code formatting

This commit is contained in:
Bernd Hahnebach
2022-07-31 23:45:55 +02:00
parent 61684dba50
commit 5d4b753940
13 changed files with 34 additions and 25 deletions

View File

@@ -62,8 +62,12 @@ FreeCAD.addExportType("FEM mesh Python (*.meshpy)", "feminout.importPyMesh")
FreeCAD.addExportType("FEM mesh TetGen (*.poly)", "feminout.convert2TetGen")
# see FemMesh::read() and FemMesh::write() methods in src/Mod/Fem/App/FemMesh.cpp
FreeCAD.addImportType("FEM mesh formats (*.bdf *.dat *.inp *.med *.unv *.vtk *.vtu *.pvtu *.z88)", "Fem")
FreeCAD.addExportType("FEM mesh formats (*.dat *.inp *.med *.stl *.unv *.vtk *.vtu *.z88)", "Fem")
FreeCAD.addImportType(
"FEM mesh formats (*.bdf *.dat *.inp *.med *.unv *.vtk *.vtu *.pvtu *.z88)", "Fem"
)
FreeCAD.addExportType(
"FEM mesh formats (*.dat *.inp *.med *.stl *.unv *.vtk *.vtu *.z88)", "Fem"
)
FreeCAD.addExportType("FEM mesh Nastran (*.bdf)", "feminout.exportNastranMesh")

View File

@@ -30,8 +30,6 @@ __url__ = "https://www.freecadweb.org"
# \ingroup FEM
# \brief FreeCAD FEM FemSelectWidget
import sys
from PySide import QtGui
from PySide import QtCore

View File

@@ -78,7 +78,7 @@ class Proxy(linear.Proxy):
# forum thread: https://forum.freecadweb.org/viewtopic.php?p=613897#p613897
obj.setExpression('NonlinearTolerance', "1e-8")
obj.setExpression('NonlinearNewtonAfterTolerance', "1e-3")
obj.setExpression('RelaxationFactor', "1.0") # must often be < 1 down to 0.01
obj.setExpression('RelaxationFactor', "1.0") # must often be < 1 down to 0.01
class ViewProxy(linear.ViewProxy):

View File

@@ -194,9 +194,11 @@ class Solve(run.Solve):
FrequencyList = []
for line in OutputList:
LineList = line.split(" ")
if (len(LineList) > 1) \
and (LineList[0] == "EigenSolve:") \
and (LineList[1] == "Computed"):
if (
len(LineList) > 1
and LineList[0] == "EigenSolve:"
and LineList[1] == "Computed"
):
# we found a result and take now the next LineList[2] lines
modeCount = int(LineList[2])
modeNumber = modeCount
@@ -217,8 +219,9 @@ class Solve(run.Solve):
# now we can perform the calculation
eigenFreq = cmath.sqrt(eigenFreq) / (2 * cmath.pi)
# create an output line
FrequencyList.append("Mode " + str(modeNumber - modeCount + 1) \
+ ": " + str(eigenFreq.real) + " Hz")
FrequencyList.append(
"Mode {}: {} Hz".format(modeNumber - modeCount + 1, eigenFreq.real)
)
modeCount = modeCount - 1
if modeNumber > 0:
# push the results and append to output
@@ -237,6 +240,7 @@ class Solve(run.Solve):
except ValueError:
return False
class Results(run.Results):
def run(self):

View File

@@ -231,7 +231,7 @@ class Writer(object):
if system() == "Windows":
subprocess.call(
args,
stdout=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
startupinfo=femutils.startProgramInfo("hide")
)
else:
@@ -241,11 +241,11 @@ class Writer(object):
args.extend(["-partdual", "-metiskway", num_cores,
"-out", self.directory])
if system() == "Windows":
subprocess.call(
args,
stdout=subprocess.DEVNULL,
startupinfo=femutils.startProgramInfo("hide")
)
subprocess.call(
args,
stdout=subprocess.DEVNULL,
startupinfo=femutils.startProgramInfo("hide")
)
else:
subprocess.call(args, stdout=subprocess.DEVNULL)
@@ -423,17 +423,23 @@ class Writer(object):
else self._getAllBodies())
for name in (n for n in refs if n in bodies):
if "Density" not in m:
raise WriteError("Used material does not specify the necessary 'Density'.")
raise WriteError(
"Used material does not specify the necessary 'Density'."
)
self._material(
name, "Density",
self._getDensity(m))
if "ThermalConductivity" not in m:
raise WriteError("Used material does not specify the necessary 'Thermal Conductivity'.")
raise WriteError(
"Used material does not specify the necessary 'Thermal Conductivity'."
)
self._material(
name, "Heat Conductivity",
self._convert(m["ThermalConductivity"], "M*L/(T^3*O)"))
if "SpecificHeat" not in m:
raise WriteError("Used material does not specify the necessary 'Specific Heat'.")
raise WriteError(
"Used material does not specify the necessary 'Specific Heat'."
)
self._material(
name, "Heat Capacity",
self._convert(m["SpecificHeat"], "L^2/(T^2*O)"))

View File

@@ -106,6 +106,7 @@ def get_binary(name):
)
return None
def get_cores(name):
""" Read number of CPU cores for solver *name* honoring user settings.

View File

@@ -137,7 +137,7 @@ class _TaskPanel:
# hide some groupBox according to material category
# note: input_fd_vol_expansion_coefficient is currently not used
# it might be used in future for solids
# it might be used in future for solids
self.parameterWidget.label_category.setText(self.obj.Category)
if self.obj.Category == "Fluid":
self.parameterWidget.groupBox_mechanical.setVisible(0)

View File

@@ -41,6 +41,7 @@ import FreeCADGui
import FemGui
def unicode(text, *args):
return str(text)

View File

@@ -25,7 +25,6 @@ __title__ = "Common FEM unit tests"
__author__ = "Bernd Hahnebach"
__url__ = "https://www.freecadweb.org"
import sys
import unittest
import FreeCAD

View File

@@ -25,7 +25,6 @@ __title__ = "Open files FEM App unit tests"
__author__ = "Bernd Hahnebach"
__url__ = "https://www.freecadweb.org"
import sys
import tempfile
import unittest
from os.path import join

View File

@@ -25,7 +25,6 @@ __title__ = "Solver elmer FEM unit tests"
__author__ = "Bernd Hahnebach"
__url__ = "https://www.freecadweb.org"
import sys
import unittest
from os.path import join

View File

@@ -26,7 +26,6 @@ __title__ = "Solver z88 FEM unit tests"
__author__ = "Bernd Hahnebach"
__url__ = "https://www.freecadweb.org"
import sys
import unittest
from os import listdir
from os.path import join

View File

@@ -25,7 +25,6 @@ __title__ = "Open files FEM Gui unit tests"
__author__ = "Bernd Hahnebach"
__url__ = "https://www.freecadweb.org"
import sys
import tempfile
import unittest
from os.path import join