def importFrd(filename, analysis=None, result_name_prefix=None): import importToolsFem import ObjectsFem if result_name_prefix is None: result_name_prefix = '' m = readResult(filename) mesh_object = None if(len(m['Nodes']) > 0): if analysis is None: analysis_name = os.path.splitext(os.path.basename(filename))[0] analysis_object = ObjectsFem.makeAnalysis('Analysis') analysis_object.Label = analysis_name else: analysis_object = analysis # see if statement few lines later, if not analysis -> no FemMesh object is created ! if 'Nodes' in m: positions = [] for k, v in m['Nodes'].items(): positions.append(v) p_x_max, p_y_max, p_z_max = map(max, zip(*positions)) p_x_min, p_y_min, p_z_min = map(min, zip(*positions)) x_span = abs(p_x_max - p_x_min) y_span = abs(p_y_max - p_y_min) z_span = abs(p_z_max - p_z_min) span = max(x_span, y_span, z_span) if (not analysis): mesh = importToolsFem.make_femmesh(m) if len(m['Nodes']) > 0: mesh_object = FreeCAD.ActiveDocument.addObject('Fem::FemMeshObject', 'ResultMesh') mesh_object.FemMesh = mesh analysis_object.Member = analysis_object.Member + [mesh_object] number_of_increments = len(m['Results']) for result_set in m['Results']: eigenmode_number = result_set['number'] step_time = result_set['time'] step_time = round(step_time, 2) if eigenmode_number > 0: results_name = result_name_prefix + 'mode_' + str(eigenmode_number) + '_results' elif number_of_increments > 1: results_name = result_name_prefix + 'time_' + str(step_time) + '_results' else: results_name = result_name_prefix + 'results' results = ObjectsFem.makeResultMechanical(results_name) for m in analysis_object.Member: # TODO analysis could have multiple mesh objects in the future if m.isDerivedFrom("Fem::FemMeshObject"): results.Mesh = m break results = importToolsFem.fill_femresult_mechanical(results, result_set, span) analysis_object.Member = analysis_object.Member + [results] if(FreeCAD.GuiUp): import FemGui FemGui.setActiveAnalysis(analysis_object)
def importFrd(filename, analysis=None, result_name_prefix=None): import importToolsFem import ObjectsFem if result_name_prefix is None: result_name_prefix = '' m = readResult(filename) result_mesh_object = None if len(m['Nodes']) > 0: if analysis: analysis_object = analysis mesh = importToolsFem.make_femmesh(m) result_mesh_object = ObjectsFem.makeMeshResult(FreeCAD.ActiveDocument, 'Result_mesh') result_mesh_object.FemMesh = mesh positions = [] for k, v in m['Nodes'].items(): positions.append(v) p_x_max, p_y_max, p_z_max = map(max, zip(*positions)) p_x_min, p_y_min, p_z_min = map(min, zip(*positions)) x_span = abs(p_x_max - p_x_min) y_span = abs(p_y_max - p_y_min) z_span = abs(p_z_max - p_z_min) span = max(x_span, y_span, z_span) number_of_increments = len(m['Results']) for result_set in m['Results']: eigenmode_number = result_set['number'] step_time = result_set['time'] step_time = round(step_time, 2) if eigenmode_number > 0: results_name = result_name_prefix + 'mode_' + str( eigenmode_number) + '_results' elif number_of_increments > 1: results_name = result_name_prefix + 'time_' + str( step_time) + '_results' else: results_name = result_name_prefix + 'results' results = ObjectsFem.makeResultMechanical(FreeCAD.ActiveDocument, results_name) results.Mesh = result_mesh_object results = importToolsFem.fill_femresult_mechanical( results, result_set, span) if analysis: analysis_object.Member = analysis_object.Member + [results] if FreeCAD.GuiUp: if analysis: import FemGui FemGui.setActiveAnalysis(analysis_object) FreeCAD.ActiveDocument.recompute() else: FreeCAD.Console.PrintError( 'Problem on frd file import. No nodes found in frd file.\n')
def import_inp(filename): "create imported objects in FreeCAD, currently only FemMesh" m = read_inp(filename) import importToolsFem mesh = importToolsFem.make_femmesh(m) mesh_name = os.path.splitext(os.path.basename(filename))[0] mesh_object = FreeCAD.ActiveDocument.addObject('Fem::FemMeshObject', mesh_name) mesh_object.FemMesh = mesh
def import_inp(filename): "create imported objects in FreeCAD, currently only FemMesh" m = read_inp(filename) import importToolsFem mesh = importToolsFem.make_femmesh(m) mesh_name = os.path.splitext(os.path.basename(filename))[0] mesh_object = FreeCAD.ActiveDocument.addObject('Fem::FemMeshObject', mesh_name) mesh_object.FemMesh = mesh
def import_z88_mesh(filename, analysis=None): '''insert a FreeCAD FEM Mesh object in the ActiveDocument ''' mesh_data = read_z88_mesh(filename) mesh_name = os.path.basename(os.path.splitext(filename)[0]) import importToolsFem femmesh = importToolsFem.make_femmesh(mesh_data) if femmesh: mesh_object = FreeCAD.ActiveDocument.addObject('Fem::FemMeshObject', mesh_name) mesh_object.FemMesh = femmesh
def import_fenics_mesh(filename, analysis=None): '''insert a FreeCAD FEM Mesh object in the ActiveDocument ''' mesh_data = read_fenics_mesh(filename) mesh_name = os.path.basename(os.path.splitext(filename)[0]) femmesh = importToolsFem.make_femmesh(mesh_data) if femmesh: mesh_object = FreeCAD.ActiveDocument.addObject('Fem::FemMeshObject', mesh_name) mesh_object.FemMesh = femmesh
def import_fenics_mesh(filename, analysis=None): '''insert a FreeCAD FEM Mesh object in the ActiveDocument ''' mesh_data = readFenicsXML.read_fenics_mesh_xml(filename) # xdmf not operational mesh_name = os.path.basename(os.path.splitext(filename)[0]) femmesh = importToolsFem.make_femmesh(mesh_data) if femmesh: mesh_object = FreeCAD.ActiveDocument.addObject('Fem::FemMeshObject', mesh_name) mesh_object.FemMesh = femmesh
def import_z88_disp(filename, analysis=None, result_name_prefix=None): '''insert a FreeCAD FEM mechanical result object in the ActiveDocument pure usage: import importZ88O2Results disp_file = '/pathtofile/z88o2.txt' importZ88O2Results.import_z88_disp(disp_file) the z888i1.txt FEMMesh file needs to be in the same directory as z88o2.txt (ahh, make a new document first ;-)) ''' import importZ88Mesh import importToolsFem import ObjectsFem if result_name_prefix is None: result_name_prefix = '' disp_read = read_z88_disp(filename) result_mesh_object = None if len(disp_read['Nodes']) > 0: if analysis: analysis_object = analysis # read result mesh if filename.endswith('z88o2.txt'): mesh_file = filename.replace('o2', 'i1') mesh_data = importZ88Mesh.read_z88_mesh(mesh_file) femmesh = importToolsFem.make_femmesh(mesh_data) result_mesh_object = ObjectsFem.makeMeshResult( FreeCAD.ActiveDocument, 'Result_mesh') result_mesh_object.FemMesh = femmesh else: FreeCAD.Console.PrintError('Z88 mesh file z88i1.txt not found!') # create result obj for result_set in disp_read['Results']: results_name = result_name_prefix + 'results' results = ObjectsFem.makeResultMechanical(FreeCAD.ActiveDocument, results_name) results.Mesh = result_mesh_object results = importToolsFem.fill_femresult_mechanical( results, result_set, 0) if analysis: analysis_object.Member = analysis_object.Member + [results] if FreeCAD.GuiUp: if analysis: import FemGui FemGui.setActiveAnalysis(analysis_object) FreeCAD.ActiveDocument.recompute() else: FreeCAD.Console.PrintError( 'Problem on frd file import. No nodes found in frd file.\n')
def importFrd(filename, analysis=None, result_name_prefix=None): import importToolsFem import ObjectsFem if result_name_prefix is None: result_name_prefix = '' m = readResult(filename) result_mesh_object = None if len(m['Nodes']) > 0: if analysis: analysis_object = analysis mesh = importToolsFem.make_femmesh(m) result_mesh_object = ObjectsFem.makeMeshResult(FreeCAD.ActiveDocument, 'Result_mesh') result_mesh_object.FemMesh = mesh positions = [] for k, v in m['Nodes'].items(): positions.append(v) p_x_max, p_y_max, p_z_max = map(max, zip(*positions)) p_x_min, p_y_min, p_z_min = map(min, zip(*positions)) x_span = abs(p_x_max - p_x_min) y_span = abs(p_y_max - p_y_min) z_span = abs(p_z_max - p_z_min) span = max(x_span, y_span, z_span) number_of_increments = len(m['Results']) for result_set in m['Results']: eigenmode_number = result_set['number'] step_time = result_set['time'] step_time = round(step_time, 2) if eigenmode_number > 0: results_name = result_name_prefix + 'mode_' + str(eigenmode_number) + '_results' elif number_of_increments > 1: results_name = result_name_prefix + 'time_' + str(step_time) + '_results' else: results_name = result_name_prefix + 'results' results = ObjectsFem.makeResultMechanical(FreeCAD.ActiveDocument, results_name) results.Mesh = result_mesh_object results = importToolsFem.fill_femresult_mechanical(results, result_set, span) if analysis: analysis_object.addObject(results) if FreeCAD.GuiUp: if analysis: import FemGui FemGui.setActiveAnalysis(analysis_object) FreeCAD.ActiveDocument.recompute() else: FreeCAD.Console.PrintError('Problem on frd file import. No nodes found in frd file.\n')
def import_z88_disp(filename, analysis=None, result_name_prefix=None): '''insert a FreeCAD FEM mechanical result object in the ActiveDocument pure usage: import importZ88O2Results disp_file = '/pathtofile/z88o2.txt' importZ88O2Results.import_z88_disp(disp_file) the z888i1.txt FEMMesh file needs to be in the same directory as z88o2.txt (ahh, make a new document first ;-)) ''' import importZ88Mesh import importToolsFem import ObjectsFem if result_name_prefix is None: result_name_prefix = '' disp_read = read_z88_disp(filename) result_mesh_object = None if len(disp_read['Nodes']) > 0: if analysis: analysis_object = analysis # read result mesh if filename.endswith('z88o2.txt'): mesh_file = filename.replace('o2', 'i1') mesh_data = importZ88Mesh.read_z88_mesh(mesh_file) femmesh = importToolsFem.make_femmesh(mesh_data) result_mesh_object = ObjectsFem.makeMeshResult(FreeCAD.ActiveDocument, 'Result_mesh') result_mesh_object.FemMesh = femmesh else: FreeCAD.Console.PrintError('Z88 mesh file z88i1.txt not found!') # create result obj for result_set in disp_read['Results']: results_name = result_name_prefix + 'results' results = ObjectsFem.makeResultMechanical(FreeCAD.ActiveDocument, results_name) results.Mesh = result_mesh_object results = importToolsFem.fill_femresult_mechanical(results, result_set, 0) if analysis: analysis_object.addObject(results) if FreeCAD.GuiUp: if analysis: import FemGui FemGui.setActiveAnalysis(analysis_object) FreeCAD.ActiveDocument.recompute() else: FreeCAD.Console.PrintError('Problem on frd file import. No nodes found in frd file.\n')