amrex
amrex copied to clipboard
Data associated with boxes
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
amrex::LayoutData<T>
is probably what you are looking for. You could also use std::map<int,T>
, where the key is MFIter::index()
.
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
.
Yes, you would declare variables as amrex::LayoutData<int>
, amrex::LayoutData<double>
, amrex::LayoutData<std::pair<int,double>>
, etc.
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.
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
}
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 ...
What go into bxdat(...)
are what go into a constructor.
https://github.com/AMReX-Codes/amrex/blob/ab99ea69089f4fffbfd727ed965d5ceb3d905baa/Src/Base/AMReX_LayoutData.H#L19
Got it, now it works, the penny dropped. Many thanks!