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

Updating fields #11

Closed
tiagovla opened this issue Jan 23, 2021 · 3 comments
Closed

Updating fields #11

tiagovla opened this issue Jan 23, 2021 · 3 comments

Comments

@tiagovla
Copy link

# grid.py
def update_E(self):
        """ update the electric field by using the curl of the magnetic field """

        curl = curl_H(self.H)
        self.E += self.courant_number * self.inverse_permittivity * curl

        # update objects
        for obj in self.objects:
            obj.update_E(curl)

Here you update E for the whole grid. Then you update E inside the objects, changing E in-place, locally.

#objects.py
def update_E(self, curl_H):
        """ custom update equations for inside the anisotropic object
        Args:
            curl_H: the curl of magnetic field in the grid.
        """
        loc = (self.x, self.y, self.z)
        self.grid.E[loc] *= (1 - self.absorption_factor) / (1 + self.absorption_factor)
        self.grid.E[loc] += (
            self.grid.courant_number
            * self.inverse_permittivity
            * curl_H[loc]
            / (1 + self.absorption_factor)
        )

Aren't you doing it twice?

# first time
    E += c*dt*inv(ε)*curl(H)
# second time
    f = 0.5*dt*σ
    E *= inv(1 + f) * (1 - f)
    E += inv(1 + f)*sc*inv(ε)*curl_H
@flaport
Copy link
Owner

flaport commented Jan 25, 2021

No, when adding an object to the grid, the inverse_permittivity at the location of the object is set to zero:

self.grid.inverse_permittivity[self.x, self.y, self.z] = 0

This means that effectively, only the second update equation is used at the location of the object.

@flaport flaport closed this as completed Jan 25, 2021
@estebvac
Copy link

Hi flaport,
In that sense, wasn't it better if the method _register_grid in object.py set the permittivity of the object directly in the grid. Repeating calculations can be critical when the simulation size is bigger.

@flaport
Copy link
Owner

flaport commented Aug 21, 2022

That's a fair point and in fact nothing is stopping you to do exactly that... Just do an in-place index replacement within inverse_epsilon...

The reason that I chose the Object route is that back in the day I was working on simulating photo-refractive crystals in which I was also modeling the electro-optic effect. Moreover those objects required non-diagonal epsilon elements which is a much more expensive update. Going the object-route allowed me to just have those expensive update equations in a localized component and still use the quick update equations everywhere else in the grid.

That said, for normal use cases a replacement in the grid is a much better approach and I agree we should probably make that the default.

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

No branches or pull requests

3 participants