FEM: mesh group, add a needed def to mesh tools and use the new mesh group object in gmsh mesh class
This commit is contained in:
committed by
Yorik van Havre
parent
78540d2612
commit
e04c3369ee
@@ -215,17 +215,39 @@ class FemGmshTools():
|
||||
print(' ' + self.gmsh_bin)
|
||||
|
||||
def get_group_data(self):
|
||||
self.group_elements = {}
|
||||
# TODO solid, face, edge seam not work together, some print or make it work together
|
||||
# TODO handle groups for Edges and Vertexes
|
||||
|
||||
# mesh groups and groups of analysis member
|
||||
if not self.mesh_obj.MeshGroupList:
|
||||
print (' No mesh group objects.')
|
||||
else:
|
||||
print (' Mesh group objects, we need to get the elements.')
|
||||
for mg in self.mesh_obj.MeshGroupList:
|
||||
new_group_elements = FemMeshTools.get_mesh_group_elements(mg, self.part_obj)
|
||||
for ge in new_group_elements:
|
||||
if ge not in self.group_elements:
|
||||
self.group_elements[ge] = new_group_elements[ge]
|
||||
else:
|
||||
FreeCAD.Console.PrintError(" A group with this name exists already.\n")
|
||||
if self.analysis:
|
||||
print(' Group meshing.')
|
||||
self.group_elements = FemMeshTools.get_analysis_group_elements(self.analysis, self.part_obj)
|
||||
print(' {}'.format(self.group_elements))
|
||||
new_group_elements = FemMeshTools.get_analysis_group_elements(self.analysis, self.part_obj)
|
||||
for ge in new_group_elements:
|
||||
if ge not in self.group_elements:
|
||||
self.group_elements[ge] = new_group_elements[ge]
|
||||
else:
|
||||
FreeCAD.Console.PrintError(" A group with this name exists already.\n")
|
||||
else:
|
||||
print(' NO group meshing.')
|
||||
print(' No anlysis members for group meshing.')
|
||||
print(' {}'.format(self.group_elements))
|
||||
|
||||
# mesh regions
|
||||
self.ele_length_map = {} # { 'ElementString' : element length }
|
||||
self.ele_node_map = {} # { 'ElementString' : [element nodes] }
|
||||
if not self.mesh_obj.MeshRegionList:
|
||||
print (' No Mesh regions.')
|
||||
print (' No mesh regions.')
|
||||
else:
|
||||
print (' Mesh regions, we need to get the elements.')
|
||||
if self.part_obj.Shape.ShapeType == 'Compound':
|
||||
@@ -279,7 +301,7 @@ class FemGmshTools():
|
||||
geo = open(self.temp_file_geo, "w")
|
||||
geo.write('Merge "' + self.temp_file_geometry + '";\n')
|
||||
geo.write("\n")
|
||||
if self.analysis and self.group_elements:
|
||||
if self.group_elements:
|
||||
# print(' We gone have found elements to make mesh groups for.')
|
||||
geo.write("// group data\n")
|
||||
# we use the element name of FreeCAD which starts with 1 (example: 'Face1'), same as GMSH
|
||||
|
||||
@@ -995,54 +995,43 @@ def get_ref_shape_node_sum_geom_table(node_geom_table):
|
||||
return node_sum_geom_table
|
||||
|
||||
|
||||
def get_mesh_group_elements(mesh_group_obj, aPart):
|
||||
'''the Reference shapes of the mesh_group_object are searched in the Shape of aPart. If found in shape they are added to a dict
|
||||
{MeshGroupIdentifier : ['ShapeType of the Elements'], [ElementID, ElementID, ...], ...}
|
||||
'''
|
||||
group_elements = {} # { name : [element, element, ... , element]}
|
||||
if mesh_group_obj.References:
|
||||
grp_ele = get_reference_group_elements(mesh_group_obj, aPart)
|
||||
group_elements[grp_ele[0]] = grp_ele[1]
|
||||
else:
|
||||
FreeCAD.Console.PrintError(' Empty reference in mesh group object: ' + mesh_group_obj.Name + ' ' + mesh_group_obj.Label)
|
||||
return group_elements
|
||||
|
||||
|
||||
def get_analysis_group_elements(aAnalysis, aPart):
|
||||
''' all Reference shapes of all Analysis member are searched in the Shape of aPart. If found in shape they are added to a dict
|
||||
{ConstraintName : ['ShapeType of the Elements'], [ElementID, ElementID, ...], ...}
|
||||
'''
|
||||
aShape = aPart.Shape
|
||||
group_elements = {} # { name : [element, element, ... , element]}
|
||||
empty_references = []
|
||||
for m in aAnalysis.Member:
|
||||
if hasattr(m, "References"):
|
||||
# print(m.Name)
|
||||
key = m.Name
|
||||
elements = []
|
||||
stype = None
|
||||
if m.References:
|
||||
for r in m.References:
|
||||
parent = r[0]
|
||||
childs = r[1]
|
||||
# print(parent)
|
||||
# print(childs)
|
||||
for child in childs:
|
||||
ref_shape = get_element(parent, child) # the method getElement(element) does not return Solid elements
|
||||
if not stype:
|
||||
stype = ref_shape.ShapeType
|
||||
elif stype != ref_shape.ShapeType:
|
||||
FreeCAD.Console.PrintError('Error, two refschapes in References with different ShapeTypes.\n')
|
||||
# print(ref_shape)
|
||||
found_element = find_element_in_shape(aShape, ref_shape)
|
||||
if found_element is not None:
|
||||
elements.append(found_element)
|
||||
else:
|
||||
FreeCAD.Console.PrintError('Problem: No element found for: ' + str(ref_shape) + '\n')
|
||||
print(' ' + m.Name)
|
||||
print(' ' + str(m.References))
|
||||
print(' ' + r[0].Name)
|
||||
group_elements[key] = sorted(elements)
|
||||
grp_ele = get_reference_group_elements(m, aPart)
|
||||
group_elements[grp_ele[0]] = grp_ele[1]
|
||||
else:
|
||||
print(' Empty reference: ' + m.Name)
|
||||
empty_references.append(m)
|
||||
if empty_references:
|
||||
if len(empty_references) == 1:
|
||||
group_elements = get_anlysis_empty_references_group_elements(group_elements, aAnalysis, aShape)
|
||||
group_elements = get_anlysis_empty_references_group_elements(group_elements, aAnalysis, aPart.Shape)
|
||||
else:
|
||||
FreeCAD.Console.PrintError('Problem: more than one object with empty references.\n')
|
||||
print('We gone try to get the empty material references anyway.\n')
|
||||
# ShellThickness and BeamSection could have empty references, but on solid meshes only materials should have empty references
|
||||
for er in empty_references:
|
||||
print(er.Name)
|
||||
group_elements = get_anlysis_empty_references_group_elements(group_elements, aAnalysis, aShape)
|
||||
group_elements = get_anlysis_empty_references_group_elements(group_elements, aAnalysis, aPart.Shape)
|
||||
# check if all groups have elements:
|
||||
for g in group_elements:
|
||||
# print(group_elements[g])
|
||||
@@ -1051,6 +1040,37 @@ def get_analysis_group_elements(aAnalysis, aPart):
|
||||
return group_elements
|
||||
|
||||
|
||||
def get_reference_group_elements(obj, aPart):
|
||||
aShape = aPart.Shape
|
||||
if hasattr(obj, "UseLabel") and obj.UseLabel:
|
||||
key = obj.Label # TODO check the character of the Label, only allow underline and standard english character
|
||||
else:
|
||||
key = obj.Name
|
||||
elements = []
|
||||
stype = None
|
||||
for r in obj.References:
|
||||
parent = r[0]
|
||||
childs = r[1]
|
||||
# print(parent)
|
||||
# print(childs)
|
||||
for child in childs:
|
||||
ref_shape = get_element(parent, child) # the method getElement(element) does not return Solid elements
|
||||
if not stype:
|
||||
stype = ref_shape.ShapeType
|
||||
elif stype != ref_shape.ShapeType:
|
||||
FreeCAD.Console.PrintError('Error, two refschapes in References with different ShapeTypes.\n')
|
||||
# print(ref_shape)
|
||||
found_element = find_element_in_shape(aShape, ref_shape)
|
||||
if found_element is not None:
|
||||
elements.append(found_element)
|
||||
else:
|
||||
FreeCAD.Console.PrintError('Problem: No element found for: ' + str(ref_shape) + '\n')
|
||||
print(' ' + obj.Name)
|
||||
print(' ' + str(obj.References))
|
||||
print(' ' + r[0].Name)
|
||||
return (key, sorted(elements))
|
||||
|
||||
|
||||
def get_anlysis_empty_references_group_elements(group_elements, aAnalysis, aShape):
|
||||
'''get the elementIDs if the Reference shape is empty
|
||||
see get_analysis_group_elements() for more informatations
|
||||
|
||||
Reference in New Issue
Block a user