def write_z88_elements_properties(self): element_properties_file_path = self.file_name + 'elp.txt' elements_data = [] if FemMeshTools.is_edge_femmesh(self.femmesh): if len(self.beamsection_objects) == 1: beam_obj = self.beamsection_objects[0]['Object'] width = beam_obj.RectWidth.getValueAs('mm') height = beam_obj.RectHeight.getValueAs('mm') area = str(width * height) elements_data.append('1 ' + str(self.element_count) + ' ' + area + ' 0 0 0 0 0 0 ') print("Be aware, only trusses are supported for edge meshes!") else: print("Multiple beamsections for Z88 not yet supported!") elif FemMeshTools.is_face_femmesh(self.femmesh): if len(self.shellthickness_objects) == 1: thick_obj = self.shellthickness_objects[0]['Object'] thickness = str(thick_obj.Thickness.getValueAs('mm')) elements_data.append('1 ' + str(self.element_count) + ' ' + thickness + ' 0 0 0 0 0 0 ') else: print("Multiple thicknesses for Z88 not yet supported!") elif FemMeshTools.is_solid_femmesh(self.femmesh): elements_data.append('1 ' + str(self.element_count) + ' 0 0 0 0 0 0 0') else: print("Error!") f = open(element_properties_file_path, 'w') f.write(str(len(elements_data)) + '\n') for e in elements_data: f.write(e) f.write('\n') f.close()
def get_z88_element_type(femmesh, femelement_table=None): if not femmesh: Console.PrintError("Error: No femmesh.\n") if not femelement_table: Console.PrintError("The femelement_table need to be calculated.\n") femelement_table = meshtools.get_femelement_table(femmesh) # in some cases lowest key in femelement_table is not [1] for elem in sorted(femelement_table): elem_length = len(femelement_table[elem]) Console.PrintLog( "Node count of first element: {}\n".format(elem_length)) break # break after the first elem if meshtools.is_solid_femmesh(femmesh): if femmesh.TetraCount == femmesh.VolumeCount: if elem_length == 4: return 17 elif elem_length == 10: return 16 else: Console.PrintMessage("Tetra with neither 4 nor 10 nodes.\n") elif femmesh.HexaCount == femmesh.VolumeCount: if elem_length == 8: return 1 elif elem_length == 20: return 10 else: Console.PrintError("Hexa with neither 8 nor 20 nodes.\n") return 0 else: Console.PrintError("no tetra, no hexa or Mixed Volume Elements.\n") elif meshtools.is_face_femmesh(femmesh): if femmesh.TriangleCount == femmesh.FaceCount: if elem_length == 3: Console.PrintError("tria3mesh, not supported by Z88.\n") return 0 elif elem_length == 6: return 24 else: Console.PrintError("Tria with neither 3 nor 6 nodes.\n") return 0 elif femmesh.QuadrangleCount == femmesh.FaceCount: if elem_length == 4: Console.PrintError("quad4mesh, not supported by Z88.\n") return 0 elif elem_length == 8: return 23 else: Console.PrintError("Quad with neither 4 nor 8 nodes.\n") return 0 else: Console.PrintError("no tria, no quad\n") return 0 elif meshtools.is_edge_femmesh(femmesh): Console.PrintMessage( "Edge femmesh will be exported as 3D truss element nr 4.\n") return 4 else: Console.PrintError("Neither edge nor face nor solid femmesh.\n") return 0 return 0
def export(objectslist, filename): "called when freecad exports a file" if len(objectslist) != 1: FreeCAD.Console.PrintError( "This exporter can only export one object.\n") return obj = objectslist[0] if not obj.isDerivedFrom("Fem::FemMeshObject"): FreeCAD.Console.PrintError("No FEM mesh object selected.\n") return femnodes_mesh = obj.FemMesh.Nodes femelement_table = meshtools.get_femelement_table(obj.FemMesh) if meshtools.is_solid_femmesh(obj.FemMesh): fem_mesh_type = "Solid" elif meshtools.is_face_femmesh(obj.FemMesh): fem_mesh_type = "Face" elif meshtools.is_edge_femmesh(obj.FemMesh): fem_mesh_type = "Edge" else: FreeCAD.Console.PrintError( "Export of this FEM mesh to Python not supported.\n") return f = pyopen(filename, "w") write_python_mesh_to_file(femnodes_mesh, femelement_table, fem_mesh_type, f) f.close()
def get_constraints_force_nodeloads(self): # check shape type of reference shape for femobj in self.force_objects: # femobj --> dict, FreeCAD document object is femobj['Object'] print("Constraint force: " + femobj['Object'].Name) frc_obj = femobj['Object'] if femobj['RefShapeType'] == 'Vertex': # print("load on vertices --> we do not need the femelement_table and femnodes_mesh for node load calculation") pass elif femobj['RefShapeType'] == 'Face' and FemMeshTools.is_solid_femmesh(self.femmesh) and not FemMeshTools.has_no_face_data(self.femmesh): # print("solid_mesh with face data --> we do not need the femelement_table but we need the femnodes_mesh for node load calculation") if not self.femnodes_mesh: self.femnodes_mesh = self.femmesh.Nodes else: # print("mesh without needed data --> we need the femelement_table and femnodes_mesh for node load calculation") if not self.femnodes_mesh: self.femnodes_mesh = self.femmesh.Nodes if not self.femelement_table: self.femelement_table = FemMeshTools.get_femelement_table(self.femmesh) # get node loads for femobj in self.force_objects: # femobj --> dict, FreeCAD document object is femobj['Object'] frc_obj = femobj['Object'] if frc_obj.Force == 0: print(' Warning --> Force = 0') if femobj['RefShapeType'] == 'Vertex': # point load on vertieces femobj['NodeLoadTable'] = FemMeshTools.get_force_obj_vertex_nodeload_table(self.femmesh, frc_obj) elif femobj['RefShapeType'] == 'Edge': # line load on edges femobj['NodeLoadTable'] = FemMeshTools.get_force_obj_edge_nodeload_table(self.femmesh, self.femelement_table, self.femnodes_mesh, frc_obj) elif femobj['RefShapeType'] == 'Face': # area load on faces femobj['NodeLoadTable'] = FemMeshTools.get_force_obj_face_nodeload_table(self.femmesh, self.femelement_table, self.femnodes_mesh, frc_obj)
def write_z88_elements_properties(self): element_properties_file_path = self.file_name + 'elp.txt' elements_data = [] if FemMeshTools.is_edge_femmesh(self.femmesh): if len(self.beamsection_objects) == 1: beam_obj = self.beamsection_objects[0]['Object'] width = beam_obj.RectWidth.getValueAs('mm') height = beam_obj.RectHeight.getValueAs('mm') area = str(width * height) elements_data.append('1 ' + str(self.element_count) + ' ' + area + ' 0 0 0 0 0 0 ') FreeCAD.Console.PrintMessage("Be aware, only trusses are supported for edge meshes!\n") else: FreeCAD.Console.PrintError("Multiple beamsections for Z88 not yet supported!\n") elif FemMeshTools.is_face_femmesh(self.femmesh): if len(self.shellthickness_objects) == 1: thick_obj = self.shellthickness_objects[0]['Object'] thickness = str(thick_obj.Thickness.getValueAs('mm')) elements_data.append('1 ' + str(self.element_count) + ' ' + thickness + ' 0 0 0 0 0 0 ') else: FreeCAD.Console.PrintError("Multiple thicknesses for Z88 not yet supported!\n") elif FemMeshTools.is_solid_femmesh(self.femmesh): elements_data.append('1 ' + str(self.element_count) + ' 0 0 0 0 0 0 0') else: FreeCAD.Console.PrintError("Error!\n") f = open(element_properties_file_path, 'w') f.write(str(len(elements_data)) + '\n') for e in elements_data: f.write(e) f.write('\n') f.close()
def get_z88_element_type(femmesh, femelement_table=None): import femmesh.meshtools as FemMeshTools if not femmesh: print("Error: No femmesh!") if not femelement_table: print("We need to get the femelement_table first!") femelement_table = FemMeshTools.get_femelement_table(femmesh) # in some cases lowest key in femelement_table is not [1] for elem in sorted(femelement_table): elem_length = len(femelement_table[elem]) FreeCAD.Console.PrintLog('node count of first element: ' + str(elem_length) + '\n') break # break after the first elem if FemMeshTools.is_solid_femmesh(femmesh): if femmesh.TetraCount == femmesh.VolumeCount: if elem_length == 4: return 17 elif elem_length == 10: return 16 else: print('Tetra with neither 4 nor 10 nodes') elif femmesh.HexaCount == femmesh.VolumeCount: if elem_length == 8: return 1 elif elem_length == 20: return 10 else: print('Hexa with neither 8 nor 20 nodes') return 0 else: print('no tetra, no hexa or Mixed Volume Elements') elif FemMeshTools.is_face_femmesh(femmesh): if femmesh.TriangleCount == femmesh.FaceCount: if elem_length == 3: print('tria3mesh, not supported by z88') return 0 elif elem_length == 6: return 24 else: print('Tria with neither 3 nor 6 nodes') return 0 elif femmesh.QuadrangleCount == femmesh.FaceCount: if elem_length == 4: print('quad4mesh, not supported by z88') return 0 elif elem_length == 8: return 23 else: print('Quad with neither 4 nor 8 nodes') return 0 else: print('no tria, no quad') return 0 elif FemMeshTools.is_edge_femmesh(femmesh): print('Edge femmesh will be exported as 3D truss element nr 4') return 4 else: print('Neither edge nor face nor solid femmesh') return 0 return 0
def get_constraints_force_nodeloads(self): # check shape type of reference shape for femobj in self.force_objects: # femobj --> dict, FreeCAD document object is femobj['Object'] FreeCAD.Console.PrintMessage("Constraint force: " + femobj['Object'].Name + '\n') frc_obj = femobj['Object'] if femobj['RefShapeType'] == 'Vertex': # print("load on vertices --> we do not need the femelement_table and femnodes_mesh for node load calculation") pass elif femobj['RefShapeType'] == 'Face' and FemMeshTools.is_solid_femmesh(self.femmesh) and not FemMeshTools.has_no_face_data(self.femmesh): # print("solid_mesh with face data --> we do not need the femelement_table but we need the femnodes_mesh for node load calculation") if not self.femnodes_mesh: self.femnodes_mesh = self.femmesh.Nodes else: # print("mesh without needed data --> we need the femelement_table and femnodes_mesh for node load calculation") if not self.femnodes_mesh: self.femnodes_mesh = self.femmesh.Nodes if not self.femelement_table: self.femelement_table = FemMeshTools.get_femelement_table(self.femmesh) # get node loads for femobj in self.force_objects: # femobj --> dict, FreeCAD document object is femobj['Object'] frc_obj = femobj['Object'] if frc_obj.Force == 0: FreeCAD.Console.PrintMessage(' Warning --> Force = 0\n') if femobj['RefShapeType'] == 'Vertex': # point load on vertieces femobj['NodeLoadTable'] = FemMeshTools.get_force_obj_vertex_nodeload_table(self.femmesh, frc_obj) elif femobj['RefShapeType'] == 'Edge': # line load on edges femobj['NodeLoadTable'] = FemMeshTools.get_force_obj_edge_nodeload_table(self.femmesh, self.femelement_table, self.femnodes_mesh, frc_obj) elif femobj['RefShapeType'] == 'Face': # area load on faces femobj['NodeLoadTable'] = FemMeshTools.get_force_obj_face_nodeload_table(self.femmesh, self.femelement_table, self.femnodes_mesh, frc_obj)
def get_constraints_force_nodeloads(self): # check shape type of reference shape for femobj in self.force_objects: # femobj --> dict, FreeCAD document object is femobj['Object'] FreeCAD.Console.PrintMessage("Constraint force:" + ' ' + femobj['Object'].Name + '\n') frc_obj = femobj['Object'] if femobj['RefShapeType'] == 'Vertex': # print("load on vertices --> we do not need the femelement_table and femnodes_mesh for node load calculation") pass elif femobj['RefShapeType'] == 'Face' and FemMeshTools.is_solid_femmesh(self.femmesh) and not FemMeshTools.has_no_face_data(self.femmesh): # print("solid_mesh with face data --> we do not need the femelement_table but we need the femnodes_mesh for node load calculation") if not self.femnodes_mesh: self.femnodes_mesh = self.femmesh.Nodes else: # print("mesh without needed data --> we need the femelement_table and femnodes_mesh for node load calculation") if not self.femnodes_mesh: self.femnodes_mesh = self.femmesh.Nodes if not self.femelement_table: self.femelement_table = FemMeshTools.get_femelement_table(self.femmesh) # get node loads FreeCAD.Console.PrintMessage(" Finite element mesh nodes will be retrieved by searching the appropriate nodes in the finite element mesh.\n") FreeCAD.Console.PrintMessage(" The appropriate finite element mesh node load values will be calculated according to the finite element definition.\n") for femobj in self.force_objects: # femobj --> dict, FreeCAD document object is femobj['Object'] frc_obj = femobj['Object'] if frc_obj.Force == 0: FreeCAD.Console.PrintMessage(' Warning --> Force = 0\n') if femobj['RefShapeType'] == 'Vertex': # point load on vertieces femobj['NodeLoadTable'] = FemMeshTools.get_force_obj_vertex_nodeload_table(self.femmesh, frc_obj) elif femobj['RefShapeType'] == 'Edge': # line load on edges femobj['NodeLoadTable'] = FemMeshTools.get_force_obj_edge_nodeload_table(self.femmesh, self.femelement_table, self.femnodes_mesh, frc_obj) elif femobj['RefShapeType'] == 'Face': # area load on faces femobj['NodeLoadTable'] = FemMeshTools.get_force_obj_face_nodeload_table(self.femmesh, self.femelement_table, self.femnodes_mesh, frc_obj)
def get_z88_element_type(femmesh, femelement_table=None): import femmesh.meshtools as FemMeshTools if not femmesh: print("Error: No femmesh!") if not femelement_table: print("We need to get the femelement_table first!") femelement_table = FemMeshTools.get_femelement_table(femmesh) # in some cases lowest key in femelement_table is not [1] for elem in sorted(femelement_table): elem_length = len(femelement_table[elem]) print(elem_length) break # break after the first elem if FemMeshTools.is_solid_femmesh(femmesh): if femmesh.TetraCount == femmesh.VolumeCount: if elem_length == 4: return 17 elif elem_length == 10: return 16 else: print('Tetra with neither 4 nor 10 nodes') elif femmesh.HexaCount == femmesh.VolumeCount: if elem_length == 8: return 1 elif elem_length == 20: return 10 else: print('Hexa with neither 8 nor 20 nodes') return 0 else: print('no tetra, no hexa or Mixed Volume Elements') elif FemMeshTools.is_face_femmesh(femmesh): if femmesh.TriangleCount == femmesh.FaceCount: if elem_length == 3: print('tria3mesh, not supported by z88') return 0 elif elem_length == 6: return 24 else: print('Tria with neither 3 nor 6 nodes') return 0 elif femmesh.QuadrangleCount == femmesh.FaceCount: if elem_length == 4: print('quad4mesh, not supported by z88') return 0 elif elem_length == 8: return 23 else: print('Quad with neither 4 nor 8 nodes') return 0 else: print('no tria, no quad') return 0 elif FemMeshTools.is_edge_femmesh(femmesh): print('Edge femmesh will be exported as 3D truss element nr 4') return 4 else: print('Neither edge nor face nor solid femmesh') return 0 return 0
def get_constraints_force_nodeloads(self): if not self.member.cons_force: return # check shape type of reference shape for femobj in self.member.cons_force: # femobj --> dict, FreeCAD document object is femobj["Object"] print_obj_info(femobj["Object"], log=True) if femobj["RefShapeType"] == "Vertex": FreeCAD.Console.PrintLog( " load on vertices --> The femelement_table " "and femnodes_mesh are not needed for node load calculation.\n" ) elif femobj["RefShapeType"] == "Face" \ and meshtools.is_solid_femmesh(self.femmesh) \ and not meshtools.has_no_face_data(self.femmesh): FreeCAD.Console.PrintLog( " solid_mesh with face data --> The femelement_table is not " "needed but the femnodes_mesh is needed for node load calculation.\n" ) if not self.femnodes_mesh: self.femnodes_mesh = self.femmesh.Nodes else: FreeCAD.Console.PrintLog( " mesh without needed data --> The femelement_table " "and femnodes_mesh are not needed for node load calculation.\n" ) if not self.femnodes_mesh: self.femnodes_mesh = self.femmesh.Nodes if not self.femelement_table: self.femelement_table = meshtools.get_femelement_table( self.femmesh) # get node loads FreeCAD.Console.PrintLog( " Finite element mesh nodes will be retrieved by searching " "the appropriate nodes in the finite element mesh.\n") FreeCAD.Console.PrintLog( " The appropriate finite element mesh node load values will " "be calculated according to the finite element definition.\n") for femobj in self.member.cons_force: # femobj --> dict, FreeCAD document object is femobj["Object"] frc_obj = femobj["Object"] print_obj_info(frc_obj) if frc_obj.Force == 0: FreeCAD.Console.PrintMessage(" Warning --> Force = 0\n") if femobj["RefShapeType"] == "Vertex": # point load on vertices femobj[ "NodeLoadTable"] = meshtools.get_force_obj_vertex_nodeload_table( self.femmesh, frc_obj) elif femobj["RefShapeType"] == "Edge": # line load on edges femobj[ "NodeLoadTable"] = meshtools.get_force_obj_edge_nodeload_table( self.femmesh, self.femelement_table, self.femnodes_mesh, frc_obj) elif femobj["RefShapeType"] == "Face": # area load on faces femobj[ "NodeLoadTable"] = meshtools.get_force_obj_face_nodeload_table( self.femmesh, self.femelement_table, self.femnodes_mesh, frc_obj)
def write_z88_elements_properties(self): element_properties_file_path = self.file_name + "elp.txt" elements_data = [] if meshtools.is_edge_femmesh(self.femmesh): beam_obj = self.member.geos_beamsection[0]["Object"] area = 0 if beam_obj.SectionType == "Rectangular": width = beam_obj.RectWidth.getValueAs("mm").Value height = beam_obj.RectHeight.getValueAs("mm").Value area = width * height elif beam_obj.SectionType == "Circular": diameter = beam_obj.CircDiameter.getValueAs("mm").Value from math import pi area = 0.25 * pi * diameter * diameter else: FreeCAD.Console.PrintError( "Cross section type {} not supported, " "cross section area will be 0 in solver input.\n" .format(beam_obj.SectionType) ) # TODO make the check in prechecks and delete it here # no extensive errorhandling in writer # this way the solver will fail and an exception is raised somehow elements_data.append( "1 {} {} 0 0 0 0 0 0 " .format(self.element_count, area) ) FreeCAD.Console.PrintWarning( "Be aware, only trusses are supported for edge meshes!\n" ) elif meshtools.is_face_femmesh(self.femmesh): thick_obj = self.member.geos_shellthickness[0]["Object"] thickness = thick_obj.Thickness.getValueAs("mm").Value elements_data.append( "1 {} {} 0 0 0 0 0 0 " .format(self.element_count, thickness) ) elif meshtools.is_solid_femmesh(self.femmesh): elements_data.append( "1 {} 0 0 0 0 0 0 0" .format(self.element_count) ) else: FreeCAD.Console.PrintError("Error!\n") f = open(element_properties_file_path, "w") f.write(str(len(elements_data)) + "\n") for e in elements_data: f.write(e) f.write("\n") f.close()
def write_z88_elements_properties(self): element_properties_file_path = self.file_name + "elp.txt" elements_data = [] if meshtools.is_edge_femmesh(self.femmesh): if len(self.beamsection_objects) == 1: beam_obj = self.beamsection_objects[0]["Object"] width = beam_obj.RectWidth.getValueAs("mm") height = beam_obj.RectHeight.getValueAs("mm") area = str(width * height) elements_data.append( "1 " + str(self.element_count) + " " + area + " 0 0 0 0 0 0 " ) FreeCAD.Console.PrintMessage( "Be aware, only trusses are supported for edge meshes!\n" ) else: FreeCAD.Console.PrintError("Multiple beamsections for Z88 not yet supported!\n") elif meshtools.is_face_femmesh(self.femmesh): if len(self.shellthickness_objects) == 1: thick_obj = self.shellthickness_objects[0]["Object"] thickness = str(thick_obj.Thickness.getValueAs("mm")) elements_data.append( "1 " + str(self.element_count) + " " + thickness + " 0 0 0 0 0 0 " ) else: FreeCAD.Console.PrintError( "Multiple thicknesses for Z88 not yet supported!\n" ) elif meshtools.is_solid_femmesh(self.femmesh): elements_data.append("1 " + str(self.element_count) + " 0 0 0 0 0 0 0") else: FreeCAD.Console.PrintError("Error!\n") f = open(element_properties_file_path, "w") f.write(str(len(elements_data)) + "\n") for e in elements_data: f.write(e) f.write("\n") f.close()
def write(fem_mesh, filename): """directly write a FemMesh to a Python mesh file fem_mesh: a FemMesh""" if not fem_mesh.isDerivedFrom("Fem::FemMesh"): FreeCAD.Console.PrintError("Not a FemMesh was given as parameter.\n") return femnodes_mesh = fem_mesh.Nodes femelement_table = meshtools.get_femelement_table(fem_mesh) if meshtools.is_solid_femmesh(fem_mesh): fem_mesh_type = "Solid" elif meshtools.is_face_femmesh(fem_mesh): fem_mesh_type = "Face" elif meshtools.is_edge_femmesh(fem_mesh): fem_mesh_type = "Edge" else: FreeCAD.Console.PrintError( "Export of this FEM mesh to Python not supported.\n") return f = pyopen(filename, "w") write_python_mesh_to_file(femnodes_mesh, femelement_table, fem_mesh_type, f) f.close()