Use of implicit functions in COMSOL

Please login with a confirmed email address before reporting spam

I am solving an adsorption process in comsol. My model calculates the value of concentration which is dependednt on a variable q. When the variable q can be calculated explicitly using a formulation q=f(c,T), the model is easier to define. However, I need to calculate the variable q implicitly using the equation c=q/k(aq^2+bq^2+cq^3). How should I implement this in my model. I tried using functions but I am not sure how to obtain q using the above equation.


9 Replies Last Post 1 nov 2023, 04:32 GMT-4
Dave Greve Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 6 months ago 29 ott 2023, 13:41 GMT-4
Updated: 6 months ago 29 ott 2023, 13:43 GMT-4

This sort of equation can be solved in a Global ODE physics, because after all an algebraic equation is a special case of a differential equation.

There will be multiple roots. You will need to choose initial conditions to get the one you want.

This sort of equation can be solved in a Global ODE physics, because after all an algebraic equation is a special case of a differential equation. There will be multiple roots. You will need to choose initial conditions to get the one you want.

Edgar J. Kaiser Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 6 months ago 29 ott 2023, 13:42 GMT-4
Updated: 6 months ago 29 ott 2023, 13:43 GMT-4

Hi,

you can set up an algebraic equation to solve for q. Check the documentation and examples for the equations interface. Those are very powerful tools in COMSOL.

Cheers Edgar

Dave was quicker

-------------------
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
Hi, you can set up an algebraic equation to solve for q. Check the documentation and examples for the equations interface. Those are very powerful tools in COMSOL. Cheers Edgar Dave was quicker

Please login with a confirmed email address before reporting spam

Posted: 6 months ago 30 ott 2023, 04:49 GMT-4
Updated: 6 months ago 30 ott 2023, 04:50 GMT-4

Thank you for the responses. Do I need to add the algebraic equations using matlab or they can be solely solved in COMSOL. I found one solution using MATLAB equations in COMSOL. Is there a way to solve without using MATLAB equations?

Thank you for the responses. Do I need to add the algebraic equations using matlab or they can be solely solved in COMSOL. I found one solution using MATLAB equations in COMSOL. Is there a way to solve without using MATLAB equations?

Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 6 months ago 30 ott 2023, 05:32 GMT-4

You shouldn't use Matlab for this. Just add the equstion to your Comsol model and the Comsol solvers will solve this equation together with the rest of your physics.

-------------------
Lars Gregersen
Comsol Denmark
You shouldn't use Matlab for this. Just add the equstion to your Comsol model and the Comsol solvers will solve this equation together with the rest of your physics.

Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 6 months ago 30 ott 2023, 05:36 GMT-4

Hi Hina,

No, there is no need to use MATLAB. As Dave and Edgar mentioned, you can set up this algebraic equation using a Global ODEs and DAEs interface with a Global Equations node, where you solve for q using a general algebraic equations f(q, qt, qtt, t). You can also define the contants k, a, b, and c using a Parameters node in the COMSOL Desktop.

Best regards,

Magnus

Hi Hina, No, there is no need to use MATLAB. As Dave and Edgar mentioned, you can set up this algebraic equation using a **Global ODEs and DAEs** interface with a **Global Equations** node, where you solve for `q` using a general algebraic equations `f(q, qt, qtt, t)`. You can also define the contants `k`, `a`, `b`, and `c` using a **Parameters** node in the COMSOL Desktop. Best regards, Magnus

Please login with a confirmed email address before reporting spam

Posted: 6 months ago 30 ott 2023, 08:00 GMT-4
Updated: 6 months ago 30 ott 2023, 08:04 GMT-4

Thank you Magnus for the clear explanation. As suggested, I added Global ODEs and DAEs interface and a Global Equations node. I wrote my equation as c1-(q/k)exp(aq+bq^2+cq^3). I have to calculate 'q' from this equation and the value of 'c1' is caluclated from the solver which is being used to obtain 'q'. Other parameters k, a, b and c are given as constant. While implementing the interface and computing the model it is giving me an 'undefined variable' error for 'c1'. Do you have some idea where I am going wrong.

