Skip to content

variable density floor feature: simplified test problem#1551

Draft
chongchonghe wants to merge 16 commits into
developmentfrom
chong/copy/variable-den-floor-v2
Draft

variable density floor feature: simplified test problem#1551
chongchonghe wants to merge 16 commits into
developmentfrom
chong/copy/variable-den-floor-v2

Conversation

@chongchonghe

Copy link
Copy Markdown
Contributor

Description

Simplified version of #1520

Related issues

None.

Checklist

Before this pull request can be reviewed, all of these tasks should be completed. Denote completed tasks with an x inside the square brackets [ ] in the Markdown source below:

  • I have added a description (see above).
  • I have added a link to any related issues (if applicable; see above).
  • I have read the Contributing Guide.
  • I have added tests for any new physics that this PR adds to the code.
  • (For quokka-astro org members) I have manually triggered the GPU tests with the magic comment /azp run.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Dec 29, 2025
@chongchonghe chongchonghe marked this pull request as draft December 29, 2025 10:41
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @chongchonghe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a flexible variable density floor mechanism, allowing problem generators to define spatially varying density floors. This enhances the simulation's ability to handle complex physical scenarios where a uniform density floor might be insufficient. The changes involve modifying core simulation classes and updating the StarCluster problem to demonstrate and test this new functionality.

Highlights

  • Variable Density Floor Implementation: Introduced a new densityFloor method in QuokkaSimulation that can be specialized by problem generators to define spatially varying density floors.
  • Enforcement Mechanism: Added an enforceDensityFloor method to QuokkaSimulation and AMRSimulation to apply the calculated density floor, replacing direct calls to HydroSystem::EnforceLimits.
  • HydroSystem Update: Modified HydroSystem::EnforceLimits to accept a GeometryData and a DensityFloorFunc template, allowing it to apply coordinate-dependent density floors.
  • StarCluster Problem Adaptation: Updated the StarCluster problem to utilize and test the new variable density floor feature, including a custom localDensityFloor function and post-evolution analysis with optional plotting.
  • Test Configuration Change: Reduced max_timesteps in inputs/StarCluster.in from 300 to 1, likely to speed up testing of the new feature.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot Bot added the enhancement New feature or request label Dec 29, 2025

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a valuable feature for a variable density floor, which can be customized for specific problems. The implementation is well-structured, primarily by templating the EnforceLimits function to accept a function object for the density floor calculation and adding a virtual densityFloor method in QuokkaSimulation for problem-specific specializations. The new test case in StarCluster effectively demonstrates and validates this new capability. My review includes a few suggestions to enhance code quality by removing dead code, simplifying coordinate calculations for better readability, and correcting a potential logic error in the new test case.

{
amrex::Real r = std::sqrt(x * x + y * y + z * z);
const Real rho_base_floor = 0.001;
const Real rho_peak = 1.0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

There is an inconsistency between the comment for the custom density floor and its implementation. The comment on line 227 states the function is max(0.001, 0.1 - 0.01 * r), but the implementation with rho_peak = 1.0 results in max(0.001, 1.0 - 0.1 * r). To match the comment, rho_peak should be 0.1.

	const Real rho_peak = 0.1;

Comment thread src/QuokkaSimulation.hpp Outdated
Comment on lines +1696 to +1709
// if (this->useDensityFloorParser_) {
// auto const density_floor_parser = this->densityFloorParserExe_.value();
// auto const density_floor_func = [=] AMREX_GPU_HOST_DEVICE(amrex::Real x, amrex::Real y, amrex::Real z,
// amrex::Real base_density_floor) -> amrex::Real {
// return density_floor_parser(x, y, z, base_density_floor);
// };
// HydroSystem<problem_t>::EnforceLimits(densityFloor_, tempFloor_, state_mf, geom[lev].data(), density_floor_func);
// } else {
// auto const density_floor_func = [this] AMREX_GPU_HOST_DEVICE(amrex::Real x, amrex::Real y, amrex::Real z,
// amrex::Real base_density_floor) -> amrex::Real {
// return densityFloor(x, y, z, base_density_floor);
// };
// HydroSystem<problem_t>::EnforceLimits(densityFloor_, tempFloor_, state_mf, geom[lev].data(), density_floor_func);
// }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This large block of commented-out code should be removed to improve maintainability. The logic within the else block is identical to the active code that follows.

Comment on lines +949 to +959
amrex::Real const x = prob_lo[0] + (static_cast<amrex::Real>(i) + static_cast<amrex::Real>(0.5)) * dx[0];
#if (AMREX_SPACEDIM >= 2)
amrex::Real const y = prob_lo[1] + (static_cast<amrex::Real>(j) + static_cast<amrex::Real>(0.5)) * dx[1];
#else
amrex::Real const y = 0.0;
#endif
#if (AMREX_SPACEDIM == 3)
amrex::Real const z = prob_lo[2] + (static_cast<amrex::Real>(k) + static_cast<amrex::Real>(0.5)) * dx[2];
#else
amrex::Real const z = 0.0;
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The calculation of cell-center coordinates is a bit verbose with explicit static_cast. This can be simplified by relying on implicit type promotion, which improves readability.

amrex::Real const x = prob_lo[0] + (i + 0.5) * dx[0];
#if (AMREX_SPACEDIM >= 2)
	amrex::Real const y = prob_lo[1] + (j + 0.5) * dx[1];
#else
	amrex::Real const y = 0.0;
#endif
#if (AMREX_SPACEDIM == 3)
	amrex::Real const z = prob_lo[2] + (k + 0.5) * dx[2];
#else
	amrex::Real const z = 0.0;
#endif

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/simulation.hpp
// (e.g., caused by the flux register or from interpolation)
virtual void FixupState(int level) = 0;

virtual void enforceDensityFloor(int lev, amrex::MultiFab &state_mf) = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Pure virtual floor method not implemented by AdvectionSimulation

Making enforceDensityFloor(int, amrex::MultiFab&) pure virtual in AMRSimulation now requires every subclass to override it. AdvectionSimulation (src/linear_advection/AdvectionSimulation.hpp lines 32–75) derives from AMRSimulation but defines no enforceDensityFloor, so the class becomes abstract and any advection problem (e.g., testAdvection*.cpp) will fail to compile or instantiate. Provide an override or a base implementation to restore buildability.

Useful? React with 👍 / 👎.

@chongchonghe chongchonghe changed the title A simple implementation of the variable density floor feature variable density floor feature: simplified test problem Dec 30, 2025
@chongchonghe

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@chongchonghe

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@chongchonghe

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@sonarqubecloud

sonarqubecloud Bot commented Jan 1, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@BenWibking

Copy link
Copy Markdown
Collaborator

Is this PR still needed?

1 similar comment
@BenWibking

Copy link
Copy Markdown
Collaborator

Is this PR still needed?

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

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants