Skip to content

Commit

Permalink
FEM: oofem unit tests, input file writing:
Browse files Browse the repository at this point in the history
- PlaneStress2D
- cantilever ccx node load
- cantilever ccx prescribed displacement
  • Loading branch information
berndhahnebach committed Apr 27, 2020
1 parent f233860 commit 794f4a7
Show file tree
Hide file tree
Showing 7 changed files with 1,119 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Mod/Fem/CMakeLists.txt
Expand Up @@ -172,6 +172,7 @@ SET(FemTestsApp_SRCS
femtest/app/test_object.py
femtest/app/test_result.py
femtest/app/test_solverframework.py
femtest/app/test_solveroofem.py
)

SET(FemTestsFiles_SRCS
Expand Down Expand Up @@ -229,6 +230,13 @@ SET(FemTestsMesh_SRCS
femtest/data/mesh/tetra10_mesh.z88
)

SET(FemTestsOofem_SRCS
femtest/data/oofem/__init__.py
femtest/data/oofem/OOFEM_CantileverCcxNodeLoad.in
femtest/data/oofem/OOFEM_CantileverCcxPrescribedDisplacement.in
femtest/data/oofem/OOFEM_PlaneStress2D.in
)

SET(FemTools_SRCS
femtools/__init__.py
femtools/ccxtools.py
Expand Down Expand Up @@ -287,6 +295,7 @@ SET(FemAllScripts
${FemTestsCcx_SRCS}
${FemTestsElmer_SRCS}
${FemTestsMesh_SRCS}
${FemTestsOofem_SRCS}
${FemTools_SRCS}
${FemObjectsScripts_SRCS}
)
Expand Down Expand Up @@ -320,6 +329,7 @@ INSTALL(FILES ${FemTestsFiles_SRCS} DESTINATION Mod/Fem/femtest/data)
INSTALL(FILES ${FemTestsCcx_SRCS} DESTINATION Mod/Fem/femtest/data/ccx)
INSTALL(FILES ${FemTestsElmer_SRCS} DESTINATION Mod/Fem/femtest/data/elmer)
INSTALL(FILES ${FemTestsMesh_SRCS} DESTINATION Mod/Fem/femtest/data/mesh)
INSTALL(FILES ${FemTestsOofem_SRCS} DESTINATION Mod/Fem/femtest/data/oofem)
INSTALL(FILES ${FemTools_SRCS} DESTINATION Mod/Fem/femtools)
INSTALL(FILES ${FemObjectsScripts_SRCS} DESTINATION Mod/Fem/femobjects)

Expand Down
4 changes: 4 additions & 0 deletions src/Mod/Fem/TestFem.py
Expand Up @@ -35,6 +35,7 @@
from femtest.app.test_result import TestResult as FemTest08
from femtest.app.test_ccxtools import TestCcxTools as FemTest09
from femtest.app.test_solverframework import TestSolverFrameWork as FemTest10
from femtest.app.test_solveroofem import TestOofem as FemTest11

# dummy usage to get flake8 and lgtm quiet
False if FemTest01.__name__ else True
Expand All @@ -47,6 +48,7 @@
False if FemTest08.__name__ else True
False if FemTest09.__name__ else True
False if FemTest10.__name__ else True
False if FemTest11.__name__ else True


# For more information on how to run a specific test class or a test method see
Expand Down Expand Up @@ -105,6 +107,7 @@
./bin/FreeCAD --run-test "femtest.app.test_object"
./bin/FreeCAD --run-test "femtest.app.test_result"
./bin/FreeCAD --run-test "femtest.app.test_solverframework"
./bin/FreeCAD --run-test "femtest.app.test_solveroofem"
./bin/FreeCADCmd --run-test "femtest.app.test_femimport"
./bin/FreeCADCmd --run-test "femtest.app.test_ccxtools"
./bin/FreeCADCmd --run-test "femtest.app.test_common"
Expand All @@ -113,6 +116,7 @@
./bin/FreeCADCmd --run-test "femtest.app.test_object"
./bin/FreeCADCmd --run-test "femtest.app.test_result"
./bin/FreeCADCmd --run-test "femtest.app.test_solverframework"
./bin/FreeCADCmd --run-test "femtest.app.test_solveroofem"
# class
./bin/FreeCAD --run-test "femtest.app.test_common.TestFemCommon"
Expand Down
171 changes: 171 additions & 0 deletions src/Mod/Fem/femtest/app/test_solveroofem.py
@@ -0,0 +1,171 @@
# ***************************************************************************
# * Copyright (c) 2019 Bernd Hahnebach <bernd@bimstatik.org> *
# * *
# * 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. *
# * *
# * FreeCAD 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 FreeCAD; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************

__title__ = "Solver OOFEM unit tests"
__author__ = "Bernd Hahnebach"
__url__ = "http://www.freecadweb.org"

import unittest
from os.path import join

import FreeCAD

from . import support_utils as testtools
from .support_utils import fcc_print


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

# ********************************************************************************************
def setUp(
self
):
# setUp is executed before every test
# setting up a document to hold the tests
self.doc_name = self.__class__.__name__
if FreeCAD.ActiveDocument:
if FreeCAD.ActiveDocument.Name != self.doc_name:
FreeCAD.newDocument(self.doc_name)
else:
FreeCAD.newDocument(self.doc_name)
FreeCAD.setActiveDocument(self.doc_name)
self.active_doc = FreeCAD.ActiveDocument

# more inits
self.mesh_name = "Mesh"
self.temp_dir = testtools.get_fem_test_tmp_dir()
self.test_file_dir = join(
testtools.get_fem_test_home_dir(),
"oofem"
)

# ********************************************************************************************
def test_planestress2d(
self
):
# test oofem input file writing for oofem manual example PlaneStress2D.in
from femexamples.oofem_planestress2d import setup
setup(self.active_doc, "oofem")
self.write_inputfile("OOFEM_PlaneStress2D")

# ********************************************************************************************
def test_cantileverccxnodeload(
self
):
# test oofem input file writing for CalculiX cantilever loaded by 9 MN as node loads
from femexamples.ccx_cantilever_std import setup_cantilevernodeload as cantinoadload
cantinoadload(self.active_doc, "oofem")
self.write_inputfile("OOFEM_CantileverCcxNodeLoad")

# ********************************************************************************************
def test_canticcxprescribeddisp(
self
):
# test oofem input file writing for CalculiX cantilever loaded by 9 MN as node loads
from femexamples.ccx_cantilever_std import \
setup_cantileverprescribeddisplacement as cantipredisp
cantipredisp(self.active_doc, "oofem")
self.write_inputfile("OOFEM_CantileverCcxPrescribedDisplacement")

# ********************************************************************************************
def write_inputfile(
self,
static_base_name
):

# recompute
self.active_doc.recompute()

# fcc_print(self.active_doc.Objects)
# fcc_print([obj.Name for obj in self.active_doc.Objects])

# save file, needs before input file writing because of besides dir
solverframework_analysis_dir = testtools.get_unit_test_tmp_dir(
testtools.get_fem_test_tmp_dir(),
"FEM_oofem"
)
save_fc_file = join(solverframework_analysis_dir, static_base_name) + ".FCStd"
fcc_print(
"Save FreeCAD file for {} analysis to {}"
.format(static_base_name, save_fc_file)
)
self.active_doc.saveAs(save_fc_file)

# solver
solver = self.active_doc.SolverOOFEM

# get analysis workig dir
from femtools.femutils import get_beside_dir
working_dir = get_beside_dir(solver)

fcc_print("Checking FEM OOFEM solver ...")
fcc_print("machine_oofem")

# write input file
from femsolver.run import PREPARE
# set up the machine with testmode True
machine_oofem = solver.Proxy.createMachine(solver, working_dir, True)
machine_oofem.target = PREPARE
machine_oofem.start()
machine_oofem.join() # wait for the machine to finish.

# compare input files
inpfile_given = join(
testtools.get_fem_test_home_dir(),
"oofem",
(static_base_name + ".in")
)
inpfile_totest = join(
working_dir,
(self.mesh_name + ".in")
)
fcc_print(
"Comparing {} to {}"
.format(inpfile_given, inpfile_totest)
)
ret = testtools.compare_inp_files(
inpfile_given,
inpfile_totest
)
self.assertFalse(
ret,
"OOFEM write_inp_file for {0} test failed.\n{1}".format(static_base_name, ret)
)

# ********************************************************************************************
def tearDown(
self
):
FreeCAD.closeDocument(self.doc_name)
fcc_print("Document closed")
pass


"""
make -j4 && ./bin/FreeCAD --run-test "femtest.app.test_solveroofem.TestOofem"
make -j4 && ./bin/FreeCAD --run-test "femtest.app.test_solveroofem.TestOofem.test_planestress2d"
make -j4 && ./bin/FreeCAD --run-test "femtest.app.test_solveroofem.TestOofem.test_cantileverccxnodeload"
make -j4 && ./bin/FreeCAD --run-test "femtest.app.test_solveroofem.TestOofem.test_canticcxprescribeddisp"
"""

0 comments on commit 794f4a7

Please sign in to comment.