diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index a1477734bd..be62a64a03 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -207,7 +207,8 @@ SET(FemTestsApp_SRCS femtest/app/test_object.py femtest/app/test_open.py femtest/app/test_result.py - femtest/app/test_solverframework.py + femtest/app/test_solver_calculix.py + femtest/app/test_solver_elmer.py ) SET(FemTestsFiles_SRCS diff --git a/src/Mod/Fem/TestFemApp.py b/src/Mod/Fem/TestFemApp.py index a0c12d3dff..09f280a9bd 100644 --- a/src/Mod/Fem/TestFemApp.py +++ b/src/Mod/Fem/TestFemApp.py @@ -35,7 +35,8 @@ from femtest.app.test_mesh import TestMeshEleTetra10 as FemTest08 from femtest.app.test_mesh import TestMeshGroups as FemTest09 from femtest.app.test_result import TestResult as FemTest10 from femtest.app.test_ccxtools import TestCcxTools as FemTest11 -from femtest.app.test_solverframework import TestSolverFrameWork as FemTest12 +from femtest.app.test_solver_calculix import TestSolverCalculix as FemTest12 +from femtest.app.test_solver_elmer import TestSolverElmer as FemTest13 # dummy usage to get flake8 and lgtm quiet False if FemTest01.__name__ else True @@ -50,3 +51,4 @@ False if FemTest09.__name__ else True False if FemTest10.__name__ else True False if FemTest11.__name__ else True False if FemTest12.__name__ else True +False if FemTest13.__name__ else True diff --git a/src/Mod/Fem/femtest/app/test_solver_calculix.py b/src/Mod/Fem/femtest/app/test_solver_calculix.py new file mode 100644 index 0000000000..94f342bf7a --- /dev/null +++ b/src/Mod/Fem/femtest/app/test_solver_calculix.py @@ -0,0 +1,117 @@ +# *************************************************************************** +# * Copyright (c) 2018 Bernd Hahnebach * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +__title__ = "Solver calculix FEM unit tests" +__author__ = "Bernd Hahnebach" +__url__ = "http://www.freecadweb.org" + +import unittest +from os.path import join + +import FreeCAD + +import femsolver.run +from . import support_utils as testtools +from .support_utils import fcc_print + + +class TestSolverCalculix(unittest.TestCase): + fcc_print("import TestSolverCalculix") + + # ******************************************************************************************** + def setUp( + self + ): + # setUp is executed before every test + + # new document + self.document = FreeCAD.newDocument(self.__class__.__name__) + + # more inits + self.mesh_name = "Mesh" + self.temp_dir = testtools.get_unit_test_tmp_dir( + testtools.get_fem_test_tmp_dir(), + "FEM_solver_calculix" + ) + + # ******************************************************************************************** + def tearDown( + self + ): + # tearDown is executed after every test + FreeCAD.closeDocument(self.document.Name) + + # ******************************************************************************************** + def test_00print( + self + ): + # since method name starts with 00 this will be run first + # this test just prints a line with stars + + fcc_print("\n{0}\n{1} run FEM TestSolverFrameWork tests {2}\n{0}".format( + 100 * "*", + 10 * "*", + 55 * "*" + )) + + # ******************************************************************************************** + def test_solver_calculix( + self + ): + fcc_print("\n--------------- Start of FEM tests solver framework solver CalculiX ------") + + # set up the CalculiX static analysis example + from femexamples.boxanalysis_static import setup + setup(self.document, "calculix") + + solver_obj = self.document.SolverCalculiX + + base_name = "cube_static" + analysis_dir = testtools.get_unit_test_tmp_dir(self.temp_dir, solver_obj.Name) + + # save the file + save_fc_file = join(analysis_dir, solver_obj.Name + "_" + base_name + ".FCStd") + fcc_print("Save FreeCAD file to {}...".format(save_fc_file)) + self.document.saveAs(save_fc_file) + + # write input file + fcc_print("Checking FEM input file writing for CalculiX solver framework solver ...") + machine_ccx = solver_obj.Proxy.createMachine( + solver_obj, + analysis_dir + ) + machine_ccx.target = femsolver.run.PREPARE + machine_ccx.start() + machine_ccx.join() # wait for the machine to finish. + + infile_given = join( + testtools.get_fem_test_home_dir(), + "ccx", + (base_name + ".inp") + ) + inpfile_totest = join(analysis_dir, (self.mesh_name + ".inp")) + fcc_print("Comparing {} to {}".format(infile_given, inpfile_totest)) + ret = testtools.compare_inp_files(infile_given, inpfile_totest) + self.assertFalse(ret, "ccxtools write_inp_file test failed.\n{}".format(ret)) + + fcc_print("--------------- End of FEM tests solver framework solver CalculiX --------") diff --git a/src/Mod/Fem/femtest/app/test_solverframework.py b/src/Mod/Fem/femtest/app/test_solver_elmer.py similarity index 79% rename from src/Mod/Fem/femtest/app/test_solverframework.py rename to src/Mod/Fem/femtest/app/test_solver_elmer.py index c4e7f207d7..c1fc02f57b 100644 --- a/src/Mod/Fem/femtest/app/test_solverframework.py +++ b/src/Mod/Fem/femtest/app/test_solver_elmer.py @@ -21,7 +21,7 @@ # * * # *************************************************************************** -__title__ = "Solver frame work FEM unit tests" +__title__ = "Solver elmer FEM unit tests" __author__ = "Bernd Hahnebach" __url__ = "http://www.freecadweb.org" @@ -36,8 +36,8 @@ from . import support_utils as testtools from .support_utils import fcc_print -class TestSolverFrameWork(unittest.TestCase): - fcc_print("import TestSolverFrameWork") +class TestSolverElmer(unittest.TestCase): + fcc_print("import TestSolverElmer") # ******************************************************************************************** def setUp( @@ -52,7 +52,7 @@ class TestSolverFrameWork(unittest.TestCase): self.mesh_name = "Mesh" self.temp_dir = testtools.get_unit_test_tmp_dir( testtools.get_fem_test_tmp_dir(), - "FEM_solverframework" + "FEM_solver_elmer" ) # make sure std FreeCAD unit system mm/kg/s is used @@ -88,48 +88,6 @@ class TestSolverFrameWork(unittest.TestCase): 55 * "*" )) - # ******************************************************************************************** - def test_solver_calculix( - self - ): - fcc_print("\n--------------- Start of FEM tests solver framework solver CalculiX ------") - - # set up the CalculiX static analysis example - from femexamples.boxanalysis_static import setup - setup(self.document, "calculix") - - solver_obj = self.document.SolverCalculiX - - base_name = "cube_static" - analysis_dir = testtools.get_unit_test_tmp_dir(self.temp_dir, solver_obj.Name) - - # save the file - save_fc_file = join(analysis_dir, solver_obj.Name + "_" + base_name + ".FCStd") - fcc_print("Save FreeCAD file to {}...".format(save_fc_file)) - self.document.saveAs(save_fc_file) - - # write input file - fcc_print("Checking FEM input file writing for CalculiX solver framework solver ...") - machine_ccx = solver_obj.Proxy.createMachine( - solver_obj, - analysis_dir - ) - machine_ccx.target = femsolver.run.PREPARE - machine_ccx.start() - machine_ccx.join() # wait for the machine to finish. - - infile_given = join( - testtools.get_fem_test_home_dir(), - "ccx", - (base_name + ".inp") - ) - inpfile_totest = join(analysis_dir, (self.mesh_name + ".inp")) - fcc_print("Comparing {} to {}".format(infile_given, inpfile_totest)) - ret = testtools.compare_inp_files(infile_given, inpfile_totest) - self.assertFalse(ret, "ccxtools write_inp_file test failed.\n{}".format(ret)) - - fcc_print("--------------- End of FEM tests solver framework solver CalculiX --------") - # ******************************************************************************************** def test_solver_elmer( self diff --git a/src/Mod/Fem/femtest/test_commands.sh b/src/Mod/Fem/femtest/test_commands.sh index 02a23ad44d..12443420bd 100644 --- a/src/Mod/Fem/femtest/test_commands.sh +++ b/src/Mod/Fem/femtest/test_commands.sh @@ -15,7 +15,8 @@ make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_mesh make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_object make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_open make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_result -make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_solverframework +make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_solver_calculix +make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_solver_elmer # classes @@ -31,7 +32,8 @@ make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_object.TestObjectCreate make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_object.TestObjectType make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_open.TestObjectOpen make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_result.TestResult -make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_solverframework.TestSolverFrameWork +make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_solver_calculix.TestSolverCalculix +make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_solver_elmer.TestSolverElmer # methods @@ -79,8 +81,8 @@ make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_result.TestResult.test_stress_ make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_result.TestResult.test_stress_principal_reinforced make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_result.TestResult.test_rho make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_result.TestResult.test_disp_abs -make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_solverframework.TestSolverFrameWork.test_solver_calculix -make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_solverframework.TestSolverFrameWork.test_solver_elmer +make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_solver_calculix.TestSolverCalculix.test_solver_calculix +make -j 4 && ./bin/FreeCADCmd -t femtest.app.test_solver_elmer.TestSolverElmer.test_solver_elmer # methods in FreeCAD @@ -307,10 +309,10 @@ unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName( import unittest unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName( - 'femtest.app.test_solverframework.TestSolverFrameWork.test_solver_calculix' + 'femtest.app.test_solver_calculix.TestSolverCalculix.test_solver_calculix' )) import unittest unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName( - 'femtest.app.test_solverframework.TestSolverFrameWork.test_solver_elmer' + 'femtest.app.test_solver_elmer.TestSolverElmer.test_solver_elmer' ))