FEM: prints, use FreeCAD console prints and console error for ccx tools and writer module

This commit is contained in:
Bernd Hahnebach
2018-02-07 13:32:27 +01:00
committed by wmayer
parent 6417db4582
commit ecf7f45813
4 changed files with 59 additions and 56 deletions

View File

@@ -64,9 +64,9 @@ class FemInputWriterCcx(FemInputWriter.FemInputWriter):
self.file_name = self.dir_name + self.main_file_name
self.FluidInletoutlet_ele = []
self.fluid_inout_nodes_file = self.dir_name + self.mesh_object.Name + '_inout_nodes.txt'
print('FemInputWriterCcx --> self.dir_name --> ' + self.dir_name)
print('FemInputWriterCcx --> self.main_file_name --> ' + self.main_file_name)
print('FemInputWriterCcx --> self.file_name --> ' + self.file_name)
FreeCAD.Console.PrintMessage('FemInputWriterCcx --> self.dir_name --> ' + self.dir_name + '\n')
FreeCAD.Console.PrintMessage('FemInputWriterCcx --> self.main_file_name --> ' + self.main_file_name + '\n')
FreeCAD.Console.PrintMessage('FemInputWriterCcx --> self.file_name --> ' + self.file_name + '\n')
def write_calculix_input_file(self):
timestart = time.clock()
@@ -74,7 +74,7 @@ class FemInputWriterCcx(FemInputWriter.FemInputWriter):
self.write_calculix_splitted_input_file()
else:
self.write_calculix_one_input_file()
print("Writing time input file: " + str(time.clock() - timestart) + ' \n')
FreeCAD.Console.PrintMessage("Writing time input file: " + str(time.clock() - timestart) + ' \n\n')
return self.file_name
def write_calculix_one_input_file(self):
@@ -700,7 +700,7 @@ class FemInputWriterCcx(FemInputWriter.FemInputWriter):
if self.analysis_type == 'static' or self.analysis_type == 'thermomech':
step += ', NLGEOM' # https://www.comsol.com/blogs/what-is-geometric-nonlinearity/
elif self.analysis_type == 'frequency':
print('Analysis type frequency and geometrical nonlinear analyis are not allowed together, linear is used instead!')
FreeCAD.Console.PrintMessage('Analysis type frequency and geometrical nonlinear analyis are not allowed together, linear is used instead!\n')
if self.solver_obj.IterationsThermoMechMaximum:
if self.analysis_type == 'thermomech':
step += ', INC=' + str(self.solver_obj.IterationsThermoMechMaximum)
@@ -738,7 +738,7 @@ class FemInputWriterCcx(FemInputWriter.FemInputWriter):
elif self.analysis_type == 'thermomech':
analysis_type += ', DIRECT'
elif self.analysis_type == 'frequency':
print('Analysis type frequency and IterationsUserDefinedIncrementations are not allowed together, it is ignored')
FreeCAD.Console.PrintMessage('Analysis type frequency and IterationsUserDefinedIncrementations are not allowed together, it is ignored\n')
# analysis line --> steadystate --> thermomech only
if self.solver_obj.ThermoMechSteadyState:
if self.analysis_type == 'thermomech': # bernd: I do not know if STEADY STATE is allowed with DIRECT but since time steps are 1.0 it makes no sense IMHO
@@ -983,7 +983,7 @@ class FemInputWriterCcx(FemInputWriter.FemInputWriter):
lines = inout_nodes_file.readlines()
inout_nodes_file.close()
else:
print("1DFlow inout nodes file not found: " + self.fluid_inout_nodes_file)
FreeCAD.Console.PrintError("1DFlow inout nodes file not found: " + self.fluid_inout_nodes_file + '\n')
# get nodes
self.get_constraints_fluidsection_nodes()
for femobj in self.fluidsection_objects: # femobj --> dict, FreeCAD document object is femobj['Object']

View File

