MemoryError: Unable to allocate array

Hi,
I wrote a simple code for heat diffusion with Fenics

from fenics import *

t_end = 1
dt = 0.1
k = 10
u_in = 20
u_out = -20

xml_file = "01Mesh.xml"
mesh = Mesh(xml_file)
fd = MeshFunction('size_t', mesh, "01Mesh_physical_region.xml");

V = FunctionSpace(mesh, 'P', 1340)

bc1 = DirichletBC(V, Constant(u_in), fd, 1322)
bc2 = DirichletBC(V, Constant(u_out), fd, 1342)
bc = [bc1, bc2]

u = TrialFunction(V)
v = TestFunction(V)
u_n = Function(V)

F = u*v*dx + dt*k*dot(grad(u), grad(v))*dx - u_n*v*dx
a, L = lhs(F), rhs(F)

u = Function(V)
t = 0
vtkfile = File('output/output.pvd')

num_steps = int(t_end/dt)
for n in range(num_steps):
    t += dt
    solve(a == L, u, bc)
    u_n.assign(u)
    vtkfile << (u, t)

but I got the flowing error:

MemoryError: Unable to allocate array with shape (899811, 899811) and data type float64

The mesh is also very simple. Its 2D, just some cycle inside a rectangle.

Fenics Version: 2019.2.0.dev0
Os: Ubuntu 20.04
RAM: 8Gb
Swap memory: 1 Gb

I guess it is because you are trying to create a function space of order 1340

Surely this is not what you intended to do?

1 Like