Skip to content

Commit

Permalink
FEM: unit tests, add z88 writing test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudhanshu-Dubey14 committed Jul 7, 2020
1 parent cab4077 commit 5b104e1
Show file tree
Hide file tree
Showing 14 changed files with 965 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Mod/Fem/CMakeLists.txt
Expand Up @@ -222,6 +222,7 @@ SET(FemTestsApp_SRCS
femtest/app/test_result.py
femtest/app/test_solver_calculix.py
femtest/app/test_solver_elmer.py
femtest/app/test_solver_z88.py
)

SET(FemTestsFiles_SRCS
Expand Down Expand Up @@ -296,6 +297,19 @@ SET(FemTestsOpen_SRCS
femtest/data/open/all_objects_de9b3fb438.FCStd
)

SET(FemTestsZ88_SRCS
femtest/data/z88/__init__.py
femtest/data/z88/cube_static/51.txt
femtest/data/z88/cube_static/z88.dyn
femtest/data/z88/cube_static/z88elp.txt
femtest/data/z88/cube_static/z88i1.txt
femtest/data/z88/cube_static/z88i2.txt
femtest/data/z88/cube_static/z88i5.txt
femtest/data/z88/cube_static/z88int.txt
femtest/data/z88/cube_static/z88man.txt
femtest/data/z88/cube_static/z88mat.txt
)

SET(FemTools_SRCS
femtools/__init__.py
femtools/ccxtools.py
Expand Down Expand Up @@ -331,6 +345,7 @@ SET(FemAllScripts
${FemTestsElmer_SRCS}
${FemTestsMesh_SRCS}
${FemTestsOpen_SRCS}
${FemTestsZ88_SRCS}
${FemTools_SRCS}
)

Expand Down Expand Up @@ -363,6 +378,7 @@ INSTALL(FILES ${FemTestsCcx_SRCS} DESTINATION Mod/Fem/femtest/data/calculix)
INSTALL(FILES ${FemTestsElmer_SRCS} DESTINATION Mod/Fem/femtest/data/elmer)
INSTALL(FILES ${FemTestsMesh_SRCS} DESTINATION Mod/Fem/femtest/data/mesh)
INSTALL(FILES ${FemTestsOpen_SRCS} DESTINATION Mod/Fem/femtest/data/open)
INSTALL(FILES ${FemTestsZ88_SRCS} DESTINATION Mod/Fem/femtest/data/z88)
INSTALL(FILES ${FemTools_SRCS} DESTINATION Mod/Fem/femtools)


Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Fem/TestFemApp.py
Expand Up @@ -37,6 +37,7 @@
from femtest.app.test_ccxtools import TestCcxTools as FemTest11
from femtest.app.test_solver_calculix import TestSolverCalculix as FemTest12
from femtest.app.test_solver_elmer import TestSolverElmer as FemTest13
from femtest.app.test_solver_z88 import TestSolverZ88 as FemTest14

# dummy usage to get flake8 and lgtm quiet
False if FemTest01.__name__ else True
Expand All @@ -52,3 +53,4 @@
False if FemTest11.__name__ else True
False if FemTest12.__name__ else True
False if FemTest13.__name__ else True
False if FemTest14.__name__ else True
142 changes: 142 additions & 0 deletions src/Mod/Fem/femtest/app/test_solver_z88.py
@@ -0,0 +1,142 @@
# ***************************************************************************
# * Copyright (c) 2018 Bernd Hahnebach <bernd@bimstatik.org> *
# * Copyright (c) 2020 Sudhanshu Dubey <sudhanshu.thethunder@gmail.com> *
# * *
# * 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 z88 FEM unit tests"
__author__ = "Bernd Hahnebach"
__url__ = "http://www.freecadweb.org"

import unittest
from os import listdir
from os.path import join

import FreeCAD

import femsolver.run
from . import support_utils as testtools
from .support_utils import fcc_print


class TestSolverZ88(unittest.TestCase):
fcc_print("import TestSolverZ88")

# ********************************************************************************************
def setUp(
self
):
# setUp is executed before every test

# new document
self.document = FreeCAD.newDocument(self.__class__.__name__)

# more inits
self.mesh_name = "Mesh"

# ********************************************************************************************
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_z88(
self
):
from femexamples.boxanalysis_static import setup
setup(self.document, "z88")
self.z88_inputfile_writing_test("cube_static")

# ********************************************************************************************
def z88_inputfile_writing_test(
self,
base_name
):

self.document.recompute()

# start
fcc_print(
"\n------------- Start of FEM Z88 tests for {} -------"
.format(base_name)
)

# get analysis working directory and save FreeCAD file
working_dir = testtools.get_fem_test_tmp_dir("solver_z88_" + base_name)
save_fc_file = join(working_dir, base_name + ".FCStd")
fcc_print("Save FreeCAD file to {} ...".format(save_fc_file))
self.document.saveAs(save_fc_file)

# write input file
machine = self.document.SolverZ88.Proxy.createMachine(
self.document.SolverZ88,
working_dir,
True # set testmode to True
)
machine.target = femsolver.run.PREPARE
machine.start()
machine.join() # wait for the machine to finish

# compare input file with the given one
test_path = join(testtools.get_fem_test_home_dir(), "z88", base_name)
test_files = [f for f in listdir(test_path)]
for test_file in test_files:
inpfile_given = join(
test_path,
test_file
)
inpfile_totest = join(
working_dir,
test_file
)
fcc_print(
"Comparing {} to {}"
.format(inpfile_given, inpfile_totest)
)
ret = testtools.compare_inp_files(
inpfile_given,
inpfile_totest
)
self.assertFalse(
ret,
"Z88 write_inp_file for {0} test failed.\n{1}".format(base_name, ret)
)

# end
fcc_print(
"--------------- End of FEM Z88 tests for {} ---------"
.format(base_name)
)
Empty file.
1 change: 1 addition & 0 deletions src/Mod/Fem/femtest/data/z88/cube_static/51.txt
@@ -0,0 +1 @@
200000.0 0.300
49 changes: 49 additions & 0 deletions src/Mod/Fem/femtest/data/z88/cube_static/z88.dyn
@@ -0,0 +1,49 @@
DYNAMIC START
---------------------------------------------------------------------------
Z88 new version 14OS Z88 neue Version 14OS
---------------------------------------------------------------------------

---------------------------------------------------------------------------
LANGUAGE SPRACHE
---------------------------------------------------------------------------
GERMAN

---------------------------------------------------------------------------
Entries for mesh generator Z88N Daten fuer Netzgenerator
---------------------------------------------------------------------------
NET START
MAXSE 40000
MAXESS 800
MAXKSS 4000
MAXAN 15
NET END

---------------------------------------------------------------------------
Common entries for all modules gemeinsame Daten fuer alle Module
---------------------------------------------------------------------------

COMMON START
MAXGS 50000000
MAXKOI 1200000
MAXK 60000
MAXE 300000
MAXNFG 200000
MAXMAT 32
MAXPEL 32
MAXJNT 32
MAXPR 10000
MAXRBD 15000
MAXIEZ 6000000
MAXGP 2000000
COMMON END

---------------------------------------------------------------------------
Entries for Cuthill-McKee Z88H Daten fuer Cuthill- McKee Programm
---------------------------------------------------------------------------
CUTKEE START
MAXGRA 200
MAXNDL 1000
CUTKEE END


DYNAMIC END
2 changes: 2 additions & 0 deletions src/Mod/Fem/femtest/data/z88/cube_static/z88elp.txt
@@ -0,0 +1,2 @@
1
1 129 0 0 0 0 0 0 0

0 comments on commit 5b104e1

Please sign in to comment.