Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Coupled Boundary Conditions

Subject: Coupled Boundary Conditions

From: Baha

Date: 8 Jul, 2013 11:19:10

Message: 1 of 11

Hi all,
I have 4-PDEs and I have coupled Neumann boundary conditions such as:
@x=d -> D(u1)/Dx = 1/c1*(c2*u4 - c3*u1*(c4 - u4));
@y=0 -> D(u1)/Dy =-1/c1*(c2*u4 - c3*u1*(c4 - u4));
main variables: u1,u2,u3,u4
constants: c1,c2,...

Anybody knows how to implement these boundary conditions? I appreciate...

Subject: Coupled Boundary Conditions

From: Torsten

Date: 8 Jul, 2013 12:09:10

Message: 2 of 11

"Baha " <ibaha411@gmail.com> wrote in message <kre77d$e53$1@newscl01ah.mathworks.com>...
> Hi all,
> I have 4-PDEs and I have coupled Neumann boundary conditions such as:
> @x=d -> D(u1)/Dx = 1/c1*(c2*u4 - c3*u1*(c4 - u4));
> @y=0 -> D(u1)/Dy =-1/c1*(c2*u4 - c3*u1*(c4 - u4));
> main variables: u1,u2,u3,u4
> constants: c1,c2,...
>
> Anybody knows how to implement these boundary conditions? I appreciate...

Do you intend to use a certain software with restrictions on the possible boundary conditions ?
Otherwise, use
@x=d: D(u1)/dx ~ (u1(n+1,j)-u1(n,j))/deltax =
1/c1*(c2*u4(n+1,j)-c3*u1(n+1,j)*(c4-u4(n+1,j)))
and
@y=0: D(u1)/dy ~ (u1(i,1)-u1(i,0))/deltay =
-1/c1*(c2*u4(i,0)-c3_u1(i,0)*(c4-u4(i,0))).
where indices (n+1,j) and (i,0) refer to boundary points.

Best wishes
Torsten.

Subject: Coupled Boundary Conditions

From: Baha

Date: 8 Jul, 2013 17:48:11

Message: 3 of 11

> Do you intend to use a certain software with restrictions on the possible boundary conditions ?
> Otherwise, use
> @x=d: D(u1)/dx ~ (u1(n+1,j)-u1(n,j))/deltax =
> 1/c1*(c2*u4(n+1,j)-c3*u1(n+1,j)*(c4-u4(n+1,j)))
> and
> @y=0: D(u1)/dy ~ (u1(i,1)-u1(i,0))/deltay =
> -1/c1*(c2*u4(i,0)-c3_u1(i,0)*(c4-u4(i,0))).
> where indices (n+1,j) and (i,0) refer to boundary points.
>
> Best wishes
> Torsten.

Thank you for your email Torsten. Is there any way that I can put these equations in pdetool? I already defined the problem in pdetool without coupling in BCs, but I am now trying to add these coupled conditions.

Subject: Coupled Boundary Conditions

From: Torsten

Date: 9 Jul, 2013 08:19:11

Message: 4 of 11

"Baha " <ibaha411@gmail.com> wrote in message <kreu0r$h2j$1@newscl01ah.mathworks.com>...
> > Do you intend to use a certain software with restrictions on the possible boundary conditions ?
> > Otherwise, use
> > @x=d: D(u1)/dx ~ (u1(n+1,j)-u1(n,j))/deltax =
> > 1/c1*(c2*u4(n+1,j)-c3*u1(n+1,j)*(c4-u4(n+1,j)))
> > and
> > @y=0: D(u1)/dy ~ (u1(i,1)-u1(i,0))/deltay =
> > -1/c1*(c2*u4(i,0)-c3_u1(i,0)*(c4-u4(i,0))).
> > where indices (n+1,j) and (i,0) refer to boundary points.
> >
> > Best wishes
> > Torsten.
>
> Thank you for your email Torsten. Is there any way that I can put these equations in pdetool? I already defined the problem in pdetool without coupling in BCs, but I am now trying to add these coupled conditions.

Sorry, but I have no experience with the PDE-toolbox.

Best wishes
Torsten.

Subject: Coupled Boundary Conditions

From: Baha

Date: 9 Jul, 2013 22:39:17

Message: 5 of 11

> > > @x=d: D(u1)/dx ~ (u1(n+1,j)-u1(n,j))/deltax =
> > > 1/c1*(c2*u4(n+1,j)-c3*u1(n+1,j)*(c4-u4(n+1,j)))
> > > and
> > > @y=0: D(u1)/dy ~ (u1(i,1)-u1(i,0))/deltay =
> > > -1/c1*(c2*u4(i,0)-c3_u1(i,0)*(c4-u4(i,0))).
> > > where indices (n+1,j) and (i,0) refer to boundary points.

That's alright. I think this problem is either unsolvable or there is something wrong with it...

