Exporting data for Paraview, problem of coloring

Hello, I have a problem exporting my data created with Fenics to view them with Paraview. With Fenics, I solve the heat equation for different time. I stock all of my solutions in a Zip file because I want to visualize my solutions during time. The problem is, in Paraview, all of my solutions have a different code coloring, so during my simulation I only can see the first solution with color. I know I have to change something in my Fenics code, but I don’t know what. Here is my code :

from google.colab import files
from dolfin import File

x1 = [0.4,0]
x2 = [0.6,0.2]
Temp = 25

alpha = 1

tol = 0.005
pre = 50

t = 0
T = 0.1
pasos = 100

rect1 = Rectangle(Point(0,0),Point(1,1))
rect2 = Rectangle(Point(x1[0],x1[1]),Point(x2[0],x2[1]))
domain = rect1 - rect2

mesh = generate_mesh(domain, pre)
V = FunctionSpace(mesh, “P”, 1) #REVISAR

def boundary(x, on_boundary):
return on_boundary

def lados_rect1(x, on_boundary):
return on_boundary and (near(x[0],0) or near(x[0],1) or ((x1[0]>x[0] or x[0]>x2[0]) and near(x[1],x1[1])) or near(x[1],x2[1]))

def lados_rect2(x, on_boundary):
return on_boundary and (near(x[0],x1[0]) or near(x[0],x2[0]) or near(x[1],x2[1]))

def estufa(x, on_boundary):
return ((x[0]>=x1[0] and x[0]<=x2[0]) and (x[1]>=x1[1] and x[1]<=x2[1]))

zero = Constant(0.0)
bc_lads_rect1 = DirichletBC(V, zero, lados_rect1)
bc_lads_rect2 = DirichletBC(V, Constant(Temp), lados_rect2)
bc_lads_estufa = DirichletBC(V,Constant(Temp), estufa)

bcs = [bc_lads_rect1, bc_lads_rect2, bc_lads_estufa]

dt = T / pasos

u_0 = zero
u_n = interpolate(u_0, V)

u = TrialFunction(V)
v = TestFunction(V)
f = zero

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

u = Function(V, name = “u”)
puntos =
tiempo =
temp_media =
sol =

def integral_media_espacio(u,dom):
integral = assemble(u * dx)
superficie = 1- abs(x1[0]-x2[0])*abs(x1[1]-x2[1])
return integral/superficie

for n in trange(pasos):

t += dt

solve(a == L, u, bcs)

sol.append(u.copy(True))

u_n.assign(u)

from google.colab import files
from dolfin import File
!mkdir solutions

for i, solution in enumerate(sol):
filename = f"solutions/solution_{i}.pvd"
File(filename) << solution , i

!zip -r solutions.zip solutions
files.download(‘solutions.zip’)

Thanks !

First of all please encapsulate your code with 3x`, ie

```python
#add Python code here

```

Several things that should be changed here:

  1. assemble A once, as it is time-independent, see https://github.com/Simula-SSCP/SSCP_2023_lectures/blob/main/L12%20(FEniCS%20Intro)/L02_FEniCS_Diffusion.ipynb

  2. when you do the copy, solutions[i] gets a new name. You should call sol[-1].rename("u", "") after appending a solution.