AMReX-Codes / amrex

AMReX: Software Framework for Block Structured AMR
https://amrex-codes.github.io/amrex
Other
506 stars 337 forks source link

How to plot multple Fields in the AmrCore turtorial. #3877

Closed ztdepztdep closed 2 months ago

ztdepztdep commented 3 months ago

In the amrcore exaples, I want to add the phi_old to the output file. In the "PlotFileMF()" function, i add the following line, but it seems doesn't work. the "phi_old" variable take nan values in visit.

amrex::Vector<const amrex::MultiFab*> ScalarTransport_MultiLevel::PlotFileMF () const
{
    amrex::Vector<const amrex::MultiFab*> r;
    for (int i = 0; i <= finest_level; ++i) {
        r.push_back(&phi_new[i]);
    }

    for (int i = 0; i <= finest_level; ++i) {
        r.push_back(&phi_old[i]);
    }
    return r;
}
WeiqunZhang commented 3 months ago

First, you need to make sure phi_old does not contain NaNs. In the AmrCore example, we do not initialize phi_old because it is not needed. But if you want to save phi_old in plotfiles, you need to initialize phi_old every time you remake an old level or creating a new level from scratch.

The modification to PlotFileMF will not work even if phi_old has no NaNs. The returned vector must have the size of finest_level+1, not 2*(finiest_level+1), because it is expected to have one MulitFab per level. There are two approaches you can take. You can put phi_new and phi_old in the same MultiFab. Or you can create a temporary 2 components MultiFab for plotfiles. For example, https://github.com/AMReX-Codes/amrex/blob/2a3955a5f5aac1aef6e6e72687f182331e049c39/Tests/LinearSolvers/ABecLaplacian_C/MyTestPlotfile.cpp#L31.