-
Notifications
You must be signed in to change notification settings - Fork 633
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
add stop_when_energy_decayed termination condition #2021
Conversation
Is there any particular reason to call it on every timestep? Also, note that you might want to look at |
Given the performance penalty of calling
Done. |
cell_size: Union[meep.geom.Vector3, Tuple[float, ...], NoneType] = None, | ||
resolution: float = None, | ||
geometry: Optional[List[meep.geom.GeometricObject]] = None, | ||
sources: Optional[List[meep.source.Source]] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's going on with all of these Union -> Optional
changes? Seems like they belong in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1919 added the Optional
type hint to various parameters of the Simulation
constructor such as geometry
, sources
, etc. The type hint Optional[Type]
is equivalent to Union[Type, None]
according to PEP 484. The default values of each parameter are parsed by the ast.parse()
function in doc/generate_py_api.py
. Because I have been using different versions of Python (3.5, 3.8) to call generate_py_api.py
in various PRs which involve updating the docs (i.e., #1958, #1926, etc.), the different Python grammars seem to have been interchanging Optional
and Union
. The same thing seems to be happening again in this PR. ast.parse()
is also inserting an extra space before and after the =
sign. We therefore probably need to edit generate_py_api.py
in a separate PR to ensure consistent parsing of the type hints and thus avoid these unnecessary changes.
Those changes were caused by running |
For simulations involving a large computational cell in which the sources and the monitors are separated by a large distance (i.e., tens to hundreds of wavelengths), the available termination conditions
stop_when_fields_decayed
andstop_when_dft_decayed
are inadequate because they often stop the simulation prematurely as the fields have not had sufficient time to propagate throughout the entire cell.This PR introduces a new termination condition
stop_when_energy_decayed
which tracks the electric energy over the entire cell. However, the cost of calling the functionelectric_energy_in_box
at every timestep to obtain the energy can be significant: in tests, ~20X slow down in the time-stepping rate compared to using a fixed runtime termination condition.The performance penalty notwithstanding, some preliminary tests have demonstrated that this feature provides an improvement compared to using a large, fixed, and overly conservative run time chosen arbitrarily.