question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

removing objects doesn't reset grid permittivity

See original GitHub issue

Very cool project! I look forward to seeing where it goes.

Small observation here, after playing around a little bit:
When you add an object, and then later remove it, you end up with a section of the grid with altered permittivity, but without an object present in the visualization. Lacking a grid.remove_object() method, I naively just popped the object from grid.objects… and used grid.reset(). but obviously, that doesn’t undo the changes to the grid that occurred when the object was registered.

I’d definitely understand if support for removing items (rather than just re-instantiating a new grid) was low priority for now, but just figured I’d mention it. thanks again!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
0xDBFB7commented, Jun 5, 2020

@Kiranalu There’s an even easier method; use the pyEVTK library and Paraview!

    def dump_to_vtk(self, filename, iteration, Ex_dump=False, Ey_dump=False, Ez_dump=False, Emag_dump=True, objects_dump=True, ports_dump=True):
        '''
        Extension is automatically chosen, you don't need to supply it

        thanks
        https://pyscience.wordpress.com/2014/09/06/numpy-to-vtk-converting-your-numpy-arrays-to-vtk-arrays-and-files/
        https://bitbucket.org/pauloh/pyevtk/src/default/src/hl.py

        Paraview needs a threshold operation to view the objects correctly.

        '''


        x = np.linspace(0, self.cell_size*self.grid.Nx, self.grid.Nx+1) #there might be an off-by-one error here.
        y = np.linspace(0, self.cell_size*self.grid.Ny, self.grid.Ny+1)
        z = np.linspace(0, self.cell_size*self.grid.Nz, self.grid.Nz+1)

        cellData = {}

        if(not isinstance(fdtd.backend, NumpyBackend)):
            E_copy = self.grid.E.cpu()
        else:
            E_copy = self.grid.E

        if(objects_dump):
            objects = np.zeros_like(E_copy[:,:,:,X])
            for obj in self.grid.objects:
                objects[obj.x.start:obj.x.stop, obj.y.start:obj.y.stop, obj.z.start:obj.z.stop] = 1
            cellData['objects'] = objects

        if(Ex_dump):
            cellData['Ex'] = np.ascontiguousarray(E_copy[:,:,:,X])
        if(Ey_dump):
            cellData['Ey'] = np.ascontiguousarray(E_copy[:,:,:,Y])
        if(Ez_dump):
            cellData['Ez'] = np.ascontiguousarray(E_copy[:,:,:,Z])
        if(Emag_dump):
            cellData['Emag'] = np.ascontiguousarray(self.E_magnitude(E_copy)) # gridToVTK expects a contiguous array.


        gridToVTK(filename + str(iteration), x, y, z, cellData = cellData)

Paraview makes very pretty videos.

woot

1reaction
0xDBFB7commented, May 30, 2020

@Kiranalu I don’t know how the OP did it, but something like this might work (untested):

for i in range(0, N_timesteps):
    grid.step()
    grid.visualize(show=False)
    plt.savefig(str(i) + ".png")

and then use something like ffmpeg to make the .png images into a movie.

Matplotlib also has an animation module that might be easier, but I haven’t tried it.

Good luck!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overlapping Source inside Object · Issue #22 · flaport/fdtd
This causes some problems and ideally a better solution should be found (see removing objects doesn't reset grid permittivity #4 and new grid...
Read more >
When using external grid filtering, how do I hide the `Clear ...
I've tried using uiGridGridMenuService. removeFromGridMenu(grid, id) to unregister the menu option, but this won't work when the grid is first ...
Read more >
pgfplots: How to selectively remove major grid lines at ...
Following this answer, I tried to remove the grid lines at xmin and xmax , but it fails. What is missing here?
Read more >
Chem3D 17.0 User Guide
Chem3D ignores objects, such as arrows, orbitals, and curves copied to the clipboard. ... The constraint doesn't remove the atoms from a computation....
Read more >
Chapter 4. Layout Configuration
These round-off related problems are usually associated with non-orthogonal geometry. For example, in the following figure, if the grid dots represent the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found