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  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 */
27 #ifndef OPM_COMPUTE_FROM_REFERENCE_PHASE_HPP
28 #define OPM_COMPUTE_FROM_REFERENCE_PHASE_HPP
29 
31 
32 #include <opm/common/Exceptions.hpp>
33 #include <opm/common/ErrorMacros.hpp>
34 #include <opm/common/Valgrind.hpp>
35 
36 #include <dune/common/fvector.hh>
37 
38 namespace Opm {
39 
65 template <class Scalar, class FluidSystem, class Evaluation = Scalar>
67 {
68  enum { numPhases = FluidSystem::numPhases };
69  enum { numComponents = FluidSystem::numComponents };
71  typedef Dune::FieldVector<Evaluation, numComponents> ComponentVector;
72 
73 public:
108  template <class FluidState>
109  static void solve(FluidState& fluidState,
110  typename FluidSystem::template ParameterCache<typename FluidState::Scalar>& paramCache,
111  unsigned refPhaseIdx,
112  bool setViscosity,
113  bool setEnthalpy)
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] = Opm::decay<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
static void solve(FluidState &fluidState, typename FluidSystem::template ParameterCache< typename FluidState::Scalar > &paramCache, unsigned phaseIdx, const ComponentVector &targetFug)
Calculates the chemical equilibrium from the component fugacities in a phase.
Definition: CompositionFromFugacities.hpp:88
Computes all quantities of a generic fluid state if a reference phase has been specified.
Definition: ComputeFromReferencePhase.hpp:66
Definition: Air_Mesitylene.hpp:33
static void solve(FluidState &fluidState, typename FluidSystem::template ParameterCache< typename FluidState::Scalar > &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:109
Calculates the chemical equilibrium from the component fugacities in a phase.
Calculates the chemical equilibrium from the component fugacities in a phase.
Definition: CompositionFromFugacities.hpp:54