janitoring: fix some formatting in HybridNewton

This commit is contained in:
Arne Morten Kvarving committed 2025-10-15 09:53:15 +02:00
1 parent 6a6bb8c762
commit dffa39e8ba
2 files changed
+38 -29

No files matched your search

+20 -20
View File
@@ -147,7 +147,6 @@ private:
}
protected:
void validateFluidSystem()
{
const auto& eclState = simulator_.vanguard().eclState();
@@ -230,9 +229,8 @@ protected:
* \param config HybridNewtonConfig containing feature definitions and cell indices.
* \return A 1D tensor of Evaluation values with the computed layout.
*/
ML::Tensor<Evaluation> constructInputTensor(
const HybridNewtonConfig& config
)
ML::Tensor<Evaluation>
constructInputTensor(const HybridNewtonConfig& config)
{
const auto& features = config.input_features;
@@ -374,7 +372,8 @@ protected:
* output tensor does not match the expected feature layout.
*/
ML::Tensor<Evaluation>
constructOutputTensor(const ML::Tensor<Evaluation>& input, const HybridNewtonConfig& config)
constructOutputTensor(const ML::Tensor<Evaluation>& input,
const HybridNewtonConfig& config)
{
const auto& features = config.output_features;
const int n_features = features.size();
@@ -415,10 +414,8 @@ protected:
* \throws std::runtime_error if an unknown output feature is encountered
* or if state consistency cannot be enforced.
*/
void updateInitialGuess(
ML::Tensor<Evaluation>& output,
const HybridNewtonConfig& config
)
void updateInitialGuess(ML::Tensor<Evaluation>& output,
const HybridNewtonConfig& config)
{
const auto& features = config.output_features;
@@ -492,7 +489,9 @@ protected:
++feature_idx;
}
int sat_count = static_cast<int>(flags.has_SWAT) + static_cast<int>(flags.has_SOIL) + static_cast<int>(flags.has_SGAS);
int sat_count = static_cast<int>(flags.has_SWAT) +
static_cast<int>(flags.has_SOIL) +
static_cast<int>(flags.has_SGAS);
if (sat_count >= 2) {
Scalar sw = sw_val;
@@ -543,11 +542,12 @@ protected:
simulator_.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx*/0);
}
struct FeatureFlags {
bool has_SWAT = false;
bool has_SOIL = false;
bool has_SGAS = false;
bool has_PRESSURE = false;
struct FeatureFlags
{
bool has_SWAT = false;
bool has_SOIL = false;
bool has_SGAS = false;
bool has_PRESSURE = false;
};
FeatureFlags flagFeatures(const std::vector<std::pair<std::string, FeatureSpec>>& features)
@@ -570,11 +570,11 @@ protected:
return flags;
}
protected:
Simulator& simulator_;
std::vector<HybridNewtonConfig> configs_;
bool configsLoaded_;
};
protected:
Simulator& simulator_;
std::vector<HybridNewtonConfig> configs_;
bool configsLoaded_;
};
} // namespace Opm
+18 -9
View File
@@ -38,14 +38,16 @@ namespace Opm {
*
* Supports standard (mean/std) and min-max scaling.
*/
struct Scaler {
struct Scaler
{
enum class Type { None, Standard, MinMax } type = Type::None;
double mean = 0.0;
double std = 1.0;
double min = 0.0;
double max = 1.0;
double scale(double raw_value) const {
double scale(double raw_value) const
{
switch (type) {
case Type::Standard:
return (std == 0.0) ? mean : (raw_value - mean) / std;
@@ -59,7 +61,8 @@ struct Scaler {
}
}
double unscale(double scaled_value) const {
double unscale(double scaled_value) const
{
switch (type) {
case Type::Standard: return scaled_value * std + mean;
case Type::MinMax: return scaled_value * (max - min) + min;
@@ -75,18 +78,21 @@ struct Scaler {
* Supports log, log10, log1p, and no transform. Provides forward
* and inverse methods.
*/
struct Transform {
struct Transform
{
enum class Type { None, Log, Log10, Log1p } type = Type::None;
Transform() = default;
explicit Transform(const std::string& name) {
explicit Transform(const std::string& name)
{
if (name == "log10") type = Type::Log10;
else if (name == "log") type = Type::Log;
else if (name == "log1p") type = Type::Log1p;
else type = Type::None;
}
double apply(double raw_value) const {
double apply(double raw_value) const
{
switch (type) {
case Type::Log10: return std::log10(raw_value);
case Type::Log: return std::log(raw_value);
@@ -96,7 +102,8 @@ struct Transform {
}
}
double applyInverse(double transformed_value) const {
double applyInverse(double transformed_value) const
{
switch (type) {
case Type::Log10: return std::pow(10.0, transformed_value);
case Type::Log: return std::exp(transformed_value);
@@ -112,7 +119,8 @@ struct Transform {
*
* Includes transformation, scaling, delta flag, and actual feature name.
*/
struct FeatureSpec {
struct FeatureSpec
{
Transform transform;
Scaler scaler;
bool is_delta = false;
@@ -127,7 +135,8 @@ struct FeatureSpec {
* Encapsulates model path, cell indices, apply times, input/output
* features, and validation. Can be constructed from a PropertyTree.
*/
class HybridNewtonConfig {
class HybridNewtonConfig
{
public:
std::string model_path;
std::string cell_indices_file;