How to properly define the divergence of the gradient of a scalar variable manually?

Please login with a confirmed email address before reporting spam

Hi,

I am trying to define the divergence of the gradient of a scalar variable, namely

,

and use it as a source term in a general form PDE in a 2D model, where is a constant and is the dependent variable.

By the definition of the divergence of the gradient of a scalar variable, I assume what I should do is define a variable in COMSOL like below

Laplacian_xi=d(d(xi,x),x)+d(d(xi,y),y)

which corresponds to

.

However, if I put Laplacian_xi in the source term of the general form PDE, and set Conserved flux as 0, the result differs greatly from defining d(xi,x) and d(xi,y) in the Conserved flux and set the source term as 0.

Can anyone tell me what I did wrong? Do I need to define any weak form to make d(d(xi,x),x)+d(d(xi,y),y) work properly?

Best Runzi Wang


4 Replies Last Post 2025年2月28日 GMT-5 05:44
Henrik Sönnerlind COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 6 days ago 2025年2月25日 GMT-5 09:49

The most important consideration here is the order of the shape functions used for your dependent variables. If you, for example, would use linear shape functions, the second derivative is =0 by definition. But even with quadratic shape functions, the prediction of second derivatives is bad (element constant).

If you really need a formulation where the Laplacian is used, you need at least third-order shape functions or a very dense mesh to get reasonable accuracy.

-------------------
Henrik Sönnerlind
COMSOL
The most important consideration here is the order of the shape functions used for your dependent variables. If you, for example, would use linear shape functions, the second derivative is =0 by definition. But even with quadratic shape functions, the prediction of second derivatives is bad (element constant). If you really need a formulation where the Laplacian is used, you need at least third-order shape functions or a very dense mesh to get reasonable accuracy.

Please login with a confirmed email address before reporting spam

Posted: 6 days ago 2025年2月25日 GMT-5 23:15
Updated: 6 days ago 2025年2月25日 GMT-5 23:18

Hi Henrik, thank you for your reply.

I am wondering what does COMSOL do behind the Conserved flux and what are the equations. Because when I put d(xi,x) and d(xi,y) in the Conserved flux, the result seems correct even if I use linear shape function.

If I can understand how does COMSOL solve , then I can try reproduce it manually. But I couldn't find the way COMSOL do it in the equation view. Could you tell me what does COMSOL do or where to find it?

Best

Runzi Wang

Hi Henrik, thank you for your reply. I am wondering what does COMSOL do behind the *Conserved flux* \nabla\cdot\mathbf{\Gamma} and what are the equations. Because when I put d(xi,x) and d(xi,y) in the *Conserved flux*, the result seems correct even if I use linear shape function. If I can understand how does COMSOL solve \nabla\cdot\mathbf{\Gamma}, then I can try reproduce it manually. But I couldn't find the way COMSOL do it in the equation view. Could you tell me what does COMSOL do or where to find it? Best Runzi Wang

Henrik Sönnerlind COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 5 days ago 2025年2月26日 GMT-5 07:19

In Equation view, the weak contribution is

g.Gax*test(u3x)+g.Gay*test(u3y)+g.Gaz*test(u3z)

where g.Gax is the input for Conservative Flux. Thus, you have only first derivative in that case when you enter d(xi,x).

-------------------
Henrik Sönnerlind
COMSOL
In Equation view, the weak contribution is g.Gax\*test(u3x)+g.Gay\*test(u3y)+g.Gaz\*test(u3z) where g.Gax is the input for Conservative Flux. Thus, you have only first derivative in that case when you enter d(xi,x).

Please login with a confirmed email address before reporting spam

Posted: 3 days ago 2025年2月28日 GMT-5 05:44

I see. Thank you for you help.

I see. Thank you for you help.

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.