It is a little bit confusing because Dirichlet BCs are given only for one edge of the rectangle and Neumann BCs are given for other 3-edges. That means I don't know the value of u1(@x=d) and u4(@x=d) so I guess I can't directly calculate this term you gave:
@x=d: D(u1)/dx ~ (u1(n+1,j)-u1(n,j))/deltax =
1/c1*(c2*u4(n+1,j)-c3*u1(n+1,j)*(c4-u4(n+1,j)))

Original problem I posted a couple of days back is here (I got no reply for this question): http://www.mathworks.com/matlabcentral/newsreader/view_thread/330397

Thanks,
B.

Subject: Coupled Boundary Conditions

From: Nasser M. Abbasi

Date: 9 Jul, 2013 23:08:26

Message: 6 of 11

On 7/9/2013 5:39 PM, Baha wrote:
>>>> @x=d: D(u1)/dx ~ (u1(n+1,j)-u1(n,j))/deltax =
>>>> 1/c1*(c2*u4(n+1,j)-c3*u1(n+1,j)*(c4-u4(n+1,j)))
>>>> and
>>>> @y=0: D(u1)/dy ~ (u1(i,1)-u1(i,0))/deltay =
>>>> -1/c1*(c2*u4(i,0)-c3_u1(i,0)*(c4-u4(i,0))).
>>>> where indices (n+1,j) and (i,0) refer to boundary points.
>
> That's alright. I think this problem is either unsolvable or there is something wrong with it...
>
> It is a little bit confusing because Dirichlet BCs are given only for one edge
>of the rectangle and Neumann BCs are given for other 3-edges. That means I don't
>know the value of u1(@x=d) and u4(@x=d) so I guess I can't directly calculate
>this term you gave:
> @x=d: D(u1)/dx ~ (u1(n+1,j)-u1(n,j))/deltax =
> 1/c1*(c2*u4(n+1,j)-c3*u1(n+1,j)*(c4-u4(n+1,j)))
>

I have not followed this discussion. But for Neumann BC, you can
use the ghost point method to obtain an expression for the
unknown at the edge. (if this is what I understand you are
asking about above).

--Nasser

Subject: Coupled Boundary Conditions

From: Baha

Date: 10 Jul, 2013 00:10:11

Message: 7 of 11

Thnx for your reply Nasser,
I am not expert on PDEs but this problems gets harder than I expected. I am trying to use matlab's pde toolbox, rather than writing a numerical algorithm of finite element or central difference, this would be too much to go into. You can check the entire problem from the link: http://www.mathworks.com/matlabcentral/newsreader/view_thread/330397

Subject: Coupled Boundary Conditions

From: Nasser M. Abbasi

Date: 10 Jul, 2013 02:39:55

Message: 8 of 11

On 7/9/2013 7:10 PM, Baha wrote:
> Thnx for your reply Nasser,
> I am not expert on PDEs but this problems gets harder than I expected.
>I am trying to use matlab's pde toolbox, rather than writing a numerical algorithm
>of finite element or central difference, this would be too much to go into.
>You can check the entire problem from the link:
>http://www.mathworks.com/matlabcentral/newsreader/view_thread/330397
>

When I used pde toolbox myself to verify some answers for my
hand written code, I only used the GUI version of the pde toolbox,
not the callable API version.

With the GUI version, all what I had to do is to select the
pde type, set the parameter of the pde valuaes, and using
the GUI set the boundary conditions. I do not think I did one
with initial conditions, I do not remember now.

pde toolbox GUI supports mixed BC also
http://www.mathworks.com/help/pde/ug/pdetool.html

Sorry can't help you more on this at this time.
good luck;

--Nasser
  

Subject: Coupled Boundary Conditions

From: Baha

Date: 10 Jul, 2013 05:01:10

Message: 9 of 11

Thank you Naseer. I hope I can figure it out soon.

If the problem was 1D, I could use "pdepe" command to solve it easily (I solved the 1D version of the problem with pdepe), but pdepe is only for 1D problems. For 2D problem it is really complicated and I couldn't find a good example for 2D problem with 3-4 variables and coupling in variables. It may not be possible to solve it with GUI.

Subject: Coupled Boundary Conditions

From: Bill Greene

Date: 10 Jul, 2013 12:52:10

Message: 10 of 11

"Baha " <ibaha411@gmail.com> wrote in message <kripqm$cne$1@newscl01ah.mathworks.com>...
> Thank you Naseer. I hope I can figure it out soon.
>
> If the problem was 1D, I could use "pdepe" command to solve it easily (I solved the 1D version of the problem with pdepe), but pdepe is only for 1D problems. For 2D problem it is really complicated and I couldn't find a good example for 2D problem with 3-4 variables and coupling in variables. It may not be possible to solve it with GUI.

Hi,

I think the most straightforward way to define these boundary conditions in PDE
Toolbox is to write a MATLAB function that is called by PDE Toolbox. This is referred to
as a "boundary file" in the PDE Toolbox documentation:
http://www.mathworks.com/help/pde/ug/boundary-conditions-for-pde-systems.html

