319 const auto& intQuants = simulator_.model().intensiveQuantities(cell_index, 0);
320 const auto& fs = intQuants.fluidState();
321 const auto& unitSyst = simulator_.vanguard().schedule().getUnits();
325 if (spec.actual_name ==
"PRESSURE") {
326 value = getValue(fs.pressure(oilPhaseIdx));
327 value = unitSyst.from_si(UnitSystem::measure::pressure, value);
328 }
else if (spec.actual_name ==
"SWAT") {
329 value = getValue(fs.saturation(waterPhaseIdx));
330 }
else if (spec.actual_name ==
"SGAS") {
331 value = getValue(fs.saturation(gasPhaseIdx));
332 }
else if (spec.actual_name ==
"SOIL") {
333 value = getValue(fs.saturation(oilPhaseIdx));
334 }
else if (spec.actual_name ==
"RS") {
335 value = getValue(fs.Rs());
336 value = unitSyst.from_si(UnitSystem::measure::gas_oil_ratio, value);
337 }
else if (spec.actual_name ==
"RV") {
338 value = getValue(fs.Rv());
339 value = unitSyst.from_si(UnitSystem::measure::oil_gas_ratio, value);
340 }
else if (spec.actual_name ==
"PERMX") {
341 const auto& eclState = simulator_.vanguard().eclState();
342 const auto& fp = eclState.fieldProps();
343 auto permX = fp.get_double(
"PERMX");
344 value = permX[cell_index];
345 value = unitSyst.from_si(UnitSystem::measure::permeability, value);
347 OPM_THROW(std::runtime_error,
"Unknown per-cell feature: " + spec.actual_name);
350 Scalar transformed = spec.transform.apply(value);
351 Scalar scaled = spec.scaler.scale(transformed);
420 const auto& features = config.output_features;
424 const auto& unitSyst = simulator_.vanguard().schedule().getUnits();
426 for (std::size_t i = 0; i < config.n_cells; ++i) {
427 const int cell_idx = config.cell_indices[i];
428 const auto& intQuants = simulator_.model().intensiveQuantities(cell_idx, 0);
429 auto fs = intQuants.fluidState();
434 Scalar sw_val = -1.0;
435 Scalar so_val = -1.0;
436 Scalar sg_val = -1.0;
437 Scalar po_val = -1.0;
439 for (
const auto& [name, spec] : features) {
441 auto scaled_value = getValue(output(feature_idx * config.n_cells + i));
444 Scalar raw_value = spec.scaler.unscale(scaled_value);
447 raw_value = spec.transform.applyInverse(raw_value);
450 if (spec.actual_name ==
"PRESSURE") {
451 raw_value = raw_value + unitSyst.from_si(UnitSystem::measure::pressure, getValue(fs.pressure(oilPhaseIdx)));
452 }
else if (spec.actual_name ==
"SWAT") {
453 raw_value += getValue(fs.saturation(waterPhaseIdx));
454 }
else if (spec.actual_name ==
"SOIL") {
455 raw_value += getValue(fs.saturation(oilPhaseIdx));
456 }
else if (spec.actual_name ==
"SGAS") {
457 raw_value += getValue(fs.saturation(gasPhaseIdx));
458 }
else if (spec.actual_name ==
"RS") {
459 raw_value = raw_value + unitSyst.from_si(UnitSystem::measure::gas_oil_ratio, getValue(fs.Rs()));
460 }
else if (spec.actual_name ==
"RV") {
461 raw_value = raw_value + unitSyst.from_si(UnitSystem::measure::oil_gas_ratio, getValue(fs.Rv()));
463 OPM_THROW(std::runtime_error,
"Unknown delta feature: " + name);
467 if (spec.actual_name ==
"PRESSURE") {
468 po_val = unitSyst.to_si(UnitSystem::measure::pressure, raw_value);
469 }
else if (spec.actual_name ==
"SWAT") {
471 }
else if (spec.actual_name ==
"SOIL") {
473 }
else if (spec.actual_name ==
"SGAS") {
475 }
else if (spec.actual_name ==
"RS") {
476 if constexpr (compositionSwitchEnabled) {
477 raw_value = unitSyst.to_si(UnitSystem::measure::gas_oil_ratio, raw_value);
480 }
else if (spec.actual_name ==
"RV") {
481 if constexpr (compositionSwitchEnabled) {
482 raw_value = unitSyst.to_si(UnitSystem::measure::oil_gas_ratio, raw_value);
486 OPM_THROW(std::runtime_error,
"Unknown output feature: " + name);
492 int sat_count =
static_cast<int>(flags.has_SWAT) +
493 static_cast<int>(flags.has_SOIL) +
494 static_cast<int>(flags.has_SGAS);
496 if (sat_count >= 2) {
501 if (!flags.has_SWAT) {
503 }
else if (!flags.has_SOIL) {
505 }
else if (!flags.has_SGAS) {
509 sw = max(0.0, min(sw, 1.0));
510 so = max(0.0, min(so, 1.0));
511 sg = max(0.0, min(sg, 1.0));
513 Scalar sum = sw + so + sg;
515 OPM_THROW(std::runtime_error,
"Saturation sum is zero in cell " + std::to_string(cell_idx));
518 fs.setSaturation(waterPhaseIdx, sw / sum);
519 fs.setSaturation(oilPhaseIdx, so / sum);
520 fs.setSaturation(gasPhaseIdx, sg / sum);
523 if (flags.has_PRESSURE) {
524 std::array<Evaluation, numPhases> pC;
525 const auto& materialParams = simulator_.problem().materialLawParams(cell_idx);
526 MaterialLaw::capillaryPressures(pC, materialParams, fs);
528 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
529 if (!FluidSystem::phaseIsActive(phaseIdx))
continue;
530 if (phaseIdx == oilPhaseIdx) {
531 fs.setPressure(phaseIdx, po_val);
533 fs.setPressure(phaseIdx, po_val - pC[phaseIdx]);
538 auto& primaryVars = simulator_.model().solution(0)[cell_idx];
539 primaryVars.assignNaive(fs);
542 simulator_.model().invalidateAndUpdateIntensiveQuantities(0);