diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 5b19ff81c..050b85327 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -70,6 +70,7 @@ if(ENABLE_ECL_INPUT) src/opm/parser/eclipse/EclipseState/Grid/GridProperty.cpp src/opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.cpp src/opm/parser/eclipse/EclipseState/Grid/NNC.cpp + src/opm/parser/eclipse/EclipseState/Grid/Operate.cpp src/opm/parser/eclipse/EclipseState/Grid/PinchMode.cpp src/opm/parser/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.cpp src/opm/parser/eclipse/EclipseState/Grid/setKeywordBox.cpp diff --git a/src/opm/parser/eclipse/EclipseState/Grid/GridProperties.cpp b/src/opm/parser/eclipse/EclipseState/Grid/GridProperties.cpp index 28778ff60..9163bda75 100644 --- a/src/opm/parser/eclipse/EclipseState/Grid/GridProperties.cpp +++ b/src/opm/parser/eclipse/EclipseState/Grid/GridProperties.cpp @@ -26,6 +26,7 @@ #include #include "setKeywordBox.hpp" +#include "Operate.hpp" namespace Opm { @@ -411,91 +412,6 @@ namespace Opm { } } - namespace { - /* - The functions in this namespace are those listed as - available operations in the OPERATE keyword. - */ - - double MULTA(double, double X, double alpha, double beta) { - return alpha*X + beta; - } - - // NB: The POLY function and the MULTIPLY function both use - // the R value in the calculation. That implies that we should - // ideally check that the R property has already been - // initialized with a valid value, For all the other - // operations R only appears on the left side of the equation, - // and can be fully assigned to. - double POLY(double R, double X, double alpha, double beta) { - return R + alpha * std::pow(X , beta ); - } - - double MULTIPLY(double R, double X, double , double ) { - return R * X; - } - - double SLOG(double, double X, double alpha, double beta) { - return pow(10 , alpha + beta * X); - } - - double LOG10(double, double X, double , double ) { - return log10(X); - } - - double LOGE(double, double X, double , double ) { - return log(X); - } - - double INV(double, double X, double , double ) { - return 1.0/X; - } - - double MULTX(double, double X, double alpha, double ) { - return alpha * X; - } - - double ADDX(double, double X, double alpha, double ) { - return alpha + X; - } - - double COPY(double, double X, double, double ) { - return X; - } - - double MAXLIM(double, double X, double alpha, double ) { - return std::min( alpha , X ); - } - - double MINLIM(double, double X, double alpha, double ) { - return std::max( alpha , X ); - } - - double MULTP(double, double X, double alpha, double beta) { - return alpha * pow(X, beta ); - } - - double ABS(double, double X, double, double) { - return std::abs(X); - } - - using operate_fptr = decltype( &MULTA ); - static const std::map operations = {{"MULTA" , &MULTA}, - {"POLY" , &POLY}, - {"SLOG" , &SLOG}, - {"LOG10" , &LOG10}, - {"LOGE" , &LOGE}, - {"INV" , &INV}, - {"MULTX" , &MULTX}, - {"ADDX" , &ADDX}, - {"COPY" , ©}, - {"MAXLIM" , &MAXLIM}, - {"MINLIM" , &MINLIM}, - {"MULTP" , &MULTP}, - {"ABS" , &ABS}, - {"MULTIPLY" , &MULTIPLY}}; - } - template void GridProperties::handleOPERATERecord( const DeckRecord& record, BoxManager& boxManager) { @@ -519,7 +435,7 @@ namespace Opm { std::vector targetData = result_prop.getData(); const std::vector& srcData = getKeyword( srcArray ).getData(); - operate_fptr func = operations.at( operation ); + Operate::function func = Operate::get( operation ); setKeywordBox(record, boxManager); for (auto index : boxManager.getActiveBox().getIndexList()) @@ -552,7 +468,7 @@ namespace Opm { std::vector result_data = result_prop.getData(); const std::vector& parameter_data = getKeyword( parameter_array ).getData(); - operate_fptr func = operations.at( operation ); + Operate::function func = Operate::get(operation); std::vector mask; regionProperty.initMask(region_value, mask); diff --git a/src/opm/parser/eclipse/EclipseState/Grid/Operate.cpp b/src/opm/parser/eclipse/EclipseState/Grid/Operate.cpp new file mode 100644 index 000000000..87ef4df4d --- /dev/null +++ b/src/opm/parser/eclipse/EclipseState/Grid/Operate.cpp @@ -0,0 +1,128 @@ +/* + Copyright 2019 Equinor ASA. + + 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 . +*/ +#include +#include + +#include "Operate.hpp" + +namespace Opm { +namespace Operate { +namespace { + /* + The functions in this namespace are those listed as + available operations in the OPERATE keyword. + */ + + double MULTA(double, double X, double alpha, double beta) + { + return alpha * X + beta; + } + + // NB: The POLY function and the MULTIPLY function both use + // the R value in the calculation. That implies that we should + // ideally check that the R property has already been + // initialized with a valid value, For all the other + // operations R only appears on the left side of the equation, + // and can be fully assigned to. + double POLY(double R, double X, double alpha, double beta) + { + return R + alpha * std::pow(X, beta); + } + + double MULTIPLY(double R, double X, double, double) + { + return R * X; + } + + double SLOG(double, double X, double alpha, double beta) + { + return pow(10, alpha + beta * X); + } + + double LOG10(double, double X, double, double) + { + return log10(X); + } + + double LOGE(double, double X, double, double) + { + return log(X); + } + + double INV(double, double X, double, double) + { + return 1.0 / X; + } + + double MULTX(double, double X, double alpha, double) + { + return alpha * X; + } + + double ADDX(double, double X, double alpha, double) + { + return alpha + X; + } + + double COPY(double, double X, double, double) + { + return X; + } + + double MAXLIM(double, double X, double alpha, double) + { + return std::min(alpha, X); + } + + double MINLIM(double, double X, double alpha, double) + { + return std::max(alpha, X); + } + + double MULTP(double, double X, double alpha, double beta) + { + return alpha * pow(X, beta); + } + + double ABS(double, double X, double, double) + { + return std::abs(X); + } + + static const std::map operations = {{"MULTA", &MULTA}, + {"POLY", &POLY}, + {"SLOG", &SLOG}, + {"LOG10", &LOG10}, + {"LOGE", &LOGE}, + {"INV", &INV}, + {"MULTX", &MULTX}, + {"ADDX", &ADDX}, + {"COPY", ©}, + {"MAXLIM", &MAXLIM}, + {"MINLIM", &MINLIM}, + {"MULTP", &MULTP}, + {"ABS", &ABS}, + {"MULTIPLY", &MULTIPLY}}; +} + +function get(const std::string& func) { + return operations.at(func); +} + +} +} diff --git a/src/opm/parser/eclipse/EclipseState/Grid/Operate.hpp b/src/opm/parser/eclipse/EclipseState/Grid/Operate.hpp new file mode 100644 index 000000000..b12bbdcef --- /dev/null +++ b/src/opm/parser/eclipse/EclipseState/Grid/Operate.hpp @@ -0,0 +1,34 @@ +/* + Copyright 2019 Equinor ASA. + + 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 . +*/ +#ifndef OPERATE_HPP +#define OPERATE_HPP + +#include + + +namespace Opm { +namespace Operate { + +//using operate_fptr = decltype(&MULTA); +using function = std::function; + +function get(const std::string& function); + +} +} +#endif