Please find a snippet below illustrating the usage. The script has not been carefully tested. Accordingly, I cannot give any warranty that the script is working properly.
[color=blue][font=courier]
import sys, os
sys.path.append('C:\\Program Files\\DHI\\2017\\FEFLOW 7.1\\bin64')
import ifm
try:
def no_selection(n_selections):
assert (n_selections != 0),"No selections are available"
cwd = os.getcwd()
FEM_FILE_in = cwd + "\\..\\femdata\\box.fem"
FEM_FILE_out = cwd + "\\..\\femdata\\box_out.fem"
doc = ifm.loadDocument(FEM_FILE_in)
sel_type=1 # nodal=0, elemental=1
n_selections = doc.getNumberOfSelections(sel_type)
n_elements = doc.getNumberOfElements()
n_dimensions=doc.getNumberOfDimensions()
new_selection_id = 0
if n_selections == 0:
print no_selection(n_selections)
print "FEM_FILE in: " + FEM_FILE_in
print "FEM_FILE in: " + FEM_FILE_out
print "Number of selections: " + str(n_selections)
print "Available selections:"
for selection in range(0,n_selections-1):
print " ", doc.getSelectionName(sel_type,selection)
selection_members_list_all = []
for selection in range(0, n_selections):
selection_members_list_current = []
for element_id in range(0, n_elements):
if doc.selectionItemIsSet(sel_type, selection, element_id) == 1:
selection_members_list_current.append(element_id)
selection_members_list_all.append(selection_members_list_current)
# Make selection sets
selection_set_list = []
for i in range(0, n_selections):
selection_set_list.append(set(selection_members_list_all[i]))
# Intersect two selections
for selection in range(0,n_selections-1):
name_new_selection = "INTERSECT_" + str(doc.getSelectionName(sel_type, selection)) + "_" + str(doc.getSelectionName(sel_type, selection + 1))
doc.createSelection(sel_type, name_new_selection)
selection_members_list_current = list(selection_set_list[selection].intersection(selection_set_list[selection+1]))
new_selection_id = doc.findSelection(sel_type, name_new_selection)
for element in range(0, n_elements):
if element in selection_members_list_current:
doc.setSelectionItem(sel_type, new_selection_id, element)
# Union two selections
for selection in range(0, n_selections - 1):
name_new_selection = "UNION_" + str(doc.getSelectionName(sel_type, selection)) + "_" + str(doc.getSelectionName(sel_type, selection + 1))
doc.createSelection(sel_type, name_new_selection)
selection_members_list_current = list(selection_set_list[selection].union(selection_set_list[selection + 1]))
new_selection_id = doc.findSelection(sel_type, name_new_selection)
for element in range(0, n_elements):
if element in selection_members_list_current:
doc.setSelectionItem(sel_type, new_selection_id, element)
# Difference between selection i and i-1
for selection in range(0, n_selections - 1):
name_new_selection = "DIFFERENCE_" + str(doc.getSelectionName(sel_type, selection)) + "_" + str(doc.getSelectionName(sel_type, selection + 1))
doc.createSelection(sel_type, name_new_selection)
selection_members_list_current = list(
selection_set_list[selection].difference(selection_set_list[selection + 1]))
new_selection_id = doc.findSelection(sel_type, name_new_selection)
for element in range(0, n_elements):
if element in selection_members_list_current:
doc.setSelectionItem(sel_type, new_selection_id, element)
# Symmetric difference of two selections in two directions
for selection in range(0, n_selections - 1):
name_new_selection = "SYMMETRIC_DIFFERENCE_" + str(doc.getSelectionName(sel_type, selection)) + "_" + str(
doc.getSelectionName(sel_type, selection + 1))
doc.createSelection(sel_type, name_new_selection)
selection_members_list_current = list(
selection_set_list[selection].symmetric_difference(selection_set_list[selection + 1]))
new_selection_id = doc.findSelection(sel_type, name_new_selection)
for element in range(0, n_elements):
if element in selection_members_list_current:
doc.setSelectionItem(sel_type, new_selection_id, element)
# Save new fem file with new selection sets
doc.saveDocument(FEM_FILE_out)
except Exception as err:
print >> sys.stderr, 'Error: ' + str(err) + '!'
sys.exit(-1);
[/font][/color]