Alamo
Debug.H
Go to the documentation of this file.
1#ifndef UTIL_DEBUG_H
2#define UTIL_DEBUG_H
3
4#include "Util/Util.H"
5
6// This code is for debugging purposes only
7// LCOV_EXCL_START
8
9namespace Util
10{
11namespace Debug
12{
13
14template<class T>
15AMREX_FORCE_INLINE
16void Probe(
17 std::string file, std::string func, int line,
18 amrex::FabArray<amrex::BaseFab<T>> &a_mf, int i, int j, int k, int n)
19{
20 // Loop over boxes owned by this rank
21 for (amrex::MFIter mfi(a_mf); mfi.isValid(); ++mfi)
22 {
23 const amrex::Box& validbox = mfi.validbox();
24 const amrex::Box& box = mfi.grownnodaltilebox();
25
26 if (box.contains(amrex::IntVect(AMREX_D_DECL(i,j,0))))
27 {
28 const auto& arr = a_mf.const_array(mfi);
29 if (validbox.strictly_contains(i,j,k))
30 Util::ParallelMessage(file,func,line, "inside: (",i,",",j,",",k,") ",arr(i, j, k, n));
31 else if (validbox.contains(i,j,k))
32 Util::ParallelMessage(file,func,line, "border: (",i,",",j,",",k,") ",arr(i, j, k, n));
33 else
34 Util::ParallelMessage(file,func,line, "ghost: (",i,",",j,",",k,") ",arr(i, j, k, n));
35 }
36 }
37}
38
39AMREX_FORCE_INLINE
41 std::string file, std::string func, int line,
42 const amrex::MultiFab &a_mf, int _i, int _j, int /*_k*/, int n,
43 int pad = 0)
44{
45 const int t_notexist = 0;
46 const int t_inside = 1;
47 const int t_border = 2;
48 const int t_ghost = 3;
49
50 int hit = 0;
51
52 for (int rank = 0; rank < amrex::ParallelDescriptor::NProcs() ; rank++)
53 {
54 amrex::ParallelDescriptor::Barrier();
55 if (rank != amrex::ParallelDescriptor::MyRankInTeam()) continue;
56
57 // Loop over boxes owned by this rank
58 for (amrex::MFIter mfi(a_mf,false); mfi.isValid(); ++mfi)
59 {
60 const amrex::Box& validbox = mfi.validbox();
61 const amrex::Box& box = mfi.grownnodaltilebox();
62 bool contains = false;
63
64 std::vector<std::vector<Set::Scalar>> vals(2*pad + 1);
65 std::vector<std::vector<int>> types(2*pad + 1);
66 for (auto & val : vals) val.resize(2*pad + 1,NAN);
67 for (auto & type : types) type.resize(2*pad + 1,t_notexist);
68
69 for (int I = 0; I <= 2*pad; I++)
70 {
71 for (int J = 0; J <= 2*pad; J++)
72 {
73 int i = (_i - pad) + I;
74 int j = (_j - pad) + J;
75
76 if (box.contains(amrex::IntVect(AMREX_D_DECL(i,j,0))))
77 {
78 const auto& arr = a_mf.const_array(mfi);
79 vals[I][J] = arr(i,j,0,n);
80 if (validbox.strictly_contains(i,j,0)) types[I][J] = t_inside;
81 else if (validbox.contains(i,j,0)) types[I][J] = t_border;
82 else types[I][J] = t_ghost;
83 contains = true;
84 }
85 }
86 }
87
88 if (contains)
89 {
90 hit++;
91 std::stringstream ss;
92 ss << " " << std::setw(10) << Color::FG::LightYellow;
93 for (int I = 0; I <= 2*pad; I++)
94 {
95 int i = (_i - pad) + I;
96 ss << "i=" << std::left << std::setw(13) << i;
97 }
98 Util::ParallelMessage(file,func,line,ss.str());
99
100
101 for (int J = 2*pad; J >= 0; J--)
102 {
103 int j = (_j - pad) + J;
104
105 std::stringstream ss;
106 ss << Color::FG::LightYellow << "j=" << std::left << std::setw(5) << j << Color::Reset;
107 for (int I = 0; I <= 2*pad; I++)
108 {
109 if (types[I][J] == t_ghost) ss << Color::Dim;
110 if (types[I][J] == t_border) ss << Color::FG::Green;
111 if (types[I][J] == t_inside) ss << Color::FG::Blue;
112 if (types[I][J] == t_notexist) ss << Color::FG::Red;
113 ss << std::left << std::setw(15) << vals[I][J];
114 ss << Color::Reset;
115 }
116 Util::ParallelMessage(file,func,line,ss.str());
117 }
118 }
119 }
120 }
121 amrex::ParallelDescriptor::ReduceIntSum(hit);
122 return hit;
123}
124
125
126AMREX_FORCE_INLINE
127void Probe(
128 std::string file, std::string func, int line,
129 amrex::iMultiFab &a_mf, int i, int j, int k, int n)
130{
131 // Loop over boxes owned by this rank
132 for (amrex::MFIter mfi(a_mf); mfi.isValid(); ++mfi)
133 {
134 const amrex::Box& validbox = mfi.validbox();
135 const amrex::Box& box = mfi.grownnodaltilebox();
136
137 if (box.contains(amrex::IntVect(AMREX_D_DECL(i,j,0))))
138 {
139 const auto& arr = a_mf.const_array(mfi);
140 if (validbox.strictly_contains(i,j,k))
141 Util::ParallelMessage(file,func,line, "inside: (",i,",",j,",",k,") ",arr(i, j, k, n));
142 else if (validbox.contains(i,j,k))
143 Util::ParallelMessage(file,func,line, "border: (",i,",",j,",",k,") ",arr(i, j, k, n));
144 else
145 Util::ParallelMessage(file,func,line, "ghost: (",i,",",j,",",k,") ",arr(i, j, k, n));
146 }
147 }
148}
149
150void Compare(
151 std::string file, std::string func, int line,
152 const amrex::MultiFab &mf, std::string desc, const amrex::Box domain, int ngrow);
153
154AMREX_FORCE_INLINE
156 std::string file, std::string func, int line,
157 const amrex::MultiFab &mf, const amrex::Box domain, int ngrow)
158{
159 Compare(file,func,line,mf,"",domain, ngrow);
160}
161AMREX_FORCE_INLINE
163 std::string file, std::string func, int line,
164 const amrex::MultiFab &mf, int ngrow)
165{
166 Compare(file,func,line,mf,"",amrex::Box::TheUnitBox(), ngrow);
167}
168
169AMREX_FORCE_INLINE
171 std::string file, std::string func, int line,
172 const amrex::MultiFab &mf, std::string desc="")
173{
174 Compare(file,func,line,mf,desc,amrex::Box::TheUnitBox(),0);
175}
176
177}
178}
179// LCOV_EXCL_STOP
180
181
182#endif
static std::string LightYellow
Definition Color.H:30
static std::string Green
Definition Color.H:21
static std::string Blue
Definition Color.H:23
static std::string Red
Definition Color.H:20
static std::string Reset
Definition Color.H:8
static std::string Dim
Definition Color.H:10
void Compare(std::string file, std::string func, int line, const amrex::MultiFab &a_mf, std::string desc, amrex::Box domain, int)
Definition Debug.cpp:22
AMREX_FORCE_INLINE void Probe(std::string file, std::string func, int line, amrex::FabArray< amrex::BaseFab< T > > &a_mf, int i, int j, int k, int n)
Definition Debug.H:16
A collection of utility routines.
Definition Set.cpp:33
void ParallelMessage(std::string file, std::string func, int line, Args const &... args)
Definition Util.H:185