EM Field Enhancement: local coordinates, dynamic placements and mapped fields#1012
EM Field Enhancement: local coordinates, dynamic placements and mapped fields#1012srmarcballestero wants to merge 19 commits into
Conversation
- Allows fields to be defined relative to the local coordinate system of the physical volumes. - Paves the way for the mapped field implementation
…ld definition in local coordinates and updates for dynamic geometry changes
There was a problem hiding this comment.
Pull request overview
This draft PR refactors magnetic-field handling so fields are defined in the local coordinate system of the volume they’re attached to, and introduces infrastructure to cache and refresh placement transforms (including multi-placement logical volumes) across dynamic geometry updates between runs.
Changes:
- Wraps magnetic fields in a new C++
GateMagneticField(built onGateField) to transform query points world↔local per physical placement and to support transform refreshes. - Updates Python magnetic-field classes to construct an “inner” Geant4 field in local coordinates and then wrap it with
GateMagneticField. - Adds a run-start hook to refresh cached transforms after dynamic geometry changers are applied, and wires the attached volume object into field construction.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| opengate/geometry/fields.py | Refactors magnetic fields to create local-coordinate inner fields and wrap them with GateMagneticField; adds refresh_transforms(). |
| opengate/engines.py | Passes the attached volume object into field instances before creating field managers. |
| opengate/actors/dynamicactors.py | Refreshes field transforms after dynamic geometry changes at begin-of-run. |
| core/opengate_core/opengate_lib/GateField.h / GateField.cpp | Adds a C++ helper to cache placement transforms and locate the containing placement (with overshoot fallback). |
| core/opengate_core/opengate_lib/GateMagneticField.h / GateMagneticField.cpp | Adds a C++ magnetic-field wrapper that evaluates inner fields in local coords and rotates results back to world. |
| core/opengate_core/opengate_lib/pyGateMagneticField.cpp | Adds pybind11 bindings for GateMagneticField and SetTransforms. |
| core/opengate_core/opengate_core.cpp | Registers GateMagneticField bindings in the Python module init. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… a faster UniformElectroMagneticField
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ns all the common functionality and field-specific implementations are now minimal Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 47 out of 47 changed files in this pull request and generated 6 comments.
Comments suppressed due to low confidence (1)
docs/source/user_guide/user_guide_fields.rst:165
- The CustomElectroMagneticField code snippet also uses
teslawithout defining it in the snippet. Consider addingtesla = gate.g4_units.teslanear the existingvolt/mdefinitions so users can copy-paste the example successfully.
**CustomElectroMagneticField** -- Arbitrary combined field. The callback must return all six components ``[Bx, By, Bz, Ex, Ey, Ez]``.
.. code-block:: python
def my_EM_field(x, y, z, t):
return [0, 1 * tesla, 0, 1e6 * volt / m, 0, 0]
…ctricField, and MappedElectroMagneticField
|
Fork synced with master and PR ready for review |
9e165ae to
0a5457f
Compare
Rationale
Enhancement and maintenance of the internal field management infrastructure. Implement mapped fields. User API remains unchanged.
Fixes
GetFieldValuecall, so a field attached to a repeated or rotated volume automatically applies with the correct orientation and position at each placement.New Features
Internal Changes
The whole C++ field management infrastructure has been rethought and refactored. Now, all field types share a single base class,
GateFieldBase, which resolves the physical placement of the volume and manages coordinate transforms. Concrete implementations are minimal.Tests and Documentation
Tests for the new features have been added, and I have updated the EM fields documentation page.
Cheers,
Marc :)