FEM: ccx tools, remove setting analysis type with the analysis tools, is done in solver object

This commit is contained in:
Bernd Hahnebach
2018-02-07 13:32:16 +01:00
committed by wmayer
parent b99cc55a6b
commit d0b5798ae4
8 changed files with 21 additions and 48 deletions

View File

@@ -259,7 +259,6 @@ class _TaskPanelFemSolverCalculix:
QApplication.setOverrideCursor(Qt.WaitCursor)
self.inp_file_name = ""
fea = ccxtools.FemToolsCcx(None, self.solver_object)
fea.set_analysis_type(self.solver_object.AnalysisType)
fea.update_objects()
fea.write_inp_file()
if fea.inp_file_name != "":

View File

@@ -67,7 +67,7 @@ class Prepare(run.Prepare):
c.pressure_constraints, c.temperature_constraints,
c.heatflux_constraints, c.initialtemperature_constraints,
c.beam_sections, c.beam_rotations, c.shell_thicknesses, c.fluid_sections,
self.solver.AnalysisType, self.directory)
self.directory)
path = w.write_calculix_input_file()
# report to user if task succeeded
if path is not None:

View File

@@ -46,7 +46,7 @@ class FemInputWriterCcx(FemInputWriter.FemInputWriter):
selfweight_obj, force_obj, pressure_obj,
temperature_obj, heatflux_obj, initialtemperature_obj,
beamsection_obj, beamrotation_obj, shellthickness_obj, fluidsection_obj,
analysis_type=None, dir_name=None
dir_name=None
):
FemInputWriter.FemInputWriter.__init__(
@@ -58,7 +58,7 @@ class FemInputWriterCcx(FemInputWriter.FemInputWriter):
selfweight_obj, force_obj, pressure_obj,
temperature_obj, heatflux_obj, initialtemperature_obj,
beamsection_obj, beamrotation_obj, shellthickness_obj, fluidsection_obj,
analysis_type, dir_name)
dir_name)
# self.dir_name does have a slash at the end
self.main_file_name = self.mesh_object.Name + '.inp'
self.file_name = self.dir_name + self.main_file_name

View File

@@ -41,10 +41,11 @@ class FemInputWriter():
selfweight_obj, force_obj, pressure_obj,
temperature_obj, heatflux_obj, initialtemperature_obj,
beamsection_obj, beamrotation_obj, shellthickness_obj, fluidsection_obj,
analysis_type, dir_name
dir_name
):
self.analysis = analysis_obj
self.solver_obj = solver_obj
self.analysis_type = self.solver_obj.AnalysisType
self.mesh_object = mesh_obj
self.material_objects = matlin_obj
self.material_nonlinear_objects = matnonlin_obj
@@ -63,7 +64,6 @@ class FemInputWriter():
self.beamrotation_objects = beamrotation_obj
self.fluidsection_objects = fluidsection_obj
self.shellthickness_objects = shellthickness_obj
self.analysis_type = analysis_type
self.dir_name = dir_name
if not dir_name:
print('Error: FemInputWriter has no working_dir --> we are going to make a temporary one!')

View File

@@ -65,7 +65,7 @@ class Prepare(run.Prepare):
c.pressure_constraints, c.temperature_constraints,
c.heatflux_constraints, c.initialtemperature_constraints,
c.beam_sections, c.beam_rotations, c.shell_thicknesses, c.fluid_sections,
self.solver.AnalysisType, self.directory)
self.directory)
path = w.write_z88_input()
# report to user if task succeeded
if path is not None:

View File

@@ -43,7 +43,7 @@ class FemInputWriterZ88(FemInputWriter.FemInputWriter):
selfweight_obj, force_obj, pressure_obj,
temperature_obj, heatflux_obj, initialtemperature_obj,
beamsection_obj, beamrotation_obj, shellthickness_obj, fluidsection_obj,
analysis_type=None, dir_name=None
dir_name=None
):
FemInputWriter.FemInputWriter.__init__(
@@ -55,7 +55,7 @@ class FemInputWriterZ88(FemInputWriter.FemInputWriter):
selfweight_obj, force_obj, pressure_obj,
temperature_obj, heatflux_obj, initialtemperature_obj,
beamsection_obj, beamrotation_obj, shellthickness_obj, fluidsection_obj,
analysis_type, dir_name)
dir_name)
# self.dir_name does have a slash at the end
self.file_name = self.dir_name + 'z88'
print('FemInputWriterZ88 --> self.dir_name --> ' + self.dir_name)

View File

@@ -681,6 +681,7 @@ class FemCcxAnalysisTest(unittest.TestCase):
fcc_print('Checking FEM new solver...')
solver_object = ObjectsFem.makeSolverCalculixCcxTools(self.active_doc, 'CalculiX')
solver_object.AnalysisType = 'static'
solver_object.GeometricalNonlinearity = 'linear'
solver_object.ThermoMechSteadyState = False
solver_object.MatrixSolverType = 'default'
@@ -753,11 +754,6 @@ class FemCcxAnalysisTest(unittest.TestCase):
self.assertFalse(error, "ccxtools check_prerequisites returned error message: {}".format(error))
fcc_print('Checking FEM inp file write...')
fcc_print('Setting analysis type to \'static\"')
fea.set_analysis_type("static")
self.assertTrue(True if fea.analysis_type == 'static' else False, "Setting analysis type to \'static\' failed")
fcc_print('Writing {}/{}.inp for static analysis'.format(static_analysis_dir, mesh_name))
error = fea.write_inp_file()
self.assertFalse(error, "Writing failed")
@@ -796,8 +792,8 @@ class FemCcxAnalysisTest(unittest.TestCase):
fcc_print('Reset Statik analysis')
fea.reset_all()
fcc_print('Setting analysis type to \'frequency\"')
fea.set_analysis_type("frequency")
self.assertTrue(True if fea.analysis_type == 'frequency' else False, "Setting analysis type to \'frequency\' failed")
solver_object.AnalysisType = 'frequency'
fcc_print('Setting up working directory to {} in order to write frequency calculations'.format(frequency_analysis_dir))
fea.setup_working_dir(frequency_analysis_dir)
@@ -926,10 +922,6 @@ class FemCcxAnalysisTest(unittest.TestCase):
self.assertTrue(True if fea.working_dir == thermomech_analysis_dir else False,
"Setting working directory {} failed".format(thermomech_analysis_dir))
fcc_print('Setting analysis type to \'thermomech\"')
fea.set_analysis_type("thermomech")
self.assertTrue(True if fea.analysis_type == 'thermomech' else False, "Setting analysis type to \'thermomech\' failed")
fcc_print('Checking FEM inp file prerequisites for thermo-mechanical analysis...')
error = fea.check_prerequisites()
self.assertFalse(error, "ccxtools check_prerequisites returned error message: {}".format(error))
@@ -1174,10 +1166,6 @@ class FemCcxAnalysisTest(unittest.TestCase):
self.assertTrue(True if fea.working_dir == Flow1D_thermomech_analysis_dir else False,
"Setting working directory {} failed".format(Flow1D_thermomech_analysis_dir))
fcc_print('Setting analysis type to \'thermomech\"')
fea.set_analysis_type("thermomech")
self.assertTrue(True if fea.analysis_type == 'thermomech' else False, "Setting analysis type to \'thermomech\' failed")
fcc_print('Checking FEM inp file prerequisites for thermo-mechanical analysis...')
error = fea.check_prerequisites()
self.assertFalse(error, "ccxtools check_prerequisites returned error message: {}".format(error))
@@ -1536,7 +1524,7 @@ def create_test_results():
print("create frequency result files")
fea.reset_all()
fea.set_analysis_type('frequency')
FreeCAD.ActiveDocument.CalculiX.AnalysisType = 'frequency'
fea.solver.EigenmodesCount = 1 # we should only have one result object
fea.run()
fea.load_results()

View File

