diff --git a/src/Mod/Fem/femsolver/calculix/writer.py b/src/Mod/Fem/femsolver/calculix/writer.py index cda2e3820011..326fe01a44b4 100644 --- a/src/Mod/Fem/femsolver/calculix/writer.py +++ b/src/Mod/Fem/femsolver/calculix/writer.py @@ -116,24 +116,18 @@ def write_calculix_one_input_file(self): inpfile = open(self.file_name, "a") # node and element sets self.write_element_sets_material_and_femelement_type(inpfile) - if self.fixed_objects: - self.write_node_sets_constraints_fixed(inpfile) - if self.displacement_objects: - self.write_node_sets_constraints_displacement(inpfile) - if self.planerotation_objects: - self.write_node_sets_constraints_planerotation(inpfile) - if self.contact_objects: - self.write_surfaces_constraints_contact(inpfile) - if self.tie_objects: - self.write_surfaces_constraints_tie(inpfile) - if self.transform_objects: - self.write_node_sets_constraints_transform(inpfile) - if self.analysis_type == "thermomech" and self.temperature_objects: + self.write_node_sets_constraints_fixed(inpfile) + self.write_node_sets_constraints_displacement(inpfile) + self.write_node_sets_constraints_planerotation(inpfile) + self.write_surfaces_constraints_contact(inpfile) + self.write_surfaces_constraints_tie(inpfile) + self.write_node_sets_constraints_transform(inpfile) + if self.analysis_type == "thermomech": self.write_node_sets_constraints_temperature(inpfile) # materials and fem element types self.write_materials(inpfile) - if self.analysis_type == "thermomech" and self.initialtemperature_objects: + if self.analysis_type == "thermomech": self.write_constraints_initialtemperature(inpfile) self.write_femelementsets(inpfile) # Fluid section: Inlet and Outlet requires special element definition @@ -148,47 +142,32 @@ def write_calculix_one_input_file(self): inpfile = open(self.file_name, "a") # constraints independent from steps - if self.planerotation_objects: - self.write_constraints_planerotation(inpfile) - if self.contact_objects: - self.write_constraints_contact(inpfile) - if self.tie_objects: - self.write_constraints_tie(inpfile) - if self.transform_objects: - self.write_constraints_transform(inpfile) + self.write_constraints_planerotation(inpfile) + self.write_constraints_contact(inpfile) + self.write_constraints_tie(inpfile) + self.write_constraints_transform(inpfile) # step begin self.write_step_begin(inpfile) # constraints depend on step used in all analysis types - if self.fixed_objects: - self.write_constraints_fixed(inpfile) - if self.displacement_objects: - self.write_constraints_displacement(inpfile) + self.write_constraints_fixed(inpfile) + self.write_constraints_displacement(inpfile) # constraints depend on step and depending on analysis type if self.analysis_type == "frequency" or self.analysis_type == "check": pass elif self.analysis_type == "static": - if self.selfweight_objects: - self.write_constraints_selfweight(inpfile) - if self.force_objects: - self.write_constraints_force(inpfile) - if self.pressure_objects: - self.write_constraints_pressure(inpfile) + self.write_constraints_selfweight(inpfile) + self.write_constraints_force(inpfile) + self.write_constraints_pressure(inpfile) elif self.analysis_type == "thermomech": - if self.selfweight_objects: - self.write_constraints_selfweight(inpfile) - if self.force_objects: - self.write_constraints_force(inpfile) - if self.pressure_objects: - self.write_constraints_pressure(inpfile) - if self.temperature_objects: - self.write_constraints_temperature(inpfile) - if self.heatflux_objects: - self.write_constraints_heatflux(inpfile) - if self.fluidsection_objects: - self.write_constraints_fluidsection(inpfile) + self.write_constraints_selfweight(inpfile) + self.write_constraints_force(inpfile) + self.write_constraints_pressure(inpfile) + self.write_constraints_temperature(inpfile) + self.write_constraints_heatflux(inpfile) + self.write_constraints_fluidsection(inpfile) # output and step end self.write_outputs_types(inpfile) @@ -247,18 +226,12 @@ def write_calculix_splitted_input_file(self): # node and element sets self.write_element_sets_material_and_femelement_type(inpfileMain) - if self.fixed_objects: - self.write_node_sets_constraints_fixed(inpfileNodes) - if self.displacement_objects: - self.write_node_sets_constraints_displacement(inpfileNodes) - if self.planerotation_objects: - self.write_node_sets_constraints_planerotation(inpfileNodes) - if self.contact_objects: - self.write_surfaces_constraints_contact(inpfileContact) - if self.tie_objects: - self.write_surfaces_constraints_tie(inpfileTie) - if self.transform_objects: - self.write_node_sets_constraints_transform(inpfileTransform) + self.write_node_sets_constraints_fixed(inpfileNodes) + self.write_node_sets_constraints_displacement(inpfileNodes) + self.write_node_sets_constraints_planerotation(inpfileNodes) + self.write_surfaces_constraints_contact(inpfileContact) + self.write_surfaces_constraints_tie(inpfileTie) + self.write_node_sets_constraints_transform(inpfileTransform) # write commentary and include statement for static case node sets inpfileMain.write("\n***********************************************************\n") @@ -287,7 +260,7 @@ def write_calculix_splitted_input_file(self): if self.transform_objects: inpfileMain.write("*INCLUDE,INPUT=" + include_name + "_Node_Transform.inp \n") - if self.analysis_type == "thermomech" and self.temperature_objects: + if self.analysis_type == "thermomech": self.write_node_sets_constraints_temperature(inpfileNodeTemp) # include separately written temperature constraint in input file @@ -300,7 +273,7 @@ def write_calculix_splitted_input_file(self): # materials and fem element types self.write_materials(inpfileMain) - if self.analysis_type == "thermomech" and self.initialtemperature_objects: + if self.analysis_type == "thermomech": self.write_constraints_initialtemperature(inpfileMain) self.write_femelementsets(inpfileMain) # Fluid section: Inlet and Outlet requires special element definition @@ -312,47 +285,32 @@ def write_calculix_splitted_input_file(self): ) # constraints independent from steps - if self.planerotation_objects: - self.write_constraints_planerotation(inpfileMain) - if self.contact_objects: - self.write_constraints_contact(inpfileMain) - if self.tie_objects: - self.write_constraints_tie(inpfileMain) - if self.transform_objects: - self.write_constraints_transform(inpfileMain) + self.write_constraints_planerotation(inpfileMain) + self.write_constraints_contact(inpfileMain) + self.write_constraints_tie(inpfileMain) + self.write_constraints_transform(inpfileMain) # step begin self.write_step_begin(inpfileMain) # constraints depend on step used in all analysis types - if self.fixed_objects: - self.write_constraints_fixed(inpfileMain) - if self.displacement_objects: - self.write_constraints_displacement(inpfileMain) + self.write_constraints_fixed(inpfileMain) + self.write_constraints_displacement(inpfileMain) # constraints depend on step and depending on analysis type if self.analysis_type == "frequency" or self.analysis_type == "check": pass elif self.analysis_type == "static": - if self.selfweight_objects: - self.write_constraints_selfweight(inpfileMain) - if self.force_objects: - self.write_constraints_force(inpfileForce) - if self.pressure_objects: - self.write_constraints_pressure(inpfilePressure) + self.write_constraints_selfweight(inpfileMain) + self.write_constraints_force(inpfileForce) + self.write_constraints_pressure(inpfilePressure) elif self.analysis_type == "thermomech": - if self.selfweight_objects: - self.write_constraints_selfweight(inpfileMain) - if self.force_objects: - self.write_constraints_force(inpfileForce) - if self.pressure_objects: - self.write_constraints_pressure(inpfilePressure) - if self.temperature_objects: - self.write_constraints_temperature(inpfileMain) - if self.heatflux_objects: - self.write_constraints_heatflux(inpfileHeatflux) - if self.fluidsection_objects: - self.write_constraints_fluidsection(inpfileMain) + self.write_constraints_selfweight(inpfileMain) + self.write_constraints_force(inpfileForce) + self.write_constraints_pressure(inpfilePressure) + self.write_constraints_temperature(inpfileMain) + self.write_constraints_heatflux(inpfileHeatflux) + self.write_constraints_fluidsection(inpfileMain) # include separately written constraints in input file inpfileMain.write("\n***********************************************************\n") @@ -490,6 +448,8 @@ def write_element_sets_material_and_femelement_type(self, f): f.write(str(elid) + ",\n") def write_node_sets_constraints_fixed(self, f): + if not self.fixed_objects: + return # get nodes self.get_constraints_fixed_nodes() # write nodes to file @@ -516,6 +476,8 @@ def write_node_sets_constraints_fixed(self, f): f.write(str(n) + ",\n") def write_node_sets_constraints_displacement(self, f): + if not self.displacement_objects: + return # get nodes self.get_constraints_displacement_nodes() # write nodes to file @@ -531,6 +493,8 @@ def write_node_sets_constraints_displacement(self, f): f.write(str(n) + ",\n") def write_node_sets_constraints_planerotation(self, f): + if not self.planerotation_objects: + return # get nodes self.get_constraints_planerotation_nodes() # write nodes to file @@ -578,6 +542,8 @@ def write_node_sets_constraints_planerotation(self, f): f.write(str(MPC_nodes[i]) + ",\n") def write_surfaces_constraints_contact(self, f): + if not self.contact_objects: + return # get faces self.get_constraints_contact_faces() # write faces to file @@ -598,6 +564,8 @@ def write_surfaces_constraints_contact(self, f): f.write("{},S{}\n".format(i[0], i[1])) def write_surfaces_constraints_tie(self, f): + if not self.tie_objects: + return # get faces self.get_constraints_tie_faces() # write faces to file @@ -618,6 +586,8 @@ def write_surfaces_constraints_tie(self, f): f.write("{},S{}\n".format(i[0], i[1])) def write_node_sets_constraints_transform(self, f): + if not self.transform_objects: + return # get nodes self.get_constraints_transform_nodes() # write nodes to file @@ -636,6 +606,8 @@ def write_node_sets_constraints_transform(self, f): f.write(str(n) + ",\n") def write_node_sets_constraints_temperature(self, f): + if not self.temperature_objects: + return # get nodes self.get_constraints_temperature_nodes() # write nodes to file @@ -743,6 +715,8 @@ def write_materials(self, f): f.write("\n") def write_constraints_initialtemperature(self, f): + if not self.initialtemperature_objects: + return f.write("\n***********************************************************\n") f.write("** Initial temperature constraint\n") f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) @@ -950,6 +924,8 @@ def write_step_begin(self, f): f.write(analysis_parameter + "\n") def write_constraints_fixed(self, f): + if not self.fixed_objects: + return f.write("\n***********************************************************\n") f.write("** Fixed Constraints\n") f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) @@ -986,6 +962,8 @@ def write_constraints_fixed(self, f): f.write("\n") def write_constraints_displacement(self, f): + if not self.displacement_objects: + return f.write("\n***********************************************************\n") f.write("** Displacement constraint applied\n") f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) @@ -1024,6 +1002,8 @@ def write_constraints_displacement(self, f): f.write("\n") def write_constraints_contact(self, f): + if not self.contact_objects: + return f.write("\n***********************************************************\n") f.write("** Contact Constraints\n") f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) @@ -1049,6 +1029,8 @@ def write_constraints_contact(self, f): f.write(str(friction) + ", " + str(stick) + " \n") def write_constraints_tie(self, f): + if not self.tie_objects: + return f.write("\n***********************************************************\n") f.write("** Tie Constraints\n") f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) @@ -1066,6 +1048,8 @@ def write_constraints_tie(self, f): f.write("{},{}\n".format(dep_surf, ind_surf)) def write_constraints_planerotation(self, f): + if not self.planerotation_objects: + return f.write("\n***********************************************************\n") f.write("** PlaneRotation Constraints\n") f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) @@ -1077,6 +1061,8 @@ def write_constraints_planerotation(self, f): f.write("PLANE," + fric_obj_name + "\n") def write_constraints_transform(self, f): + if not self.transform_objects: + return f.write("\n***********************************************************\n") f.write("** Transform Constraints\n") f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) @@ -1093,6 +1079,8 @@ def write_constraints_transform(self, f): f.write(coords + "\n") def write_constraints_selfweight(self, f): + if not self.selfweight_objects: + return f.write("\n***********************************************************\n") f.write("** Self weight Constraint\n") f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) @@ -1119,6 +1107,8 @@ def write_constraints_selfweight(self, f): # are written in the material element sets already def write_constraints_force(self, f): + if not self.force_objects: + return # check shape type of reference shape and get node loads self.get_constraints_force_nodeloads() # write node loads to file @@ -1147,6 +1137,8 @@ def write_constraints_force(self, f): f.write("\n") def write_constraints_pressure(self, f): + if not self.pressure_objects: + return # get the faces and face numbers self.get_constraints_pressure_faces() # write face loads to file @@ -1177,6 +1169,8 @@ def write_constraints_pressure(self, f): f.write("{},P,{}\n".format(face, -1 * rev * prs_obj.Pressure)) def write_constraints_temperature(self, f): + if not self.temperature_objects: + return f.write("\n***********************************************************\n") f.write("** Fixed temperature constraint applied\n") f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) @@ -1197,6 +1191,8 @@ def write_constraints_temperature(self, f): f.write("\n") def write_constraints_heatflux(self, f): + if not self.heatflux_objects: + return f.write("\n***********************************************************\n") f.write("** Heatflux constraints\n") f.write("** written by {} function\n".format(sys._getframe().f_code.co_name)) @@ -1236,6 +1232,8 @@ def write_constraints_heatflux(self, f): )) def write_constraints_fluidsection(self, f): + if not self.fluidsection_objects: + return f.write("\n***********************************************************\n") f.write("** FluidSection constraints\n") f.write("** written by {} function\n".format(sys._getframe().f_code.co_name))