AMReX-Codes / amrex

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

Can i out the value of a value not located in the IOprocessors? #3859

Closed ztdepztdep closed 3 months ago

ztdepztdep commented 4 months ago

I'm working with a Multifab data structure and I want to monitor the value at index (50, 90). However, there's a possibility that this particular index might not be present in the I/O processor. My question is: Can I still output the value using print functions, even if the index is missing?

WeiqunZhang commented 4 months ago

amrex::printCell( my_multifab, amrex::IntVect(50,90)); (for 2d)

https://amrex-codes.github.io/amrex/doxygen/namespaceamrex.html#a376ff66b5e6a76d195cace00df41d05e

ztdepztdep commented 3 months ago

amrex::printCell( my_multifab, amrex::IntVect(50,90)); (for 2d)

https://amrex-codes.github.io/amrex/doxygen/namespaceamrex.html#a376ff66b5e6a76d195cace00df41d05e

How to monitor its value , i.e. assign the value at (50,90) to a variable,then broadcast it to all the other processs.

WeiqunZhang commented 3 months ago
#include <AMReX_MultiFabUtil.H>

MultiFab mf(...);
IntVect cell(....);

auto v = amrex::get_cell_data(mf, cell);
auto const& ba = mf.boxArray();
auto isects = ba.intersections(Box(cell,cell,ba.ixType()));
int root = mf.DistributionMap()[isects[0].first];
if (ParallelDescriptor::MyProc() != root) {
    v.resize(mf.nComp());
}
ParallelDescriptor::Bcast(v.data(), v.size() , root);

Note that there might be typos.