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.

Taking a derivative over custom variable

Please login with a confirmed email address before reporting spam

Hello,

I'm using wave optics module, and I came across a problem of calculating effective refractive index (n_eff) in bent waveguide. n_eff for straight and bent waveguides are different, so I can’t use results from boundary mode analysis.

Ultimately, I solved it in an awkward way: 1. Since electric field (Ez) is a sinus I got its phase as atan2[imag(ewfd.Ez),real(ewfd.Ez)] 2. Plotted it over my arc length L (the waveguide is bent) 3. Copied plot data to a table, which provided 2 columns – L and phase. 4. Used an interpolation function with the table I got as data source, which provided a function of phase over L… 5. … so I could take a derivative of it over L with operator d, and calculate n_eff.

What I initially wanted to be able to do is use the differentiation operator d(y,x) right away, like this: d(phase,L). Unfortunately, it does not work – it returns zero, as if phase is not dependent on L. And it doesn’t matter what L actually equals – I can put there simply x and it won’t work, has something to do with how the operator d(y,x) is coded. However, when I create the dependance with a plot and use an interpolated function (as I described above) so it looks like d(int1(L),L) – it works.

What I want is to get this result automatically, without using tables. Because tables are not dynamic, you have to remake them every time the model changes. But interpolation function only accepts tables (or files, which is even worse) as input. So my question is – can I make a dependency without manual exports, or is there a way to make the differentiation operator d(y,x) see the dependency on a custom variable, or is there some other way to take a derivative?

I’ve come up with another solution, where I take derivatives over x and y independently, and then take a square root over the sum of squares: sqrt[d(phase,x)^2 + d(phase,y)^2]. But the results I get from this seem off. My guess is it depends on the mesh too much, and since I’m running geometry swipes, I’m not completely sure I can trust this.


0 Replies Last Post 10 févr. 2021, 07:42 UTC−5
COMSOL Moderator

Hello Mikhail Vorobjov

Your Discussion has gone 30 days without a reply. If you still need help with COMSOL and have an on-subscription license, please visit our Support Center for help.

If you do not hold an on-subscription license, you may find an answer in another Discussion or in the Knowledge Base.

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.