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

Fully anisotropic materials #846

Merged
merged 4 commits into from
May 18, 2023
Merged

Fully anisotropic materials #846

merged 4 commits into from
May 18, 2023

Conversation

dbochkov-flexcompute
Copy link
Contributor

@dbochkov-flexcompute dbochkov-flexcompute commented Apr 18, 2023

Frontend interface for fully anisotropic materials:

  • Since AnisotropicMedium was already taken, fully anisotropic materials are called FullyAnisotropicMedium
  • Currently only materials for which main directions of permittivity and conductivity (symmetric part) tensors coincide (to have well-defined main complex permittivities)
  • A helper class RotationAroundAxis(AbstractRotation) is implemented for convenient rotation of tensors in space. In future we can add more methods like RotationEulerAngles(AbstractRotation), etc.
  • Automatic mesher now takes into account only the max eps among all directions (previous treatment based on normal direction resulted in underresolving because tangential direction define wavelength)
  • For now injection of plane waves and gaussian beams into anisotropic materials is prohibited
  • When plotted, FullyAnisotropicMedium returns main components
  • Slight modification of ModeSolver so that it is feeded with the full permittivity tensor
  • To help that new method eps_comp is introduced in material classes to retrieve a specified component of a permittivity tensor

Review todo's:

  • Unify rotation functionality
  • Generalize ArrayLike
  • Standardize order of components in mode solver
  • changelog
  • unify plotting for AnisotropicMedium and FullyAnisotropicMedium
  • converge on naming/unification of AnisotropicMedium and FullyAnisotropicMedium

@dbochkov-flexcompute dbochkov-flexcompute self-assigned this Apr 18, 2023
@dbochkov-flexcompute dbochkov-flexcompute force-pushed the daniil/fully-anisotropic branch 3 times, most recently from ea73ee4 to 1f168da Compare April 19, 2023 04:14
@dbochkov-flexcompute dbochkov-flexcompute changed the base branch from develop to pre/2.2 April 19, 2023 04:50
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.

Looks really good, thanks Daniil for this long awaited and critical feature.

A few general things to discuss:

  • Add item in changelog
  • compatibility with old AnisotropicMedium: the naming conflict is a pain. But it does seem that these two have different functionality (eg can fully anisotropic handle dispersive?) so they should be separate. However, I do wish that we could have called this one AnisotropicMedium and the diagonal one DiagonallyAnisotropicMedium or something. in the future, are we planning to keep both separate or merge them? If merge, when we get closer to that, we can add a deprecation warning to encourage people to switch to the more general syntax given what we decide.
  • Can RotationAroundAxis be used in some of the geometry handling? We currently have some rotation code there, but I think it would be nice to unify things.

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
@@ -2579,7 +2595,10 @@ def make_eps_data(coords: Coords):
return xr.DataArray(eps_array, coords=coords, dims=("x", "y", "z"))

# combine all data into dictionary
coords = grid[coord_key]
if coord_key[0] != "E":
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe a bit simpler to do

if coord_key[0] == "E":
    coord_key = coord_key[0:2]
coords = grid[coord_key]
return make_eps_data(coords)

although I',m not exactly sure what this bit is doing exactly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this part a little bit to try to make it more clear.
Here I'm trying to generalize epsilon_on_grid(..., coord_key: str, ...) to be able to return off-diagonal components too. The way I did this is that in addition to coord_key = "Ex", "Ey", "Ez" we can also call coord_key = "Exy", "Exz", "Eyx", ... which would return a corresponding off-diagonal component but still at an Yee location (e.g., eps_xy at Ex). So, for those keys I just remove the last letter.

What I'm a bit hesitant about is that:

  • things like Ezy are not proper physical concepts
  • from efficiency point of view, maybe it would make more sense to add a separate flag include_off_diag, and then coord_key="Ex", include_off_diag=True would return three arrays eps_xx, eps_xy, eps_xz

