# The ideas behind LinearForm Assemble?

from ngsolve import *
from ngsolve.webgui import Draw
from netgen.occ import *

mesh = Mesh(unit_cube.GenerateMesh(maxh = 0.5))
k =2
V_top = Compress(H1(mesh, definedon = mesh.Boundaries(“right”), order = k))
V_bottom = Compress(H1(mesh, definedon = mesh.Boundaries(“bottom”), order = k))

u,v = V_top.TnT()
u2,v2 = V_bottom.TnT()

Method 1:(correct)
f_v2 = LinearForm(V_bottom)
f_v2+= (x**2* y+sin(x))* v2*ds(“bottom”)
f_v2.Assemble()

method 2:(multiplying the wrong test function v without any error/warning)
f_v = LinearForm(V_bottom)
f_v += (x**2*y+sin(x))*v * ds(“bottom”)
f_v.Assemble()

However, f_v.vec is exactly same as f_v2.vec. Why???
I use wrong test function but get the correct result in f_v.
SO what is the idea behind the ideas behind LinearForm Assemble?
Seemly, it doesn’t depend on test function.

Hm what you are doing is not defined. And internal code logic does this:
f_v is on V_bottom, v is a testfunction on V_top which says “i’m evaluation on the full space”. The integrator then ignores that v is on a different space and uses it’s evaluator on V_bottom, which works (as it is the same evalutor).
See v more as a symbolic object in here to assemble the form, it needs to be on the space, but you could do grad(v) or other operators of v…

what would you want to do here?

Note that there is also another syntax that doesn’t define the linearform on a space:

``````f_v = LinearForm((x**2*y+sin(x))*v * ds("bottom"))
``````

then the space is taken from the `v` object → vector is 0

Hi, Thanks. It is just a bug when I was coding. I found some different performance for different LinearForm assemble ways.
I also test : f_v = LinearForm((x**2*y+sin(x))*v * ds(“bottom”)) does correct thing. For this syntax, v just like the usually test function which is non-zero on top boundary, but zero on bottom.

I think it is totally the same as the test fucntion concept in the usually FE theory. Because test functions depend on the underlying domain.
v is an python object as you said here. Probably, object v has an attribute of the underlying domain geometry: mesh.Boundaries(“top”).

However,

In the above syntax, you said v is just a evalutor/symbol. no FE space information in v. Here the underlying geometry is encoding when "f_v = LinearForm(V_bottom) " executes. then v is a symbol to indicate that oh we need integral x**2*y+sin(x) multiply basis function. so no any error/warning.

Are the above ideas correct?

basically yes, v always carries space info as well, but if linearform already has it it is just not used and only info on how to intrgrate is used

Okay, many thanks to you