Skip to content

Add the ability to pass local scale ratios to ScaledEOS and ScaledFreeEnergy through the lambda - #672

Open
buechlerm wants to merge 15 commits into
mainfrom
buechler/local_scales
Open

buechlerm wants to merge 15 commits into
mainfrom
buechler/local_scales

Conversation

@buechlerm

Copy link
Copy Markdown
Collaborator

This make local scaling ratios possible.

PR Summary

This adds evaluation of the lambda for local scale factors to ScaledEOS and ScaledFreeEnergy. The vector interfaces also forward those local factors now too.

NOTE: I have not yet addressed eospac.

PR Checklist

  • Adds a test for any bugs fixed. Adds tests for new features.
  • Format your changes by using the make format command after configuring with cmake.
  • Document any new features, update documentation for changes made.
  • Make sure the copyright notice on any files you modified is up to date.
  • After creating a pull request, note it in the CHANGELOG.md file.
  • LANL employees: make sure tests pass both on the github CI and on the Darwin CI
  • If ML was used, make sure to add a disclaimer at the top of a file indicating ML was used to assist in generating the file.
  • If Agentic AI was used, have the AI generate a "proposed changes" markdown file and store it in the plan_histories folder, with a filename the same as the MR number.

If preparing for a new release, in addition please check the following:

  • Update the version in cmake.
  • Move the changes in the CHANGELOG.md file under a new header for the new release, and reset the categories.
  • Maintainers: ensure spackages are up to date:
    • LANL-internal team, update XCAP spackages
    • Current maintainer of upstream spackages, submit MR to spack

Comment on lines +79 to +82
const auto local_scale = factors.scale;
const auto local_inv_scale = factors.inv_scale;
return t_.TemperatureFromDensityInternalEnergy(local_scale * rho,
local_inv_scale * sie, lambda);

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.

Suggested change
const auto local_scale = factors.scale;
const auto local_inv_scale = factors.inv_scale;
return t_.TemperatureFromDensityInternalEnergy(local_scale * rho,
local_inv_scale * sie, lambda);
const auto rho_scale = factors.scale * rho;
const auto sie_scale = factors.inv_scale * sie;
return t_.TemperatureFromDensityInternalEnergy(rho_scale,
sie_scale, lambda);

What do you think is more useful to have in a local register here? The scaled density & sie, or the scaling factors, or neither? It's a genuine question. I suppose the answer might change for the different use cases in this file....

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

You're using the word register, so I'm guessing you are asking about performance, and I honestly wouldn't have any idea. In terms of debugging, I could live with either one, but your suggestion looks good to me.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I agreed to do this before switching to the structured bindings. Would you still rather I create temporaries like rho_scale and sie_scale?

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.

Either way is fine

Comment on lines +384 to +409
struct ScaleFactors {
Real scale;
Real inv_scale;
};

template <typename Indexer_t>
PORTABLE_FORCEINLINE_FUNCTION ScaleFactors
GetScaleFactors(const Indexer_t &lambda) const {
Real local_scale = scale_;

// Checks for the named index and apply it if it exists.
if (singularity::IndexerUtils::SafeGet<IndexableTypes::DensityScalingRatio>(
lambda, local_scale)) {
PORTABLE_ALWAYS_REQUIRE(local_scale > 0.0,
"Local density scaling ratio must be positive.");

const Real local_inv_scale = 1.0 / local_scale;

PORTABLE_ALWAYS_REQUIRE(local_inv_scale > 0.0,
"Inverse local density scaling ratio must be positive.");

return {local_scale, local_inv_scale};
}

return {scale_, inv_scale_};
}

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.

We could do away with the struct and just return a tuple, that would let you then capture the two scale factors into local variables without first making a struct then copying the two members into local variables.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

std::tuple? Is that always device safe? Not exactly a fix for the copy concern, but where it's used, we could do const auto [scale, inv_scale] = GetScaleFactors(lambda);

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.

I think it depends on the situation, but I've never had a problem. I believe this use case should be fine. And I'd do const auto &[scale, inv_scale]... with the reference binding. We could try it out and see if the testing falls over.

This branch has not been deployed

No deployments
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.

2 participants