Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Construct medium from a transfer function #1974

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

dmarek-flex
Copy link
Contributor

@dmarek-flex dmarek-flex commented Sep 23, 2024

Not sure if this is of interest to others, but when working on lumped elements I found that I needed to construct a PoleResidue medium given an admittance function in the Laplace domain, which is most commonly written as a rational expression. This might be useful in other cases where you would like to model a material that is not easily converted to PoleResidue format, but the differential equation governing the polarization current is available.

More precisely, given $\epsilon_\infty$ and an admittance relationship between electric field and a polarization current density

$$ J_p(s) = Y(s)E(s)$$

where

$$Y(s) = \frac{a_0 + a_1 s + \dots + a_M s^M}{b_0 + b_1 s + \dots + b_N s^N}$$

we can find an equivalent complex permittivity (assuming $Y(s)$ is causal, substitute $s = j \omega$)

$$\epsilon(\omega) = \epsilon_\infty - \frac{1}{\epsilon_0 j \omega}Y(j \omega).$$

Finally, we compute the poles and residues of $\frac{1}{\epsilon_0 j \omega}Y(j \omega)$ to convert it into a PoleResidue medium.

At this point I am just curious if this would be useful outside of lumped elements.

@dmarek-flex dmarek-flex force-pushed the dmarek/medium-from-transfer-function branch from ab7b508 to 857b25a Compare September 23, 2024 20:52
Copy link
Collaborator

@tylerflex tylerflex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment about scipy. otherwise looks good!

tidy3d/components/medium.py Show resolved Hide resolved
@tylerflex
Copy link
Collaborator

oh yea, and reminder to add changelog item for it

Copy link
Contributor

@caseyflex caseyflex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! My one suggestion would be that the name from_transfer_function is a bit ambiguous, I might think that a and b are just the numerator and denominator coeffs of eps(s) unless I read carefully. Maybe from_admittance_coeffs or something to make it clear that there is an additional step before partial fraction decomposition?

Actually, along those lines, maybe we can also split this function into two functions. One from_admittance_coeffs or something, and the other one can just be _real_partial_fraction_decomposition which does partial fraction decomposition using scipy and then takes only one representative of each complex conjugate pair.

@weiliangjin2021
Copy link
Collaborator

Nice work!

Actually, along those lines, maybe we can also split this function into two functions. One from_admittance_coeffs or something, and the other one can just be _real_partial_fraction_decomposition which does partial fraction decomposition using scipy and then takes only one representative of each complex conjugate pair.

I also feel it's better to split this function, so that one can apply it directly in other cases when it's not from a transfer function. E.g. it can be applied #1479 and partially (though not the best practice) #1240

tidy3d/components/medium.py Outdated Show resolved Hide resolved
tidy3d/components/medium.py Outdated Show resolved Hide resolved
tidy3d/components/medium.py Outdated Show resolved Hide resolved
tidy3d/components/medium.py Outdated Show resolved Hide resolved
tidy3d/components/medium.py Outdated Show resolved Hide resolved
@dmarek-flex dmarek-flex force-pushed the dmarek/medium-from-transfer-function branch from 857b25a to d4d43bf Compare September 24, 2024 21:30
@dmarek-flex dmarek-flex force-pushed the dmarek/medium-from-transfer-function branch from d4d43bf to cf89d31 Compare September 25, 2024 13:41
@dmarek-flex dmarek-flex force-pushed the dmarek/medium-from-transfer-function branch from cf89d31 to 4223a93 Compare September 25, 2024 20:37
@caseyflex
Copy link
Contributor

@weiliangjin2021 @dmarek-flex
In principle the partial fraction decomposition is uniquely defined, so if we start from a transfer function which is stable and passive, we obtain a pole residue model which is stable and passive. I wonder if this is numerically robust here? If we start with a pole on the frequency axis, could we end up finding a pole slightly below it? If we start with Im(eps) = 0, could we end up with Im(eps) < 0?

@dmarek-flex dmarek-flex force-pushed the dmarek/medium-from-transfer-function branch from 4223a93 to 7f237e8 Compare September 26, 2024 16:17
@dmarek-flex
Copy link
Contributor Author

@weiliangjin2021 @dmarek-flex In principle the partial fraction decomposition is uniquely defined, so if we start from a transfer function which is stable and passive, we obtain a pole residue model which is stable and passive. I wonder if this is numerically robust here? If we start with a pole on the frequency axis, could we end up finding a pole slightly below it? If we start with Im(eps) = 0, could we end up with Im(eps) < 0?

I assume that is a possibility, I was going to try and give a better answer, but could not find one! Instead I at least added more tests and validation to this convenience function to ensure that the supplied admittance transfer function is realizable from passive components. But it doesn't guarantee that the final computed PoleResidue medium will be passive over all frequencies if there is some kind of numerical error when computing residues and poles.

@dmarek-flex dmarek-flex force-pushed the dmarek/medium-from-transfer-function branch 3 times, most recently from 91bfbab to e5ff855 Compare September 26, 2024 18:23
@caseyflex
Copy link
Contributor

@weiliangjin2021 @dmarek-flex In principle the partial fraction decomposition is uniquely defined, so if we start from a transfer function which is stable and passive, we obtain a pole residue model which is stable and passive. I wonder if this is numerically robust here? If we start with a pole on the frequency axis, could we end up finding a pole slightly below it? If we start with Im(eps) = 0, could we end up with Im(eps) < 0?

I assume that is a possibility, I was going to try and give a better answer, but could not find one! Instead I at least added more tests and validation to this convenience function to ensure that the supplied admittance transfer function is realizable from passive components. But it doesn't guarantee that the final computed PoleResidue medium will be passive over all frequencies if there is some kind of numerical error when computing residues and poles.

Maybe you can check PoleResidue._imag_eps_extrema_with_samples to warn the user if the resulting model is not passive?

@dmarek-flex dmarek-flex force-pushed the dmarek/medium-from-transfer-function branch from e5ff855 to abd9bb9 Compare September 27, 2024 15:21
@dmarek-flex
Copy link
Contributor Author

@caseyflex Good idea, I added the test you suggested and at very high frequencies one of the admittance functions I was testing does show slight gain, although it is very small ~-1e-22. In fact, in this case I think it is numerical error when computing the complex permittivity that is causing a small negative part to appear. So I added a warning to the log when a gain term larger than machine precision is detected.

@caseyflex
Copy link
Contributor

caseyflex commented Sep 27, 2024 via email

… equation relating polarization current density to electric field
@dmarek-flex dmarek-flex force-pushed the dmarek/medium-from-transfer-function branch from abd9bb9 to 2e2ca56 Compare October 1, 2024 15:44
@dmarek-flex
Copy link
Contributor Author

I'm gonna merge this unless you have any final comments @tylerflex

Copy link
Collaborator

@tylerflex tylerflex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go for it!

@dmarek-flex dmarek-flex merged commit 87a0c58 into pre/2.8 Oct 1, 2024
15 checks passed
@dmarek-flex dmarek-flex deleted the dmarek/medium-from-transfer-function branch October 1, 2024 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants