FEM: calculix writer, move generic constraint writer into base writer

This commit is contained in:
Bernd Hahnebach
2021-07-13 07:59:21 +02:00
parent d72d24b30c
commit ad76c5b554
2 changed files with 101 additions and 98 deletions

View File

@@ -170,44 +170,44 @@ class FemInputWriterCcx(writerbase.FemInputWriter):
inpfile = con_fluidsection.handle_fluidsection_liquid_inlet_outlet(inpfile, self)
# element sets constraints
self.write_constraints_sets(inpfile, self.centrif_objects, con_centrif)
self.write_constraints_meshsets(inpfile, self.centrif_objects, con_centrif)
# node sets
self.write_constraints_sets(inpfile, self.fixed_objects, con_fixed)
self.write_constraints_sets(inpfile, self.displacement_objects, con_displacement)
self.write_constraints_sets(inpfile, self.planerotation_objects, con_planerotation)
self.write_constraints_sets(inpfile, self.transform_objects, con_transform)
self.write_constraints_sets(inpfile, self.temperature_objects, con_temperature)
self.write_constraints_meshsets(inpfile, self.fixed_objects, con_fixed)
self.write_constraints_meshsets(inpfile, self.displacement_objects, con_displacement)
self.write_constraints_meshsets(inpfile, self.planerotation_objects, con_planerotation)
self.write_constraints_meshsets(inpfile, self.transform_objects, con_transform)
self.write_constraints_meshsets(inpfile, self.temperature_objects, con_temperature)
# surface sets
self.write_constraints_sets(inpfile, self.contact_objects, con_contact)
self.write_constraints_sets(inpfile, self.tie_objects, con_tie)
self.write_constraints_sets(inpfile, self.sectionprint_objects, con_sectionprint)
self.write_constraints_meshsets(inpfile, self.contact_objects, con_contact)
self.write_constraints_meshsets(inpfile, self.tie_objects, con_tie)
self.write_constraints_meshsets(inpfile, self.sectionprint_objects, con_sectionprint)
# materials and fem element types
write_femelement_material.write_femelement_material(inpfile, self)
self.write_constraints_data(inpfile, self.initialtemperature_objects, con_initialtemp)
self.write_constraints_propdata(inpfile, self.initialtemperature_objects, con_initialtemp)
write_femelement_geometry.write_femelement_geometry(inpfile, self)
# constraints independent from steps
self.write_constraints_data(inpfile, self.planerotation_objects, con_planerotation)
self.write_constraints_data(inpfile, self.contact_objects, con_contact)
self.write_constraints_data(inpfile, self.tie_objects, con_tie)
self.write_constraints_data(inpfile, self.transform_objects, con_transform)
self.write_constraints_propdata(inpfile, self.planerotation_objects, con_planerotation)
self.write_constraints_propdata(inpfile, self.contact_objects, con_contact)
self.write_constraints_propdata(inpfile, self.tie_objects, con_tie)
self.write_constraints_propdata(inpfile, self.transform_objects, con_transform)
# step equation
write_step_equation.write_step_equation(inpfile, self)
# constraints dependent from steps
self.write_constraints_data(inpfile, self.fixed_objects, con_fixed)
self.write_constraints_data(inpfile, self.displacement_objects, con_displacement)
self.write_constraints_data(inpfile, self.sectionprint_objects, con_sectionprint)
self.write_constraints_data(inpfile, self.selfweight_objects, con_selfweight)
self.write_constraints_data(inpfile, self.centrif_objects, con_centrif)
self.write_constraints_sets(inpfile, self.force_objects, con_force)
self.write_constraints_sets(inpfile, self.pressure_objects, con_pressure)
self.write_constraints_data(inpfile, self.temperature_objects, con_temperature)
self.write_constraints_sets(inpfile, self.heatflux_objects, con_heatflux)
self.write_constraints_propdata(inpfile, self.fixed_objects, con_fixed)
self.write_constraints_propdata(inpfile, self.displacement_objects, con_displacement)
self.write_constraints_propdata(inpfile, self.sectionprint_objects, con_sectionprint)
self.write_constraints_propdata(inpfile, self.selfweight_objects, con_selfweight)
self.write_constraints_propdata(inpfile, self.centrif_objects, con_centrif)
self.write_constraints_meshsets(inpfile, self.force_objects, con_force)
self.write_constraints_meshsets(inpfile, self.pressure_objects, con_pressure)
self.write_constraints_propdata(inpfile, self.temperature_objects, con_temperature)
self.write_constraints_meshsets(inpfile, self.heatflux_objects, con_heatflux)
con_fluidsection.write_constraints_fluidsection(inpfile, self)
# output and step end
@@ -218,80 +218,5 @@ class FemInputWriterCcx(writerbase.FemInputWriter):
write_footer.write_footer(inpfile, self)
inpfile.close()
# ********************************************************************************************
# write constraint node sets, constraint face sets, constraint element sets
def write_constraints_sets(
self,
f,
femobjs,
con_module
):
if not femobjs:
return
analysis_types = con_module.get_analysis_types()
if analysis_types != "all" and self.analysis_type not in analysis_types:
return
def constraint_sets_loop_writing(the_file, femobjs, write_before, write_after):
if write_before != "":
f.write(write_before)
for femobj in femobjs:
# femobj --> dict, FreeCAD document object is femobj["Object"]
the_obj = femobj["Object"]
f.write("** {}\n".format(the_obj.Label))
con_module.write_meshdata_constraint(the_file, femobj, the_obj, self)
if write_after != "":
f.write(write_after)
write_before = con_module.get_before_write_meshdata_constraint()
write_after = con_module.get_after_write_meshdata_constraint()
# write sets to file
write_name = con_module.get_sets_name()
f.write("\n{}\n".format(59 * "*"))
f.write("** {}\n".format(write_name.replace("_", " ")))
if self.split_inpfile is True:
file_name_split = "{}_{}.inp".format(self.mesh_name, write_name)
f.write("** {}\n".format(write_name.replace("_", " ")))
f.write("*INCLUDE,INPUT={}\n".format(file_name_split))
inpfile_split = open(join(self.dir_name, file_name_split), "w")
constraint_sets_loop_writing(inpfile_split, femobjs, write_before, write_after)
inpfile_split.close()
else:
constraint_sets_loop_writing(f, femobjs, write_before, write_after)
# ********************************************************************************************
# write constraint data
def write_constraints_data(
self,
f,
femobjs,
con_module
):
if not femobjs:
return
analysis_types = con_module.get_analysis_types()
if analysis_types != "all" and self.analysis_type not in analysis_types:
return
write_before = con_module.get_before_write_constraint()
write_after = con_module.get_after_write_constraint()
# write constraint to file
f.write("\n{}\n".format(59 * "*"))
f.write("** {}\n".format(con_module.get_constraint_title()))
if write_before != "":
f.write(write_before)
for femobj in femobjs:
# femobj --> dict, FreeCAD document object is femobj["Object"]
the_obj = femobj["Object"]
f.write("** {}\n".format(the_obj.Label))
con_module.write_constraint(f, femobj, the_obj, self)
if write_after != "":
f.write(write_after)
## @}

