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.

Problem in Plot in COMSOL!

Please login with a confirmed email address before reporting spam

Hi all,

very simple problem but

I have txt file which the first column is time and the second column is f(x).

I know that the maximum value that I have for the function is at time= 15206400 which is equal 101.061, but when I am trying to prepare the plot for this interpolation fn the maximum value is around 59!!

I attached my txt file plus the picture of the plot that I got from comsol.

Could you kindly let me know why is comsol is not able to show the correct values?

And I want to know that if COMSOL is it using this value or not? because if it is not considering it then I will have problem.



9 Replies Last Post Nov 5, 2015, 12:06 p.m. EST
Edgar J. Kaiser Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 9 years ago Oct 22, 2015, 1:12 p.m. EDT
Sepideh,

this is a visualisation effect. You can use create plot and then increase the resolution in the resulting grid dataset to 10000. In the default setting the plot misses some values due to the default resolution of just 1000.
The interpolation function will be evaluated correctly anyway.

Cheers
Edgar

--
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
Sepideh, this is a visualisation effect. You can use create plot and then increase the resolution in the resulting grid dataset to 10000. In the default setting the plot misses some values due to the default resolution of just 1000. The interpolation function will be evaluated correctly anyway. Cheers Edgar -- Edgar J. Kaiser emPhys Physical Technology http://www.emphys.com

Gunnar Andersson COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 9 years ago Oct 23, 2015, 2:32 a.m. EDT
Edgar is right: Limited sampling causes this effect. Note that this effect sometimes occurs also when solving: The mesh respects the geometry's details, and the time stepper respects the list of times to solver for, but neither of them guarantee that function spikes and discontinuities are respected.
Edgar is right: Limited sampling causes this effect. Note that this effect sometimes occurs also when solving: The mesh respects the geometry's details, and the time stepper respects the list of times to solver for, but neither of them guarantee that function spikes and discontinuities are respected.

Edgar J. Kaiser Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 9 years ago Oct 23, 2015, 4:58 a.m. EDT
Hi Gunnar,

maybe this behavior of the plotting algorithms should be discussed a little further because it can lead to drastically incorrect interpretations of results, as Sepideh's initial post shows.

I would suggest to think about introducing some sort of binning, that means that all values, e.g. in a 1D plot show up in the plot, regardless of sampling resolution. This would make sure that extrema don't get lost. You don't always look into the underlying table (if there is one). Of course in case the data rate is higher than the sampling rate, some points will overlap, but the binning makes shure they don't get lost in the visualisation.
In 1D plots in many cases it is the extrema you are interested in, aren't you?

Cheers
Edgar

--
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
Hi Gunnar, maybe this behavior of the plotting algorithms should be discussed a little further because it can lead to drastically incorrect interpretations of results, as Sepideh's initial post shows. I would suggest to think about introducing some sort of binning, that means that all values, e.g. in a 1D plot show up in the plot, regardless of sampling resolution. This would make sure that extrema don't get lost. You don't always look into the underlying table (if there is one). Of course in case the data rate is higher than the sampling rate, some points will overlap, but the binning makes shure they don't get lost in the visualisation. In 1D plots in many cases it is the extrema you are interested in, aren't you? Cheers Edgar -- Edgar J. Kaiser emPhys Physical Technology http://www.emphys.com

Gunnar Andersson COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 9 years ago Oct 23, 2015, 6:49 a.m. EDT
I would suggest to think about introducing some sort of binning, that means that all values, e.g. in a 1D plot show up in the plot, regardless of sampling resolution. This would make sure that extrema don't get lost. You don't always look into the underlying table (if there is one). Of course in case the data rate is higher than the sampling rate, some points will overlap, but the binning makes shure they don't get lost in the visualisation.
In 1D plots in many cases it is the extrema you are interested in, aren't you?


I think that guaranteeing that all values show up is a bad idea as this can lead to an unreadable plot - consider e.g. random sample points from a sine wave with a large number of periods. But you're right that we should try to improve the point selection; at the very least, the extreme points should always be included. I'll file an enhancement request for this.

A small drawback with improving the function plot is that more users will be hurt by undersampling when solving.
[QUOTE]I would suggest to think about introducing some sort of binning, that means that all values, e.g. in a 1D plot show up in the plot, regardless of sampling resolution. This would make sure that extrema don't get lost. You don't always look into the underlying table (if there is one). Of course in case the data rate is higher than the sampling rate, some points will overlap, but the binning makes shure they don't get lost in the visualisation. In 1D plots in many cases it is the extrema you are interested in, aren't you?[/QUOTE] I think that guaranteeing that all values show up is a bad idea as this can lead to an unreadable plot - consider e.g. random sample points from a sine wave with a large number of periods. But you're right that we should try to improve the point selection; at the very least, the extreme points should always be included. I'll file an enhancement request for this. A small drawback with improving the function plot is that more users will be hurt by undersampling when solving.

