mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
changed: split VFP classes in base (ebos) and legacy
to get rid of eigen usage in ebos based classes
This commit is contained in:
@@ -22,9 +22,10 @@
|
||||
#define OPM_AUTODIFF_VFPHELPERS_HPP_
|
||||
|
||||
|
||||
#include <cmath>
|
||||
#include <opm/common/ErrorMacros.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/VFPInjTable.hpp>
|
||||
#include <opm/autodiff/AutoDiffHelpers.hpp>
|
||||
#include <opm/material/densead/Math.hpp>
|
||||
#include <opm/material/densead/Evaluation.hpp>
|
||||
|
||||
@@ -35,9 +36,6 @@ namespace Opm {
|
||||
namespace detail {
|
||||
|
||||
|
||||
typedef AutoDiffBlock<double> ADB;
|
||||
|
||||
|
||||
/**
|
||||
* Returns zero if input value is NaN
|
||||
*/
|
||||
@@ -45,6 +43,7 @@ inline double zeroIfNan(const double& value) {
|
||||
return (std::isnan(value)) ? 0.0 : value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns zero if input value is NaN
|
||||
*/
|
||||
@@ -54,24 +53,6 @@ inline EvalWell zeroIfNan(const EvalWell& value) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns zero for every entry in the ADB which is NaN
|
||||
*/
|
||||
inline ADB zeroIfNan(const ADB& values) {
|
||||
Selector<ADB::V::Scalar> not_nan_selector(values.value(), Selector<ADB::V::Scalar>::NotNaN);
|
||||
|
||||
const ADB::V z = ADB::V::Zero(values.size());
|
||||
const ADB zero = ADB::constant(z, values.blockPattern());
|
||||
|
||||
ADB retval = not_nan_selector.select(values, zero);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Computes the flo parameter according to the flo_type_
|
||||
* for production tables
|
||||
@@ -564,77 +545,6 @@ const T* getTable(const std::map<int, T*> tables, int table_id) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets block_pattern to be the "union of x.blockPattern() and block_pattern".
|
||||
*/
|
||||
inline void extendBlockPattern(const ADB& x, std::vector<int>& block_pattern) {
|
||||
std::vector<int> x_block_pattern = x.blockPattern();
|
||||
|
||||
if (x_block_pattern.empty()) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (block_pattern.empty()) {
|
||||
block_pattern = x_block_pattern;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (x_block_pattern != block_pattern) {
|
||||
OPM_THROW(std::logic_error, "Block patterns do not match");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the common block pattern for all inputs
|
||||
*/
|
||||
inline std::vector<int> commonBlockPattern(
|
||||
const ADB& x1,
|
||||
const ADB& x2,
|
||||
const ADB& x3,
|
||||
const ADB& x4) {
|
||||
std::vector<int> block_pattern;
|
||||
|
||||
extendBlockPattern(x1, block_pattern);
|
||||
extendBlockPattern(x2, block_pattern);
|
||||
extendBlockPattern(x3, block_pattern);
|
||||
extendBlockPattern(x4, block_pattern);
|
||||
|
||||
return block_pattern;
|
||||
}
|
||||
|
||||
inline std::vector<int> commonBlockPattern(
|
||||
const ADB& x1,
|
||||
const ADB& x2,
|
||||
const ADB& x3,
|
||||
const ADB& x4,
|
||||
const ADB& x5) {
|
||||
std::vector<int> block_pattern = commonBlockPattern(x1, x2, x3, x4);
|
||||
extendBlockPattern(x5, block_pattern);
|
||||
|
||||
return block_pattern;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the type variable for FLO/GFR/WFR for production tables
|
||||
*/
|
||||
@@ -670,125 +580,6 @@ VFPInjTable::FLO_TYPE getType(const VFPInjTable* table) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the actual ADB for the type of FLO/GFR/WFR type
|
||||
*/
|
||||
template <typename TYPE>
|
||||
ADB getValue(
|
||||
const ADB& aqua,
|
||||
const ADB& liquid,
|
||||
const ADB& vapour, TYPE type);
|
||||
|
||||
template <>
|
||||
inline
|
||||
ADB getValue(
|
||||
const ADB& aqua,
|
||||
const ADB& liquid,
|
||||
const ADB& vapour,
|
||||
VFPProdTable::FLO_TYPE type) {
|
||||
return detail::getFlo(aqua, liquid, vapour, type);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline
|
||||
ADB getValue(
|
||||
const ADB& aqua,
|
||||
const ADB& liquid,
|
||||
const ADB& vapour,
|
||||
VFPProdTable::WFR_TYPE type) {
|
||||
return detail::getWFR(aqua, liquid, vapour, type);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline
|
||||
ADB getValue(
|
||||
const ADB& aqua,
|
||||
const ADB& liquid,
|
||||
const ADB& vapour,
|
||||
VFPProdTable::GFR_TYPE type) {
|
||||
return detail::getGFR(aqua, liquid, vapour, type);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline
|
||||
ADB getValue(
|
||||
const ADB& aqua,
|
||||
const ADB& liquid,
|
||||
const ADB& vapour,
|
||||
VFPInjTable::FLO_TYPE type) {
|
||||
return detail::getFlo(aqua, liquid, vapour, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given m wells and n types of VFP variables (e.g., FLO = {FLO_OIL, FLO_LIQ}
|
||||
* this function combines the n types of ADB objects, so that each of the
|
||||
* m wells gets the right ADB.
|
||||
* @param TYPE Type of variable to return, e.g., FLO_TYPE, WFR_TYPE, GFR_TYPE
|
||||
* @param TABLE Type of table to use, e.g., VFPInjTable, VFPProdTable.
|
||||
*/
|
||||
template <typename TYPE, typename TABLE>
|
||||
ADB combineADBVars(const std::vector<const TABLE*>& well_tables,
|
||||
const ADB& aqua,
|
||||
const ADB& liquid,
|
||||
const ADB& vapour) {
|
||||
|
||||
const int num_wells = static_cast<int>(well_tables.size());
|
||||
assert(aqua.size() == num_wells);
|
||||
assert(liquid.size() == num_wells);
|
||||
assert(vapour.size() == num_wells);
|
||||
|
||||
//Caching variable for flo/wfr/gfr
|
||||
std::map<TYPE, ADB> map;
|
||||
|
||||
//Indexing variable used when combining the different ADB types
|
||||
std::map<TYPE, std::vector<int> > elems;
|
||||
|
||||
//Compute all of the different ADB types,
|
||||
//and record which wells use which types
|
||||
for (int i=0; i<num_wells; ++i) {
|
||||
const TABLE* table = well_tables[i];
|
||||
|
||||
//Only do something if this well is under THP control
|
||||
if (table != NULL) {
|
||||
TYPE type = getType<TYPE>(table);
|
||||
|
||||
//"Caching" of flo_type etc: Only calculate used types
|
||||
//Create type if it does not exist
|
||||
if (map.find(type) == map.end()) {
|
||||
map.insert(std::pair<TYPE, ADB>(
|
||||
type,
|
||||
detail::getValue<TYPE>(aqua, liquid, vapour, type)
|
||||
));
|
||||
}
|
||||
|
||||
//Add the index for assembly later in gather_vars
|
||||
elems[type].push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
//Loop over all types of ADB variables, and combine them
|
||||
//so that each well gets the proper variable
|
||||
ADB retval = ADB::constant(ADB::V::Zero(num_wells));
|
||||
for (const auto& entry : elems) {
|
||||
const auto& key = entry.first;
|
||||
const auto& value = entry.second;
|
||||
|
||||
//Get the ADB for this type of variable
|
||||
assert(map.find(key) != map.end());
|
||||
const ADB& values = map.find(key)->second;
|
||||
|
||||
//Get indices to all elements that should use this ADB
|
||||
const std::vector<int>& current = value;
|
||||
|
||||
//Add these elements to retval
|
||||
retval = retval + superset(subset(values, current), current, values.size());
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that finds x for a given value of y for a line
|
||||
* *NOTE ORDER OF ARGUMENTS*
|
||||
|
||||
Reference in New Issue
Block a user