tidy3d/components/structure.py Outdated Show resolved Hide resolved
tidy3d/plugins/mode/mode_solver.py Outdated Show resolved Hide resolved
tidy3d/plugins/mode/mode_solver.py Show resolved Hide resolved
tidy3d/components/types.py Outdated Show resolved Hide resolved
def _source_homogeneous(cls, val, values):
"""Error if a plane wave or gaussian beam source is not in a homogeneous region."""
def _source_homogeneous_isotropic(cls, val, values):
"""Error if a plane wave or gaussian beam source is not in a homogeneous and isotropic
Copy link
Collaborator

Choose a reason for hiding this comment

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

TFSF should also error if the box crosses any anisotropic region?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, added

@dbochkov-flexcompute
Copy link
Contributor Author

@tylerflex :

Can RotationAroundAxis be used in some of the geometry handling? We currently have some rotation code there, but I think it would be nice to unify things.

You must be talking about this https://github.com/flexcompute/tidy3d/blob/daniil/fully-anisotropic/tidy3d/components/geometry.py#L635? You're right, it's actually a specific case of RotationAroundAxis when it is strictly along one of the Cartesian directions. I'll think how to unify them.

compatibility with old AnisotropicMedium: the naming conflict is a pain. But it does seem that these two have different functionality (eg can fully anisotropic handle dispersive?) so they should be separate. However, I do wish that we could have called this one AnisotropicMedium and the diagonal one DiagonallyAnisotropicMedium or something. in the future, are we planning to keep both separate or merge them? If merge, when we get closer to that, we can add a deprecation warning to encourage people to switch to the more general syntax given what we decide.

One way how AnisotropicMedium and FullyAnisotropicMedium can be unified is by just adding additional field rotation to AnisotropicMedium. In this case a user won't be able to provide permittivity and conductivity as tensors, but (1) I already impose quite strict restriction on that (only tensor with coinciding main direction are allowed, so that there is a well defined main complex epsilons), and (2) this is how some other FDTD packages do

@momchil-flex
Copy link
Collaborator

One way how AnisotropicMedium and FullyAnisotropicMedium can be unified is by just adding additional field rotation to AnisotropicMedium. In this case a user won't be able to provide permittivity and conductivity as tensors, but (1) I already impose quite strict restriction on that (only tensor with coinciding main direction are allowed, so that there is a well defined main complex epsilons), and (2) this is how some other FDTD packages do

A gyrotropic medium with external magnetic field will have a tensorial conductivity in every axis orientation, no?

@dbochkov-flexcompute
Copy link
Contributor Author

One way how AnisotropicMedium and FullyAnisotropicMedium can be unified is by just adding additional field rotation to AnisotropicMedium. In this case a user won't be able to provide permittivity and conductivity as tensors, but (1) I already impose quite strict restriction on that (only tensor with coinciding main direction are allowed, so that there is a well defined main complex epsilons), and (2) this is how some other FDTD packages do

A gyrotropic medium with external magnetic field will have a tensorial conductivity in every axis orientation, no?

Yeah, I forgot to mention that we would also need a field to specify gyrotropic part of permittivity, which could be defined as gyration vector g = (gx, gy, gz), which I guess typically is assumed to be proportional to external magnetic field. Then total complex permittivity becomes eps = eps_re - 1j * sigma / omega - 1j * G, where antisymmetric matrix G = [[0, gz, -gy], [-gz, 0, gx], [gy, -gx, 0]]. In terms of permittivity and conductivity: permittivity = eps_re, conductivity = sigma + G * omega.

So, eventually we have something like

medium = td.AnistropicMedium(
    xx=td.Medium(permittivity=2),
    yy=td.Medium(permittivity=3, conductivity=1),
    zz=td.Medium(permittivity=4),
    gyration=(1,2,3),
    rotation=td.RotationAroundAxis(axis=(1,1,0), angle=np.pi/3),
)

where we would need to decide whether gyration vector is given in coordinates before or after rotation (probably before)

@dbochkov-flexcompute dbochkov-flexcompute force-pushed the daniil/fully-anisotropic branch 2 times, most recently from 5faede6 to 4ea819b Compare April 27, 2023 17:24
@dbochkov-flexcompute
Copy link
Contributor Author

I think I've addressed all the comments so far, in case you want to give these corrections a look

@momchil-flex momchil-flex merged commit 235174b into pre/2.2 May 18, 2023
@dbochkov-flexcompute dbochkov-flexcompute deleted the daniil/fully-anisotropic branch September 5, 2023 23:59
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.

None yet

3 participants