2021-11-05 09:21:35 -05:00
|
|
|
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
// vi: set et ts=4 sw=4 sts=4:
|
|
|
|
/*
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Consult the COPYING file in the top-level source directory of this
|
|
|
|
module for the precise wording of the license and the list of
|
|
|
|
copyright holders.
|
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
* \file
|
|
|
|
*
|
2021-11-10 04:17:23 -06:00
|
|
|
* \brief This is test for the ChiFlash flash solver.
|
2021-11-05 09:21:35 -05:00
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <opm/material/constraintsolvers/ChiFlash.hpp>
|
2021-11-09 07:39:45 -06:00
|
|
|
#include <opm/material/fluidsystems/chifluid/twophasefluidsystem.hh>
|
2021-11-05 09:21:35 -05:00
|
|
|
|
|
|
|
#include <opm/material/densead/Evaluation.hpp>
|
|
|
|
#include <opm/material/constraintsolvers/ComputeFromReferencePhase.hpp>
|
2021-11-10 04:17:23 -06:00
|
|
|
// #include <opm/material/constraintsolvers/NcpFlash.hpp>
|
2021-11-05 09:21:35 -05:00
|
|
|
#include <opm/material/fluidstates/CompositionalFluidState.hpp>
|
2021-11-10 04:17:23 -06:00
|
|
|
// #include <opm/material/fluidsystems/Spe5FluidSystem.hpp>
|
2021-11-05 09:21:35 -05:00
|
|
|
#include <opm/material/fluidmatrixinteractions/LinearMaterial.hpp>
|
2021-11-10 04:17:23 -06:00
|
|
|
// #include <opm/material/fluidmatrixinteractions/MaterialTraits.hpp>
|
2021-11-05 09:21:35 -05:00
|
|
|
|
|
|
|
#include <dune/common/parallel/mpihelper.hh>
|
|
|
|
|
|
|
|
void testChiFlash()
|
|
|
|
{
|
|
|
|
using Scalar = double;
|
2021-11-09 07:39:45 -06:00
|
|
|
using FluidSystem = Opm::TwoPhaseThreeComponentFluidSystem<Scalar>;
|
2021-11-05 09:21:35 -05:00
|
|
|
|
2021-11-09 07:39:45 -06:00
|
|
|
constexpr auto numComponents = FluidSystem::numComponents;
|
2021-11-05 09:21:35 -05:00
|
|
|
typedef Dune::FieldVector<Scalar, numComponents> ComponentVector;
|
|
|
|
typedef Opm::CompositionalFluidState<Scalar, FluidSystem> FluidState;
|
|
|
|
|
2021-11-10 04:17:23 -06:00
|
|
|
// From co2-compositional branch, it uses
|
|
|
|
// typename FluidSystem::template ParameterCache<Evaluation> paramCache;
|
2021-11-05 09:21:35 -05:00
|
|
|
typedef typename FluidSystem::template ParameterCache<Scalar> ParameterCache;
|
2021-11-10 04:17:23 -06:00
|
|
|
using ComponentVector = Dune::FieldVector<Scalar, numComponents>;
|
|
|
|
using Evaluation = Opm::DenseAd::Evaluation<double, numComponents>;
|
2021-11-05 09:21:35 -05:00
|
|
|
|
|
|
|
|
2021-11-10 04:17:23 -06:00
|
|
|
FluidState fs;
|
|
|
|
// TODO: no capillary pressure for now
|
|
|
|
const Scalar p_init = 100.*1.e5; // 100 bar
|
|
|
|
fs.setPressure(FluidSystem::oilPhaseIdx, p_init);
|
|
|
|
fs.setPressure(FluidSystem::gasPhaseIdx, p_init);
|
2021-11-05 09:21:35 -05:00
|
|
|
|
2021-11-10 04:17:23 -06:00
|
|
|
fs.setMoleFraction(FluidSystem::oilPhaseIdx, FluidSystem::Comp0Idx, MFCOMP0);
|
|
|
|
fs.setMoleFraction(FluidSystem::oilPhaseIdx, FluidSystem::Comp1Idx, MFCOMP1);
|
|
|
|
|
|
|
|
fs.setMoleFraction(FluidSystem::gasPhaseIdx, FluidSystem::Comp0Idx, MFCOMP0);
|
|
|
|
fs.setMoleFraction(FluidSystem::gasPhaseIdx, FluidSystem::Comp1Idx, MFCOMP1);
|
|
|
|
|
|
|
|
fs.setSaturation(FluidSystem::oilPhaseIdx, 1.0);
|
|
|
|
fs.setSaturation(FluidSystem::gasPhaseIdx, 0.0);
|
2021-11-05 09:21:35 -05:00
|
|
|
|
2021-11-10 04:17:23 -06:00
|
|
|
fs.setTemperature(303);
|
|
|
|
|
|
|
|
ParameterCache paramCache;
|
|
|
|
paramCache.updatePhase(fs, FluidSystem::oilPhaseIdx);
|
|
|
|
paramCache.updatePhase(fs, FluidSystem::gasPhaseIdx);
|
|
|
|
fs.setDensity(FluidSystem::oilPhaseIdx, FluidSystem::density(fs, paramCache, FluidSystem::oilPhaseIdx));
|
|
|
|
fs.setDensity(FluidSystem::gasPhaseIdx, FluidSystem::density(fs, paramCache, FluidSystem::gasPhaseIdx));
|
|
|
|
|
|
|
|
ComponentVector zInit(0.); // TODO; zInit needs to be normalized.
|
|
|
|
const double flash_tolerance = 1.e-8;
|
|
|
|
const int flash_verbosity = 1;
|
|
|
|
const std::string flash_twophase_method = "ssi";
|
|
|
|
|
|
|
|
// Set initial K and L
|
|
|
|
for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
|
|
|
|
const Scalar Ktmp = fs.wilsonK_(compIdx);
|
|
|
|
fs.setKvalue(compIdx, Ktmp);
|
2021-11-05 09:21:35 -05:00
|
|
|
}
|
2021-11-10 04:17:23 -06:00
|
|
|
const Scalar Ltmp = -1.0;
|
|
|
|
fs.setLvalue(Ltmp);
|
2021-11-05 09:21:35 -05:00
|
|
|
|
2021-11-10 04:17:23 -06:00
|
|
|
const int spatialIdx = 0;
|
|
|
|
using Flash = Opm::ChiFlash<double, Evaluation, FluidSystem>;
|
|
|
|
Flash::solve(fs, zInit, spatialIdx, flash_verbosity, flash_twophase_method, flash_tolerance);
|
2021-11-05 09:21:35 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
Dune::MPIHelper::instance(argc, argv);
|
|
|
|
|
|
|
|
testChiFlash();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|