From 05547d80e949dfd0d99f5fecae425112cc4e7b4f Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Mon, 5 Jul 2021 09:15:44 +0200 Subject: [PATCH 1/5] FEM: calculix writer, use generic method to write sets --- src/Mod/Fem/femsolver/calculix/writer.py | 367 ++++++++--------------- src/Mod/Fem/femsolver/writerbase.py | 8 + 2 files changed, 140 insertions(+), 235 deletions(-) diff --git a/src/Mod/Fem/femsolver/calculix/writer.py b/src/Mod/Fem/femsolver/calculix/writer.py index 429d2fea80..6cda101184 100644 --- a/src/Mod/Fem/femsolver/calculix/writer.py +++ b/src/Mod/Fem/femsolver/calculix/writer.py @@ -265,29 +265,52 @@ class FemInputWriterCcx(writerbase.FemInputWriter): return inpfile # ******************************************************************************************** - # constraints fixed - def write_node_sets_constraints_fixed(self, f): - if not self.fixed_objects: + # write constraint node sets, constraint face sets, constraint element sets + def write_constraints_sets( + self, + f, + femobjs, + analysis_types, + sets_getter_method, + write_name, + sets_writer_method, + caller_method_name="", + ): + if not femobjs: return - # write for all analysis types - # get nodes - self.get_constraints_fixed_nodes() + if analysis_types != "all" and self.analysis_type not in analysis_types: + return - write_name = "constraints_fixed_node_sets" - f.write("\n***********************************************************\n") + # get the sets + sets_getter_method() + + f.write("\n{}\n".format(59 * "*")) f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) + f.write("** written by {} function\n".format(caller_method_name)) if self.split_inpfile is True: - file_name_split = self.mesh_name + "_" + write_name + ".inp" + file_name_split = "{}_{}.inp".format(self.mesh_name, write_name) f.write("** {}\n".format(write_name.replace("_", " "))) f.write("*INCLUDE,INPUT={}\n".format(file_name_split)) inpfile_split = open(join(self.dir_name, file_name_split), "w") - self.write_node_sets_nodes_constraints_fixed(inpfile_split) + sets_writer_method(inpfile_split) inpfile_split.close() else: - self.write_node_sets_nodes_constraints_fixed(f) + sets_writer_method(f) + + # ******************************************************************************************** + # constraints fixed + def write_node_sets_constraints_fixed(self, f): + self.write_constraints_sets( + f, + femobjs=self.fixed_objects, + analysis_types="all", # write for all analysis types + sets_getter_method=self.get_constraints_fixed_nodes, + write_name="constraints_fixed_node_sets", + sets_writer_method=self.write_node_sets_nodes_constraints_fixed, + caller_method_name=sys._getframe().f_code.co_name, + ) def write_node_sets_nodes_constraints_fixed(self, f): # write nodes to file @@ -354,27 +377,15 @@ class FemInputWriterCcx(writerbase.FemInputWriter): # ******************************************************************************************** # constraints displacement def write_node_sets_constraints_displacement(self, f): - if not self.displacement_objects: - return - # write for all analysis types - - # get nodes - self.get_constraints_displacement_nodes() - - write_name = "constraints_displacement_node_sets" - f.write("\n***********************************************************\n") - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) - - if self.split_inpfile is True: - file_name_split = self.mesh_name + "_" + write_name + ".inp" - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("*INCLUDE,INPUT={}\n".format(file_name_split)) - inpfile_split = open(join(self.dir_name, file_name_split), "w") - self.write_node_sets_nodes_constraints_displacement(inpfile_split) - inpfile_split.close() - else: - self.write_node_sets_nodes_constraints_displacement(f) + self.write_constraints_sets( + f, + femobjs=self.displacement_objects, + analysis_types="all", # write for all analysis types + sets_getter_method=self.get_constraints_displacement_nodes, + write_name="constraints_displacement_node_sets", + sets_writer_method=self.write_node_sets_nodes_constraints_displacement, + caller_method_name=sys._getframe().f_code.co_name, + ) def write_node_sets_nodes_constraints_displacement(self, f): # write nodes to file @@ -432,27 +443,15 @@ class FemInputWriterCcx(writerbase.FemInputWriter): # ******************************************************************************************** # constraints planerotation def write_node_sets_constraints_planerotation(self, f): - if not self.planerotation_objects: - return - # write for all analysis types - - # get nodes - self.get_constraints_planerotation_nodes() - - write_name = "constraints_planerotation_node_sets" - f.write("\n***********************************************************\n") - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) - - if self.split_inpfile is True: - file_name_split = self.mesh_name + "_" + write_name + ".inp" - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("*INCLUDE,INPUT={}\n".format(file_name_split)) - inpfile_split = open(join(self.dir_name, file_name_split), "w") - self.write_node_sets_nodes_constraints_planerotation(inpfile_split) - inpfile_split.close() - else: - self.write_node_sets_nodes_constraints_planerotation(f) + self.write_constraints_sets( + f, + femobjs=self.planerotation_objects, + analysis_types="all", # write for all analysis types + sets_getter_method=self.get_constraints_planerotation_nodes, + write_name="constraints_planerotation_node_sets", + sets_writer_method=self.write_node_sets_nodes_constraints_planerotation, + caller_method_name=sys._getframe().f_code.co_name, + ) def write_node_sets_nodes_constraints_planerotation(self, f): # write nodes to file @@ -515,27 +514,15 @@ class FemInputWriterCcx(writerbase.FemInputWriter): # ******************************************************************************************** # constraints contact def write_surfaces_constraints_contact(self, f): - if not self.contact_objects: - return - # write for all analysis types - - # get faces - self.get_constraints_contact_faces() - - write_name = "constraints_contact_surface_sets" - f.write("\n***********************************************************\n") - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) - - if self.split_inpfile is True: - file_name_split = self.mesh_name + "_" + write_name + ".inp" - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("*INCLUDE,INPUT={}\n".format(file_name_split)) - inpfile_split = open(join(self.dir_name, file_name_split), "w") - self.write_surfacefaces_constraints_contact(inpfile_split) - inpfile_split.close() - else: - self.write_surfacefaces_constraints_contact(f) + self.write_constraints_sets( + f, + femobjs=self.contact_objects, + analysis_types="all", # write for all analysis types + sets_getter_method=self.get_constraints_contact_faces, + write_name="constraints_contact_surface_sets", + sets_writer_method=self.write_surfacefaces_constraints_contact, + caller_method_name=sys._getframe().f_code.co_name, + ) def write_surfacefaces_constraints_contact(self, f): # write faces to file @@ -585,27 +572,15 @@ class FemInputWriterCcx(writerbase.FemInputWriter): # ******************************************************************************************** # constraints tie def write_surfaces_constraints_tie(self, f): - if not self.tie_objects: - return - # write for all analysis types - - # get faces - self.get_constraints_tie_faces() - - write_name = "constraints_tie_surface_sets" - f.write("\n***********************************************************\n") - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) - - if self.split_inpfile is True: - file_name_split = self.mesh_name + "_" + write_name + ".inp" - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("*INCLUDE,INPUT={}\n".format(file_name_split)) - inpfile_split = open(join(self.dir_name, file_name_split), "w") - self.write_surfacefaces_constraints_tie(inpfile_split) - inpfile_split.close() - else: - self.write_surfacefaces_constraints_tie(f) + self.write_constraints_sets( + f, + femobjs=self.tie_objects, + analysis_types="all", # write for all analysis types + sets_getter_method=self.get_constraints_tie_faces, + write_name="constraints_tie_surface_sets", + sets_writer_method=self.write_surfacefaces_constraints_tie, + caller_method_name=sys._getframe().f_code.co_name, + ) def write_surfacefaces_constraints_tie(self, f): # write faces to file @@ -647,26 +622,18 @@ class FemInputWriterCcx(writerbase.FemInputWriter): # ******************************************************************************************** # constraints sectionprint def write_surfaces_constraints_sectionprint(self, f): - if not self.sectionprint_objects: - return - # write for all analysis types - - write_name = "constraints_sectionprint_surface_sets" - f.write("\n***********************************************************\n") - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) - - if self.split_inpfile is True: - file_name_split = self.mesh_name + "_" + write_name + ".inp" - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("*INCLUDE,INPUT={}\n".format(file_name_split)) - inpfile_split = open(join(self.dir_name, file_name_split), "w") - self.write_surfacefaces_constraints_sectionprint(inpfile_split) - inpfile_split.close() - else: - self.write_surfacefaces_constraints_sectionprint(f) + self.write_constraints_sets( + f, + femobjs=self.sectionprint_objects, + analysis_types="all", # write for all analysis types + sets_getter_method=self.get_constraints_sectionprint_faces, + write_name="constraints_sectionprint_surface_sets", + sets_writer_method=self.write_surfacefaces_constraints_sectionprint, + caller_method_name=sys._getframe().f_code.co_name, + ) # TODO move code parts from this method to base writer module + # into get_constraints_sectionprint_faces method def write_surfacefaces_constraints_sectionprint(self, f): # get surface nodes and write them to file obj = 0 @@ -724,27 +691,15 @@ class FemInputWriterCcx(writerbase.FemInputWriter): # ******************************************************************************************** # constraints transform def write_node_sets_constraints_transform(self, f): - if not self.transform_objects: - return - # write for all analysis types - - # get nodes - self.get_constraints_transform_nodes() - - write_name = "constraints_transform_node_sets" - f.write("\n***********************************************************\n") - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) - - if self.split_inpfile is True: - file_name_split = self.mesh_name + "_" + write_name + ".inp" - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("*INCLUDE,INPUT={}\n".format(file_name_split)) - inpfile_split = open(join(self.dir_name, file_name_split), "w") - self.write_node_sets_nodes_constraints_transform(inpfile_split) - inpfile_split.close() - else: - self.write_node_sets_nodes_constraints_transform(f) + self.write_constraints_sets( + f, + femobjs=self.transform_objects, + analysis_types="all", # write for all analysis types + sets_getter_method=self.get_constraints_transform_nodes, + write_name="constraints_transform_node_sets", + sets_writer_method=self.write_node_sets_nodes_constraints_transform, + caller_method_name=sys._getframe().f_code.co_name, + ) def write_node_sets_nodes_constraints_transform(self, f): # write nodes to file @@ -798,28 +753,15 @@ class FemInputWriterCcx(writerbase.FemInputWriter): # ******************************************************************************************** # constraints temperature def write_node_sets_constraints_temperature(self, f): - if not self.temperature_objects: - return - if not self.analysis_type == "thermomech": - return - - # get nodes - self.get_constraints_temperature_nodes() - - write_name = "constraints_temperature_node_sets" - f.write("\n***********************************************************\n") - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) - - if self.split_inpfile is True: - file_name_split = self.mesh_name + "_" + write_name + ".inp" - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("*INCLUDE,INPUT={}\n".format(file_name_split)) - inpfile_split = open(join(self.dir_name, file_name_split), "w") - self.write_node_sets_nodes_constraints_temperature(inpfile_split) - inpfile_split.close() - else: - self.write_node_sets_nodes_constraints_temperature(f) + self.write_constraints_sets( + f, + femobjs=self.temperature_objects, + analysis_types=["thermomech"], + sets_getter_method=self.get_constraints_temperature_nodes, + write_name="constraints_temperature_node_sets", + sets_writer_method=self.write_node_sets_nodes_constraints_temperature, + caller_method_name=sys._getframe().f_code.co_name, + ) def write_node_sets_nodes_constraints_temperature(self, f): # write nodes to file @@ -862,7 +804,7 @@ class FemInputWriterCcx(writerbase.FemInputWriter): def write_constraints_initialtemperature(self, f): if not self.initialtemperature_objects: return - if not self.analysis_type == "thermomech": + if self.analysis_type not in ["thermomech"]: return # write constraint to file @@ -880,11 +822,7 @@ class FemInputWriterCcx(writerbase.FemInputWriter): def write_constraints_selfweight(self, f): if not self.selfweight_objects: return - if not ( - self.analysis_type == "static" - or self.analysis_type == "thermomech" - or self.analysis_type == "buckling" - ): + if self.analysis_type not in ["buckling", "static", "thermomech"]: return # write constraint to file @@ -916,32 +854,15 @@ class FemInputWriterCcx(writerbase.FemInputWriter): # ******************************************************************************************** # constraints force def write_constraints_force(self, f): - if not self.force_objects: - return - if not ( - self.analysis_type == "static" - or self.analysis_type == "thermomech" - or self.analysis_type == "buckling" - ): - return - - # check shape type of reference shape and get node loads - self.get_constraints_force_nodeloads() - - write_name = "constraints_force_node_loads" - f.write("\n***********************************************************\n") - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) - - if self.split_inpfile is True: - file_name_split = self.mesh_name + "_" + write_name + ".inp" - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("*INCLUDE,INPUT={}\n".format(file_name_split)) - inpfile_split = open(join(self.dir_name, file_name_split), "w") - self.write_nodeloads_constraints_force(inpfile_split) - inpfile_split.close() - else: - self.write_nodeloads_constraints_force(f) + self.write_constraints_sets( + f, + femobjs=self.force_objects, + analysis_types=["buckling", "static", "thermomech"], + sets_getter_method=self.get_constraints_force_nodeloads, + write_name="constraints_force_node_loads", + sets_writer_method=self.write_nodeloads_constraints_force, + caller_method_name=sys._getframe().f_code.co_name, + ) def write_nodeloads_constraints_force(self, f): # write node loads to file @@ -969,32 +890,15 @@ class FemInputWriterCcx(writerbase.FemInputWriter): # ******************************************************************************************** # constraints pressure def write_constraints_pressure(self, f): - if not self.pressure_objects: - return - if not ( - self.analysis_type == "static" - or self.analysis_type == "thermomech" - or self.analysis_type == "buckling" - ): - return - - # get the faces and face numbers - self.get_constraints_pressure_faces() - - write_name = "constraints_pressure_element_face_loads" - f.write("\n***********************************************************\n") - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) - - if self.split_inpfile is True: - file_name_split = self.mesh_name + "_" + write_name + ".inp" - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("*INCLUDE,INPUT={}\n".format(file_name_split)) - inpfile_split = open(join(self.dir_name, file_name_split), "w") - self.write_faceloads_constraints_pressure(inpfile_split) - inpfile_split.close() - else: - self.write_faceloads_constraints_pressure(f) + self.write_constraints_sets( + f, + femobjs=self.pressure_objects, + analysis_types=["buckling", "static", "thermomech"], + sets_getter_method=self.get_constraints_pressure_faces, + write_name="constraints_pressure_element_face_loads", + sets_writer_method=self.write_faceloads_constraints_pressure, + caller_method_name=sys._getframe().f_code.co_name, + ) def write_faceloads_constraints_pressure(self, f): # write face loads to file @@ -1024,26 +928,18 @@ class FemInputWriterCcx(writerbase.FemInputWriter): # ******************************************************************************************** # constraints heatflux def write_constraints_heatflux(self, f): - if not self.heatflux_objects: - return - if not self.analysis_type == "thermomech": - return - - write_name = "constraints_heatflux_element_face_heatflux" - f.write("\n***********************************************************\n") - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) - - if self.split_inpfile is True: - file_name_split = self.mesh_name + "_" + write_name + ".inp" - f.write("** {}\n".format(write_name.replace("_", " "))) - f.write("*INCLUDE,INPUT={}\n".format(file_name_split)) - inpfile_split = open(join(self.dir_name, file_name_split), "w") - self.write_faceheatflux_constraints_heatflux(inpfile_split) - inpfile_split.close() - else: - self.write_faceheatflux_constraints_heatflux(f) + self.write_constraints_sets( + f, + femobjs=self.heatflux_objects, + analysis_types=["thermomech"], + sets_getter_method=self.get_constraints_heatflux_faces, + write_name="constraints_heatflux_element_face_heatflux", + sets_writer_method=self.write_faceheatflux_constraints_heatflux, + caller_method_name=sys._getframe().f_code.co_name, + ) + # TODO move code parts from this method to base writer module + # into get_constraints_heatflux_faces method def write_faceheatflux_constraints_heatflux(self, f): # write heat flux faces to file for hfobj in self.heatflux_objects: @@ -1083,10 +979,11 @@ class FemInputWriterCcx(writerbase.FemInputWriter): # ******************************************************************************************** # constraints fluidsection + # TODO: split method into separate methods and move some part into base writer def write_constraints_fluidsection(self, f): if not self.fluidsection_objects: return - if not self.analysis_type == "thermomech": + if self.analysis_type not in ["thermomech"]: return # write constraint to file diff --git a/src/Mod/Fem/femsolver/writerbase.py b/src/Mod/Fem/femsolver/writerbase.py index 47a460f8f1..295bc13678 100644 --- a/src/Mod/Fem/femsolver/writerbase.py +++ b/src/Mod/Fem/femsolver/writerbase.py @@ -394,6 +394,14 @@ class FemInputWriter(): # FreeCAD.Console.PrintLog("{}\n".format(femobj["ContactSlaveFaces"])) # FreeCAD.Console.PrintLog("{}\n".format(femobj["ContactMasterFaces"])) + def get_constraints_sectionprint_faces(self): + pass + # TODO implement + + def get_constraints_heatflux_faces(self): + pass + # TODO implement + # ******************************************************************************************** # ******************************************************************************************** # element sets From 3b323eb24b9fcb08a187a06b7e3516d1a300a418 Mon Sep 17 00:00:00 2001 From: UR-0 Date: Wed, 9 Jun 2021 12:06:07 +0200 Subject: [PATCH 2/5] FEM: calculix writer, add method is density needed --- src/Mod/Fem/femsolver/calculix/writer.py | 30 ++++++++++-------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/Mod/Fem/femsolver/calculix/writer.py b/src/Mod/Fem/femsolver/calculix/writer.py index 6cda101184..4cf3a3d3c9 100644 --- a/src/Mod/Fem/femsolver/calculix/writer.py +++ b/src/Mod/Fem/femsolver/calculix/writer.py @@ -1662,17 +1662,21 @@ class FemInputWriterCcx(writerbase.FemInputWriter): ccx_elset["ccx_mat_name"] = mat_obj.Material["Name"] self.ccx_elsets.append(ccx_elset) + def is_DENSITY_card_needed(self): + if self.analysis_type == "frequency": + return True + if self.selfweight_objects: + return True + if self.analysis_type == "thermomech" and not self.solver_obj.ThermoMechSteadyState: + return True + return False + def write_materials(self, f): f.write("\n***********************************************************\n") f.write("** Materials\n") f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) f.write("** Young\'s modulus unit is MPa = N/mm2\n") - if self.analysis_type == "frequency" \ - or self.selfweight_objects \ - or ( - self.analysis_type == "thermomech" - and not self.solver_obj.ThermoMechSteadyState - ): + if self.is_DENSITY_card_needed() is True: f.write("** Density\'s unit is t/mm^3\n") if self.analysis_type == "thermomech": f.write("** Thermal conductivity unit is kW/mm/K = t*mm/K*s^3\n") @@ -1688,12 +1692,7 @@ class FemInputWriterCcx(writerbase.FemInputWriter): YM = FreeCAD.Units.Quantity(mat_obj.Material["YoungsModulus"]) YM_in_MPa = float(YM.getValueAs("MPa")) PR = float(mat_obj.Material["PoissonRatio"]) - if self.analysis_type == "frequency" \ - or self.selfweight_objects \ - or ( - self.analysis_type == "thermomech" - and not self.solver_obj.ThermoMechSteadyState - ): + if self.is_DENSITY_card_needed() is True: density = FreeCAD.Units.Quantity(mat_obj.Material["Density"]) density_in_tonne_per_mm3 = float(density.getValueAs("t/mm^3")) if self.analysis_type == "thermomech": @@ -1718,12 +1717,7 @@ class FemInputWriterCcx(writerbase.FemInputWriter): f.write("*ELASTIC\n") f.write("{0:.0f}, {1:.3f}\n".format(YM_in_MPa, PR)) - if self.analysis_type == "frequency" \ - or self.selfweight_objects \ - or ( - self.analysis_type == "thermomech" - and not self.solver_obj.ThermoMechSteadyState - ): + if self.is_DENSITY_card_needed() is True: f.write("*DENSITY\n") f.write("{0:.3e}\n".format(density_in_tonne_per_mm3)) if self.analysis_type == "thermomech": From c90f48546e319d5df2d430809fd33f671efcb6d1 Mon Sep 17 00:00:00 2001 From: UR-0 Date: Wed, 9 Jun 2021 11:57:05 +0200 Subject: [PATCH 3/5] FEM: selection widget, small improvements --- src/Mod/Fem/femguiutils/selection_widgets.py | 41 ++++++++++---------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/Mod/Fem/femguiutils/selection_widgets.py b/src/Mod/Fem/femguiutils/selection_widgets.py index 19fe48ba25..f423a19509 100644 --- a/src/Mod/Fem/femguiutils/selection_widgets.py +++ b/src/Mod/Fem/femguiutils/selection_widgets.py @@ -235,13 +235,11 @@ class GeometryElementsSelection(QtGui.QWidget): super(GeometryElementsSelection, self).__init__() # init ui stuff FreeCADGui.Selection.clearSelection() - self.selection_mode_solid = False self.sel_server = None self.obj_notvisible = [] self.initElemTypes(eltypes) self.allow_multiple_geom_types = multigeom self.showHintEmptyList = showHintEmptyList - # print(self.allow_multiple_geom_types) self.initUI() # set references and fill the list widget self.references = [] @@ -279,25 +277,19 @@ class GeometryElementsSelection(QtGui.QWidget): # label self._helpTextLbl = QtGui.QLabel() self._helpTextLbl.setWordWrap(True) - helpTextPart1 = self.tr( - 'Click on "Add" and select geometric elements to add to the list.' - ) - helpTextPart2 = self.tr( - "The following geometry elements are allowed to select: " - ) + self.sel_elem_text - helpTextPart3 = self.tr( - "If no geometry is added to the list, all remaining ones are used." - ) + helpTextPart1 = self.tr('Click on "Add" and select geometric elements to add them to the list.') + helpTextPart2 = self.tr("The following geometry elements are allowed to select: ") + "" + self.sel_elem_text + "" + helpTextPart3 = self.tr("If no geometry is added to the list, all remaining ones are used.") if self.showHintEmptyList is True: self._helpTextLbl.setText( - helpTextPart1 + "\n" - + helpTextPart2 + "\n" - + helpTextPart3 + helpTextPart1 + "
" + + helpTextPart2 + "
" + + helpTextPart3 ) else: self._helpTextLbl.setText( - helpTextPart1 + "\n" - + helpTextPart2 + helpTextPart1 + "
" + + helpTextPart2 ) # list self.list_References = QtGui.QListWidget() @@ -306,9 +298,7 @@ class GeometryElementsSelection(QtGui.QWidget): self.lb_selmod.setText(self.tr("Selection mode")) self.rb_standard = QtGui.QRadioButton(self.tr(self.sel_elem_text.lstrip("Solid, "))) self.rb_solid = QtGui.QRadioButton(self.tr("Solid")) - self.rb_standard.setChecked(True) - self.rb_solid.setChecked(False) - # radio butoon layout + # radio button layout rbtnLayout = QtGui.QHBoxLayout() rbtnLayout.addWidget(self.lb_selmod) rbtnLayout.addWidget(self.rb_standard) @@ -318,8 +308,19 @@ class GeometryElementsSelection(QtGui.QWidget): mainLayout.addWidget(self._helpTextLbl) mainLayout.addWidget(self.pushButton_Add) mainLayout.addWidget(self.list_References) - if "Solid" in self.sel_elem_types: + + # if only "Solid" is avail, std-sel-mode is obsolete + if "Solid" in self.sel_elem_types and len (self.sel_elem_types) == 1: + self.selection_mode_solid = True + else: + self.selection_mode_solid = False + + # show radio buttons, if a solid and at least one nonsolid is allowed + if "Solid" in self.sel_elem_types and len (self.sel_elem_types) > 1: + self.rb_standard.setChecked(True) + self.rb_solid.setChecked(False) mainLayout.addLayout(rbtnLayout) + self.setLayout(mainLayout) # signals and slots self.list_References.itemSelectionChanged.connect(self.select_clicked_reference_shape) From 6d9f0bfc65533d73591dd7dd3a4fcb58ca963c80 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Mon, 5 Jul 2021 13:06:21 +0200 Subject: [PATCH 4/5] FEM: code formating --- src/Mod/Fem/femguiutils/selection_widgets.py | 22 +++++++++++--------- src/Mod/Fem/femsolver/calculix/writer.py | 12 +++++------ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Mod/Fem/femguiutils/selection_widgets.py b/src/Mod/Fem/femguiutils/selection_widgets.py index f423a19509..c7ae25c214 100644 --- a/src/Mod/Fem/femguiutils/selection_widgets.py +++ b/src/Mod/Fem/femguiutils/selection_widgets.py @@ -277,19 +277,21 @@ class GeometryElementsSelection(QtGui.QWidget): # label self._helpTextLbl = QtGui.QLabel() self._helpTextLbl.setWordWrap(True) - helpTextPart1 = self.tr('Click on "Add" and select geometric elements to add them to the list.') - helpTextPart2 = self.tr("The following geometry elements are allowed to select: ") + "" + self.sel_elem_text + "" - helpTextPart3 = self.tr("If no geometry is added to the list, all remaining ones are used.") + helpTextPart1 = self.tr( + 'Click on "Add" and select geometric elements to add them to the list.{}' + "The following geometry elements are allowed to select: {}{}{}" + .format("
", "", self.sel_elem_text, "") + ) + helpTextEmpty = self.tr( + "{}If no geometry is added to the list, all remaining ones are used.".format("
") + ) if self.showHintEmptyList is True: self._helpTextLbl.setText( - helpTextPart1 + "
" + - helpTextPart2 + "
" + - helpTextPart3 + helpTextPart1 + helpTextEmpty ) else: self._helpTextLbl.setText( - helpTextPart1 + "
" + - helpTextPart2 + helpTextPart1 ) # list self.list_References = QtGui.QListWidget() @@ -310,13 +312,13 @@ class GeometryElementsSelection(QtGui.QWidget): mainLayout.addWidget(self.list_References) # if only "Solid" is avail, std-sel-mode is obsolete - if "Solid" in self.sel_elem_types and len (self.sel_elem_types) == 1: + if "Solid" in self.sel_elem_types and len(self.sel_elem_types) == 1: self.selection_mode_solid = True else: self.selection_mode_solid = False # show radio buttons, if a solid and at least one nonsolid is allowed - if "Solid" in self.sel_elem_types and len (self.sel_elem_types) > 1: + if "Solid" in self.sel_elem_types and len(self.sel_elem_types) > 1: self.rb_standard.setChecked(True) self.rb_solid.setChecked(False) mainLayout.addLayout(rbtnLayout) diff --git a/src/Mod/Fem/femsolver/calculix/writer.py b/src/Mod/Fem/femsolver/calculix/writer.py index 4cf3a3d3c9..7df2fca43d 100644 --- a/src/Mod/Fem/femsolver/calculix/writer.py +++ b/src/Mod/Fem/femsolver/calculix/writer.py @@ -1662,13 +1662,13 @@ class FemInputWriterCcx(writerbase.FemInputWriter): ccx_elset["ccx_mat_name"] = mat_obj.Material["Name"] self.ccx_elsets.append(ccx_elset) - def is_DENSITY_card_needed(self): + def is_density_needed(self): if self.analysis_type == "frequency": return True - if self.selfweight_objects: - return True if self.analysis_type == "thermomech" and not self.solver_obj.ThermoMechSteadyState: return True + if self.selfweight_objects: + return True return False def write_materials(self, f): @@ -1676,7 +1676,7 @@ class FemInputWriterCcx(writerbase.FemInputWriter): f.write("** Materials\n") f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) f.write("** Young\'s modulus unit is MPa = N/mm2\n") - if self.is_DENSITY_card_needed() is True: + if self.is_density_needed() is True: f.write("** Density\'s unit is t/mm^3\n") if self.analysis_type == "thermomech": f.write("** Thermal conductivity unit is kW/mm/K = t*mm/K*s^3\n") @@ -1692,7 +1692,7 @@ class FemInputWriterCcx(writerbase.FemInputWriter): YM = FreeCAD.Units.Quantity(mat_obj.Material["YoungsModulus"]) YM_in_MPa = float(YM.getValueAs("MPa")) PR = float(mat_obj.Material["PoissonRatio"]) - if self.is_DENSITY_card_needed() is True: + if self.is_density_needed() is True: density = FreeCAD.Units.Quantity(mat_obj.Material["Density"]) density_in_tonne_per_mm3 = float(density.getValueAs("t/mm^3")) if self.analysis_type == "thermomech": @@ -1717,7 +1717,7 @@ class FemInputWriterCcx(writerbase.FemInputWriter): f.write("*ELASTIC\n") f.write("{0:.0f}, {1:.3f}\n".format(YM_in_MPa, PR)) - if self.is_DENSITY_card_needed() is True: + if self.is_density_needed() is True: f.write("*DENSITY\n") f.write("{0:.3e}\n".format(density_in_tonne_per_mm3)) if self.analysis_type == "thermomech": From ee12068253cdbdeaf76e1a358474605fbde51740 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Mon, 5 Jul 2021 23:57:57 +0200 Subject: [PATCH 5/5] FEM: fix failing unit test due to wrong result name, related: 761ac1ca5b1a --- src/Mod/Fem/femtest/app/test_ccxtools.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Mod/Fem/femtest/app/test_ccxtools.py b/src/Mod/Fem/femtest/app/test_ccxtools.py index 1f600347fd..3d0ccfd0e8 100644 --- a/src/Mod/Fem/femtest/app/test_ccxtools.py +++ b/src/Mod/Fem/femtest/app/test_ccxtools.py @@ -87,7 +87,7 @@ class TestCcxTools(unittest.TestCase): from femexamples.boxanalysis_frequency import setup setup(self.document, "ccxtools") base_name = get_namefromdef("test_") - res_obj_name = "CCX_Mode1_Results" + res_obj_name = "CCX_EigenMode_1_Results" analysis_dir = testtools.get_fem_test_tmp_dir(self.pre_dir_name + base_name) # test input file writing @@ -98,7 +98,6 @@ class TestCcxTools(unittest.TestCase): test_end=True, ) - """ temporary deactivate test due to 79b41f739381 # test result reading self.result_reading_test( None, @@ -107,7 +106,6 @@ class TestCcxTools(unittest.TestCase): fea=fea, res_obj_name=res_obj_name, ) - """ # ******************************************************************************************** def test_box_static( @@ -145,7 +143,7 @@ class TestCcxTools(unittest.TestCase): from femexamples.thermomech_flow1d import setup setup(self.document, "ccxtools") base_name = get_namefromdef("test_") - res_obj_name = "CCX_Time1_0_Results" + res_obj_name = "CCX_Time_1_0_Results" analysis_dir = testtools.get_fem_test_tmp_dir(self.pre_dir_name + base_name) # test input file writing @@ -156,7 +154,6 @@ class TestCcxTools(unittest.TestCase): test_end=True, ) - """ temporary deactivate test due to 79b41f739381 # test result reading self.result_reading_test( None, @@ -165,7 +162,6 @@ class TestCcxTools(unittest.TestCase): fea=fea, res_obj_name=res_obj_name, ) - """ # ******************************************************************************************** def test_thermomech_spine(