15 views (last 30 days)

Dear All,

I am trying to model a coupled Ion Exchange - Electrodialysis model. This is similar to the adsorption model. The extra term in this model is that of transport of ions due to the electric field. The first snapshot I have attached shows the original model. The second snapshot shows the rearranged form of the model to match the adsorption model (without axial dispersion). In this second snapshot you can see the extra term containing 'phi', the potential gradient.

In the adsorption model, the 2 independent variables are time and one direction. The 2 dependent variables are bulk concentration and solid phase concentration. In this model, the 3 independent variables are time and 2 directions. 1 direction (x) is the direction the ions move under the influence of the electric field. The second direction (z) is the direction that the bulk fluid moves in. The 3 dependent variables are the bulk concentration, solid phase concentration and the electric potential.

The sample code for the adsorption model is given below (Taken from https://uk.mathworks.com/matlabcentral/answers/385756-adsorption-modelling-solving-pde-axial-dispersion-model. Coded by Ashley Gratton, Torsten). Please let me know how I can change this for my model which has 3 independent and 3 dependent variables.

Thank you in advance.

function main

% Initialisation

close all

clear all

clc

%System Set-up %

%Define Variables

D = 3*10^-8; % Axial Dispersion coefficient

v = 1*10^-3; % Superficial velocity

epsilon = 0.4; % Voidage fraction

k = 3*10^-5; % Mass Transfer Coefficient

b = 2.5*10^-5; % Langmuir parameter

qs = 2*10^4; % Saturation capacity

cFeed = 10; % Feed concentration

L = 1; % Column length

t0 = 0; % Initial Time

tf = 1000; % Final time

dt = 0.5; % Time step

z = [0:0.01:L]; % Mesh generation

t = [t0:dt:tf];% Time vector

n = numel(z); % Size of mesh grid

%Initial Conditions / Vector Creation

c0 = zeros(n,1);

c0(1) = cFeed;

q0 = zeros(n,1); % t = 0, q = 0 for all z, this makes sense to me

y0 = [c0 ; q0]; % Appends conditions together

%ODE15S Solver

[T, Y] = ode15s(@(t,y) MyFun(t,y,z,n),t,y0);

function DyDt=MyFun(~, y, z, n)

% Defining Constants

D = 3*10^-8; % Axial Dispersion coefficient

v = 1*10^-3; % Superficial velocity

epsilon = 0.4; % Voidage fraction

k = 3*10^-5; % Mass Transfer Coefficient

b = 2.5*10^-5; % Langmuir parameter

qs = 20000; % Saturation capacity

% Variables being allocated zero vectors

c = zeros(n,1);

q = zeros(n,1);

DcDt = zeros(n,1);

DqDt = zeros(n,1);

DyDt = zeros(2*n,1);

zhalf = zeros(n-1,1);

DcDz = zeros(n,1);

D2cDz2 = zeros(n,1);

c = y(1:n);

q = y(n+1:2*n);

% Interior mesh points

zhalf(1:n-1)=(z(1:n-1)+z(2:n))/2;

for i=2:n-1

DcDz(i) = ((z(i)-z(i-1))/(z(i+1)-z(i))*(c(i+1)-c(i))+(z(i+1)-z(i))/(z(i)-z(i-1))*(c(i)-c(i-1)))/(z(i+1)-z(i-1));

D2cDz2(i) = (zhalf(i)*(c(i+1)-c(i))/(z(i+1)-z(i))-zhalf(i-1)*(c(i)-c(i-1))/(z(i)-z(i-1)))/(zhalf(i)-zhalf(i-1));

end

% Calculate DcDz and D2cDz2 at z=L for boundary condition dc/dz = 0

DcDz(n) = 0;

D2cDz2(n) = -1.0/(z(n)-zhalf(n-1))*(c(n)-c(n-1))/(z(n)-z(n-1));

% Set time derivatives at z=0

% DcDt = 0 since c=cFeed remains constant over time and is already set as initial condition

% Standard setting for q

DqDt(1) = k*( ((qs*b*c(1))/(1 + b*c(1))) - q(1) );

DcDt(1) = 0.0;

% Set time derivatives in remaining points

for i=2:n

%Equation: dq/dt = k(q*-q) where q* = qs * (b*c)/(1+b*c)

DqDt(i) = k*( ((qs*b*c(i))/(1 + b*c(i))) - q(i) );

%Equation: dc/dt = D * d2c/dz2 - v*dc/dz - ((1-e)/(e))*dq/dt

DcDt(i) = D*D2cDz2(i) - v*DcDz(i) - ((1-epsilon)/(epsilon))*DqDt(i);

end

% Concatenate vector of time derivatives

DyDt = [DcDt;DqDt];

end

hbulusoy
on 17 Sep 2019

Opportunities for recent engineering grads.

Apply Today
## 34 Comments

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_722898

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_722898

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723021

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723021

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723030

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723030

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723037

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723037

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723040

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723040

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723049

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723049

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723053

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723053

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723059

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723059

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723065

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723065

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723073

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723073

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723079

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723079

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723135

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723135

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723153

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723153

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723165

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723165

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723170

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723170

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723182

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723182

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723200

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723200

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723261

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723261

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723402

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723402

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723448

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723448

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723456

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723456

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723462

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723462

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723463

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723463

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723483

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723483

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723494

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723494

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723507

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723507

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723520

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723520

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723525

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723525

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723534

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723534

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723548

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723548

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723553

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723553

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723561

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723561

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723605

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_723605

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_724092

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/470857-coupled-ion-exchange-electrodialysis-model-using-partial-differential-equations#comment_724092

Sign in to comment.