Skip to content

Braginskii viscosities for Fci - #645

Open
totork wants to merge 19 commits into
boutproject:masterfrom
totork:viscosities-fci
Open

totork wants to merge 19 commits into
boutproject:masterfrom
totork:viscosities-fci

Conversation

@totork

@totork totork commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

This PR adjusts the Braginksii ion and electron viscosity components to be functional in Fci.

Change Summary

  • Change Bxy, sqrtB etc. to be Field3DParallels.
  • Calculation of sqrtB etc. is not taking place in transform but in the constructor to safe calculations
  • Add MMS tests
  • Add option to turn of viscous heating. Can help at the start of simulations when the flows have not developed.

Validation

Two 1D slab MMS tests for both viscosity components.

AI Assistance

None

Documentation

None

Review Notes

The asserts are still temporary and I will remove them later. It was just a little bit easier to debug in case something was not working.
Needs boutproject/BOUT-dev#3498 to be finalized.

@totork
totork marked this pull request as draft August 26, 2026 13:21
@bshanahan

Copy link
Copy Markdown
Collaborator

Sorry, but I've missed something. Why don't we use FieldMetric for Bxy, etc? I feel like these should be able to fall back to Field2D.

@codecov

codecov Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.77%. Comparing base (8057228) to head (14d7162).
⚠️ Report is 17 commits behind head on master.

Files with missing lines Patch % Lines
src/braginskii_ion_viscosity.cxx 82.35% 2 Missing and 1 partial ⚠️
src/braginskii_electron_viscosity.cxx 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #645      +/-   ##
==========================================
+ Coverage   58.49%   59.77%   +1.28%     
==========================================
  Files          98       98              
  Lines       10470    10285     -185     
  Branches     1550     1487      -63     
==========================================
+ Hits         6124     6148      +24     
+ Misses       3699     3489     -210     
- Partials      647      648       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@totork

totork commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Sorry, but I've missed something. Why don't we use FieldMetric for Bxy, etc? I feel like these should be able to fall back to Field2D.

@bshanahan Good question. Before this I had

const Coordinates::FieldMetric Bxy = coord->Bxy; const Coordinates::FieldMetric sqrtB = sqrt(Bxy.asField3DParallel());

but apparently Field3D sqrtB = sqrt(Bxy.asField3DParallel()) does not keep the parallel slices. So choosing FieldMetric here does miss the parallel slices.

@bshanahan

bshanahan commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator

Field3D sqrtB = sqrt(Bxy.asField3DParallel()) does not keep the parallel slices. So choosing FieldMetric here does miss the parallel slices.

This seems like an error in sqrt that can be fixed. @dschwoerer ?

@bendudson

Copy link
Copy Markdown
Collaborator

Field3D sqrtB = sqrt(Bxy.asField3DParallel()) does not keep the parallel slices. So choosing FieldMetric here does miss the parallel slices.

This seems like an error in sqrt that can be fixed. @dschwoerer ?

Hi @bshanahan If you want to keep the slices then this should assign to Field3DParallel:

Field3DParallel sqrtB = sqrt(Bxy);

This is now the way to determine whether expressions should be evaluated in the parallel slices (based on how the output is used, rather than the input type).

Changed in this PR: boutproject/BOUT-dev#3430

@bshanahan

Copy link
Copy Markdown
Collaborator

Thanks for the clarification @bendudson. How does this affect memory and efficiency? This PR has a few changes from const auto to const Field3DParallel.

@bendudson

Copy link
Copy Markdown
Collaborator

Thanks for the clarification @bendudson. How does this affect memory and efficiency? This PR has a few changes from const auto to const Field3DParallel.

This should improve efficiency, especially on GPUs, because expressions involving multiple operations have only one loop over the domain, rather than one loop per operation. We no longer need to store intermediate values so that should improve memory cache use. The main motivation for all this is GPU performance, for which we need to merge operations into kernels.

The change from const auto to const FieldParallel is to force evaluation of the expression: const auto just takes the type of whatever is on the right, but that is now some kind of BinaryExpr<...> complicated type. The expressions are only evaluated when they are assigned to a Field.

@dschwoerer

Copy link
Copy Markdown
Collaborator

boutproject/BOUT-dev#3477 introduces FieldMetricParallel to compute Bxy with parallel slices for FCI.

Comment thread src/braginskii_electron_viscosity.cxx Outdated
Comment thread src/braginskii_ion_viscosity.cxx Outdated
Comment thread src/braginskii_ion_viscosity.cxx Outdated
Comment thread src/braginskii_ion_viscosity.cxx Outdated
Comment thread src/braginskii_ion_viscosity.cxx Outdated
Comment thread tests/integrated/1D-ionviscosity-fci/runtest Outdated
@totork
totork marked this pull request as ready for review September 18, 2026 13:37
@totork
totork requested a review from dschwoerer September 22, 2026 21:02

@dschwoerer dschwoerer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just some minor cleanup.

Comment thread include/braginskii_ion_viscosity.hxx Outdated
Comment thread src/braginskii_electron_viscosity.cxx Outdated
Comment thread src/braginskii_electron_viscosity.cxx Outdated
@totork
totork requested a review from dschwoerer September 30, 2026 14:53
Comment thread src/braginskii_electron_viscosity.cxx Outdated
}

// Fci needs communication for the parallel slices
if (P.isFci()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not

Suggested change
if (P.isFci()) {
if (P.isFci() or eta_limit_alpha > 0.) {

and remove above communication?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do I care about the applyParallelBoundary here when this is FA? Does it change the physics?

Comment on lines 52 to +55
Coordinates* coord = P.getCoordinates();
const Field3D Bxy = coord->Bxy();
const Field3D sqrtB = sqrt(Bxy);
Bxy = coord->Bxy();
// If not allocated calculated, otherwise skip as already done
if (!sqrtB.isAllocated()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Might as well move everything into the brackets?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does the assignment of the field take that much time? Otherwise at some point we have to look through the code and adjust all of these

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants