Skip to content
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 external particle fields ohms law hybrid #5275

Conversation

clarkse
Copy link
Member

@clarkse clarkse commented Sep 16, 2024

This PR allows for the addition of external fields through the particle fields analytical interface. This is useful for field splitting external vs. self fields in the hybrid ohm's law solver.

@clarkse clarkse marked this pull request as draft September 16, 2024 18:12
@clarkse clarkse force-pushed the add_external_particle_fields_ohms_law_hybrid branch from b534e43 to 5f75428 Compare September 18, 2024 21:52
pre-commit-ci bot and others added 14 commits September 18, 2024 21:52
Signed-off-by: S. Eric Clark <25495882+clarkse@users.noreply.github.com>
….com:clarkse/WarpX into add_external_particle_fields_ohms_law_hybrid
Signed-off-by: S. Eric Clark <25495882+clarkse@users.noreply.github.com>
….com:clarkse/WarpX into add_external_particle_fields_ohms_law_hybrid
Signed-off-by: S. Eric Clark <25495882+clarkse@users.noreply.github.com>
….com:clarkse/WarpX into add_external_particle_fields_ohms_law_hybrid
…tical field values into ghost cells. The E/B fields and edge_lengths have different numbers of ghost cells.

Signed-off-by: S. Eric Clark <25495882+clarkse@users.noreply.github.com>
…hen not enabled.

Signed-off-by: S. Eric Clark <25495882+clarkse@users.noreply.github.com>
…ternal data loading.

Signed-off-by: S. Eric Clark <25495882+clarkse@users.noreply.github.com>
… computed by curlA and E is computed by computing numerical derivative of seperable time component.
….com:clarkse/WarpX into add_external_particle_fields_ohms_law_hybrid
Signed-off-by: S. Eric Clark <25495882+clarkse@users.noreply.github.com>
Signed-off-by: S. Eric Clark <25495882+clarkse@users.noreply.github.com>
Signed-off-by: S. Eric Clark <25495882+clarkse@users.noreply.github.com>
Signed-off-by: S. Eric Clark <25495882+clarkse@users.noreply.github.com>
Copy link
Member

@roelof-groenewald roelof-groenewald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made some progress but have not fully reviewed all the changes yet. Here are some comments I've recorded so far.

clarkse and others added 7 commits February 12, 2025 09:42
Co-authored-by: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com>
…ohm_solver_cylinder_compression_picmi.py

Co-authored-by: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com>
Co-authored-by: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com>
Co-authored-by: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com>
Co-authored-by: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com>
Co-authored-by: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com>
Co-authored-by: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com>
@clarkse
Copy link
Member Author

clarkse commented Feb 12, 2025

@roelof-groenewald thanks for the partial review. I will start making some of the non-trivial changes and rechecking the tests. Very thorough review as usual. This will make for a better PR.

Signed-off-by: S. Eric Clark <25495882+clarkse@users.noreply.github.com>
Signed-off-by: S. Eric Clark <25495882+clarkse@users.noreply.github.com>
Copy link
Member

