2016-06-06 08:40:06 -05:00
|
|
|
/*
|
|
|
|
Copyright 2013, 2015 SINTEF ICT, Applied Mathematics.
|
|
|
|
Copyright 2014, 2015 Dr. Blatt - HPC-Simulation-Software & Services
|
|
|
|
Copyright 2014, 2015 Statoil ASA.
|
|
|
|
Copyright 2015 NTNU
|
2017-11-22 07:39:42 -06:00
|
|
|
Copyright 2015, 2016, 2017 IRIS AS
|
2016-06-06 08:40:06 -05:00
|
|
|
|
|
|
|
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 3 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OPM_BLACKOILMODELEBOS_HEADER_INCLUDED
|
|
|
|
#define OPM_BLACKOILMODELEBOS_HEADER_INCLUDED
|
|
|
|
|
2023-05-03 06:17:20 -05:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2016-11-11 08:05:13 -06:00
|
|
|
#include <ebos/eclproblem.hh>
|
2016-06-06 08:40:06 -05:00
|
|
|
|
|
|
|
#include <opm/common/ErrorMacros.hpp>
|
|
|
|
#include <opm/common/Exceptions.hpp>
|
|
|
|
#include <opm/common/OpmLog/OpmLog.hpp>
|
2022-12-13 05:54:27 -06:00
|
|
|
|
|
|
|
#include <opm/core/props/phaseUsageFromDeck.hpp>
|
|
|
|
|
|
|
|
#include <opm/grid/UnstructuredGrid.h>
|
2023-06-26 10:37:13 -05:00
|
|
|
#include <opm/grid/common/SubGridPart.hpp>
|
2022-12-13 05:54:27 -06:00
|
|
|
|
2021-12-14 01:30:15 -06:00
|
|
|
#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
|
|
|
|
#include <opm/input/eclipse/EclipseState/Tables/TableManager.hpp>
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2023-07-04 06:33:23 -05:00
|
|
|
#include <opm/simulators/aquifers/AquiferGridUtils.hpp>
|
2022-12-13 05:54:27 -06:00
|
|
|
#include <opm/simulators/aquifers/BlackoilAquiferModel.hpp>
|
|
|
|
#include <opm/simulators/flow/countGlobalCells.hpp>
|
2023-06-26 10:37:13 -05:00
|
|
|
#include <opm/simulators/flow/partitionCells.hpp>
|
2022-12-13 05:54:27 -06:00
|
|
|
#include <opm/simulators/flow/NonlinearSolverEbos.hpp>
|
|
|
|
#include <opm/simulators/flow/BlackoilModelParametersEbos.hpp>
|
2023-06-26 10:37:13 -05:00
|
|
|
#include <opm/simulators/flow/SubDomain.hpp>
|
|
|
|
#include <opm/simulators/linalg/extractMatrix.hpp>
|
2019-05-07 06:06:02 -05:00
|
|
|
#include <opm/simulators/linalg/ISTLSolverEbos.hpp>
|
2022-12-13 05:54:27 -06:00
|
|
|
#include <opm/simulators/timestepping/AdaptiveTimeSteppingEbos.hpp>
|
2023-03-01 06:40:54 -06:00
|
|
|
#include <opm/simulators/timestepping/ConvergenceReport.hpp>
|
2022-12-13 05:54:27 -06:00
|
|
|
#include <opm/simulators/timestepping/SimulatorReport.hpp>
|
|
|
|
#include <opm/simulators/timestepping/SimulatorTimer.hpp>
|
2023-06-30 04:18:27 -05:00
|
|
|
#include <opm/simulators/utils/ComponentName.hpp>
|
2022-12-13 05:54:27 -06:00
|
|
|
#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
|
2023-03-03 06:21:36 -06:00
|
|
|
#include <opm/simulators/utils/ParallelCommunication.hpp>
|
2022-12-13 05:54:27 -06:00
|
|
|
#include <opm/simulators/wells/BlackoilWellModel.hpp>
|
|
|
|
#include <opm/simulators/wells/WellConnectionAuxiliaryModule.hpp>
|
2016-11-11 07:25:19 -06:00
|
|
|
|
2016-11-23 14:44:33 -06:00
|
|
|
#include <dune/common/timer.hh>
|
2016-11-11 07:25:19 -06:00
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2022-12-08 07:09:09 -06:00
|
|
|
#include <algorithm>
|
2016-06-06 08:40:06 -05:00
|
|
|
#include <cassert>
|
|
|
|
#include <cmath>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <limits>
|
2023-06-14 02:18:53 -05:00
|
|
|
#include <type_traits>
|
2023-03-03 06:49:51 -06:00
|
|
|
#include <tuple>
|
2022-12-08 07:09:09 -06:00
|
|
|
#include <utility>
|
2016-06-06 08:40:06 -05:00
|
|
|
#include <vector>
|
|
|
|
|
2020-08-21 06:42:08 -05:00
|
|
|
namespace Opm::Properties {
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2020-08-27 03:30:29 -05:00
|
|
|
namespace TTag {
|
|
|
|
struct EclFlowProblem {
|
|
|
|
using InheritsFrom = std::tuple<FlowTimeSteppingParameters, FlowModelParameters,
|
|
|
|
FlowNonLinearSolver, EclBaseProblem, BlackOilModel>;
|
|
|
|
};
|
|
|
|
}
|
2020-08-27 04:38:38 -05:00
|
|
|
template<class TypeTag>
|
|
|
|
struct OutputDir<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
static constexpr auto value = "";
|
|
|
|
};
|
2020-08-27 04:38:38 -05:00
|
|
|
template<class TypeTag>
|
|
|
|
struct EnableDebuggingChecks<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
static constexpr bool value = false;
|
|
|
|
};
|
2017-06-29 02:59:48 -05:00
|
|
|
// default in flow is to formulate the equations in surface volumes
|
2020-08-27 04:38:38 -05:00
|
|
|
template<class TypeTag>
|
|
|
|
struct BlackoilConserveSurfaceVolume<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
static constexpr bool value = true;
|
|
|
|
};
|
|
|
|
template<class TypeTag>
|
|
|
|
struct UseVolumetricResidual<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
static constexpr bool value = false;
|
|
|
|
};
|
2018-01-30 04:53:30 -06:00
|
|
|
|
2020-08-27 04:38:38 -05:00
|
|
|
template<class TypeTag>
|
|
|
|
struct EclAquiferModel<TypeTag, TTag::EclFlowProblem> {
|
2021-05-05 04:22:44 -05:00
|
|
|
using type = BlackoilAquiferModel<TypeTag>;
|
2020-08-27 04:38:38 -05:00
|
|
|
};
|
2018-10-25 09:47:00 -05:00
|
|
|
|
2018-01-30 04:53:30 -06:00
|
|
|
// disable all extensions supported by black oil model. this should not really be
|
|
|
|
// necessary but it makes things a bit more explicit
|
2020-08-27 04:38:38 -05:00
|
|
|
template<class TypeTag>
|
|
|
|
struct EnablePolymer<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
static constexpr bool value = false;
|
|
|
|
};
|
|
|
|
template<class TypeTag>
|
|
|
|
struct EnableSolvent<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
static constexpr bool value = false;
|
|
|
|
};
|
|
|
|
template<class TypeTag>
|
|
|
|
struct EnableTemperature<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
static constexpr bool value = true;
|
|
|
|
};
|
|
|
|
template<class TypeTag>
|
|
|
|
struct EnableEnergy<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
static constexpr bool value = false;
|
|
|
|
};
|
|
|
|
template<class TypeTag>
|
|
|
|
struct EnableFoam<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
static constexpr bool value = false;
|
|
|
|
};
|
|
|
|
template<class TypeTag>
|
|
|
|
struct EnableBrine<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
static constexpr bool value = false;
|
|
|
|
};
|
2021-10-06 12:32:35 -05:00
|
|
|
template<class TypeTag>
|
2022-01-06 05:50:52 -06:00
|
|
|
struct EnableSaltPrecipitation<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
static constexpr bool value = false;
|
|
|
|
};
|
|
|
|
template<class TypeTag>
|
2021-10-06 12:32:35 -05:00
|
|
|
struct EnableMICP<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
static constexpr bool value = false;
|
|
|
|
};
|
2018-06-21 05:14:17 -05:00
|
|
|
|
2020-08-27 04:38:38 -05:00
|
|
|
template<class TypeTag>
|
|
|
|
struct EclWellModel<TypeTag, TTag::EclFlowProblem> {
|
2021-05-05 04:22:44 -05:00
|
|
|
using type = BlackoilWellModel<TypeTag>;
|
2020-08-27 04:38:38 -05:00
|
|
|
};
|
2020-08-27 04:38:38 -05:00
|
|
|
template<class TypeTag>
|
|
|
|
struct LinearSolverSplice<TypeTag, TTag::EclFlowProblem> {
|
|
|
|
using type = TTag::FlowIstlSolver;
|
|
|
|
};
|
2018-11-12 04:03:54 -06:00
|
|
|
|
2020-08-21 06:42:08 -05:00
|
|
|
} // namespace Opm::Properties
|
2016-06-06 08:40:06 -05:00
|
|
|
|
|
|
|
namespace Opm {
|
|
|
|
/// A model implementation for three-phase black oil.
|
|
|
|
///
|
|
|
|
/// The simulator is capable of handling three-phase problems
|
|
|
|
/// where gas can be dissolved in oil and vice versa. It
|
|
|
|
/// uses an industry-standard TPFA discretization with per-phase
|
|
|
|
/// upwind weighting of mobilities.
|
2017-06-07 02:29:31 -05:00
|
|
|
template <class TypeTag>
|
2016-06-06 08:40:06 -05:00
|
|
|
class BlackoilModelEbos
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// --------- Types and enums ---------
|
2023-03-03 06:25:46 -06:00
|
|
|
using ModelParameters = BlackoilModelParametersEbos<TypeTag>;
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2020-08-26 03:49:52 -05:00
|
|
|
using Simulator = GetPropType<TypeTag, Properties::Simulator>;
|
|
|
|
using Grid = GetPropType<TypeTag, Properties::Grid>;
|
|
|
|
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
|
2023-07-03 03:11:45 -05:00
|
|
|
using IntensiveQuantities = GetPropType<TypeTag, Properties::IntensiveQuantities>;
|
2020-08-26 03:49:52 -05:00
|
|
|
using SparseMatrixAdapter = GetPropType<TypeTag, Properties::SparseMatrixAdapter>;
|
|
|
|
using SolutionVector = GetPropType<TypeTag, Properties::SolutionVector>;
|
|
|
|
using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
|
|
|
|
using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
|
|
|
|
using Indices = GetPropType<TypeTag, Properties::Indices>;
|
|
|
|
using MaterialLaw = GetPropType<TypeTag, Properties::MaterialLaw>;
|
|
|
|
using MaterialLawParams = GetPropType<TypeTag, Properties::MaterialLawParams>;
|
2023-03-03 06:25:46 -06:00
|
|
|
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
|
2016-08-25 08:25:01 -05:00
|
|
|
|
2023-03-03 06:28:55 -06:00
|
|
|
static constexpr int numEq = Indices::numEq;
|
|
|
|
static constexpr int contiSolventEqIdx = Indices::contiSolventEqIdx;
|
|
|
|
static constexpr int contiZfracEqIdx = Indices::contiZfracEqIdx;
|
|
|
|
static constexpr int contiPolymerEqIdx = Indices::contiPolymerEqIdx;
|
|
|
|
static constexpr int contiEnergyEqIdx = Indices::contiEnergyEqIdx;
|
|
|
|
static constexpr int contiPolymerMWEqIdx = Indices::contiPolymerMWEqIdx;
|
|
|
|
static constexpr int contiFoamEqIdx = Indices::contiFoamEqIdx;
|
|
|
|
static constexpr int contiBrineEqIdx = Indices::contiBrineEqIdx;
|
|
|
|
static constexpr int contiMicrobialEqIdx = Indices::contiMicrobialEqIdx;
|
|
|
|
static constexpr int contiOxygenEqIdx = Indices::contiOxygenEqIdx;
|
|
|
|
static constexpr int contiUreaEqIdx = Indices::contiUreaEqIdx;
|
|
|
|
static constexpr int contiBiofilmEqIdx = Indices::contiBiofilmEqIdx;
|
|
|
|
static constexpr int contiCalciteEqIdx = Indices::contiCalciteEqIdx;
|
|
|
|
static constexpr int solventSaturationIdx = Indices::solventSaturationIdx;
|
|
|
|
static constexpr int zFractionIdx = Indices::zFractionIdx;
|
|
|
|
static constexpr int polymerConcentrationIdx = Indices::polymerConcentrationIdx;
|
|
|
|
static constexpr int polymerMoleWeightIdx = Indices::polymerMoleWeightIdx;
|
|
|
|
static constexpr int temperatureIdx = Indices::temperatureIdx;
|
|
|
|
static constexpr int foamConcentrationIdx = Indices::foamConcentrationIdx;
|
|
|
|
static constexpr int saltConcentrationIdx = Indices::saltConcentrationIdx;
|
|
|
|
static constexpr int microbialConcentrationIdx = Indices::microbialConcentrationIdx;
|
|
|
|
static constexpr int oxygenConcentrationIdx = Indices::oxygenConcentrationIdx;
|
|
|
|
static constexpr int ureaConcentrationIdx = Indices::ureaConcentrationIdx;
|
|
|
|
static constexpr int biofilmConcentrationIdx = Indices::biofilmConcentrationIdx;
|
|
|
|
static constexpr int calciteConcentrationIdx = Indices::calciteConcentrationIdx;
|
2017-06-07 02:29:31 -05:00
|
|
|
|
2023-03-03 06:25:46 -06:00
|
|
|
using VectorBlockType = Dune::FieldVector<Scalar, numEq>;
|
|
|
|
using MatrixBlockType = typename SparseMatrixAdapter::MatrixBlock;
|
|
|
|
using Mat = typename SparseMatrixAdapter::IstlMatrix;
|
|
|
|
using BVector = Dune::BlockVector<VectorBlockType>;
|
2016-11-02 07:10:44 -05:00
|
|
|
|
2023-06-30 04:18:27 -05:00
|
|
|
using ComponentName = ::Opm::ComponentName<FluidSystem,Indices>;
|
2023-06-14 02:18:53 -05:00
|
|
|
using Domain = SubDomain<Grid>;
|
|
|
|
|
2023-03-03 06:25:46 -06:00
|
|
|
using ISTLSolverType = ISTLSolverEbos<TypeTag>;
|
2022-12-08 07:09:09 -06:00
|
|
|
|
2016-06-06 08:40:06 -05:00
|
|
|
// --------- Public methods ---------
|
|
|
|
|
|
|
|
/// Construct the model. It will retain references to the
|
|
|
|
/// arguments of this functions, and they are expected to
|
|
|
|
/// remain in scope for the lifetime of the solver.
|
|
|
|
/// \param[in] param parameters
|
|
|
|
/// \param[in] grid grid data structure
|
|
|
|
/// \param[in] wells well structure
|
|
|
|
/// \param[in] vfp_properties Vertical flow performance tables
|
|
|
|
/// \param[in] linsolver linear solver
|
|
|
|
/// \param[in] eclState eclipse state
|
|
|
|
/// \param[in] terminal_output request output to cout/cerr
|
2016-08-08 07:31:32 -05:00
|
|
|
BlackoilModelEbos(Simulator& ebosSimulator,
|
2017-04-05 08:48:23 -05:00
|
|
|
const ModelParameters& param,
|
2017-09-26 03:52:05 -05:00
|
|
|
BlackoilWellModel<TypeTag>& well_model,
|
2018-06-06 03:59:41 -05:00
|
|
|
const bool terminal_output)
|
2016-08-08 07:31:32 -05:00
|
|
|
: ebosSimulator_(ebosSimulator)
|
2018-02-01 09:27:42 -06:00
|
|
|
, grid_(ebosSimulator_.vanguard().grid())
|
2017-06-16 06:52:51 -05:00
|
|
|
, phaseUsage_(phaseUsageFromDeck(eclState()))
|
2016-06-06 08:40:06 -05:00
|
|
|
, param_( param )
|
2017-08-09 05:32:45 -05:00
|
|
|
, well_model_ (well_model)
|
2016-06-06 08:40:06 -05:00
|
|
|
, terminal_output_ (terminal_output)
|
|
|
|
, current_relaxation_(1.0)
|
2021-12-01 07:00:21 -06:00
|
|
|
, dx_old_(ebosSimulator_.model().numGridDof())
|
2016-06-06 08:40:06 -05:00
|
|
|
{
|
2016-11-02 10:59:08 -05:00
|
|
|
// compute global sum of number of cells
|
2017-03-17 04:26:00 -05:00
|
|
|
global_nc_ = detail::countGlobalCells(grid_);
|
2018-11-15 14:21:25 -06:00
|
|
|
convergence_reports_.reserve(300); // Often insufficient, but avoids frequent moves.
|
2023-06-14 02:18:53 -05:00
|
|
|
// TODO: remember to fix!
|
|
|
|
if (param_.nonlinear_solver_ == "nldd") {
|
|
|
|
if (terminal_output) {
|
|
|
|
OpmLog::info("Using Non-Linear Domain Decomposition solver (nldd).");
|
|
|
|
}
|
|
|
|
setupSubDomains();
|
|
|
|
} else if (param_.nonlinear_solver_ == "newton") {
|
|
|
|
if (terminal_output) {
|
|
|
|
OpmLog::info("Using Newton nonlinear solver.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
OPM_THROW(std::runtime_error, "Unknown nonlinear solver option: " + param_.nonlinear_solver_);
|
|
|
|
}
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
|
2017-01-11 11:57:47 -06:00
|
|
|
bool isParallel() const
|
|
|
|
{ return grid_.comm().size() > 1; }
|
2016-11-08 01:46:42 -06:00
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
|
2016-08-08 08:26:09 -05:00
|
|
|
const EclipseState& eclState() const
|
2018-02-01 09:27:42 -06:00
|
|
|
{ return ebosSimulator_.vanguard().eclState(); }
|
2016-08-08 08:26:09 -05:00
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
|
|
|
|
|
|
|
|
void setupSubDomains()
|
|
|
|
{
|
|
|
|
// Create partitions.
|
|
|
|
const auto& [partition_vector, num_domains] =
|
2023-06-29 05:40:57 -05:00
|
|
|
partitionCells(this->grid_,
|
|
|
|
this->ebosSimulator_.vanguard().schedule().getWellsatEnd(),
|
|
|
|
this->param_.local_domain_partition_method_,
|
|
|
|
this->param_.num_local_domains_,
|
|
|
|
this->param_.local_domain_partition_imbalance_);
|
2023-06-14 02:18:53 -05:00
|
|
|
|
|
|
|
// Scan through partitioning to get correct size for each.
|
|
|
|
std::vector<int> sizes(num_domains, 0);
|
|
|
|
for (const auto& p : partition_vector) {
|
|
|
|
++sizes[p];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up correctly sized vectors of entity seeds and of indices for each partition.
|
|
|
|
using EntitySeed = typename Grid::template Codim<0>::EntitySeed;
|
|
|
|
std::vector<std::vector<EntitySeed>> seeds(num_domains);
|
|
|
|
std::vector<std::vector<int>> partitions(num_domains);
|
|
|
|
for (int domain = 0; domain < num_domains; ++domain) {
|
|
|
|
seeds[domain].resize(sizes[domain]);
|
|
|
|
partitions[domain].resize(sizes[domain]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate through grid once, setting the seeds of all partitions.
|
|
|
|
std::vector<int> count(num_domains, 0);
|
|
|
|
const auto beg = grid_.template leafbegin<0>();
|
|
|
|
const auto end = grid_.template leafend<0>();
|
|
|
|
int cell = 0;
|
|
|
|
for (auto it = beg; it != end; ++it, ++cell) {
|
|
|
|
const int p = partition_vector[cell];
|
|
|
|
seeds[p][count[p]] = it->seed();
|
|
|
|
partitions[p][count[p]] = cell;
|
|
|
|
++count[p];
|
|
|
|
}
|
|
|
|
assert(count == sizes);
|
|
|
|
|
|
|
|
// Create the domains.
|
|
|
|
for (int index = 0; index < num_domains; ++index) {
|
|
|
|
std::vector<bool> interior(partition_vector.size(), false);
|
|
|
|
for (int ix : partitions[index]) {
|
|
|
|
interior[ix] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Dune::SubGridPart<Grid> view {
|
|
|
|
ebosSimulator_.vanguard().grid(),
|
|
|
|
std::move(seeds[index])
|
|
|
|
};
|
|
|
|
|
|
|
|
this->domains_.emplace_back(index,
|
|
|
|
std::move(partitions[index]),
|
|
|
|
std::move(interior),
|
|
|
|
std::move(view));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up container for the local system matrices.
|
|
|
|
domain_matrices_.resize(num_domains);
|
|
|
|
|
|
|
|
// Set up container for the local linear solvers.
|
|
|
|
for (int index = 0; index < num_domains; ++index) {
|
|
|
|
// TODO: The ISTLSolverEbos constructor will make
|
|
|
|
// parallel structures appropriate for the full grid
|
|
|
|
// only. This must be addressed before going parallel.
|
|
|
|
FlowLinearSolverParameters param;
|
|
|
|
param.template init<TypeTag>(ebosSimulator_.vanguard().eclState().getSimulationConfig().useCPR());
|
|
|
|
// Override solver type with umfpack if small domain.
|
|
|
|
// Otherwise hardcode to ILU0
|
|
|
|
if (domains_[index].cells.size() < 200) {
|
|
|
|
param.linsolver_ = "umfpack";
|
|
|
|
} else {
|
|
|
|
param.linsolver_ = "ilu0";
|
|
|
|
param.linear_solver_reduction_ = 1e-2;
|
|
|
|
}
|
|
|
|
param.linear_solver_print_json_definition_ = false;
|
|
|
|
domain_linsolvers_.emplace_back(ebosSimulator_, param);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(int(domains_.size()) == num_domains);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-06-06 08:40:06 -05:00
|
|
|
/// Called once before each time step.
|
|
|
|
/// \param[in] timer simulation timer
|
2020-12-10 06:39:01 -06:00
|
|
|
SimulatorReportSingle prepareStep(const SimulatorTimerInterface& timer)
|
2016-06-06 08:40:06 -05:00
|
|
|
{
|
2020-12-10 06:39:01 -06:00
|
|
|
SimulatorReportSingle report;
|
|
|
|
Dune::Timer perfTimer;
|
|
|
|
perfTimer.start();
|
2017-11-08 05:17:31 -06:00
|
|
|
// update the solution variables in ebos
|
|
|
|
if ( timer.lastStepFailed() ) {
|
2018-03-06 06:18:03 -06:00
|
|
|
ebosSimulator_.model().updateFailed();
|
2017-11-08 05:17:31 -06:00
|
|
|
} else {
|
2018-03-06 06:18:03 -06:00
|
|
|
ebosSimulator_.model().advanceTimeLevel();
|
2017-11-08 05:17:31 -06:00
|
|
|
}
|
|
|
|
|
2021-01-29 05:30:34 -06:00
|
|
|
// Set the timestep size, episode index, and non-linear iteration index
|
|
|
|
// for ebos explicitly. ebos needs to know the report step/episode index
|
|
|
|
// because of timing dependent data despite the fact that flow uses its
|
|
|
|
// own time stepper. (The length of the episode does not matter, though.)
|
2019-04-03 10:26:57 -05:00
|
|
|
ebosSimulator_.setTime(timer.simulationTimeElapsed());
|
2018-06-27 05:13:49 -05:00
|
|
|
ebosSimulator_.setTimeStepSize(timer.currentStepLength());
|
2021-01-29 00:59:56 -06:00
|
|
|
ebosSimulator_.model().newtonMethod().setIterationIndex(0);
|
2017-11-24 03:49:23 -06:00
|
|
|
|
2021-01-29 05:30:34 -06:00
|
|
|
ebosSimulator_.problem().beginTimeStep();
|
|
|
|
|
2017-06-21 09:26:06 -05:00
|
|
|
unsigned numDof = ebosSimulator_.model().numGridDof();
|
|
|
|
wasSwitched_.resize(numDof);
|
|
|
|
std::fill(wasSwitched_.begin(), wasSwitched_.end(), false);
|
2017-11-08 06:57:36 -06:00
|
|
|
|
2017-11-24 03:49:23 -06:00
|
|
|
if (param_.update_equations_scaling_) {
|
2023-03-03 06:45:36 -06:00
|
|
|
OpmLog::error("Equation scaling not supported");
|
2017-11-24 03:49:23 -06:00
|
|
|
//updateEquationsScaling();
|
|
|
|
}
|
2023-06-14 02:18:53 -05:00
|
|
|
|
|
|
|
if (!domains_.empty()) {
|
|
|
|
// Setup domain->well mapping.
|
|
|
|
wellModel().setupDomains(domains_);
|
|
|
|
}
|
|
|
|
|
2020-12-10 06:39:01 -06:00
|
|
|
report.pre_post_time += perfTimer.stop();
|
|
|
|
|
|
|
|
return report;
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-04 08:37:50 -05:00
|
|
|
void initialLinearization(SimulatorReportSingle& report,
|
|
|
|
const int iteration,
|
|
|
|
const int minIter,
|
|
|
|
const SimulatorTimerInterface& timer)
|
|
|
|
{
|
|
|
|
// ----------- Set up reports and timer -----------
|
|
|
|
failureReport_ = SimulatorReportSingle();
|
|
|
|
Dune::Timer perfTimer;
|
|
|
|
|
|
|
|
perfTimer.start();
|
|
|
|
report.total_linearizations = 1;
|
|
|
|
|
|
|
|
// ----------- Assemble -----------
|
|
|
|
try {
|
|
|
|
report += assembleReservoir(timer, iteration);
|
|
|
|
report.assemble_time += perfTimer.stop();
|
|
|
|
}
|
|
|
|
catch (...) {
|
|
|
|
report.assemble_time += perfTimer.stop();
|
|
|
|
failureReport_ += report;
|
|
|
|
throw; // continue throwing the stick
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------- Check if converged -----------
|
|
|
|
std::vector<double> residual_norms;
|
|
|
|
perfTimer.reset();
|
|
|
|
perfTimer.start();
|
|
|
|
// the step is not considered converged until at least minIter iterations is done
|
|
|
|
{
|
|
|
|
auto convrep = getConvergence(timer, iteration, residual_norms);
|
|
|
|
report.converged = convrep.converged() && iteration > minIter;
|
|
|
|
ConvergenceReport::Severity severity = convrep.severityOfWorstFailure();
|
|
|
|
convergence_reports_.back().report.push_back(std::move(convrep));
|
|
|
|
|
|
|
|
// Throw if any NaN or too large residual found.
|
|
|
|
if (severity == ConvergenceReport::Severity::NotANumber) {
|
|
|
|
OPM_THROW(NumericalProblem, "NaN residual found!");
|
|
|
|
} else if (severity == ConvergenceReport::Severity::TooLarge) {
|
|
|
|
OPM_THROW_NOLOG(NumericalProblem, "Too large residual found!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
report.update_time += perfTimer.stop();
|
|
|
|
residual_norms_history_.push_back(residual_norms);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-06 08:40:06 -05:00
|
|
|
/// Called once per nonlinear iteration.
|
|
|
|
/// This model will perform a Newton-Raphson update, changing reservoir_state
|
|
|
|
/// and well_state. It will also use the nonlinear_solver to do relaxation of
|
|
|
|
/// updates if necessary.
|
|
|
|
/// \param[in] iteration should be 0 for the first call of a new timestep
|
|
|
|
/// \param[in] timer simulation timer
|
|
|
|
/// \param[in] nonlinear_solver nonlinear solver used (for oscillation/relaxation control)
|
|
|
|
template <class NonlinearSolverType>
|
2020-05-07 09:13:39 -05:00
|
|
|
SimulatorReportSingle nonlinearIteration(const int iteration,
|
|
|
|
const SimulatorTimerInterface& timer,
|
|
|
|
NonlinearSolverType& nonlinear_solver)
|
2016-06-06 08:40:06 -05:00
|
|
|
{
|
|
|
|
if (iteration == 0) {
|
|
|
|
// For each iteration we store in a vector the norms of the residual of
|
|
|
|
// the mass balance for each active phase, the well flux and the well equations.
|
|
|
|
residual_norms_history_.clear();
|
|
|
|
current_relaxation_ = 1.0;
|
2016-09-07 04:21:51 -05:00
|
|
|
dx_old_ = 0.0;
|
2018-11-22 04:14:39 -06:00
|
|
|
convergence_reports_.push_back({timer.reportStepNum(), timer.currentStepNum(), {}});
|
|
|
|
convergence_reports_.back().report.reserve(11);
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
2016-11-17 04:55:30 -06:00
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
if (iteration == 0) {
|
|
|
|
return nonlinearIterationNewton(iteration, timer, nonlinear_solver);
|
|
|
|
}
|
|
|
|
if (param_.nonlinear_solver_ == "nldd") {
|
|
|
|
return nonlinearIterationNldd(iteration, timer, nonlinear_solver);
|
|
|
|
} else {
|
|
|
|
return nonlinearIterationNewton(iteration, timer, nonlinear_solver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class NonlinearSolverType>
|
|
|
|
SimulatorReportSingle nonlinearIterationNewton(const int iteration,
|
|
|
|
const SimulatorTimerInterface& timer,
|
|
|
|
NonlinearSolverType& nonlinear_solver)
|
|
|
|
{
|
|
|
|
|
|
|
|
// ----------- Set up reports and timer -----------
|
|
|
|
SimulatorReportSingle report;
|
|
|
|
Dune::Timer perfTimer;
|
|
|
|
|
2023-07-03 03:32:20 -05:00
|
|
|
this->initialLinearization(report, iteration, nonlinear_solver.minIter(), timer);
|
2023-06-14 02:18:53 -05:00
|
|
|
|
|
|
|
// ----------- If not converged, solve linear system and do Newton update -----------
|
2016-12-05 05:14:28 -06:00
|
|
|
if (!report.converged) {
|
2016-11-23 14:44:33 -06:00
|
|
|
perfTimer.reset();
|
|
|
|
perfTimer.start();
|
|
|
|
report.total_newton_iterations = 1;
|
2016-11-17 04:55:30 -06:00
|
|
|
|
2016-06-06 08:40:06 -05:00
|
|
|
// Compute the nonlinear update.
|
2021-12-01 07:00:21 -06:00
|
|
|
unsigned nc = ebosSimulator_.model().numGridDof();
|
2016-09-07 03:13:24 -05:00
|
|
|
BVector x(nc);
|
2016-11-17 04:55:30 -06:00
|
|
|
|
2019-04-05 04:21:36 -05:00
|
|
|
// Solve the linear system.
|
|
|
|
linear_solve_setup_time_ = 0.0;
|
2016-11-23 14:44:33 -06:00
|
|
|
try {
|
2023-06-14 02:18:53 -05:00
|
|
|
// Apply the Schur complement of the well model to
|
|
|
|
// the reservoir linearized equations.
|
2021-10-08 06:45:57 -05:00
|
|
|
// Note that linearize may throw for MSwells.
|
|
|
|
wellModel().linearize(ebosSimulator().model().linearizer().jacobian(),
|
|
|
|
ebosSimulator().model().linearizer().residual());
|
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
// ---- Solve linear system ----
|
2017-07-20 07:23:29 -05:00
|
|
|
solveJacobianSystem(x);
|
2023-06-14 02:18:53 -05:00
|
|
|
|
2019-04-05 04:21:36 -05:00
|
|
|
report.linear_solve_setup_time += linear_solve_setup_time_;
|
2016-11-23 14:44:33 -06:00
|
|
|
report.linear_solve_time += perfTimer.stop();
|
|
|
|
report.total_linear_iterations += linearIterationsLastSolve();
|
|
|
|
}
|
|
|
|
catch (...) {
|
2019-04-05 04:21:36 -05:00
|
|
|
report.linear_solve_setup_time += linear_solve_setup_time_;
|
2016-11-23 14:44:33 -06:00
|
|
|
report.linear_solve_time += perfTimer.stop();
|
|
|
|
report.total_linear_iterations += linearIterationsLastSolve();
|
2017-04-10 08:55:30 -05:00
|
|
|
|
|
|
|
failureReport_ += report;
|
2016-11-23 14:44:33 -06:00
|
|
|
throw; // re-throw up
|
|
|
|
}
|
|
|
|
|
|
|
|
perfTimer.reset();
|
|
|
|
perfTimer.start();
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2017-09-22 06:41:05 -05:00
|
|
|
// handling well state update before oscillation treatment is a decision based
|
|
|
|
// on observation to avoid some big performance degeneration under some circumstances.
|
|
|
|
// there is no theorectical explanation which way is better for sure.
|
2018-08-16 04:51:36 -05:00
|
|
|
wellModel().postSolve(x);
|
2017-09-22 06:41:05 -05:00
|
|
|
|
2017-06-21 09:26:06 -05:00
|
|
|
if (param_.use_update_stabilization_) {
|
2017-08-18 01:37:25 -05:00
|
|
|
// Stabilize the nonlinear update.
|
|
|
|
bool isOscillate = false;
|
|
|
|
bool isStagnate = false;
|
2023-06-14 02:18:53 -05:00
|
|
|
nonlinear_solver.detectOscillations(residual_norms_history_, residual_norms_history_.size() - 1, isOscillate, isStagnate);
|
2017-08-18 01:37:25 -05:00
|
|
|
if (isOscillate) {
|
|
|
|
current_relaxation_ -= nonlinear_solver.relaxIncrement();
|
|
|
|
current_relaxation_ = std::max(current_relaxation_, nonlinear_solver.relaxMax());
|
|
|
|
if (terminalOutputEnabled()) {
|
|
|
|
std::string msg = " Oscillating behavior detected: Relaxation set to "
|
|
|
|
+ std::to_string(current_relaxation_);
|
|
|
|
OpmLog::info(msg);
|
|
|
|
}
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
2017-08-18 01:37:25 -05:00
|
|
|
nonlinear_solver.stabilizeNonlinearUpdate(x, dx_old_, current_relaxation_);
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
// ---- Newton update ----
|
2016-11-23 14:44:33 -06:00
|
|
|
// Apply the update, with considering model-dependent limitations and
|
|
|
|
// chopping of the update.
|
2018-08-03 05:27:20 -05:00
|
|
|
updateSolution(x);
|
2017-07-21 08:30:34 -05:00
|
|
|
|
2016-11-23 14:44:33 -06:00
|
|
|
report.update_time += perfTimer.stop();
|
2016-11-17 04:55:30 -06:00
|
|
|
}
|
|
|
|
|
2016-11-23 14:44:33 -06:00
|
|
|
return report;
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
2016-11-17 04:55:30 -06:00
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class NonlinearSolverType>
|
|
|
|
SimulatorReportSingle nonlinearIterationNldd(const int iteration,
|
|
|
|
const SimulatorTimerInterface& timer,
|
|
|
|
NonlinearSolverType& nonlinear_solver)
|
|
|
|
{
|
|
|
|
// ----------- Set up reports and timer -----------
|
|
|
|
SimulatorReportSingle report;
|
|
|
|
Dune::Timer perfTimer;
|
|
|
|
|
2023-07-03 03:32:20 -05:00
|
|
|
this->initialLinearization(report, iteration, nonlinear_solver.minIter(), timer);
|
2023-06-14 02:18:53 -05:00
|
|
|
|
|
|
|
if (report.converged) {
|
|
|
|
return report;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------- If not converged, do an NLDD iteration -----------
|
|
|
|
|
|
|
|
auto& solution = ebosSimulator().model().solution(0);
|
|
|
|
auto initial_solution = solution;
|
|
|
|
auto locally_solved = initial_solution;
|
|
|
|
|
|
|
|
// ----------- Decide on an ordering for the domains -----------
|
2023-07-03 04:10:32 -05:00
|
|
|
const auto domain_order = this->getSubdomainOrder();
|
2023-06-14 02:18:53 -05:00
|
|
|
|
|
|
|
// ----------- Solve each domain separately -----------
|
|
|
|
std::vector<SimulatorReportSingle> domain_reports(domains_.size());
|
|
|
|
for (const int domain_index : domain_order) {
|
|
|
|
const auto& domain = domains_[domain_index];
|
|
|
|
SimulatorReportSingle local_report;
|
2023-07-03 06:05:21 -05:00
|
|
|
switch (param_.local_solve_approach_) {
|
|
|
|
case DomainSolveApproach::Jacobi:
|
2023-07-03 05:40:15 -05:00
|
|
|
solveDomainJacobi(solution, locally_solved, local_report,
|
|
|
|
iteration, timer, domain);
|
2023-07-03 06:05:21 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case DomainSolveApproach::GaussSeidel:
|
2023-07-03 05:40:15 -05:00
|
|
|
solveDomainGaussSeidel(solution, locally_solved, local_report,
|
|
|
|
iteration, timer, domain);
|
2023-07-03 06:05:21 -05:00
|
|
|
break;
|
2023-06-14 02:18:53 -05:00
|
|
|
}
|
|
|
|
// This should have updated the global matrix to be
|
|
|
|
// dR_i/du_j evaluated at new local solutions for
|
|
|
|
// i == j, at old solution for i != j.
|
|
|
|
if (!local_report.converged) {
|
|
|
|
// TODO: more proper treatment, including in parallel.
|
|
|
|
OpmLog::debug("Convergence failure in domain " + std::to_string(domain.index));
|
|
|
|
}
|
|
|
|
domain_reports[domain.index] = local_report;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Log summary of local solve convergence to DBG file.
|
|
|
|
{
|
|
|
|
int num_converged = 0;
|
|
|
|
SimulatorReportSingle rep;
|
|
|
|
for (const auto& dr : domain_reports) {
|
|
|
|
if (dr.converged) {
|
|
|
|
++num_converged;
|
|
|
|
}
|
|
|
|
rep += dr;
|
|
|
|
}
|
|
|
|
std::ostringstream os;
|
|
|
|
os << fmt::format("Local solves finished. Converged for {}/{} domains.\n",
|
|
|
|
num_converged, domain_reports.size());
|
|
|
|
rep.reportFullyImplicit(os, nullptr);
|
|
|
|
OpmLog::debug(os.str());
|
|
|
|
local_reports_accumulated_ += rep;
|
|
|
|
}
|
|
|
|
|
2023-07-03 06:05:21 -05:00
|
|
|
if (param_.local_solve_approach_ == DomainSolveApproach::Jacobi) {
|
2023-06-14 02:18:53 -05:00
|
|
|
solution = locally_solved;
|
|
|
|
ebosSimulator_.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finish with a Newton step.
|
|
|
|
// Note that the "iteration + 100" is a simple way to avoid entering
|
|
|
|
// "if (iteration == 0)" and similar blocks, and also makes it a little
|
|
|
|
// easier to spot the iteration residuals in the DBG file. A more sophisticated
|
|
|
|
// approach can be done later.
|
|
|
|
auto rep = nonlinearIterationNewton(iteration + 100, timer, nonlinear_solver);
|
|
|
|
report += rep;
|
|
|
|
if (rep.converged) {
|
|
|
|
report.converged = true;
|
|
|
|
}
|
|
|
|
return report;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::pair<SimulatorReportSingle, ConvergenceReport>
|
|
|
|
solveDomain(const Domain& domain,
|
|
|
|
const SimulatorTimerInterface& timer,
|
2023-06-20 15:52:51 -05:00
|
|
|
[[maybe_unused]] const int global_iteration,
|
2023-06-14 02:18:53 -05:00
|
|
|
const bool initial_assembly_required = false)
|
|
|
|
{
|
|
|
|
SimulatorReportSingle report;
|
|
|
|
Dune::Timer solveTimer;
|
|
|
|
solveTimer.start();
|
|
|
|
Dune::Timer detailTimer;
|
|
|
|
|
|
|
|
ebosSimulator_.model().newtonMethod().setIterationIndex(0);
|
|
|
|
|
|
|
|
// When called, if assembly has already been performed
|
|
|
|
// with the initial values, we only need to check
|
|
|
|
// for local convergence. Otherwise, we must do a local
|
|
|
|
// assembly.
|
|
|
|
int iter = 0;
|
|
|
|
if (initial_assembly_required) {
|
|
|
|
detailTimer.start();
|
|
|
|
ebosSimulator_.model().newtonMethod().setIterationIndex(iter);
|
|
|
|
// TODO: we should have a beginIterationLocal function()
|
|
|
|
// only handling the well model for now
|
|
|
|
ebosSimulator_.problem().wellModel().assembleDomain(ebosSimulator_.model().newtonMethod().numIterations(),
|
|
|
|
ebosSimulator_.timeStepSize(),
|
|
|
|
domain);
|
|
|
|
// Assemble reservoir locally.
|
2023-06-20 15:52:51 -05:00
|
|
|
report += assembleReservoirDomain(domain);
|
2023-06-14 02:18:53 -05:00
|
|
|
report.assemble_time += detailTimer.stop();
|
|
|
|
}
|
|
|
|
detailTimer.reset();
|
|
|
|
detailTimer.start();
|
|
|
|
std::vector<double> resnorms;
|
|
|
|
auto convreport = getDomainConvergence(domain, timer, 0, resnorms);
|
|
|
|
if (convreport.converged()) {
|
|
|
|
// TODO: set more info, timing etc.
|
|
|
|
report.converged = true;
|
|
|
|
return { report, convreport };
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have already assembled for the first iteration,
|
|
|
|
// but not done the Schur complement for the wells yet.
|
|
|
|
detailTimer.reset();
|
|
|
|
detailTimer.start();
|
|
|
|
wellModel().linearizeDomain(domain,
|
|
|
|
ebosSimulator().model().linearizer().jacobian(),
|
|
|
|
ebosSimulator().model().linearizer().residual());
|
|
|
|
const double tt1 = detailTimer.stop();
|
|
|
|
report.assemble_time += tt1;
|
|
|
|
report.assemble_time_well += tt1;
|
|
|
|
|
|
|
|
// Local Newton loop.
|
|
|
|
const int max_iter = param_.max_local_solve_iterations_;
|
|
|
|
do {
|
|
|
|
// Solve local linear system.
|
|
|
|
// Note that x has full size, we expect it to be nonzero only for in-domain cells.
|
|
|
|
const int nc = grid_.size(0);
|
|
|
|
BVector x(nc);
|
|
|
|
detailTimer.reset();
|
|
|
|
detailTimer.start();
|
|
|
|
solveJacobianSystemDomain(domain, x);
|
|
|
|
wellModel().postSolveDomain(x, domain);
|
|
|
|
report.linear_solve_time += detailTimer.stop();
|
|
|
|
report.linear_solve_setup_time += linear_solve_setup_time_;
|
|
|
|
report.total_linear_iterations = linearIterationsLastSolve();
|
|
|
|
|
|
|
|
// Update local solution. // TODO: x is still full size, should we optimize it?
|
|
|
|
detailTimer.reset();
|
|
|
|
detailTimer.start();
|
|
|
|
updateDomainSolution(domain, x);
|
|
|
|
report.update_time += detailTimer.stop();
|
|
|
|
|
|
|
|
// Assemble well and reservoir.
|
|
|
|
detailTimer.reset();
|
|
|
|
detailTimer.start();
|
|
|
|
++iter;
|
|
|
|
ebosSimulator_.model().newtonMethod().setIterationIndex(iter);
|
|
|
|
// TODO: we should have a beginIterationLocal function()
|
|
|
|
// only handling the well model for now
|
|
|
|
// Assemble reservoir locally.
|
|
|
|
ebosSimulator_.problem().wellModel().assembleDomain(ebosSimulator_.model().newtonMethod().numIterations(),
|
|
|
|
ebosSimulator_.timeStepSize(),
|
|
|
|
domain);
|
2023-06-20 15:52:51 -05:00
|
|
|
report += assembleReservoirDomain(domain);
|
2023-06-14 02:18:53 -05:00
|
|
|
report.assemble_time += detailTimer.stop();
|
|
|
|
|
|
|
|
// Check for local convergence.
|
|
|
|
detailTimer.reset();
|
|
|
|
detailTimer.start();
|
|
|
|
convreport = getDomainConvergence(domain, timer, iter, resnorms);
|
|
|
|
|
|
|
|
// apply the Schur complement of the well model to the
|
|
|
|
// reservoir linearized equations
|
|
|
|
detailTimer.reset();
|
|
|
|
detailTimer.start();
|
|
|
|
wellModel().linearizeDomain(domain,
|
|
|
|
ebosSimulator().model().linearizer().jacobian(),
|
|
|
|
ebosSimulator().model().linearizer().residual());
|
|
|
|
const double tt2 = detailTimer.stop();
|
|
|
|
report.assemble_time += tt2;
|
|
|
|
report.assemble_time_well += tt2;
|
|
|
|
} while (!convreport.converged() && iter <= max_iter);
|
|
|
|
|
|
|
|
ebosSimulator_.problem().endIteration();
|
|
|
|
|
|
|
|
report.converged = convreport.converged();
|
|
|
|
report.total_newton_iterations = iter;
|
|
|
|
report.total_linearizations = iter;
|
|
|
|
report.total_time = solveTimer.stop();
|
|
|
|
// TODO: set more info, timing etc.
|
|
|
|
return { report, convreport };
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-06-06 08:40:06 -05:00
|
|
|
/// Called once after each time step.
|
|
|
|
/// In this class, this function does nothing.
|
|
|
|
/// \param[in] timer simulation timer
|
2021-08-02 07:55:41 -05:00
|
|
|
SimulatorReportSingle afterStep(const SimulatorTimerInterface&)
|
2016-06-06 08:40:06 -05:00
|
|
|
{
|
2020-12-10 06:39:01 -06:00
|
|
|
SimulatorReportSingle report;
|
|
|
|
Dune::Timer perfTimer;
|
|
|
|
perfTimer.start();
|
2017-11-24 03:49:23 -06:00
|
|
|
ebosSimulator_.problem().endTimeStep();
|
2020-12-10 06:39:01 -06:00
|
|
|
report.pre_post_time += perfTimer.stop();
|
|
|
|
return report;
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Assemble the residual and Jacobian of the nonlinear system.
|
2020-05-07 09:13:39 -05:00
|
|
|
SimulatorReportSingle assembleReservoir(const SimulatorTimerInterface& /* timer */,
|
|
|
|
const int iterationIdx)
|
2016-06-06 08:40:06 -05:00
|
|
|
{
|
|
|
|
// -------- Mass balance equations --------
|
2017-11-24 03:49:23 -06:00
|
|
|
ebosSimulator_.model().newtonMethod().setIterationIndex(iterationIdx);
|
|
|
|
ebosSimulator_.problem().beginIteration();
|
2019-02-25 04:24:30 -06:00
|
|
|
ebosSimulator_.model().linearizer().linearizeDomain();
|
2017-11-24 03:49:23 -06:00
|
|
|
ebosSimulator_.problem().endIteration();
|
2023-06-14 02:18:53 -05:00
|
|
|
return wellModel().lastReport();
|
|
|
|
}
|
2018-06-27 05:13:49 -05:00
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
/// Assemble the residual and Jacobian of the nonlinear system.
|
2023-06-20 15:52:51 -05:00
|
|
|
SimulatorReportSingle assembleReservoirDomain(const Domain& domain)
|
2023-06-14 02:18:53 -05:00
|
|
|
{
|
|
|
|
// -------- Mass balance equations --------
|
|
|
|
ebosSimulator_.model().linearizer().linearizeDomain(domain);
|
2017-11-08 06:57:36 -06:00
|
|
|
return wellModel().lastReport();
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
|
|
|
|
2017-06-21 09:26:06 -05:00
|
|
|
// compute the "relative" change of the solution between time steps
|
2018-06-06 03:59:41 -05:00
|
|
|
double relativeChange() const
|
2016-06-06 08:40:06 -05:00
|
|
|
{
|
2017-06-21 09:26:06 -05:00
|
|
|
Scalar resultDelta = 0.0;
|
|
|
|
Scalar resultDenom = 0.0;
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2017-08-18 01:37:25 -05:00
|
|
|
const auto& elemMapper = ebosSimulator_.model().elementMapper();
|
2017-06-21 09:26:06 -05:00
|
|
|
const auto& gridView = ebosSimulator_.gridView();
|
2022-10-12 07:27:20 -05:00
|
|
|
for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
|
2018-05-29 07:16:19 -05:00
|
|
|
unsigned globalElemIdx = elemMapper.index(elem);
|
2017-06-21 09:26:06 -05:00
|
|
|
const auto& priVarsNew = ebosSimulator_.model().solution(/*timeIdx=*/0)[globalElemIdx];
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2017-06-21 09:26:06 -05:00
|
|
|
Scalar pressureNew;
|
2018-05-29 07:16:19 -05:00
|
|
|
pressureNew = priVarsNew[Indices::pressureSwitchIdx];
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2018-05-29 07:16:19 -05:00
|
|
|
Scalar saturationsNew[FluidSystem::numPhases] = { 0.0 };
|
2017-08-08 01:07:09 -05:00
|
|
|
Scalar oilSaturationNew = 1.0;
|
2022-11-24 01:27:55 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx) &&
|
|
|
|
FluidSystem::numActivePhases() > 1 &&
|
2022-11-25 05:36:40 -06:00
|
|
|
priVarsNew.primaryVarsMeaningWater() == PrimaryVariables::WaterMeaning::Sw) {
|
2022-11-25 02:29:38 -06:00
|
|
|
saturationsNew[FluidSystem::waterPhaseIdx] = priVarsNew[Indices::waterSwitchIdx];
|
2017-08-08 01:07:09 -05:00
|
|
|
oilSaturationNew -= saturationsNew[FluidSystem::waterPhaseIdx];
|
|
|
|
}
|
2017-10-16 09:46:28 -05:00
|
|
|
|
2021-10-06 12:32:35 -05:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx) &&
|
|
|
|
FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) &&
|
2022-11-25 05:36:40 -06:00
|
|
|
priVarsNew.primaryVarsMeaningGas() == PrimaryVariables::GasMeaning::Sg) {
|
2021-08-01 11:09:54 -05:00
|
|
|
assert(Indices::compositionSwitchIdx >= 0 );
|
2017-08-08 01:07:09 -05:00
|
|
|
saturationsNew[FluidSystem::gasPhaseIdx] = priVarsNew[Indices::compositionSwitchIdx];
|
2017-10-16 09:46:28 -05:00
|
|
|
oilSaturationNew -= saturationsNew[FluidSystem::gasPhaseIdx];
|
2017-08-08 01:07:09 -05:00
|
|
|
}
|
2017-10-16 09:46:28 -05:00
|
|
|
|
2017-08-08 01:07:09 -05:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
|
|
|
|
saturationsNew[FluidSystem::oilPhaseIdx] = oilSaturationNew;
|
|
|
|
}
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2017-06-21 09:26:06 -05:00
|
|
|
const auto& priVarsOld = ebosSimulator_.model().solution(/*timeIdx=*/1)[globalElemIdx];
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2017-06-21 09:26:06 -05:00
|
|
|
Scalar pressureOld;
|
2017-08-08 01:07:09 -05:00
|
|
|
pressureOld = priVarsOld[Indices::pressureSwitchIdx];
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2017-06-21 09:26:06 -05:00
|
|
|
Scalar saturationsOld[FluidSystem::numPhases] = { 0.0 };
|
2017-08-08 01:07:09 -05:00
|
|
|
Scalar oilSaturationOld = 1.0;
|
2019-10-11 08:29:49 -05:00
|
|
|
|
2019-10-11 08:57:51 -05:00
|
|
|
// NB fix me! adding pressures changes to satutation changes does not make sense
|
2019-10-11 08:29:49 -05:00
|
|
|
Scalar tmp = pressureNew - pressureOld;
|
|
|
|
resultDelta += tmp*tmp;
|
|
|
|
resultDenom += pressureNew*pressureNew;
|
|
|
|
|
2019-10-11 08:57:51 -05:00
|
|
|
if (FluidSystem::numActivePhases() > 1) {
|
2022-11-25 05:36:40 -06:00
|
|
|
if (priVarsOld.primaryVarsMeaningWater() == PrimaryVariables::WaterMeaning::Sw) {
|
2022-11-25 02:29:38 -06:00
|
|
|
saturationsOld[FluidSystem::waterPhaseIdx] = priVarsOld[Indices::waterSwitchIdx];
|
2019-10-11 08:57:51 -05:00
|
|
|
oilSaturationOld -= saturationsOld[FluidSystem::waterPhaseIdx];
|
|
|
|
}
|
|
|
|
|
2022-11-25 05:36:40 -06:00
|
|
|
if (priVarsOld.primaryVarsMeaningGas() == PrimaryVariables::GasMeaning::Sg)
|
2019-10-11 08:57:51 -05:00
|
|
|
{
|
2021-08-01 11:09:54 -05:00
|
|
|
assert(Indices::compositionSwitchIdx >= 0 );
|
2019-10-11 08:57:51 -05:00
|
|
|
saturationsOld[FluidSystem::gasPhaseIdx] = priVarsOld[Indices::compositionSwitchIdx];
|
|
|
|
oilSaturationOld -= saturationsOld[FluidSystem::gasPhaseIdx];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
|
|
|
|
saturationsOld[FluidSystem::oilPhaseIdx] = oilSaturationOld;
|
|
|
|
}
|
|
|
|
for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++ phaseIdx) {
|
2019-10-11 13:18:53 -05:00
|
|
|
Scalar tmpSat = saturationsNew[phaseIdx] - saturationsOld[phaseIdx];
|
|
|
|
resultDelta += tmpSat*tmpSat;
|
2019-10-11 08:57:51 -05:00
|
|
|
resultDenom += saturationsNew[phaseIdx]*saturationsNew[phaseIdx];
|
|
|
|
assert(std::isfinite(resultDelta));
|
|
|
|
assert(std::isfinite(resultDenom));
|
|
|
|
}
|
|
|
|
}
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
2017-06-21 09:26:06 -05:00
|
|
|
|
|
|
|
resultDelta = gridView.comm().sum(resultDelta);
|
|
|
|
resultDenom = gridView.comm().sum(resultDenom);
|
|
|
|
|
2018-05-29 07:16:19 -05:00
|
|
|
if (resultDenom > 0.0)
|
2018-06-06 03:59:41 -05:00
|
|
|
return resultDelta/resultDenom;
|
2018-05-29 07:16:19 -05:00
|
|
|
return 0.0;
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Number of linear iterations used in last call to solveJacobianSystem().
|
|
|
|
int linearIterationsLastSolve() const
|
|
|
|
{
|
2018-11-12 04:03:54 -06:00
|
|
|
return ebosSimulator_.model().newtonMethod().linearSolver().iterations ();
|
2018-11-06 07:14:50 -06:00
|
|
|
}
|
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
|
|
|
|
void solveJacobianSystemDomain(const Domain& domain, BVector& global_x)
|
|
|
|
{
|
|
|
|
Dune::Timer perfTimer;
|
|
|
|
perfTimer.start();
|
|
|
|
|
|
|
|
const Mat& main_matrix = ebosSimulator_.model().linearizer().jacobian().istlMatrix();
|
|
|
|
if (domain_matrices_[domain.index]) {
|
|
|
|
Details::copySubMatrix(main_matrix, domain.cells, *domain_matrices_[domain.index]);
|
|
|
|
} else {
|
|
|
|
domain_matrices_[domain.index] = std::make_unique<Mat>(Details::extractMatrix(main_matrix, domain.cells));
|
|
|
|
}
|
|
|
|
auto& jac = *domain_matrices_[domain.index];
|
|
|
|
auto res = Details::extractVector(ebosSimulator_.model().linearizer().residual(), domain.cells);
|
|
|
|
auto x = res;
|
|
|
|
|
|
|
|
// set initial guess
|
|
|
|
global_x = 0.0;
|
|
|
|
x = 0.0;
|
|
|
|
|
|
|
|
auto& linsolver = domain_linsolvers_[domain.index];
|
|
|
|
|
|
|
|
linsolver.prepare(jac, res);
|
|
|
|
linear_solve_setup_time_ = perfTimer.stop();
|
|
|
|
linsolver.setResidual(res);
|
|
|
|
linsolver.solve(x);
|
|
|
|
|
|
|
|
Details::setGlobal(x, domain.cells, global_x);
|
|
|
|
}
|
|
|
|
|
2016-06-06 08:40:06 -05:00
|
|
|
/// Solve the Jacobian system Jx = r where J is the Jacobian and
|
|
|
|
/// r is the residual.
|
2018-11-12 04:03:54 -06:00
|
|
|
void solveJacobianSystem(BVector& x)
|
2016-06-06 08:40:06 -05:00
|
|
|
{
|
2018-11-12 04:03:54 -06:00
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
auto& ebosJac = ebosSimulator_.model().linearizer().jacobian().istlMatrix();
|
2018-11-12 04:03:54 -06:00
|
|
|
auto& ebosResid = ebosSimulator_.model().linearizer().residual();
|
2018-11-05 08:54:48 -06:00
|
|
|
|
2016-11-02 07:10:44 -05:00
|
|
|
// set initial guess
|
2016-08-25 08:25:01 -05:00
|
|
|
x = 0.0;
|
2016-11-02 07:10:44 -05:00
|
|
|
|
2018-11-12 04:03:54 -06:00
|
|
|
auto& ebosSolver = ebosSimulator_.model().newtonMethod().linearSolver();
|
2019-04-05 04:21:36 -05:00
|
|
|
Dune::Timer perfTimer;
|
2019-04-04 05:20:30 -05:00
|
|
|
perfTimer.start();
|
2019-01-30 08:13:38 -06:00
|
|
|
ebosSolver.prepare(ebosJac, ebosResid);
|
2019-04-05 04:21:36 -05:00
|
|
|
linear_solve_setup_time_ = perfTimer.stop();
|
2019-01-18 02:05:23 -06:00
|
|
|
ebosSolver.setResidual(ebosResid);
|
|
|
|
// actually, the error needs to be calculated after setResidual in order to
|
|
|
|
// account for parallelization properly. since the residual of ECFV
|
|
|
|
// discretizations does not need to be synchronized across processes to be
|
|
|
|
// consistent, this is not relevant for OPM-flow...
|
2018-11-12 04:03:54 -06:00
|
|
|
ebosSolver.solve(x);
|
|
|
|
}
|
2016-08-25 08:25:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
/// Apply an update to the primary variables.
|
|
|
|
void updateDomainSolution(const Domain& domain, const BVector& dx)
|
|
|
|
{
|
|
|
|
auto& ebosNewtonMethod = ebosSimulator_.model().newtonMethod();
|
|
|
|
SolutionVector& solution = ebosSimulator_.model().solution(/*timeIdx=*/0);
|
|
|
|
|
|
|
|
ebosNewtonMethod.update_(/*nextSolution=*/solution,
|
|
|
|
/*curSolution=*/solution,
|
|
|
|
/*update=*/dx,
|
|
|
|
/*resid=*/dx,
|
|
|
|
domain.cells); // the update routines of the black
|
|
|
|
// oil model do not care about the
|
|
|
|
// residual
|
|
|
|
|
|
|
|
// if the solution is updated, the intensive quantities need to be recalculated
|
|
|
|
ebosSimulator_.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0, domain.view);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-03 05:27:20 -05:00
|
|
|
/// Apply an update to the primary variables.
|
|
|
|
void updateSolution(const BVector& dx)
|
2016-06-06 08:40:06 -05:00
|
|
|
{
|
2023-02-15 02:41:37 -06:00
|
|
|
OPM_TIMEBLOCK(updateSolution);
|
2018-08-03 05:27:20 -05:00
|
|
|
auto& ebosNewtonMethod = ebosSimulator_.model().newtonMethod();
|
|
|
|
SolutionVector& solution = ebosSimulator_.model().solution(/*timeIdx=*/0);
|
2016-09-07 03:13:24 -05:00
|
|
|
|
2018-08-03 05:27:20 -05:00
|
|
|
ebosNewtonMethod.update_(/*nextSolution=*/solution,
|
|
|
|
/*curSolution=*/solution,
|
|
|
|
/*update=*/dx,
|
|
|
|
/*resid=*/dx); // the update routines of the black
|
|
|
|
// oil model do not care about the
|
|
|
|
// residual
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2018-08-03 05:27:20 -05:00
|
|
|
// if the solution is updated, the intensive quantities need to be recalculated
|
2023-02-15 02:41:37 -06:00
|
|
|
{
|
|
|
|
OPM_TIMEBLOCK(invalidateAndUpdateIntensiveQuantities);
|
|
|
|
ebosSimulator_.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0);
|
2023-03-22 13:17:22 -05:00
|
|
|
ebosSimulator_.problem().eclWriter()->mutableEclOutputModule().invalidateLocalData();
|
2023-02-15 02:41:37 -06:00
|
|
|
}
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Return true if output to cout is wanted.
|
|
|
|
bool terminalOutputEnabled() const
|
|
|
|
{
|
|
|
|
return terminal_output_;
|
|
|
|
}
|
|
|
|
|
2023-03-03 06:21:36 -06:00
|
|
|
std::tuple<double,double> convergenceReduction(Parallel::Communication comm,
|
2021-10-25 09:37:25 -05:00
|
|
|
const double pvSumLocal,
|
|
|
|
const double numAquiferPvSumLocal,
|
|
|
|
std::vector< Scalar >& R_sum,
|
|
|
|
std::vector< Scalar >& maxCoeff,
|
|
|
|
std::vector< Scalar >& B_avg)
|
2016-11-02 10:59:08 -05:00
|
|
|
{
|
2023-02-15 02:41:37 -06:00
|
|
|
OPM_TIMEBLOCK(convergenceReduction);
|
2017-01-11 05:20:32 -06:00
|
|
|
// Compute total pore volume (use only owned entries)
|
2017-06-22 07:37:43 -05:00
|
|
|
double pvSum = pvSumLocal;
|
2021-10-25 09:37:25 -05:00
|
|
|
double numAquiferPvSum = numAquiferPvSumLocal;
|
2016-11-02 10:59:08 -05:00
|
|
|
|
|
|
|
if( comm.size() > 1 )
|
|
|
|
{
|
|
|
|
// global reduction
|
|
|
|
std::vector< Scalar > sumBuffer;
|
|
|
|
std::vector< Scalar > maxBuffer;
|
2017-06-22 07:37:43 -05:00
|
|
|
const int numComp = B_avg.size();
|
2021-10-25 09:37:25 -05:00
|
|
|
sumBuffer.reserve( 2*numComp + 2 ); // +2 for (numAquifer)pvSum
|
2017-08-14 06:36:13 -05:00
|
|
|
maxBuffer.reserve( numComp );
|
2017-05-03 06:34:15 -05:00
|
|
|
for( int compIdx = 0; compIdx < numComp; ++compIdx )
|
2016-11-02 10:59:08 -05:00
|
|
|
{
|
2017-05-03 06:34:15 -05:00
|
|
|
sumBuffer.push_back( B_avg[ compIdx ] );
|
|
|
|
sumBuffer.push_back( R_sum[ compIdx ] );
|
|
|
|
maxBuffer.push_back( maxCoeff[ compIdx ] );
|
2016-11-02 10:59:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compute total pore volume
|
|
|
|
sumBuffer.push_back( pvSum );
|
2021-10-25 09:37:25 -05:00
|
|
|
sumBuffer.push_back( numAquiferPvSum );
|
2016-11-02 10:59:08 -05:00
|
|
|
|
|
|
|
// compute global sum
|
|
|
|
comm.sum( sumBuffer.data(), sumBuffer.size() );
|
|
|
|
|
|
|
|
// compute global max
|
|
|
|
comm.max( maxBuffer.data(), maxBuffer.size() );
|
|
|
|
|
|
|
|
// restore values to local variables
|
2017-05-03 06:34:15 -05:00
|
|
|
for( int compIdx = 0, buffIdx = 0; compIdx < numComp; ++compIdx, ++buffIdx )
|
2016-11-02 10:59:08 -05:00
|
|
|
{
|
2017-05-03 06:34:15 -05:00
|
|
|
B_avg[ compIdx ] = sumBuffer[ buffIdx ];
|
2016-11-02 10:59:08 -05:00
|
|
|
++buffIdx;
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
R_sum[ compIdx ] = sumBuffer[ buffIdx ];
|
2017-08-14 06:36:13 -05:00
|
|
|
}
|
|
|
|
|
2017-08-18 09:25:05 -05:00
|
|
|
for( int compIdx = 0; compIdx < numComp; ++compIdx )
|
2017-08-14 06:36:13 -05:00
|
|
|
{
|
2017-08-18 09:25:05 -05:00
|
|
|
maxCoeff[ compIdx ] = maxBuffer[ compIdx ];
|
2016-11-02 10:59:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// restore global pore volume
|
2021-10-25 09:37:25 -05:00
|
|
|
pvSum = sumBuffer[sumBuffer.size()-2];
|
|
|
|
numAquiferPvSum = sumBuffer.back();
|
2016-11-02 10:59:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// return global pore volume
|
2021-10-25 09:37:25 -05:00
|
|
|
return {pvSum, numAquiferPvSum};
|
2016-11-02 10:59:08 -05:00
|
|
|
}
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2021-10-25 09:37:25 -05:00
|
|
|
/// \brief Get reservoir quantities on this process needed for convergence calculations.
|
|
|
|
/// \return A pair of the local pore volume of interior cells and the pore volumes
|
|
|
|
/// of the cells associated with a numerical aquifer.
|
2023-06-26 04:13:45 -05:00
|
|
|
std::pair<double,double> localConvergenceData(std::vector<Scalar>& R_sum,
|
|
|
|
std::vector<Scalar>& maxCoeff,
|
|
|
|
std::vector<Scalar>& B_avg,
|
|
|
|
std::vector<int>& maxCoeffCell)
|
2016-06-06 08:40:06 -05:00
|
|
|
{
|
2023-02-15 02:41:37 -06:00
|
|
|
OPM_TIMEBLOCK(localConvergenceData);
|
2018-10-24 08:03:17 -05:00
|
|
|
double pvSumLocal = 0.0;
|
2021-10-25 09:37:25 -05:00
|
|
|
double numAquiferPvSumLocal = 0.0;
|
2017-06-22 07:37:43 -05:00
|
|
|
const auto& ebosModel = ebosSimulator_.model();
|
|
|
|
const auto& ebosProblem = ebosSimulator_.problem();
|
2016-10-20 10:47:45 -05:00
|
|
|
|
|
|
|
const auto& ebosResid = ebosSimulator_.model().linearizer().residual();
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2017-03-20 10:38:17 -05:00
|
|
|
ElementContext elemCtx(ebosSimulator_);
|
2017-03-20 15:01:36 -05:00
|
|
|
const auto& gridView = ebosSimulator().gridView();
|
2023-07-04 06:33:23 -05:00
|
|
|
IsNumericalAquiferCell isNumericalAquiferCell(gridView.grid());
|
2021-09-20 04:12:27 -05:00
|
|
|
OPM_BEGIN_PARALLEL_TRY_CATCH();
|
2022-10-12 07:27:20 -05:00
|
|
|
for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
|
2017-03-20 15:01:36 -05:00
|
|
|
elemCtx.updatePrimaryStencil(elem);
|
2023-06-26 04:13:45 -05:00
|
|
|
elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
|
2023-06-14 02:18:53 -05:00
|
|
|
|
2017-03-20 15:01:36 -05:00
|
|
|
const unsigned cell_idx = elemCtx.globalSpaceIndex(/*spaceIdx=*/0, /*timeIdx=*/0);
|
2023-06-26 04:13:45 -05:00
|
|
|
const auto& intQuants = elemCtx.intensiveQuantities(/*spaceIdx=*/0, /*timeIdx=*/0);
|
2017-03-20 15:01:36 -05:00
|
|
|
const auto& fs = intQuants.fluidState();
|
2016-10-20 10:47:45 -05:00
|
|
|
|
2023-07-03 03:11:45 -05:00
|
|
|
const auto pvValue = ebosProblem.referencePorosity(cell_idx, /*timeIdx=*/0) *
|
|
|
|
ebosModel.dofTotalVolume(cell_idx);
|
2017-06-22 07:37:43 -05:00
|
|
|
pvSumLocal += pvValue;
|
|
|
|
|
2023-07-04 06:33:23 -05:00
|
|
|
if (isNumericalAquiferCell(elem))
|
2021-10-25 09:37:25 -05:00
|
|
|
{
|
|
|
|
numAquiferPvSumLocal += pvValue;
|
|
|
|
}
|
|
|
|
|
2023-07-03 03:11:45 -05:00
|
|
|
this->getMaxCoeff(cell_idx, intQuants, fs, ebosResid, pvValue,
|
|
|
|
B_avg, R_sum, maxCoeff, maxCoeffCell);
|
2023-06-14 02:18:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
OPM_END_PARALLEL_TRY_CATCH("BlackoilModelEbos::localConvergenceData() failed: ", grid_.comm());
|
|
|
|
|
|
|
|
// compute local average in terms of global number of elements
|
|
|
|
const int bSize = B_avg.size();
|
|
|
|
for ( int i = 0; i<bSize; ++i )
|
|
|
|
{
|
|
|
|
B_avg[ i ] /= Scalar( global_nc_ );
|
|
|
|
}
|
|
|
|
|
|
|
|
return {pvSumLocal, numAquiferPvSumLocal};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get reservoir quantities on this process needed for convergence calculations.
|
2023-06-26 04:13:45 -05:00
|
|
|
std::pair<double, double> localDomainConvergenceData(const Domain& domain,
|
|
|
|
std::vector<Scalar>& R_sum,
|
|
|
|
std::vector<Scalar>& maxCoeff,
|
|
|
|
std::vector<Scalar>& B_avg,
|
|
|
|
std::vector<int>& maxCoeffCell)
|
2023-06-14 02:18:53 -05:00
|
|
|
{
|
|
|
|
double pvSumLocal = 0.0;
|
2023-06-26 04:13:45 -05:00
|
|
|
double numAquiferPvSumLocal = 0.0;
|
2023-06-14 02:18:53 -05:00
|
|
|
const auto& ebosModel = ebosSimulator_.model();
|
|
|
|
const auto& ebosProblem = ebosSimulator_.problem();
|
|
|
|
|
|
|
|
const auto& ebosResid = ebosSimulator_.model().linearizer().residual();
|
|
|
|
|
|
|
|
ElementContext elemCtx(ebosSimulator_);
|
|
|
|
const auto& gridView = domain.view;
|
|
|
|
const auto& elemEndIt = gridView.template end</*codim=*/0>();
|
2023-07-04 06:33:23 -05:00
|
|
|
IsNumericalAquiferCell isNumericalAquiferCell(gridView.grid());
|
2023-06-14 02:18:53 -05:00
|
|
|
OPM_BEGIN_PARALLEL_TRY_CATCH();
|
|
|
|
for (auto elemIt = gridView.template begin</*codim=*/0>();
|
|
|
|
elemIt != elemEndIt;
|
|
|
|
++elemIt)
|
|
|
|
{
|
|
|
|
if (elemIt->partitionType() != Dune::InteriorEntity) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const auto& elem = *elemIt;
|
|
|
|
elemCtx.updatePrimaryStencil(elem);
|
2023-06-26 04:13:45 -05:00
|
|
|
elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
|
2023-06-14 02:18:53 -05:00
|
|
|
|
2023-06-26 04:13:45 -05:00
|
|
|
const unsigned cell_idx = elemCtx.globalSpaceIndex(/*spaceIdx=*/0, /*timeIdx=*/0);
|
|
|
|
const auto& intQuants = elemCtx.intensiveQuantities(/*spaceIdx=*/0, /*timeIdx=*/0);
|
2023-06-14 02:18:53 -05:00
|
|
|
const auto& fs = intQuants.fluidState();
|
|
|
|
|
2023-07-03 03:11:45 -05:00
|
|
|
const auto pvValue = ebosProblem.referencePorosity(cell_idx, /*timeIdx=*/0) *
|
|
|
|
ebosModel.dofTotalVolume(cell_idx);
|
2023-06-14 02:18:53 -05:00
|
|
|
pvSumLocal += pvValue;
|
|
|
|
|
2023-07-04 06:33:23 -05:00
|
|
|
if (isNumericalAquiferCell(elem))
|
2023-06-26 04:13:45 -05:00
|
|
|
{
|
|
|
|
numAquiferPvSumLocal += pvValue;
|
|
|
|
}
|
|
|
|
|
2023-07-03 03:11:45 -05:00
|
|
|
this->getMaxCoeff(cell_idx, intQuants, fs, ebosResid, pvValue,
|
|
|
|
B_avg, R_sum, maxCoeff, maxCoeffCell);
|
2021-10-06 12:32:35 -05:00
|
|
|
}
|
2016-08-12 07:34:27 -05:00
|
|
|
|
2021-05-25 05:57:11 -05:00
|
|
|
OPM_END_PARALLEL_TRY_CATCH("BlackoilModelEbos::localConvergenceData() failed: ", grid_.comm());
|
2021-09-20 04:12:27 -05:00
|
|
|
|
2017-06-22 07:37:43 -05:00
|
|
|
// compute local average in terms of global number of elements
|
|
|
|
const int bSize = B_avg.size();
|
|
|
|
for ( int i = 0; i<bSize; ++i )
|
|
|
|
{
|
2023-06-14 02:18:53 -05:00
|
|
|
B_avg[ i ] /= Scalar(domain.cells.size());
|
2017-04-05 08:48:23 -05:00
|
|
|
}
|
|
|
|
|
2023-06-26 04:13:45 -05:00
|
|
|
return {pvSumLocal, numAquiferPvSumLocal};
|
2023-06-14 02:18:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double computeCnvErrorPvLocal(const Domain& domain, const std::vector<Scalar>& B_avg, double dt)
|
|
|
|
{
|
|
|
|
double errorPV{};
|
|
|
|
const auto& ebosModel = ebosSimulator_.model();
|
|
|
|
const auto& ebosProblem = ebosSimulator_.problem();
|
|
|
|
const auto& ebosResid = ebosSimulator_.model().linearizer().residual();
|
|
|
|
|
|
|
|
for (const int cell_idx : domain.cells)
|
|
|
|
{
|
|
|
|
const double pvValue = ebosProblem.referencePorosity(cell_idx, /*timeIdx=*/0) * ebosModel.dofTotalVolume( cell_idx );
|
|
|
|
const auto& cellResidual = ebosResid[cell_idx];
|
|
|
|
bool cnvViolated = false;
|
|
|
|
|
|
|
|
for (unsigned eqIdx = 0; eqIdx < cellResidual.size(); ++eqIdx)
|
|
|
|
{
|
|
|
|
using std::fabs;
|
|
|
|
Scalar CNV = cellResidual[eqIdx] * dt * B_avg[eqIdx] / pvValue;
|
|
|
|
cnvViolated = cnvViolated || (fabs(CNV) > param_.tolerance_cnv_);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnvViolated)
|
|
|
|
{
|
|
|
|
errorPV += pvValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return errorPV;
|
2018-10-24 08:03:17 -05:00
|
|
|
}
|
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
|
2021-10-25 09:37:25 -05:00
|
|
|
/// \brief Compute the total pore volume of cells violating CNV that are not part
|
|
|
|
/// of a numerical aquifer.
|
2020-07-02 04:52:44 -05:00
|
|
|
double computeCnvErrorPv(const std::vector<Scalar>& B_avg, double dt)
|
|
|
|
{
|
2023-02-15 02:41:37 -06:00
|
|
|
OPM_TIMEBLOCK(computeCnvErrorPv);
|
2020-07-02 04:52:44 -05:00
|
|
|
double errorPV{};
|
|
|
|
const auto& ebosModel = ebosSimulator_.model();
|
|
|
|
const auto& ebosProblem = ebosSimulator_.problem();
|
|
|
|
const auto& ebosResid = ebosSimulator_.model().linearizer().residual();
|
|
|
|
const auto& gridView = ebosSimulator().gridView();
|
|
|
|
ElementContext elemCtx(ebosSimulator_);
|
2023-07-04 06:33:23 -05:00
|
|
|
IsNumericalAquiferCell isNumericalAquiferCell(gridView.grid());
|
2020-07-02 04:52:44 -05:00
|
|
|
|
2021-09-20 04:12:27 -05:00
|
|
|
OPM_BEGIN_PARALLEL_TRY_CATCH();
|
|
|
|
|
2022-10-12 07:27:20 -05:00
|
|
|
for (const auto& elem : elements(gridView, Dune::Partitions::interiorBorder))
|
2020-07-02 04:52:44 -05:00
|
|
|
{
|
2021-10-25 09:37:25 -05:00
|
|
|
// Skip cells of numerical Aquifer
|
2023-07-04 06:33:23 -05:00
|
|
|
if (isNumericalAquiferCell(elem))
|
2021-10-25 09:37:25 -05:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-07-02 04:52:44 -05:00
|
|
|
elemCtx.updatePrimaryStencil(elem);
|
2023-06-14 02:18:53 -05:00
|
|
|
// elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
|
2020-07-02 04:52:44 -05:00
|
|
|
const unsigned cell_idx = elemCtx.globalSpaceIndex(/*spaceIdx=*/0, /*timeIdx=*/0);
|
|
|
|
const double pvValue = ebosProblem.referencePorosity(cell_idx, /*timeIdx=*/0) * ebosModel.dofTotalVolume( cell_idx );
|
2020-08-25 07:07:27 -05:00
|
|
|
const auto& cellResidual = ebosResid[cell_idx];
|
2020-07-02 04:52:44 -05:00
|
|
|
bool cnvViolated = false;
|
|
|
|
|
|
|
|
for (unsigned eqIdx = 0; eqIdx < cellResidual.size(); ++eqIdx)
|
|
|
|
{
|
|
|
|
using std::abs;
|
|
|
|
Scalar CNV = cellResidual[eqIdx] * dt * B_avg[eqIdx] / pvValue;
|
|
|
|
cnvViolated = cnvViolated || (abs(CNV) > param_.tolerance_cnv_);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnvViolated)
|
|
|
|
{
|
|
|
|
errorPV += pvValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-25 05:57:11 -05:00
|
|
|
OPM_END_PARALLEL_TRY_CATCH("BlackoilModelEbos::ComputeCnvError() failed: ", grid_.comm());
|
2021-09-20 04:12:27 -05:00
|
|
|
|
2020-07-02 04:52:44 -05:00
|
|
|
return grid_.comm().sum(errorPV);
|
|
|
|
}
|
|
|
|
|
2023-05-03 06:17:20 -05:00
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
ConvergenceReport getDomainReservoirConvergence(const double reportTime,
|
|
|
|
const double dt,
|
|
|
|
const int iteration,
|
|
|
|
const Domain& domain,
|
|
|
|
std::vector<Scalar>& B_avg,
|
|
|
|
std::vector<Scalar>& residual_norms)
|
|
|
|
{
|
|
|
|
typedef std::vector< Scalar > Vector;
|
|
|
|
|
|
|
|
const int numComp = numEq;
|
|
|
|
Vector R_sum(numComp, 0.0 );
|
|
|
|
Vector maxCoeff(numComp, std::numeric_limits< Scalar >::lowest() );
|
|
|
|
std::vector<int> maxCoeffCell(numComp, -1);
|
2023-06-26 04:13:45 -05:00
|
|
|
const auto [ pvSum, numAquiferPvSum]
|
|
|
|
= localDomainConvergenceData(domain, R_sum, maxCoeff, B_avg, maxCoeffCell);
|
2023-06-14 02:18:53 -05:00
|
|
|
|
|
|
|
auto cnvErrorPvFraction = computeCnvErrorPvLocal(domain, B_avg, dt);
|
2023-06-26 04:13:45 -05:00
|
|
|
cnvErrorPvFraction /= (pvSum - numAquiferPvSum);
|
2023-06-14 02:18:53 -05:00
|
|
|
|
|
|
|
const double tol_mb = param_.local_tolerance_scaling_mb_ * param_.tolerance_mb_;
|
|
|
|
// Default value of relaxed_max_pv_fraction_ is 0.03 and min_strict_cnv_iter_ is 0.
|
|
|
|
// For each iteration, we need to determine whether to use the relaxed CNV tolerance.
|
|
|
|
// To disable the usage of relaxed CNV tolerance, you can set the relaxed_max_pv_fraction_ to be 0.
|
|
|
|
const bool use_relaxed = cnvErrorPvFraction < param_.relaxed_max_pv_fraction_ && iteration >= param_.min_strict_cnv_iter_;
|
|
|
|
// Tighter bound for local convergence should increase the
|
|
|
|
// likelyhood of: local convergence => global convergence
|
|
|
|
const double tol_cnv = param_.local_tolerance_scaling_cnv_
|
|
|
|
* (use_relaxed ? param_.tolerance_cnv_relaxed_ : param_.tolerance_cnv_);
|
|
|
|
|
|
|
|
// Finish computation
|
|
|
|
std::vector<Scalar> CNV(numComp);
|
|
|
|
std::vector<Scalar> mass_balance_residual(numComp);
|
|
|
|
for ( int compIdx = 0; compIdx < numComp; ++compIdx )
|
|
|
|
{
|
|
|
|
CNV[compIdx] = B_avg[compIdx] * dt * maxCoeff[compIdx];
|
|
|
|
mass_balance_residual[compIdx] = std::abs(B_avg[compIdx]*R_sum[compIdx]) * dt / pvSum;
|
|
|
|
residual_norms.push_back(CNV[compIdx]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create convergence report.
|
2023-06-20 15:52:51 -05:00
|
|
|
ConvergenceReport report{reportTime};
|
2023-06-14 02:18:53 -05:00
|
|
|
using CR = ConvergenceReport;
|
|
|
|
for (int compIdx = 0; compIdx < numComp; ++compIdx) {
|
|
|
|
double res[2] = { mass_balance_residual[compIdx], CNV[compIdx] };
|
|
|
|
CR::ReservoirFailure::Type types[2] = { CR::ReservoirFailure::Type::MassBalance,
|
|
|
|
CR::ReservoirFailure::Type::Cnv };
|
|
|
|
double tol[2] = { tol_mb, tol_cnv };
|
|
|
|
for (int ii : {0, 1}) {
|
|
|
|
if (std::isnan(res[ii])) {
|
2023-06-26 10:37:13 -05:00
|
|
|
report.setReservoirFailed({types[ii], CR::Severity::NotANumber, compIdx});
|
2023-06-14 02:18:53 -05:00
|
|
|
if ( terminal_output_ ) {
|
|
|
|
OpmLog::debug("NaN residual for " + compNames_.name(compIdx) + " equation.");
|
|
|
|
}
|
|
|
|
} else if (res[ii] > maxResidualAllowed()) {
|
2023-06-26 10:37:13 -05:00
|
|
|
report.setReservoirFailed({types[ii], CR::Severity::TooLarge, compIdx});
|
2023-06-14 02:18:53 -05:00
|
|
|
if ( terminal_output_ ) {
|
|
|
|
OpmLog::debug("Too large residual for " + compNames_.name(compIdx) + " equation.");
|
|
|
|
}
|
|
|
|
} else if (res[ii] < 0.0) {
|
2023-06-26 10:37:13 -05:00
|
|
|
report.setReservoirFailed({types[ii], CR::Severity::Normal, compIdx});
|
2023-06-14 02:18:53 -05:00
|
|
|
if ( terminal_output_ ) {
|
|
|
|
OpmLog::debug("Negative residual for " + compNames_.name(compIdx) + " equation.");
|
|
|
|
}
|
|
|
|
} else if (res[ii] > tol[ii]) {
|
2023-06-26 10:37:13 -05:00
|
|
|
report.setReservoirFailed({types[ii], CR::Severity::Normal, compIdx});
|
2023-06-14 02:18:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Output of residuals.
|
|
|
|
if ( terminal_output_ )
|
|
|
|
{
|
|
|
|
// Only rank 0 does print to std::cout
|
|
|
|
if (iteration == 0) {
|
|
|
|
std::string msg = fmt::format("Domain {}, size {}, containing cell {}\n| Iter",
|
|
|
|
domain.index, domain.cells.size(), domain.cells[0]);
|
|
|
|
for (int compIdx = 0; compIdx < numComp; ++compIdx) {
|
|
|
|
msg += " MB(";
|
|
|
|
msg += compNames_.name(compIdx)[0];
|
|
|
|
msg += ") ";
|
|
|
|
}
|
|
|
|
for (int compIdx = 0; compIdx < numComp; ++compIdx) {
|
|
|
|
msg += " CNV(";
|
|
|
|
msg += compNames_.name(compIdx)[0];
|
|
|
|
msg += ") ";
|
|
|
|
}
|
|
|
|
OpmLog::debug(msg);
|
|
|
|
}
|
|
|
|
std::ostringstream ss;
|
|
|
|
ss << "| ";
|
|
|
|
const std::streamsize oprec = ss.precision(3);
|
|
|
|
const std::ios::fmtflags oflags = ss.setf(std::ios::scientific);
|
|
|
|
ss << std::setw(4) << iteration;
|
|
|
|
for (int compIdx = 0; compIdx < numComp; ++compIdx) {
|
|
|
|
ss << std::setw(11) << mass_balance_residual[compIdx];
|
|
|
|
}
|
|
|
|
for (int compIdx = 0; compIdx < numComp; ++compIdx) {
|
|
|
|
ss << std::setw(11) << CNV[compIdx];
|
|
|
|
}
|
|
|
|
ss.precision(oprec);
|
|
|
|
ss.flags(oflags);
|
|
|
|
OpmLog::debug(ss.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return report;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-05-03 06:17:20 -05:00
|
|
|
void updateTUNING(const Tuning& tuning) {
|
2023-05-12 06:09:32 -05:00
|
|
|
param_.tolerance_mb_ = tuning.XXXMBE;
|
|
|
|
if ( terminal_output_ ) {
|
|
|
|
OpmLog::debug(fmt::format("Setting BlackoilModelEbos mass balance limit (XXXMBE) to {:.2e}", tuning.XXXMBE));
|
2023-05-03 06:17:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-08 10:16:34 -06:00
|
|
|
ConvergenceReport getReservoirConvergence(const double reportTime,
|
|
|
|
const double dt,
|
2018-11-15 13:38:25 -06:00
|
|
|
const int iteration,
|
|
|
|
std::vector<Scalar>& B_avg,
|
|
|
|
std::vector<Scalar>& residual_norms)
|
2018-10-24 08:03:17 -05:00
|
|
|
{
|
2023-02-15 02:41:37 -06:00
|
|
|
OPM_TIMEBLOCK(getReservoirConvergence);
|
2023-03-03 06:25:46 -06:00
|
|
|
using Vector = std::vector<Scalar>;
|
2017-08-14 06:36:13 -05:00
|
|
|
|
2018-10-24 08:03:17 -05:00
|
|
|
const int numComp = numEq;
|
|
|
|
Vector R_sum(numComp, 0.0 );
|
|
|
|
Vector maxCoeff(numComp, std::numeric_limits< Scalar >::lowest() );
|
2023-06-14 02:18:53 -05:00
|
|
|
std::vector<int> maxCoeffCell(numComp, -1);
|
|
|
|
const auto [ pvSumLocal, numAquiferPvSumLocal] = localConvergenceData(R_sum, maxCoeff, B_avg, maxCoeffCell);
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2017-06-22 07:37:43 -05:00
|
|
|
// compute global sum and max of quantities
|
2021-10-25 09:37:25 -05:00
|
|
|
const auto [ pvSum, numAquiferPvSum ] =
|
|
|
|
convergenceReduction(grid_.comm(), pvSumLocal,
|
|
|
|
numAquiferPvSumLocal,
|
|
|
|
R_sum, maxCoeff, B_avg);
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2020-07-02 04:52:44 -05:00
|
|
|
auto cnvErrorPvFraction = computeCnvErrorPv(B_avg, dt);
|
2021-10-25 09:37:25 -05:00
|
|
|
cnvErrorPvFraction /= (pvSum - numAquiferPvSum);
|
2020-07-02 04:52:44 -05:00
|
|
|
|
|
|
|
const double tol_mb = param_.tolerance_mb_;
|
2022-09-07 07:12:03 -05:00
|
|
|
// Default value of relaxed_max_pv_fraction_ is 0.03 and min_strict_cnv_iter_ is 0.
|
|
|
|
// For each iteration, we need to determine whether to use the relaxed CNV tolerance.
|
|
|
|
// To disable the usage of relaxed CNV tolerance, you can set the relaxed_max_pv_fraction_ to be 0.
|
|
|
|
const bool use_relaxed = cnvErrorPvFraction < param_.relaxed_max_pv_fraction_ && iteration >= param_.min_strict_cnv_iter_;
|
2020-08-19 01:50:39 -05:00
|
|
|
const double tol_cnv = use_relaxed ? param_.tolerance_cnv_relaxed_ : param_.tolerance_cnv_;
|
2020-07-02 04:52:44 -05:00
|
|
|
|
2016-06-06 08:40:06 -05:00
|
|
|
// Finish computation
|
2018-11-15 13:38:25 -06:00
|
|
|
std::vector<Scalar> CNV(numComp);
|
|
|
|
std::vector<Scalar> mass_balance_residual(numComp);
|
2017-05-03 06:34:15 -05:00
|
|
|
for ( int compIdx = 0; compIdx < numComp; ++compIdx )
|
2016-06-06 08:40:06 -05:00
|
|
|
{
|
2017-05-03 06:34:15 -05:00
|
|
|
CNV[compIdx] = B_avg[compIdx] * dt * maxCoeff[compIdx];
|
|
|
|
mass_balance_residual[compIdx] = std::abs(B_avg[compIdx]*R_sum[compIdx]) * dt / pvSum;
|
|
|
|
residual_norms.push_back(CNV[compIdx]);
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
|
|
|
|
2018-11-15 13:38:25 -06:00
|
|
|
// Create convergence report.
|
2022-12-08 10:16:34 -06:00
|
|
|
ConvergenceReport report{reportTime};
|
2018-11-15 13:38:25 -06:00
|
|
|
using CR = ConvergenceReport;
|
2018-11-19 07:46:31 -06:00
|
|
|
for (int compIdx = 0; compIdx < numComp; ++compIdx) {
|
2018-11-15 13:38:25 -06:00
|
|
|
double res[2] = { mass_balance_residual[compIdx], CNV[compIdx] };
|
|
|
|
CR::ReservoirFailure::Type types[2] = { CR::ReservoirFailure::Type::MassBalance,
|
|
|
|
CR::ReservoirFailure::Type::Cnv };
|
|
|
|
double tol[2] = { tol_mb, tol_cnv };
|
|
|
|
for (int ii : {0, 1}) {
|
|
|
|
if (std::isnan(res[ii])) {
|
2023-06-26 10:37:13 -05:00
|
|
|
report.setReservoirFailed({types[ii], CR::Severity::NotANumber, compIdx});
|
2018-11-19 07:46:31 -06:00
|
|
|
if ( terminal_output_ ) {
|
2022-12-08 07:09:09 -06:00
|
|
|
OpmLog::debug("NaN residual for " + this->compNames_.name(compIdx) + " equation.");
|
2018-11-19 07:46:31 -06:00
|
|
|
}
|
2018-11-15 13:38:25 -06:00
|
|
|
} else if (res[ii] > maxResidualAllowed()) {
|
2023-06-26 10:37:13 -05:00
|
|
|
report.setReservoirFailed({types[ii], CR::Severity::TooLarge, compIdx});
|
2018-11-19 07:46:31 -06:00
|
|
|
if ( terminal_output_ ) {
|
2022-12-08 07:09:09 -06:00
|
|
|
OpmLog::debug("Too large residual for " + this->compNames_.name(compIdx) + " equation.");
|
2018-11-19 07:46:31 -06:00
|
|
|
}
|
2018-11-15 13:38:25 -06:00
|
|
|
} else if (res[ii] < 0.0) {
|
2023-06-26 10:37:13 -05:00
|
|
|
report.setReservoirFailed({types[ii], CR::Severity::Normal, compIdx});
|
2018-11-19 07:46:31 -06:00
|
|
|
if ( terminal_output_ ) {
|
2022-12-08 07:09:09 -06:00
|
|
|
OpmLog::debug("Negative residual for " + this->compNames_.name(compIdx) + " equation.");
|
2018-11-19 07:46:31 -06:00
|
|
|
}
|
2018-11-15 13:38:25 -06:00
|
|
|
} else if (res[ii] > tol[ii]) {
|
2023-06-26 10:37:13 -05:00
|
|
|
report.setReservoirFailed({types[ii], CR::Severity::Normal, compIdx});
|
2018-11-15 13:38:25 -06:00
|
|
|
}
|
2022-12-08 10:16:34 -06:00
|
|
|
report.setReservoirConvergenceMetric(types[ii], compIdx, res[ii]);
|
2018-11-15 13:38:25 -06:00
|
|
|
}
|
|
|
|
}
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2018-11-15 13:38:25 -06:00
|
|
|
// Output of residuals.
|
2016-06-06 08:40:06 -05:00
|
|
|
if ( terminal_output_ )
|
|
|
|
{
|
|
|
|
// Only rank 0 does print to std::cout
|
|
|
|
if (iteration == 0) {
|
|
|
|
std::string msg = "Iter";
|
2017-05-03 06:34:15 -05:00
|
|
|
for (int compIdx = 0; compIdx < numComp; ++compIdx) {
|
2018-11-19 07:46:31 -06:00
|
|
|
msg += " MB(";
|
2022-12-08 07:09:09 -06:00
|
|
|
msg += this->compNames_.name(compIdx)[0];
|
2018-11-19 07:46:31 -06:00
|
|
|
msg += ") ";
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
2017-05-03 06:34:15 -05:00
|
|
|
for (int compIdx = 0; compIdx < numComp; ++compIdx) {
|
2018-11-19 07:46:31 -06:00
|
|
|
msg += " CNV(";
|
2022-12-08 07:09:09 -06:00
|
|
|
msg += this->compNames_.name(compIdx)[0];
|
2018-11-19 07:46:31 -06:00
|
|
|
msg += ") ";
|
2016-11-02 05:25:43 -05:00
|
|
|
}
|
2017-10-13 06:29:31 -05:00
|
|
|
OpmLog::debug(msg);
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
|
|
|
std::ostringstream ss;
|
|
|
|
const std::streamsize oprec = ss.precision(3);
|
|
|
|
const std::ios::fmtflags oflags = ss.setf(std::ios::scientific);
|
|
|
|
ss << std::setw(4) << iteration;
|
2017-05-03 06:34:15 -05:00
|
|
|
for (int compIdx = 0; compIdx < numComp; ++compIdx) {
|
|
|
|
ss << std::setw(11) << mass_balance_residual[compIdx];
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
2017-05-03 06:34:15 -05:00
|
|
|
for (int compIdx = 0; compIdx < numComp; ++compIdx) {
|
|
|
|
ss << std::setw(11) << CNV[compIdx];
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
|
|
|
ss.precision(oprec);
|
|
|
|
ss.flags(oflags);
|
2017-10-13 06:29:31 -05:00
|
|
|
OpmLog::debug(ss.str());
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
|
|
|
|
2018-11-15 13:38:25 -06:00
|
|
|
return report;
|
|
|
|
}
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
ConvergenceReport getDomainConvergence(const Domain& domain,
|
|
|
|
const SimulatorTimerInterface& timer,
|
|
|
|
const int iteration,
|
|
|
|
std::vector<double>& residual_norms)
|
|
|
|
{
|
|
|
|
std::vector<Scalar> B_avg(numEq, 0.0);
|
|
|
|
auto report = getDomainReservoirConvergence(timer.simulationTimeElapsed(),
|
|
|
|
timer.currentStepLength(),
|
|
|
|
iteration,
|
|
|
|
domain,
|
|
|
|
B_avg,
|
|
|
|
residual_norms);
|
|
|
|
report += wellModel().getDomainWellConvergence(domain, B_avg);
|
|
|
|
return report;
|
|
|
|
}
|
|
|
|
|
2018-11-15 13:38:25 -06:00
|
|
|
/// Compute convergence based on total mass balance (tol_mb) and maximum
|
|
|
|
/// residual mass balance (tol_cnv).
|
|
|
|
/// \param[in] timer simulation timer
|
|
|
|
/// \param[in] iteration current iteration number
|
|
|
|
/// \param[out] residual_norms CNV residuals by phase
|
2018-11-15 14:21:25 -06:00
|
|
|
ConvergenceReport getConvergence(const SimulatorTimerInterface& timer,
|
|
|
|
const int iteration,
|
|
|
|
std::vector<double>& residual_norms)
|
2018-11-15 13:38:25 -06:00
|
|
|
{
|
2023-02-15 02:41:37 -06:00
|
|
|
OPM_TIMEBLOCK(getConvergence);
|
2018-11-15 13:38:25 -06:00
|
|
|
// Get convergence reports for reservoir and wells.
|
|
|
|
std::vector<Scalar> B_avg(numEq, 0.0);
|
2022-12-08 10:16:34 -06:00
|
|
|
auto report = getReservoirConvergence(timer.simulationTimeElapsed(),
|
|
|
|
timer.currentStepLength(),
|
|
|
|
iteration, B_avg, residual_norms);
|
2023-02-15 02:41:37 -06:00
|
|
|
{
|
|
|
|
OPM_TIMEBLOCK(getWellConvergence);
|
|
|
|
report += wellModel().getWellConvergence(B_avg, /*checkWellGroupControls*/report.converged());
|
|
|
|
}
|
2018-11-15 14:21:25 -06:00
|
|
|
return report;
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The number of active fluid phases in the model.
|
|
|
|
int numPhases() const
|
|
|
|
{
|
2017-06-16 06:52:51 -05:00
|
|
|
return phaseUsage_.num_phases;
|
2016-06-06 08:40:06 -05:00
|
|
|
}
|
|
|
|
|
2017-02-06 09:51:22 -06:00
|
|
|
/// Wrapper required due to not following generic API
|
|
|
|
template<class T>
|
|
|
|
std::vector<std::vector<double> >
|
|
|
|
computeFluidInPlace(const T&, const std::vector<int>& fipnum) const
|
|
|
|
{
|
|
|
|
return computeFluidInPlace(fipnum);
|
|
|
|
}
|
|
|
|
|
2018-01-15 06:51:40 -06:00
|
|
|
/// Should not be called
|
2016-09-12 16:28:44 -05:00
|
|
|
std::vector<std::vector<double> >
|
2018-01-15 06:51:40 -06:00
|
|
|
computeFluidInPlace(const std::vector<int>& /*fipnum*/) const
|
2018-12-21 06:51:13 -06:00
|
|
|
{
|
2023-02-15 02:41:37 -06:00
|
|
|
OPM_TIMEBLOCK(computeFluidInPlace);
|
2018-01-15 06:51:40 -06:00
|
|
|
//assert(true)
|
|
|
|
//return an empty vector
|
|
|
|
std::vector<std::vector<double> > regionValues(0, std::vector<double>(0,0.0));
|
2017-03-13 04:04:31 -05:00
|
|
|
return regionValues;
|
2016-09-12 16:28:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const Simulator& ebosSimulator() const
|
|
|
|
{ return ebosSimulator_; }
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2018-06-06 03:59:41 -05:00
|
|
|
Simulator& ebosSimulator()
|
|
|
|
{ return ebosSimulator_; }
|
|
|
|
|
2017-04-10 08:55:30 -05:00
|
|
|
/// return the statistics if the nonlinearIteration() method failed
|
2020-05-07 09:13:39 -05:00
|
|
|
const SimulatorReportSingle& failureReport() const
|
2017-04-10 08:55:30 -05:00
|
|
|
{ return failureReport_; }
|
|
|
|
|
2023-06-14 02:18:53 -05:00
|
|
|
/// return the statistics if the nonlinearIteration() method failed
|
|
|
|
const SimulatorReportSingle& localAccumulatedReports() const
|
|
|
|
{ return local_reports_accumulated_; }
|
|
|
|
|
2018-11-22 04:14:39 -06:00
|
|
|
const std::vector<StepReport>& stepReports() const
|
|
|
|
{
|
|
|
|
return convergence_reports_;
|
|
|
|
}
|
|
|
|
|
2017-03-13 04:04:27 -05:00
|
|
|
protected:
|
2016-06-06 08:40:06 -05:00
|
|
|
// --------- Data members ---------
|
|
|
|
|
2016-08-08 07:31:32 -05:00
|
|
|
Simulator& ebosSimulator_;
|
2016-11-02 07:10:44 -05:00
|
|
|
const Grid& grid_;
|
2017-06-16 06:52:51 -05:00
|
|
|
const PhaseUsage phaseUsage_;
|
2020-12-07 05:16:04 -06:00
|
|
|
static constexpr bool has_solvent_ = getPropValue<TypeTag, Properties::EnableSolvent>();
|
2020-12-04 06:40:14 -06:00
|
|
|
static constexpr bool has_extbo_ = getPropValue<TypeTag, Properties::EnableExtbo>();
|
2020-12-07 05:16:04 -06:00
|
|
|
static constexpr bool has_polymer_ = getPropValue<TypeTag, Properties::EnablePolymer>();
|
|
|
|
static constexpr bool has_polymermw_ = getPropValue<TypeTag, Properties::EnablePolymerMW>();
|
|
|
|
static constexpr bool has_energy_ = getPropValue<TypeTag, Properties::EnableEnergy>();
|
|
|
|
static constexpr bool has_foam_ = getPropValue<TypeTag, Properties::EnableFoam>();
|
|
|
|
static constexpr bool has_brine_ = getPropValue<TypeTag, Properties::EnableBrine>();
|
2021-10-06 12:32:35 -05:00
|
|
|
static constexpr bool has_micp_ = getPropValue<TypeTag, Properties::EnableMICP>();
|
2016-06-06 08:40:06 -05:00
|
|
|
|
|
|
|
ModelParameters param_;
|
2020-05-07 09:13:39 -05:00
|
|
|
SimulatorReportSingle failureReport_;
|
2023-06-14 02:18:53 -05:00
|
|
|
SimulatorReportSingle local_reports_accumulated_;
|
2016-06-06 08:40:06 -05:00
|
|
|
|
|
|
|
// Well Model
|
2017-09-26 03:52:05 -05:00
|
|
|
BlackoilWellModel<TypeTag>& well_model_;
|
2016-06-06 08:40:06 -05:00
|
|
|
|
|
|
|
/// \brief Whether we print something to std::cout
|
|
|
|
bool terminal_output_;
|
|
|
|
/// \brief The number of cells of the global grid.
|
2016-11-02 10:59:08 -05:00
|
|
|
long int global_nc_;
|
2016-06-06 08:40:06 -05:00
|
|
|
|
|
|
|
std::vector<std::vector<double>> residual_norms_history_;
|
|
|
|
double current_relaxation_;
|
2016-09-07 03:13:24 -05:00
|
|
|
BVector dx_old_;
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2018-11-22 04:14:39 -06:00
|
|
|
std::vector<StepReport> convergence_reports_;
|
2022-12-08 07:09:09 -06:00
|
|
|
ComponentName compNames_{};
|
2023-06-14 02:18:53 -05:00
|
|
|
std::vector<Domain> domains_;
|
|
|
|
std::vector<std::unique_ptr<Mat>> domain_matrices_;
|
|
|
|
std::vector<ISTLSolverType> domain_linsolvers_;
|
2022-12-08 07:09:09 -06:00
|
|
|
|
2016-06-06 08:40:06 -05:00
|
|
|
public:
|
|
|
|
/// return the StandardWells object
|
2017-09-26 03:52:05 -05:00
|
|
|
BlackoilWellModel<TypeTag>&
|
2017-04-04 03:56:26 -05:00
|
|
|
wellModel() { return well_model_; }
|
2017-09-26 03:52:05 -05:00
|
|
|
|
|
|
|
const BlackoilWellModel<TypeTag>&
|
2017-04-04 03:56:26 -05:00
|
|
|
wellModel() const { return well_model_; }
|
2016-06-06 08:40:06 -05:00
|
|
|
|
2019-06-26 02:50:56 -05:00
|
|
|
void beginReportStep()
|
2016-08-08 07:58:25 -05:00
|
|
|
{
|
2019-06-26 02:50:56 -05:00
|
|
|
ebosSimulator_.problem().beginEpisode();
|
2016-08-08 07:58:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void endReportStep()
|
|
|
|
{
|
|
|
|
ebosSimulator_.problem().endEpisode();
|
|
|
|
}
|
|
|
|
|
2023-07-03 03:11:45 -05:00
|
|
|
template<class FluidState, class Residual>
|
|
|
|
void getMaxCoeff(const unsigned cell_idx,
|
|
|
|
const IntensiveQuantities& intQuants,
|
|
|
|
const FluidState& fs,
|
|
|
|
const Residual& ebosResid,
|
|
|
|
const Scalar pvValue,
|
|
|
|
std::vector<Scalar>& B_avg,
|
|
|
|
std::vector<Scalar>& R_sum,
|
|
|
|
std::vector<Scalar>& maxCoeff,
|
|
|
|
std::vector<int>& maxCoeffCell)
|
|
|
|
{
|
|
|
|
for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
|
|
|
|
{
|
|
|
|
if (!FluidSystem::phaseIsActive(phaseIdx)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned compIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
|
|
|
|
|
|
|
|
B_avg[compIdx] += 1.0 / fs.invB(phaseIdx).value();
|
|
|
|
const auto R2 = ebosResid[cell_idx][compIdx];
|
|
|
|
|
|
|
|
R_sum[compIdx] += R2;
|
|
|
|
const double Rval = std::abs(R2) / pvValue;
|
|
|
|
if (Rval > maxCoeff[compIdx]) {
|
|
|
|
maxCoeff[compIdx] = Rval;
|
|
|
|
maxCoeffCell[compIdx] = cell_idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if constexpr (has_solvent_) {
|
|
|
|
B_avg[contiSolventEqIdx] += 1.0 / intQuants.solventInverseFormationVolumeFactor().value();
|
|
|
|
const auto R2 = ebosResid[cell_idx][contiSolventEqIdx];
|
|
|
|
R_sum[contiSolventEqIdx] += R2;
|
|
|
|
maxCoeff[contiSolventEqIdx] = std::max(maxCoeff[contiSolventEqIdx],
|
|
|
|
std::abs(R2) / pvValue);
|
|
|
|
}
|
|
|
|
if constexpr (has_extbo_) {
|
|
|
|
B_avg[contiZfracEqIdx] += 1.0 / fs.invB(FluidSystem::gasPhaseIdx).value();
|
|
|
|
const auto R2 = ebosResid[cell_idx][contiZfracEqIdx];
|
|
|
|
R_sum[ contiZfracEqIdx ] += R2;
|
|
|
|
maxCoeff[contiZfracEqIdx] = std::max(maxCoeff[contiZfracEqIdx],
|
|
|
|
std::abs(R2) / pvValue);
|
|
|
|
}
|
|
|
|
if constexpr (has_polymer_) {
|
|
|
|
B_avg[contiPolymerEqIdx] += 1.0 / fs.invB(FluidSystem::waterPhaseIdx).value();
|
|
|
|
const auto R2 = ebosResid[cell_idx][contiPolymerEqIdx];
|
|
|
|
R_sum[contiPolymerEqIdx] += R2;
|
|
|
|
maxCoeff[contiPolymerEqIdx] = std::max(maxCoeff[contiPolymerEqIdx],
|
|
|
|
std::abs(R2) / pvValue);
|
|
|
|
}
|
|
|
|
if constexpr (has_foam_) {
|
|
|
|
B_avg[ contiFoamEqIdx ] += 1.0 / fs.invB(FluidSystem::gasPhaseIdx).value();
|
|
|
|
const auto R2 = ebosResid[cell_idx][contiFoamEqIdx];
|
|
|
|
R_sum[contiFoamEqIdx] += R2;
|
|
|
|
maxCoeff[contiFoamEqIdx] = std::max(maxCoeff[contiFoamEqIdx],
|
|
|
|
std::abs(R2) / pvValue);
|
|
|
|
}
|
|
|
|
if constexpr (has_brine_) {
|
|
|
|
B_avg[ contiBrineEqIdx ] += 1.0 / fs.invB(FluidSystem::waterPhaseIdx).value();
|
|
|
|
const auto R2 = ebosResid[cell_idx][contiBrineEqIdx];
|
|
|
|
R_sum[contiBrineEqIdx] += R2;
|
|
|
|
maxCoeff[contiBrineEqIdx] = std::max(maxCoeff[contiBrineEqIdx],
|
|
|
|
std::abs(R2) / pvValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if constexpr (has_polymermw_) {
|
|
|
|
static_assert(has_polymer_);
|
|
|
|
|
|
|
|
B_avg[contiPolymerMWEqIdx] += 1.0 / fs.invB(FluidSystem::waterPhaseIdx).value();
|
|
|
|
// the residual of the polymer molecular equation is scaled down by a 100, since molecular weight
|
|
|
|
// can be much bigger than 1, and this equation shares the same tolerance with other mass balance equations
|
|
|
|
// TODO: there should be a more general way to determine the scaling-down coefficient
|
|
|
|
const auto R2 = ebosResid[cell_idx][contiPolymerMWEqIdx] / 100.;
|
|
|
|
R_sum[contiPolymerMWEqIdx] += R2;
|
|
|
|
maxCoeff[contiPolymerMWEqIdx] = std::max(maxCoeff[contiPolymerMWEqIdx],
|
|
|
|
std::abs(R2) / pvValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if constexpr (has_energy_) {
|
|
|
|
B_avg[contiEnergyEqIdx] += 1.0 / (4.182e1); // converting J -> RM3 (entalpy / (cp * deltaK * rho) assuming change of 1e-5K of water
|
|
|
|
const auto R2 = ebosResid[cell_idx][contiEnergyEqIdx];
|
|
|
|
R_sum[contiEnergyEqIdx] += R2;
|
|
|
|
maxCoeff[contiEnergyEqIdx] = std::max(maxCoeff[contiEnergyEqIdx],
|
|
|
|
std::abs(R2) / pvValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if constexpr (has_micp_) {
|
|
|
|
B_avg[contiMicrobialEqIdx] += 1.0 / fs.invB(FluidSystem::waterPhaseIdx).value();
|
|
|
|
const auto R1 = ebosResid[cell_idx][contiMicrobialEqIdx];
|
|
|
|
R_sum[contiMicrobialEqIdx] += R1;
|
|
|
|
maxCoeff[contiMicrobialEqIdx] = std::max(maxCoeff[contiMicrobialEqIdx],
|
|
|
|
std::abs(R1) / pvValue);
|
|
|
|
B_avg[contiOxygenEqIdx] += 1.0 / fs.invB(FluidSystem::waterPhaseIdx).value();
|
|
|
|
const auto R2 = ebosResid[cell_idx][contiOxygenEqIdx];
|
|
|
|
R_sum[contiOxygenEqIdx] += R2;
|
|
|
|
maxCoeff[contiOxygenEqIdx] = std::max(maxCoeff[contiOxygenEqIdx],
|
|
|
|
std::abs(R2) / pvValue);
|
|
|
|
B_avg[contiUreaEqIdx] += 1.0 / fs.invB(FluidSystem::waterPhaseIdx).value();
|
|
|
|
const auto R3 = ebosResid[cell_idx][contiUreaEqIdx];
|
|
|
|
R_sum[contiUreaEqIdx] += R3;
|
|
|
|
maxCoeff[contiUreaEqIdx] = std::max(maxCoeff[contiUreaEqIdx],
|
|
|
|
std::abs(R3) / pvValue);
|
|
|
|
B_avg[contiBiofilmEqIdx] += 1.0 / fs.invB(FluidSystem::waterPhaseIdx).value();
|
|
|
|
const auto R4 = ebosResid[cell_idx][contiBiofilmEqIdx];
|
|
|
|
R_sum[contiBiofilmEqIdx] += R4;
|
|
|
|
maxCoeff[contiBiofilmEqIdx] = std::max(maxCoeff[contiBiofilmEqIdx],
|
|
|
|
std::abs(R4) / pvValue);
|
|
|
|
B_avg[contiCalciteEqIdx] += 1.0 / fs.invB(FluidSystem::waterPhaseIdx).value();
|
|
|
|
const auto R5 = ebosResid[cell_idx][contiCalciteEqIdx];
|
|
|
|
R_sum[contiCalciteEqIdx] += R5;
|
|
|
|
maxCoeff[contiCalciteEqIdx] = std::max(maxCoeff[contiCalciteEqIdx],
|
|
|
|
std::abs(R5) / pvValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-04 08:37:50 -05:00
|
|
|
private:
|
2016-06-06 08:40:06 -05:00
|
|
|
double dpMaxRel() const { return param_.dp_max_rel_; }
|
|
|
|
double dsMax() const { return param_.ds_max_; }
|
|
|
|
double drMaxRel() const { return param_.dr_max_rel_; }
|
|
|
|
double maxResidualAllowed() const { return param_.max_residual_allowed_; }
|
2019-04-04 05:20:30 -05:00
|
|
|
double linear_solve_setup_time_;
|
2023-03-01 06:40:54 -06:00
|
|
|
|
2023-07-03 04:10:32 -05:00
|
|
|
//! \brief Returns subdomain ordered according to method and ordering measure.
|
|
|
|
std::vector<int> getSubdomainOrder()
|
|
|
|
{
|
|
|
|
const auto& solution = ebosSimulator().model().solution(0);
|
|
|
|
|
|
|
|
std::vector<int> domain_order(domains_.size());
|
2023-07-03 06:05:21 -05:00
|
|
|
switch (param_.local_solve_approach_) {
|
|
|
|
case DomainSolveApproach::GaussSeidel: {
|
2023-07-03 05:16:30 -05:00
|
|
|
switch (param_.local_domain_ordering_) {
|
|
|
|
case DomainOrderingMeasure::AveragePressure: {
|
2023-07-03 04:10:32 -05:00
|
|
|
// Use average pressures to order domains.
|
|
|
|
std::vector<std::pair<double, int>> avgpress_per_domain(domains_.size());
|
|
|
|
for (const auto& domain : domains_) {
|
|
|
|
double press_sum = 0.0;
|
|
|
|
for (const int c : domain.cells) {
|
|
|
|
press_sum += solution[c][Indices::pressureSwitchIdx];
|
|
|
|
}
|
|
|
|
const double avgpress = press_sum / domain.cells.size();
|
|
|
|
avgpress_per_domain[domain.index] = std::make_pair(avgpress, domain.index);
|
|
|
|
}
|
|
|
|
// Lexicographical sort by pressure, then index.
|
|
|
|
std::sort(avgpress_per_domain.begin(), avgpress_per_domain.end());
|
|
|
|
// Reverse since we want high-pressure regions solved first.
|
|
|
|
std::reverse(avgpress_per_domain.begin(), avgpress_per_domain.end());
|
|
|
|
for (size_t ii = 0; ii < domains_.size(); ++ii) {
|
|
|
|
domain_order[ii] = avgpress_per_domain[ii].second;
|
|
|
|
}
|
2023-07-03 05:16:30 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DomainOrderingMeasure::Residual: {
|
2023-07-03 04:10:32 -05:00
|
|
|
// Use maximum residual to order domains.
|
|
|
|
const auto& residual = ebosSimulator().model().linearizer().residual();
|
|
|
|
const int num_vars = residual[0].size();
|
|
|
|
std::vector<std::pair<double, int>> maxres_per_domain(domains_.size());
|
|
|
|
for (const auto& domain : domains_) {
|
|
|
|
double maxres = 0.0;
|
|
|
|
for (const int c : domain.cells) {
|
|
|
|
for (int ii = 0; ii < num_vars; ++ii) {
|
|
|
|
maxres = std::max(maxres, std::fabs(residual[c][ii]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
maxres_per_domain[domain.index] = std::make_pair(maxres, domain.index);
|
|
|
|
}
|
|
|
|
// Lexicographical sort by pressure, then index.
|
|
|
|
std::sort(maxres_per_domain.begin(), maxres_per_domain.end());
|
|
|
|
// Reverse since we want high-pressure regions solved first.
|
|
|
|
std::reverse(maxres_per_domain.begin(), maxres_per_domain.end());
|
|
|
|
for (size_t ii = 0; ii < domains_.size(); ++ii) {
|
|
|
|
domain_order[ii] = maxres_per_domain[ii].second;
|
|
|
|
}
|
|
|
|
}
|
2023-07-03 06:05:21 -05:00
|
|
|
break;
|
2023-07-03 05:16:30 -05:00
|
|
|
}
|
2023-07-03 06:05:21 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DomainSolveApproach::Jacobi:
|
|
|
|
default:
|
2023-07-03 04:10:32 -05:00
|
|
|
std::iota(domain_order.begin(), domain_order.end(), 0);
|
2023-07-03 06:05:21 -05:00
|
|
|
break;
|
2023-07-03 04:10:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return domain_order;
|
|
|
|
}
|
|
|
|
|
2023-07-03 05:40:15 -05:00
|
|
|
template<class GlobalEqVector>
|
|
|
|
void solveDomainJacobi(GlobalEqVector& solution,
|
|
|
|
GlobalEqVector& locally_solved,
|
|
|
|
SimulatorReportSingle& local_report,
|
|
|
|
const int iteration,
|
|
|
|
const SimulatorTimerInterface& timer,
|
|
|
|
const Domain& domain)
|
|
|
|
{
|
|
|
|
auto initial_local_well_primary_vars = wellModel().getPrimaryVarsDomain(domain);
|
|
|
|
auto initial_local_solution = Details::extractVector(solution, domain.cells);
|
|
|
|
auto res = solveDomain(domain, timer, iteration);
|
|
|
|
local_report = res.first;
|
|
|
|
if (local_report.converged) {
|
|
|
|
auto local_solution = Details::extractVector(solution, domain.cells);
|
|
|
|
Details::setGlobal(local_solution, domain.cells, locally_solved);
|
|
|
|
Details::setGlobal(initial_local_solution, domain.cells, solution);
|
|
|
|
ebosSimulator_.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0, domain.view);
|
|
|
|
} else {
|
|
|
|
wellModel().setPrimaryVarsDomain(domain, initial_local_well_primary_vars);
|
|
|
|
Details::setGlobal(initial_local_solution, domain.cells, solution);
|
|
|
|
ebosSimulator_.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0, domain.view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 05:40:15 -05:00
|
|
|
template<class GlobalEqVector>
|
|
|
|
void solveDomainGaussSeidel(GlobalEqVector& solution,
|
|
|
|
GlobalEqVector& locally_solved,
|
|
|
|
SimulatorReportSingle& local_report,
|
|
|
|
const int iteration,
|
|
|
|
const SimulatorTimerInterface& timer,
|
|
|
|
const Domain& domain)
|
|
|
|
{
|
|
|
|
auto initial_local_well_primary_vars = wellModel().getPrimaryVarsDomain(domain);
|
|
|
|
auto initial_local_solution = Details::extractVector(solution, domain.cells);
|
|
|
|
auto res = solveDomain(domain, timer, iteration);
|
|
|
|
local_report = res.first;
|
|
|
|
if (!local_report.converged) {
|
|
|
|
// We look at the detailed convergence report to evaluate
|
|
|
|
// if we should accept the unconverged solution.
|
|
|
|
const auto& convrep = res.second;
|
|
|
|
// We do not accept a solution if the wells are unconverged.
|
|
|
|
if (!convrep.wellFailed()) {
|
|
|
|
// Calculare the sums of the mb and cnv failures.
|
|
|
|
double mb_sum = 0.0;
|
|
|
|
double cnv_sum = 0.0;
|
|
|
|
for (const auto& rc : convrep.reservoirConvergence()) {
|
|
|
|
if (rc.type() == ConvergenceReport::ReservoirFailure::Type::MassBalance) {
|
|
|
|
mb_sum += rc.value();
|
|
|
|
} else if (rc.type() == ConvergenceReport::ReservoirFailure::Type::Cnv) {
|
|
|
|
cnv_sum += rc.value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If not too high, we overrule the convergence failure.
|
|
|
|
const double acceptable_local_mb_sum = 1e-3;
|
|
|
|
const double acceptable_local_cnv_sum = 1.0;
|
|
|
|
if (mb_sum < acceptable_local_mb_sum && cnv_sum < acceptable_local_cnv_sum) {
|
|
|
|
local_report.converged = true;
|
|
|
|
OpmLog::debug("Accepting solution in unconverged domain " + std::to_string(domain.index));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (local_report.converged) {
|
|
|
|
auto local_solution = Details::extractVector(solution, domain.cells);
|
|
|
|
Details::setGlobal(local_solution, domain.cells, locally_solved);
|
|
|
|
} else {
|
|
|
|
wellModel().setPrimaryVarsDomain(domain, initial_local_well_primary_vars);
|
|
|
|
Details::setGlobal(initial_local_solution, domain.cells, solution);
|
|
|
|
ebosSimulator_.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0, domain.view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-08 07:58:25 -05:00
|
|
|
public:
|
2017-06-21 09:26:06 -05:00
|
|
|
std::vector<bool> wasSwitched_;
|
2016-06-06 08:40:06 -05:00
|
|
|
};
|
|
|
|
} // namespace Opm
|
|
|
|
|
2018-06-06 03:59:41 -05:00
|
|
|
#endif // OPM_BLACKOILMODELBASE_IMPL_HEADER_INCLUDED
|