From 5e3b10c92fc376de909cf956bd6e4e944168412e Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Thu, 11 Oct 2018 11:10:42 +0200 Subject: [PATCH] FEM: code formating, cut lines with more than 200 diggits --- .../femguiobjects/_ViewProviderFemMaterial.py | 3 +- .../femguiobjects/_ViewProviderFemMeshGmsh.py | 6 ++- src/Mod/Fem/femmesh/gmshtools.py | 6 ++- src/Mod/Fem/femmesh/meshtools.py | 6 ++- src/Mod/Fem/femobjects/_FemElementFluid1D.py | 5 ++- src/Mod/Fem/femobjects/_FemSolverCalculix.py | 9 ++-- src/Mod/Fem/femsolver/calculix/solver.py | 6 ++- src/Mod/Fem/femsolver/calculix/writer.py | 9 ++-- src/Mod/Fem/femtools/ccxtools.py | 43 ++++++++++++++----- 9 files changed, 70 insertions(+), 23 deletions(-) diff --git a/src/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py b/src/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py index 5e4fb12072..12e9185dee 100644 --- a/src/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py +++ b/src/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py @@ -314,7 +314,8 @@ class _TaskPanelFemMaterial: print('KinematicViscosity not found in material data of: ' + self.material['Name']) self.material['KinematicViscosity'] = '0 m^2/s' if 'VolumetricThermalExpansionCoefficient' in self.material: - if 'ThermalExpansionCoefficient' not in str(Units.Unit(self.material['VolumetricThermalExpansionCoefficient'])): # unit type of VolumetricThermalExpansionCoefficient is ThermalExpansionCoefficient + # unit type of VolumetricThermalExpansionCoefficient is ThermalExpansionCoefficient + if 'ThermalExpansionCoefficient' not in str(Units.Unit(self.material['VolumetricThermalExpansionCoefficient'])): print('VolumetricThermalExpansionCoefficient in material data seems to have no unit or a wrong unit (reset the value): ' + self.material['Name']) self.material['VolumetricThermalExpansionCoefficient'] = '0 m/m/K' else: diff --git a/src/Mod/Fem/femguiobjects/_ViewProviderFemMeshGmsh.py b/src/Mod/Fem/femguiobjects/_ViewProviderFemMeshGmsh.py index 86a032ef94..e1e7c75212 100644 --- a/src/Mod/Fem/femguiobjects/_ViewProviderFemMeshGmsh.py +++ b/src/Mod/Fem/femguiobjects/_ViewProviderFemMeshGmsh.py @@ -300,7 +300,11 @@ class _TaskPanelFemMeshGmsh: if self.mesh_obj.MeshRegionList: if part.Shape.ShapeType == "Compound" and hasattr(part, "Proxy"): # other part obj might not have a Proxy, thus an exception would be raised if (part.Proxy.Type == "FeatureBooleanFragments" or part.Proxy.Type == "FeatureSlice" or part.Proxy.Type == "FeatureXOR"): - error_message = "The mesh to shape is a boolean split tools Compound and the mesh has mesh region list. Gmsh could return unexpected meshes in such circumstances. It is strongly recommended to extract the shape to mesh from the Compound and use this one." + error_message = ( + 'The mesh to shape is a boolean split tools Compound and the mesh has mesh region list. ' + 'Gmsh could return unexpected meshes in such circumstances. ' + 'It is strongly recommended to extract the shape to mesh from the Compound and use this one.' + ) QtGui.QMessageBox.critical(None, "Shape to mesh is a BooleanFragmentsCompound and mesh regions are defined", error_message) self.Start = time.time() self.form.l_time.setText('Time: {0:4.1f}: '.format(time.time() - self.Start)) diff --git a/src/Mod/Fem/femmesh/gmshtools.py b/src/Mod/Fem/femmesh/gmshtools.py index 64bff127b1..bc0252a238 100644 --- a/src/Mod/Fem/femmesh/gmshtools.py +++ b/src/Mod/Fem/femmesh/gmshtools.py @@ -295,7 +295,11 @@ class GmshTools(): if self.mesh_obj.MeshRegionList: if part.Shape.ShapeType == "Compound" and hasattr(part, "Proxy"): # other part obj might not have a Proxy, thus an exception would be raised if (part.Proxy.Type == "FeatureBooleanFragments" or part.Proxy.Type == "FeatureSlice" or part.Proxy.Type == "FeatureXOR"): - error_message = " The mesh to shape is a boolean split tools Compound and the mesh has mesh region list. Gmsh could return unexpected meshes in such circumstances. It is strongly recommended to extract the shape to mesh from the Compound and use this one." + error_message = ( + ' The mesh to shape is a boolean split tools Compound and the mesh has mesh region list. ' + 'Gmsh could return unexpected meshes in such circumstances. ' + 'It is strongly recommended to extract the shape to mesh from the Compound and use this one.' + ) FreeCAD.Console.PrintError(error_message + "\n") # TODO: no gui popup because FreeCAD will be in a endless print loop # as long as the pop up is on --> maybe find a better solution for diff --git a/src/Mod/Fem/femmesh/meshtools.py b/src/Mod/Fem/femmesh/meshtools.py index 30fa2bd477..9ce899efd8 100644 --- a/src/Mod/Fem/femmesh/meshtools.py +++ b/src/Mod/Fem/femmesh/meshtools.py @@ -1338,7 +1338,11 @@ def find_element_in_shape(aShape, anElement): return ele FreeCAD.Console.PrintError('Solid ' + str(anElement) + ' not found in: ' + str(aShape) + '\n') if ele_st == 'Solid' and aShape.ShapeType == 'Solid': - print('We have been searching for a Solid in a Solid and we have not found it. In most cases this should be searching for a Solid inside a CompSolid. Check the ShapeType of your Part to mesh.') + messagePart = ( + 'We have been searching for a Solid in a Solid and we have not found it. ' + 'In most cases this should be searching for a Solid inside a CompSolid. Check the ShapeType of your Part to mesh.' + ) + print(messagePart) # Part.show(anElement) # Part.show(aShape) elif ele_st == 'Face' or ele_st == 'Shell': diff --git a/src/Mod/Fem/femobjects/_FemElementFluid1D.py b/src/Mod/Fem/femobjects/_FemElementFluid1D.py index aed662ef63..242853503c 100644 --- a/src/Mod/Fem/femobjects/_FemElementFluid1D.py +++ b/src/Mod/Fem/femobjects/_FemElementFluid1D.py @@ -33,7 +33,10 @@ class _FemElementFluid1D: "The FemElementFluid1D object" known_fluid_types = ['Liquid', 'Gas', 'Open Channel'] - known_liquid_types = ['PIPE MANNING', 'PIPE ENLARGEMENT', 'PIPE CONTRACTION', 'PIPE INLET', 'PIPE OUTLET', 'PIPE ENTRANCE', 'PIPE DIAPHRAGM', 'PIPE BEND', 'PIPE GATE VALVE', 'LIQUID PUMP', 'PIPE WHITE-COLEBROOK'] + known_liquid_types = [ + 'PIPE MANNING', 'PIPE ENLARGEMENT', 'PIPE CONTRACTION', 'PIPE INLET', 'PIPE OUTLET', 'PIPE ENTRANCE', + 'PIPE DIAPHRAGM', 'PIPE BEND', 'PIPE GATE VALVE', 'LIQUID PUMP', 'PIPE WHITE-COLEBROOK' + ] known_gas_types = ['NONE'] known_channel_types = ['NONE'] diff --git a/src/Mod/Fem/femobjects/_FemSolverCalculix.py b/src/Mod/Fem/femobjects/_FemSolverCalculix.py index f5feeaacc0..bb4ceee55f 100644 --- a/src/Mod/Fem/femobjects/_FemSolverCalculix.py +++ b/src/Mod/Fem/femobjects/_FemSolverCalculix.py @@ -76,7 +76,8 @@ class _FemSolverCalculix(): ehl = ccx_prefs.GetFloat("EigenmodeHighLimit", 1000000.0) obj.EigenmodeHighLimit = (ehl, 0.0, 1000000.0, 10000.0) - obj.addProperty("App::PropertyIntegerConstraint", "IterationsThermoMechMaximum", "Fem", "Maximum Number of thermo mechanical iterations in each time step before stopping jobs") + stringIterationsThermoMechMaximum = "Maximum Number of thermo mechanical iterations in each time step before stopping jobs" + obj.addProperty("App::PropertyIntegerConstraint", "IterationsThermoMechMaximum", "Fem", stringIterationsThermoMechMaximum) niter = ccx_prefs.GetInt("AnalysisMaxIterations", 200) obj.IterationsThermoMechMaximum = niter @@ -129,10 +130,12 @@ class _FemSolverCalculix(): obj.addProperty("App::PropertyString", "IterationsControlParameterCutb", "Fem", "User defined time incrementation cutbacks control parameter") obj.IterationsControlParameterCutb = p_cutb - obj.addProperty("App::PropertyBool", "IterationsUserDefinedIncrementations", "Fem", "Set to True to switch off the ccx automatic incrementation completely (ccx parameter DIRECT). Use with care. Analysis may not converge!") + stringIterationsUserDefinedIncrementations = "Set to True to switch off the ccx automatic incrementation completely (ccx parameter DIRECT). Use with care. Analysis may not converge!" + obj.addProperty("App::PropertyBool", "IterationsUserDefinedIncrementations", "Fem", stringIterationsUserDefinedIncrementations) obj.IterationsUserDefinedIncrementations = False - obj.addProperty("App::PropertyBool", "IterationsUserDefinedTimeStepLength", "Fem", "Set to True to use the user defined time steps. The time steps are set with TimeInitialStep and TimeEnd") + infoIterationsUserDefinedTimeStepLength = "Set to True to use the user defined time steps. The time steps are set with TimeInitialStep and TimeEnd" + obj.addProperty("App::PropertyBool", "IterationsUserDefinedTimeStepLength", "Fem", infoIterationsUserDefinedTimeStepLength) obj.IterationsUserDefinedTimeStepLength = False known_ccx_solver_types = ["default", "spooles", "iterativescaling", "iterativecholesky"] diff --git a/src/Mod/Fem/femsolver/calculix/solver.py b/src/Mod/Fem/femsolver/calculix/solver.py index 312e6e8feb..2c40b754fd 100644 --- a/src/Mod/Fem/femsolver/calculix/solver.py +++ b/src/Mod/Fem/femsolver/calculix/solver.py @@ -146,10 +146,12 @@ class Proxy(solverbase.Proxy): obj.addProperty("App::PropertyString", "IterationsControlParameterCutb", "Fem", "User defined time incrementation cutbacks control parameter") obj.IterationsControlParameterCutb = p_cutb - obj.addProperty("App::PropertyBool", "IterationsUserDefinedIncrementations", "Fem", "Set to True to switch off the ccx automatic incrementation completely (ccx parameter DIRECT). Use with care. Analysis may not converge!") + stringIterationsUserDefinedIncrementations = "Set to True to switch off the ccx automatic incrementation completely (ccx parameter DIRECT). Use with care. Analysis may not converge!" + obj.addProperty("App::PropertyBool", "IterationsUserDefinedIncrementations", "Fem", stringIterationsUserDefinedIncrementations) obj.IterationsUserDefinedIncrementations = False - obj.addProperty("App::PropertyBool", "IterationsUserDefinedTimeStepLength", "Fem", "Set to True to use the user defined time steps. The time steps are set with TimeInitialStep and TimeEnd") + stringIterationsUserDefinedTimeStepLength = "Set to True to use the user defined time steps. The time steps are set with TimeInitialStep and TimeEnd" + obj.addProperty("App::PropertyBool", "IterationsUserDefinedTimeStepLength", "Fem", stringIterationsUserDefinedTimeStepLength) obj.IterationsUserDefinedTimeStepLength = False known_ccx_solver_types = ["default", "spooles", "iterativescaling", "iterativecholesky"] diff --git a/src/Mod/Fem/femsolver/calculix/writer.py b/src/Mod/Fem/femsolver/calculix/writer.py index 55d30d5a1f..b8527b37c2 100644 --- a/src/Mod/Fem/femsolver/calculix/writer.py +++ b/src/Mod/Fem/femsolver/calculix/writer.py @@ -992,7 +992,8 @@ class FemInputWriterCcx(FemInputWriter.FemInputWriter): v = self.mesh_object.FemMesh.getccxVolumesByFace(ho) f.write("** Heat flux on face {}\n".format(elem)) for i in v: - f.write("{},F{},{},{}\n".format(i[0], i[1], heatflux_obj.AmbientTemp, heatflux_obj.FilmCoef * 0.001)) # SvdW add factor to force heatflux to units system of t/mm/s/K # OvG: Only write out the VolumeIDs linked to a particular face + # SvdW: add factor to force heatflux to units system of t/mm/s/K # OvG: Only write out the VolumeIDs linked to a particular face + f.write("{},F{},{},{}\n".format(i[0], i[1], heatflux_obj.AmbientTemp, heatflux_obj.FilmCoef * 0.001)) elif heatflux_obj.ConstraintType == "DFlux": f.write('*DFLUX\n') for o, elem_tup in heatflux_obj.References: @@ -1035,7 +1036,8 @@ class FemInputWriterCcx(FemInputWriter.FemInputWriter): for line in lines: b = line.split(',') if int(b[0]) == n and b[3] == 'PIPE INLET\n': - f.write(b[1] + ',1,1,' + str(fluidsection_obj.InletFlowRate * 0.001) + '\n') # degree of freedom 1 is for defining flow rate, factor applied to convert unit from kg/s to t/s + # degree of freedom 1 is for defining flow rate, factor applied to convert unit from kg/s to t/s + f.write(b[1] + ',1,1,' + str(fluidsection_obj.InletFlowRate * 0.001) + '\n') elif fluidsection_obj.LiquidSectionType == 'PIPE OUTLET': f.write('**Fluid Section Outlet \n') if fluidsection_obj.OutletPressureActive is True: @@ -1051,7 +1053,8 @@ class FemInputWriterCcx(FemInputWriter.FemInputWriter): for line in lines: b = line.split(',') if int(b[0]) == n and b[3] == 'PIPE OUTLET\n': - f.write(b[1] + ',1,1,' + str(fluidsection_obj.OutletFlowRate * 0.001) + '\n') # degree of freedom 1 is for defining flow rate, factor applied to convert unit from kg/s to t/s + # degree of freedom 1 is for defining flow rate, factor applied to convert unit from kg/s to t/s + f.write(b[1] + ',1,1,' + str(fluidsection_obj.OutletFlowRate * 0.001) + '\n') def write_outputs_types(self, f): f.write('\n***********************************************************\n') diff --git a/src/Mod/Fem/femtools/ccxtools.py b/src/Mod/Fem/femtools/ccxtools.py index 24796f1cca..411e9495ba 100644 --- a/src/Mod/Fem/femtools/ccxtools.py +++ b/src/Mod/Fem/femtools/ccxtools.py @@ -324,8 +324,12 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject): ref_shty = get_refshape_type(m['Object']) if not mat_ref_shty: mat_ref_shty = ref_shty - if mat_ref_shty and ref_shty and ref_shty != mat_ref_shty: # mat_ref_shty could be empty in one material, only the not empty ones should have the same shape type - message += 'Some material objects do not have the same reference shape type (all material objects must have the same reference shape type, at the moment).\n' + if mat_ref_shty and ref_shty and ref_shty != mat_ref_shty: + # mat_ref_shty could be empty in one material, only the not empty ones should have the same shape type + message += ( + 'Some material objects do not have the same reference shape type ' + '(all material objects must have the same reference shape type, at the moment).\n' + ) for m in self.materials_linear: mat_map = m['Object'].Material mat_obj = m['Object'] @@ -358,9 +362,13 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject): if has_nonlinear_material is False: has_nonlinear_material = True else: - message += "At least two nonlinear materials use the same linear base material. Only one nonlinear material for each linear material allowed.\n" + message += ( + "At least two nonlinear materials use the same linear base material. " + "Only one nonlinear material for each linear material allowed.\n" + ) # which analysis needs which constraints - # no check in the regard of loads existence (constraint force, pressure, self weight) is done because an analysis without loads at all is an valid analysis too + # no check in the regard of loads existence (constraint force, pressure, self weight) is done + # because an analysis without loads at all is an valid analysis too if self.solver.AnalysisType == "static": if not (self.fixed_constraints or self.displacement_constraints): message += "Static analysis: Neither constraint fixed nor constraint displacement defined.\n" @@ -575,7 +583,10 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject): else: ccx_path = p1.stdout.read().split('\n')[0] elif p1.wait() == 1: - error_message = "FEM: CalculiX binary ccx not found in standard system binary path. Please install ccx or set path to binary in FEM preferences tab CalculiX.\n" + error_message = ( + "FEM: CalculiX binary ccx not found in standard system binary path. " + "Please install ccx or set path to binary in FEM preferences tab CalculiX.\n" + ) if FreeCAD.GuiUp: QtGui.QMessageBox.critical(None, error_title, error_message) raise Exception(error_message) @@ -586,7 +597,10 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject): ccx_binary = self.ccx_prefs.GetString("ccxBinaryPath", "") if not ccx_binary: FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/Ccx").SetBool("UseStandardCcxLocation", True) - error_message = "FEM: CalculiX binary ccx path not set at all. The use of standard path was activated in FEM preferences tab CalculiX. Please try again!\n" + error_message = ( + "FEM: CalculiX binary ccx path not set at all. " + "The use of standard path was activated in FEM preferences tab CalculiX. Please try again!\n" + ) if FreeCAD.GuiUp: QtGui.QMessageBox.critical(None, error_title, error_message) raise Exception(error_message) @@ -608,18 +622,27 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject): if ccx_binary_sig in str(ccx_stdout): self.ccx_binary_present = True else: - raise Exception("FEM: wrong ccx binary") # since we raise an exception the try will fail and the exception later with the error popup will be raised - # TODO: I'm still able to break it. If user doesn't give a file but a path without a file or a file which is not a binary no exception at all is raised. + raise Exception("FEM: wrong ccx binary") + # since we raise an exception the try will fail and the exception later with the error popup will be raised + # TODO: I'm still able to break it. If user doesn't give a file but a path without a file or + # a file which is not a binary no exception at all is raised. except OSError as e: FreeCAD.Console.PrintError(str(e)) if e.errno == 2: - error_message = "FEM: CalculiX binary ccx \'{}\' not found. Please set the CalculiX binary ccx path in FEM preferences tab CalculiX.\n".format(ccx_binary) + error_message = ( + "FEM: CalculiX binary ccx \'{}\' not found. " + "Please set the CalculiX binary ccx path in FEM preferences tab CalculiX.\n".format(ccx_binary) + ) if FreeCAD.GuiUp: QtGui.QMessageBox.critical(None, error_title, error_message) raise Exception(error_message) except Exception as e: FreeCAD.Console.PrintError(str(e)) - error_message = "FEM: CalculiX ccx \'{}\' output \'{}\' doesn't contain expected phrase \'{}\'. There are some problems when running the ccx binary. Check if ccx runs standalone without FreeCAD.\n".format(ccx_binary, ccx_stdout, ccx_binary_sig) + error_message = ( + "FEM: CalculiX ccx \'{}\' output \'{}\' doesn't contain expected phrase \'{}\'. " + 'There are some problems when running the ccx binary. ' + 'Check if ccx runs standalone without FreeCAD.\n'.format(ccx_binary, ccx_stdout, ccx_binary_sig) + ) if FreeCAD.GuiUp: QtGui.QMessageBox.critical(None, error_title, error_message) raise Exception(error_message)