2

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 xand 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!

szolo9
  • 21
  • 2
  • Ah, I committed a fallacy in reasoning. The code above is correct and giving the correct results. The FE that are generated are of course `100`, that's right. But in order to compute the Matrix I have now vectors of length `100` to multiply with each other, which results in a Matrix of `100 *100` – szolo9 Apr 15 '21 at 08:58

0 Answers0