You will need to write your generalized Neumann boundary conditions in the form
required by PDE Toolbox and then define the q-matrix on the two edges in your
boundary file function.

An example of such a function for a single PDE is here:

http://www.mathworks.com/help/pde/examples/heat-distribution-in-radioactive-rod.html

An example defining Dirichlet conditions for a system of three PDEs is here

http://www.mathworks.com/help/pde/examples/deflection-of-a-piezoelectric-actuator.html

Bill

Subject: Coupled Boundary Conditions

From: Baha

Date: 10 Jul, 2013 17:10:29

Message: 11 of 11

Thank you for your reply Bill. Last night I was actually doing same thing "literally" manually. I will check these links but let me share what I did and perhaps there is someone who can understand and find my mistake since it is giving a size mismatch error for matrix multiplication. Please lemme know if anyone can find the mistake. Here it is:

%%%
domain = [0 0; 1 0; 1 1; 0 1];
gd = [2; size(domain,1); domain(:,1); domain(:,2)];
gl = decsg(gd);
time =2;
c1=1; c2=1; c3=1; c4=1; c5=1; c6=1; c7=1; % coefficients
xd_1 = sprintf('1/%g*(%g*u(4,:)-%g*u(1,:).*(%g-u(4,:)))',c1,c2,c3,c4);
xd_2 = '0';
xd_3 = '0';
xd_4 = '0';
%
y0_1 = sprintf('-1/%g*(%g*u(4,:)-%g*u(1,:).*(%g-u(4,:)))',c1,c2,c3,c4);
y0_2 = '0';
y0_3 = '0';
y0_4 = '0';
y0_cell = {y0_1, y0_2, y0_3, y0_4};
y0 = char(y0_cell);
%
x0_1 = '0';
x0_2 = '0';
x0_3 = '0';
x0_4 = '0';
%
u_1 = sprintf('%g*exp(-%g)',c5,time); % yh_1
% u2 = '1/2*(sqrt(c5^2*exp(-2*t)+4*c6)-c5*exp(-t))'; % yh_2
u_2 = sprintf('1/2*(sqrt(%g^2*exp(-2*%g)+4*%g)-%g*exp(-%g))',c5,time,c6,c5,time);
u_3 = sprintf('1/2*(sqrt(%g^2*exp(-2*%g)+4*%g)+%g*exp(-%g))',c5,time,c6,c5,time);
u_4 = '0';
%%
clear b
b(1,:) = [4 4 4 4]; % first row Edges
b(2,:) = [4 4 4 0]; % add second row, Dirichlet and Neumann indicator
b(3:18,:) = repmat(ones(1,4),16,1); % q
b(19:22,:) = [length(y0_1) length(xd_1) 1 length(x0_1);... %g1
              length(y0_2) length(xd_2) 1 length(x0_2);... %g2
              length(y0_3) length(xd_3) 1 length(x0_3);... %g3
              length(y0_4) length(xd_4) 1 length(x0_4)]; %g4
b = [b; double(y0_1)' [double(xd_1)';1] double(ones(length(y0_1),1)) double(x0_1*zeros(length(y0_1),1));...
        double(y0_2) double(xd_2) double(1) double(x0_2);... %g2
        double(y0_3) double(xd_3) double(1) double(x0_3);... %g3
        double(y0_4) double(xd_4) double(1) double(x0_4)]; %g4
% h:
b =[b; double('1')*ones(1,4); double('0')*ones(1,4);...
       double('0')*ones(1,4); double('0')*ones(1,4)];
b =[b; double('0')*ones(1,4); double('1')*ones(1,4);...
       double('0')*ones(1,4); double('0')*ones(1,4)];
b =[b; double('0')*ones(1,4); double('0')*ones(1,4);...
       double('1')*ones(1,4); double('0')*ones(1,4)];
b =[b; double('0')*ones(1,4); double('0')*ones(1,4);...
       double('0')*ones(1,4); double('1')*ones(1,4)];
% r:
b = [b; double(1)*ones(length(u_1),1) double(1)*ones(length(u_1),1) double(u_1)' double(1)*ones(length(u_1),1);...
        double(1)*ones(length(u_2),1) double(1)*ones(length(u_2),1) double(u_2)' double(1)*ones(length(u_2),1);...
        double(1)*ones(length(u_3),1) double(1)*ones(length(u_3),1) double(u_3)' double(1)*ones(length(u_3),1);...
        double(1)*ones(1 ,1) double(1)*ones(1 ,1) double(u_4)' double(1)*ones(1, 1)];
%%
[p,e,t] = initmesh(gl);
[p,e,t] = refinemesh(gl, p,e,t);
%%
c = diag([1 1 1 1]);
a = diag([0 0 0 0]);
fCell = {'0', '0', '0', sprintf('%g*u(1,:).*(%g-u(4,:))-%g*u(4,:)',c3,c4,c2)};
f=char(fCell);
u=pdenonlin(b, p, e, t, c, a, f, 'U0', .001);
%%%%%%%%%%%%%%%%%

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us