Assemble_matrix on frequency dependent form

Yes, I understand the issue. This means that the optimal approach is to make the matrices (and vectors) not frequency dependent and assemble them outside of the for loop. This will also move dolfinx.fem.form outside of the loop.

then I would build the matrix A as linear combination of the assembled matrix as you say here:

that in my case means building the matrix A in this way:

K_a = assemble_matrix(K_a_form), [])
K_a.assemble()
M_a = assemble_matrix(M_a_form), [])
M_a.assemble()

# creating KSP solver
...
# frequency loop
for freq in frequency_range:

    omega.value = 2*np.pi*freq # this is the only frequency dependent value
    
    A = K_a - omega**2 * M_a

    # solving the problem  A * x = b

is it a correct approach?