fvbaseprimaryvariables.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
28#ifndef EWOMS_FV_BASE_PRIMARY_VARIABLES_HH
29#define EWOMS_FV_BASE_PRIMARY_VARIABLES_HH
30
31#include <dune/common/fvector.hh>
32
33#include <opm/material/common/MathToolbox.hpp>
34#include <opm/material/common/Valgrind.hpp>
35
38
39#include <stdexcept>
40#include <type_traits>
41
42namespace Opm {
43
49template <class TypeTag>
51 : public Dune::FieldVector<GetPropType<TypeTag, Properties::Scalar>,
52 getPropValue<TypeTag, Properties::NumEq>()>
53{
56
57 enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
58
59 using Toolbox = MathToolbox<Evaluation>;
60 using ParentType = Dune::FieldVector<Scalar, numEq>;
61
62public:
64 : ParentType()
65 { Valgrind::SetUndefined(*this); }
66
71
76
77 using ParentType::operator=;
78
79 static void init()
80 {
81 // Nothing required by default.
82 }
83
84 static void registerParameters()
85 {
86 // No parameters to register by default.
87 }
88
96 Evaluation makeEvaluation(unsigned varIdx, unsigned timeIdx,
97 LinearizationType linearizationType = LinearizationType()) const
98 {
99 if constexpr (std::is_same_v<Evaluation, Scalar>) {
100 return (*this)[varIdx]; // finite differences
101 }
102 else {
103 // automatic differentiation
104 if (timeIdx == linearizationType.time) {
105 return Toolbox::createVariable((*this)[varIdx], varIdx);
106 }
107 else {
108 return Toolbox::createConstant((*this)[varIdx]);
109 }
110 }
111 }
112
123 template <class FluidState>
124 void assignNaive(const FluidState&)
125 {
126 throw std::runtime_error("The PrimaryVariables class does not define "
127 "an assignNaive() method");
128 }
129
133 void checkDefined() const
134 {
135 Valgrind::CheckDefined(*static_cast<const ParentType*>(this));
136 }
137};
138
139} // namespace Opm
140
141namespace Dune {
142
145 template<class TypeTag, bool>
147
150 template<class TypeTag>
151 struct FieldTraitsImpl<TypeTag, true>
152 : public FieldTraits<FieldVector<Opm::GetPropType<TypeTag, Opm::Properties::Scalar>,
153 Opm::getPropValue<TypeTag, Opm::Properties::NumEq>()>>
154 {
155 };
156
159 template<class T>
160 struct FieldTraitsImpl<T, false>
161 : public FieldTraits<T>
162 {
163 };
164
166 template<class TypeTag, template <class> class EwomsPrimaryVariable>
167 struct FieldTraits<EwomsPrimaryVariable<TypeTag>>
168 : public FieldTraitsImpl<TypeTag,
169 std::is_base_of_v<Opm::FvBasePrimaryVariables<TypeTag>,
170 EwomsPrimaryVariable<TypeTag>>>
171 {
172 };
173
174} // namespace Dune
175
176#endif
Represents the primary variables used by the a model.
Definition: fvbaseprimaryvariables.hh:53
FvBasePrimaryVariables()
Definition: fvbaseprimaryvariables.hh:63
static void registerParameters()
Definition: fvbaseprimaryvariables.hh:84
static void init()
< Import base class assignment operators.
Definition: fvbaseprimaryvariables.hh:79
FvBasePrimaryVariables(const FvBasePrimaryVariables &value)=default
Assignment from another primary variables object.
FvBasePrimaryVariables & operator=(const FvBasePrimaryVariables &value)=default
Assignment from another primary variables object.
void checkDefined() const
Instruct valgrind to check the definedness of all attributes of this class.
Definition: fvbaseprimaryvariables.hh:133
void assignNaive(const FluidState &)
Assign the primary variables "somehow" from a fluid state.
Definition: fvbaseprimaryvariables.hh:124
Evaluation makeEvaluation(unsigned varIdx, unsigned timeIdx, LinearizationType linearizationType=LinearizationType()) const
Return a primary variable intensive evaluation.
Definition: fvbaseprimaryvariables.hh:96
Declare the properties used by the infrastructure code of the finite volume discretizations.
Definition: fvbaseprimaryvariables.hh:141
Definition: blackoilboundaryratevector.hh:39
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233
Definition: fvbaseprimaryvariables.hh:146
Definition: linearizationtype.hh:34