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

Diagnostics: reduce reliance on WarpX::GetInstance() #5752

Open
wants to merge 3 commits into
base: development
Choose a base branch
from

Conversation

lucafedeli88
Copy link
Member

@lucafedeli88 lucafedeli88 commented Mar 11, 2025

Reduce reliance on WarpX::GetInstance() in diagnostics by passing more parameters as arguments.

What do you think about passing a group of parameters as a struct?

struct InitDiagnosticsParameters
{
    int finest_level;
    int max_level;

    int do_moving_window;
    int moving_window_dir;
    amrex::Real moving_window_x;
    amrex::Real cell_size_lev0_mwdir;
};

I think that it is useful especially for WarpXIO.cpp since several function calls requiring these parameters are made.
I am really sorry that C++17 doesn't have label initialization for structs like C .

⚠️⚠️ ⚠️ Note that FlushFormatSensei requires a pointer to the base class of the WarpX object, which is now passed as an argument auto* p_warpx_mesh = dynamic_cast<amrex::AmrMesh*>(this); . Before, this was obtained by const casting a const pointer obtained from WarpX::GetInstance(). The refactored code has the added benefit that it removes this const_cast (usage of const_cast is often discouraged because it could lead to Undefined Behavior issues, see: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es50-dont-cast-away-const).

@lucafedeli88 lucafedeli88 added cleaning Clean code, improve readability component: diagnostics all types of outputs labels Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleaning Clean code, improve readability component: diagnostics all types of outputs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant