Skip to content

Doc: AMREX_ENUM Functions#4764

Merged
WeiqunZhang merged 2 commits intoAMReX-Codes:developmentfrom
ax3l:doc-enum-funcs
Nov 7, 2025
Merged

Doc: AMREX_ENUM Functions#4764
WeiqunZhang merged 2 commits intoAMReX-Codes:developmentfrom
ax3l:doc-enum-funcs

Conversation

@ax3l
Copy link
Copy Markdown
Member

@ax3l ax3l commented Nov 7, 2025

Summary

Enum Doxygen strings and examples :)

Additional background

Checklist

The proposed changes:

  • fix a bug or incorrect behavior in AMReX
  • add new capabilities to AMReX
  • changes answers in the test suite to more than roundoff level
  • are likely to significantly affect the results of downstream AMReX users
  • include documentation in the code and/or rst files, if appropriate

@ax3l ax3l requested a review from WeiqunZhang November 7, 2025 01:58
* nonlinear
* );
* pp_element.queryAdd("model", model_str);
* Model const model = amrex::getEnum<Model>(model_str);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's avoid using ParmParse in the example, because ParmParse can read amrex_enum directly without using a string.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Or we could keep the example, but mention this is equivalent to

pp_element.queryAdd("model", model);

Copy link
Copy Markdown
Member

@WeiqunZhang WeiqunZhang Nov 7, 2025

Choose a reason for hiding this comment

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

#4765

using namespace amrex;

AMREX_ENUM(Model, linear, nonlinear);

int main(int argc, char* argv[])
{   
    amrex::Initialize(argc,argv);

    {
        auto model = Model::linear;
        ParmParse pp;

        pp.queryAdd("model", model);
        amrex::Print() << " model is " << amrex::getEnumNameString(model) << "\n";

        model = Model::linear;
        amrex::Print() << " model is " << amrex::getEnumNameString(model) << "\n";

        pp.queryAdd("model", model);
        amrex::Print() << " model is " << amrex::getEnumNameString(model) << "\n";
    }

    amrex::Finalize();
}

gives as expected when running with model="nonlinear"

 model is nonlinear
 model is linear
 model is nonlinear

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I change the code to

    {   
        auto model = Model::linear;
        ParmParse pp;

        pp.queryAdd("model", model);
        amrex::Print() << " model is " << amrex::getEnumNameString(model) << "\n";

        model = Model::nonlinear;
        amrex::Print() << " model is " << amrex::getEnumNameString(model) << "\n";

        pp.queryAdd("model", model);
        amrex::Print() << " model is " << amrex::getEnumNameString(model) << "\n";
    }

and run without any parameters, I get this as expected

 model is linear
 model is nonlinear
 model is linear

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Very cool :) :)

Doxygen strings and examples :)
@ax3l ax3l requested a review from WeiqunZhang November 7, 2025 04:45
@WeiqunZhang WeiqunZhang merged commit 4dad166 into AMReX-Codes:development Nov 7, 2025
72 of 73 checks passed
@ax3l ax3l deleted the doc-enum-funcs branch November 7, 2025 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants