Skip to content

Commit

Permalink
FEM: calculix solver unit tests, add generic inp file writing method …
Browse files Browse the repository at this point in the history
…and make use of it
  • Loading branch information
berndhahnebach committed Jul 3, 2020
1 parent 5d51198 commit 7103688
Showing 1 changed file with 47 additions and 26 deletions.
73 changes: 47 additions & 26 deletions src/Mod/Fem/femtest/app/test_solver_calculix.py
Expand Up @@ -49,10 +49,6 @@ def setUp(

# 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(
Expand All @@ -78,40 +74,65 @@ def test_00print(
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")
self.calculix_inputfile_writing_test("cube_static")

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

solver_obj = self.document.SolverCalculiX
self.document.recompute()

base_name = "cube_static"
analysis_dir = testtools.get_unit_test_tmp_dir(self.temp_dir, solver_obj.Name)
# start
fcc_print(
"\n------------- Start of FEM CalculiX tests for {} -------"
.format(base_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))
# get analysis working directory and save FreeCAD file
working_dir = testtools.get_fem_test_tmp_dir("solver_calculix_" + 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
fcc_print("Checking FEM input file writing for CalculiX solver framework solver ...")
machine_ccx = solver_obj.Proxy.createMachine(
solver_obj,
analysis_dir
machine = self.document.SolverCalculiX.Proxy.createMachine(
self.document.SolverCalculiX,
working_dir,
True # set testmode to True
)
machine_ccx.target = femsolver.run.PREPARE
machine_ccx.start()
machine_ccx.join() # wait for the machine to finish.
machine.target = femsolver.run.PREPARE
machine.start()
machine.join() # wait for the machine to finish

infile_given = join(
# compare input file with the given one
inpfile_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))
inpfile_totest = join(
working_dir,
self.mesh_name + ".inp"
)
fcc_print(
"Comparing {} to {}"
.format(inpfile_given, inpfile_totest)
)
ret = testtools.compare_inp_files(
inpfile_given,
inpfile_totest
)
self.assertFalse(
ret,
"CalculiX write_inp_file for {0} test failed.\n{1}".format(base_name, ret)
)

fcc_print("--------------- End of FEM tests solver framework solver CalculiX --------")
# end
fcc_print(
"--------------- End of FEM CalculiX tests for {} ---------"
.format(base_name)
)

0 comments on commit 7103688

Please sign in to comment.