Commit e9cde7e4 authored by Kilian Weishaupt's avatar Kilian Weishaupt Committed by Timo Koch
Browse files

[porousmediumflow] Use adapted NewtonSolver

* export PrivarSwitch in VolVars
* do not set PriVarSwitch property in model.hh anymore
parent 335433aa
......@@ -76,7 +76,6 @@
#include "localresidual.hh"
#include "indices.hh"
#include "volumevariables.hh"
#include "primaryvariableswitch.hh"
namespace Dumux {
......@@ -191,10 +190,6 @@ public:
using type = TwoPOneCVolumeVariables<Traits>;
};
//! The primary variable switch for the 2p1cni model.
template<class TypeTag>
struct PrimaryVariableSwitch<TypeTag, TTag::TwoPOneCNI> { using type = TwoPOneCPrimaryVariableSwitch; };
//! The primary variables vector for the 2p1cni model.
template<class TypeTag>
struct PrimaryVariables<TypeTag, TTag::TwoPOneCNI>
......
......@@ -34,6 +34,8 @@
#include <dumux/porousmediumflow/2p/formulation.hh>
#include <dumux/material/solidstates/updatesolidvolumefractions.hh>
#include "primaryvariableswitch.hh"
namespace Dumux {
/*!
......@@ -91,6 +93,8 @@ public:
using SolidState = typename Traits::SolidState;
//! export type of solid system
using SolidSystem = typename Traits::SolidSystem;
//! export the primary variable switch
using PrimaryVariableSwitch = TwoPOneCPrimaryVariableSwitch;
//! return the two-phase formulation used here
static constexpr TwoPFormulation priVarFormulation() { return formulation; }
......
......@@ -34,6 +34,7 @@
#include <dumux/porousmediumflow/nonisothermal/volumevariables.hh>
#include <dumux/porousmediumflow/2p/formulation.hh>
#include <dumux/material/solidstates/updatesolidvolumefractions.hh>
#include <dumux/porousmediumflow/2pnc/primaryvariableswitch.hh>
namespace Dumux {
......@@ -93,6 +94,8 @@ public:
using SolidState = typename Traits::SolidState;
//! export type of solid system
using SolidSystem = typename Traits::SolidSystem;
//! export the primary variable switch
using PrimaryVariableSwitch = TwoPNCPrimaryVariableSwitch;
//! return whether moles or masses are balanced
static constexpr bool useMoles() { return ModelTraits::useMoles(); }
......
......@@ -102,7 +102,6 @@
#include <dumux/porousmediumflow/2p/formulation.hh>
#include "volumevariables.hh"
#include "primaryvariableswitch.hh"
#include "iofields.hh"
#include "indices.hh"
......@@ -182,9 +181,6 @@ public:
using type = SwitchablePrimaryVariables<PrimaryVariablesVector, int>;
};
template<class TypeTag>
struct PrimaryVariableSwitch<TypeTag, TTag::TwoPNC> { using type = TwoPNCPrimaryVariableSwitch<TypeTag>; }; //!< The primary variable switch for the 2pnc model
//! Set the volume variables property
template<class TypeTag>
struct VolumeVariables<TypeTag, TTag::TwoPNC>
......
......@@ -35,11 +35,10 @@ namespace Dumux {
* \ingroup TwoPNCModel
* \brief The primary variable switch controlling the phase presence state variable
*/
template<class TypeTag>
class TwoPNCPrimaryVariableSwitch
: public PrimaryVariableSwitch<TwoPNCPrimaryVariableSwitch<TypeTag>>
: public PrimaryVariableSwitch<TwoPNCPrimaryVariableSwitch>
{
using ParentType = PrimaryVariableSwitch<TwoPNCPrimaryVariableSwitch<TypeTag>>;
using ParentType = PrimaryVariableSwitch<TwoPNCPrimaryVariableSwitch>;
friend ParentType;
public:
using ParentType::ParentType;
......
......@@ -41,6 +41,8 @@
#include <dumux/porousmediumflow/2p/formulation.hh>
#include "primaryvariableswitch.hh"
namespace Dumux {
/*!
......@@ -98,6 +100,8 @@ public:
using SolidState = typename Traits::SolidState;
//! export type of solid system
using SolidSystem = typename Traits::SolidSystem;
//! export the primary variable switch
using PrimaryVariableSwitch = TwoPNCPrimaryVariableSwitch;
//! return whether moles or masses are balanced
static constexpr bool useMoles() { return Traits::ModelTraits::useMoles(); }
......
......@@ -96,7 +96,6 @@
#include "indices.hh"
#include "volumevariables.hh"
#include "iofields.hh"
#include "primaryvariableswitch.hh"
#include "localresidual.hh"
namespace Dumux {
......@@ -198,10 +197,6 @@ struct FluidState<TypeTag, TTag::ThreePThreeC>{
template<class TypeTag>
struct LocalResidual<TypeTag, TTag::ThreePThreeC> { using type = ThreePThreeCLocalResidual<TypeTag>; };
//! The primary variable switch for the 3p3c model
template<class TypeTag>
struct PrimaryVariableSwitch<TypeTag, TTag::ThreePThreeC> { using type = ThreePThreeCPrimaryVariableSwitch; };
//! The primary variables vector for the 3p3c model
template<class TypeTag>
struct PrimaryVariables<TypeTag, TTag::ThreePThreeC>
......
......@@ -33,6 +33,8 @@
#include <dumux/porousmediumflow/nonisothermal/volumevariables.hh>
#include <dumux/material/solidstates/updatesolidvolumefractions.hh>
#include "primaryvariableswitch.hh"
namespace Dumux {
/*!
......@@ -93,6 +95,8 @@ public:
using SolidState = typename Traits::SolidState;
//! export type of solid system
using SolidSystem = typename Traits::SolidSystem;
//! export the primary variable switch
using PrimaryVariableSwitch = ThreePThreeCPrimaryVariableSwitch;
/*!
* \brief Update all quantities for a given control volume
......
......@@ -88,7 +88,6 @@
#include "model.hh"
#include "volumevariables.hh"
#include "localresidual.hh"
#include "primaryvariableswitch.hh"
#include "iofields.hh"
namespace Dumux {
......@@ -181,10 +180,6 @@ struct LocalResidual<TypeTag, TTag::ThreePWaterOilNI> { using type = ThreePWater
template<class TypeTag>
struct ReplaceCompEqIdx<TypeTag, TTag::ThreePWaterOilNI> { static constexpr int value = GetPropType<TypeTag, Properties::ModelTraits>::numComponents(); };
//! The primary variable switch for the 3p3c model
template<class TypeTag>
struct PrimaryVariableSwitch<TypeTag, TTag::ThreePWaterOilNI> { using type = ThreePWaterOilPrimaryVariableSwitch<TypeTag>; };
//! The primary variables vector for the 3p3c model
template<class TypeTag>
struct PrimaryVariables<TypeTag, TTag::ThreePWaterOilNI>
......
......@@ -39,6 +39,8 @@
#include <dumux/common/valgrind.hh>
#include <dumux/common/exceptions.hh>
#include "primaryvariableswitch.hh"
namespace Dumux {
/*!
......@@ -55,7 +57,6 @@ class ThreePWaterOilVolumeVariables
using EnergyVolVars = EnergyVolumeVariables<Traits, ThreePWaterOilVolumeVariables<Traits> >;
using Scalar = typename Traits::PrimaryVariables::value_type;
using ModelTraits = typename Traits::ModelTraits;
using Indices = typename ModelTraits::Indices;
using FS = typename Traits::FluidSystem;
static constexpr int numFluidComps = ParentType::numComponents();
......@@ -69,19 +70,19 @@ class ThreePWaterOilVolumeVariables
gPhaseIdx = FS::gPhaseIdx,
nPhaseIdx = FS::nPhaseIdx,
switch1Idx = Indices::switch1Idx,
switch2Idx = Indices::switch2Idx,
pressureIdx = Indices::pressureIdx
switch1Idx = ModelTraits::Indices::switch1Idx,
switch2Idx = ModelTraits::Indices::switch2Idx,
pressureIdx = ModelTraits::Indices::pressureIdx
};
// present phases
enum {
threePhases = Indices::threePhases,
wPhaseOnly = Indices::wPhaseOnly,
gnPhaseOnly = Indices::gnPhaseOnly,
wnPhaseOnly = Indices::wnPhaseOnly,
gPhaseOnly = Indices::gPhaseOnly,
wgPhaseOnly = Indices::wgPhaseOnly
threePhases = ModelTraits::Indices::threePhases,
wPhaseOnly = ModelTraits::Indices::wPhaseOnly,
gnPhaseOnly = ModelTraits::Indices::gnPhaseOnly,
wnPhaseOnly = ModelTraits::Indices::wnPhaseOnly,
gPhaseOnly = ModelTraits::Indices::gPhaseOnly,
wgPhaseOnly = ModelTraits::Indices::wgPhaseOnly
};
public:
......@@ -89,10 +90,17 @@ public:
using FluidState = typename Traits::FluidState;
//! The type of the fluid system
using FluidSystem = typename Traits::FluidSystem;
//! export the indices
using Indices = typename ModelTraits::Indices;
//! export type of solid state
using SolidState = typename Traits::SolidState;
//! export type of solid system
using SolidSystem = typename Traits::SolidSystem;
//! export the primary variable switch
using PrimaryVariableSwitch = ThreePWaterOilPrimaryVariableSwitch;
//! state if only the gas phase is allowed to disappear
static constexpr bool onlyGasPhaseCanDisappear()
{ return Traits::ModelTraits::onlyGasPhaseCanDisappear(); }
/*!
* \copydoc ImplicitVolumeVariables::update
......@@ -107,13 +115,11 @@ public:
const auto& priVars = elemSol[scv.localDofIndex()];
const auto phasePresence = priVars.state();
bool onlyGasPhaseCanDisappear = Traits::ModelTraits::onlyGasPhaseCanDisappear();
// capillary pressure parameters
using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
if(!onlyGasPhaseCanDisappear)
if(!onlyGasPhaseCanDisappear())
{
/* first the saturations */
if (phasePresence == threePhases)
......
......@@ -26,7 +26,6 @@
#include <dumux/common/properties.hh>
#include <dumux/porousmediumflow/2p2c/model.hh>
#include "primaryvariableswitch.hh"
#include "volumevariables.hh"
/*!
......@@ -80,12 +79,6 @@ struct TwoPTwoCCO2 { using InheritsFrom = std::tuple<TwoPTwoC>; };
struct TwoPTwoCCO2NI { using InheritsFrom = std::tuple<TwoPTwoCNI>; };
} // end namespace TTag
//! the CO2 privarswitch and VolumeVariables properties
template<class TypeTag>
struct PrimaryVariableSwitch<TypeTag, TTag::TwoPTwoCCO2> { using type = TwoPTwoCCO2PrimaryVariableSwitch; };
template<class TypeTag>
struct PrimaryVariableSwitch<TypeTag, TTag::TwoPTwoCCO2NI> { using type = TwoPTwoCCO2PrimaryVariableSwitch; };
//! the co2 volume variables use the same traits as the 2p2c model
template<class TypeTag>
struct VolumeVariables<TypeTag, TTag::TwoPTwoCCO2>
......
......@@ -34,6 +34,8 @@
#include <dumux/porousmediumflow/nonisothermal/volumevariables.hh>
#include <dumux/material/solidstates/updatesolidvolumefractions.hh>
#include "primaryvariableswitch.hh"
namespace Dumux {
/*!
......@@ -91,6 +93,8 @@ public:
using SolidState = typename Traits::SolidState;
//! export type of solid system
using SolidSystem = typename Traits::SolidSystem;
//! export the type of the primary variable switch
using PrimaryVariableSwitch = TwoPTwoCCO2PrimaryVariableSwitch;
//! return whether moles or masses are balanced
......
......@@ -43,12 +43,11 @@ public:
template<typename... Args>
NoPrimaryVariableSwitch(Args&&...) {}
template<typename... Args> void init(Args&&...) {}
template<typename... Args> void reset(Args&&...) {}
template<typename... Args> bool wasSwitched(Args&&...) const { return false; }
template<typename... Args> bool update(Args&&...) { return false; }
template<typename... Args> void updateSwitchedVolVars(Args&&...) {}
template<typename... Args> void updateSwitchedFluxVarsCache(Args&&...) {}
template<typename... Args> bool update_(Args&&...) {return false; }
};
/*!
......@@ -59,11 +58,9 @@ template<class Implementation>
class PrimaryVariableSwitch
{
public:
PrimaryVariableSwitch(const std::size_t& numDofs, int verbosity = 1)
PrimaryVariableSwitch(int verbosity = 1)
: verbosity_(verbosity)
{
wasSwitched_.resize(numDofs, false);
}
{}
//! If the primary variables were recently switched
bool wasSwitched(std::size_t dofIdxGlobal) const
......@@ -71,6 +68,12 @@ public:
return wasSwitched_[dofIdxGlobal];
}
//! Reset all flags
void reset(const std::size_t numDofs)
{
wasSwitched_.resize(numDofs, false);
}
/*!
* \brief Update the variable switch / phase presence
*
......
......@@ -5,6 +5,5 @@ localresidual.hh
model.hh
newtonsolver.hh
primaryvariableswitch.hh
privarswitchnewtonsolver.hh
volumevariables.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux/porousmediumflow/richards)
......@@ -113,7 +113,6 @@
#include "volumevariables.hh"
#include "iofields.hh"
#include "localresidual.hh"
#include "primaryvariableswitch.hh"
namespace Dumux {
......@@ -239,10 +238,6 @@ public:
using type = SwitchablePrimaryVariables<PrimaryVariablesVector, int>;
};
//! The primary variable switch for the richards model
template<class TypeTag>
struct PrimaryVariableSwitch<TypeTag, TTag::Richards> { using type = ExtendedRichardsPrimaryVariableSwitch; };
/*!
*\brief The fluid system used by the model.
*
......
......@@ -25,7 +25,7 @@
#define DUMUX_RICHARDS_NEWTON_SOLVER_HH
#include <dumux/common/properties.hh>
#include <dumux/porousmediumflow/richards/privarswitchnewtonsolver.hh>
#include <dumux/nonlinear/newtonsolver.hh>
#include <dumux/discretization/elementsolution.hh>
namespace Dumux {
......@@ -39,15 +39,15 @@ namespace Dumux {
* \todo make this typetag independent by extracting anything model specific from assembler
* or from possible ModelTraits.
*/
template <class TypeTag, class Assembler, class LinearSolver>
class RichardsNewtonSolver : public RichardsPrivarSwitchNewtonSolver<TypeTag, Assembler, LinearSolver>
template <class Assembler, class LinearSolver>
class RichardsNewtonSolver : public NewtonSolver<Assembler, LinearSolver>
{
using Scalar = typename Assembler::Scalar;
using ParentType = RichardsPrivarSwitchNewtonSolver<TypeTag, Assembler, LinearSolver>;
using ParentType = NewtonSolver<Assembler, LinearSolver>;
using SolutionVector = typename Assembler::ResidualType;
using MaterialLaw = typename Assembler::Problem::SpatialParams::MaterialLaw;
using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
using Indices = typename Assembler::GridVariables::VolumeVariables::Indices;
enum { pressureIdx = Indices::pressureIdx };
public:
......
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
* See the file COPYING for full copying permissions. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
/*!
* \file
* \ingroup RichardsModel
* \brief A Richards model newton solver.
*/
#ifndef DUMUX_RICHARDS_PRIVAR_SWITCH_NEWTON_SOLVER_HH
#define DUMUX_RICHARDS_PRIVAR_SWITCH_NEWTON_SOLVER_HH
#include <dumux/common/properties.hh>
#include <dumux/nonlinear/newtonsolver.hh>
#include <dumux/nonlinear/privarswitchnewtonsolver.hh>
#include <dumux/discretization/elementsolution.hh>
namespace Dumux {
template <class TypeTag, class Assembler, class LinearSolver, bool enableWaterDiffusionInAir>
class RichardsPrivarSwitchNewtonSolverImplementation;
/*!
* \ingroup RichardsModel
* \brief A base for the richards newton solver which derives from the right base newton solver.
*/
template <class TypeTag, class Assembler, class LinearSolver>
using RichardsPrivarSwitchNewtonSolver = RichardsPrivarSwitchNewtonSolverImplementation <TypeTag, Assembler, LinearSolver, getPropValue<TypeTag, Properties::EnableWaterDiffusionInAir>()>;
/*!
* \ingroup RichardsModel
* \brief the case without a primary variables switch
*/
template <class TypeTag, class Assembler, class LinearSolver>
class RichardsPrivarSwitchNewtonSolverImplementation<TypeTag, Assembler, LinearSolver, false> : public NewtonSolver<Assembler, LinearSolver>
{
using ParentType = NewtonSolver<Assembler, LinearSolver>;
public:
using ParentType::ParentType;
};
/*!
* \ingroup RichardsModel
* \brief the case with switchable primary variables
*/
template <class TypeTag, class Assembler, class LinearSolver>
class RichardsPrivarSwitchNewtonSolverImplementation<TypeTag, Assembler, LinearSolver, true> : public PriVarSwitchNewtonSolver<Assembler, LinearSolver, GetPropType<TypeTag, Properties::PrimaryVariableSwitch>>
{
using PrimaryVariableSwitch = GetPropType<TypeTag, Properties::PrimaryVariableSwitch>;
using ParentType = PriVarSwitchNewtonSolver<Assembler, LinearSolver, PrimaryVariableSwitch>;
public:
using ParentType::ParentType;
};
} // end namespace Dumux
#endif
......@@ -34,8 +34,21 @@
#include <dumux/material/constants.hh>
#include <dumux/material/solidstates/updatesolidvolumefractions.hh>
#include "primaryvariableswitch.hh"
namespace Dumux {
namespace Detail {
//! helper structs to conditionally use a primary variable switch or not
struct VolVarsWithPVSwitch
{
using PrimaryVariableSwitch = ExtendedRichardsPrimaryVariableSwitch;
};
struct VolVarsWithOutPVSwitch
{};
}
/*!
* \ingroup RichardsModel
* \brief Volume averaged quantities required by the Richards model.
......@@ -47,6 +60,8 @@ template <class Traits>
class RichardsVolumeVariables
: public PorousMediumFlowVolumeVariables<Traits>
, public EnergyVolumeVariables<Traits, RichardsVolumeVariables<Traits> >
, public std::conditional_t<Traits::ModelTraits::enableMolecularDiffusion(),
Detail::VolVarsWithPVSwitch, Detail::VolVarsWithOutPVSwitch>
{
using ParentType = PorousMediumFlowVolumeVariables<Traits>;
using EnergyVolVars = EnergyVolumeVariables<Traits, RichardsVolumeVariables<Traits> >;
......
......@@ -42,7 +42,7 @@
#include <dumux/common/defaultusagemessage.hh>
#include <dumux/linear/seqsolverbackend.hh>
#include <dumux/nonlinear/privarswitchnewtonsolver.hh>
#include <dumux/nonlinear/newtonsolver.hh>
#include <dumux/assembly/fvassembler.hh>
......@@ -128,8 +128,7 @@ int main(int argc, char** argv) try
auto linearSolver = std::make_shared<LinearSolver>();
// the non-linear solver
using PrimaryVariableSwitch = GetPropType<TypeTag, Properties::PrimaryVariableSwitch>;
using NewtonSolver = Dumux::PriVarSwitchNewtonSolver<Assembler, LinearSolver, PrimaryVariableSwitch>;
using NewtonSolver = NewtonSolver<Assembler, LinearSolver>;
NewtonSolver nonLinearSolver(assembler, linearSolver);
// time loop
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment