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.
Use of implicit functions in COMSOL
Posted Oct 29, 2023, 9:23 a.m. EDT Computational Fluid Dynamics (CFD), Equation-Based Modeling, Modeling Workflow Version 5.6 9 Replies
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.
Please login with a confirmed email address before reporting spam
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.
Please login with a confirmed email address before reporting spam
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
Please login with a confirmed email address before reporting spam
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?
Please login with a confirmed email address before reporting spam
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
Please login with a confirmed email address before reporting spam
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
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.
Please login with a confirmed email address before reporting spam
It sounds like c1 varies in space. In that case, use a Domain ODE and DAE.
Jeff
-------------------Jeff Hiller
Please login with a confirmed email address before reporting spam
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
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.
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.