Extracted OPERATE function to separate file

This commit is contained in:
Joakim Hove
2019-10-23 07:24:07 +02:00
parent cadadbde4d
commit ccb3ddced9
4 changed files with 166 additions and 87 deletions

View File

@@ -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

View File

@@ -26,6 +26,7 @@
#include <opm/parser/eclipse/Utility/String.hpp>
#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<std::string , operate_fptr> operations = {{"MULTA" , &MULTA},
{"POLY" , &POLY},
{"SLOG" , &SLOG},
{"LOG10" , &LOG10},
{"LOGE" , &LOGE},
{"INV" , &INV},
{"MULTX" , &MULTX},
{"ADDX" , &ADDX},
{"COPY" , &COPY},
{"MAXLIM" , &MAXLIM},
{"MINLIM" , &MINLIM},
{"MULTP" , &MULTP},
{"ABS" , &ABS},
{"MULTIPLY" , &MULTIPLY}};
}
template <typename T>
void GridProperties<T>::handleOPERATERecord( const DeckRecord& record, BoxManager& boxManager) {
@@ -519,7 +435,7 @@ namespace Opm {
std::vector<T> targetData = result_prop.getData();
const std::vector<T>& 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<T> result_data = result_prop.getData();
const std::vector<T>& parameter_data = getKeyword( parameter_array ).getData();
operate_fptr func = operations.at( operation );
Operate::function func = Operate::get(operation);
std::vector<bool> mask;
regionProperty.initMask(region_value, mask);

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include <cmath>
#include <map>
#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<std::string, function> operations = {{"MULTA", &MULTA},
{"POLY", &POLY},
{"SLOG", &SLOG},
{"LOG10", &LOG10},
{"LOGE", &LOGE},
{"INV", &INV},
{"MULTX", &MULTX},
{"ADDX", &ADDX},
{"COPY", &COPY},
{"MAXLIM", &MAXLIM},
{"MINLIM", &MINLIM},
{"MULTP", &MULTP},
{"ABS", &ABS},
{"MULTIPLY", &MULTIPLY}};
}
function get(const std::string& func) {
return operations.at(func);
}
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef OPERATE_HPP
#define OPERATE_HPP
#include <functional>
namespace Opm {
namespace Operate {
//using operate_fptr = decltype(&MULTA);
using function = std::function<double(double,double,double,double)>;
function get(const std::string& function);
}
}
#endif