@@ -71,7 +71,6 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
# boolean variable indicating if there are calculation results ready for use
self.results_present = False
if self.solver:
self.set_analysis_type()
self.setup_working_dir()
else:
raise Exception('FEM: No solver found!')
@@ -274,8 +273,6 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
# analysis
if not self.analysis:
message += "No active Analysis\n"
if self.analysis_type not in self.known_analysis_types:
message += "Unknown analysis type: {}\n".format(self.analysis_type)
if not self.working_dir:
message += "Working directory not set\n"
import os
@@ -285,7 +282,9 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
if not self.solver:
message += "No solver object defined in the analysis\n"
else:
if self.analysis_type == "frequency":
if self.solver.AnalysisType not in self.known_analysis_types:
message += "Unknown analysis type: {}\n".format(self.solver.AnalysisType)
if self.solver.AnalysisType == "frequency":
if not hasattr(self.solver, "EigenmodeHighLimit"):
message += "Frequency analysis: Solver has no EigenmodeHighLimit.\n"
elif not hasattr(self.solver, "EigenmodeLowLimit"):
@@ -336,10 +335,10 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
message += "No YoungsModulus defined for at least one material.\n"
if 'PoissonRatio' not in mat_map:
message += "No PoissonRatio defined for at least one material.\n" # PoissonRatio is allowed to be 0.0 (in ccx), but it should be set anyway.
if self.analysis_type == "frequency" or self.selfweight_constraints:
if self.solver.AnalysisType == "frequency" or self.selfweight_constraints:
if 'Density' not in mat_map:
message += "No Density defined for at least one material.\n"
if self.analysis_type == "thermomech":
if self.solver.AnalysisType == "thermomech":
if 'ThermalConductivity' in mat_map:
if not Units.Quantity(mat_map['ThermalConductivity']).Value:
message += "Value of ThermalConductivity is set to 0.0.\n"
@@ -359,10 +358,10 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
message += "At least two nonlinear materials use the same linear base material. Only one nonlinear material for each linear material allowed.\n"
# which analysis needs which constraints
# no check in the regard of loads existence (constraint force, pressure, self weight) is done because an analysis without loads at all is an valid analysis too
if self.analysis_type == "static":
if self.solver.AnalysisType == "static":
if not (self.fixed_constraints or self.displacement_constraints):
message += "Static analysis: Neither constraint fixed nor constraint displacement defined.\n"
if self.analysis_type == "thermomech":
if self.solver.AnalysisType == "thermomech":
if not self.initialtemperature_constraints:
if not self.fluid_sections:
message += "Thermomechanical analysis: No initial temperature defined.\n"
@@ -455,7 +454,7 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
if self.fluid_sections:
if not self.selfweight_constraints:
message += "A fluid network analysis requires self weight constraint to be applied"
if self.analysis_type != "thermomech":
if self.solver.AnalysisType != "thermomech":
message += "A fluid network analysis can only be done in a thermomech analysis"
has_no_references = False
for f in self.fluid_sections:
@@ -493,19 +492,6 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
# self.working_dir does have a slash at the end
self.inp_file_name = self.working_dir + self.base_name + '.inp'
## Sets analysis type.
# @param self The python object self
# @param analysis_type type of the analysis.
def set_analysis_type(self, analysis_type=None):
if analysis_type is not None:
self.analysis_type = analysis_type
else:
try:
self.analysis_type = self.solver.AnalysisType
except:
self.fem_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/General")
self.analysis_type = self.fem_prefs.GetString("AnalysisType", "static")
## Sets working dir for solver execution. Called with no working_dir uses WorkingDir from FEM preferences
# @param self The python object self
# @working_dir directory to be used for writing solver input file or files and executing solver
@@ -557,7 +543,7 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
self.selfweight_constraints, self.force_constraints, self.pressure_constraints,
self.temperature_constraints, self.heatflux_constraints, self.initialtemperature_constraints,
self.beam_sections, self.beam_rotations, self.shell_thicknesses, self.fluid_sections,
self.analysis_type, self.working_dir)
self.working_dir)
self.inp_file_name = inp_writer.write_calculix_input_file()
except:
print("Unexpected error when writing CalculiX input file:", sys.exc_info()[0])