Modeling DAE system with discontinous solution (jump condition domain)
Show older comments
Hello,
I am trying build steady-state 1D electrodialysis model in matlab, cromprizing three sub domains, namely the analyte channel, the catholyte channel and an ion exchange membrane inbetween. I have provided the key eqations, while there are still some other minor algebraic equations.
DAE system:
(dc/dt=0)

Boundary condition: Neuman boundary conditions (also shown in the sketch)
Internal boundary condition (jump condition)
(membran solution interface continuity condition)The masstransport is modeled using the nerst plank equation for each species and the electricfield is calculated through ohms law. Additionally I use the electron neutrality condition to close the mass balance. The individuall sub domains are connetced through an internal flux continuity boundary condition.
So far i have a rough understanding of the various ode solvers but from what i understand, the ode solvers only work when the whole problem is fully defined. In my case however, I have these sub domains connected via flux continuity boundary conditions, which is why i can not solve the sub domains individually. I have to solve them all at once. Additionally the boundary continuity boundary condition at the membrane interface introduces a jump (discontinuity) to the conentration and the potential profile. (qualitatively sketched below)

I am now looking for an appropirate way to model this system. The tricky part is the continuity condition at the membrane interface.
I hope to solve this problem with bvp5c where one can define multiple boundary condition inside the domain as described in this documentation:
But I am not entirlly sure how to implement the countinuity condition.
I have figured that it is possible to have jumps in the solution but since the continuity boundary condition which i am aiming to use is more complex that what has been done in the documentation, I am not quite sure on how to implent it. I would need the derivertives at the interface, instad of simply relating the absolute values at the interface to each other. (as it is done here)

