https://mooseframework.inl.gov
SwapBackSentinel.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 // MOOSE includes
13 #include "MooseTypes.h"
14 
15 // Forward declarations
16 class FEProblemBase;
17 
33 {
34 public:
41 
47  SwapBackFunction func,
48  THREAD_ID tid,
49  const bool & predicate,
50  const bool store_pred_as_value = true)
51  : _fe_problem(fe_problem),
52  _func(func),
53  _thread_id(tid),
54  _predicate(store_pred_as_value ? (predicate ? _always_true : _always_false) : predicate)
55  {
56  }
57 
59  : _fe_problem(fe_problem), _func(func), _thread_id(tid), _predicate(_always_true)
60  {
61  }
62 
67  {
68  if (_predicate)
70  }
71 
72 private:
76  static constexpr bool _always_true = true;
77  static constexpr bool _always_false = false;
78  const bool & _predicate;
79 };
void(FEProblemBase::*)(THREAD_ID) SwapBackFunction
SwapBackFunction is a typedef for a pointer to an FEProblemBase member function taking a THREAD_ID an...
~SwapBackSentinel()
The destructor calls swap back function only if the predicate is true.
static constexpr bool _always_false
const bool & _predicate
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
FEProblemBase & _fe_problem
SwapBackSentinel(FEProblemBase &fe_problem, SwapBackFunction func, THREAD_ID tid)
static constexpr bool _always_true
class infix_ostream_iterator if void
Definition: InfixIterator.h:26
SwapBackSentinel(FEProblemBase &fe_problem, SwapBackFunction func, THREAD_ID tid, const bool &predicate, const bool store_pred_as_value=true)
Constructor taking an FEProblemBase reference, a function to call, and the THREAD_ID argument...
SwapBackFunction _func
unsigned int THREAD_ID
Definition: MooseTypes.h:209
The "SwapBackSentinel" class's destructor guarantees that FEProblemBase::swapBackMaterials{Face,Neighbor}() is called even when an exception is thrown from FEProblemBase::reinitMaterials{Face,Neighbor}.