# Exporting data for Paraview, problem of coloring

**URL:** <https://fenicsproject.discourse.group/t/exporting-data-for-paraview-problem-of-coloring/11707>\
**Category:** General\
**Created:** [July 10, 2023, 9:39pm UTC](https://fenicsproject.discourse.group/t/exporting-data-for-paraview-problem-of-coloring/11707 "2023-07-10T21:39:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zilazila](https://avatars.discourse-cdn.com/v4/letter/z/76d3ee/32.png) [@zilazila](https://fenicsproject.discourse.group/u/zilazila)\
**Post date:** [July 10, 2023, 9:39pm UTC](https://fenicsproject.discourse.group/t/exporting-data-for-paraview-problem-of-coloring/11707/1 "2023-07-10T21:39:53Z")

</div>

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 = u_v_dx + dt\*dot(grad(u), grad(v))_dx - (u\_n + dt_f)_v_dx  
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 !

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [July 11, 2023, 5:01am UTC](https://fenicsproject.discourse.group/t/exporting-data-for-paraview-problem-of-coloring/11707/2 "2023-07-11T05:01:20Z")

</div>

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

````python
```python
#add Python code here

```

````

> [@zilazila](#):
>
> ```auto
> solve(a == L, u, bcs)
> 
> sol.append(u.copy(True))
> 
> ```

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](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.
