Skip to content

Commit 22cff7c

Browse files
authored
Merge pull request #7393 from GitPaean/comp_tidy
Tidy compositional flash diagnostics
2 parents 9992092 + 322186d commit 22cff7c

4 files changed

Lines changed: 49 additions & 30 deletions

File tree

opm/models/ptflash/flashintensivequantities.hh

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <dune/common/fmatrix.hh>
3232
#include <dune/common/fvector.hh>
3333

34+
#include <opm/common/OpmLog/OpmLog.hpp>
35+
3436
#include <opm/material/Constants.hpp>
3537
#include <opm/material/common/Valgrind.hpp>
3638
#include <opm/material/fluidstates/CompositionalFluidState.hpp>
@@ -43,8 +45,10 @@
4345
#include <opm/models/ptflash/flashindices.hh>
4446
#include <opm/models/ptflash/flashparameters.hh>
4547

48+
#include <fmt/format.h>
49+
4650
#include <array>
47-
#include <iostream>
51+
#include <iterator>
4852
#include <string>
4953

5054
namespace Opm {
@@ -189,31 +193,26 @@ public:
189193
// Compute the phase compositions and densities
190194
/////////////
191195
if (flashVerbosity >= 1) {
192-
const int spatialIdx = elemCtx.globalSpaceIndex(dofIdx, timeIdx);
193-
std::cout << " updating the intensive quantities for Cell " << spatialIdx << std::endl;
196+
OpmLog::debug(fmt::format("Updating the intensive quantities for cell {}",
197+
elemCtx.globalSpaceIndex(dofIdx, timeIdx)));
194198
}
195199
const auto& eos_type = problem.getEosType();
196200
FlashSolver::solve(fluidState_, flashTwoPhaseMethod, flashTolerance, eos_type, flashVerbosity);
197201

198202
if (flashVerbosity >= 5) {
199-
// printing of flash result after solve
200-
const int spatialIdx = elemCtx.globalSpaceIndex(dofIdx, timeIdx);
201-
std::cout << " \n After flash solve for cell " << spatialIdx << std::endl;
202-
ComponentVector x, y;
203-
for (unsigned comp_idx = 0; comp_idx < numComponents; ++comp_idx) {
204-
x[comp_idx] = fluidState_.moleFraction(FluidSystem::oilPhaseIdx, comp_idx);
205-
y[comp_idx] = fluidState_.moleFraction(FluidSystem::gasPhaseIdx, comp_idx);
206-
}
207-
for (unsigned comp_idx = 0; comp_idx < numComponents; ++comp_idx) {
208-
std::cout << " x for component: " << comp_idx << " is:" << std::endl;
209-
std::cout << x[comp_idx] << std::endl;
210-
211-
std::cout << " y for component: " << comp_idx << "is:" << std::endl;
212-
std::cout << y[comp_idx] << std::endl;
203+
std::string phaseCompositions;
204+
for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
205+
fmt::format_to(
206+
std::back_inserter(phaseCompositions),
207+
" component {}: x = {}, y = {}\n",
208+
compIdx,
209+
getValue(fluidState_.moleFraction(FluidSystem::oilPhaseIdx, compIdx)),
210+
getValue(fluidState_.moleFraction(FluidSystem::gasPhaseIdx, compIdx)));
213211
}
214-
const Evaluation& L = fluidState_.L();
215-
std::cout << " L is:" << std::endl;
216-
std::cout << L << std::endl;
212+
OpmLog::debug(fmt::format("After the flash for cell {}: liquid fraction = {}\n{}",
213+
elemCtx.globalSpaceIndex(dofIdx, timeIdx),
214+
getValue(fluidState_.L()),
215+
phaseCompositions));
217216
}
218217

219218
// Update phases
@@ -254,13 +253,16 @@ public:
254253
fluidState_.setCompressFactor(FluidSystem::oilPhaseIdx, Z_L);
255254
fluidState_.setCompressFactor(FluidSystem::gasPhaseIdx, Z_V);
256255

257-
// Print saturation
258256
if (flashVerbosity >= 5) {
259-
std::cout << "So = " << So << std::endl;
260-
std::cout << "Sg = " << Sg << std::endl;
261-
std::cout << "Vm_L = " << Vm_L << std::endl;
262-
std::cout << "Vm_V = " << Vm_V << std::endl;
263-
}
257+
OpmLog::debug(fmt::format("Flash phase properties for cell {}: "
258+
"oil saturation = {}, gas saturation = {}, "
259+
"oil molar volume = {}, gas molar volume = {}",
260+
elemCtx.globalSpaceIndex(dofIdx, timeIdx),
261+
getValue(So),
262+
getValue(Sg),
263+
getValue(Vm_L),
264+
getValue(Vm_V)));
265+
}
264266

265267
/////////////
266268
// Compute rel. perm and viscosity and densities

opm/models/ptflash/flashmodel.hh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,9 @@ public:
233233
Parameters::Register<Parameters::FlashTolerance<Scalar>>
234234
("The maximum tolerance for the flash solver to "
235235
"consider the solution converged");
236-
Parameters::Register<Parameters::FlashVerbosity>
237-
("Flash solver verbosity level");
236+
Parameters::Register<Parameters::FlashVerbosity>(
237+
"Flash solver verbosity level. Messages are written to the debug log and require "
238+
"--debug-verbosity-level to be at least 1");
238239
Parameters::Register<Parameters::FlashTwoPhaseMethod>
239240
("Method for solving vapor-liquid composition. Available options include: "
240241
"ssi, newton, ssi+newton");

opm/simulators/flow/FlowMain.hpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <opm/input/eclipse/EclipseState/IOConfig/IOConfig.hpp>
2727
#include <opm/input/eclipse/EclipseState/InitConfig/InitConfig.hpp>
2828

29+
#include <opm/models/ptflash/flashparameters.hh>
2930
#include <opm/models/utils/start.hh>
3031

3132
#include <opm/simulators/flow/Banners.hpp>
@@ -63,6 +64,21 @@ namespace Opm {
6364

6465
class Deck;
6566

67+
namespace detail
68+
{
69+
70+
inline bool allRanksDebugLoggingEnabled()
71+
{
72+
// FlashVerbosity is only registered by compositional models, so neither
73+
// query may insist on prior registration: IsSet() only looks for a
74+
// user-supplied value, and Get() must read it without the registry.
75+
return Parameters::Get<Parameters::EnableLoggingFalloutWarning>()
76+
|| (Parameters::IsSet<Parameters::FlashVerbosity>(false)
77+
&& (Parameters::Get<Parameters::FlashVerbosity>(false) > 0));
78+
}
79+
80+
} // namespace detail
81+
6682
// The FlowMain class is the standard fully implicit flow simulator.
6783
template <class TypeTag>
6884
class FlowMain
@@ -356,7 +372,7 @@ namespace Opm {
356372

357373
detail::mergeParallelLogFiles(eclState().getIOConfig().getOutputDir(),
358374
Parameters::Get<Parameters::EclDeckFileName>(),
359-
Parameters::Get<Parameters::EnableLoggingFalloutWarning>());
375+
detail::allRanksDebugLoggingEnabled());
360376
}
361377

362378
void setupModelSimulator()

opm/simulators/flow/Main.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class Main
319319
outputDir,
320320
Parameters::Get<Parameters::OutputMode>(),
321321
!Parameters::Get<Parameters::SchedRestart>(),
322-
Parameters::Get<Parameters::EnableLoggingFalloutWarning>(),
322+
detail::allRanksDebugLoggingEnabled(),
323323
Parameters::Get<Parameters::ParsingStrictness>(),
324324
Parameters::Get<Parameters::ActionParsingStrictness>(),
325325
Parameters::Get<Parameters::InputSkipMode>(),

0 commit comments

Comments
 (0)