Thank you Magnus for the clear explanation. As suggested, I added Global ODEs and DAEs interface and a Global Equations node. I wrote my equation as c1-(q/k)*exp(a*q+b*q^2+c*q^3). I have to calculate 'q' from this equation and the value of 'c1' is caluclated from the solver which is being used to obtain 'q'. Other parameters k, a, b and c are given as constant. While implementing the interface and computing the model it is giving me an 'undefined variable' error for 'c1'. Do you have some idea where I am going wrong.

Jeff Hiller COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 6 months ago 30 ott 2023, 14:30 GMT-4
Updated: 6 months ago 30 ott 2023, 14:29 GMT-4

It sounds like c1 varies in space. In that case, use a Domain ODE and DAE.

Jeff

-------------------
Jeff Hiller
It sounds like c1 varies in space. In that case, use a Domain ODE and DAE. Jeff

Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 6 months ago 31 ott 2023, 05:27 GMT-4

Hi Hina,

Yes, it's either as Jeff suggests above, or else c1 cannot be a field variable (space-dependent variable) in a global DAE, but it can be a scalar function of time, such as an average value, using an Average nonlocal coupling variable, or a value in a point in the geometry. Also, if you want to add units for the DAE, make sure to "dedimensionalize" c1 in the expression for the exponent.

Best regards, Magnus

Hi Hina, Yes, it's either as Jeff suggests above, or else `c1` cannot be a field variable (space-dependent variable) in a global DAE, but it can be a scalar function of time, such as an average value, using an **Average** nonlocal coupling variable, or a value in a point in the geometry. Also, if you want to add units for the DAE, make sure to "dedimensionalize" `c1` in the expression for the exponent. Best regards, Magnus

Please login with a confirmed email address before reporting spam

Posted: 6 months ago 1 nov 2023, 04:32 GMT-4
Updated: 6 months ago 1 nov 2023, 08:53 GMT-4

Thank you Jeff and Magnus for the suggestions. Yes you are right that c1 varies in space. I was able to solve my problem using 'Domain ODE and DAE' interface and am able to obtain q1 using the value cp1 calculated from the solver for this equation

cp1-(q1/k1)exp(a1q1+b1q1^2+c1*q1^3)=0

Now second part of my problem is that I have to solve two equations simultaneously and obtain two unknowns. The equations are like:

cp1-(q1/k1)exp(a1q1+b1q1^2+c1*q1^3)=0

and

cp2-(q2/k2)exp(a2q1+b2q2^2+c2*q2^3)=0

The parameters k1,a1,b1,c1, k2,a2,b2,c2 are known. cp1 and cp2 are calculated from the solver which are used to solve the above two eqns and obtain q1 and q2. When I am using two equations simultaneously I am getting an error that 'Nonlinear solver did not converge.' Can you please guide me in this? I am able to solve the above two equations in MATLAB and obtain values for q1 and q2.

Thank you Jeff and Magnus for the suggestions. Yes you are right that c1 varies in space. I was able to solve my problem using 'Domain ODE and DAE' interface and am able to obtain q1 using the value cp1 calculated from the solver for this equation cp1-(q1/k1)exp(a1*q1+b1*q1^2+c1*q1^3)=0 Now second part of my problem is that I have to solve two equations simultaneously and obtain two unknowns. The equations are like: cp1-(q1/k1)exp(a1*q1+b1*q1^2+c1*q1^3)=0 and cp2-(q2/k2)exp(a2*q1+b2*q2^2+c2*q2^3)=0 The parameters k1,a1,b1,c1, k2,a2,b2,c2 are known. cp1 and cp2 are calculated from the solver which are used to solve the above two eqns and obtain q1 and q2. When I am using two equations simultaneously I am getting an error that 'Nonlinear solver did not converge.' Can you please guide me in this? I am able to solve the above two equations in MATLAB and obtain values for q1 and q2.

Reply

Please read the discussion forum rules before posting.

Please log in to post a reply.

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.