@@ -122,51 +122,38 @@ def add_exodus_geometry_section(cubit, input_file, rel_exo_file_path):
122122 The relative path (as seen from the yaml input file) to the exodus
123123 file that contains the mesh.
124124 """
125+ # Retrieve a list of the block IDs and the corresponding block data of the current session
126+ element_block_ids = cubit .cubit .get_block_id_list ()
127+ element_blocks = cubit .blocks
125128
126- # check which 4C sections are currently defined
127- sections = {data [0 ].get_four_c_section () for data in cubit .blocks }
128- if not len (sections ) == 1 :
129- raise RuntimeError (
130- "A geometry section can currently only be generated if a single"
131- "element type is defined in the cubit session, but I found "
132- f"{ len (sections )} different element types: { ', ' .join (sections )} . "
133- "Please include the mesh in the .yaml input file by rerunning "
134- "'cubit.dump()' with the 'mesh_in_exo' argument set to False."
135- )
136- problem_key = sections .pop () + " GEOMETRY"
137-
138- # create the dictionary for the geometry section
139- geometry_section_dict = {}
140-
141- # add the relative path to the exodus file
142- geometry_section_dict ["FILE" ] = rel_exo_file_path
143- # always show a detailed summary
144- geometry_section_dict ["SHOW_INFO" ] = "detailed_summary"
145-
146- # add the element blocks
147- geometry_section_dict ["ELEMENT_BLOCKS" ] = []
148- # iterate over all blocks
149- block_ids = cubit .cubit .get_block_id_list ()
150- for list_index , block_id in enumerate (block_ids ):
151- # retrieve the data associated with the block
152- data = cubit .blocks [list_index ]
129+ # Iterate over all blocks and add them to the input file
130+ for cur_block_id , cur_block_data in zip (element_block_ids , element_blocks ):
131+ # retrieve the name of the geometry section that this block belongs to
132+ cur_geometry_section_key = cur_block_data [0 ].get_four_c_section () + " GEOMETRY"
133+ # If the geometry section for this block does not exist yet, create it
134+ if input_file .sections .get (cur_geometry_section_key ) is None :
135+ # add the geometry section to the input file
136+ input_file [cur_geometry_section_key ] = {
137+ "FILE" : rel_exo_file_path ,
138+ "SHOW_INFO" : "detailed_summary" ,
139+ "ELEMENT_BLOCKS" : [],
140+ }
153141 # retrieve the fourc name for the element
154- four_c_element_name = data [0 ].get_four_c_name ()
142+ four_c_element_name = cur_block_data [0 ].get_four_c_name ()
155143 # convert the material data from dict to string because 4C currently does not support a dict here
156144 element_data_string = " " .join (
157- f"{ key } { value } " for key , value in data [1 ].items ()
145+ f"{ key } { value } " for key , value in cur_block_data [1 ].items ()
158146 )
159147 # add block id, fourc element name and element data string to the element block dictionary
160148 element_block_dict = {
161- "ID" : block_id ,
149+ "ID" : cur_block_id ,
162150 "ELEMENT_NAME" : four_c_element_name ,
163151 "ELEMENT_DATA" : element_data_string ,
164152 }
165153 # append the dictionary with the element block information to the element block list
166- geometry_section_dict ["ELEMENT_BLOCKS" ].append (element_block_dict )
167-
168- # at long last, append the geometry section to the input file
169- input_file [problem_key ] = geometry_section_dict
154+ input_file [cur_geometry_section_key ]["ELEMENT_BLOCKS" ].append (
155+ element_block_dict
156+ )
170157
171158
172159def get_element_connectivity_list (connectivity ):
0 commit comments