@@ -66,7 +66,7 @@ class FemInputWriter():
self.shellthickness_objects = shellthickness_obj
self.dir_name = dir_name
if not dir_name:
print('Error: FemInputWriter has no working_dir --> we are going to make a temporary one!')
FreeCAD.Console.PrintError('Error: FemInputWriter has no working_dir --> we are going to make a temporary one!\n')
self.dir_name = FreeCAD.ActiveDocument.TransientDir.replace('\\', '/') + '/FemAnl_' + analysis_obj.Uid[-4:]
self.dir_name = os.path.join(self.dir_name, '') # check dir_name has a slash at the end, if not add one
if not os.path.isdir(self.dir_name):
@@ -91,7 +91,7 @@ class FemInputWriter():
def get_constraints_fixed_nodes(self):
# get nodes
for femobj in self.fixed_objects: # femobj --> dict, FreeCAD document object is femobj['Object']
print("Constraint fixed: " + femobj['Object'].Name)
FreeCAD.Console.PrintMessage("Constraint fixed: " + femobj['Object'].Name + '\n')
femobj['Nodes'] = FemMeshTools.get_femnodes_by_femobj_with_references(self.femmesh, femobj)
# add nodes to constraint_conflict_nodes, needed by constraint plane rotation
for node in femobj['Nodes']:
@@ -100,7 +100,7 @@ class FemInputWriter():
def get_constraints_displacement_nodes(self):
# get nodes
for femobj in self.displacement_objects: # femobj --> dict, FreeCAD document object is femobj['Object']
print("Constraint displacement: " + femobj['Object'].Name)
FreeCAD.Console.PrintMessage("Constraint displacement: " + femobj['Object'].Name + '\n')
femobj['Nodes'] = FemMeshTools.get_femnodes_by_femobj_with_references(self.femmesh, femobj)
# add nodes to constraint_conflict_nodes, needed by constraint plane rotation
for node in femobj['Nodes']:
@@ -109,31 +109,31 @@ class FemInputWriter():
def get_constraints_planerotation_nodes(self):
# get nodes
for femobj in self.planerotation_objects: # femobj --> dict, FreeCAD document object is femobj['Object']
print("Constraint plane rotation: " + femobj['Object'].Name)
FreeCAD.Console.PrintMessage("Constraint plane rotation: " + femobj['Object'].Name + '\n')
femobj['Nodes'] = FemMeshTools.get_femnodes_by_femobj_with_references(self.femmesh, femobj)
def get_constraints_transform_nodes(self):
# get nodes
for femobj in self.transform_objects: # femobj --> dict, FreeCAD document object is femobj['Object']
print("Constraint transform nodes: " + femobj['Object'].Name)
FreeCAD.Console.PrintMessage("Constraint transform nodes: " + femobj['Object'].Name + '\n')
femobj['Nodes'] = FemMeshTools.get_femnodes_by_femobj_with_references(self.femmesh, femobj)
def get_constraints_temperature_nodes(self):
# get nodes
for femobj in self.temperature_objects: # femobj --> dict, FreeCAD document object is femobj['Object']
print("Constraint temperature: " + femobj['Object'].Name)
FreeCAD.Console.PrintMessage("Constraint temperature: " + femobj['Object'].Name + '\n')
femobj['Nodes'] = FemMeshTools.get_femnodes_by_femobj_with_references(self.femmesh, femobj)
def get_constraints_fluidsection_nodes(self):
# get nodes
for femobj in self.fluidsection_objects: # femobj --> dict, FreeCAD document object is femobj['Object']
print("Constraint fluid section: " + femobj['Object'].Name)
FreeCAD.Console.PrintMessage("Constraint fluid section: " + femobj['Object'].Name + '\n')
femobj['Nodes'] = FemMeshTools.get_femnodes_by_femobj_with_references(self.femmesh, femobj)
def get_constraints_force_nodeloads(self):
# check shape type of reference shape
for femobj in self.force_objects: # femobj --> dict, FreeCAD document object is femobj['Object']
print("Constraint force: " + femobj['Object'].Name)
FreeCAD.Console.PrintMessage("Constraint force: " + femobj['Object'].Name + '\n')
frc_obj = femobj['Object']
if femobj['RefShapeType'] == 'Vertex':
# print("load on vertices --> we do not need the femelement_table and femnodes_mesh for node load calculation")
@@ -152,7 +152,7 @@ class FemInputWriter():
for femobj in self.force_objects: # femobj --> dict, FreeCAD document object is femobj['Object']
frc_obj = femobj['Object']
if frc_obj.Force == 0:
print(' Warning --> Force = 0')
FreeCAD.Console.PrintMessage(' Warning --> Force = 0\n')
if femobj['RefShapeType'] == 'Vertex': # point load on vertieces
femobj['NodeLoadTable'] = FemMeshTools.get_force_obj_vertex_nodeload_table(self.femmesh, frc_obj)
elif femobj['RefShapeType'] == 'Edge': # line load on edges
@@ -179,22 +179,23 @@ class FemInputWriter():
self.femnodes_ele_table = FemMeshTools.get_femnodes_ele_table(self.femnodes_mesh, self.femelement_table)
for femobj in self.pressure_objects: # femobj --> dict, FreeCAD document object is femobj['Object']
print("Constraint pressure: " + femobj['Object'].Name)
FreeCAD.Console.PrintMessage("Constraint pressure: " + femobj['Object'].Name + '\n')
pressure_faces = FemMeshTools.get_pressure_obj_faces(self.femmesh, self.femelement_table, self.femnodes_ele_table, femobj)
# print(len(pressure_faces))
femobj['PressureFaces'] = [(femobj['Object'].Name + ': face load', pressure_faces)]
print(femobj['PressureFaces'])
FreeCAD.Console.PrintMessage(femobj['PressureFaces'])
FreeCAD.Console.PrintMessage('\n')
def get_element_geometry2D_elements(self):
# get element ids and write them into the objects
print("Shell thicknesses")
FreeCAD.Console.PrintMessage('Shell thicknesses\n')
if not self.femelement_table:
self.femelement_table = FemMeshTools.get_femelement_table(self.femmesh)
FemMeshTools.get_femelement_sets(self.femmesh, self.femelement_table, self.shellthickness_objects)
def get_element_geometry1D_elements(self):
# get element ids and write them into the objects
print("Beam sections")
FreeCAD.Console.PrintMessage('Beam sections\n')
if not self.femelement_table:
self.femelement_table = FemMeshTools.get_femelement_table(self.femmesh)
FemMeshTools.get_femelement_sets(self.femmesh, self.femelement_table, self.beamsection_objects)
@@ -207,7 +208,7 @@ class FemInputWriter():
def get_element_fluid1D_elements(self):
# get element ids and write them into the objects
print("Fluid sections")
FreeCAD.Console.PrintMessage('Fluid sections\n')
if not self.femelement_table:
self.femelement_table = FemMeshTools.get_femelement_table(self.femmesh)
FemMeshTools.get_femelement_sets(self.femmesh, self.femelement_table, self.fluidsection_objects)
@@ -215,7 +216,7 @@ class FemInputWriter():
def get_material_elements(self):
# it only works if either Volumes or Shellthicknesses or Beamsections are in the material objects
# it means it does not work for mixed meshes and multiple materials, this is checked in check_prerequisites
print("Materials")
FreeCAD.Console.PrintMessage('Materials\n')
if self.femmesh.Volumes:
# we only could do this for volumes, if a mesh contains volumes we're going to use them in the analysis
# but a mesh could contain the element faces of the volumes as faces and the edges of the faces as edges,
@@ -223,7 +224,8 @@ class FemInputWriter():
all_found = False
if self.femmesh.GroupCount:
all_found = FemMeshTools.get_femelement_sets_from_group_data(self.femmesh, self.material_objects)
print(all_found)
FreeCAD.Console.PrintMessage(all_found)
FreeCAD.Console.PrintMessage('\n')
if all_found is False:
if not self.femelement_table:
self.femelement_table = FemMeshTools.get_femelement_table(self.femmesh)