Please login with a confirmed email address before reporting spam

Posted: 9 years ago Oct 23, 2015, 11:50 a.m. EDT

Edgar is right: Limited sampling causes this effect. Note that this effect sometimes occurs also when solving: The mesh respects the geometry's details, and the time stepper respects the list of times to solver for, but neither of them guarantee that function spikes and discontinuities are respected.



Many thanks to both of you for reply.

So, if I understand correctly, the extreme value that I have in my function is not going to be considered in my simulations? Am I right?

If yes, this will be real problem, because I am focusing in Extreme events.
Is there any way to solve this problem?

Hope to hear from you.
Thanks
Sepideh
[QUOTE] Edgar is right: Limited sampling causes this effect. Note that this effect sometimes occurs also when solving: The mesh respects the geometry's details, and the time stepper respects the list of times to solver for, but neither of them guarantee that function spikes and discontinuities are respected. [/QUOTE] Many thanks to both of you for reply. So, if I understand correctly, the extreme value that I have in my function is not going to be considered in my simulations? Am I right? If yes, this will be real problem, because I am focusing in Extreme events. Is there any way to solve this problem? Hope to hear from you. Thanks Sepideh

Edgar J. Kaiser Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 9 years ago Oct 23, 2015, 4:10 p.m. EDT
Sepideh,

no, the function is evaluated properly in the simulation. Only the plot isn't showing all values in the default settings. But you can correct that by creating a plot with higher resolution as I explained in my first posting.

Cheers
Edgar

Edit: I just read Gunnar's post once more and I am not sure any longer. Can it really happen that when using the function, e.g. in some boundary definition or whatever, a function call would miss a spike due to limited sampling resolution?
Gunnar, I would be grateful if you clarified that.

Thank you

--
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
Sepideh, no, the function is evaluated properly in the simulation. Only the plot isn't showing all values in the default settings. But you can correct that by creating a plot with higher resolution as I explained in my first posting. Cheers Edgar Edit: I just read Gunnar's post once more and I am not sure any longer. Can it really happen that when using the function, e.g. in some boundary definition or whatever, a function call would miss a spike due to limited sampling resolution? Gunnar, I would be grateful if you clarified that. Thank you -- Edgar J. Kaiser emPhys Physical Technology http://www.emphys.com

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: 9 years ago Oct 24, 2015, 3:12 p.m. EDT
Thanks Sepideh for pointing to an interesting issue

True that EXCEL manage to give a different render of the curve and that the under-sampling in COMSOL plots opens up for some discussions. But for me this is the classical issue of sampling continuous functions versus discrete ones.
Your data is "discrete data" as rainfall per day, so if one need to under sample it correctly one should bin by summing: rainfall per 2 days, per 3 days etc. This would change the max value but the integral remains since the total sum is divided by 2, 3 respectively.
While if one looks at a continuous sinus curve of amplitude 1, sampling it by 1000 points per period, and then under sampling it by 2 by taking the first, the second or the average of two consecutive values will give the same general shape and amplitude, with a little phasing error. But if one where to do binned by adding, as for the discrete date case, then one would change the amplitude and the curve which is obviously misleading and the integral would not remain constant.

COMSOL could add some warning on a plot when its under sampled, and improve the sampling while zooming (not the case now), or do some checks on the integral of the displayed curve. But I agree with you that for discrete data this way to plot is very misleading.

But this means also that to get all data used correctly in a simulation, one must ensure that the time stepping is really one per day (or corresponding to the data sampling)

