Block-Structured AMR Software Framework
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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_Vector.H>
7#include <AMReX_REAL.H>
8#include <AMReX_ArrayLim.H>
9#include <AMReX_MultiFab.H>
10#include <AMReX_TagBox.H>
11#include <AMReX_Geometry.H>
12
13#include <string>
14#include <memory>
15
16namespace amrex {
17
18
19extern "C"
20{
21
44 using ErrorFuncDefault = void (*)(int* tag, AMREX_ARLIM_P(tlo), AMREX_ARLIM_P(thi),
45 const int* tagval, const int* clearval,
46 amrex::Real* data, AMREX_ARLIM_P(data_lo), AMREX_ARLIM_P(data_hi),
47 const int* lo, const int * hi, const int* nvar,
48 const int* domain_lo, const int* domain_hi,
49 const amrex::Real* dx, const amrex::Real* xlo,
50 const amrex::Real* prob_lo, const amrex::Real* time,
51 const int* level);
52
53 using ErrorFunc2Default = void (*)(int* tag, AMREX_ARLIM_P(tlo), AMREX_ARLIM_P(thi),
54 const int* tagval, const int* clearval,
55 amrex::Real* data, AMREX_ARLIM_P(data_lo), AMREX_ARLIM_P(data_hi),
56 const int* lo, const int * hi, const int* nvar,
57 const int* domain_lo, const int* domain_hi,
58 const amrex::Real* dx, const int* level, const amrex::Real* avg);
59
60
84 using ErrorFunc3DDefault = void (*)(int* tag, const int* tlo, const int* thi,
85 const int* tagval, const int* clearval,
86 amrex::Real* data, const int* data_lo, const int* data_hi,
87 const int* lo, const int * hi, const int* nvar,
88 const int* domain_lo, const int* domain_hi,
89 const amrex::Real* dx, const amrex::Real* xlo,
90 const amrex::Real* prob_lo, const amrex::Real* time,
91 const int* level);
92
93}
94
95
106{
107public:
108 //
109 // Error types.
110 //
112 //
113 // Class wrapper around ErrorFuncDefault.
114 //
116 {
117 public:
118
123
129 // No explicit because some codes rely on it.
131
137 // No explicit because some codes rely on it.
139
144 [[nodiscard]] virtual ErrorFunc* clone () const;
145
149 virtual ~ErrorFunc () = default;
150
151 ErrorFunc (ErrorFunc const&) = default;
152 ErrorFunc (ErrorFunc &&) = delete;
153 ErrorFunc& operator= (ErrorFunc const&) = default;
155
178 virtual void operator () (int* tag, AMREX_ARLIM_P(tlo), AMREX_ARLIM_P(thi),
179 const int* tagval, const int* clearval,
180 Real* data, AMREX_ARLIM_P(data_lo), AMREX_ARLIM_P(data_hi),
181 const int* lo, const int * hi, const int* nvar,
182 const int* domain_lo, const int* domain_hi,
183 const Real* dx, const Real* xlo,
184 const Real* prob_lo, const Real* time,
185 const int* level) const;
186
209 virtual void operator () (int* tag, const int* tlo, const int* thi,
210 const int* tagval, const int* clearval,
211 Real* data, const int* dlo, const int* dhi,
212 const int* lo, const int * hi, const int* nvar,
213 const int* domain_lo, const int* domain_hi,
214 const Real* dx, const Real* xlo,
215 const Real* prob_lo, const Real* time,
216 const int* level) const;
217 protected:
218
221 };
223 {
224 public:
225
230
236 // No explicit because some codes rely on it.
238
243 [[nodiscard]] virtual ErrorFunc2* clone () const;
244
248 virtual ~ErrorFunc2 () = default;
249
250 ErrorFunc2 (ErrorFunc2 const&) = default;
251 ErrorFunc2 (ErrorFunc2 &&) = delete;
252 ErrorFunc2& operator= (ErrorFunc2 const&) = default;
254
275 virtual void operator () (int* tag, AMREX_ARLIM_P(tlo), AMREX_ARLIM_P(thi),
276 const int* tagval, const int* clearval,
277 Real* data, AMREX_ARLIM_P(data_lo), AMREX_ARLIM_P(data_hi),
278 const int* lo, const int * hi, const int* nvar,
279 const int* domain_lo, const int* domain_hi,
280 const Real* dx, const int* level, const Real* avg) const;
281 protected:
282
284 };
285
294 ErrorRec (std::string nm, int ng, ErrorType etyp,
295 const ErrorRec::ErrorFunc2& f2);
296
297 ErrorRec (std::string nm, int ng, ErrorType etyp,
298 const ErrorRec::ErrorFunc& f);
299
300 virtual ~ErrorRec ();
301
302 ErrorRec (ErrorRec const&) = delete;
303 ErrorRec (ErrorRec &&) = delete;
304 ErrorRec& operator= (ErrorRec const&) = delete;
306
310 [[nodiscard]] const std::string& name () const noexcept;
311
315 [[nodiscard]] int nGrow () const noexcept;
316
320 [[nodiscard]] ErrorType errType () const noexcept;
321
325 [[nodiscard]] virtual const ErrorRec::ErrorFunc& errFunc () const;
326 [[nodiscard]] virtual const ErrorRec::ErrorFunc2& errFunc2() const;
327
328private:
329
331 std::string derive_name;
332
334 int ngrow;
335
338
342};
343
344
351{
352public:
353 ErrorList() noexcept = default;
354
358 [[nodiscard]] int size () const noexcept;
359
368 void add (const std::string& name,
369 int nextra,
370 ErrorRec::ErrorType typ,
371 const ErrorRec::ErrorFunc& func);
372
373 void add (const std::string& name,
374 int nextra,
375 ErrorRec::ErrorType typ,
376 const ErrorRec::ErrorFunc2& func);
377
379 [[nodiscard]] const ErrorRec& operator[] (int k) const noexcept;
380
381 void clear (bool rs0 = false) { vec.clear(); if(rs0) { vec.resize(0); } }
382
383private:
384
386};
387
388std::ostream& operator << (std::ostream& os, const ErrorList& elst);
389
391 {
392 int m_max_level = 1000;
393 Real m_min_time = std::numeric_limits<Real>::lowest();
394 Real m_max_time = std::numeric_limits<Real>::max();
395 int m_volume_weighting = 0;
396 int m_derefine = 0;
398
399 AMRErrorTagInfo& SetMaxLevel (int max_level) noexcept {
400 m_max_level = max_level;
401 return *this;
402 }
403 AMRErrorTagInfo& SetMinTime (amrex::Real min_time) noexcept {
404 m_min_time = min_time;
405 return *this;
406 }
407 AMRErrorTagInfo& SetMaxTime (amrex::Real max_time) noexcept {
408 m_max_time = max_time;
409 return *this;
410 }
411 AMRErrorTagInfo& SetRealBox (const amrex::RealBox& realbox) noexcept {
412 m_realbox = realbox;
413 return *this;
414 }
415 AMRErrorTagInfo& SetVolumeWeighting (int volume_weighting) noexcept {
416 m_volume_weighting = volume_weighting;
417 return *this;
418 }
419 AMRErrorTagInfo& SetDerefine (int derefine) noexcept {
420 m_derefine = derefine;
421 return *this;
422 }
423 };
424
426 {
427 public:
428
429 enum TEST {GRAD=0, RELGRAD, LESS, GREATER, VORT, BOX, USER};
430
431 struct UserFunc
432 {
433 virtual ~UserFunc () = default;
434
435 UserFunc (UserFunc const&) = default;
436 UserFunc (UserFunc &&) = default;
437 UserFunc& operator= (UserFunc const&) = default;
438 UserFunc& operator= (UserFunc &&) = default;
439
440 virtual void operator() (const amrex::Box& bx,
442 amrex::Array4<char> const& tag,
443 amrex::Real time,
444 int level,
445 char tagval,
446 char clearval) = 0;
447 };
448
449 explicit AMRErrorTag (const AMRErrorTagInfo& info = AMRErrorTagInfo()) noexcept
450 : m_info(info), m_ngrow(SetNGrow()) {}
451
452 AMRErrorTag (amrex::Real value,
454 std::string field,
455 const AMRErrorTagInfo& info = AMRErrorTagInfo()) noexcept
456 : m_value(info.m_max_level, value), m_test(test), m_field(std::move(field)), m_info(info),
457 m_ngrow(SetNGrow())
458 {
459 }
460
463 std::string field,
464 const AMRErrorTagInfo& info = AMRErrorTagInfo()) noexcept
465 : m_test(test), m_field(std::move(field)), m_info(info), m_ngrow(SetNGrow())
466 {
467 AMREX_ASSERT(!value.empty());
468 m_value.resize(info.m_max_level);
469 for (int i = 0; i < m_value.size() && i < value.size(); ++i) {
470 m_value[i] = value[i];
471 }
472 // If the user didn't provided a value for every level,
473 // assume the last value holds for all higher levels.
474 for (auto i = int(value.size()); i < m_value.size(); ++i) {
475 m_value[i] = value[value.size()-1];
476 }
477 }
478
480 std::string field,
481 int ngrow,
482 const AMRErrorTagInfo& info = AMRErrorTagInfo()) noexcept
483 : m_userfunc(userfunc), m_field(std::move(field)), m_info(info), m_ngrow(ngrow) {}
484
485 void operator() (amrex::TagBoxArray& tb,
486 const amrex::MultiFab* mf,
487 char clearval,
488 char tagval,
489 amrex::Real time,
490 int level,
491 const amrex::Geometry& geom) const noexcept;
492
493 [[nodiscard]] int NGrow() const noexcept {return m_ngrow;}
494 [[nodiscard]] const std::string& Field () const noexcept {return m_field;}
495
496 [[nodiscard]] AMRErrorTagInfo& GetInfo () noexcept {return m_info;}
497 [[nodiscard]] AMRErrorTagInfo const& GetInfo () const noexcept {return m_info;}
498 void SetInfo (AMRErrorTagInfo const& info) noexcept {m_info = info;}
499
500 protected:
501 [[nodiscard]] int SetNGrow () const noexcept;
502
503 Vector<Real> m_value;
504 TEST m_test{BOX};
505 UserFunc* m_userfunc = nullptr;
506 std::string m_field;
509 };
510}
511
512#endif
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
Definition AMReX_ErrorList.H:426
AMRErrorTagInfo & GetInfo() noexcept
Definition AMReX_ErrorList.H:496
AMRErrorTag(AMRErrorTag::UserFunc *userfunc, std::string field, int ngrow, const AMRErrorTagInfo &info=AMRErrorTagInfo()) noexcept
Definition AMReX_ErrorList.H:479
int NGrow() const noexcept
Definition AMReX_ErrorList.H:493
AMRErrorTag(amrex::Vector< amrex::Real > value, AMRErrorTag::TEST test, std::string field, const AMRErrorTagInfo &info=AMRErrorTagInfo()) noexcept
Definition AMReX_ErrorList.H:461
AMRErrorTag(amrex::Real value, AMRErrorTag::TEST test, std::string field, const AMRErrorTagInfo &info=AMRErrorTagInfo()) noexcept
Definition AMReX_ErrorList.H:452
AMRErrorTagInfo m_info
Definition AMReX_ErrorList.H:507
AMRErrorTag(const AMRErrorTagInfo &info=AMRErrorTagInfo()) noexcept
Definition AMReX_ErrorList.H:449
std::string m_field
Definition AMReX_ErrorList.H:506
int m_ngrow
Definition AMReX_ErrorList.H:508
AMRErrorTagInfo const & GetInfo() const noexcept
Definition AMReX_ErrorList.H:497
const std::string & Field() const noexcept
Definition AMReX_ErrorList.H:494
TEST
Definition AMReX_ErrorList.H:429
@ BOX
Definition AMReX_ErrorList.H:429
void SetInfo(AMRErrorTagInfo const &info) noexcept
Definition AMReX_ErrorList.H:498
A List of ErrorRecs.
Definition AMReX_ErrorList.H:351
Vector< std::unique_ptr< ErrorRec > > vec
Definition AMReX_ErrorList.H:385
ErrorList() noexcept=default
Definition AMReX_ErrorList.H:223
virtual ~ErrorFunc2()=default
Destructor.
ErrorFunc2 & operator=(ErrorFunc2 const &)=default
ErrorFunc2Default m_func
Definition AMReX_ErrorList.H:283
virtual void operator()(int *tag, AMREX_ARLIM_P(tlo), AMREX_ARLIM_P(thi), const int *tagval, const int *clearval, Real *data, AMREX_ARLIM_P(data_lo), AMREX_ARLIM_P(data_hi), const int *lo, const int *hi, const int *nvar, const int *domain_lo, const int *domain_hi, const Real *dx, const int *level, const Real *avg) const
Tag cells cells using "v2" interface.
Definition AMReX_ErrorList.cpp:82
ErrorFunc2(ErrorFunc2 &&)=delete
ErrorFunc2(ErrorFunc2 const &)=default
ErrorFunc2()
Bogus constructor.
virtual ErrorFunc2 * clone() const
Return a ptr to a clone of this object. It is the responsibility of the caller to delete the result.
Definition AMReX_ErrorList.cpp:76
Definition AMReX_ErrorList.H:116
ErrorFunc(ErrorFunc &&)=delete
virtual ErrorFunc * clone() const
Return a ptr to a clone of this object. It is the responsibility of the caller to delete the result.
Definition AMReX_ErrorList.cpp:23
ErrorFunc(ErrorFunc const &)=default
ErrorFunc3DDefault m_func3D
Definition AMReX_ErrorList.H:220
virtual void operator()(int *tag, AMREX_ARLIM_P(tlo), AMREX_ARLIM_P(thi), const int *tagval, const int *clearval, Real *data, AMREX_ARLIM_P(data_lo), AMREX_ARLIM_P(data_hi), 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.
ErrorFuncDefault m_func
Definition AMReX_ErrorList.H:219
ErrorFunc()
Bogus constructor.
ErrorFunc & operator=(ErrorFunc const &)=default
virtual ~ErrorFunc()=default
Destructor.
Error Record.
Definition AMReX_ErrorList.H:106
int ngrow
Number of extra zones.
Definition AMReX_ErrorList.H:334
ErrorRec(ErrorRec &&)=delete
ErrorRec(ErrorRec const &)=delete
ErrorRec & operator=(ErrorRec const &)=delete
int nGrow() const noexcept
The number of extra zones needed for derivation.
Definition AMReX_ErrorList.cpp:126
virtual const ErrorRec::ErrorFunc2 & errFunc2() const
Definition AMReX_ErrorList.cpp:144
virtual const ErrorRec::ErrorFunc & errFunc() const
The extern "C" functions to do the error tagging.
Definition AMReX_ErrorList.cpp:138
const std::string & name() const noexcept
The name of the quantity to derive.
Definition AMReX_ErrorList.cpp:120
std::string derive_name
Name of quantity to derive.
Definition AMReX_ErrorList.H:331
virtual ~ErrorRec()
Definition AMReX_ErrorList.cpp:149
ErrorType err_type
The type of Error.
Definition AMReX_ErrorList.H:337
ErrorType errType() const noexcept
The type of the error tagging.
Definition AMReX_ErrorList.cpp:132
ErrorFunc * err_func
Functions to do error estimation.
Definition AMReX_ErrorList.H:340
ErrorFunc2 * err_func2
Definition AMReX_ErrorList.H:341
ErrorType
Definition AMReX_ErrorList.H:111
@ UseAverage
Definition AMReX_ErrorList.H:111
@ Special
Definition AMReX_ErrorList.H:111
@ Standard
Definition AMReX_ErrorList.H:111
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:73
A collection (stored as an array) of FArrayBox objects.
Definition AMReX_MultiFab.H:38
A Box with real dimensions. A RealBox is OK iff volume >= 0.
Definition AMReX_RealBox.H:21
An array of TagBoxes.
Definition AMReX_TagBox.H:150
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:27
Long size() const noexcept
Definition AMReX_Vector.H:50
Definition AMReX_Amr.cpp:49
void(*)(int *tag, AMREX_ARLIM_P(tlo), AMREX_ARLIM_P(thi), const int *tagval, const int *clearval, amrex::Real *data, AMREX_ARLIM_P(data_lo), AMREX_ARLIM_P(data_hi), 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:58
void(*)(int *tag, AMREX_ARLIM_P(tlo), AMREX_ARLIM_P(thi), const int *tagval, const int *clearval, amrex::Real *data, AMREX_ARLIM_P(data_lo), AMREX_ARLIM_P(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) ErrorFuncDefault
Type of extern "C" function called by ErrorRec to do tagging of cells for refinement.
Definition AMReX_ErrorList.H:51
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:91
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Definition AMReX_AmrMesh.cpp:1236
Definition AMReX_ErrorList.H:391
AMRErrorTagInfo & SetRealBox(const amrex::RealBox &realbox) noexcept
Definition AMReX_ErrorList.H:411
AMRErrorTagInfo & SetMaxTime(amrex::Real max_time) noexcept
Definition AMReX_ErrorList.H:407
AMRErrorTagInfo & SetDerefine(int derefine) noexcept
Definition AMReX_ErrorList.H:419
AMRErrorTagInfo & SetMaxLevel(int max_level) noexcept
Definition AMReX_ErrorList.H:399
AMRErrorTagInfo & SetMinTime(amrex::Real min_time) noexcept
Definition AMReX_ErrorList.H:403
RealBox m_realbox
Definition AMReX_ErrorList.H:397
AMRErrorTagInfo & SetVolumeWeighting(int volume_weighting) noexcept
Definition AMReX_ErrorList.H:415
Definition AMReX_ErrorList.H:432
virtual ~UserFunc()=default
UserFunc(UserFunc const &)=default
UserFunc(UserFunc &&)=default
Definition AMReX_Array4.H:61