def compare_stats(fea, stat_file=None, loc_stat_types=None, res_obj_name=None): import femresult.resulttools as resulttools stat_types = ["U1", "U2", "U3", "Uabs", "Sabs", "MaxPrin", "MidPrin", "MinPrin", "MaxShear", "Peeq", "Temp", "MFlow", "NPress"] if not loc_stat_types: loc_stat_types = stat_types if stat_file: sf = open(stat_file, 'r') sf_content = [] for l in sf.readlines(): for st in loc_stat_types: if l.startswith(st): sf_content.append(l) sf.close() sf_content = force_unix_line_ends(sf_content) stats = [] for s in loc_stat_types: if res_obj_name: statval = resulttools.get_stats(FreeCAD.ActiveDocument.getObject(res_obj_name), s) else: print('No result object name given') return False stats.append("{0}: ({1:.14g}, {2:.14g}, {3:.14g})\n".format(s, statval[0], statval[1], statval[2])) if sf_content != stats: fcc_print("Expected stats from {}".format(stat_file)) fcc_print(sf_content) fcc_print("Stats read from {}.frd file".format(fea.base_name)) fcc_print(stats) return True return False
def compare_stats(fea, stat_file, res_obj_name, loc_stat_types=None): import femresult.resulttools as resulttools # get the stat types which should be compared stat_types = [ "U1", "U2", "U3", "Uabs", "Sabs", "MaxPrin", "MidPrin", "MinPrin", "MaxShear", "Peeq", "Temp", "MFlow", "NPress" ] if not loc_stat_types: loc_stat_types = stat_types # get stats from result obj which should be compared obj = FreeCAD.ActiveDocument.getObject(res_obj_name) # fcc_print(obj) if obj: # fcc_print(obj.Name) stats = [] for s in loc_stat_types: statval = resulttools.get_stats(obj, s) stats.append("{}: ({:.10f}, {:.10f}, {:.10f})\n".format( s, statval[0], statval[1], statval[2])) else: fcc_print("Result object not found. Name: {}".format(res_obj_name)) return True # get stats to compare with, the expected ones sf = open(stat_file, 'r') sf_content = [] for l in sf.readlines(): for st in loc_stat_types: if l.startswith(st): sf_content.append(l) sf.close() sf_content = force_unix_line_ends(sf_content) if sf_content == []: return True # compare stats if stats != sf_content: fcc_print("Stats read from {}.frd file".format(fea.base_name)) fcc_print("!=") fcc_print("Expected stats from {}".format(stat_file)) for i in range(len(stats)): if stats[i] != sf_content[i]: fcc_print("{} != {}".format(stats[i].rstrip(), sf_content[i].rstrip())) return True return False
def create_test_results(): import os import shutil import sys import FemGui import Test import femresult.resulttools as resulttools from femtools import ccxtools stat_types = [ "U1", "U2", "U3", "Uabs", "Sabs", "MaxPrin", "MidPrin", "MinPrin", "MaxShear", "Peeq", "Temp", "MFlow", "NPress" ] temp_dir = testtools.get_fem_test_tmp_dir() static_analysis_dir = temp_dir + "FEM_ccx_static/" frequency_analysis_dir = temp_dir + "FEM_ccx_frequency/" thermomech_analysis_dir = temp_dir + "FEM_ccx_thermomech/" Flow1D_thermomech_analysis_dir = temp_dir + "FEM_ccx_Flow1D_thermomech/" # run all unit tests from this module current_module = sys.modules[__name__] Test.runTestsFromModule(current_module) # static cube FreeCAD.open(static_analysis_dir + "cube_static.FCStd") FemGui.setActiveAnalysis(FreeCAD.ActiveDocument.Analysis) fea = ccxtools.FemToolsCcx() fea.update_objects() print("create static result files") fea.reset_all() fea.run() fea.load_results() stats_static = [] for s in stat_types: statval = resulttools.get_stats( FreeCAD.ActiveDocument.getObject("CalculiX_static_results"), s) stats_static.append("{0}: ({1:.14g}, {2:.14g}, {3:.14g})\n".format( s, statval[0], statval[1], statval[2])) static_expected_values_file = join(static_analysis_dir, "cube_static_expected_values") f = open(static_expected_values_file, "w") for s in stats_static: f.write(s) f.close() frd_result_file = os.path.splitext(fea.inp_file_name)[0] + ".frd" dat_result_file = os.path.splitext(fea.inp_file_name)[0] + ".dat" frd_static_test_result_file = static_analysis_dir + "cube_static.frd" dat_static_test_result_file = static_analysis_dir + "cube_static.dat" shutil.copyfile(frd_result_file, frd_static_test_result_file) shutil.copyfile(dat_result_file, dat_static_test_result_file) # frequency cube FreeCAD.open(frequency_analysis_dir + "cube_frequency.FCStd") FemGui.setActiveAnalysis(FreeCAD.ActiveDocument.Analysis) fea = ccxtools.FemToolsCcx() fea.update_objects() print("create frequency result files") fea.reset_all() fea.solver.EigenmodesCount = 1 # we should only have one result object fea.run() fea.load_results() stats_frequency = [] for s in stat_types: statval = resulttools.get_stats( FreeCAD.ActiveDocument.getObject( "CalculiX_frequency_mode_1_results"), s) stats_frequency.append("{0}: ({1:.14g}, {2:.14g}, {3:.14g})\n".format( s, statval[0], statval[1], statval[2])) frequency_expected_values_file = join(frequency_analysis_dir, "cube_frequency_expected_values") f = open(frequency_expected_values_file, "w") for s in stats_frequency: f.write(s) f.close() frd_frequency_test_result_file = frequency_analysis_dir + "cube_frequency.frd" dat_frequency_test_result_file = frequency_analysis_dir + "cube_frequency.dat" shutil.copyfile(frd_result_file, frd_frequency_test_result_file) shutil.copyfile(dat_result_file, dat_frequency_test_result_file) # thermomech print("create thermomech result files") FreeCAD.open(thermomech_analysis_dir + "spine_thermomech.FCStd") FemGui.setActiveAnalysis(FreeCAD.ActiveDocument.Analysis) fea = ccxtools.FemToolsCcx() fea.reset_all() fea.run() fea.load_results() stats_thermomech = [] for s in stat_types: statval = resulttools.get_stats( FreeCAD.ActiveDocument.getObject("CalculiX_thermomech_results"), s) stats_thermomech.append("{0}: ({1:.14g}, {2:.14g}, {3:.14g})\n".format( s, statval[0], statval[1], statval[2])) thermomech_expected_values_file = join(thermomech_analysis_dir, "spine_thermomech_expected_values") f = open(thermomech_expected_values_file, "w") for s in stats_thermomech: f.write(s) f.close() frd_result_file = os.path.splitext(fea.inp_file_name)[0] + ".frd" dat_result_file = os.path.splitext(fea.inp_file_name)[0] + ".dat" frd_thermomech_test_result_file = thermomech_analysis_dir + "spine_thermomech.frd" dat_thermomech_test_result_file = thermomech_analysis_dir + "spine_thermomech.dat" shutil.copyfile(frd_result_file, frd_thermomech_test_result_file) shutil.copyfile(dat_result_file, dat_thermomech_test_result_file) print("Results copied to the appropriate FEM test dirs in: " + temp_dir) # Flow1D print("create Flow1D result files") FreeCAD.open(Flow1D_thermomech_analysis_dir + "Flow1D_thermomech.FCStd") FemGui.setActiveAnalysis(FreeCAD.ActiveDocument.Analysis) fea = ccxtools.FemToolsCcx() fea.reset_all() fea.run() fea.load_results() stats_flow1D = [] for s in stat_types: statval = resulttools.get_stats( FreeCAD.ActiveDocument.getObject( "CalculiX_thermomech_time_1_0_results"), s) stats_flow1D.append("{0}: ({1:.14g}, {2:.14g}, {3:.14g})\n".format( s, statval[0], statval[1], statval[2])) Flow1D_thermomech_expected_values_file = join( Flow1D_thermomech_analysis_dir, "Flow1D_thermomech_expected_values") f = open(Flow1D_thermomech_expected_values_file, "w") for s in stats_flow1D: f.write(s) f.close() frd_result_file = os.path.splitext(fea.inp_file_name)[0] + ".frd" dat_result_file = os.path.splitext(fea.inp_file_name)[0] + ".dat" frd_Flow1D_thermomech_test_result_file = join( Flow1D_thermomech_analysis_dir, "Flow1D_thermomech.frd") dat_Flow1D_thermomech_test_result_file = join( Flow1D_thermomech_analysis_dir, "Flow1D_thermomech.dat") shutil.copyfile(frd_result_file, frd_Flow1D_thermomech_test_result_file) shutil.copyfile(dat_result_file, dat_Flow1D_thermomech_test_result_file) print( "Flow1D thermomech results copied to the appropriate FEM test dirs in: " + temp_dir)
def create_test_results(): import shutil import os import FemGui import femresult.resulttools as resulttools from femtools import ccxtools stat_types = ["U1", "U2", "U3", "Uabs", "Sabs", "MaxPrin", "MidPrin", "MinPrin", "MaxShear", "Peeq", "Temp", "MFlow", "NPress"] temp_dir = testtools.get_fem_test_tmp_dir() static_analysis_dir = temp_dir + 'FEM_ccx_static/' frequency_analysis_dir = temp_dir + 'FEM_ccx_frequency/' thermomech_analysis_dir = temp_dir + 'FEM_ccx_thermomech/' Flow1D_thermomech_analysis_dir = temp_dir + 'FEM_ccx_Flow1D_thermomech/' # run all unit tests from this module import Test import sys current_module = sys.modules[__name__] Test.runTestsFromModule(current_module) # static cube FreeCAD.open(static_analysis_dir + 'cube_static.fcstd') FemGui.setActiveAnalysis(FreeCAD.ActiveDocument.Analysis) fea = ccxtools.FemToolsCcx() print("create static result files") fea.reset_all() fea.run() fea.load_results() stats_static = [] for s in stat_types: statval = resulttools.get_stats(FreeCAD.ActiveDocument.getObject('CalculiX_static_results'), s) stats_static.append("{0}: ({1:.14g}, {2:.14g}, {3:.14g})\n".format(s, statval[0], statval[1], statval[2])) static_expected_values_file = static_analysis_dir + 'cube_static_expected_values' f = open(static_expected_values_file, 'w') for s in stats_static: f.write(s) f.close() frd_result_file = os.path.splitext(fea.inp_file_name)[0] + '.frd' dat_result_file = os.path.splitext(fea.inp_file_name)[0] + '.dat' frd_static_test_result_file = static_analysis_dir + 'cube_static.frd' dat_static_test_result_file = static_analysis_dir + 'cube_static.dat' shutil.copyfile(frd_result_file, frd_static_test_result_file) shutil.copyfile(dat_result_file, dat_static_test_result_file) # frequency cube FreeCAD.open(frequency_analysis_dir + 'cube_frequency.fcstd') FemGui.setActiveAnalysis(FreeCAD.ActiveDocument.Analysis) fea = ccxtools.FemToolsCcx() print("create frequency result files") fea.reset_all() fea.solver.EigenmodesCount = 1 # we should only have one result object fea.run() fea.load_results() stats_frequency = [] for s in stat_types: statval = resulttools.get_stats(FreeCAD.ActiveDocument.getObject('CalculiX_frequency_mode_1_results'), s) stats_frequency.append("{0}: ({1:.14g}, {2:.14g}, {3:.14g})\n".format(s, statval[0], statval[1], statval[2])) frequency_expected_values_file = frequency_analysis_dir + 'cube_frequency_expected_values' f = open(frequency_expected_values_file, 'w') for s in stats_frequency: f.write(s) f.close() frd_frequency_test_result_file = frequency_analysis_dir + 'cube_frequency.frd' dat_frequency_test_result_file = frequency_analysis_dir + 'cube_frequency.dat' shutil.copyfile(frd_result_file, frd_frequency_test_result_file) shutil.copyfile(dat_result_file, dat_frequency_test_result_file) # thermomech print("create thermomech result files") FreeCAD.open(thermomech_analysis_dir + 'spine_thermomech.fcstd') FemGui.setActiveAnalysis(FreeCAD.ActiveDocument.Analysis) fea = ccxtools.FemToolsCcx() fea.reset_all() fea.run() fea.load_results() stats_thermomech = [] for s in stat_types: statval = resulttools.get_stats(FreeCAD.ActiveDocument.getObject('CalculiX_thermomech_results'), s) stats_thermomech.append("{0}: ({1:.14g}, {2:.14g}, {3:.14g})\n".format(s, statval[0], statval[1], statval[2])) thermomech_expected_values_file = thermomech_analysis_dir + 'spine_thermomech_expected_values' f = open(thermomech_expected_values_file, 'w') for s in stats_thermomech: f.write(s) f.close() frd_result_file = os.path.splitext(fea.inp_file_name)[0] + '.frd' dat_result_file = os.path.splitext(fea.inp_file_name)[0] + '.dat' frd_thermomech_test_result_file = thermomech_analysis_dir + 'spine_thermomech.frd' dat_thermomech_test_result_file = thermomech_analysis_dir + 'spine_thermomech.dat' shutil.copyfile(frd_result_file, frd_thermomech_test_result_file) shutil.copyfile(dat_result_file, dat_thermomech_test_result_file) print('Results copied to the appropriate FEM test dirs in: ' + temp_dir) # Flow1D print("create Flow1D result files") FreeCAD.open(Flow1D_thermomech_analysis_dir + 'Flow1D_thermomech.fcstd') FemGui.setActiveAnalysis(FreeCAD.ActiveDocument.Analysis) fea = ccxtools.FemToolsCcx() fea.reset_all() fea.run() fea.load_results() stats_flow1D = [] for s in stat_types: statval = resulttools.get_stats(FreeCAD.ActiveDocument.getObject('CalculiX_thermomech_time_1_0_results'), s) stats_flow1D.append("{0}: ({1:.14g}, {2:.14g}, {3:.14g})\n".format(s, statval[0], statval[1], statval[2])) Flow1D_thermomech_expected_values_file = Flow1D_thermomech_analysis_dir + 'Flow1D_thermomech_expected_values' f = open(Flow1D_thermomech_expected_values_file, 'w') for s in stats_flow1D: f.write(s) f.close() frd_result_file = os.path.splitext(fea.inp_file_name)[0] + '.frd' dat_result_file = os.path.splitext(fea.inp_file_name)[0] + '.dat' frd_Flow1D_thermomech_test_result_file = Flow1D_thermomech_analysis_dir + 'Flow1D_thermomech.frd' dat_Flow1D_thermomech_test_result_file = Flow1D_thermomech_analysis_dir + 'Flow1D_thermomech.dat' shutil.copyfile(frd_result_file, frd_Flow1D_thermomech_test_result_file) shutil.copyfile(dat_result_file, dat_Flow1D_thermomech_test_result_file) print('Flow1D thermomech results copied to the appropriate FEM test dirs in: ' + temp_dir)
def get_result_stats(self, type_name): return resulttools.get_stats(self.result_obj, type_name)
def create_test_results(): import os import shutil import unittest import FemGui from femresult import resulttools from femtools import ccxtools temp_dir = testtools.get_fem_test_tmp_dir() test_class = "femtest.app.test_ccxtools.TestCcxTools" # unit test class stat_types = [ "U1", "U2", "U3", "Uabs", "Sabs", "MaxPrin", "MidPrin", "MinPrin", "MaxShear", "Peeq", "Temp", "MFlow", "NPress" ] # **************************************************************************** # static cube print("create static result files") unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName( test_class + ".test_static_analysis") ) static_analysis_dir = join(temp_dir, "FEM_ccx_static") doc_static_cube = FreeCAD.open(join(static_analysis_dir, "cube_static.FCStd")) FemGui.setActiveAnalysis(doc_static_cube.Analysis) fea = ccxtools.FemToolsCcx() fea.update_objects() fea.reset_all() fea.run() fea.load_results() stats_static = [] res_obj_static = doc_static_cube.getObject("CCX_Results") for s in stat_types: statval = resulttools.get_stats(res_obj_static, s) stats_static.append( "{0}: ({1:.14g}, {2:.14g}, )\n" .format(s, statval[0], statval[1]) ) static_expected_values_file = join( static_analysis_dir, "cube_static_expected_values" ) f = open(static_expected_values_file, "w") for s in stats_static: f.write(s) f.close() frd_result_file = os.path.splitext(fea.inp_file_name)[0] + ".frd" dat_result_file = os.path.splitext(fea.inp_file_name)[0] + ".dat" frd_static_test_result_file = join(static_analysis_dir, "cube_static.frd") dat_static_test_result_file = join(static_analysis_dir, "cube_static.dat") shutil.copyfile(frd_result_file, frd_static_test_result_file) shutil.copyfile(dat_result_file, dat_static_test_result_file) print("Results copied to the appropriate FEM test dirs in: " + temp_dir) # **************************************************************************** # frequency cube print("create frequency result files") unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName( test_class + ".test_freq_analysis") ) frequency_analysis_dir = join(temp_dir, "FEM_ccx_frequency") doc_frequency_cube = FreeCAD.open(join(frequency_analysis_dir, "cube_frequency.FCStd")) FemGui.setActiveAnalysis(doc_frequency_cube.Analysis) fea = ccxtools.FemToolsCcx() fea.update_objects() fea.reset_all() # we should only have one result object 1 to 6 will be less than 0.01 and ignored fea.solver.EigenmodesCount = 7 doc_frequency_cube.recompute() fea.run() fea.load_results() stats_frequency = [] res_obj_freq = doc_frequency_cube.getObject("CCX_Mode7_Results") for s in stat_types: statval = resulttools.get_stats(res_obj_freq, s) stats_frequency.append( "{0}: ({1:.14g}, {2:.14g})\n" .format(s, statval[0], statval[1]) ) frequency_expected_values_file = join( frequency_analysis_dir, "cube_frequency_expected_values" ) f = open(frequency_expected_values_file, "w") for s in stats_frequency: f.write(s) f.close() frd_result_file = os.path.splitext(fea.inp_file_name)[0] + ".frd" dat_result_file = os.path.splitext(fea.inp_file_name)[0] + ".dat" frd_frequency_test_result_file = join(frequency_analysis_dir, "cube_frequency.frd") dat_frequency_test_result_file = join(frequency_analysis_dir, "cube_frequency.dat") shutil.copyfile(frd_result_file, frd_frequency_test_result_file) shutil.copyfile(dat_result_file, dat_frequency_test_result_file) print("Results copied to the appropriate FEM test dirs in: " + temp_dir) # **************************************************************************** # thermomech print("create thermomech result files") unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName( test_class + ".test_thermomech_spine_analysis") ) thermomech_analysis_dir = join(temp_dir, "FEM_ccx_thermomech") doc_thermomech = FreeCAD.open(join(thermomech_analysis_dir, "spine_thermomech.FCStd")) FemGui.setActiveAnalysis(doc_thermomech.Analysis) fea = ccxtools.FemToolsCcx() fea.reset_all() fea.run() fea.load_results() stats_thermomech = [] res_obj_thermo = doc_thermomech.getObject("CCX_Results001") # two time step results after run for s in stat_types: statval = resulttools.get_stats(res_obj_thermo, s) stats_thermomech.append( "{0}: ({1:.14g}, {2:.14g})\n" .format(s, statval[0], statval[1]) ) thermomech_expected_values_file = join( thermomech_analysis_dir, "spine_thermomech_expected_values" ) f = open(thermomech_expected_values_file, "w") for s in stats_thermomech: f.write(s) f.close() frd_result_file = os.path.splitext(fea.inp_file_name)[0] + ".frd" dat_result_file = os.path.splitext(fea.inp_file_name)[0] + ".dat" frd_thermomech_test_result_file = join(thermomech_analysis_dir, "spine_thermomech.frd") dat_thermomech_test_result_file = join(thermomech_analysis_dir, "spine_thermomech.dat") shutil.copyfile(frd_result_file, frd_thermomech_test_result_file) shutil.copyfile(dat_result_file, dat_thermomech_test_result_file) print("Results copied to the appropriate FEM test dirs in: " + temp_dir) # **************************************************************************** # Flow1D print("create Flow1D result files") unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName( test_class + ".test_thermomech_flow1D_analysis") ) Flow1D_thermomech_analysis_dir = join(temp_dir, "FEM_ccx_Flow1D_thermomech") doc_flow1d = FreeCAD.open(join(Flow1D_thermomech_analysis_dir, "Flow1D_thermomech.FCStd")) FemGui.setActiveAnalysis(doc_flow1d.Analysis) fea = ccxtools.FemToolsCcx() fea.reset_all() fea.run() fea.load_results() stats_flow1D = [] res_obj_flow1d = doc_flow1d.getObject("CCX_Time1_0_Results001") for s in stat_types: statval = resulttools.get_stats(res_obj_flow1d, s) stats_flow1D.append( "{0}: ({1:.14g}, {2:.14g})\n" .format(s, statval[0], statval[1]) ) Flow1D_thermomech_expected_values_file = join( Flow1D_thermomech_analysis_dir, "Flow1D_thermomech_expected_values" ) f = open(Flow1D_thermomech_expected_values_file, "w") for s in stats_flow1D: f.write(s) f.close() frd_result_file = os.path.splitext(fea.inp_file_name)[0] + ".frd" dat_result_file = os.path.splitext(fea.inp_file_name)[0] + ".dat" frd_Flow1D_thermomech_test_result_file = join( Flow1D_thermomech_analysis_dir, "Flow1D_thermomech.frd" ) dat_Flow1D_thermomech_test_result_file = join( Flow1D_thermomech_analysis_dir, "Flow1D_thermomech.dat" ) shutil.copyfile(frd_result_file, frd_Flow1D_thermomech_test_result_file) shutil.copyfile(dat_result_file, dat_Flow1D_thermomech_test_result_file) print("Flow1D thermomech results copied to the appropriate FEM test dirs in: " + temp_dir)