Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

how to relate two variables?

Please login with a confirmed email address before reporting spam

Hi guys,

I have a quick question. I'm using the transport of diluted species module, and I have two species in my solution (c1 and c2). I want COMSOL to know that c1*c2=1e-8[unit] at all times during the calculation. How should I do this? I already set the initial value for both is 1e-4[unit].

I tried to put such relationship in local variables (i.e. c2=1e-8/c1, with units), but I kept getting error message "duplicate variable name"

I've attached a simple case with such problems.

Any help is greatly appreciated.


18 Replies Last Post Jul 7, 2012, 8:46 a.m. EDT
Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 13, 2011, 4:30 p.m. EDT
Hi

comsols equation analyser expects the equation to be written as my_expression =0, sou you should start to rewrite xour equation in that way i.e. c1*c2-1E-8 = 0, and not normalise to "1"

Check the doc for global equations

--
Good luck
Ivar
Hi comsols equation analyser expects the equation to be written as my_expression =0, sou you should start to rewrite xour equation in that way i.e. c1*c2-1E-8 = 0, and not normalise to "1" Check the doc for global equations -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 17, 2011, 11:04 a.m. EDT

Hi

comsols equation analyser expects the equation to be written as my_expression =0, sou you should start to rewrite xour equation in that way i.e. c1*c2-1E-8 = 0, and not normalise to "1"

Check the doc for global equations

--
Good luck
Ivar


Thanks Ivar,

I tried adding this to the global equation under ODE and DAE: c1*c2-1e-8, at the blank that says f(u,ut,utt,t). I tried both with unit or without, and both with initial contions at the following blanks or leaving the initial conditions emipy. But no matter what I try, it always gave me this error message:

Failed to evaluate variable.
- Variable: mod1.c1
- Global scope
Failed to evaluate expression.
- Expression: mod1.c1

I'm attaching the test file so you can see. Your help is greatly appreciated!
[QUOTE] Hi comsols equation analyser expects the equation to be written as my_expression =0, sou you should start to rewrite xour equation in that way i.e. c1*c2-1E-8 = 0, and not normalise to "1" Check the doc for global equations -- Good luck Ivar [/QUOTE] Thanks Ivar, I tried adding this to the global equation under ODE and DAE: c1*c2-1e-8, at the blank that says f(u,ut,utt,t). I tried both with unit or without, and both with initial contions at the following blanks or leaving the initial conditions emipy. But no matter what I try, it always gave me this error message: Failed to evaluate variable. - Variable: mod1.c1 - Global scope Failed to evaluate expression. - Expression: mod1.c1 I'm attaching the test file so you can see. Your help is greatly appreciated!


Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 23, 2011, 2:02 p.m. EDT


Hi

comsols equation analyser expects the equation to be written as my_expression =0, sou you should start to rewrite xour equation in that way i.e. c1*c2-1E-8 = 0, and not normalise to "1"

Check the doc for global equations

--
Good luck
Ivar


Thanks Ivar,

I tried adding this to the global equation under ODE and DAE: c1*c2-1e-8, at the blank that says f(u,ut,utt,t). I tried both with unit or without, and both with initial contions at the following blanks or leaving the initial conditions emipy. But no matter what I try, it always gave me this error message:

Failed to evaluate variable.
- Variable: mod1.c1
- Global scope
Failed to evaluate expression.
- Expression: mod1.c1

I'm attaching the test file so you can see. Your help is greatly appreciated!



Hi,
I encountered the same problem when I use the global equation.
I think maybe the reason is that what the global equation need is global variable, but in your model, c1 and c2 are both local variables.
However, I don't know how to transform a local variable to a global variable. I am trying---
[QUOTE] [QUOTE] Hi comsols equation analyser expects the equation to be written as my_expression =0, sou you should start to rewrite xour equation in that way i.e. c1*c2-1E-8 = 0, and not normalise to "1" Check the doc for global equations -- Good luck Ivar [/QUOTE] Thanks Ivar, I tried adding this to the global equation under ODE and DAE: c1*c2-1e-8, at the blank that says f(u,ut,utt,t). I tried both with unit or without, and both with initial contions at the following blanks or leaving the initial conditions emipy. But no matter what I try, it always gave me this error message: Failed to evaluate variable. - Variable: mod1.c1 - Global scope Failed to evaluate expression. - Expression: mod1.c1 I'm attaching the test file so you can see. Your help is greatly appreciated! [/QUOTE] Hi, I encountered the same problem when I use the global equation. I think maybe the reason is that what the global equation need is global variable, but in your model, c1 and c2 are both local variables. However, I don't know how to transform a local variable to a global variable. I am trying---

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 24, 2011, 1:40 a.m. EDT
Hi
basically a global variable is independent of any "Entity", while most local variables depend (implicitly that is one of the difficulties in COMSOL to identify when and why, but it's plain math and physics) so mostly you should integrate or average out the variable to make it independent of x,y,z or r, or T(x,y,z ...) etc (the dependency might be several levels deep

--
Good luck
Ivar
Hi basically a global variable is independent of any "Entity", while most local variables depend (implicitly that is one of the difficulties in COMSOL to identify when and why, but it's plain math and physics) so mostly you should integrate or average out the variable to make it independent of x,y,z or r, or T(x,y,z ...) etc (the dependency might be several levels deep -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 24, 2011, 3:49 p.m. EDT

Hi
basically a global variable is independent of any "Entity", while most local variables depend (implicitly that is one of the difficulties in COMSOL to identify when and why, but it's plain math and physics) so mostly you should integrate or average out the variable to make it independent of x,y,z or r, or T(x,y,z ...) etc (the dependency might be several levels deep

--
Good luck
Ivar


Hi Ivar, thanks a lot for your response. I'm not quite sure that I understand what you mean by integrate or average out the variables to make it independent of xyz. What I have here are two variables for concentration of two diluted species, which are not dependent of xyz. All I want to do is to somehow link these two in a way that the multiply is always a constant. I believe it should not be that hard:)

I tried to put c2=1e-8/c1 in local variables. I don't understand why that does not get registered.

Thanks.


--
Wei Wang, Ph.D. Candidate
Malloup group, Penn State
[QUOTE] Hi basically a global variable is independent of any "Entity", while most local variables depend (implicitly that is one of the difficulties in COMSOL to identify when and why, but it's plain math and physics) so mostly you should integrate or average out the variable to make it independent of x,y,z or r, or T(x,y,z ...) etc (the dependency might be several levels deep -- Good luck Ivar [/QUOTE] Hi Ivar, thanks a lot for your response. I'm not quite sure that I understand what you mean by integrate or average out the variables to make it independent of xyz. What I have here are two variables for concentration of two diluted species, which are not dependent of xyz. All I want to do is to somehow link these two in a way that the multiply is always a constant. I believe it should not be that hard:) I tried to put c2=1e-8/c1 in local variables. I don't understand why that does not get registered. Thanks. -- Wei Wang, Ph.D. Candidate Malloup group, Penn State

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 25, 2011, 1:35 a.m. EDT
Hi

I believe you are getting confused by the "implicit" notation of COMSOL:

your c1 and c2 are dependent variables!
hence they are in fact what I call a "field" and not a simple "variable". they are of the type c1(x,y,z) and c2(x,y,z) as their value might vary over the total area = domain in 2D you are considering.

So if you write out c1*c2-1E-8=0 in your global ODE, COMSOL does not know for which "point" (x,y,z) over the domain it should consider.

In fact your c1, c2 (even if they look so) are NOT any Global variable that can be considered as a constant for itself.

You mean perhaps that the TOTAL concentration product C1*C2 (note the upper case I have chosen arbitrarily) where C1=intop1(c1) and C2=intop1(c2) are constant ?

where intop1() is the integration operand over your domain

--
Good luck
Ivar
Hi I believe you are getting confused by the "implicit" notation of COMSOL: your c1 and c2 are dependent variables! hence they are in fact what I call a "field" and not a simple "variable". they are of the type c1(x,y,z) and c2(x,y,z) as their value might vary over the total area = domain in 2D you are considering. So if you write out c1*c2-1E-8=0 in your global ODE, COMSOL does not know for which "point" (x,y,z) over the domain it should consider. In fact your c1, c2 (even if they look so) are NOT any Global variable that can be considered as a constant for itself. You mean perhaps that the TOTAL concentration product C1*C2 (note the upper case I have chosen arbitrarily) where C1=intop1(c1) and C2=intop1(c2) are constant ? where intop1() is the integration operand over your domain -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 25, 2011, 11:13 a.m. EDT
I had the same problem. For my case, I need to set the relation of two variables equals to a same value at every single point in the whole domain. For example, c1*c2-1e-8=0 is for every single point. In this case, the average and integral method to set this relation in global function is not applicable.
I am still trying to relate two variables in two different multiphysics.
It would be great if someone has a lead of how to do it.

Thank you,

Jo
I had the same problem. For my case, I need to set the relation of two variables equals to a same value at every single point in the whole domain. For example, c1*c2-1e-8=0 is for every single point. In this case, the average and integral method to set this relation in global function is not applicable. I am still trying to relate two variables in two different multiphysics. It would be great if someone has a lead of how to do it. Thank you, Jo

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 26, 2011, 2:44 a.m. EDT
Hi

but can't you use the mapping operators then ? (Definition node)

--
Good luck
Ivar
Hi but can't you use the mapping operators then ? (Definition node) -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 26, 2011, 10:44 a.m. EDT

Hi

I believe you are getting confused by the "implicit" notation of COMSOL:

your c1 and c2 are dependent variables!
hence they are in fact what I call a "field" and not a simple "variable". they are of the type c1(x,y,z) and c2(x,y,z) as their value might vary over the total area = domain in 2D you are considering.

So if you write out c1*c2-1E-8=0 in your global ODE, COMSOL does not know for which "point" (x,y,z) over the domain it should consider.

In fact your c1, c2 (even if they look so) are NOT any Global variable that can be considered as a constant for itself.

You mean perhaps that the TOTAL concentration product C1*C2 (note the upper case I have chosen arbitrarily) where C1=intop1(c1) and C2=intop1(c2) are constant ?

where intop1() is the integration operand over your domain

--
Good luck
Ivar


Hi Ivar,

That clarification cleared up some confusion for me. In fact when I said c1 and c2 I meant concentration for every single point, i.e. at each point of the domain I need the multiply of c1 and c2 to be a constant, even though the number of c1 and c2 will vary at different points of the domain. I hope that sounds clear to me.

I'm still a little confused about how that should be done.

Thanks for your help.


--
Wei Wang, Ph.D. Candidate
Malloup group, Penn State
[QUOTE] Hi I believe you are getting confused by the "implicit" notation of COMSOL: your c1 and c2 are dependent variables! hence they are in fact what I call a "field" and not a simple "variable". they are of the type c1(x,y,z) and c2(x,y,z) as their value might vary over the total area = domain in 2D you are considering. So if you write out c1*c2-1E-8=0 in your global ODE, COMSOL does not know for which "point" (x,y,z) over the domain it should consider. In fact your c1, c2 (even if they look so) are NOT any Global variable that can be considered as a constant for itself. You mean perhaps that the TOTAL concentration product C1*C2 (note the upper case I have chosen arbitrarily) where C1=intop1(c1) and C2=intop1(c2) are constant ? where intop1() is the integration operand over your domain -- Good luck Ivar [/QUOTE] Hi Ivar, That clarification cleared up some confusion for me. In fact when I said c1 and c2 I meant concentration for every single point, i.e. at each point of the domain I need the multiply of c1 and c2 to be a constant, even though the number of c1 and c2 will vary at different points of the domain. I hope that sounds clear to me. I'm still a little confused about how that should be done. Thanks for your help. -- Wei Wang, Ph.D. Candidate Malloup group, Penn State

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 26, 2011, 10:45 a.m. EDT
Hi Jo I think we have very similar problem here. I look forward to hearing from Ivar or someone who can help us.

Thanks.

--
Wei Wang, Ph.D. Candidate
Malloup group, Penn State
Hi Jo I think we have very similar problem here. I look forward to hearing from Ivar or someone who can help us. Thanks. -- Wei Wang, Ph.D. Candidate Malloup group, Penn State

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 26, 2011, 11:09 a.m. EDT
Ivar, thank you for your response.
I cannot find the mapping operator under Definitions node. Would you please explain that more clearly?

Thank you,

Wei, yes, I think we have very similar problem. Hope we can find our way out soon!
Ivar, thank you for your response. I cannot find the mapping operator under Definitions node. Would you please explain that more clearly? Thank you, Wei, yes, I think we have very similar problem. Hope we can find our way out soon!

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 30, 2011, 3:56 a.m. EDT
Hi

My fault, I used the wrong therm, look after

Definitions - Model Couplings - Extrusion and Projection (depends on what you want to do, see the doc)

--
Good luck
Ivar
Hi My fault, I used the wrong therm, look after Definitions - Model Couplings - Extrusion and Projection (depends on what you want to do, see the doc) -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jun 2, 2011, 1:36 p.m. EDT
Thanks Ivar.

I tried to use extrusion coupling variable. I still can not set an equation that the multiplication of two variables (c1*c2) equals to a constant. I thought the variables will turn into global variables through extrusion coupling, and I can use them in the global equation. But it seems not to work that way.

Any feedback is appreciated.

Thank you!

Jo
Thanks Ivar. I tried to use extrusion coupling variable. I still can not set an equation that the multiplication of two variables (c1*c2) equals to a constant. I thought the variables will turn into global variables through extrusion coupling, and I can use them in the global equation. But it seems not to work that way. Any feedback is appreciated. Thank you! Jo

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jun 2, 2011, 2:34 p.m. EDT

Thanks Ivar.

I tried to use extrusion coupling variable. I still can not set an equation that the multiplication of two variables (c1*c2) equals to a constant. I thought the variables will turn into global variables through extrusion coupling, and I can use them in the global equation. But it seems not to work that way.

Any feedback is appreciated.

Thank you!

Jo


What's your settings for the extrusion?
[QUOTE] Thanks Ivar. I tried to use extrusion coupling variable. I still can not set an equation that the multiplication of two variables (c1*c2) equals to a constant. I thought the variables will turn into global variables through extrusion coupling, and I can use them in the global equation. But it seems not to work that way. Any feedback is appreciated. Thank you! Jo [/QUOTE] What's your settings for the extrusion?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jun 2, 2011, 5:49 p.m. EDT
Hi Xiaoyi

Thanks for your quick reply.

I have made the following simple model: 2D axi-symmetric application mode, I have two variables c_1 and c_2 both controlled only by diffusion and I want COMSOL knows that c_1*c_2=constant. For this I use the "Extrusion Coupling Variables - Subdomain Variables" I select the source subdomain "1", define a Name i.e. C1 and an expression c_1 for the concentration gradient as defined on this domain; also define a NAME C2 and an expression c_2. I select "General transformation" and use "x=r and y=z" as source transformation variable. Then I select the destination tab: select "Level": "subdomain" , I tick and select subdomain "1" and tick "use selected subdomains as destination". Then I give a unknown variable R for the reaction rate for both diffusion equation and I use "global equations". I select "state" Name(u) is R and equation f(u, ut, utt, t)=0 is C1*C2-constant.

But I got a message saying that "fail to evaluate C1 variable"

If somone knows where would be the problem source, please do let me know.

Thank you,
Hi Xiaoyi Thanks for your quick reply. I have made the following simple model: 2D axi-symmetric application mode, I have two variables c_1 and c_2 both controlled only by diffusion and I want COMSOL knows that c_1*c_2=constant. For this I use the "Extrusion Coupling Variables - Subdomain Variables" I select the source subdomain "1", define a Name i.e. C1 and an expression c_1 for the concentration gradient as defined on this domain; also define a NAME C2 and an expression c_2. I select "General transformation" and use "x=r and y=z" as source transformation variable. Then I select the destination tab: select "Level": "subdomain" , I tick and select subdomain "1" and tick "use selected subdomains as destination". Then I give a unknown variable R for the reaction rate for both diffusion equation and I use "global equations". I select "state" Name(u) is R and equation f(u, ut, utt, t)=0 is C1*C2-constant. But I got a message saying that "fail to evaluate C1 variable" If somone knows where would be the problem source, please do let me know. Thank you,

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jun 6, 2011, 9:34 a.m. EDT
Does anyone know how to solve that problem already?
Does anyone know how to solve that problem already?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 25, 2011, 11:06 a.m. EDT
The number of equations has to equal the number of unknowns. If c1 is determined by the diffusion equation with whatever boundary conditions, and c2 is determined by another diffusion equation with whatever boundary conditions, then c1 and c2 are already determined. You can't force c1*c2=1e-8 or any other condition to be satisfied.

Instead, you have to let the condition not be satisfied, and then use negative feedback to get rid of the discrepency. For example, you can have a variable

EXTRA = c1*c2-1e-8

then incorporate EXTRA into the diffusion equation as a reaction rate that destroys some of the c1 and/or c2 if there's too much, or creates extra c1 and/or c2 if there's too little. Then if you solve everything you may not get exactly EXTRA=0, but if you increase the feedback (multiply EXTRA by a large factor in the reaction rate), you can get very close.

This is what happens in real chemical equilibria: Equilibrium happens because the forward and reverse reaction rates depend on the concentrations, always pushing them towards equilibrium in a feedback loop.
The number of equations has to equal the number of unknowns. If c1 is determined by the diffusion equation with whatever boundary conditions, and c2 is determined by another diffusion equation with whatever boundary conditions, then c1 and c2 are already determined. You can't force c1*c2=1e-8 or any other condition to be satisfied. Instead, you have to let the condition not be satisfied, and then use negative feedback to get rid of the discrepency. For example, you can have a variable EXTRA = c1*c2-1e-8 then incorporate EXTRA into the diffusion equation as a reaction rate that destroys some of the c1 and/or c2 if there's too much, or creates extra c1 and/or c2 if there's too little. Then if you solve everything you may not get exactly EXTRA=0, but if you increase the feedback (multiply EXTRA by a large factor in the reaction rate), you can get very close. This is what happens in real chemical equilibria: Equilibrium happens because the forward and reverse reaction rates depend on the concentrations, always pushing them towards equilibrium in a feedback loop.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 7, 2012, 8:46 a.m. EDT
Hi,

I have following four reactions and want to model them as equilibrium reactions in the "transport of diluted species" interface;

r1: H2O<=>H++OH-
r2: CO2aq+H2O<=>H++HCO3-
r3: HCO3-<=>H++CO3--
r4: Na++HCO3-<=>NaHCO3aq

I need guidance about how to set equilibrium reactions within "transport of diluted species" interface. Attached is mph file to have a look how I tried to define these equilibrium reactions in the form of algebraic relations.

Solution converges for specified initial and boundary conditions. However, I am not sure about the formulation of equilibrium reactions in COMSOL.


Best Regards,

Nawaz Ahmad
KTH

Hi, I have following four reactions and want to model them as equilibrium reactions in the "transport of diluted species" interface; r1: H2OH++OH- r2: CO2aq+H2OH++HCO3- r3: HCO3-H++CO3-- r4: Na++HCO3-NaHCO3aq I need guidance about how to set equilibrium reactions within "transport of diluted species" interface. Attached is mph file to have a look how I tried to define these equilibrium reactions in the form of algebraic relations. Solution converges for specified initial and boundary conditions. However, I am not sure about the formulation of equilibrium reactions in COMSOL. Best Regards, Nawaz Ahmad KTH

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.