| 2456 | self.load_fields_file = load_fields_file |
| 2457 | |
| 2458 | def init_sim(self): |
| 2459 | if self._is_initialized: |
| 2460 | return |
| 2461 | |
| 2462 | materials = [ |
| 2463 | g.material for g in self.geometry if isinstance(g.material, mp.Medium) |
| 2464 | ] |
| 2465 | if isinstance(self.default_material, mp.Medium): |
| 2466 | materials.append(self.default_material) |
| 2467 | for med in materials: |
| 2468 | if ( |
| 2469 | (med.epsilon_diag.x < 1 and med.epsilon_diag.x > -mp.inf) |
| 2470 | or (med.epsilon_diag.y < 1 and med.epsilon_diag.y > -mp.inf) |
| 2471 | or (med.epsilon_diag.z < 1 and med.epsilon_diag.z > -mp.inf) |
| 2472 | ): |
| 2473 | |
| 2474 | eps_warning = ( |
| 2475 | "Epsilon < 1 may require adjusting the Courant parameter. " |
| 2476 | + "See the 'Numerical Stability' entry under the 'Materials' " |
| 2477 | + "section of the documentation" |
| 2478 | ) |
| 2479 | warnings.warn(eps_warning, RuntimeWarning) |
| 2480 | |
| 2481 | if self.structure is None: |
| 2482 | self._init_structure(self.k_point) |
| 2483 | |
| 2484 | self.fields = mp.fields( |
| 2485 | self.structure, |
| 2486 | self.m if self.is_cylindrical else 0, |
| 2487 | self.k_point.z if self.special_kz and self.k_point else 0, |
| 2488 | not self.accurate_fields_near_cylorigin, |
| 2489 | self.loop_tile_base_db, |
| 2490 | self.loop_tile_base_eh, |
| 2491 | self.bfast_scaled_k, |
| 2492 | ) |
| 2493 | |
| 2494 | if self.force_all_components and self.dimensions != 1: |
| 2495 | self.fields.require_component(mp.Ez) |
| 2496 | self.fields.require_component(mp.Hz) |
| 2497 | |
| 2498 | if self.using_real_fields(): |
| 2499 | self.fields.use_real_fields() |
| 2500 | elif verbosity.meep > 0: |
| 2501 | print("Meep: using complex fields.") |
| 2502 | |
| 2503 | if self.k_point: |
| 2504 | v = ( |
| 2505 | Vector3(self.k_point.x, self.k_point.y) |
| 2506 | if self.special_kz |
| 2507 | else self.k_point |
| 2508 | ) |
| 2509 | self.fields.use_bloch(py_v3_to_vec(self.dimensions, v, self.is_cylindrical)) |
| 2510 | |
| 2511 | self.add_sources() |
| 2512 | |
| 2513 | for hook in self.init_sim_hooks: |
| 2514 | hook() |
| 2515 | |