Skip to content

Breaking change: allow input decks to work for both 2D and 3D #113

Description

@RemiLehe

From our Slack discussion:

It would be useful to be able to run the exact same input deck with 2D and 3D.
(In that case, when run with 2D, variables such as
geometry.prob_lo = -150.e-6 -150.e-6 -50.e-6
would be read in such a way that only the first and last values would be used.)

The motivation is that it would avoid a lot of copy-paste mistake: 2D input decks are usually obtained by copy-pasting 3D input decks, and modifying variables (such as prob_lo) by hand. However, it is easy to forget a variable, and this can have drastic consequences on the simulation.

For variables that are read by AMReX - not WarpX directly - (such as geometry.prob_lo), we should create a corresponding WarpX variable (e.g. warpx.prob_lo) and do something like this:

    amrex::Initialize(argc,argv);
   {
       ParmParse ppw("warpx");
       ParmParse ppg("geometry");
       if (ppw.countval("prob_lo") > 0) {
           Vector<Real> plo;
           ppw.getarr("prob_lo", plo);
#if (AMREX_SPACEDIM == 3)
           ppg.addarr("prob_lo", plo);
#else
           ppg.addarr("prob_lo", {plo[0],plo[2]});
#endif
       }
       // prob_hi, is_periodic, ...
   }

In order to implement the above change we should:

  • Change the way in which most vector variables are read, in 2D
  • Add the above mentioned warpx variables, for variables read by AMReX
  • Update the documentation, and clearly mention that only the first and last variable are read, in 2D (for each vector variable)
  • Remove all the 2D scripts, in the Example folder (they would no longer be needed)

Activity

  1. WeiqunZhang commented on May 2, 2019

    @WeiqunZhang
    Member

    I don't think it will break anything. The users are not required to use the new warpx.prob_lo etc. If they don't, there are no changes in behaviors. We could make warpx.* required if that's desired.

  2. RemiLehe commented on May 2, 2019

    @RemiLehe
    MemberAuthor

    Still, it will break things like num_particles_per_cell_each_dim which will now always expect 3 numbers, even in 2D

  3. WeiqunZhang commented on May 2, 2019

    @WeiqunZhang
    Member

    Well, it's easy to maintain backward compatibility for num_particles_per_cell_each_dim.

        num_particles_per_cell_each_dim.clear();
        pp.getarr("num_particles_per_cell_each_dim", num_particles_per_cell_each_dim);
    #if (AMREX_SPACEDIM == 2)
        if (num_particles_per_cell_each_dim.size() == 2) {
            num_particles_per_cell_each_dim.resize(3);
            num_particles_per_cell_each_dim[2] = num_particles_per_cell_each_dim[1];
            num_particles_per_cell_each_dim[1] = 1;
        }
    #endif
    

    Yes, PlasmaInjector does need to be modified for 2d. But that's case independent of ParmParse.

  4. RemiLehe commented on May 2, 2019

    @RemiLehe
    MemberAuthor

    OK, sounds good. Thanks for the above code suggestion.

  5. added a commit that references this issue on Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions