From 09ec91eb60b877bfffe36a2f7f841ecf3371de2f Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Thu, 6 Jul 2017 06:29:41 +0200 Subject: [PATCH] FEM: unit tests, add all result stats, except 1DFlow --- src/Mod/Fem/TestFem.py | 16 ++++++++-------- .../ccx/cube_frequency_expected_values | 8 ++++++++ .../test_files/ccx/cube_static_expected_values | 8 ++++++++ .../ccx/spine_thermomech_expected_values | 8 ++++++++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/Mod/Fem/TestFem.py b/src/Mod/Fem/TestFem.py index 9e573e455d..1d316ec057 100644 --- a/src/Mod/Fem/TestFem.py +++ b/src/Mod/Fem/TestFem.py @@ -32,6 +32,7 @@ import tempfile import unittest mesh_name = 'Mesh' +stat_types = ["U1", "U2", "U3", "Uabs", "Sabs", "MaxPrin", "MidPrin", "MinPrin", "MaxShear", "Peeq", "Temp", "MFlow", "NPress"] home_path = FreeCAD.getHomePath() temp_dir = tempfile.gettempdir() + '/FEM_unittests' @@ -697,12 +698,12 @@ class FemCcxAnalysisTest(unittest.TestCase): self.assertTrue(True if fea.inp_file_name == Flow1D_thermomech_analysis_inp_file else False, "Setting inp file name to {} failed".format(Flow1D_thermomech_analysis_inp_file)) - fcc_print('Checking FEM frd file read from thermomech analysis...') + fcc_print('Checking FEM frd file read from Flow1D thermomech analysis...') fea.load_results() self.assertTrue(fea.results_present, "Cannot read results from {}.frd frd file".format(fea.base_name)) - fcc_print('Reading stats from result object for thermomech analysis...') - ret = compare_stats(fea, Flow1D_thermomech_expected_values) + fcc_print('Reading stats from result object for Flow1D thermomech analysis...') + ret = compare_stats(fea, Flow1D_thermomech_expected_values, ["U1", "U2", "U3", "Uabs", "Sabs"]) # TODO use all result stats self.assertFalse(ret, "Invalid results read from .frd file") fcc_print('Save FreeCAD file for thermomech analysis to {}...'.format(Flow1D_thermomech_save_fc_file)) @@ -741,15 +742,16 @@ def compare_inp_files(file_name1, file_name2): return result -def compare_stats(fea, stat_file=None): +def compare_stats(fea, stat_file=None, loc_stat_types=None): + if not loc_stat_types: + loc_stat_types = stat_types if stat_file: sf = open(stat_file, 'r') sf_content = sf.readlines() sf.close() sf_content = force_unix_line_ends(sf_content) - stat_types = ["U1", "U2", "U3", "Uabs", "Sabs"] stats = [] - for s in stat_types: + for s in loc_stat_types: stats.append("{}: {}\n".format(s, fea.get_stats(s))) if sf_content != stats: fcc_print("Expected stats from {}".format(stat_file)) @@ -800,7 +802,6 @@ def create_test_results(): fea.run() fea.load_results() - stat_types = ["U1", "U2", "U3", "Uabs", "Sabs"] stats_static = [] # we only have one result object so we are fine for s in stat_types: stats_static.append("{}: {}\n".format(s, fea.get_stats(s))) @@ -848,7 +849,6 @@ def create_test_results(): fea.run() fea.load_results() - stat_types = ["U1", "U2", "U3", "Uabs", "Sabs"] stats_thermomech = [] # we only have one result object so we are fine for s in stat_types: stats_thermomech.append("{}: {}\n".format(s, fea.get_stats(s))) diff --git a/src/Mod/Fem/test_files/ccx/cube_frequency_expected_values b/src/Mod/Fem/test_files/ccx/cube_frequency_expected_values index ac59bae002..0eec8b3a9f 100644 --- a/src/Mod/Fem/test_files/ccx/cube_frequency_expected_values +++ b/src/Mod/Fem/test_files/ccx/cube_frequency_expected_values @@ -3,3 +3,11 @@ U2: (-31.5876, 28.36729143214285, 60.9314) U3: (0.0, 288.8827953571427, 603.385) Uabs: (0.0, 311.8864585156363, 655.5261463034179) Sabs: (4.479528967136944, 71.96862334887253, 217.1885263864614) +MaxPrin: (-51.052324030743904, 39.88082216025957, 294.9265232927073) +MidPrin: (-198.6180601552034, 0.3227032003773508, 202.66494122230748) +MinPrin: (-295.6960070899379, -40.144573469342724, 46.83854286004427) +MaxShear: (2.574213187510708, 40.01269781480114, 124.04399021633152) +Peeq: (0.0, 0.0, 0.0) +Temp: (0.0, 0.0, 0.0) +MFlow: (0.0, 0.0, 0.0) +NPress: (0.0, 0.0, 0.0) diff --git a/src/Mod/Fem/test_files/ccx/cube_static_expected_values b/src/Mod/Fem/test_files/ccx/cube_static_expected_values index 0940615791..d61ef0cda9 100644 --- a/src/Mod/Fem/test_files/ccx/cube_static_expected_values +++ b/src/Mod/Fem/test_files/ccx/cube_static_expected_values @@ -3,3 +3,11 @@ U2: (-0.0109484, 1.4716768996428517e-05, 0.0110702) U3: (-0.0643181, -0.03087668257142857, 0.0) Uabs: (0.0, 0.03946299049104409, 0.09373834604097141) Sabs: (385.37990181702247, 1006.7357751358935, 2203.5090958167284) +MaxPrin: (-445.618534742656, 75.90111503580123, 908.6989814090499) +MidPrin: (-2058.523459279862, -363.98683840372263, 790.1306258178694) +MinPrin: (-2956.2880059774816, -1040.3029461492217, -172.23661850878244) +MaxShear: (218.05700933616734, 558.1020305925113, 1255.334735617413) +Peeq: (0.0, 0.0, 0.0) +Temp: (0.0, 0.0, 0.0) +MFlow: (0.0, 0.0, 0.0) +NPress: (0.0, 0.0, 0.0) diff --git a/src/Mod/Fem/test_files/ccx/spine_thermomech_expected_values b/src/Mod/Fem/test_files/ccx/spine_thermomech_expected_values index f5b46dab95..2070b6682d 100644 --- a/src/Mod/Fem/test_files/ccx/spine_thermomech_expected_values +++ b/src/Mod/Fem/test_files/ccx/spine_thermomech_expected_values @@ -3,3 +3,11 @@ U2: (-0.00163382, 0.0006165889555555556, 0.00222318) U3: (-0.00185329, 0.0005439136222222222, 0.00220675) Uabs: (0.0, 0.003644782698151031, 0.007325712241135124) Sabs: (0.30712297252407333, 7.747458526266711, 35.86180372766652) +MaxPrin: (-5.823866574600995, 1.3192417907488656, 10.92045561219017) +MidPrin: (-37.767092580118884, -4.877642532204389, 10.90982645542747) +MinPrin: (-39.36716084528015, -7.023583449500031, 6.4737666061604635) +MaxShear: (0.16818219759987152, 4.171412620124449, 18.100360778483793) +Peeq: (0.0, 0.0, 0.0) +Temp: (293.447, 299.9189333333334, 310.93) +MFlow: (0.0, 0.0, 0.0) +NPress: (0.0, 0.0, 0.0)