12#ifndef DUMUX_NONLINEAR_PRIMARY_VARIABLE_SWITCH_ADAPTER_HH
13#define DUMUX_NONLINEAR_PRIMARY_VARIABLE_SWITCH_ADAPTER_HH
16#include <dune/common/std/type_traits.hh>
23template<
class Variables>
26template<
class Variables>
35template<
class Variables>
36inline constexpr bool hasPriVarsSwitch = Dune::Std::is_detected<Detail::DetectPVSwitch, Variables>();
42template <
class Variables,
bool isVal
id = hasPriVarsSwitch<Variables>>
50 const int priVarSwitchVerbosity = getParamFromGroup<int>(paramGroup,
"PrimaryVariableSwitch.Verbosity", 1);
51 priVarSwitch_ = std::make_unique<PrimaryVariableSwitch>(priVarSwitchVerbosity);
57 template<
class SolutionVector>
60 priVarSwitch_->reset(sol.size());
61 priVarsSwitchedInLastIteration_ =
false;
62 const auto& problem = vars.curGridVolVars().problem();
63 const auto& gridGeometry = problem.gridGeometry();
64 priVarSwitch_->updateDirichletConstraints(problem, gridGeometry, vars, sol);
70 template<
class SolutionVector>
71 void invoke(SolutionVector& uCurrentIter, Variables& vars)
75 const auto& problem = vars.curGridVolVars().problem();
76 const auto& gridGeometry = problem.gridGeometry();
79 priVarsSwitchedInLastIteration_ = priVarSwitch_->update(uCurrentIter, vars, problem, gridGeometry);
80 if (priVarsSwitchedInLastIteration_)
82 for (
const auto& element : elements(gridGeometry.gridView()))
85 priVarSwitch_->updateSwitchedVolVars(problem, element, gridGeometry, vars, uCurrentIter);
88 priVarSwitch_->updateSwitchedFluxVarsCache(problem, element, gridGeometry, vars, uCurrentIter);
97 {
return priVarsSwitchedInLastIteration_; }
101 std::unique_ptr<PrimaryVariableSwitch> priVarSwitch_;
103 bool priVarsSwitchedInLastIteration_ =
false;
110template <
class Variables>
116 template<
class SolutionVector>
119 template<
class SolutionVector>
120 void invoke(SolutionVector&, Variables&) {}
void initialize(SolutionVector &, Variables &)
Definition: primaryvariableswitchadapter.hh:117
void invoke(SolutionVector &, Variables &)
Definition: primaryvariableswitchadapter.hh:120
bool switched() const
Definition: primaryvariableswitchadapter.hh:122
PrimaryVariableSwitchAdapter(const std::string ¶mGroup="")
Definition: primaryvariableswitchadapter.hh:114
An adapter for the Newton to manage models with primary variable switch.
Definition: primaryvariableswitchadapter.hh:44
void invoke(SolutionVector &uCurrentIter, Variables &vars)
Switch primary variables if necessary.
Definition: primaryvariableswitchadapter.hh:71
PrimaryVariableSwitchAdapter(const std::string ¶mGroup="")
Definition: primaryvariableswitchadapter.hh:48
void initialize(SolutionVector &sol, Variables &vars)
Initialize the privar switch.
Definition: primaryvariableswitchadapter.hh:58
bool switched() const
Whether the primary variables have been switched in the last call to invoke.
Definition: primaryvariableswitchadapter.hh:96
constexpr bool hasPriVarsSwitch
Helper boolean to check if the given variables involve primary variable switching.
Definition: primaryvariableswitchadapter.hh:36
Dune::Std::detected_or_t< int, DetectPVSwitch, Variables > PrimaryVariableSwitch
Definition: primaryvariableswitchadapter.hh:27
typename Variables::VolumeVariables::PrimaryVariableSwitch DetectPVSwitch
helper aliases to extract a primary variable switch from the VolumeVariables (if defined,...
Definition: primaryvariableswitchadapter.hh:24
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.