Computes the number of pixels contained in a 2D or 3D grid_volume object. NOTE: This assumes that z=0 means 2D simulation and z>0 means 3D. Args: grid_volume: a meep grid_volume object Returns: The 2D or 3D number of pixels in the grid_volume.
(grid_volume: mp.grid_volume)
| 101 | |
| 102 | |
| 103 | def pixel_volume(grid_volume: mp.grid_volume) -> int: |
| 104 | """Computes the number of pixels contained in a 2D or 3D grid_volume object. |
| 105 | |
| 106 | NOTE: This assumes that z=0 means 2D simulation and z>0 means 3D. |
| 107 | |
| 108 | Args: |
| 109 | grid_volume: a meep grid_volume object |
| 110 | |
| 111 | Returns: |
| 112 | The 2D or 3D number of pixels in the grid_volume. |
| 113 | """ |
| 114 | if grid_volume.nz() > 0: # we're in a 3D simulation |
| 115 | return grid_volume.nx() * grid_volume.ny() * grid_volume.nz() |
| 116 | else: # 2D simulation |
| 117 | return grid_volume.nx() * grid_volume.ny() |
| 118 | |
| 119 | |
| 120 | def get_total_volume( |
no test coverage detected