AMReX-Codes / amrex

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

Issue with Retrieving Cell Data in AMReX Using GetCellData Function #4107

Open ztdepztdep opened 4 weeks ago

ztdepztdep commented 4 weeks ago

I have the following function in my LBM_FVM class, which is supposed to get data from a specific cell (i, j) across different refinement levels. I want it to get data from the fineset level first. but it sometimes give a "zero" value, i am not sure what had happed.

`double LBM_FVM::GetCellData(amrex::Vector<amrex::MultiFab>& data, int i, int j)
{
    IntVect cell(i, j);
    for(int i=finestLevel(); i>=0; i--)
    {
        auto v = amrex::get_cell_data(data[i], cell);
        auto const& ba = data[i].boxArray();
        bool test = ba.intersects(Box(cell, cell, ba.ixType()), 0);

        if (test)
        {
            auto const& ba = data[i].boxArray();
            auto isects = ba.intersections(Box(cell, cell, ba.ixType()));
            int root = data[i].DistributionMap()[isects[0].first];
            if (ParallelDescriptor::MyProc() != root) v.resize(1);
            ParallelDescriptor::Bcast(v.data(), v.size(), root);
            return v[0];
        }
    }
    return -1; // or some error value if cell not found
}
`
pkufourier commented 3 days ago

I think the data buffer in MPI Bcast should be equal size in all processors. And v is better to be a temporal vector with a copy of data you want to bcast, other than the data reference from MFI. Therefore, the following resize is not proper. if (ParallelDescriptor::MyProc() != root) v.resize(1); ParallelDescriptor::Bcast(v.data(), v.size(), root);