View File

@@ -29,6 +29,7 @@ __url__ = "https://www.freecadweb.org"
# @{
import os
from os.path import join
import FreeCAD
@@ -127,6 +128,83 @@ class FemInputWriter():
self.femelement_edges_table = {}
self.femelement_count_test = True
# ********************************************************************************************
# ********************************************************************************************
# generic writer for constraints mesh sets and constraints property data
# write constraint node sets, constraint face sets, constraint element sets
def write_constraints_meshsets(
self,
f,
femobjs,
con_module
):
if not femobjs:
return
analysis_types = con_module.get_analysis_types()
if analysis_types != "all" and self.analysis_type not in analysis_types:
return
def constraint_sets_loop_writing(the_file, femobjs, write_before, write_after):
if write_before != "":
f.write(write_before)
for femobj in femobjs:
# femobj --> dict, FreeCAD document object is femobj["Object"]
the_obj = femobj["Object"]
f.write("** {}\n".format(the_obj.Label))
con_module.write_meshdata_constraint(the_file, femobj, the_obj, self)
if write_after != "":
f.write(write_after)
write_before = con_module.get_before_write_meshdata_constraint()
write_after = con_module.get_after_write_meshdata_constraint()
# write sets to file
write_name = con_module.get_sets_name()
f.write("\n{}\n".format(59 * "*"))
f.write("** {}\n".format(write_name.replace("_", " ")))
if self.split_inpfile is True:
file_name_split = "{}_{}.inp".format(self.mesh_name, write_name)
f.write("** {}\n".format(write_name.replace("_", " ")))
f.write("*INCLUDE,INPUT={}\n".format(file_name_split))
inpfile_split = open(join(self.dir_name, file_name_split), "w")
constraint_sets_loop_writing(inpfile_split, femobjs, write_before, write_after)
inpfile_split.close()
else:
constraint_sets_loop_writing(f, femobjs, write_before, write_after)
# write constraint property data
def write_constraints_propdata(
self,
f,
femobjs,
con_module
):
if not femobjs:
return
analysis_types = con_module.get_analysis_types()
if analysis_types != "all" and self.analysis_type not in analysis_types:
return
write_before = con_module.get_before_write_constraint()
write_after = con_module.get_after_write_constraint()
# write constraint to file
f.write("\n{}\n".format(59 * "*"))
f.write("** {}\n".format(con_module.get_constraint_title()))
if write_before != "":
f.write(write_before)
for femobj in femobjs:
# femobj --> dict, FreeCAD document object is femobj["Object"]
the_obj = femobj["Object"]
f.write("** {}\n".format(the_obj.Label))
con_module.write_constraint(f, femobj, the_obj, self)
if write_after != "":
f.write(write_after)
# ********************************************************************************************
# ********************************************************************************************
# use set for node sets to be sure all nodes are unique