- Thank you received: 0
Creating mass matrices for FEM
4 years 2 weeks ago #3282
by bakerk
Creating mass matrices for FEM was created by bakerk
Hi
I am trying to define some matrices for my FEM and I think I am misunderstanding how to use some of the ngsolve functions.
The listing below defines my geometry and the objects for FEM, then below I define the usual mass and stiffness matrices with entries like u*v and grad(u)*grad(v), and these work fine. My issue is defining this matrix b which will have entries like grad(u)*v. With the code I have below I get an error, so how should I be defining this?
#generate mesh and finite element materials
geo = SplineGeometry()
geo.AddRectangle( (-D, -D), (D, D), bcs = ("bottom", "right", "top", "left"))
mesh = Mesh( geo.GenerateMesh(maxh=msize))
fes = H1(mesh, order=1, dirichlet="bottom|right|left|top")
u = fes.TrialFunction()
v = fes.TestFunction()
#generate stiffness and mass matrices
a=BilinearForm(fes)
a+=SymbolicBFI(grad(u)*grad(v))
a.Assemble()
m=BilinearForm(fes)
m+=SymbolicBFI(u*v)
m.Assemble()
b=BilinearForm(fes)
b+=SymbolicBFI(grad(u)*v)
b.Assemble()
Thanks for any help
I am trying to define some matrices for my FEM and I think I am misunderstanding how to use some of the ngsolve functions.
The listing below defines my geometry and the objects for FEM, then below I define the usual mass and stiffness matrices with entries like u*v and grad(u)*grad(v), and these work fine. My issue is defining this matrix b which will have entries like grad(u)*v. With the code I have below I get an error, so how should I be defining this?
#generate mesh and finite element materials
geo = SplineGeometry()
geo.AddRectangle( (-D, -D), (D, D), bcs = ("bottom", "right", "top", "left"))
mesh = Mesh( geo.GenerateMesh(maxh=msize))
fes = H1(mesh, order=1, dirichlet="bottom|right|left|top")
u = fes.TrialFunction()
v = fes.TestFunction()
#generate stiffness and mass matrices
a=BilinearForm(fes)
a+=SymbolicBFI(grad(u)*grad(v))
a.Assemble()
m=BilinearForm(fes)
m+=SymbolicBFI(u*v)
m.Assemble()
b=BilinearForm(fes)
b+=SymbolicBFI(grad(u)*v)
b.Assemble()
Thanks for any help
4 years 2 weeks ago #3286
by hvwahl
Replied by hvwahl on topic Creating mass matrices for FEM
Hello bakerk,
the result of the weak form needs to be scalar, such as [tex]m(u,v) = \int u v dx[/tex] or [tex]a(u, v) = \int \nabla u \cdot \nabla v dx[/tex] when u and v are from a scalar space.
In your b-term you are multiplying a vector grad(u) with a scalar v. The result is therefore a vector which does not make sense in this setting. You should have another look at where the form for b came from to get the correct scalar weak form.
Besh wishes,
Henry
the result of the weak form needs to be scalar, such as [tex]m(u,v) = \int u v dx[/tex] or [tex]a(u, v) = \int \nabla u \cdot \nabla v dx[/tex] when u and v are from a scalar space.
In your b-term you are multiplying a vector grad(u) with a scalar v. The result is therefore a vector which does not make sense in this setting. You should have another look at where the form for b came from to get the correct scalar weak form.
Besh wishes,
Henry
Time to create page: 0.097 seconds