FEM: ccx tools, do not run all init methods on fea init

This commit is contained in:
Bernd Hahnebach
2019-02-24 22:18:24 +01:00
committed by wmayer
parent 48b738ed23
commit 46bd1501bd
2 changed files with 38 additions and 25 deletions

View File

@@ -121,6 +121,7 @@ class TestCcxTools(unittest.TestCase):
static_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('Setting up working directory {}'.format(static_analysis_dir))
fea.setup_working_dir(static_analysis_dir)
@@ -257,6 +258,7 @@ class TestCcxTools(unittest.TestCase):
self.active_doc.recompute()
static_multiplemat_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...')
@@ -326,6 +328,7 @@ class TestCcxTools(unittest.TestCase):
frequency_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)
@@ -455,6 +458,7 @@ class TestCcxTools(unittest.TestCase):
thermomech_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)
@@ -704,6 +708,7 @@ class TestCcxTools(unittest.TestCase):
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)
@@ -786,6 +791,7 @@ def create_test_results():
FreeCAD.open(static_analysis_dir + 'cube_static.FCStd')
FemGui.setActiveAnalysis(FreeCAD.ActiveDocument.Analysis)
fea = ccxtools.FemToolsCcx()
fea.update_objects()
print("create static result files")
fea.reset_all()
@@ -811,6 +817,7 @@ def create_test_results():
FreeCAD.open(frequency_analysis_dir + 'cube_frequency.FCStd')
FemGui.setActiveAnalysis(FreeCAD.ActiveDocument.Analysis)
fea = ccxtools.FemToolsCcx()
fea.update_objects()
print("create frequency result files")
fea.reset_all()

View File

@@ -64,18 +64,19 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
# solver of the analysis. Used to store the active solver and analysis parameters
self.solver = solver
else:
self.solver = None
if self.analysis:
self.update_objects()
self.find_solver()
if not self.solver:
raise Exception('FEM: No solver found!')
if self.analysis and self.solver:
self.working_dir = ''
self.ccx_binary = ''
## @var base_name
# base name of .inp/.frd file (without extension). It is used to construct .inp file path that is passed to CalculiX ccx
self.base_name = ""
## @var results_present
# boolean variable indicating if there are calculation results ready for use
self.results_present = False
if self.solver:
self.setup_working_dir()
else:
if not self.solver:
raise Exception('FEM: No solver found!')
if test_mode:
self.test_mode = True
@@ -83,7 +84,6 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
else:
self.test_mode = False
self.ccx_binary_present = False
self.setup_ccx()
self.result_object = None
else:
raise Exception('FEM: No active analysis found!')
@@ -114,6 +114,26 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
def _get_several_member(self, obj_type):
return femutils.get_several_member(self.analysis, obj_type)
def find_solver(self):
found_solver_for_use = False
for m in self.analysis.Group:
if femutils.is_of_type(m, "Fem::FemSolverCalculixCcxTools"):
# we are going to explicitly check for the ccx tools solver type only,
# thus it is possible to have lots of framework solvers inside the analysis anyway
# for some methods no solver is needed (purge_results) --> solver could be none
# analysis has one solver and no solver was set --> use the one solver
# analysis has more than one solver and no solver was set --> use solver none
# analysis has no solver --> use solver none
if not found_solver_for_use:
# no solver was found before
self.solver = m
found_solver_for_use = True
else:
self.solver = None
# another solver was found --> We have more than one solver
# we do not know which one to use, so we use none !
# FreeCAD.Console.PrintMessage('FEM: More than one solver in the analysis and no solver given to analyze. No solver is set!\n')
def update_objects(self):
# [{'Object':materials_linear}, {}, ...]
# [{'Object':materials_nonlinear}, {}, ...]
@@ -184,25 +204,8 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
# list of transform constraints from the analysis. Updated with update_objects
self.transform_constraints = self._get_several_member('Fem::ConstraintTransform')
found_solver_for_use = False
for m in self.analysis.Group:
if femutils.is_of_type(m, "Fem::FemSolverCalculixCcxTools"):
# we are going to explicitly check for the ccx tools solver type only,
# thus it is possible to have lots of framework solvers inside the analysis anyway
# for some methods no solver is needed (purge_results) --> solver could be none
# analysis has one solver and no solver was set --> use the one solver
# analysis has more than one solver and no solver was set --> use solver none
# analysis has no solver --> use solver none
if not found_solver_for_use and not self.solver:
# no solver was found before and no solver was set by constructor
self.solver = m
found_solver_for_use = True
elif found_solver_for_use:
self.solver = None
# another solver was found --> We have more than one solver
# we do not know which one to use, so we use none !
# FreeCAD.Console.PrintMessage('FEM: More than one solver in the analysis and no solver given to analyze. No solver is set!\n')
elif m.isDerivedFrom("Fem::FemMeshObject"):
if m.isDerivedFrom("Fem::FemMeshObject"):
if not self.mesh:
self.mesh = m
else:
@@ -673,6 +676,9 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
return ret_code
def run(self):
self.update_objects()
self.setup_working_dir()
self.setup_ccx()
message = self.check_prerequisites()
if message:
error_message = "CalculiX was not started due to missing prerequisites:\n{}\n".format(message)