@roelof-groenewald roelof-groenewald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it looks good! I just had a final few small comments and a somewhat bigger question:
In the solve loop $E_{ext} = -\partial A/\partial t$ is subtracted from the E-field (so in total $E = E_{plasma} - E_{ext}$ which is then used to update the B-field, giving $$B_{new} = B_{old} -\nabla \times E_{plasma} dt + \nabla \times E_{ext} dt.$$
But $\nabla \times E_{ext} dt = -\partial/\partial t \nabla \times A dt = -\partial/\partial t B_{ext} dt$, so in effect
$$B_{new} = B_{old} -\nabla \times E_{plasma} dt - B_{ext}^{t+1}.$$
Then in the next half of the field push, $B_{ext}^{t+1}$ is added to $B_{new}$, cancelling the effect of subtracting $E_{ext}$ from the E-field in the first place.
And then at the very end of the field-solve $B_{ext}$ is added to the B-field again. It seems to me it should be sufficient to have $E_{ext}$ added to the E-field at every evaluation of E, and that it would then carry the change in $B_{ext}$ through to Faraday's law (the B-field update). Maybe we can chat about this quickly tomorrow.

Here's what I mean in slightly easier to read font:
image

@@ -617,6 +655,10 @@ void FiniteDifferenceSolver::HybridPICSolveECylindrical (
+ T_Algo::Dzz(Jr, coefs_z, n_coefs_z, i, j, 0, 0) - jr_val/(r*r);
Er(i, j, 0) -= eta_h * nabla2Jr;
}

if (include_external_fields && (rho_val >= rho_floor)) {
Er(i, j, 0) -= Er_ext(i, j, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the external field subtracted rather than added?

Copy link
Member Author

@clarkse clarkse Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is set up this way since the external fields are what they are, they operate in the soak through limit. So because of this since it is not solving A via a Poisson solve with totally self-consistent boundaries. I initially tried to just use the numerical integration to integrate the total B field, but because if the user is not extra careful to make sure the external field is self-consistent with the boundaries this approach was taken. I am doing a subtraction at the beginning of the Hypric PIC loop to remove the external component from the total field solution, then the E and B fields are the plasma response fields only moving through the integration loop. This allows for the Hybrid loop to proceed with integrating the plasma response into B
$\vec{E_{plasma}} + \vec{E_{ext}} = \frac{(\vec{J_{plasma}}-\vec{J_i}) \times (\vec{B_{plasma} + \vec{B_{ext}}})}{ne} - \frac{\nabla p_e}{ne} + \eta \vec{J_{plasma}} - \eta_h \nabla^2 \vec{J_{plasma}} $

Since the E and B fields at this point are the plasma fields in the Ohm's Law solver, however the solution is for a total field in order to get the plasma response only the E_ext needs to be subtracted from both sides of the equation.

In the vacuum region it gets a bit hairier. If the resistivity in that region is high enough or if the holmstrom flag is used then the Generalized Ohms Law asymptotes to:
$\vec{E_{resistive}} \sim \eta \vec{J} $
This can be linearly added to the vacuum field to get the total field since the assumption is that it is a vacuum and not dense enough to shield an external field.
This resistive electric field gets integrated into the B field, then the resistivity term is dropped because of the cancellation of the drag term in the ion momentum update for the particle push.
Since the plasma response in the vacuum region is not well defined the algorithm switches to using this form of Ohm's law to have a smoothly varying E field around the density cutoff to limit vacuum fluctuations integrating into the plasma field. Since in the vacuum field the plasma E field should be zero except for some damping electric fields that show up near the edges of the plasma, then this gets integrated into B with the boundary conditions. E_ext is not subtracted off in this case as the plasma shielding response is just not accurate in the vacuum region. This really cuts down on the vacuum fluctuations for me and makes the simulations more stable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to get stuck on this more, but looking at it again a few hours after we talked I'm again unsure about the following:
You say the E-field from Ohm's law is the total field (i.e. $E_{plasma} + E_{ext}$), is there a clear argument for why that is the case? I agree Ohm's law of course includes induction (from $v_e \times B$, where $B$ here includes the external field), but it seems it would still only be the E-field due to the plasma response. Shouldn't there be an additional inductive E-field from $-\partial A/\partial t$?
In such a case we'd have:

$$E_{total} = E_{Ohm} + E_{ext} = E_{Ohm} - \partial A/\partial t$$

such that the full Faraday equation would give:

$$\frac{\partial}{\partial t} B_{total} = -\nabla\times E_{total}$$

$$\frac{\partial}{\partial t} (B_{plasma} + B_{ext}) = -\nabla\times E_{Ohm} + \frac{\partial}{\partial t} \nabla \times A$$

giving

$\frac{\partial}{\partial t} B_{plasma} = -\nabla\times E_{Ohm}$ and $\frac{\partial}{\partial t} B_{ext} = \frac{\partial}{\partial t} B_{ext}$.

If the Ohm's law calculated E field includes $-\partial A/\partial t$, there would not be a way to have Faraday's law operate on the full E-field that would result in a B-field with both the plasma and external B-field included. I must still be missing something...

Copy link
Member

@roelof-groenewald roelof-groenewald Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of implementation, it seems to me that if the Ohm's law E-field does not already include $E_{ext}$, the formalism here would be that a time varying external field can be mathematically included by replacing the E-field calculation with $E = E_{Ohm} + E_{ext}$ where $E_{ext} = -\partial A / \partial t$. In that case the B-field integration from Faraday would itself add the external B-field. (As you mentioned earlier, the numerics could be complicated by boundary handling, in which case treating $B_{plasma}$ and $B_{ext}$ separately is understandable).

But the point of difference with the current implementation is, for clarity:
Is $E_{total} = E_{Ohm} = E_{plasma} + E_{ext}$ or $E_{total} = E_{Ohm} + E_{ext} = E_{plasma} + E_{ext} $?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$E_{ohm} = E_{total} = E_{plasma} + E_{external}$. I agree that it would be nicer if the integration worked out, but the boundary handling of the external field is finicky and not consistent with having a PEC at the EB or the domain edge. If we did a vector potential formulation of the integration I could do this all fully self-consistent. I would also like to be able to get rid of one of the sets of MFs. I cannot fix the boundary properly with having a soak through external field that ignores the boundaries and the high-frequency PEC response in this formulation.

I am exploring options to make this better, but I think it would require either having a displacement solver that has slowed down EM waves, or the vector potential formulation with infinite speed propagation. This is more of a solution to quickly add fields to try out. I think this is better suited to deal with in a follow up PR. I think I need to do a bit of work on the Magnetostatic solver, then I can address doing a self-consistent magneto-inductive version of the hybrid algorithm.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you say $E_{ohm} = E_{plasma} + E_{external}$? That is just the part I'm stuck on. It seems to me it should be the case that $E_{ohm} = E_{plasma}$.

I think the implementation of the model as you propose is good, so I'll approve this PR and merge now. But I think we should continue a discussion of the accuracy of the underlying physics model (and adjust the implementation in future PRs if we agree it is needed).

@@ -604,7 +638,11 @@ void FiniteDifferenceSolver::HybridPICSolveECylindrical (
// interpolate the nodal neE values to the Yee grid
auto enE_r = Interp(enE, nodal, Er_stag, coarsen, i, j, 0, 0);

Er(i, j, 0) = (enE_r - grad_Pe) / rho_val;
if (rho_val < rho_floor && holmstrom_vacuum_region) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's curious to me what the clang-tidy tests focus on. I would think it would prefer this to be

if (holmstrom_vacuum_region && (rho_val < rho_floor))

due to the possibility to short-circuit and avoid the comparison.

clarkse and others added 5 commits February 14, 2025 09:53
Co-authored-by: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com>
Co-authored-by: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com>
Co-authored-by: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com>
… fields warning back to Initialization routine.

Signed-off-by: S. Eric Clark <25495882+clarkse@users.noreply.github.com>
Signed-off-by: S. Eric Clark <25495882+clarkse@users.noreply.github.com>
Copy link
Member

@roelof-groenewald roelof-groenewald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code changes look good! Thanks for the all the work to get this implemented!

@roelof-groenewald roelof-groenewald merged commit 18578b9 into ECP-WarpX:development Feb 15, 2025
37 checks passed
@clarkse clarkse deleted the add_external_particle_fields_ohms_law_hybrid branch February 18, 2025 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: fluid-ohm Related to the Ohm's law solver (with fluid electrons) enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants