SymbolicBFI definedonelements = all elements that are needed for FreeDofs?

Hello,

I have a fes for the whole system. Using the definedon=‘regexpr’ key the system is substructured into parts and stored to different fes_parts. Using the Compress method, I can use everything nice and clean for the different substructures.
To do the AssembleLinearization only on the elements in the substructure, I have a very large code-block to find all elements that have any dof in the substructure. Then translating the element-numbers into a BitArray that is then applied to the SymbolicBFI(…, definedonelements=BitArray).
Is there any shortcut available to find all elements related to the FreeDofs of such a fes_part automatically?

Also I didn’t understand the difference in the following example (dealing with exactly that):

[code]
fes_in = object.fespace(definedon=object.nonlinear_domain)

fesMini = Compress(fes_in)
u, v = fesMini.TnT()

print('---> Mini FE-Space', fesMini.ndof)

el_iterator = fesMini.Elements()

master_el_nrs = []
for el in el_iterator:
    master_el_nrs.append(el.nr)
    el_id = ElementId(VOL, el.nr)
    
act_el = BitArray(object.mesh.ne)
act_el[:] = False

for i in master_el_nrs:
    act_el[i] = True

print('active elements...........', sum(act_el))

#-------------------------------------------------------------------------   

InternalMask = fes_in.FreeDofs()
wii = np.where(InternalMask)
ix_ii = np.ix_(wii[0],wii[0])

aMini = BilinearForm(fesMini)
aMini += SymbolicBFI(object.fcn_weak_K(object, material, u,v), definedonelements=act_el )
aMini.Assemble()
KiiMini = ngsolve2spmat_mat(aMini.mat)
#Ergebnis: Immer zu klein, mit und ohne definedonelements

fesfull = object.fespace()
ufull,vfull = fesfull.TnT()
aTest = BilinearForm(fesfull)
aTest +=SymbolicBFI(object.fcn_weak_K(object, material, ufull,vfull), definedonelements=act_el )
aTest.Assemble()
ATest = ngsolve2spmat_mat(aTest.mat)
KiiTest = ATest[ix_ii]
#Ergebnis: mit definedonelements ist das Ergebnis zu klein, ohne passt es. 
#Die Anzahl der dofs sind immer gleich...[/code]

Kind regards,

Just wanted to give an update how I solved it meanwhile for me. Certainly not the most elegant way, but functional and not too slow:

def createInnerModel(object):
    # get finite element space
    fes = object.fespace()
    fes_in = Compress(object.fespace(definedon=inner_domain))
   
    # Suche alle dofs, die mit den inneren Elementen verknüpft sind
    mastervertices = []
    el_iterator = fes_in.Elements()  
    for el in el_iterator:
        el_id = ElementId(VOL, el.nr)
        mastervertices.extend(fes.GetDofNrs(el_id))

    dofs = BitArray(fes.ndof)
    dofs[:] = False
    for i in mastervertices:
        dofs[i] = True
    
    fesMini = Compress(fes, active_dofs=dofs)
    print('---> Mini FE-Space', fesMini.ndof)
    
    # Search for all elements that are related to that dofs
    master_el_nrs = []
    for el in fes.Elements(VOL):
        is_master = False
        el_id = ElementId(VOL, el.nr)
        eldofs = fes.GetDofNrs(el_id)
        for eldof in eldofs:
            is_master |= eldof in mastervertices
        if is_master:
            master_el_nrs.append(el.nr)

    E_tilde = np.unique(master_el_nrs)

    act_el = BitArray(object.mesh.ne)
    act_el[:] = False
    
    for i in E_tilde:
        act_el[i] = True    

    print('active elements...........', sum(act_el))
    
    return fesMini, act_el