Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_ErrorList.H
Go to the documentation of this file.
1#ifndef AMREX_ErrorList_H_
2#define AMREX_ErrorList_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_Array.H>
6#include <AMReX_ArrayLim.H>
7#include <AMReX_Geometry.H>
8#include <AMReX_MultiFab.H>
9#include <AMReX_Parser.H>
10#include <AMReX_REAL.H>
11#include <AMReX_TagBox.H>
12#include <AMReX_Vector.H>
13
14#include <string>
15#include <memory>
16
17namespace amrex {
18
19
20extern "C"
21{
22
26 using ErrorFuncDefault = void (*)(int* tag, AMREX_ARLIM_P(tlo), AMREX_ARLIM_P(thi),
27 const int* tagval, const int* clearval,
28 amrex::Real* data, AMREX_ARLIM_P(data_lo), AMREX_ARLIM_P(data_hi),
29 const int* lo, const int * hi, const int* nvar,
30 const int* domain_lo, const int* domain_hi,
31 const amrex::Real* dx, const amrex::Real* xlo,
32 const amrex::Real* prob_lo, const amrex::Real* time,
33 const int* level);
34
35 using ErrorFunc2Default = void (*)(int* tag, AMREX_ARLIM_P(tlo), AMREX_ARLIM_P(thi),
36 const int* tagval, const int* clearval,
37 amrex::Real* data, AMREX_ARLIM_P(data_lo), AMREX_ARLIM_P(data_hi),
38 const int* lo, const int * hi, const int* nvar,
39 const int* domain_lo, const int* domain_hi,
40 const amrex::Real* dx, const int* level, const amrex::Real* avg);
41
42
66 using ErrorFunc3DDefault = void (*)(int* tag, const int* tlo, const int* thi,
67 const int* tagval, const int* clearval,
68 amrex::Real* data, const int* data_lo, const int* data_hi,
69 const int* lo, const int * hi, const int* nvar,
70 const int* domain_lo, const int* domain_hi,
71 const amrex::Real* dx, const amrex::Real* xlo,
72 const amrex::Real* prob_lo, const amrex::Real* time,
73 const int* level);
74
75}
76
77
88{
89public:
90 //
91 // Error types.
92 //
94 //
95 // Class wrapper around ErrorFuncDefault.
96 //
98 {
99 public:
100
105
111 // No explicit because some codes rely on it.
113
119 // No explicit because some codes rely on it.
121
126 [[nodiscard]] virtual ErrorFunc* clone () const;
127
131 virtual ~ErrorFunc () = default;
132
133 ErrorFunc (ErrorFunc const&) = default;
134 ErrorFunc (ErrorFunc &&) = delete;
135 ErrorFunc& operator= (ErrorFunc const&) = default;
137
141 virtual void operator () (int* tag, AMREX_ARLIM_P(tlo), AMREX_ARLIM_P(thi),
142 const int* tagval, const int* clearval,
143 Real* data, AMREX_ARLIM_P(data_lo), AMREX_ARLIM_P(data_hi),
144 const int* lo, const int * hi, const int* nvar,
145 const int* domain_lo, const int* domain_hi,
146 const Real* dx, const Real* xlo,
147 const Real* prob_lo, const Real* time,
148 const int* level) const;
149
172 virtual void operator () (int* tag, const int* tlo, const int* thi,
173 const int* tagval, const int* clearval,
174 Real* data, const int* dlo, const int* dhi,
175 const int* lo, const int * hi, const int* nvar,
176 const int* domain_lo, const int* domain_hi,
177 const Real* dx, const Real* xlo,
178 const Real* prob_lo, const Real* time,
179 const int* level) const;
180 protected:
181
184 };
186 {
187 public:
188
193
199 // No explicit because some codes rely on it.
201
206 [[nodiscard]] virtual ErrorFunc2* clone () const;
207
211 virtual ~ErrorFunc2 () = default;
212
213 ErrorFunc2 (ErrorFunc2 const&) = default;
214 ErrorFunc2 (ErrorFunc2 &&) = delete;
215 ErrorFunc2& operator= (ErrorFunc2 const&) = default;
217
219
239 virtual void operator () (int* tag, AMREX_ARLIM_P(tlo), AMREX_ARLIM_P(thi),
240 const int* tagval, const int* clearval,
241 Real* data, AMREX_ARLIM_P(data_lo), AMREX_ARLIM_P(data_hi),
242 const int* lo, const int * hi, const int* nvar,
243 const int* domain_lo, const int* domain_hi,
244 const Real* dx, const int* level, const Real* avg) const;
246 protected:
247
249 };
250
259 ErrorRec (std::string nm, int ng, ErrorType etyp,
260 const ErrorRec::ErrorFunc2& f2);
261
263 ErrorRec (std::string nm, int ng, ErrorType etyp,
264 const ErrorRec::ErrorFunc& f);
265
266 virtual ~ErrorRec ();
267
268 ErrorRec (ErrorRec const&) = delete;
269 ErrorRec (ErrorRec &&) = delete;
270 ErrorRec& operator= (ErrorRec const&) = delete;
272
276 [[nodiscard]] const std::string& name () const noexcept;
277
281 [[nodiscard]] int nGrow () const noexcept;
282
286 [[nodiscard]] ErrorType errType () const noexcept;
287
291 [[nodiscard]] virtual const ErrorRec::ErrorFunc& errFunc () const;
292 [[nodiscard]] virtual const ErrorRec::ErrorFunc2& errFunc2() const;
293
294private:
295
297 std::string derive_name;
298
300 int ngrow;
301
303 ErrorType err_type;
304
306 ErrorFunc* err_func;
307 ErrorFunc2* err_func2;
308};
309
310
317{
318public:
319 ErrorList() noexcept = default;
320
324 [[nodiscard]] int size () const noexcept;
325
334 void add (const std::string& name,
335 int nextra,
336 ErrorRec::ErrorType typ,
337 const ErrorRec::ErrorFunc& func);
338
340 void add (const std::string& name,
341 int nextra,
342 ErrorRec::ErrorType typ,
343 const ErrorRec::ErrorFunc2& func);
344
346 [[nodiscard]] const ErrorRec& operator[] (int k) const noexcept;
347
348 void clear (bool rs0 = false) { vec.clear(); if(rs0) { vec.resize(0); } }
349
350private:
351
353};
354
355std::ostream& operator << (std::ostream& os, const ErrorList& elst);
356
359 {
360 int m_max_level = 1000;
361 Real m_min_time = std::numeric_limits<Real>::lowest();
362 Real m_max_time = std::numeric_limits<Real>::max();
363 int m_volume_weighting = 0;
364 int m_derefine = 0;
366
367 AMRErrorTagInfo& SetMaxLevel (int max_level) noexcept {
368 m_max_level = max_level;
369 return *this;
370 }
372 m_min_time = min_time;
373 return *this;
374 }
376 m_max_time = max_time;
377 return *this;
378 }
379 AMRErrorTagInfo& SetRealBox (const amrex::RealBox& realbox) noexcept {
380 m_realbox = realbox;
381 return *this;
382 }
383 AMRErrorTagInfo& SetVolumeWeighting (int volume_weighting) noexcept {
384 m_volume_weighting = volume_weighting;
385 return *this;
386 }
387 AMRErrorTagInfo& SetDerefine (int derefine) noexcept {
388 m_derefine = derefine;
389 return *this;
390 }
391 };
392
397 {
398 public:
399
400 enum TEST {GRAD=0, RELGRAD, LESS, GREATER, VORT, BOX, USER, PARSER};
401
402 struct UserFunc
403 {
404 virtual ~UserFunc () = default;
405
406 UserFunc (UserFunc const&) = default;
407 UserFunc (UserFunc &&) = default;
408 UserFunc& operator= (UserFunc const&) = default;
409 UserFunc& operator= (UserFunc &&) = default;
410
411 virtual void operator() (const amrex::Box& bx,
413 amrex::Array4<char> const& tag,
414 amrex::Real time,
415 int level,
416 char tagval,
417 char clearval) = 0;
418 };
419
421 explicit AMRErrorTag (const AMRErrorTagInfo& info = AMRErrorTagInfo()) noexcept
422 : m_info(info), m_ngrow(SetNGrow()) {}
423
434 std::string field,
435 const AMRErrorTagInfo& info = AMRErrorTagInfo()) noexcept
436 : m_value(info.m_max_level, value), m_test(test), m_field(std::move(field)), m_info(info),
437 m_ngrow(SetNGrow())
438 {
439 }
440
451 std::string field,
452 const AMRErrorTagInfo& info = AMRErrorTagInfo()) noexcept
453 : m_test(test), m_field(std::move(field)), m_info(info), m_ngrow(SetNGrow())
454 {
455 AMREX_ASSERT(!value.empty());
456 m_value.resize(info.m_max_level);
457 for (int i = 0; i < m_value.size() && i < value.size(); ++i) {
458 m_value[i] = value[i];
459 }
460 // If the user didn't provided a value for every level,
461 // assume the last value holds for all higher levels.
462 for (auto i = int(value.size()); i < m_value.size(); ++i) {
463 m_value[i] = value[value.size()-1];
464 }
465 }
466
476 std::string field,
477 int ngrow,
478 const AMRErrorTagInfo& info = AMRErrorTagInfo()) noexcept
479 : m_userfunc(userfunc), m_field(std::move(field)), m_info(info), m_ngrow(ngrow) {}
480
484 explicit AMRErrorTag (Parser parser,
485 const AMRErrorTagInfo& info = AMRErrorTagInfo());
486
498 void operator() (amrex::TagBoxArray& tb,
499 const amrex::MultiFab* mf,
500 char clearval,
501 char tagval,
502 amrex::Real time,
503 int level,
504 const amrex::Geometry& geom) const noexcept;
505
506 [[nodiscard]] int NGrow() const noexcept {return m_ngrow;}
507 [[nodiscard]] const std::string& Field () const noexcept {return m_field;}
508
509 [[nodiscard]] AMRErrorTagInfo& GetInfo () noexcept {return m_info;}
510 [[nodiscard]] AMRErrorTagInfo const& GetInfo () const noexcept {return m_info;}
511 void SetInfo (AMRErrorTagInfo const& info) noexcept {m_info = info;}
512
513 protected:
514 [[nodiscard]] int SetNGrow () const noexcept;
515
516 Vector<Real> m_value;
517 TEST m_test{BOX};
518 UserFunc* m_userfunc = nullptr;
519 std::unique_ptr<Parser> m_parser;
521 std::string m_field;
523 int m_ngrow = 0;
524 };
525}
526
527#endif
#define AMREX_ARLIM_P(x)
Definition AMReX_ArrayLim.H:30
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
Tag storage used for AMR error estimation and refinement decisions.
Flexible tagging rule that supports gradients, thresholds, boxes, and user functors.
Definition AMReX_ErrorList.H:397
ParserExecutor< 4 > m_parser_exe
Definition AMReX_ErrorList.H:520
AMRErrorTagInfo & GetInfo() noexcept
Definition AMReX_ErrorList.H:509
AMRErrorTag(AMRErrorTag::UserFunc *userfunc, std::string field, int ngrow, const AMRErrorTagInfo &info=AMRErrorTagInfo()) noexcept
Construct a tag that delegates to a user functor.
Definition AMReX_ErrorList.H:475
int NGrow() const noexcept
Definition AMReX_ErrorList.H:506
AMRErrorTag(amrex::Vector< amrex::Real > value, AMRErrorTag::TEST test, std::string field, const AMRErrorTagInfo &info=AMRErrorTagInfo()) noexcept
Construct a tag with per-level threshold values.
Definition AMReX_ErrorList.H:449
AMRErrorTag(amrex::Real value, AMRErrorTag::TEST test, std::string field, const AMRErrorTagInfo &info=AMRErrorTagInfo()) noexcept
Construct a tag using a scalar threshold across all levels.
Definition AMReX_ErrorList.H:432
std::unique_ptr< Parser > m_parser
Definition AMReX_ErrorList.H:519
AMRErrorTagInfo m_info
Definition AMReX_ErrorList.H:522
AMRErrorTag(const AMRErrorTagInfo &info=AMRErrorTagInfo()) noexcept
Construct a tag with default BOX test and the supplied metadata.
Definition AMReX_ErrorList.H:421
int SetNGrow() const noexcept
std::string m_field
Definition AMReX_ErrorList.H:521
AMRErrorTag(Parser parser, const AMRErrorTagInfo &info=AMRErrorTagInfo())
AMRErrorTagInfo const & GetInfo() const noexcept
Definition AMReX_ErrorList.H:510
const std::string & Field() const noexcept
Definition AMReX_ErrorList.H:507
TEST
Definition AMReX_ErrorList.H:400
@ BOX
Definition AMReX_ErrorList.H:400
void SetInfo(AMRErrorTagInfo const &info) noexcept
Definition AMReX_ErrorList.H:511
A List of ErrorRecs.
Definition AMReX_ErrorList.H:317
ErrorList() noexcept=default
Definition AMReX_ErrorList.H:186
ErrorFunc2(ErrorFunc2Default inFunc)
A Constructor.
virtual ~ErrorFunc2()=default
Destructor.
ErrorFunc2 & operator=(ErrorFunc2 const &)=default
ErrorFunc2Default m_func
Definition AMReX_ErrorList.H:248
ErrorFunc2(ErrorFunc2 &&)=delete
virtual ErrorFunc2 * clone() const
Return a ptr to a clone of this object. It is the responsibility of the caller to delete the result.
ErrorFunc2(ErrorFunc2 const &)=default
ErrorFunc2()
Bogus constructor.
Definition AMReX_ErrorList.H:98
ErrorFunc(ErrorFunc &&)=delete
ErrorFunc(ErrorFunc3DDefault inFunc)
A Constructor.
ErrorFunc(ErrorFuncDefault inFunc)
A Constructor.
ErrorFunc(ErrorFunc const &)=default
ErrorFunc3DDefault m_func3D
Definition AMReX_ErrorList.H:183
ErrorFuncDefault m_func
Definition AMReX_ErrorList.H:182
ErrorFunc()
Bogus constructor.
virtual void operator()(int *tag, const int &, const int &, const int &, const int &, const int &, const int &, const int *tagval, const int *clearval, Real *data, const int &, const int &, const int &, const int &, const int &, const int &, const int *lo, const int *hi, const int *nvar, const int *domain_lo, const int *domain_hi, const Real *dx, const Real *xlo, const Real *prob_lo, const Real *time, const int *level) const
Tag cells using "regular" function.
virtual ErrorFunc * clone() const
Return a ptr to a clone of this object. It is the responsibility of the caller to delete the result.
ErrorFunc & operator=(ErrorFunc const &)=default
virtual ~ErrorFunc()=default
Destructor.
Error Record.
Definition AMReX_ErrorList.H:88
virtual const ErrorRec::ErrorFunc & errFunc() const
The extern "C" functions to do the error tagging.
ErrorRec(ErrorRec &&)=delete
ErrorRec(std::string nm, int ng, ErrorType etyp, const ErrorRec::ErrorFunc &f)
Construct an error record that uses the ErrorFunc interface (same parameters as above).
ErrorRec(ErrorRec const &)=delete
ErrorRec & operator=(ErrorRec const &)=delete
ErrorType errType() const noexcept
The type of the error tagging.
int nGrow() const noexcept
The number of extra zones needed for derivation.
virtual const ErrorRec::ErrorFunc2 & errFunc2() const
ErrorRec(std::string nm, int ng, ErrorType etyp, const ErrorRec::ErrorFunc2 &f2)
Construct an error record that uses the ErrorFunc2 interface.
virtual ~ErrorRec()
const std::string & name() const noexcept
The name of the quantity to derive.
ErrorType
Definition AMReX_ErrorList.H:93
@ UseAverage
Definition AMReX_ErrorList.H:93
@ Special
Definition AMReX_ErrorList.H:93
@ Standard
Definition AMReX_ErrorList.H:93
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:74
A collection (stored as an array) of FArrayBox objects.
Definition AMReX_MultiFab.H:40
Definition AMReX_Parser.H:71
A Box with real dimensions.
Definition AMReX_RealBox.H:28
An array of TagBoxes.
Definition AMReX_TagBox.H:151
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:28
Long size() const noexcept
Definition AMReX_Vector.H:53
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:79
Definition AMReX_Amr.cpp:49
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Stream helper; forwards to the friend declared inside AmrMesh.
Definition AMReX_AmrMesh.cpp:1238
void(*)(int *tag, const int &, const int &, const int &, const int &, const int &, const int &, const int *tagval, const int *clearval, amrex::Real *data, const int &, const int &, const int &, const int &, const int &, const int &, const int *lo, const int *hi, const int *nvar, const int *domain_lo, const int *domain_hi, const amrex::Real *dx, const int *level, const amrex::Real *avg) ErrorFunc2Default
Definition AMReX_ErrorList.H:40
void(*)(int *tag, const int &, const int &, const int &, const int &, const int &, const int &, const int *tagval, const int *clearval, amrex::Real *data, const int &, const int &, const int &, const int &, const int &, const int &, const int *lo, const int *hi, const int *nvar, const int *domain_lo, const int *domain_hi, const amrex::Real *dx, const amrex::Real *xlo, const amrex::Real *prob_lo, const amrex::Real *time, const int *level) ErrorFuncDefault
Type of extern "C" function called by ErrorRec to do tagging of cells for refinement.
Definition AMReX_ErrorList.H:33
void(*)(int *tag, const int *tlo, const int *thi, const int *tagval, const int *clearval, amrex::Real *data, const int *data_lo, const int *data_hi, const int *lo, const int *hi, const int *nvar, const int *domain_lo, const int *domain_hi, const amrex::Real *dx, const amrex::Real *xlo, const amrex::Real *prob_lo, const amrex::Real *time, const int *level) ErrorFunc3DDefault
Dimension agnostic version that always has three elements. Note that this is only implemented for the...
Definition AMReX_ErrorList.H:73
Optional knobs that control AMRErrorTag behavior (time window, level limits, etc.).
Definition AMReX_ErrorList.H:359
AMRErrorTagInfo & SetRealBox(const amrex::RealBox &realbox) noexcept
Definition AMReX_ErrorList.H:379
AMRErrorTagInfo & SetMaxTime(amrex::Real max_time) noexcept
Definition AMReX_ErrorList.H:375
AMRErrorTagInfo & SetDerefine(int derefine) noexcept
Definition AMReX_ErrorList.H:387
AMRErrorTagInfo & SetMaxLevel(int max_level) noexcept
Definition AMReX_ErrorList.H:367
AMRErrorTagInfo & SetMinTime(amrex::Real min_time) noexcept
Definition AMReX_ErrorList.H:371
RealBox m_realbox
Definition AMReX_ErrorList.H:365
AMRErrorTagInfo & SetVolumeWeighting(int volume_weighting) noexcept
Definition AMReX_ErrorList.H:383
Definition AMReX_ErrorList.H:403
virtual ~UserFunc()=default
UserFunc(UserFunc const &)=default
UserFunc(UserFunc &&)=default
A multidimensional array accessor.
Definition AMReX_Array4.H:283
Definition AMReX_Parser.H:21