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

add WavePorts #1741

Open
wants to merge 1 commit into
base: pre/2.8
Choose a base branch
from
Open

add WavePorts #1741

wants to merge 1 commit into from

Conversation

dmarek-flex
Copy link
Contributor

@dmarek-flex dmarek-flex commented Jun 5, 2024

add a new type of port to the TerminalComponentModeler. WavePorts are the optimal port for exciting transmission lines, and they function like a hybrid between LumpedPorts and the modal-based Port.

Still a work in progress.

Here are some thoughts:

  • Not sure the best way to make the computed port impedances available to users. Computing the port impedances requires mode solving which is launched through ModeSolverMonitors along with the tidy3d simulations. However, some users might want to know the impedances beforehand or inspect modes before launching the simulations.
  • I have changed some of the naming to reflect that the ports of the TerminalComponentModeler are based on pairs of terminals ( a positive and negative connection or node in the circuit). LumpedPorts and WavePort are then both TerminalPorts
  • I realized it is helpful to add names and possibly attrs to DataArrays that I am creating. Maybe I should put all of these DataArrays into the microwave plugin or the Tidy3D files.

@dmarek-flex dmarek-flex self-assigned this Jun 5, 2024
@dmarek-flex dmarek-flex added the 2.8 will go into version 2.8.* label Jun 5, 2024
@dmarek-flex dmarek-flex marked this pull request as draft June 5, 2024 16:05
@dmarek-flex dmarek-flex changed the base branch from pre/2.7 to develop June 12, 2024 16:48
@dmarek-flex
Copy link
Contributor Author

@weiliangjin2021 @QimingFlex Still a bit rough at the moment in terms of docstrings and other details. But if you want to take a look over the next week while I am validating the accuracy, I am ready for feedback.

Copy link
Collaborator

@weiliangjin2021 weiliangjin2021 left a comment

Choose a reason for hiding this comment

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

1st pass through the code. I'll definitely need to take several more rounds to have a better understanding. Very cool to see all components stick together! One main question is if we should support multiple ways of computing impedance: using any two quantities of V, I, P.

tidy3d/plugins/microwave/impedance_calculator.py Outdated Show resolved Hide resolved
tidy3d/plugins/smatrix/ports/coaxial_lumped.py Outdated Show resolved Hide resolved
@dmarek-flex
Copy link
Contributor Author

One main question is if we should support multiple ways of computing impedance: using any two quantities of V, I, P.

Yeah, it is all hidden away in the ImpedanceCalculator. User can provide any definition of voltage they want (by defining the associated voltage path integral). Same goes for current computation. If both integrals are provided, the impedance is computed as expected V/I. If only one is provided, the ImpedanceCalculator will revert to using the total flux the indirectly compute the other quantity. If none are provided, a ValidationError gets raised.

@dmarek-flex dmarek-flex marked this pull request as ready for review June 18, 2024 20:07
@dmarek-flex
Copy link
Contributor Author

1st pass through the code. I'll definitely need to take several more rounds to have a better understanding. Very cool to see all components stick together! One main question is if we should support multiple ways of computing impedance: using any two quantities of V, I, P.

Might help for your review to check out this notebook.

Copy link
Collaborator

@weiliangjin2021 weiliangjin2021 left a comment

Choose a reason for hiding this comment

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