View File

@@ -58,8 +58,8 @@ class FemInputWriterZ88(FemInputWriter.FemInputWriter):
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)
print('FemInputWriterZ88 --> self.file_name --> ' + self.file_name)
FreeCAD.Console.PrintMessage('FemInputWriterZ88 --> self.dir_name --> ' + self.dir_name + '\n')
FreeCAD.Console.PrintMessage('FemInputWriterZ88 --> self.file_name --> ' + self.file_name + '\n')
def write_z88_input(self):
timestart = time.clock()
@@ -77,7 +77,7 @@ class FemInputWriterZ88(FemInputWriter.FemInputWriter):
self.write_z88_integration_properties()
self.write_z88_memory_parameter()
self.write_z88_solver_parameter()
print("Writing time input file: " + str(time.clock() - timestart) + ' \n')
FreeCAD.Console.PrintMessage("Writing time input file: " + str(time.clock() - timestart) + ' \n\n')
return self.dir_name
def set_z88_elparam(self):
@@ -94,7 +94,8 @@ class FemInputWriterZ88(FemInputWriter.FemInputWriter):
# elemente 17, 16, 10, INTORD etc ... testen !!!
self.z88_element_type = importZ88Mesh.get_z88_element_type(self.femmesh, self.femelement_table)
self.z88_elparam = self.z88_param[self.z88_element_type]
print(self.z88_elparam)
FreeCAD.Console.PrintMessage(self.z88_elparam)
FreeCAD.Console.PrintMessage('\n')
def write_z88_mesh(self):
mesh_file_path = self.file_name + 'i1.txt'
@@ -169,7 +170,7 @@ class FemInputWriterZ88(FemInputWriter.FemInputWriter):
fmd.write('\n')
fmd.close()
else:
print("Multiple Materials for Z88 not yet supported!")
FreeCAD.Console.PrintError("Multiple Materials for Z88 not yet supported!\n")
def write_z88_elements_properties(self):
element_properties_file_path = self.file_name + 'elp.txt'
@@ -181,20 +182,20 @@ class FemInputWriterZ88(FemInputWriter.FemInputWriter):
height = beam_obj.RectHeight.getValueAs('mm')
area = str(width * height)
elements_data.append('1 ' + str(self.element_count) + ' ' + area + ' 0 0 0 0 0 0 ')
print("Be aware, only trusses are supported for edge meshes!")
FreeCAD.Console.PrintMessage("Be aware, only trusses are supported for edge meshes!\n")
else:
print("Multiple beamsections for Z88 not yet supported!")
FreeCAD.Console.PrintError("Multiple beamsections for Z88 not yet supported!\n")
elif FemMeshTools.is_face_femmesh(self.femmesh):
if len(self.shellthickness_objects) == 1:
thick_obj = self.shellthickness_objects[0]['Object']
thickness = str(thick_obj.Thickness.getValueAs('mm'))
elements_data.append('1 ' + str(self.element_count) + ' ' + thickness + ' 0 0 0 0 0 0 ')
else:
print("Multiple thicknesses for Z88 not yet supported!")
FreeCAD.Console.PrintError("Multiple thicknesses for Z88 not yet supported!\n")
elif FemMeshTools.is_solid_femmesh(self.femmesh):
elements_data.append('1 ' + str(self.element_count) + ' 0 0 0 0 0 0 0')
else:
print("Error!")
FreeCAD.Console.PrintError("Error!\n")
f = open(element_properties_file_path, 'w')
f.write(str(len(elements_data)) + '\n')
for e in elements_data:

View File

@@ -191,7 +191,7 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
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 !
# print('FEM: More than one solver in the analysis and no solver given to analys. No solver is set!')
# FreeCAD.Console.PrintMessage('FEM: More than one solver in the analysis and no solver given to analys. No solver is set!\n')
elif m.isDerivedFrom("Fem::FemMeshObject"):
if not self.mesh:
self.mesh = m
@@ -506,14 +506,14 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
try:
self.working_dir = self.fem_prefs.GetString("WorkingDir")
except:
print('Could not set working directory to FEM Preferences working directory.')
FreeCAD.Console.PrintError('Could not set working directory to FEM Preferences working directory.\n')
else:
print('FEM preferences working dir is not set, the solver working directory is used.')
FreeCAD.Console.PrintMessage('FEM preferences working dir is not set, the solver working directory is used.\n')
if self.solver.WorkingDir:
try:
self.working_dir = self.solver.WorkingDir
except:
print('Could not set working directory to solver working directory.')
FreeCAD.Console.PrintError('Could not set working directory to solver working directory.\n')
# check working_dir has a slash at the end, if not add one
self.working_dir = os.path.join(self.working_dir, '')
@@ -522,11 +522,11 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
try:
os.makedirs(self.working_dir)
except:
print("Dir \'{}\' doesn't exist and cannot be created.".format(self.working_dir))
FreeCAD.Console.PrintError("Dir \'{}\' doesn't exist and cannot be created.\n".format(self.working_dir))
import tempfile
self.working_dir = tempfile.gettempdir()
print("Dir \'{}\' will be used instead.".format(self.working_dir))
print('FemToolsCCx.setup_working_dir() --> self.working_dir = ' + self.working_dir)
FreeCAD.Console.PrintMessage("Dir \'{}\' will be used instead.\n".format(self.working_dir))
FreeCAD.Console.PrintMessage('FemToolsCCx.setup_working_dir() --> self.working_dir = ' + self.working_dir + '\n')
# Update inp file name
self.set_inp_file_name()
@@ -546,7 +546,7 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
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])
FreeCAD.Console.PrintError("Unexpected error when writing CalculiX input file: {}\n".format(sys.exc_info()[0]))
raise
## Sets CalculiX ccx binary path and validates if the binary can be executed
@@ -682,23 +682,23 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
self.finished.emit(ret_code)
progress_bar.stop()
if ret_code or self.ccx_stderr:
print("CalculiX failed with exit code {}".format(ret_code))
print("--------start of stderr-------")
print(self.ccx_stderr)
print("--------end of stderr---------")
print("--------start of stdout-------")
print(self.ccx_stdout)
FreeCAD.Console.PrintError("CalculiX failed with exit code {}\n".format(ret_code))
FreeCAD.Console.PrintMessage("--------start of stderr-------\n")
FreeCAD.Console.PrintMessage(self.ccx_stderr)
FreeCAD.Console.PrintMessage("--------end of stderr---------\n")
FreeCAD.Console.PrintMessage("--------start of stdout-------\n")
FreeCAD.Console.PrintMessage(self.ccx_stdout)
self.has_for_nonpositive_jacobians()
print("--------end of stdout---------")
FreeCAD.Console.PrintMessage("--------end of stdout---------\n")
else:
print("CalculiX finished without error")
FreeCAD.Console.PrintMessage("CalculiX finished without error\n")
else:
print("CalculiX was not started due to missing prerequisites:\n{}".format(message))
FreeCAD.Console.PrintError("CalculiX was not started due to missing prerequisites:\n{}\n".format(message))
# ATM it is not possible to start CalculiX if prerequisites are not fulfilled
def has_for_nonpositive_jacobians(self):
if '*ERROR in e_c3d: nonpositive jacobian' in self.ccx_stdout:
print('CalculiX returned an error due to nonpositive jacobian elements.')
FreeCAD.Console.PrintError('CalculiX returned an error due to nonpositive jacobian elements.\n')
nonpositive_jacobian_elements = []
nonpositive_jacobian_elenodes = []
for line in self.ccx_stdout.splitlines():
@@ -716,10 +716,10 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
nonpositive_jacobian_elenodes = sorted(nonpositive_jacobian_elenodes)
command_for_nonposjacnodes = 'nonpositive_jacobian_elenodes = ' + str(nonpositive_jacobian_elenodes)
command_to_highlight = "Gui.ActiveDocument." + self.mesh.Name + ".HighlightedNodes = nonpositive_jacobian_elenodes"
print('nonpositive_jacobian_elements = ' + str(nonpositive_jacobian_elements))
print(command_for_nonposjacnodes)
print(command_to_highlight)
print('Gui.ActiveDocument.Extrude_Mesh.HighlightedNodes = []\n') # command to reset the Highlighted Nodes
FreeCAD.Console.PrintMessage('nonpositive_jacobian_elements = {}\n'.format(nonpositive_jacobian_elements))
FreeCAD.Console.PrintMessage(command_for_nonposjacnodes + '\n')
FreeCAD.Console.PrintMessage(command_to_highlight + '\n')
FreeCAD.Console.PrintMessage('Gui.ActiveDocument.Extrude_Mesh.HighlightedNodes = []\n\n') # command to reset the Highlighted Nodes
if FreeCAD.GuiUp:
import FreeCADGui
FreeCADGui.doCommand(command_for_nonposjacnodes)
@@ -784,10 +784,10 @@ def get_refshape_type(fem_doc_object):
first_ref_obj = fem_doc_object.References[0]
first_ref_shape = FemMeshTools.get_element(first_ref_obj[0], first_ref_obj[1][0])
st = first_ref_shape.ShapeType
print(fem_doc_object.Name + ' has ' + st + ' reference shapes.')
FreeCAD.Console.PrintMessage(fem_doc_object.Name + ' has ' + st + ' reference shapes.\n')
return st
else:
print(fem_doc_object.Name + ' has empty References.')
FreeCAD.Console.PrintMessage(fem_doc_object.Name + ' has empty References.\n')
return ''
## @}