- #1
robby991
- 41
- 1
Hi, I am looking to model the diffusion of a particle through 2 layers using the finite difference method in matlab. I already successfully have modeled this in a mono-layer configuration, however I am looking to code it through two layers.
I have two layers, one is 1 micron (1E-6) and the other is 10 nanometers (10E-9), for a total of 1.01E-6.
I am going to set this up in one mesh that has a total length of 1.01E-6 (for simplicity I will exclude boundary conditions because I know how to implement those). So I will first set up a matrix of all zeros with those dimensions.
The spacing between nodes is defined as:
For the region of the first layer, the diffusion I previously described as a normal second order diffusion represented in the central difference scheme ("j" is the time domain and "i" space domain):
For the interface of layer k and k+1, the spatial derivative gives:
I am unsure how to code this in for loops because I need to transistion diffusion equations after 1E-6, and I don't know exactly how many space steps (dx) this corresponds to. For example, the first for loop for the first diffusion equation for the first layer will be, where the question mark is the point at the interface, then the interface diffusion equation above will be implemented:
I can calculate it by hand but I know there is a way to do it by programming. Is this the correct approach to do it all in one mesh? Any help on this would be greatly appreciated. Thank you!
I have two layers, one is 1 micron (1E-6) and the other is 10 nanometers (10E-9), for a total of 1.01E-6.
I am going to set this up in one mesh that has a total length of 1.01E-6 (for simplicity I will exclude boundary conditions because I know how to implement those). So I will first set up a matrix of all zeros with those dimensions.
The spacing between nodes is defined as:
Code:
x = linspace(0,Length,numx);
S = zeros(numt,numx);
dx = S(2)-S(1);
For the region of the first layer, the diffusion I previously described as a normal second order diffusion represented in the central difference scheme ("j" is the time domain and "i" space domain):
Code:
for j=1:numt-1
for i=2:numx-1
S(j+1,i) = S(j,i) + (dts/dxs^2)*Ds*(S(j,i+1) - 2*S(j,i) + S(j,i-1))
end
S(j+1,1)=S(j,1)+dts*Ds*2*(S(j,2)-S(j,1))./dxs.^2-((Vmax*dts*S(j,i))/(Km+S(j,i))); %Neumann Boundary Condition
end
For the interface of layer k and k+1, the spatial derivative gives:
Code:
dP/dt = [Dk+1*Pk+1 - (Dk+1 + Dk)Pj + Dk*Uk-1]/dx^2
I am unsure how to code this in for loops because I need to transistion diffusion equations after 1E-6, and I don't know exactly how many space steps (dx) this corresponds to. For example, the first for loop for the first diffusion equation for the first layer will be, where the question mark is the point at the interface, then the interface diffusion equation above will be implemented:
Code:
for i=2:[B]?[/B]
S(j+1,i) = S(j,i) + (dts/dxs^2)*Ds*(S(j,i+1) - 2*S(j,i) + S(j,i-1))
end
I can calculate it by hand but I know there is a way to do it by programming. Is this the correct approach to do it all in one mesh? Any help on this would be greatly appreciated. Thank you!