Went through another pass. All look quite nice to me! I'm still wondering if we have a way to compute currents that doesn't need contour path integration. One way that I can think of is as follows (but don't know if it works well):

  • On the modal plane (let's assume it to be xy-plane), compute J at every grid point through J = Curl H. Next we integrate Jz over the entire modal plane. During the integration, we integrate only positive or negatie Jz, as otherwise the current cancels out. So it's int dS Heaviside(J_Z) J_z. Does it agree with the contour path approach for TEM mode?

Some minor comments:

  • It'll be very helpful to also visualize voltage/current integration path in the plot.
  • For voltage integration path, in many cases, it is an straight line. When it's axis-aligned, it'll be more convenient to allow the definition through 2 endpoints?

tidy3d/plugins/smatrix/ports/wave.py Show resolved Hide resolved
tidy3d/plugins/smatrix/ports/wave.py Outdated Show resolved Hide resolved
@dmarek-flex
Copy link
Contributor Author

dmarek-flex commented Jun 25, 2024

  • On the modal plane (let's assume it to be xy-plane), compute J at every grid point through J = Curl H. Next we integrate Jz over the entire modal plane. During the integration, we integrate only positive or negatie Jz, as otherwise the current cancels out. So it's int dS Heaviside(J_Z) J_z. Does it agree with the contour path approach for TEM mode?

That could work, and it seems like a discrete version of Stoke's theorem, so should be equivalent. It is also probably an easier way to implement the computation on the Yee grid when the conductors are complicated shapes. I don't think that I could use that method for computing currents at the ports though, because we do not know whether the current is flowing into or out of the port before computing. Could be used for compute Z0 when we can assume the propagation direction.

However, since it seems possible to apply this to more complex shapes more easily, I think I will try. We could still make the user define a path around the conductor of interest. Instead of computing the line integral though, we compute the current inside the contour using curl H.

  • It'll be very helpful to also visualize voltage/current integration path in the plot.

Yes, good idea! I'll experiment.

  • For voltage integration path, in many cases, it is an straight line. When it's axis-aligned, it'll be more convenient to allow the definition through 2 endpoints?

So do you mean an option to create path integrals given P1(x1,y1,z1) and P2(x2,y2,z2) and just ensure that that it is axis aligned with a validator? If so I can do that!

@weiliangjin2021
Copy link
Collaborator

So do you mean an option to create path integrals given P1(x1,y1,z1) and P2(x2,y2,z2) and just ensure that that it is axis aligned with a validator? If so I can do that!

Hopefully we can also support axis-unaligned straight path. But you mentioned there is complication for that

@dmarek-flex
Copy link
Contributor Author

So do you mean an option to create path integrals given P1(x1,y1,z1) and P2(x2,y2,z2) and just ensure that that it is axis aligned with a validator? If so I can do that!

Hopefully we can also support axis-unaligned straight path. But you mentioned there is complication for that

Agreed, at least we can easily swap out implementations for voltage and current integrals easily. But that is an improvement that is needed.

@dmarek-flex dmarek-flex changed the base branch from develop to pre/2.8 June 27, 2024 14:48
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.

thanks @dmarek-flex . Looks overall good to me. Although I can't follow many of the specific details.

tidy3d/plugins/microwave/custom_path_integrals.py Outdated Show resolved Hide resolved
tidy3d/plugins/microwave/path_integrals.py Show resolved Hide resolved
tidy3d/plugins/smatrix/component_modelers/base.py Outdated Show resolved Hide resolved
@dmarek-flex
Copy link
Contributor Author

dmarek-flex commented Jul 4, 2024

It'll be very helpful to also visualize voltage/current integration path in the plot.

Just adding some tests, but path integrals can be plotted now.
Screenshot from 2024-07-04 15-38-47

added path integral plotting functionality

added convenience function for voltage integral
@weiliangjin2021
Copy link
Collaborator

It'll be very helpful to also visualize voltage/current integration path in the plot.

Just adding some tests, but path integrals can be plotted now. Screenshot from 2024-07-04 15-38-47

Nice figure!

@@ -73,18 +73,15 @@ def _plot(*args, **kwargs) -> Ax:
""" plot parameters """


class PlotParams(Tidy3dBaseModel):
"""Stores plotting parameters / specifications for a given model."""
class AbstractPlotParams(Tidy3dBaseModel):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tylerflex Might want to check my changes here which I used for plotting the path integrals

@@ -684,6 +684,29 @@ def parse_xyz_kwargs(**xyz) -> Tuple[Axis, float]:
axis = "xyz".index(axis_label)
return axis, position

@staticmethod
def parse_two_xyz_kwargs(**xyz) -> List[Tuple[Axis, float]]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tylerflex also here which might affect others


MonitorDataTypes = Union[FieldData, FieldTimeData, ModeSolverData]
EMScalarFieldType = Union[ScalarFieldDataArray, ScalarFieldTimeDataArray, ScalarModeFieldDataArray]
IntegralResultTypes = Union[FreqDataArray, FreqModeDataArray, TimeDataArray]


def _check_em_field_supported(em_field: Any):
Copy link
Contributor Author

@dmarek-flex dmarek-flex Jul 5, 2024

Choose a reason for hiding this comment

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

@weiliangjin2021 @tylerflex I wonder if you have any ideas for checking class method parameters. I was experimenting with decorators and looked into pydantic support. decorators mess up the docs and pydantic support does not work in our version, I think in V2 it will be supported.

Copy link
Collaborator

Choose a reason for hiding this comment

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

as far as I understand, we use decorators for this kind of thing in a few places, but agree it's not great for the docs.
https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/components/medium.py#L95

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.8 will go into version 2.8.*
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants