|
opm-simulators
|
Hybrid Newton solver extension for the black-oil model. More...
#include <HybridNewton.hpp>
Classes | |
| struct | FeatureFlags |
Public Member Functions | |
| BlackOilHybridNewton (Simulator &simulator) | |
| void | tryApplyHybridNewton () |
| Attempt to apply the Hybrid Newton correction at the current timestep. | |
Protected Types | |
| enum | { numPhases = FluidSystem::numPhases } |
| enum | { gasPhaseIdx = FluidSystem::gasPhaseIdx } |
| enum | { oilPhaseIdx = FluidSystem::oilPhaseIdx } |
| enum | { waterPhaseIdx = FluidSystem::waterPhaseIdx } |
| using | Simulator = GetPropType<TypeTag, Properties::Simulator> |
| using | Evaluation = GetPropType<TypeTag, Properties::Evaluation> |
| using | FluidSystem = GetPropType<TypeTag, Properties::FluidSystem> |
| using | MaterialLaw = GetPropType<TypeTag, Properties::MaterialLaw> |
| using | Indices = GetPropType<TypeTag, Properties::Indices> |
| using | Scalar = GetPropType<TypeTag, Properties::Scalar> |
Protected Member Functions | |
| void | validateFluidSystem () |
| bool | shouldApplyHybridNewton (Scalar current_time, const HybridNewtonConfig &config) const |
| Check whether the Hybrid Newton method should be applied at the given time. | |
| ML::Tensor< Evaluation > | constructInputTensor (const HybridNewtonConfig &config) |
| Construct the input feature tensor for the Hybrid Newton model. | |
| Scalar | getScalarFeatureValue (const FeatureSpec &spec) |
| Retrieve and transform a scalar feature (global across the domain). | |
| Scalar | getPerCellFeatureValue (const FeatureSpec &spec, int cell_index) |
| Retrieve and transform a per-cell feature value. | |
| ML::Tensor< Evaluation > | constructOutputTensor (const ML::Tensor< Evaluation > &input, const HybridNewtonConfig &config) |
| Run the Hybrid Newton model to produce output predictions. | |
| void | updateInitialGuess (ML::Tensor< Evaluation > &output, const HybridNewtonConfig &config) |
| Update the nonlinear solver's initial guess using ML predictions. | |
| FeatureFlags | flagFeatures (const std::vector< std::pair< std::string, FeatureSpec > > &features) |
Protected Attributes | |
| Simulator & | simulator_ |
| std::vector< HybridNewtonConfig > | configs_ |
| bool | configsLoaded_ |
Static Protected Attributes | |
| static constexpr bool | compositionSwitchEnabled = Indices::compositionSwitchIdx >= 0 |
Hybrid Newton solver extension for the black-oil model.
This class integrates machine learning–based corrections into the standard Newton solver of the black-oil simulator. It uses one or more trained Hybrid Newton models to adjust the initial guess of the nonlinear solver at specific timesteps.
Each model is described by a HybridNewtonConfig, which specifies:
At runtime, the class:
|
inlineprotected |
Construct the input feature tensor for the Hybrid Newton model.
The tensor is constructed in the exact order specified by config.input_features:
Example: Suppose config.input_features = [SGAS, TIMESTEP, PRESSURE] and config.n_cells = 3. The resulting tensor layout is:
[ SGAS(cell0), SGAS(cell1), SGAS(cell2), TIMESTEP, PRESSURE(cell0), PRESSURE(cell1), PRESSURE(cell2) ]
Thus, the tensor length equals:
(# of scalar features) + (# of per-cell features × n_cells).
| config | HybridNewtonConfig containing feature definitions and cell indices. |
|
inlineprotected |
Run the Hybrid Newton model to produce output predictions.
Uses the input tensor (prepared by constructInputTensor) together with the model specified in config to compute the corresponding output tensor. Scaling and transformations defined in the configuration are applied automatically.
| input | The input tensor of shape [(# of scalar features) + (# of per-cell features × n_cells)]. |
| config | The HybridNewtonConfig specifying model path and output feature definitions. |
| std::runtime_error | if model inference fails or if the output tensor does not match the expected feature layout. |
|
inlineprotected |
Retrieve and transform a per-cell feature value.
Supported per-cell features include:
The raw value is taken from the simulator state, converted into the configured unit system, then passed through the feature's transformation and scaling functions.
| spec | The feature specification, including transform and scaling. |
| cell_index | The cell index for which to retrieve the value. |
| std::runtime_error | if the feature is unknown. |
|
inlineprotected |
Retrieve and transform a scalar feature (global across the domain).
Supported scalar feature:
The raw value is passed through the feature's transformation and scaling functions before being returned.
| spec | The feature specification, including transform and scaling. |
| std::runtime_error | if the feature is unknown. |
|
inlineprotected |
Check whether the Hybrid Newton method should be applied at the given time.
This function evaluates the current simulation time against the application times specified in the HybridNewtonConfig. The behavior depends on how many entries are provided in config.apply_times:
| current_time | The current simulation time. |
| config | The HybridNewtonConfig specifying when the Hybrid Newton method should be applied. |
current_time, false otherwise.
|
inline |
Attempt to apply the Hybrid Newton correction at the current timestep.
This function acts as the entry point for Hybrid Newton corrections. It first checks whether the Hybrid Newton mechanism is enabled (via Parameters::UseHybridNewton). If enabled, it validates the fluid system and loads model configurations from the parameter-specified configuration file (if not already loaded).
At each timestep, it iterates over all loaded configurations and applies those that match the current simulation time.
Typical call site: at the beginning of a nonlinear solve for each timestep.
| std::runtime_error | if configuration validation fails or if an invalid fluid system is encountered. |
|
inlineprotected |
Update the nonlinear solver's initial guess using ML predictions.
For each target cell, this function:
Special handling:
| output | The ML output tensor [n_cells x n_output_features]. |
| config | The model configuration specifying output feature mappings. |
| std::runtime_error | if an unknown output feature is encountered or if state consistency cannot be enforced. |