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 hybrid resistivity current term #4661

Conversation

clarkse
Copy link
Member

@clarkse clarkse commented Feb 2, 2024

This PR adds a current magnitude term in the hybrid resistivity to allow for scaling of the resistivity as a function of the magnitude of total J.

@clarkse clarkse added enhancement New feature or request component: fluid-ohm Related to the Ohm's law solver (with fluid electrons) labels Feb 2, 2024
@roelof-groenewald roelof-groenewald self-assigned this Feb 3, 2024
Comment on lines 960 to 962
Real jx_val = Interp(Jx, Jx_stag, Ex_stag, coarsen, i, j, k, 0);
Real jy_val = Interp(Jy, Jy_stag, Ex_stag, coarsen, i, j, k, 0);
Real jz_val = Interp(Jz, Jz_stag, Ex_stag, coarsen, i, j, k, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Real jx_val = Interp(Jx, Jx_stag, Ex_stag, coarsen, i, j, k, 0);
Real jy_val = Interp(Jy, Jy_stag, Ex_stag, coarsen, i, j, k, 0);
Real jz_val = Interp(Jz, Jz_stag, Ex_stag, coarsen, i, j, k, 0);
Real jx_val = Interp(Jx, Jx_stag, Ez_stag, coarsen, i, j, k, 0);
Real jy_val = Interp(Jy, Jy_stag, Ez_stag, coarsen, i, j, k, 0);
Real jz_val = Interp(Jz, Jz_stag, Ez_stag, coarsen, i, j, k, 0);

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for catching the staggering bug.

Real jr_val = Interp(Jr, Jr_stag, Er_stag, coarsen, i, j, 0, 0);
Real jt_val = Interp(Jt, Jt_stag, Er_stag, coarsen, i, j, 0, 0);
Real jz_val = Interp(Jz, Jz_stag, Er_stag, coarsen, i, j, 0, 0);
jtot_val = sqrt(pow(jr_val, 2) + pow(jt_val, 2) + pow(jz_val,2));
Copy link
Member

@roelof-groenewald roelof-groenewald Feb 5, 2024

Choose a reason for hiding this comment

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

I think the preferred way to calculate it would be:

Suggested change
jtot_val = sqrt(pow(jr_val, 2) + pow(jt_val, 2) + pow(jz_val,2));
jtot_val = sqrt(jr_val*jr_val + jt_val*jt_val + jz_val*jz_val);

and same for the other directions and Cartesian case.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have dropped using the pow call. Just curious though, with compiler optimization wouldn't pow(,2) be inlined anyway?

Copy link
Member

@roelof-groenewald roelof-groenewald Feb 5, 2024

Choose a reason for hiding this comment

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

Yes, with new enough compilers it should be but the reasoning is that with a simple square, the x*x approach will never be less efficient than pow(x, 2) whereas the latter could be less efficient with sub-optimal compiler flags.

Copy link
Member

@roelof-groenewald roelof-groenewald Feb 5, 2024

Choose a reason for hiding this comment

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

So, actually with the change I don't think you need the static_cast<Real> anymore if you use std::sqrt, even in a lambda function now (#4490).

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.

Thanks for the check to only calculate j_tot if it will be used.

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.

Thanks! I'll be curious to hear how you are using the current dependent resistivity.

@roelof-groenewald roelof-groenewald enabled auto-merge (squash) February 5, 2024 23:59
@roelof-groenewald roelof-groenewald merged commit 7e36813 into ECP-WarpX:development Feb 6, 2024
41 checks passed
@clarkse clarkse deleted the add_hybrid_resistivity_current_term branch February 6, 2024 00:27
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.

2 participants