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.

Heaviside function Comsol

Please login with a confirmed email address before reporting spam

Hi,

I am solving the heat transfer function, with an initial condition,.

In my simulation the initial variable is called Ninit, and I want to define it with a heaviside function,

Ninit = 0.4*Heaviside(0.04 - x^2 - y^2),

I am attaching the plot of the initial condition.

Can anyone tell me how to add this in comsol?


10 Replies Last Post 3 ago 2016, 14:57 GMT-4

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 14 lug 2015, 08:58 GMT-4
Look "flc1hs" or "flc2hs".
Look "flc1hs" or "flc2hs".

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 14 lug 2015, 23:49 GMT-4
Thank you very much for the reply, I tried this equation,

0.25*(flc1hs(x^2,-0.5)+flc1hs(y^2,-0.5)) and I am getting this as the initial condition (initial_comsol.jpg).

I want to achieve something like this, (initial_malab.jpg)



Thank you very much for the reply, I tried this equation, 0.25*(flc1hs(x^2,-0.5)+flc1hs(y^2,-0.5)) and I am getting this as the initial condition (initial_comsol.jpg). I want to achieve something like this, (initial_malab.jpg)


Please login with a confirmed email address before reporting spam

Posted: 9 years ago 15 lug 2015, 02:46 GMT-4
What happens if you write

0.4*flc1hs(0.04 - x^2 - y^2, 0.01)?
What happens if you write 0.4*flc1hs(0.04 - x^2 - y^2, 0.01)?

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 16 lug 2015, 01:59 GMT-4
yep that worked. I am getting this white border around the initial cell. Do you know why?

yep that worked. I am getting this white border around the initial cell. Do you know why?


Please login with a confirmed email address before reporting spam

Posted: 9 years ago 16 lug 2015, 02:13 GMT-4
I do not understand the image. How dense is the mesh around the circle? Please send a height plot.
I do not understand the image. How dense is the mesh around the circle? Please send a height plot.

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 16 lug 2015, 02:36 GMT-4
attached are the screenshots of initial stage and after 0.6seconds

attached are the screenshots of initial stage and after 0.6seconds


Please login with a confirmed email address before reporting spam

Posted: 9 years ago 16 lug 2015, 03:16 GMT-4
White areas probably represent function values < 0 and also shows your mesh. If you have a time dependent problem the initial steps tend to give negative values as the step function is numerically rather tricky thing to realize. Have you tried flc2hs which has also continuous second derivative? But in principle it appears to work. Defining the second parameter as 0.001 makes the transition range very sharp; values below that I have not found to have any improvement.
White areas probably represent function values < 0 and also shows your mesh. If you have a time dependent problem the initial steps tend to give negative values as the step function is numerically rather tricky thing to realize. Have you tried flc2hs which has also continuous second derivative? But in principle it appears to work. Defining the second parameter as 0.001 makes the transition range very sharp; values below that I have not found to have any improvement.

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 16 lug 2015, 03:28 GMT-4
Thank you very much for the quick reply

I tried flc2hs, and I'm getting a similar result. I changed the second parameter to 0.001 and it is the same,

It is like this only for the initial step. at 0.1s onward white boundary is gone
Thank you very much for the quick reply I tried flc2hs, and I'm getting a similar result. I changed the second parameter to 0.001 and it is the same, It is like this only for the initial step. at 0.1s onward white boundary is gone

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 3 ago 2016, 09:12 GMT-4
You can also trying using logicals.

for instance (x^2 + y^2 > 0.4) will return 1 when true and 0 when false.
You can also trying using logicals. for instance (x^2 + y^2 > 0.4) will return 1 when true and 0 when false.

Jeff Hiller COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 3 ago 2016, 14:57 GMT-4
Hello Ashan,
I get the feeling that this may be a case of the situation that's been discussed in this Discussion Forum before (I cannot find the thread right now) where the user tries to impose a very rapid variation of a quantity at the nodes of a single quadratic element, not realizing that this can cause the quantity to overshoot or undershoot in between the nodes.
E.g. if you imagine a 1D quadratic element covering [-2;2] and you impose at the 3 nodes u(-2)=1, u(0)=0 and u(2)=0, then u will take negative values in [0;2]. This can be counter-intuitive but it's true. If your plot is set up so that only values of u between 0 and 1 are displayed, then you will naturally get a "hole" in your plot, like what your screenshots above show.
The solution is to use a finer mesh, one that uses more than one element to capture the gradient that you're imposing.
Jeff
Hello Ashan, I get the feeling that this may be a case of the situation that's been discussed in this Discussion Forum before (I cannot find the thread right now) where the user tries to impose a very rapid variation of a quantity at the nodes of a single quadratic element, not realizing that this can cause the quantity to overshoot or undershoot in between the nodes. E.g. if you imagine a 1D quadratic element covering [-2;2] and you impose at the 3 nodes u(-2)=1, u(0)=0 and u(2)=0, then u will take negative values in [0;2]. This can be counter-intuitive but it's true. If your plot is set up so that only values of u between 0 and 1 are displayed, then you will naturally get a "hole" in your plot, like what your screenshots above show. The solution is to use a finer mesh, one that uses more than one element to capture the gradient that you're imposing. Jeff

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.