fvbaseconstraints.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  Copyright (C) 2010-2013 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
26 #ifndef EWOMS_FV_BASE_CONSTRAINTS_HH
27 #define EWOMS_FV_BASE_CONSTRAINTS_HH
28 
30 #include <opm/material/common/Valgrind.hpp>
31 
32 namespace Ewoms {
33 namespace Properties {
34 NEW_PROP_TAG(PrimaryVariables);
35 NEW_PROP_TAG(Scalar);
36 NEW_PROP_TAG(NumEq);
37 }
38 
44 template <class TypeTag>
45 class FvBaseConstraints : public GET_PROP_TYPE(TypeTag, PrimaryVariables)
46 {
47  typedef typename GET_PROP_TYPE(TypeTag, PrimaryVariables) ParentType;
48  typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
49 
50  enum { numEq = GET_PROP_VALUE(TypeTag, NumEq) };
51 
52 public:
54  { reset(); }
55 
57 
60  using ParentType::operator=;
62 
69  void reset()
70  {
71  for (int i=0; i < numEq; ++i) {
72  constraintInfo_[i].isConstraint = 0;
73 
74  eq2pvIdx_[i] = i;
75  pv2eqIdx_[i] = i;
76  }
77  }
78 
83  bool isConstraint() const
84  {
85  for (int eqIdx = 0; eqIdx < numEq; ++eqIdx)
86  if (constraintInfo_[eqIdx].isConstraint)
87  return true;
88  return false;
89  }
90 
97  bool isConstraint(int eqIdx) const
98  { return constraintInfo_[eqIdx].isConstraint; }
99 
106  {
107  for (int eqIdx = 0; eqIdx < numEq; ++ eqIdx) {
108  constraintInfo_[eqIdx].isConstraint = 1;
109 
110  eq2pvIdx_[eqIdx] = eqIdx;
111  pv2eqIdx_[eqIdx] = eqIdx;
112  }
113  //Valgrind::SetDefined(constraintInfo_[eqIdx]);
114  }
115 
124  void setConstraint(int eqIdx, int pvIdx, Scalar value)
125  {
126  setConstraint(eqIdx, pvIdx);
127  ParentType::operator[](pvIdx) = value;
128 
129  //Valgrind::SetDefined(constraintInfo_);
130  }
131 
139  void setConstraint(int eqIdx, int pvIdx)
140  {
141  constraintInfo_[eqIdx].isConstraint = 1;
142 
143  // update the equation <-> primary variable mapping
144  eq2pvIdx_[eqIdx] = pvIdx;
145  pv2eqIdx_[pvIdx] = eqIdx;
146 
147  //Valgrind::SetDefined(constraintInfo_[eqIdx]);
148  }
149 
157  unsigned pvToEqIndex(unsigned pvIdx) const
158  { return pv2eqIdx_[pvIdx]; }
159 
167  unsigned eqToPvIndex(unsigned eqIdx) const
168  { return eq2pvIdx_[eqIdx]; }
169 
170 private:
171  // this is a bitfield structure!
172  struct __attribute__((__packed__)) {
173  unsigned char isConstraint : 1;
174  } constraintInfo_[numEq];
175 
176  unsigned char eq2pvIdx_[numEq];
177  unsigned char pv2eqIdx_[numEq];
178 };
179 
180 } // namespace Ewoms
181 
182 #endif
bool isConstraint(int eqIdx) const
Returns true if constraints for given equation have been specified.
Definition: fvbaseconstraints.hh:97
bool isConstraint() const
Returns true if constraints for any equation have been specified.
Definition: fvbaseconstraints.hh:83
void setConstraint(int eqIdx, int pvIdx, Scalar value)
Set a constraint for single equation.
Definition: fvbaseconstraints.hh:124
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:468
#define GET_PROP_TYPE(TypeTag, PropTagName)
Access the type attribute of a property for a type tag.
Definition: propertysystem.hh:485
FvBaseConstraints()
Definition: fvbaseconstraints.hh:53
NEW_PROP_TAG(Grid)
The type of the DUNE grid.
unsigned pvToEqIndex(unsigned pvIdx) const
Returns the index of the equation which should be used to constrain the pvIdx's primary variable...
Definition: fvbaseconstraints.hh:157
unsigned eqToPvIndex(unsigned eqIdx) const
Returns the index of the primary variable for which a given equation should be used as a constraint...
Definition: fvbaseconstraints.hh:167
Definition: baseauxiliarymodule.hh:35
void setAllConstraint()
Set all to be constraint.
Definition: fvbaseconstraints.hh:105
void setConstraint(int eqIdx, int pvIdx)
Set a constraint for single equation.
Definition: fvbaseconstraints.hh:139
void reset()
Reset the constraints types.
Definition: fvbaseconstraints.hh:69
Provides the magic behind the eWoms property system.
Class to specify constraints for a finite volume spatial discretization.
Definition: fvbaseconstraints.hh:45