--
Good luck
Ivar
Thanks Sepideh for pointing to an interesting issue True that EXCEL manage to give a different render of the curve and that the under-sampling in COMSOL plots opens up for some discussions. But for me this is the classical issue of sampling continuous functions versus discrete ones. Your data is "discrete data" as rainfall per day, so if one need to under sample it correctly one should bin by summing: rainfall per 2 days, per 3 days etc. This would change the max value but the integral remains since the total sum is divided by 2, 3 respectively. While if one looks at a continuous sinus curve of amplitude 1, sampling it by 1000 points per period, and then under sampling it by 2 by taking the first, the second or the average of two consecutive values will give the same general shape and amplitude, with a little phasing error. But if one where to do binned by adding, as for the discrete date case, then one would change the amplitude and the curve which is obviously misleading and the integral would not remain constant. COMSOL could add some warning on a plot when its under sampled, and improve the sampling while zooming (not the case now), or do some checks on the integral of the displayed curve. But I agree with you that for discrete data this way to plot is very misleading. But this means also that to get all data used correctly in a simulation, one must ensure that the time stepping is really one per day (or corresponding to the data sampling) -- Good luck Ivar

Edgar J. Kaiser Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 9 years ago Oct 24, 2015, 4:45 p.m. EDT
Regarding the plot my first concern is that I don't want to miss extrema. So my suggestion for binning is dividing the argument range into n bins and but the function value to the bin with closest center value of the argument. In case of undersampling the plot can then show more than one point per bin but I can be sure that I don't miss a feature. If the plot gets messy I can always decide to increase the sampling. This way of binning can also easily issue a warning in case any bin contains more than one value. The way it works now I have to know the highest argument frequency of my sample and adjust the function sampling accordingly.

I was thinking a little more about the other concern regarding the evaluation of the function inside a simulation. A little example: In case Sepideh's interpolation function would be used somewhere in a time-dependent study, say using strict time stepping, she has to take care that the time stepping properly resolves the function. If the time stepping is too coarse it will miss features of the curve. And in case the time stepping is not exactly hitting the sampling intervals of the curve she will miss extrema as well. The same holds for the spatial independent variables. So in any case the function is called with discretised arguments, the user has to take care of suitable sampling, i.e. sufficiently fine discretisation. Well, this is something very general in the FE world.

So I probably repeated Gunnar's and Ivar's contributions in my own words, but to me it was a useful exercise. Hopefully for others as well.

Cheers
Edgar
--
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
Regarding the plot my first concern is that I don't want to miss extrema. So my suggestion for binning is dividing the argument range into n bins and but the function value to the bin with closest center value of the argument. In case of undersampling the plot can then show more than one point per bin but I can be sure that I don't miss a feature. If the plot gets messy I can always decide to increase the sampling. This way of binning can also easily issue a warning in case any bin contains more than one value. The way it works now I have to know the highest argument frequency of my sample and adjust the function sampling accordingly. I was thinking a little more about the other concern regarding the evaluation of the function inside a simulation. A little example: In case Sepideh's interpolation function would be used somewhere in a time-dependent study, say using strict time stepping, she has to take care that the time stepping properly resolves the function. If the time stepping is too coarse it will miss features of the curve. And in case the time stepping is not exactly hitting the sampling intervals of the curve she will miss extrema as well. The same holds for the spatial independent variables. So in any case the function is called with discretised arguments, the user has to take care of suitable sampling, i.e. sufficiently fine discretisation. Well, this is something very general in the FE world. So I probably repeated Gunnar's and Ivar's contributions in my own words, but to me it was a useful exercise. Hopefully for others as well. Cheers Edgar -- Edgar J. Kaiser emPhys Physical Technology http://www.emphys.com

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: 9 years ago Nov 5, 2015, 12:06 p.m. EST
Hi all
Comeing back to this issue after having exchanged with my signal processing specialists. Their recommandation is to resample but keeping the min and the max per resampling bin. In this way one do not get filtering on the amplitudes. Still the integrals could be wrong. This seems to be what one sees in Matlab and in Excel but my other favorite ODE tool MapleSim seem to behave as COMSOL.
But this full resolution with the zoom has a cost on the amount of data to process and store per plot.
COMSOL does not seem to change the resampling resolution when zooming in a plot. This means lighter plots but potential pitfall as described here above.
So I have learned here to take care and get out min max and RMS on the raw data for all my critical plots ;)
--
Good luck
Ivar
Hi all Comeing back to this issue after having exchanged with my signal processing specialists. Their recommandation is to resample but keeping the min and the max per resampling bin. In this way one do not get filtering on the amplitudes. Still the integrals could be wrong. This seems to be what one sees in Matlab and in Excel but my other favorite ODE tool MapleSim seem to behave as COMSOL. But this full resolution with the zoom has a cost on the amount of data to process and store per plot. COMSOL does not seem to change the resampling resolution when zooming in a plot. This means lighter plots but potential pitfall as described here above. So I have learned here to take care and get out min max and RMS on the raw data for all my critical plots ;) -- Good luck Ivar

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.