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.

running integration of variable in time domain

Please login with a confirmed email address before reporting spam

Hi everybody

Short version: How to do a running integration/averaging of a time-dependent variable on a fixed length time interval? E.g. from time-dependent variable v I want to calculate a new variable vhat given by: vhat(t) = integral of v(t) from t-T0 to t, where T0 is a fixed time period

Long version: I have a solution from a time dependent study, Comsol 4.4. It is a driven non-linear acoustic system. The driving force has frequency f0 and thus oscillation period T0=1/f0. The result for some variable "v" is varying in time. I want to extract the "slowly-varying" component of v, that being variations on time scales larger than T0. To do that I want to do a running averaging of v, which is stored in a new variable vhat defined by vhat(t) = integral of v(t) from t-T0 to t. Thus vhat is the averaged of v over the last oscillation period.
Now it seems that this can be done in the postprocessing by use of the "timeavg"
function, e.g. timeavg(t-T0,t,v). However, this is very slow and only work in postprocessing.
Is there a way to calculate vhat as part of the model, such as through a mathematics physics? (i.e. not as postprocessing)

Kind regards,
Peter Muller

ps. there is a simple way to calculate the integral from start, t=0, to the current time t, linked here www.comsol.com/support/knowledgebase/913/ . However this is not exactly what I want to do.

pps. Ivar if you are out there, you referred to doing this in a post several years ago, if you have a smart way to implement it I would be very glad to hear about it.
link: www.comsol.dk/community/forums/general/thread/4706/
Quote by Ivar in linked discussion: "Clearly if you know the periode, you can take a running integration of one periode and plot that, then you get rid of the main oscillations".

8 Replies Last Post 22.07.2015, 02:48 GMT-4
Sergei Yushanov Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 10 years ago 08.12.2014, 09:12 GMT-5
Peter,

You can use Domain ODE and DAEs (dode) interface to perform this integration, as shown in the attached image.

Regards,
Sergei
Peter, You can use Domain ODE and DAEs (dode) interface to perform this integration, as shown in the attached image. Regards, Sergei


Please login with a confirmed email address before reporting spam

Posted: 10 years ago 09.12.2014, 03:35 GMT-5
Thank you for the comment Sergei, however as I understand it, your suggestion would make vhat define by
vhat(t) = integral of v(t) from T0 to t, (Sergei's suggestion)
and not
vhat(t) = integral of v(t) from t-T0 to t, (what I wish to achieve)
as I would like it to be.
If I am wrong please explain it to me.

The question is still open for suggestions.
Thank you for the comment Sergei, however as I understand it, your suggestion would make vhat define by vhat(t) = integral of v(t) from T0 to t, (Sergei's suggestion) and not vhat(t) = integral of v(t) from t-T0 to t, (what I wish to achieve) as I would like it to be. If I am wrong please explain it to me. The question is still open for suggestions.

Sergei Yushanov Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 10 years ago 09.12.2014, 10:53 GMT-5
Peter,

To calculate integral of v(t) from t-T0 to t, you can define two functions using Domain ODE and DAEs:

vhat1(t)= integral of v(t) from 0 to t, with Source Term f=v

and

vhat2(t)= integral of v(t) from 0 to t-T0, with Source Term f=v*(t<=T0)

Then final result is

vhat(t)= vhat1(t)-vhat2(t)

Regards,
Sergei
Peter, To calculate integral of v(t) from t-T0 to t, you can define two functions using Domain ODE and DAEs: vhat1(t)= integral of v(t) from 0 to t, with Source Term f=v and vhat2(t)= integral of v(t) from 0 to t-T0, with Source Term f=v*(t

Sergei Yushanov Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 10 years ago 09.12.2014, 11:03 GMT-5
Peter,

Actually, final result should be

vhat(t)= ( vhat1(t)-vhat2(t) )*(t>=T0)

Regards,
Sergei
Peter, Actually, final result should be vhat(t)= ( vhat1(t)-vhat2(t) )*(t>=T0) Regards, Sergei

Please login with a confirmed email address before reporting spam

Posted: 10 years ago 10.12.2014, 10:50 GMT-5
Thanks again for your effort to help me Sergei. I think your idea is good, I agree on the method of vhat(t)= ( vhat1(t)-vhat2(t) )*(t>=T0), and it brought me one step closer to what I want, however, the differential equation
partial_t vhat2(t) = v*(t<=T0), which you proposed, will as I see it define vhat2(t) as
vhat2(t) = time integral of v(t) from 0 to t, for t<=T0 and
vhat2(t) = time integral of v(t) from 0 to T0, for t>T0,
and thus not as we desired
vhat2(t) = time integral of v(t) from 0 to t-T0.
I am not sure how to do this integral.

Once again thank you for contributing Sergei, I welcome any further ideas you have.

The question is still open for suggestions

Thanks again for your effort to help me Sergei. I think your idea is good, I agree on the method of vhat(t)= ( vhat1(t)-vhat2(t) )*(t>=T0), and it brought me one step closer to what I want, however, the differential equation partial_t vhat2(t) = v*(t

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 14.07.2015, 13:39 GMT-4
Have you considered using the timeint operator?
Have you considered using the timeint operator?

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 21.07.2015, 09:01 GMT-4
Hi Daniel

thank you for your contribution, but timeint works the same way as timeavg which I commented on in the original post as being very slow and only available in postprocessing
"Now it seems that this can be done in the postprocessing by use of the "timeavg"
function, e.g. timeavg(t-T0,t,v). However, this is very slow and only work in postprocessing."

I ended up doing postprocessing in Matlab instead, as I found no good solution to this problem in Comsol GUI.

Peter
Hi Daniel thank you for your contribution, but timeint works the same way as timeavg which I commented on in the original post as being very slow and only available in postprocessing "Now it seems that this can be done in the postprocessing by use of the "timeavg" function, e.g. timeavg(t-T0,t,v). However, this is very slow and only work in postprocessing." I ended up doing postprocessing in Matlab instead, as I found no good solution to this problem in Comsol GUI. Peter

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 22.07.2015, 02:48 GMT-4
Hi Peter

the only way (I know) to define INFINITE integral variable "vhat" to be used during the solver process is the way presented by Sergey: via a specific ODE or DEA.
But if I read you correctly you want a DEFINITE integral, so you have the issue how to define T0 during the solver advances and either take the difference, or to "reset" vhat at the optimum "t=T0". If you do not know the T0 value in advance it's tricky as you add in conditional testing's during the solver sequence (not sure if this is possible, have never tried)

For post-processing COMSOL has now implemented all these nice new operators timeint, timeavg ... I agree they are "slow" but the Data Sets are often really large. You can speed them up somewhat if you select a simple trapeze or triangular integration instead of the higher order polynomial one, or as you say by using Matlab to extract once just a sub array from the data set and then to process that

--
Good luck
Ivar
Hi Peter the only way (I know) to define INFINITE integral variable "vhat" to be used during the solver process is the way presented by Sergey: via a specific ODE or DEA. But if I read you correctly you want a DEFINITE integral, so you have the issue how to define T0 during the solver advances and either take the difference, or to "reset" vhat at the optimum "t=T0". If you do not know the T0 value in advance it's tricky as you add in conditional testing's during the solver sequence (not sure if this is possible, have never tried) For post-processing COMSOL has now implemented all these nice new operators timeint, timeavg ... I agree they are "slow" but the Data Sets are often really large. You can speed them up somewhat if you select a simple trapeze or triangular integration instead of the higher order polynomial one, or as you say by using Matlab to extract once just a sub array from the data set and then to process that -- 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.