Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

integration over frequency but keeping spatial dependency

Dear community,

Using the rf module I perform a frequency sweep. Now, I want to integrate the calculated absorption profile over the frequency, but keep the spatial dependency, ie no integration over the volume. Can anyone give me a tip/hint on how to do this?

Integration in 'derived values' in the 'results' part always seems to be a spatial integration (volume/surface/line) but not over other variables like frequency.

I also tried to make a global variable my_var=integrate(ewdf.Qe, freq,freqmin,freqmax) (with ewdf.Qe being the absorbed power, freqmin/freqmax minimal/maximal frequency I use) but that does not seem to be right. Comsol does not give an error message and calculates this variable, but when i plot it it is a different graph when I choose another frequency in the frequency list in the plotting window. This shouldn't be since I want to integrate over frequency and thus my_var should be frequency independent.

Any hints are very welcome,
Thanks and best regards,
Alex

7 Replies Last Post Oct 11, 2013, 6:58 AM EDT
Posted: 4 years ago Oct 7, 2013, 11:51 AM EDT
Hi,

A silly but effective trick:
1. Generate the table (freq appears at first column).
2. Save it as a text file.
3. Create an interpolation function, choosing the last text file. Say that you name it int1.
4. Update the model (with F5).
5. In "Results / Derived Values", just type (for one of the values of the parameter, for instance the first one):
integrate(int1(f), f, f1, f2)
where f1 and f2 are the lower and upper bounds of the integral.

But copying or exporting the table and integrating it in an external software (MATLAB, or even Excel) is extremely easy, you can resolve that numerical integration in few minutes.

Regards,
Jesus.
Hi, A silly but effective trick: 1. Generate the table (freq appears at first column). 2. Save it as a text file. 3. Create an interpolation function, choosing the last text file. Say that you name it int1. 4. Update the model (with F5). 5. In "Results / Derived Values", just type (for one of the values of the parameter, for instance the first one): integrate(int1(f), f, f1, f2) where f1 and f2 are the lower and upper bounds of the integral. But copying or exporting the table and integrating it in an external software (MATLAB, or even Excel) is extremely easy, you can resolve that numerical integration in few minutes. Regards, Jesus.

Posted: 4 years ago Oct 7, 2013, 4:35 PM EDT
Hi Jesus,

thanks for your reply.

Yes, I was also thinking of exporting and evaluating the integral outside of comsol. But the thing is: I'd export quite alot of points (3D and rather large computational domain with large fraction of the absorbing medium). The export-file for one frequency is already >300MB, exporting 2 frequencies already gives me the "Java Heap error" . I know i can change the java heap size somehow, but still I ususally have frequency sweeps of 50-100 freqs, so it just would be too much data which I think could be avoided if it was possible to handle all of this inside comsol.

I need:

b=b(x,y,z)=integral a(f,x,y,z) df

(lower int-limit: min_freq, upper int-limit max_freq, a=Absorption).

Any other suggestions on how to handle this? I have seen that a time-integral operator exists. Maybe there is a similar operator for frequency instead of time?

Best regards,
Alex
Hi Jesus, thanks for your reply. Yes, I was also thinking of exporting and evaluating the integral outside of comsol. But the thing is: I'd export quite alot of points (3D and rather large computational domain with large fraction of the absorbing medium). The export-file for one frequency is already >300MB, exporting 2 frequencies already gives me the "Java Heap error" . I know i can change the java heap size somehow, but still I ususally have frequency sweeps of 50-100 freqs, so it just would be too much data which I think could be avoided if it was possible to handle all of this inside comsol. I need: b=b(x,y,z)=integral a(f,x,y,z) df (lower int-limit: min_freq, upper int-limit max_freq, a=Absorption). Any other suggestions on how to handle this? I have seen that a time-integral operator exists. Maybe there is a similar operator for frequency instead of time? Best regards, Alex

Posted: 4 years ago Oct 8, 2013, 8:13 AM EDT
Hi,
Sorry for the misunderstanding. I had thought of a Global variable. But you explained it quite clear.
You could try to define an "algebraic" or ODE equation distributed over all the domain (or a PDE with all coefficients except f set to 0), for a variable b, with the expression (for f):
a - d(b, freq) .
If that works, after the solution you would have b(x, y, z), i.e., the integration of "a" over frequency.

Perhaps that could work.
Hi, Sorry for the misunderstanding. I had thought of a Global variable. But you explained it quite clear. You could try to define an "algebraic" or ODE equation distributed over all the domain (or a PDE with all coefficients except f set to 0), for a variable b, with the expression (for f): a - d(b, freq) . If that works, after the solution you would have b(x, y, z), i.e., the integration of "a" over frequency. Perhaps that could work.