function res = bc(YL,YR) % boundary conditions
res = [YL(1,1) % v(0) = 0
YR(1,1) - YL(1,2) - 1 % Here, I introduced a jump with a constant value at x=1
YR(2,1) - YL(2,2) % Continuity of C(x) at x=1
YR(2,end) - 1]; % C(lambda) = 1
end
Does anyone have an Idea, how i can use this solver for my problem. Any alternative approaches and clues are also very welcome.
Thank you^^
Bonus:
Ideally I want to build a hirachical model where all these three domains are modeled as individual systems (ode systems) and conntect them through a continiuty condtion for the concentraiton and the donnanpotential for the electric field. Also for the purpose of reusing the individuall models for later simulations. I know that this is common practice in gPROMS but i couldnt find similar approaches to modeling using matlab. Is there a similar modeling framework in matlab? I have only seen people using the various ode solvers for modeling in matlab for fully defined ODE systems.
5 Comments
Torsten
on 23 Feb 2023
You want to solve for the steady-state profiles ?
Berat Cagan Türkmen
on 23 Feb 2023
Berat Cagan Türkmen
on 25 Feb 2023
Torsten
on 26 Feb 2023
I don't understand the background of your equations which I think would be necessary to help.
What variables are known, what are unknown ?
How are ϕ and φ related ?
Is c related to the C_i ?
Berat Cagan Türkmen
on 26 Feb 2023
Answers (1)
Berat Cagan Türkmen
on 26 Feb 2023
Edited: Berat Cagan Türkmen
on 26 Feb 2023
0 votes
20 Comments
By inserting
dphi/dx = (I/F + sum_j [z_j*D_j/(R*T)]/(-F/(R*T) * sum_j [z_j^2*D_j*c_j])
into the equation
0 = -grad(D_i*dc_i/dx + z_i*D_i/(R*T)*c_i*dphi/dx) (i=1,...,N-1)
you get (N-1) second-order differential equations only in the c_i - thus phi is eliminated.
Also the two necessary transmission conditions at the interfaces can be written only in terms of the c_i and the dc_i/dx.
One is the relation between the fluxes, another will concern the concentrations on both sides, I guess.
So it should be no problem to use bvp4c or bvp5c as a boundary value problem with internal boundary conditions, shouldn't it ?
But this is only an ad hoc suggestion for a solution. There should be advices in the literature on how this well-studied problem can be solved stably and efficiently.
Berat Cagan Türkmen
on 27 Feb 2023
Torsten
on 27 Feb 2023
You have a second-order ODE, so you will have to write one equation for c_i and a second one for dc_i/dx in order to use bvp4c/bvp5c.
This is done as
dy(1) = y(2)
dy(2) = your equation for c_i solved for d^2c_i/dx^2.
Thus YL(1) = c_i from left, YR(1) = c_i from right, YL(2) = dc_i/dx from left, YR(2) = dc_i/dx from right.
Berat Cagan Türkmen
on 27 Feb 2023
Berat Cagan Türkmen
on 3 Mar 2023
Torsten
on 4 Mar 2023
You try to solve N first-order equations. Thus at each internal boundary, bvp4c/bvp5c expects N transmission conditions. Further you have to set a total of N conditions at the outer boundaries. Thus you have to derive a total of 3*N transmission/boundary conditions.
This is a mathematical fact - you won't be able to circumvent this if you start writing your own code. And bvp4c/bvp5c will try to handle these conditions if they make sense.
But in order to be able to solve for phi and not only dphi/dx, you will have to fix phi somewhere. Do you intend to set phi at one or both outer boundaries ?
Berat Cagan Türkmen
on 4 Mar 2023
Torsten
on 4 Mar 2023
Why do you have an algebraic equation ? You have a differential equation for phi:
dphi/dx = ....
Berat Cagan Türkmen
on 4 Mar 2023
But you can solve this equation for c_N - you don't need a solver for this ?!
c_N = -1/z_N * sum_{i=1}^{i=N-1} z_i*c_i
Berat Cagan Türkmen
on 4 Mar 2023
Edited: Berat Cagan Türkmen
on 4 Mar 2023
Torsten
on 4 Mar 2023
I acutally need the concentration of c_N because it is part of the dphi/dx equation right?
or do you mean i should just insert into the your equation into the ode maually?
I don't understand what you mean. If you need c_N and you solve for c_1,...,c_(N-1), you can deduce c_N using the above formula. Same for dc_N/dx.
Berat Cagan Türkmen
on 4 Mar 2023
For some reason i though, bvp5c can not handle algebraic equaitons and all the functions i provide have to be frist order odes. But that is acutally not the case. thank you for the hint.
bvp5c cannot solve algebraic equations, but as long as you can derive their solutions "manually", your system can also contain algebraic equations.
I tried to reduce the system into first order ode's but i get 4 equations. That means i get N+1 instead of N. Did i do something wrong?
I don't know why you need 4 equations. You need one for c_i, one for dc_i/dx and one for phi. To get d^2phi/dx^2 which has to be inserted in the first equation, differentiate the expression for dphi/dx for x.
As discussed before, in principle you only need 2 equations because dphi/dx and d^2phi/dx^2 can be expressed in terms of c_i, dc_i/dx and d^2c_i/dx^2 alone. But as you noted, you want to set conditions for phi at the outer boundaries.
Berat Cagan Türkmen
on 4 Mar 2023
The index in the sums must be j, not i.
As far as I can see, you get (N-1) such equations which are linear in the unknows d^2c_i/dx^2 (i=1,...,N-1).
So a linear system of equations in the unknowns d^2c_1/dx^2, d^2c_2/dx^2,...,d^2c_(N-1)/dx^2. Easily solved using backslash.
But as I said previously: a literature research about the usual solution methods for this kind of physical system should be made in order to avoid meanders. I can only tell you what is possible - if it is efficient and constructive: I don't know.
What is the COMSOL system being solved ?
Berat Cagan Türkmen
on 5 Mar 2023
Edited: Berat Cagan Türkmen
on 5 Mar 2023
Torsten
on 5 Mar 2023
but even if i did so. i still have which bvp5c wont accept because it would not be an first order ode.
d^2c_2/dx^2 = -z1/z2 * d^2c_1/dx^2
by the relation
z1*c_1 + z2*c_2 = 0
And then you solve the equation for d^2c_1/dx^2, substitute y(1) = c_1, y(2) = dc_1/dx as usual. What's the problem ?
The index in the sums must be j, not i.
I can understand why this should be the case the dc^2/dx i am inserting should be the same as the dc^2/dx which is allready in the equation.
i is the index of the equation being solved (namely for c_i), j is the summation index over all c_j coming from substituting the expression for dphi/dx.
in litterature i could find people solving almost the same system with pdepe but they did not have internal boudnaries as i have them. they only calulated the flow over the membrane. but i also want to include the solution phase. but yeah, other than that the differential eqation system is the same.
At the moment, we do not discuss about the internal boundaries, but about how to set up the system to be solved (which solution variables are to be used; should there be an extra equation for phi or should phi be completely substituted by the c_i). I think if you find the way of solving the "usual" equations in the literature (without extra difficulties) would already be of great help.
Berat Cagan Türkmen
on 5 Mar 2023
d^2c_2/dx^2 = -z1/z2 * d^2c_1/dx^2
by the relation
z1*c_1 + z2*c_2 = 0
And then you solve the equation for d^2c_1/dx^2, substitute y(1) = c_1, y(2) = dc_1/dx as usual. What's the problem ?
this works for 2 species, you are right. but i have more then 2 species i cant do that.
Write down the system for N species. If you arrange the equations with regard to d^2c_i/dx^2 (i=1,...,N-1) and substitute d^2c_N/dx^2 as you substituted d^2c_2/dx^2 above, you get a linear system of equations of the form
a11*d^2c_1/dx^2 + a12*d^2c_2/dx^2 + ... + a1,N-1*d^2c_(N-1)/dx^2 = b_1
a21*d^2c_1/dx^2 + a22*d^2c_2/dx^2 + ... + a2,N-1*d^2c_(N-1)/dx^2 = b_2
...
aN-1,1*d^2c_1/dx^2 + aN-1,2*d^2c_2/dx^2 + ... + aN-1,N-1*d^2c_(N-1)/dx^2 = b_N-1
Here, a_ij and bi depend on c_i and dc_i/dx.
This system can be solved for the d^2c_i/dx^2 using backslash, as I already told you in a previous response.
The problem i see however, is that the bvp5c model forces me to form first order odes. but if i could code a finite difference method based solver, shouldnt i be able to manually discritize me second order and the dphi/dx equation?
Where do you see a problem in writing second-order derivatives as two first-order derivatives ?
In my experience, self-written numerical code (e.g. to solve a multipoint boundary value problem) should only come into play if the available solvers are not applicable. I don't see that this is the case here.
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






















