- #1
Munin
- 4
- 0
Hi
Im doing a 2 dimensional heat spreading simulation.
I've created a matrix with 3 indices with the first index being for time step and the two other for element coordinates.
The simulation works fine but when I try to run an animate function over the time steps it only plots a density plot in the first time step. Is this the correct way to do an animate funtion for my density plot?
As it is now the color in the color function is relative to the highest value for the time step. Is there a way to get the colors relative to the highest value for all steps?
Im doing a 2 dimensional heat spreading simulation.
I've created a matrix with 3 indices with the first index being for time step and the two other for element coordinates.
Code:
height = 20;
width = 4;
a = 0.5;
J = Round[height/a];
L = Round[width/a];
h = 0.1;
roomT = 20;
T = 90;
t = 1000;
Dev = Normal[ConstantArray[1, {t, J, L}]];
u = T*Normal[ConstantArray[1, {J, L}]];
J*L
v = Normal[ConstantArray[0, {J*L, 1} ]];
A = Normal[ConstantArray[0, {J*L, J*L}]];
u[[All, 1]] = roomT;
u[[All, L]] = roomT;
u[[1, All]] = roomT;
u[[J, All]] = roomT;
For[j = 1, j <= J, j++,
For[l = 1, l <= L, l++,
index = (j - 1)*L + l;
v[[index, 1]] = u[[j, l]];
];
];
For[i = 1, i <= J*L, i++,
A[[i, i]] = -4;
If[i + L <= J*L, A[[i, i + L]] = 1, A[[i, i]] = A[[i, i]] + 1];
If[i - L >= 1, A[[i, i - L]] = 1, A[[i, i]] = A[[i, i]] + 1];
If[i + 1 <= J*L, A[[i, i + 1]] = 1, A[[i, i]] = A[[i, i]] + 1];
If[i - 1 >= 1, A[[i, i - 1]] = 1, A[[i, i]] = A[[i, i]] + 1];
]
A = A/a^2;
Ett = SparseArray[{i_, i_} -> 1, {J*L, J*L}];
Mtemp = Ett - h*A;
M = Inverse[Mtemp];
For[i = 1, i <= L, i++,
M[[i, All]] = 0;
M[[(J - 1)*L + i, All]] = 0;
M[[i, i]] = 1;
M[[(J - 1)*L + i, (J - 1)*L + i]] = 1;
];
For[i = 1, i <= J, i++,
M[[1 + L*(i - 1), All]] = 0;
M[[1 + L*(i - 1), 1 + L*(i - 1)]] = 1;
M[[L*i, All]] = 0;
M[[L*i, L*i]] = 1;
];
k = 1;
While[k < t + 1,
For[j = 1, j <= J, j++,
For[l = 1, l <= L, l++,
index = (j - 1)*L + l;
u[[j, l]] = v[[index, 1]];
];
];
Dev[[k, All, All]] = u;
If[u[[Round[J/2], Round[L/2]]] < 21,
Break[]
];
v = M.v;
k++;
];
t = k;
Print[t]
The simulation works fine but when I try to run an animate function over the time steps it only plots a density plot in the first time step. Is this the correct way to do an animate funtion for my density plot?
Code:
Animate[ListDensityPlot[Dev[[m, All, All]],
ColorFunction -> (RGBColor[1, 1 - #, 0] &)], {m, 1, t},
AnimationRunning -> False]
As it is now the color in the color function is relative to the highest value for the time step. Is there a way to get the colors relative to the highest value for all steps?