amrex icon indicating copy to clipboard operation
amrex copied to clipboard

Data associated with boxes

Open nw236 opened this issue 2 years ago • 3 comments

Hello, I am trying to figure out if it is possible to have data structures other than the grid data stored or associated with boxes.

For example, in a situation where an equation does not need to be solved everywhere in the domain one could use a single integer variable for each box to mark if this equation needs to be solved. If not, the mfiter loop could cycle to the next box.

I can think of many other applications for this concept, such has holding non-grid data structures, only needed in some parts of the domains. Ideally some of these could be dynamic in size...?

If this is explained in the documentation, could you point me to the right section, as I did not find it.

Many thanks for your help. Cheers Nils

nw236 avatar Jun 07 '22 22:06 nw236

amrex::LayoutData<T> is probably what you are looking for. You could also use std::map<int,T>, where the key is MFIter::index().

WeiqunZhang avatar Jun 07 '22 22:06 WeiqunZhang

Thank you for the quick response. This looks promising.

Just to make sure I fully understand your response. T stands for data-type (i.e. integer or float etc), and I would simply declare variables as being of type amrex::LayoutData.

nw236 avatar Jun 08 '22 09:06 nw236

Yes, you would declare variables as amrex::LayoutData<int>, amrex::LayoutData<double>, amrex::LayoutData<std::pair<int,double>>, etc.

WeiqunZhang avatar Jun 08 '22 16:06 WeiqunZhang

Hi, its been a while since I've asked this question.

I managed to get some results using std:map.

When using amrex::LayoutData<T> however I cannot find a way to store data in the previously declared variable. What I do is along the lines

amrex::LayoutData<int> bxdat;
...
bxdat = 1;

When reading bxdat.data() I get a value, but I cannot assign one. Reading the doxygen documentation was not very helpful. I would not be surprised if I am missing something very simple and fundamental.

nw236 avatar Jan 27 '24 20:01 nw236

operator[] is probably what you want to use. https://github.com/AMReX-Codes/amrex/blob/ab99ea69089f4fffbfd727ed965d5ceb3d905baa/Src/Base/AMReX_LayoutData.H#L84

amrex::LayoutData<int> bxdat(...);
for (MFIter mfi(mf); mfi.isValid(); ++mfi) {
   bxdat[mfi] = .....;
}

for (MFIter mfi(mf); mfi.isValid(); ++mfi) {
    if (bxdat[mfi]) {
        ....
     } // else do nothing
}

WeiqunZhang avatar Jan 28 '24 00:01 WeiqunZhang

Hmm, if I do the following I get a segmentation fault.

amrex::LayoutData<int> bxdat;
for (MFIter mfi(mf); mfi.isValid(); ++mfi) {
   bxdat[mfi] = 13;
}

I am not sure what should go into bxdat(...) in place of ...

nw236 avatar Jan 28 '24 21:01 nw236

What go into bxdat(...) are what go into a constructor. https://github.com/AMReX-Codes/amrex/blob/ab99ea69089f4fffbfd727ed965d5ceb3d905baa/Src/Base/AMReX_LayoutData.H#L19

WeiqunZhang avatar Jan 28 '24 22:01 WeiqunZhang

Got it, now it works, the penny dropped. Many thanks!

nw236 avatar Jan 30 '24 00:01 nw236