Posted: 4 years ago Oct 8, 2013, 11:45 AM EDT
Hi,

Thanks for your suggestion, very much appreciated!

I tried your suggestion (ODE equation "a - d(b, freq)"), but it seems that either

...when adding an additional study to evaluate that additional ODE: comsol does not know about 'a' (=Absorption=efwd.Qe) during solving, it gives the error message "cannot evaluate expression" and "cannot evaluate variable efwd.Qe".

...when adding an additional study step in the same study in which the electric fields are solved: comsol just gives zero for the variable i look for

I am wondering if there is any way to let comsol do the integration after solving. It shouldn't involve an additional solving step, since it does not need solve again, just evaluate / process the solutions.

Best regards
Hi, Thanks for your suggestion, very much appreciated! I tried your suggestion (ODE equation "a - d(b, freq)"), but it seems that either ...when adding an additional study to evaluate that additional ODE: comsol does not know about 'a' (=Absorption=efwd.Qe) during solving, it gives the error message "cannot evaluate expression" and "cannot evaluate variable efwd.Qe". ...when adding an additional study step in the same study in which the electric fields are solved: comsol just gives zero for the variable i look for I am wondering if there is any way to let comsol do the integration after solving. It shouldn't involve an additional solving step, since it does not need solve again, just evaluate / process the solutions. Best regards

Posted: 4 years ago Oct 8, 2013, 2:31 PM EDT
Hi, Alex,

I didn't mean to add a study, but to add a physics like "PDE Coefficient Form". And by "a" I meant your integrand variable (absorption?). I have tried something similar (in a simple 2D model), and it seems to work. I added a "Coefficient Form PDE" with dependent variable "b", and with coefficients all set to zero, except:

f (source term), set to "d(b,freq) - absor", where "absor" is your integrand (absorption?), and
a (absorption coefficient), set to a very small value, say 0.00001 . Try with lower values.

Once you have the solution (also for "b"), you can just compute (for instance show as a color plot) "b(freq2) - b(freq1)".

Regards,
Jesus.
Hi, Alex, I didn't mean to add a study, but to add a physics like "PDE Coefficient Form". And by "a" I meant your integrand variable (absorption?). I have tried something similar (in a simple 2D model), and it seems to work. I added a "Coefficient Form PDE" with dependent variable "b", and with coefficients all set to zero, except: f (source term), set to "d(b,freq) - absor", where "absor" is your integrand (absorption?), and a (absorption coefficient), set to a very small value, say 0.00001 . Try with lower values. Once you have the solution (also for "b"), you can just compute (for instance show as a color plot) "b(freq2) - b(freq1)". Regards, Jesus.

Posted: 4 years ago Oct 10, 2013, 7:22 AM EDT
Hi Jesus,

yes, i got you, sorry for the confusion.

Thanks for your suggestions. Your approach looked very promising, and I tried it out / several things based on your approach. But I see some problems:

First, when including an additional PDE, solving time is more than doubled compared to only solving for the EM fields (ok, i could live with this).

It still feels somehow wrong: why does the variable i am after need to be solved for? Basically it should just be a simple algorithm: Adding all the absorption profiles (multiplicated with delta frequency) together, or in other words, get the area under the graph of the absorption profile plotted agains frequency (for each spatial point though to keep the spatial dependency).

Second, the results I get by the suggested approach are wrong: b(f2)-b(1) (with f2>f1) can be positive or negative depending on f1 and f2. Since b basically is the summed up abosrption it should always be the same sign (+/- depending on convention)

Any further comments very welcome!
Best regards,
Alex
Hi Jesus, yes, i got you, sorry for the confusion. Thanks for your suggestions. Your approach looked very promising, and I tried it out / several things based on your approach. But I see some problems: First, when including an additional PDE, solving time is more than doubled compared to only solving for the EM fields (ok, i could live with this). It still feels somehow wrong: why does the variable i am after need to be solved for? Basically it should just be a simple algorithm: Adding all the absorption profiles (multiplicated with delta frequency) together, or in other words, get the area under the graph of the absorption profile plotted agains frequency (for each spatial point though to keep the spatial dependency). Second, the results I get by the suggested approach are wrong: b(f2)-b(1) (with f2>f1) can be positive or negative depending on f1 and f2. Since b basically is the summed up abosrption it should always be the same sign (+/- depending on convention) Any further comments very welcome! Best regards, Alex

Posted: 4 years ago Oct 11, 2013, 6:58 AM EDT
Hi, Alex

If you could upload your file (better, a 2D simplified version of it), perhaps we could help you.

Regards,
Jesus.
Hi, Alex If you could upload your file (better, a 2D simplified version of it), perhaps we could help you. Regards, Jesus.

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.