# Efficient Formulation and Acceleration Techniques for Nonlinear Problems

Hello community,

I am currently working on a non linear magnetic problem where I need to define a BH curves that are different on each elements of a specific region.

This is a the simplified logic of my code. I create B and H list for each element. Then, for each element a BSpline is created along with the analytical formulation depending on this Bspline.

fes_tau = L2(mesh, order = 0)
for el in mesh.Elements() :
B_data[el.nr] = …
# logic to compute B list depending on the element. H list doesnt change

for el in elements :
gf_indice_mesh = GridFunction(fes_tau) # grid function created to define formulation on 1 element
gf_indice_mesh.vec.data[el.nr] = 1 # grid function = 1 on current element, 0 elswere
hb_curve = BSpline(2, [0]+[0]+list(B_data[el.nr]), [0]+list(H))
energy_dens = hb_curve.Integrate() # BSpline created for each elemeent

This method is functionnal, however very time consuming. I have thus two questions :

1 - Defining stuff on elements
Is there a more convinient way to define CoefficientFunctions or SumOfIntegrals objects on elements.

2 - Solving Time
Secondly, the computation time to solve such problem is very high. By this I mean the computation time of the solver nonlinear iteration. Is there any way to improve it ?