24#ifndef DUMUX_NONLINEAR_PRIMARY_VARIABLE_SWITCH_ADAPTER_HH
25#define DUMUX_NONLINEAR_PRIMARY_VARIABLE_SWITCH_ADAPTER_HH
28#include <dune/common/std/type_traits.hh>
35template<
class Variables>
38template<
class Variables>
39using GetPVSwitch = Dune::Std::detected_or<int, DetectPVSwitch, Variables>;
41template<
class Variables>
50template<
class Variables>
57template <
class Variables,
bool isVal
id = hasPriVarsSwitch<Variables>>
65 const int priVarSwitchVerbosity = getParamFromGroup<int>(paramGroup,
"PrimaryVariableSwitch.Verbosity", 1);
66 priVarSwitch_ = std::make_unique<PrimaryVariableSwitch>(priVarSwitchVerbosity);
72 template<
class SolutionVector>
75 priVarSwitch_->reset(sol.size());
76 priVarsSwitchedInLastIteration_ =
false;
77 const auto& problem = vars.curGridVolVars().problem();
78 const auto& gridGeometry = problem.gridGeometry();
79 priVarSwitch_->updateDirichletConstraints(problem, gridGeometry, vars, sol);
85 template<
class SolutionVector>
86 void invoke(SolutionVector& uCurrentIter, Variables& vars)
90 const auto& problem = vars.curGridVolVars().problem();
91 const auto& gridGeometry = problem.gridGeometry();
94 priVarsSwitchedInLastIteration_ = priVarSwitch_->update(uCurrentIter, vars, problem, gridGeometry);
95 if (priVarsSwitchedInLastIteration_)
97 for (
const auto& element : elements(gridGeometry.gridView()))
100 priVarSwitch_->updateSwitchedVolVars(problem, element, gridGeometry, vars, uCurrentIter);
103 priVarSwitch_->updateSwitchedFluxVarsCache(problem, element, gridGeometry, vars, uCurrentIter);
112 {
return priVarsSwitchedInLastIteration_; }
116 std::unique_ptr<PrimaryVariableSwitch> priVarSwitch_;
118 bool priVarsSwitchedInLastIteration_ =
false;
125template <
class Variables>
131 template<
class SolutionVector>
134 template<
class SolutionVector>
135 void invoke(SolutionVector&, Variables&) {}
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
constexpr bool hasPriVarsSwitch
Helper boolean to check if the given variables involve primary variable switching.
Definition: primaryvariableswitchadapter.hh:51
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
typename GetPVSwitch< Variables >::type PrimaryVariableSwitch
Definition: primaryvariableswitchadapter.hh:42
Dune::Std::detected_or< int, DetectPVSwitch, Variables > GetPVSwitch
Definition: primaryvariableswitchadapter.hh:39
typename Variables::VolumeVariables::PrimaryVariableSwitch DetectPVSwitch
helper aliases to extract a primary variable switch from the VolumeVariables (if defined,...
Definition: primaryvariableswitchadapter.hh:36
An adapter for the Newton to manage models with primary variable switch.
Definition: primaryvariableswitchadapter.hh:59
void invoke(SolutionVector &uCurrentIter, Variables &vars)
Switch primary variables if necessary.
Definition: primaryvariableswitchadapter.hh:86
PrimaryVariableSwitchAdapter(const std::string ¶mGroup="")
Definition: primaryvariableswitchadapter.hh:63
void initialize(SolutionVector &sol, Variables &vars)
Initialize the privar switch.
Definition: primaryvariableswitchadapter.hh:73
bool switched() const
Whether the primary variables have been switched in the last call to invoke.
Definition: primaryvariableswitchadapter.hh:111
void initialize(SolutionVector &, Variables &)
Definition: primaryvariableswitchadapter.hh:132
void invoke(SolutionVector &, Variables &)
Definition: primaryvariableswitchadapter.hh:135
bool switched() const
Definition: primaryvariableswitchadapter.hh:137
PrimaryVariableSwitchAdapter(const std::string ¶mGroup="")
Definition: primaryvariableswitchadapter.hh:129