From 6fe6461dc9444207ed5daa4f0019978435f3d57e Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Fri, 17 Jan 2020 13:11:19 +0100 Subject: [PATCH 1/8] FEM, unit test, improve ccx tools Flow1D unit test --- src/Mod/Fem/femtest/app/test_ccxtools.py | 107 ++++++++++------------- 1 file changed, 47 insertions(+), 60 deletions(-) diff --git a/src/Mod/Fem/femtest/app/test_ccxtools.py b/src/Mod/Fem/femtest/app/test_ccxtools.py index 337a6e8a8b..66b8e9ab38 100644 --- a/src/Mod/Fem/femtest/app/test_ccxtools.py +++ b/src/Mod/Fem/femtest/app/test_ccxtools.py @@ -441,51 +441,27 @@ class TestCcxTools(unittest.TestCase): def test_5_Flow1D_thermomech_analysis( self ): - fcc_print("\n--------------- Start of FEM ccxtools Flow1D analysis test ---------------") - - # set up the thermomech flow1d example + # set up from femexamples.thermomech_flow1d import setup as flow1d flow1d(self.active_doc, "ccxtools") - analysis = self.active_doc.Analysis - Flow1D_thermomech_analysis_dir = testtools.get_unit_test_tmp_dir( + test_name = "Flow1D analysis test" + base_name = "Flow1D_thermomech" + analysis_dir = testtools.get_unit_test_tmp_dir( self.temp_dir, "FEM_ccx_Flow1D_thermomech" ) - fea = ccxtools.FemToolsCcx(analysis, test_mode=True) - fea.update_objects() - fcc_print("Setting up working directory {}".format(Flow1D_thermomech_analysis_dir)) - fea.setup_working_dir(Flow1D_thermomech_analysis_dir) - self.assertTrue( - True if fea.working_dir == Flow1D_thermomech_analysis_dir else False, - "Setting working directory {} failed".format(Flow1D_thermomech_analysis_dir) + # test input file writing + fea = self.input_file_writing_test( + test_name=test_name, + base_name=base_name, + analysis_dir=analysis_dir, + test_end=True, ) - fcc_print("Checking FEM inp file prerequisites for thermo-mechanical analysis...") - error = fea.check_prerequisites() - self.assertFalse( - error, - "ccxtools check_prerequisites returned error message: {}".format(error) - ) - - Flow1D_thermomech_base_name = "Flow1D_thermomech" - inpfile_given = join(self.test_file_dir, (Flow1D_thermomech_base_name + ".inp")) - inpfile_totest = join(Flow1D_thermomech_analysis_dir, (self.mesh_name + ".inp")) - fcc_print("Checking FEM inp file write...") - fcc_print("Writing {} for thermomech analysis".format(inpfile_totest)) - error = fea.write_inp_file() - self.assertFalse( - error, - "Writing failed" - ) - - fcc_print("Comparing {} to {}".format(inpfile_given, inpfile_totest)) - ret = testtools.compare_inp_files(inpfile_given, inpfile_totest) - self.assertFalse( - ret, - "ccxtools write_inp_file test failed.\n{}".format(ret) - ) + # continue tests ... + inpfile_given = join(self.test_file_dir, (base_name + ".inp")) fcc_print( "Setting up working directory to {} in order to read simulated calculations" @@ -497,35 +473,41 @@ class TestCcxTools(unittest.TestCase): "Setting working directory {} failed".format(self.test_file_dir) ) - fcc_print("Setting base name to read test {}.frd file...".format("Flow1D_thermomech")) - fea.set_base_name(Flow1D_thermomech_base_name) + fcc_print( + "Setting base name to read test {}.frd file..." + .format(base_name) + ) + fea.set_base_name(base_name) self.assertTrue( - True if fea.base_name == Flow1D_thermomech_base_name else False, - "Setting base name to {} failed".format(Flow1D_thermomech_base_name) + True if fea.base_name == base_name else False, + "Setting base name to {} failed".format(base_name) ) - fcc_print("Setting inp file name to read test {}.frd file...".format("Flow1D_thermomech")) + fcc_print( + "Setting inp file name to read test {}.frd file..." + .format(base_name) + ) fea.set_inp_file_name() self.assertTrue( True if fea.inp_file_name == inpfile_given else False, "Setting inp file name to {} failed".format(inpfile_given) ) - fcc_print("Checking FEM frd file read from Flow1D thermomech analysis...") + fcc_print("Checking FEM frd file read from {}...".format(test_name)) 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 Flow1D thermomech analysis...") - Flow1D_thermomech_expected_values = join( + fcc_print("Reading stats from result object for {}...".format(test_name)) + expected_values = join( self.test_file_dir, - "Flow1D_thermomech_expected_values" + base_name + "_expected_values" ) ret = testtools.compare_stats( fea, - Flow1D_thermomech_expected_values, + expected_values, "CCX_Time1_0_Results" ) self.assertFalse( @@ -533,31 +515,35 @@ class TestCcxTools(unittest.TestCase): "Invalid results read from .frd file" ) - Flow1D_thermomech_save_fc_file = join( - Flow1D_thermomech_analysis_dir, - (Flow1D_thermomech_base_name + ".FCStd") + save_fc_file = join( + analysis_dir, + (base_name + ".FCStd") ) fcc_print( - "Save FreeCAD file for thermomech analysis to {}..." - .format(Flow1D_thermomech_save_fc_file) + "Save FreeCAD file for {} to {}..." + .format(test_name, save_fc_file) ) - self.active_doc.saveAs(Flow1D_thermomech_save_fc_file) + self.active_doc.saveAs(save_fc_file) - fcc_print("--------------- End of FEM ccxtools Flow1D analysis test -------------------") + fcc_print("--------------- End of {} -------------------".format(test_name)) # ******************************************************************************************** def test_6_contact_shell_shell( self ): - # set up the example + # set up from femexamples import contact_shell_shell as shellcontact shellcontact.setup(self.active_doc, "ccxtools") + analysis_dir = testtools.get_unit_test_tmp_dir( + self.temp_dir, + "FEM_ccx_contact_shell_shell", + ) # test input file writing self.input_file_writing_test( test_name="contact shell shell analysis test", base_name="contact_shell_shell", - test_dir="FEM_ccx_contact_shell_shell", + analysis_dir=analysis_dir, ) # ******************************************************************************************** @@ -565,7 +551,8 @@ class TestCcxTools(unittest.TestCase): self, test_name, base_name, - test_dir + analysis_dir, + test_end=False, ): fcc_print( "\n--------------- " @@ -576,10 +563,6 @@ class TestCcxTools(unittest.TestCase): analysis = self.active_doc.Analysis solver_object = self.active_doc.CalculiXccxTools - analysis_dir = testtools.get_unit_test_tmp_dir( - self.temp_dir, - test_dir, - ) fea = ccxtools.FemToolsCcx(analysis, solver_object, test_mode=True) fea.update_objects() @@ -614,6 +597,10 @@ class TestCcxTools(unittest.TestCase): "ccxtools write_inp_file test failed.\n{}".format(ret) ) + if test_end is True: + # do not save and print End of tests + return fea + static_save_fc_file = analysis_dir + base_name + ".FCStd" fcc_print( "Save FreeCAD file for {} to {}..." From 2696477573eb8d9c4fcb98d7022f8993a24ea642 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Sat, 18 Jan 2020 06:23:36 +0100 Subject: [PATCH 2/8] FEM, unit test, ccx tools, move result reading in own def --- src/Mod/Fem/femtest/app/test_ccxtools.py | 145 +++++++++++++---------- 1 file changed, 80 insertions(+), 65 deletions(-) diff --git a/src/Mod/Fem/femtest/app/test_ccxtools.py b/src/Mod/Fem/femtest/app/test_ccxtools.py index 66b8e9ab38..8df86d50ba 100644 --- a/src/Mod/Fem/femtest/app/test_ccxtools.py +++ b/src/Mod/Fem/femtest/app/test_ccxtools.py @@ -460,72 +460,13 @@ class TestCcxTools(unittest.TestCase): test_end=True, ) - # continue tests ... - inpfile_given = join(self.test_file_dir, (base_name + ".inp")) - - fcc_print( - "Setting up working directory to {} in order to read simulated calculations" - .format(self.test_file_dir) + # test result reading + self.result_reading_test( + test_name=test_name, + base_name=base_name, + analysis_dir=analysis_dir, + fea=fea, ) - fea.setup_working_dir(self.test_file_dir) - self.assertTrue( - True if fea.working_dir == self.test_file_dir else False, - "Setting working directory {} failed".format(self.test_file_dir) - ) - - fcc_print( - "Setting base name to read test {}.frd file..." - .format(base_name) - ) - fea.set_base_name(base_name) - self.assertTrue( - True if fea.base_name == base_name else False, - "Setting base name to {} failed".format(base_name) - ) - - fcc_print( - "Setting inp file name to read test {}.frd file..." - .format(base_name) - ) - fea.set_inp_file_name() - self.assertTrue( - True if fea.inp_file_name == inpfile_given else False, - "Setting inp file name to {} failed".format(inpfile_given) - ) - - fcc_print("Checking FEM frd file read from {}...".format(test_name)) - 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 {}...".format(test_name)) - expected_values = join( - self.test_file_dir, - base_name + "_expected_values" - ) - ret = testtools.compare_stats( - fea, - expected_values, - "CCX_Time1_0_Results" - ) - self.assertFalse( - ret, - "Invalid results read from .frd file" - ) - - save_fc_file = join( - analysis_dir, - (base_name + ".FCStd") - ) - fcc_print( - "Save FreeCAD file for {} to {}..." - .format(test_name, save_fc_file) - ) - self.active_doc.saveAs(save_fc_file) - - fcc_print("--------------- End of {} -------------------".format(test_name)) # ******************************************************************************************** def test_6_contact_shell_shell( @@ -615,6 +556,80 @@ class TestCcxTools(unittest.TestCase): .format(test_name) ) + # ******************************************************************************************** + def result_reading_test( + self, + test_name, + base_name, + analysis_dir, + fea, + ): + inpfile_given = join(self.test_file_dir, (base_name + ".inp")) + + fcc_print( + "Setting up working directory to {} in order to read simulated calculations" + .format(self.test_file_dir) + ) + fea.setup_working_dir(self.test_file_dir) + self.assertTrue( + True if fea.working_dir == self.test_file_dir else False, + "Setting working directory {} failed".format(self.test_file_dir) + ) + + fcc_print( + "Setting base name to read test {}.frd file..." + .format(base_name) + ) + fea.set_base_name(base_name) + self.assertTrue( + True if fea.base_name == base_name else False, + "Setting base name to {} failed".format(base_name) + ) + + fcc_print( + "Setting inp file name to read test {}.frd file..." + .format(base_name) + ) + fea.set_inp_file_name() + self.assertTrue( + True if fea.inp_file_name == inpfile_given else False, + "Setting inp file name to {} failed".format(inpfile_given) + ) + + fcc_print("Checking FEM frd file read from {}...".format(test_name)) + 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 {}...".format(test_name)) + expected_values = join( + self.test_file_dir, + base_name + "_expected_values" + ) + ret = testtools.compare_stats( + fea, + expected_values, + "CCX_Time1_0_Results" + ) + self.assertFalse( + ret, + "Invalid results read from .frd file" + ) + + save_fc_file = join( + analysis_dir, + (base_name + ".FCStd") + ) + fcc_print( + "Save FreeCAD file for {} to {}..." + .format(test_name, save_fc_file) + ) + self.active_doc.saveAs(save_fc_file) + + fcc_print("--------------- End of {} -------------------".format(test_name)) + # ******************************************************************************************** def tearDown( self From a9a67ccbf9460baec2c01a43eb03cca1de8f1387 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Sat, 18 Jan 2020 06:24:43 +0100 Subject: [PATCH 3/8] FEM: unit test ccx tools, better var name --- src/Mod/Fem/femtest/app/test_ccxtools.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Mod/Fem/femtest/app/test_ccxtools.py b/src/Mod/Fem/femtest/app/test_ccxtools.py index 8df86d50ba..f34bacd6e2 100644 --- a/src/Mod/Fem/femtest/app/test_ccxtools.py +++ b/src/Mod/Fem/femtest/app/test_ccxtools.py @@ -542,12 +542,12 @@ class TestCcxTools(unittest.TestCase): # do not save and print End of tests return fea - static_save_fc_file = analysis_dir + base_name + ".FCStd" + save_fc_file = analysis_dir + base_name + ".FCStd" fcc_print( "Save FreeCAD file for {} to {}..." - .format(test_name, static_save_fc_file) + .format(test_name, save_fc_file) ) - self.active_doc.saveAs(static_save_fc_file) + self.active_doc.saveAs(save_fc_file) fcc_print( "\n--------------- " From 6b81d39b144b7d2c0026ddabaccd09d90537db8d Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Sat, 18 Jan 2020 06:35:31 +0100 Subject: [PATCH 4/8] FEM: unit test, ccx tools, use methods for thermomechanical test --- src/Mod/Fem/femtest/app/test_ccxtools.py | 115 +++++------------------ 1 file changed, 22 insertions(+), 93 deletions(-) diff --git a/src/Mod/Fem/femtest/app/test_ccxtools.py b/src/Mod/Fem/femtest/app/test_ccxtools.py index f34bacd6e2..e3440ce3f6 100644 --- a/src/Mod/Fem/femtest/app/test_ccxtools.py +++ b/src/Mod/Fem/femtest/app/test_ccxtools.py @@ -334,109 +334,35 @@ class TestCcxTools(unittest.TestCase): def test_4_thermomech_analysis( self ): - - fcc_print("\n--------------- Start of FEM ccxtools thermomechanical analysis test -----") - - # set up the thermomech example + # set up from femexamples.thermomech_spine import setup as thermomech thermomech(self.active_doc, "ccxtools") - analysis = self.active_doc.Analysis - - thermomech_analysis_dir = testtools.get_unit_test_tmp_dir( + test_name = "thermomechanical analysis test" + base_name = "spine_thermomech" + res_obj_name = "CCX_Results" + analysis_dir = testtools.get_unit_test_tmp_dir( self.temp_dir, "FEM_ccx_thermomech" ) - fea = ccxtools.FemToolsCcx(analysis, test_mode=True) - fea.update_objects() - fcc_print("Setting up working directory {}".format(thermomech_analysis_dir)) - fea.setup_working_dir(thermomech_analysis_dir) - self.assertTrue( - True if fea.working_dir == thermomech_analysis_dir else False, - "Setting working directory {} failed".format(thermomech_analysis_dir) + # test input file writing + fea = self.input_file_writing_test( + test_name=test_name, + base_name=base_name, + analysis_dir=analysis_dir, + test_end=True, ) - fcc_print("Checking FEM inp file prerequisites for thermo-mechanical analysis...") - error = fea.check_prerequisites() - self.assertFalse( - error, - "ccxtools check_prerequisites returned error message: {}".format(error) + # test result reading + self.result_reading_test( + test_name=test_name, + base_name=base_name, + analysis_dir=analysis_dir, + fea=fea, + res_obj_name=res_obj_name, ) - thermomech_base_name = "spine_thermomech" - inpfile_given = join(self.test_file_dir, (thermomech_base_name + ".inp")) - inpfile_totest = join(thermomech_analysis_dir, (self.mesh_name + ".inp")) - fcc_print("Checking FEM inp file write...") - fcc_print("Writing {} for thermomech analysis".format(inpfile_totest)) - error = fea.write_inp_file() - self.assertFalse( - error, - "Writing failed" - ) - - fcc_print("Comparing {} to {}".format(inpfile_given, inpfile_totest)) - ret = testtools.compare_inp_files(inpfile_given, inpfile_totest) - self.assertFalse( - ret, - "ccxtools write_inp_file test failed.\n{}".format(ret) - ) - - fcc_print( - "Setting up working directory to {} in order to read simulated calculations" - .format(self.test_file_dir) - ) - fea.setup_working_dir(self.test_file_dir) - self.assertTrue( - True if fea.working_dir == self.test_file_dir else False, - "Setting working directory {} failed".format(self.test_file_dir) - ) - - fcc_print("Setting base name to read test {}.frd file...".format("spine_thermomech")) - fea.set_base_name(thermomech_base_name) - self.assertTrue( - True if fea.base_name == thermomech_base_name else False, - "Setting base name to {} failed".format(thermomech_base_name) - ) - - fcc_print("Setting inp file name to read test {}.frd file...".format("spine_thermomech")) - fea.set_inp_file_name() - self.assertTrue( - True if fea.inp_file_name == inpfile_given else False, - "Setting inp file name to {} failed".format(inpfile_given) - ) - - fcc_print("Checking FEM frd file read from 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...") - thermomech_expected_values = join( - self.test_file_dir, - "spine_thermomech_expected_values" - ) - ret = testtools.compare_stats( - fea, - thermomech_expected_values, - "CCX_Results" - ) - self.assertFalse( - ret, - "Invalid results read from .frd file" - ) - - thermomech_save_fc_file = thermomech_analysis_dir + thermomech_base_name + ".FCStd" - fcc_print( - "Save FreeCAD file for thermomech analysis to {}..." - .format(thermomech_save_fc_file) - ) - self.active_doc.saveAs(thermomech_save_fc_file) - - fcc_print("--------------- End of FEM ccxtools thermomechanical analysis test ---------") - # ******************************************************************************************** def test_5_Flow1D_thermomech_analysis( self @@ -447,6 +373,7 @@ class TestCcxTools(unittest.TestCase): test_name = "Flow1D analysis test" base_name = "Flow1D_thermomech" + res_obj_name = "CCX_Time1_0_Results" analysis_dir = testtools.get_unit_test_tmp_dir( self.temp_dir, "FEM_ccx_Flow1D_thermomech" @@ -466,6 +393,7 @@ class TestCcxTools(unittest.TestCase): base_name=base_name, analysis_dir=analysis_dir, fea=fea, + res_obj_name=res_obj_name, ) # ******************************************************************************************** @@ -563,6 +491,7 @@ class TestCcxTools(unittest.TestCase): base_name, analysis_dir, fea, + res_obj_name, ): inpfile_given = join(self.test_file_dir, (base_name + ".inp")) @@ -611,7 +540,7 @@ class TestCcxTools(unittest.TestCase): ret = testtools.compare_stats( fea, expected_values, - "CCX_Time1_0_Results" + res_obj_name ) self.assertFalse( ret, From 1ad0d00ab3d43394bb4a5336c2b2b1a49abedd62 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Sat, 18 Jan 2020 06:43:11 +0100 Subject: [PATCH 5/8] FEM: unit test, ccx tools, use methods for all the rest tests --- src/Mod/Fem/femtest/app/test_ccxtools.py | 267 ++++------------------- 1 file changed, 46 insertions(+), 221 deletions(-) diff --git a/src/Mod/Fem/femtest/app/test_ccxtools.py b/src/Mod/Fem/femtest/app/test_ccxtools.py index e3440ce3f6..95ab456eb9 100644 --- a/src/Mod/Fem/femtest/app/test_ccxtools.py +++ b/src/Mod/Fem/femtest/app/test_ccxtools.py @@ -71,265 +71,90 @@ class TestCcxTools(unittest.TestCase): def test_1_static_analysis( self ): - fcc_print("\n--------------- Start of FEM ccxtools static analysis test ---------------") - - # set up the static analysis example + # set up from femexamples import boxanalysis as box box.setup_static(self.active_doc, "ccxtools") - analysis = self.active_doc.Analysis - solver_object = self.active_doc.CalculiXccxTools - fcc_print("Analysis {}".format(type(analysis))) - fcc_print("Analysis {}".format(analysis.TypeId)) - - static_analysis_dir = testtools.get_unit_test_tmp_dir( + test_name = "ccxtools static analysis test" + base_name = "cube_static" + res_obj_name = "CCX_Results" + analysis_dir = testtools.get_unit_test_tmp_dir( self.temp_dir, "FEM_ccx_static" ) - fea = ccxtools.FemToolsCcx(analysis, solver_object, test_mode=True) - fea.update_objects() - fcc_print("fea Analysis {}".format(type(fea.analysis))) - fcc_print("fea Analysis {}".format(fea.analysis.TypeId)) - fcc_print("Setting up working directory {}".format(static_analysis_dir)) - fea.setup_working_dir(static_analysis_dir) - self.assertTrue( - True if fea.working_dir == static_analysis_dir else False, - "Setting working directory {} failed".format(static_analysis_dir) + # test input file writing + fea = self.input_file_writing_test( + test_name=test_name, + base_name=base_name, + analysis_dir=analysis_dir, + test_end=True, ) - fcc_print("Checking FEM inp file prerequisites for static analysis...") - error = fea.check_prerequisites() - self.assertFalse( - error, - "ccxtools check_prerequisites returned error message: {}".format(error) + # test result reading + self.result_reading_test( + test_name=test_name, + base_name=base_name, + analysis_dir=analysis_dir, + fea=fea, + res_obj_name=res_obj_name, ) - static_base_name = "cube_static" - inpfile_given = join(self.test_file_dir, (static_base_name + ".inp")) - inpfile_totest = join(static_analysis_dir, (self.mesh_name + ".inp")) - fcc_print("Checking FEM inp file write...") - fcc_print("Writing {} for static analysis".format(inpfile_totest)) - error = fea.write_inp_file() - self.assertFalse( - error, - "Writing failed" - ) - - fcc_print("Comparing {} to {}".format(inpfile_given, inpfile_totest)) - ret = testtools.compare_inp_files(inpfile_given, inpfile_totest) - self.assertFalse( - ret, - "ccxtools write_inp_file test failed.\n{}".format(ret) - ) - - fcc_print( - "Setting up working directory to {} in order to read simulated calculations" - .format(self.test_file_dir) - ) - fea.setup_working_dir(self.test_file_dir) - fcc_print(fea.working_dir) - fcc_print(self.test_file_dir) - self.assertTrue( - True if fea.working_dir == self.test_file_dir else False, - "Setting working directory {} failed".format(self.test_file_dir) - ) - - fcc_print("Setting base name to read test {}.frd file...".format("cube_static")) - fea.set_base_name(static_base_name) - self.assertTrue( - True if fea.base_name == static_base_name else False, - "Setting base name to {} failed".format(static_base_name) - ) - - fcc_print("Setting inp file name to read test {}.frd file...".format("cube_static")) - fea.set_inp_file_name() - self.assertTrue( - True if fea.inp_file_name == inpfile_given else False, - "Setting inp file name to {} failed".format(inpfile_given) - ) - - fcc_print("Checking FEM frd file read from static 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 static analysis...") - static_expected_values = join(self.test_file_dir, "cube_static_expected_values") - ret = testtools.compare_stats( - fea, - static_expected_values, - "CCX_Results" - ) - self.assertFalse( - ret, - "Invalid results read from .frd file" - ) - - static_save_fc_file = static_analysis_dir + static_base_name + ".FCStd" - fcc_print("Save FreeCAD file for static analysis to {}...".format(static_save_fc_file)) - self.active_doc.saveAs(static_save_fc_file) - - fcc_print("--------------- End of FEM ccxtools static analysis test -------------------") - # ******************************************************************************************** def test_2_static_multiple_material( self ): - fcc_print("\n--------------- Start of FEM ccxtools multiple material test -------------") - - # set up the simple multimat example + # set up from femexamples import material_multiple_twoboxes material_multiple_twoboxes.setup(self.active_doc, "ccxtools") - analysis = self.active_doc.Analysis - solver_object = self.active_doc.CalculiXccxTools - - static_multiplemat_dir = testtools.get_unit_test_tmp_dir( + test_name = "multiple material test" + base_name = "multimat" + analysis_dir = testtools.get_unit_test_tmp_dir( self.temp_dir, - "FEM_ccx_multimat/" - ) - fea = ccxtools.FemToolsCcx(analysis, solver_object, test_mode=True) - fea.update_objects() - fea.setup_working_dir(static_multiplemat_dir) - - fcc_print("Checking FEM inp file prerequisites for ccxtools multimat analysis...") - error = fea.check_prerequisites() - self.assertFalse( - error, - "ccxtools check_prerequisites returned error message: {}".format(error) + "FEM_ccx_multimat" ) - static_base_name = "multimat" - inpfile_given = join(self.test_file_dir, (static_base_name + ".inp")) - inpfile_totest = join(static_multiplemat_dir, (self.mesh_name + ".inp")) - fcc_print("Checking FEM inp file write...") - fcc_print("Writing {} for static multiple material".format(inpfile_totest)) - error = fea.write_inp_file() - self.assertFalse( - error, - "Writing failed" + # test input file writing + self.input_file_writing_test( + test_name=test_name, + base_name=base_name, + analysis_dir=analysis_dir, ) - fcc_print("Comparing {} to {}".format(inpfile_given, inpfile_totest)) - ret = testtools.compare_inp_files(inpfile_given, inpfile_totest) - self.assertFalse( - ret, - "ccxtools write_inp_file test failed.\n{}".format(ret) - ) - - static_save_fc_file = static_multiplemat_dir + static_base_name + ".FCStd" - fcc_print("Save FreeCAD file for static analysis to {}...".format(static_save_fc_file)) - self.active_doc.saveAs(static_save_fc_file) - - fcc_print("--------------- End of FEM ccxtools multiple material test -----------------") - # ******************************************************************************************** def test_3_freq_analysis( self ): - fcc_print("\n--------------- Start of FEM ccxtools frequency analysis test ------------") - - # set up the static analysis example + # set up from femexamples import boxanalysis as box box.setup_frequency(self.active_doc, "ccxtools") - analysis = self.active_doc.Analysis - solver_object = self.active_doc.CalculiXccxTools - - frequency_analysis_dir = testtools.get_unit_test_tmp_dir( + test_name = "frequency analysis test" + base_name = "cube_frequency" + res_obj_name = "CCX_Mode1_Results" + analysis_dir = testtools.get_unit_test_tmp_dir( self.temp_dir, "FEM_ccx_frequency" ) - fea = ccxtools.FemToolsCcx(analysis, solver_object, test_mode=True) - fea.update_objects() - fcc_print("Setting up working directory {}".format(frequency_analysis_dir)) - fea.setup_working_dir(frequency_analysis_dir) - self.assertTrue( - True if fea.working_dir == frequency_analysis_dir else False, - "Setting working directory {} failed".format(frequency_analysis_dir) + # test input file writing + fea = self.input_file_writing_test( + test_name=test_name, + base_name=base_name, + analysis_dir=analysis_dir, + test_end=True, ) - fcc_print("Checking FEM inp file prerequisites for frequency analysis...") - error = fea.check_prerequisites() - self.assertFalse( - error, - "ccxtools check_prerequisites returned error message: {}".format(error) + # test result reading + self.result_reading_test( + test_name=test_name, + base_name=base_name, + analysis_dir=analysis_dir, + fea=fea, + res_obj_name=res_obj_name, ) - frequency_base_name = "cube_frequency" - inpfile_given = join(self.test_file_dir, (frequency_base_name + ".inp")) - inpfile_totest = join(frequency_analysis_dir, (self.mesh_name + ".inp")) - fcc_print("Checking FEM inp file write...") - fcc_print("Writing {} for frequency analysis".format(inpfile_totest)) - error = fea.write_inp_file() - self.assertFalse( - error, - "Writing failed" - ) - - fcc_print("Comparing {} to {}".format(inpfile_given, inpfile_totest)) - ret = testtools.compare_inp_files(inpfile_given, inpfile_totest) - self.assertFalse( - ret, - "ccxtools write_inp_file test failed.\n{}".format(ret) - ) - - fcc_print( - "Setting up working directory to {} in order to read simulated calculations". - format(self.test_file_dir) - ) - fea.setup_working_dir(self.test_file_dir) - self.assertTrue( - True if fea.working_dir == self.test_file_dir else False, - "Setting working directory {} failed".format(self.test_file_dir) - ) - - fcc_print("Setting base name to read test {}.frd file...".format(frequency_base_name)) - fea.set_base_name(frequency_base_name) - self.assertTrue( - True if fea.base_name == frequency_base_name else False, - "Setting base name to {} failed".format(frequency_base_name) - ) - - fcc_print("Setting inp file name to read test {}.frd file...".format("cube_frequency")) - fea.set_inp_file_name() - self.assertTrue( - True if fea.inp_file_name == inpfile_given else False, - "Setting inp file name to {} failed".format(inpfile_given) - ) - - fcc_print("Checking FEM frd file read from frequency 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 frequency analysis...") - frequency_expected_values = join(self.test_file_dir, "cube_frequency_expected_values") - ret = testtools.compare_stats( - fea, - frequency_expected_values, - "CCX_Mode1_Results" - ) - self.assertFalse( - ret, - "Invalid results read from .frd file" - ) - - frequency_save_fc_file = frequency_analysis_dir + frequency_base_name + ".FCStd" - fcc_print( - "Save FreeCAD file for frequency analysis to {}..." - .format(frequency_save_fc_file) - ) - self.active_doc.saveAs(frequency_save_fc_file) - - fcc_print("--------------- End of FEM ccxtools frequency analysis test ----------------") - # ******************************************************************************************** def test_4_thermomech_analysis( self From 6866397c14226a504232b027b73ce4085e73f01e Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 18 Jan 2020 12:21:00 +0100 Subject: [PATCH 6/8] Py2: [skip ci] provide time._process_time --- src/App/FreeCADInit.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/App/FreeCADInit.py b/src/App/FreeCADInit.py index 70366570c4..336c9cf1d7 100644 --- a/src/App/FreeCADInit.py +++ b/src/App/FreeCADInit.py @@ -247,6 +247,12 @@ except ImportError: FreeCAD.Console.PrintError("\n\nSeems the python standard libs are not installed, bailing out!\n\n") raise +# Backward compatibility to Py2 +import sys +if sys.version_info.major < 3: + import time + time.process_time = time.clock + class FCADLogger(object): '''Convenient class for tagged logging. From a3622ee49feb4391e3c1015f8922095e75af538f Mon Sep 17 00:00:00 2001 From: donovaly Date: Fri, 17 Jan 2020 21:31:49 +0100 Subject: [PATCH 7/8] [TD] rename some Draw* elements - try 2 as discussed here: https://forum.freecadweb.org/viewtopic.php?p=360042#p360042 --- src/Mod/TechDraw/App/DrawWeldSymbol.cpp | 4 ++-- src/Mod/TechDraw/Gui/TaskActiveView.cpp | 2 +- src/Mod/TechDraw/Gui/TaskLeaderLine.cpp | 2 +- src/Mod/TechDraw/Gui/TaskRichAnno.cpp | 2 +- src/Mod/TechDraw/Gui/TaskSectionView.cpp | 2 +- src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawWeldSymbol.cpp b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp index 638ee17b03..155c7dea99 100644 --- a/src/Mod/TechDraw/App/DrawWeldSymbol.cpp +++ b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp @@ -87,14 +87,14 @@ void DrawWeldSymbol::onSettingDocument() return; } - std::string tileName1 = doc->getUniqueObjectName("DrawTileWeld"); + std::string tileName1 = doc->getUniqueObjectName("TileWeld"); auto tile1Obj( doc->addObject( "TechDraw::DrawTileWeld", tileName1.c_str() ) ); DrawTileWeld* tile1 = dynamic_cast(tile1Obj); if (tile1 != nullptr) { tile1->TileParent.setValue(this); } - std::string tileName2 = doc->getUniqueObjectName("DrawTileWeld"); + std::string tileName2 = doc->getUniqueObjectName("TileWeld"); auto tile2Obj( doc->addObject( "TechDraw::DrawTileWeld", tileName2.c_str() ) ); DrawTileWeld* tile2 = dynamic_cast(tile2Obj); if (tile2 != nullptr) { diff --git a/src/Mod/TechDraw/Gui/TaskActiveView.cpp b/src/Mod/TechDraw/Gui/TaskActiveView.cpp index 8e61eeaa29..1bb61b5623 100644 --- a/src/Mod/TechDraw/Gui/TaskActiveView.cpp +++ b/src/Mod/TechDraw/Gui/TaskActiveView.cpp @@ -116,7 +116,7 @@ TechDraw::DrawViewSymbol* TaskActiveView::createActiveView(void) { // Base::Console().Message("TAV::createActiveView()\n"); - std::string symbolName = m_pageFeat->getDocument()->getUniqueObjectName("DrawActiveView"); + std::string symbolName = m_pageFeat->getDocument()->getUniqueObjectName("ActiveView"); std::string symbolType = "TechDraw::DrawViewSymbol"; std::string pageName = m_pageFeat->getNameInDocument(); diff --git a/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp b/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp index ddfb437cfa..5b87221bd9 100644 --- a/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp +++ b/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp @@ -261,7 +261,7 @@ void TaskLeaderLine::setUiEdit() void TaskLeaderLine::createLeaderFeature(std::vector converted) { // Base::Console().Message("TTL::createLeaderFeature()\n"); - m_leaderName = m_basePage->getDocument()->getUniqueObjectName("DrawLeaderLine"); + m_leaderName = m_basePage->getDocument()->getUniqueObjectName("LeaderLine"); m_leaderType = "TechDraw::DrawLeaderLine"; std::string PageName = m_basePage->getNameInDocument(); diff --git a/src/Mod/TechDraw/Gui/TaskRichAnno.cpp b/src/Mod/TechDraw/Gui/TaskRichAnno.cpp index fec698e24f..4b34908314 100644 --- a/src/Mod/TechDraw/Gui/TaskRichAnno.cpp +++ b/src/Mod/TechDraw/Gui/TaskRichAnno.cpp @@ -281,7 +281,7 @@ void TaskRichAnno::onEditorExit(void) void TaskRichAnno::createAnnoFeature() { // Base::Console().Message("TRA::createAnnoFeature()"); - std::string annoName = m_basePage->getDocument()->getUniqueObjectName("DrawRichAnno"); + std::string annoName = m_basePage->getDocument()->getUniqueObjectName("RichTextAnnotation"); std::string annoType = "TechDraw::DrawRichAnno"; std::string PageName = m_basePage->getNameInDocument(); diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.cpp b/src/Mod/TechDraw/Gui/TaskSectionView.cpp index 964a63ebd5..c5c8c5567e 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.cpp +++ b/src/Mod/TechDraw/Gui/TaskSectionView.cpp @@ -351,7 +351,7 @@ TechDraw::DrawViewSection* TaskSectionView::createSectionView(void) Gui::Command::openCommand("Create SectionView"); TechDraw::DrawViewSection* newSection = nullptr; if (m_section == nullptr) { - sectionName = m_base->getDocument()->getUniqueObjectName("DrawViewSection"); + sectionName = m_base->getDocument()->getUniqueObjectName("SectionView"); std::string sectionType = "TechDraw::DrawViewSection"; TechDraw::DrawPage* page = m_base->findParentPage(); diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp index 18829d0d05..5e42060dfd 100644 --- a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp @@ -434,7 +434,7 @@ TechDraw::DrawWeldSymbol* TaskWeldingSymbol::createWeldingSymbol(void) { // Base::Console().Message("TWS::createWeldingSymbol()\n"); - std::string symbolName = m_leadFeat->getDocument()->getUniqueObjectName("DrawWeldSymbol"); + std::string symbolName = m_leadFeat->getDocument()->getUniqueObjectName("WeldSymbol"); std::string symbolType = "TechDraw::DrawWeldSymbol"; TechDraw::DrawPage* page = m_leadFeat->findParentPage(); From 120b69c74f7dac8c4fa6dbc0a7e10674bde9216c Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 18 Jan 2020 15:29:44 +0100 Subject: [PATCH 8/8] App: add methods to change import/export module of a registered filetype --- src/App/Application.cpp | 38 +++++++++++++++++++++++++++++--------- src/App/Application.h | 6 ++++++ src/App/ApplicationPy.cpp | 28 ++++++++++++++++++++++++++++ src/Mod/Import/InitGui.py | 4 ++++ src/Mod/Part/Init.py | 4 ++-- 5 files changed, 69 insertions(+), 11 deletions(-) diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 5624e8e4e7..679e4753e1 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -130,13 +130,13 @@ using namespace App; using namespace std; using namespace boost; -using namespace boost::program_options; - - -// scriptings (scripts are built-in but can be overridden by command line option) -#include -#include -#include +using namespace boost::program_options; + + +// scriptings (scripts are built-in but can be overridden by command line option) +#include +#include +#include #ifdef _MSC_VER // New handler for Microsoft Visual C++ compiler # pragma warning( disable : 4535 ) @@ -1082,6 +1082,16 @@ void Application::addImportType(const char* Type, const char* ModuleName) } } +void Application::changeImportModule(const char* Type, const char* OldModuleName, const char* NewModuleName) +{ + for (auto& it : _mImportTypes) { + if (it.filter == Type && it.module == OldModuleName) { + it.module = NewModuleName; + break; + } + } +} + std::vector Application::getImportModules(const char* Type) const { std::vector modules; @@ -1195,6 +1205,16 @@ void Application::addExportType(const char* Type, const char* ModuleName) } } +void Application::changeExportModule(const char* Type, const char* OldModuleName, const char* NewModuleName) +{ + for (auto& it : _mExportTypes) { + if (it.filter == Type && it.module == OldModuleName) { + it.module = NewModuleName; + break; + } + } +} + std::vector Application::getExportModules(const char* Type) const { std::vector modules; @@ -2256,7 +2276,7 @@ void Application::LoadParameters(void) #if defined(_MSC_VER) // fix weird error while linking boost (all versions of VC) -// VS2010: https://forum.freecadweb.org/viewtopic.php?f=4&t=1886&p=12553&hilit=boost%3A%3Afilesystem%3A%3Aget#p12553 +// VS2010: https://forum.freecadweb.org/viewtopic.php?f=4&t=1886&p=12553&hilit=boost%3A%3Afilesystem%3A%3Aget#p12553 namespace boost { namespace program_options { std::string arg="arg"; } } #if (defined (BOOST_VERSION) && (BOOST_VERSION >= 104100)) namespace boost { namespace program_options { @@ -2946,7 +2966,7 @@ std::string Application::FindHomePath(const char* sCall) binPath += L"bin"; SetDllDirectoryW(binPath.c_str()); - // https://stackoverflow.com/questions/5625884/conversion-of-stdwstring-to-qstring-throws-linker-error + // https://stackoverflow.com/questions/5625884/conversion-of-stdwstring-to-qstring-throws-linker-error #ifdef _MSC_VER QString str = QString::fromUtf16(reinterpret_cast(homePath.c_str())); #else diff --git a/src/App/Application.h b/src/App/Application.h index ba4d941643..1605a48ce4 100644 --- a/src/App/Application.h +++ b/src/App/Application.h @@ -300,6 +300,8 @@ public: //@{ /// Register an import filetype and a module name void addImportType(const char* Type, const char* ModuleName); + /// Change the module name of a registered filetype + void changeImportModule(const char* Type, const char* OldModuleName, const char* NewModuleName); /// Return a list of modules that support the given filetype. std::vector getImportModules(const char* Type) const; /// Return a list of all modules. @@ -316,6 +318,8 @@ public: //@{ /// Register an export filetype and a module name void addExportType(const char* Type, const char* ModuleName); + /// Change the module name of a registered filetype + void changeExportModule(const char* Type, const char* OldModuleName, const char* NewModuleName); /// Return a list of modules that support the given filetype. std::vector getExportModules(const char* Type) const; /// Return a list of all modules. @@ -458,8 +462,10 @@ private: static PyObject* sSetConfig (PyObject *self,PyObject *args); static PyObject* sDumpConfig (PyObject *self,PyObject *args); static PyObject* sAddImportType (PyObject *self,PyObject *args); + static PyObject* sChangeImportModule(PyObject *self,PyObject *args); static PyObject* sGetImportType (PyObject *self,PyObject *args); static PyObject* sAddExportType (PyObject *self,PyObject *args); + static PyObject* sChangeExportModule(PyObject *self,PyObject *args); static PyObject* sGetExportType (PyObject *self,PyObject *args); static PyObject* sGetResourceDir (PyObject *self,PyObject *args); static PyObject* sGetUserAppDataDir (PyObject *self,PyObject *args); diff --git a/src/App/ApplicationPy.cpp b/src/App/ApplicationPy.cpp index 75e943824e..44687ac0ad 100644 --- a/src/App/ApplicationPy.cpp +++ b/src/App/ApplicationPy.cpp @@ -72,6 +72,8 @@ PyMethodDef Application::Methods[] = { "Dump the configuration to the output."}, {"addImportType", (PyCFunction) Application::sAddImportType, METH_VARARGS, "Register filetype for import"}, + {"changeImportModule", (PyCFunction) Application::sChangeImportModule, METH_VARARGS, + "Change the import module name of a registered filetype"}, {"getImportType", (PyCFunction) Application::sGetImportType, METH_VARARGS, "Get the name of the module that can import the filetype"}, {"EndingAdd", (PyCFunction) Application::sAddImportType, METH_VARARGS, // deprecated @@ -80,6 +82,8 @@ PyMethodDef Application::Methods[] = { "deprecated -- use getImportType"}, {"addExportType", (PyCFunction) Application::sAddExportType, METH_VARARGS, "Register filetype for export"}, + {"changeExportModule", (PyCFunction) Application::sChangeExportModule, METH_VARARGS, + "Change the export module name of a registered filetype"}, {"getExportType", (PyCFunction) Application::sGetExportType, METH_VARARGS, "Get the name of the module that can export the filetype"}, {"getResourceDir", (PyCFunction) Application::sGetResourceDir, METH_VARARGS, @@ -526,6 +530,18 @@ PyObject* Application::sAddImportType(PyObject * /*self*/, PyObject *args) Py_Return; } +PyObject* Application::sChangeImportModule(PyObject * /*self*/, PyObject *args) +{ + char *key,*oldMod,*newMod; + + if (!PyArg_ParseTuple(args, "sss", &key,&oldMod,&newMod)) + return nullptr; + + GetApplication().changeImportModule(key,oldMod,newMod); + + Py_Return; +} + PyObject* Application::sGetImportType(PyObject * /*self*/, PyObject *args) { char* psKey=0; @@ -578,6 +594,18 @@ PyObject* Application::sAddExportType(PyObject * /*self*/, PyObject *args) Py_Return; } +PyObject* Application::sChangeExportModule(PyObject * /*self*/, PyObject *args) +{ + char *key,*oldMod,*newMod; + + if (!PyArg_ParseTuple(args, "sss", &key,&oldMod,&newMod)) + return nullptr; + + GetApplication().changeExportModule(key,oldMod,newMod); + + Py_Return; +} + PyObject* Application::sGetExportType(PyObject * /*self*/, PyObject *args) { char* psKey=0; diff --git a/src/Mod/Import/InitGui.py b/src/Mod/Import/InitGui.py index ee078669e3..d55f9c0d2c 100644 --- a/src/Mod/Import/InitGui.py +++ b/src/Mod/Import/InitGui.py @@ -29,6 +29,10 @@ #***************************************************************************/ +# Registered in Part's Init.py file +FreeCAD.changeImportModule("STEP with colors (*.step *.stp)","Import","ImportGui") +FreeCAD.changeExportModule("STEP with colors (*.step *.stp)","Import","ImportGui") + """ class ImportWorkbench ( Workbench ): "Import workbench object" diff --git a/src/Mod/Part/Init.py b/src/Mod/Part/Init.py index 23ecd7cb1b..a0ba689b53 100644 --- a/src/Mod/Part/Init.py +++ b/src/Mod/Part/Init.py @@ -32,7 +32,7 @@ FreeCAD.addImportType("BREP format (*.brep *.brp)","Part") FreeCAD.addExportType("BREP format (*.brep *.brp)","Part") FreeCAD.addImportType("IGES format (*.iges *.igs)","Part") FreeCAD.addExportType("IGES format (*.iges *.igs)","Part") -FreeCAD.addImportType("STEP with colors (*.step *.stp)","ImportGui") -FreeCAD.addExportType("STEP with colors (*.step *.stp)","ImportGui") +FreeCAD.addImportType("STEP with colors (*.step *.stp)","Import") +FreeCAD.addExportType("STEP with colors (*.step *.stp)","Import") FreeCAD.__unit_test__ += [ "TestPartApp" ]