-
Notifications
You must be signed in to change notification settings - Fork 50
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 calculation of EM energy #431
base: dev
Are you sure you want to change the base?
Conversation
# Compute the energy | ||
energy_density = const.epsilon_0/2.*(Ex**2 + Ey**2 + Ez**2) + 1./(2*const.mu_0)*(Bx**2 + By**2 + Bz**2) | ||
volume = info.dx*info.dy*info.dz # Cell volume | ||
E = (energy_density*volume).sum() |
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.
A small optimization is to do the sum first, avoiding multiplying the whole array be the volume. Or is the volume an array also, the volume of each grid cell?
E = energy_density.sum()*volume
# Check that the fields have either the thetaMode or 3dcartesian geometry | ||
if (self.fields_metadata['E']['geometry'] not in ['thetaMode', '3dcartesian']) or \ | ||
(self.fields_metadata['B']['geometry'] not in ['thetaMode', '3dcartesian']): | ||
raise ValueError('The electromagnetic energy can only be computed for 3D Cartesian and cylindrical simulations.') |
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.
It looks like this should work for 2D and 1D, though depending on how info.dy and info.dz are defined.
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.
Yes, this is a bit tricky. info.dy
does not exist in 2D and 1D in openPMD-viewer
.
Technically, we could multiply only by info.dx
(instead of info.dx
and info.dy
) and get a result in J/m (instead of J), but I wanted to avoid this, so that the user does not get confused.
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.
For comparison, this is what is done in the WarpX reduced field energy diagnostic. The volume is calculated with the assumption that the extra dimensions have a length of 1. This would be easy to implement here so might as well for completeness so you wouldn't have to come back and submit another change if this is requested in the future.
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.
OK, sounds good. Will do.
It is often useful to compute the total electromagnetic energy in the box. (This is oftentimes a good proxy for the laser energy.) This PR adds this function in
LpaDiagnostic
.