ComputeFromReferencePhase.hpp
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) 2011-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 */
25 #ifndef OPM_COMPUTE_FROM_REFERENCE_PHASE_HPP
26 #define OPM_COMPUTE_FROM_REFERENCE_PHASE_HPP
27 
29 
30 #include <opm/common/Exceptions.hpp>
31 #include <opm/common/ErrorMacros.hpp>
33 
34 #include <dune/common/fvector.hh>
35 
36 namespace Opm {
37 
63 template <class Scalar, class FluidSystem, class Evaluation = Scalar>
65 {
66  enum { numPhases = FluidSystem::numPhases };
67  enum { numComponents = FluidSystem::numComponents };
69  typedef Dune::FieldVector<Evaluation, numComponents> ComponentVector;
70 
71 public:
106  template <class FluidState, class ParameterCache>
107  static void solve(FluidState &fluidState,
108  ParameterCache &paramCache,
109  unsigned refPhaseIdx,
110  bool setViscosity,
111  bool setEnthalpy)
112  {
114 
115  // compute the density and enthalpy of the
116  // reference phase
117  paramCache.updatePhase(fluidState, refPhaseIdx);
118  fluidState.setDensity(refPhaseIdx,
119  FluidSystem::density(fluidState,
120  paramCache,
121  refPhaseIdx));
122 
123  if (setEnthalpy)
124  fluidState.setEnthalpy(refPhaseIdx,
125  FluidSystem::enthalpy(fluidState,
126  paramCache,
127  refPhaseIdx));
128 
129  if (setViscosity)
130  fluidState.setViscosity(refPhaseIdx,
131  FluidSystem::viscosity(fluidState,
132  paramCache,
133  refPhaseIdx));
134 
135  // compute the fugacities of all components in the reference phase
136  for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
137  fluidState.setFugacityCoefficient(refPhaseIdx,
138  compIdx,
139  FluidSystem::fugacityCoefficient(fluidState,
140  paramCache,
141  refPhaseIdx,
142  compIdx));
143  }
144 
145  // compute all quantities for the non-reference phases
146  for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
147  if (phaseIdx == refPhaseIdx)
148  continue; // reference phase is already calculated
149 
150  ComponentVector fugVec;
151  for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
152  const auto& fug = fluidState.fugacity(refPhaseIdx, compIdx);
153  fugVec[compIdx] = FsToolbox::template toLhs<Evaluation>(fug);
154  }
155 
156  CompositionFromFugacities::solve(fluidState, paramCache, phaseIdx, fugVec);
157 
158  if (setViscosity)
159  fluidState.setViscosity(phaseIdx,
160  FluidSystem::viscosity(fluidState,
161  paramCache,
162  phaseIdx));
163 
164  if (setEnthalpy)
165  fluidState.setEnthalpy(phaseIdx,
166  FluidSystem::enthalpy(fluidState,
167  paramCache,
168  phaseIdx));
169  }
170  }
171 };
172 
173 } // namespace Opm
174 
175 #endif
Calculates the chemical equilibrium from the component fugacities in a phase.
Definition: CompositionFromFugacities.hpp:47
Definition: MathToolbox.hpp:39
Definition: Air_Mesitylene.hpp:31
Some templates to wrap the valgrind client request macros.
static void solve(FluidState &fluidState, ParameterCache &paramCache, unsigned phaseIdx, const ComponentVector &targetFug)
Calculates the chemical equilibrium from the component fugacities in a phase.
Definition: CompositionFromFugacities.hpp:84
Calculates the chemical equilibrium from the component fugacities in a phase.
Computes all quantities of a generic fluid state if a reference phase has been specified.
Definition: ComputeFromReferencePhase.hpp:64
static void solve(FluidState &fluidState, ParameterCache &paramCache, unsigned refPhaseIdx, bool setViscosity, bool setEnthalpy)
Computes all quantities of a generic fluid state if a reference phase has been specified.
Definition: ComputeFromReferencePhase.hpp:107