Many Meep functions require you to specify a volume in space, corresponding to the C++ type `meep::volume`. This class creates such a volume object, given the `center` and `size` properties (just like e.g. a `Block` object). If the `size` is not specified, it defaults to `(0,0,0)`,
| 400 | |
| 401 | |
| 402 | class Volume: |
| 403 | """ |
| 404 | Many Meep functions require you to specify a volume in space, corresponding to the C++ |
| 405 | type `meep::volume`. This class creates such a volume object, given the `center` and |
| 406 | `size` properties (just like e.g. a `Block` object). If the `size` is not specified, |
| 407 | it defaults to `(0,0,0)`, i.e. a single point. Any method that accepts such a volume |
| 408 | also accepts `center` and `size` keyword arguments. If these are specified instead of |
| 409 | the volume, the library will construct a volume for you. Alternatively, you can |
| 410 | specify a list of `Vector3` vertices using the `vertices` parameter. The `center` and |
| 411 | `size` will automatically be computed from this list. |
| 412 | """ |
| 413 | |
| 414 | def __init__( |
| 415 | self, |
| 416 | center: Vector3Type = Vector3(), |
| 417 | size: Vector3Type = Vector3(), |
| 418 | dims: int = 2, |
| 419 | is_cylindrical: bool = False, |
| 420 | vertices: Optional[List[Vector3Type]] = None, |
| 421 | ): |
| 422 | """ |
| 423 | Construct a Volume. |
| 424 | """ |
| 425 | if not vertices: |
| 426 | self.center = Vector3(*center) |
| 427 | self.size = Vector3(*size) |
| 428 | else: |
| 429 | vertices = np.array([np.array(i) for i in vertices]) |
| 430 | self.center = Vector3(*np.mean(vertices, axis=0)) |
| 431 | x_list = np.unique(vertices[:, 0]) |
| 432 | y_list = np.unique(vertices[:, 1]) |
| 433 | z_list = np.unique(vertices[:, 2]) |
| 434 | |
| 435 | x_size = 0 if x_list.size == 1 else np.abs(np.diff(x_list)[0]) |
| 436 | y_size = 0 if y_list.size == 1 else np.abs(np.diff(y_list)[0]) |
| 437 | z_size = 0 if z_list.size == 1 else np.abs(np.diff(z_list)[0]) |
| 438 | |
| 439 | self.size = Vector3(x_size, y_size, z_size) |
| 440 | |
| 441 | self.dims = dims |
| 442 | |
| 443 | v1 = self.center - self.size.scale(0.5) |
| 444 | v2 = self.center + self.size.scale(0.5) |
| 445 | |
| 446 | vec1 = py_v3_to_vec(self.dims, v1, is_cylindrical) |
| 447 | vec2 = py_v3_to_vec(self.dims, v2, is_cylindrical) |
| 448 | |
| 449 | self.swigobj = mp.volume(vec1, vec2) |
| 450 | |
| 451 | def get_vertices(self): |
| 452 | xmin = self.center.x - self.size.x / 2 |
| 453 | xmax = self.center.x + self.size.x / 2 |
| 454 | ymin = self.center.y - self.size.y / 2 |
| 455 | ymax = self.center.y + self.size.y / 2 |
| 456 | zmin = self.center.z - self.size.z / 2 |
| 457 | zmax = self.center.z + self.size.z / 2 |
| 458 | |
| 459 | # Iterate over and remove duplicates for collapsed dimensions (i.e. min=max)) |
no outgoing calls
no test coverage detected