opm-simulators
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 #include <opm/common/utility/gpuDecorators.hpp>
33 
34 #include <opm/material/common/MathToolbox.hpp>
35 #include <opm/material/common/Valgrind.hpp>
36 
39 
40 #include <stdexcept>
41 #include <type_traits>
42 
43 namespace Opm {
44 
50 template <class TypeTag, template<class, int> class VectorType = Dune::FieldVector>
52  : public VectorType<GetPropType<TypeTag, Properties::Scalar>,
53  getPropValue<TypeTag, Properties::NumEq>()>
54 {
57 
58  enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
59 
60  using Toolbox = MathToolbox<Evaluation>;
61  using ParentType = VectorType<Scalar, numEq>;
62 
63 public:
64  OPM_HOST_DEVICE FvBasePrimaryVariables()
65  : ParentType()
66  { Valgrind::SetUndefined(*this); }
67 
73  template <class OtherTypeTag, template<class, int> class OtherVectorType>
74  explicit OPM_HOST_DEVICE FvBasePrimaryVariables(
76  : ParentType()
77  {
78  static_assert(getPropValue<TypeTag, Properties::NumEq>() ==
79  getPropValue<OtherTypeTag, Properties::NumEq>(),
80  "Incompatible number of equations in primary variables copy "
81  "constructor");
82  for (unsigned i = 0; i < this->size(); ++i) {
83  (*this)[i] = other[i];
84  }
85  }
86 
90  FvBasePrimaryVariables(const FvBasePrimaryVariables& value) = default;
91 
96 
97  using ParentType::operator=;
98 
99  OPM_HOST_DEVICE static void init()
100  {
101  // Nothing required by default.
102  }
103 
104  static void registerParameters()
105  {
106  // No parameters to register by default.
107  }
108 
116  OPM_HOST_DEVICE Evaluation makeEvaluation(unsigned varIdx, unsigned timeIdx,
117  LinearizationType linearizationType = LinearizationType()) const
118  {
119  if constexpr (std::is_same_v<Evaluation, Scalar>) {
120  return (*this)[varIdx]; // finite differences
121  }
122  else {
123  // automatic differentiation
124  if (timeIdx == linearizationType.time) {
125  return Toolbox::createVariable((*this)[varIdx], varIdx);
126  }
127  else {
128  return Toolbox::createConstant((*this)[varIdx]);
129  }
130  }
131  }
132 
143  template <class FluidState>
144  OPM_HOST_DEVICE void assignNaive(const FluidState&)
145  {
146  throw std::runtime_error("The PrimaryVariables class does not define "
147  "an assignNaive() method");
148  }
149 
153  OPM_HOST_DEVICE void checkDefined() const
154  {
155  Valgrind::CheckDefined(*static_cast<const ParentType*>(this));
156  }
157 };
158 
159 } // namespace Opm
160 
161 namespace Dune {
162 
165  template<class TypeTag, bool>
167 
170  template<class TypeTag>
171  struct FieldTraitsImpl<TypeTag, true>
172  : public FieldTraits<FieldVector<Opm::GetPropType<TypeTag, Opm::Properties::Scalar>,
173  Opm::getPropValue<TypeTag, Opm::Properties::NumEq>()>>
174  {
175  };
176 
179  template<class T>
180  struct FieldTraitsImpl<T, false>
181  : public FieldTraits<T>
182  {
183  };
184 
186  template<class TypeTag, template <class> class EwomsPrimaryVariable>
187  struct FieldTraits<EwomsPrimaryVariable<TypeTag>>
188  : public FieldTraitsImpl<TypeTag,
189  std::is_base_of_v<Opm::FvBasePrimaryVariables<TypeTag>,
190  EwomsPrimaryVariable<TypeTag>>>
191  {
192  };
193 
194 } // namespace Dune
195 
196 #endif
OPM_HOST_DEVICE FvBasePrimaryVariables(const FvBasePrimaryVariables< OtherTypeTag, OtherVectorType > &other)
Copy constructor from another primary variables object.
Definition: fvbaseprimaryvariables.hh:74
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:161
FvBasePrimaryVariables & operator=(const FvBasePrimaryVariables &value)=default
Assignment from another primary variables object.
OPM_HOST_DEVICE void checkDefined() const
Instruct valgrind to check the definedness of all attributes of this class.
Definition: fvbaseprimaryvariables.hh:153
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
static OPM_HOST_DEVICE void init()
< Import base class assignment operators.
Definition: fvbaseprimaryvariables.hh:99
OPM_HOST_DEVICE void assignNaive(const FluidState &)
Assign the primary variables "somehow" from a fluid state.
Definition: fvbaseprimaryvariables.hh:144
Declare the properties used by the infrastructure code of the finite volume discretizations.
Represents the primary variables used by the a model.
Definition: fvbaseprimaryvariables.hh:51
Definition: linearizationtype.hh:33
The common code for the linearizers of non-linear systems of equations.
OPM_HOST_DEVICE Evaluation makeEvaluation(unsigned varIdx, unsigned timeIdx, LinearizationType linearizationType=LinearizationType()) const
Return a primary variable intensive evaluation.
Definition: fvbaseprimaryvariables.hh:116
Compatibility traits class for DenseVector and DenseMatrix.
Definition: fvbaseprimaryvariables.hh:166