FEM: import tools, displacement abs, move calculation and adding into result tools

This commit is contained in:
Bernd Hahnebach
2019-01-29 23:51:43 +01:00
committed by Yorik van Havre
parent 52aa1b24cc
commit ebbe781771
4 changed files with 18 additions and 11 deletions

View File

@@ -103,6 +103,7 @@ def importFrd(filename, analysis=None, result_name_prefix=None):
# only compact result if not Flow 1D results
# compact result object, workaround for bug 2873, https://www.freecadweb.org/tracker/view.php?id=2873
res_obj = restools.compact_result(res_obj)
res_obj = restools.add_disp_apps(res_obj) # fill DisplacementLengths
res_obj = restools.fill_femresult_stats(res_obj) # fill Stats
else:
error_message = (

View File

@@ -240,7 +240,6 @@ def fill_femresult_mechanical(results, result_set):
results.DisplacementVectors = list(map((lambda x: x * scale), disp.values()))
results.NodeNumbers = list(disp.keys())
results.DisplacementLengths = calculate_disp_abs(displacement)
if 'stress' in result_set:
stress = result_set['stress']
@@ -368,12 +367,6 @@ def calculate_principal_stress(i):
return (float('NaN'), float('NaN'), float('NaN'), float('NaN'))
def calculate_disp_abs(displacements):
disp_abs = []
for d in displacements:
disp_abs.append(sqrt(pow(d[0], 2) + pow(d[1], 2) + pow(d[2], 2)))
return disp_abs
def get_span(node_items):
positions = [] # list of node vectors
for k, v in node_items:

View File

@@ -119,7 +119,6 @@ def importVtkFCResult(filename, resultname, analysis=None, result_name_prefix=No
# See _getFreeCADMechResultProperties() in FemVTKTools.cpp for the supported names
import ObjectsFem
from . import importToolsFem
if result_name_prefix is None:
result_name_prefix = ''
if analysis:
@@ -129,10 +128,10 @@ def importVtkFCResult(filename, resultname, analysis=None, result_name_prefix=No
result_obj = ObjectsFem.makeResultMechanical(FreeCAD.ActiveDocument, results_name)
Fem.readResult(filename, result_obj.Name) # readResult always creates a new femmesh named ResultMesh
# workaround for the DisplacementLengths (They should have been calculated by Fem.readResult)
# add missing DisplacementLengths (They should have been added by Fem.readResult)
if not result_obj.DisplacementLengths:
result_obj.DisplacementLengths = importToolsFem.calculate_disp_abs(result_obj.DisplacementVectors)
FreeCAD.Console.PrintMessage('Recalculated DisplacementLengths.\n')
import femresult.resulttools as restools
result_obj = restools.add_disp_apps(result_obj) # DisplacementLengths
''' seems unused at the moment
filenamebase = '.'.join(filename.split('.')[:-1]) # pattern: filebase_timestamp.vtk

View File

@@ -28,6 +28,7 @@ __url__ = "http://www.freecadweb.org"
# @{
import FreeCAD
from math import sqrt
## Removes all result objects from an analysis group
@@ -240,6 +241,12 @@ def fill_femresult_stats(results):
return results
def add_disp_apps(res_obj):
res_obj.DisplacementLengths = calculate_disp_abs(res_obj.DisplacementVectors)
FreeCAD.Console.PrintMessage('Added DisplacementLengths.\n')
return res_obj
def compact_result(res_obj):
'''
compacts result.Mesh and appropriate result.NodeNumbers
@@ -264,4 +271,11 @@ def compact_result(res_obj):
return res_obj
def calculate_disp_abs(displacements):
disp_abs = []
for d in displacements:
disp_abs.append(sqrt(pow(d[0], 2) + pow(d[1], 2) + pow(d[2], 2)))
return disp_abs
## @}