I'm new to stackoverflow and fenics. I recently used the env to compute input code for another file.
I want to calculate finite elements and save the assembled matrices, say over a rectangle domain D=(-1,1)*(-2,2)
. I set the number of discretising points in direction of x
and y
, setting nx,ny=9
, i.e. 2*10*10
triangles.
when I calculate the matrices and assemble them they have the size (nx+1)*(ny+1)*(nx+1)*(ny+1)
instead of (nx+1)*(ny+1)
.
MWE:
from dolfin import *
import numpy as np
# Mesh and function space
# mesh (generates 2*nx*ny number of triangles) and function space
# number of FEM = (nx+1)*(ny+1) = 100
# matrixSize = (nx+1)*(ny+1) * (nx+1)*(ny+1) = 100*100
nx = 9
ny = 9
# mesh dims
x = [-1, 1]
y = [-2, 2]
mesh = RectangleMesh(Point(x[0], y[0]), Point(x[1], y[1]), nx, ny)
V = FunctionSpace(mesh, "CG", 1)
# Time variables
dt = Constant(0.3)
g_expr = 'alpha'
g = Expression(g_expr , alpha=0.0, degree=2)
u0 = interpolate(g, V)
# Variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Expression('-exp(-(pow(x[0], 2)+pow(x[1], 2)))', degree=2)
a = u*v*dx + dt*inner(grad(u), grad(v))*dx
L = u0*v*dx + dt*f*v*dx
bc = DirichletBC(V, g, "on_boundary")
A = assemble(a)
print(A.array())
# print the sizes of row and col space of assembled matrix A (both = 100)
print((len(A.array()), len(A.array()[0])))
I'd appreciate any help, thx!