Alsvinn  0.5.3
The fast FVM simulator with UQ support
BuckleyLeverett.hpp
Go to the documentation of this file.
1 /* Copyright (c) 2018 ETH Zurich, Kjetil Olsen Lye
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 #pragma once
17 #include "alsfvm/types.hpp"
18 #include <cmath>
24 
26 #include "alsfvm/volume/Volume.hpp"
28 #define USE_LOG_ENTROPY 1
29 namespace alsfvm {
30 namespace equation {
31 namespace buckleyleverett {
32 
34 public:
35 
37  // empty
38  }
39 
45 
49  static std::string getName() {
50  return "buckleyleverett";
51  }
52 
56  static const std::vector<std::string> conservedVariables;
57 
61  static const std::vector<std::string> primitiveVariables;
62 
66  static const std::vector<std::string> extraVariables;
67 
71  static const size_t numberOfConservedVariables = 1;
72 
78  static const constexpr real entropyLowerBound = 0;
79 
85  static const constexpr real entropyUpperBound = 2;
86 
88  return 1;
89  }
90 
95 
100 
101 
106  size_t index) const {
107  return makeAllVariables(views.u.at(index));
108  }
109 
110  template<class T, class S>
111  __device__ __host__ static ConservedVariables fetchConservedVariables(
112  buckleyleverett::Views<T, S>& views, size_t index) {
113  return ConservedVariables(views.u.at(index));
114  }
115 
117  size_t index) const {
118  return ExtraVariables();
119  }
120 
124  __device__ __host__ static void setViewAt(Views& output, size_t index,
125  const ConservedVariables& input) {
126  output.u.at(index) = input.u;
127  }
128 
132  __device__ __host__ void setExtraViewAt(ViewsExtra& output, size_t index,
133  const ExtraVariables& input) const {
134  // empty
135  }
136 
142  __device__ __host__ static void addToViewAt(Views& output, size_t index,
143  const ConservedVariables& input) {
144  output.u.at(index) += input.u;
145  }
146 
158 
159  template<size_t direction>
160  __device__ __host__ void computePointFlux(const AllVariables& u,
161  ConservedVariables& F) const {
162  static_assert(direction < 3, "We only support up to three dimensions");
163  double u2 = u.u * u.u;
164  F = u2 / (u2 + (1 - u.u) * (1 - u.u));
165  }
166 
167 
168 
172  __device__ __host__ ExtraVariables computeExtra(const ConservedVariables& u)
173  const {
174  return ExtraVariables();
175  }
176 
181  __device__ __host__ ExtraVariables computeExtra(const PrimitiveVariables&
182  primitiveVariables) const {
183  return ExtraVariables();
184  }
185 
195  const PrimitiveVariables& primitiveVariables) const {
196  return ConservedVariables(primitiveVariables.u);
197  }
198 
203  template<int direction>
204  __device__ __host__ real computeWaveSpeed(const ConservedVariables& u,
205  const ExtraVariables& v) const {
206  static_assert(direction >= 0, "Direction can not be negative");
207  static_assert(direction < 3, "We only support dimension up to and inclusive 3");
208 
209  return fabs(2 * u.u * (u.u * u.u + (1 - u.u) * (1 - u.u)) - u.u * u.u *
210  (2 * u.u - 2 * (1 - u.u)))
211  / ((u.u * u.u + (1 - u.u) * (1 - u.u)) * (u.u * u.u + (1 - u.u) * (1 - u.u)));
212  }
213 
223  __device__ __host__ bool obeysConstraints(const ConservedVariables& u,
224  const ExtraVariables& v) const {
225 
226  return u.u < INFINITY && (u.u == u.u);
227  }
228 
229  __device__ __host__ AllVariables makeAllVariables(real u) const {
230 
231  return AllVariables(u);
232  }
233 
234  __device__ __host__ real getWeight(const ConstViews& in, size_t index) const {
235  return in.u.at(index);
236  }
237 
239  const ConservedVariables& conserved) const {
240  return PrimitiveVariables(conserved.u);
241  }
242 
251  conserved) const {
252 #if USE_LOG_ENTROPY
253  return (1 / (entropyUpperBound - conserved.u)) - 1 / (conserved.u -
255 #else
256  return conserved.u;
257 #endif
258 
259  }
260 
268  conserved) const {
269 #if USE_LOG_ENTROPY
270  return computeEntropyVariables(conserved) * 0.5 * conserved.u * conserved.u -
271  (-2 * conserved.u
272  - entropyUpperBound * log(entropyUpperBound - conserved.u) - entropyLowerBound *
273  log(conserved.u - entropyLowerBound));
274 #else
275  return 1.0 / 6.0 * (conserved.u * conserved.u * conserved.u);
276 #endif
277 
278  }
279 
280  template<int direction>
282  const ConservedVariables& conserved) const {
283 
284 #if USE_LOG_ENTROPY
285  return rvec1(2.0 * conserved.u / (conserved.u * (conserved.u - 2)));
286 #else
287  return rvec1(conserved.u);
288 #endif
289  }
290 
291  template<int direction>
293  conserved) const {
294 
295  matrix1 matrixWithEigenVectors;
296  matrixWithEigenVectors(0, 0) = 1;
297  return matrixWithEigenVectors;
298  }
299 
300  template<int direction>
301  __device__ __host__ rvec1 computeEigenValues(const ConservedVariables& u)
302  const {
303  return (2 * u.u * (u.u * u.u + (1 - u.u) * (1 - u.u)) - u.u * u.u *
304  (2 * u.u - 2 * (1 - u.u)))
305  / ((u.u * u.u + (1 - u.u) * (1 - u.u)) * (u.u * u.u + (1 - u.u) * (1 - u.u)));
306  }
307 
308 };
309 } // namespace alsfvm
310 } // namespace equation
311 } // namespace buckleyleverett
__device__ __host__ ExtraVariables computeExtra(const PrimitiveVariables &primitiveVariables) const
computes the extra variables from the primitive ones
Definition: BuckleyLeverett.hpp:181
__device__ __host__ real computeWaveSpeed(const ConservedVariables &u, const ExtraVariables &v) const
Definition: BuckleyLeverett.hpp:204
static std::string getName()
Definition: BuckleyLeverett.hpp:49
__device__ __host__ rvec1 computeEntropyVariables(const ConservedVariables &conserved) const
Definition: BuckleyLeverett.hpp:250
__device__ __host__ real getWeight(const ConstViews &in, size_t index) const
Definition: BuckleyLeverett.hpp:234
__device__ __host__ AllVariables makeAllVariables(real u) const
Definition: BuckleyLeverett.hpp:229
__device__ __host__ rvec1 computeEigenValues(const ConservedVariables &u) const
Definition: BuckleyLeverett.hpp:301
simulator::SimulatorParameters & parameters
Definition: CellComputerFactory.cpp:60
__device__ __host__ AllVariables fetchAllVariables(ConstViews &views, size_t index) const
Definition: BuckleyLeverett.hpp:105
static const size_t numberOfConservedVariables
Definition: BuckleyLeverett.hpp:71
__device__ static __host__ void addToViewAt(Views &output, size_t index, const ConservedVariables &input)
Definition: BuckleyLeverett.hpp:142
static const std::vector< std::string > extraVariables
Definition: BuckleyLeverett.hpp:66
Definition: BuckleyLeverett.hpp:33
static const std::vector< std::string > primitiveVariables
Definition: BuckleyLeverett.hpp:61
#define __host__
Definition: types.hpp:46
Definition: ConservedVariables.hpp:26
equation::buckleyleverett::ViewsExtra< volume::Volume, memory::View< real > > ViewsExtra
Definition: BuckleyLeverett.hpp:97
BuckleyLeverett(const EquationParameters &parameters)
Definition: BuckleyLeverett.hpp:36
__device__ __host__ void computePointFlux(const AllVariables &u, ConservedVariables &F) const
Definition: BuckleyLeverett.hpp:160
__device__ __host__ rvec1 computeEntropyVariablesMultipliedByEigenVectorMatrix(const ConservedVariables &conserved) const
Definition: BuckleyLeverett.hpp:281
__device__ __host__ bool obeysConstraints(const ConservedVariables &u, const ExtraVariables &v) const
Definition: BuckleyLeverett.hpp:223
double real
Definition: types.hpp:65
__device__ __host__ rvec1 computeEntropyPotential(const ConservedVariables &conserved) const
Definition: BuckleyLeverett.hpp:267
__device__ __host__ PrimitiveVariables computePrimitiveVariables(const ConservedVariables &conserved) const
Definition: BuckleyLeverett.hpp:238
Definition: ExtraVariables.hpp:22
EquationParameters Parameters
Definition: BuckleyLeverett.hpp:40
real u
Definition: ConservedVariables.hpp:54
Definition: mat.hpp:23
__device__ __host__ void setExtraViewAt(ViewsExtra &output, size_t index, const ExtraVariables &input) const
Definition: BuckleyLeverett.hpp:132
buckleyleverett::ConservedVariables ConservedVariables
Definition: BuckleyLeverett.hpp:41
Definition: EquationParameters.hpp:21
equation::buckleyleverett::Views< volume::Volume, memory::View< real > > Views
Definition: BuckleyLeverett.hpp:92
buckleyleverett::AllVariables AllVariables
Definition: BuckleyLeverett.hpp:44
equation::buckleyleverett::ViewsExtra< const volume::Volume, const memory::View< const real > > ConstViewsExtra
Definition: BuckleyLeverett.hpp:99
Definition: vec1.hpp:24
__device__ __host__ ExtraVariables fetchExtraVariables(ConstViewsExtra &views, size_t index) const
Definition: BuckleyLeverett.hpp:116
#define static_assert(x, y)
Definition: types.hpp:52
real u
Definition: PrimitiveVariables.hpp:34
__device__ static __host__ void setViewAt(Views &output, size_t index, const ConservedVariables &input)
Definition: BuckleyLeverett.hpp:124
static const constexpr real entropyLowerBound
Definition: BuckleyLeverett.hpp:78
__device__ static __host__ size_t getNumberOfConservedVariables()
Definition: BuckleyLeverett.hpp:87
buckleyleverett::PrimitiveVariables PrimitiveVariables
Definition: BuckleyLeverett.hpp:43
#define __device__
Definition: types.hpp:45
ViewType u
Definition: Views.hpp:55
Various utility functions to implement the tecno flux.
Definition: types.hpp:30
__device__ __host__ matrix1 computeEigenVectorMatrix(const ConservedVariables &conserved) const
Definition: BuckleyLeverett.hpp:292
buckleyleverett::ExtraVariables ExtraVariables
Definition: BuckleyLeverett.hpp:42
__device__ __host__ ConservedVariables computeConserved(const PrimitiveVariables &primitiveVariables) const
computes the conserved variables from the primitive ones
Definition: BuckleyLeverett.hpp:194
vec1< real > rvec1
Definition: types.hpp:70
Definition: PrimitiveVariables.hpp:23
static const constexpr real entropyUpperBound
Definition: BuckleyLeverett.hpp:85
__device__ static __host__ ConservedVariables fetchConservedVariables(buckleyleverett::Views< T, S > &views, size_t index)
Definition: BuckleyLeverett.hpp:111
equation::buckleyleverett::Views< const volume::Volume, const memory::View< const real > > ConstViews
Definition: BuckleyLeverett.hpp:94
__device__ __host__ ExtraVariables computeExtra(const ConservedVariables &u) const
Definition: BuckleyLeverett.hpp:172
static const std::vector< std::string > conservedVariables
Definition: BuckleyLeverett.hpp:56