VFPInjProperties: template Scalar type

This commit is contained in:
Arne Morten Kvarving 2024-02-19 14:00:51 +01:00
parent 8a4e78e7c4
commit 099322b0f0
3 changed files with 66 additions and 57 deletions

View File

@ -17,45 +17,47 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <opm/simulators/wells/VFPInjProperties.hpp>
#include <opm/input/eclipse/Schedule/VFPInjTable.hpp>
#include <opm/material/densead/Math.hpp>
#include <opm/material/densead/Evaluation.hpp>
#include <opm/input/eclipse/Schedule/VFPInjTable.hpp>
#include <opm/simulators/wells/VFPHelpers.hpp>
#include <limits>
namespace Opm {
double VFPInjProperties::bhp(int table_id,
const double& aqua,
const double& liquid,
const double& vapour,
const double& thp_arg) const {
template<class Scalar>
Scalar VFPInjProperties<Scalar>::
bhp(const int table_id,
const Scalar aqua,
const Scalar liquid,
const Scalar vapour,
const Scalar thp_arg) const
{
const VFPInjTable& table = detail::getTable(m_tables, table_id);
detail::VFPEvaluation retval = detail::bhp(table, aqua, liquid, vapour, thp_arg);
return retval.value;
}
double VFPInjProperties::thp(int table_id,
const double& aqua,
const double& liquid,
const double& vapour,
const double& bhp_arg) const {
template<class Scalar>
Scalar VFPInjProperties<Scalar>::
thp(const int table_id,
const Scalar aqua,
const Scalar liquid,
const Scalar vapour,
const Scalar bhp_arg) const
{
const VFPInjTable& table = detail::getTable(m_tables, table_id);
//Find interpolation variables
const double flo = detail::getFlo(table, aqua, liquid, vapour);
if (std::abs(flo) < std::numeric_limits<double>::epsilon()) {
const Scalar flo = detail::getFlo(table, aqua, liquid, vapour);
if (std::abs(flo) < std::numeric_limits<Scalar>::epsilon()) {
return 0.;
}
@ -68,34 +70,41 @@ double VFPInjProperties::thp(int table_id,
* expensive, but let us assome that nthp is small
*/
auto flo_i = detail::findInterpData(flo, table.getFloAxis());
std::vector<double> bhp_array(nthp);
for (int i=0; i<nthp; ++i) {
std::vector<Scalar> bhp_array(nthp);
for (int i = 0; i < nthp; ++i) {
auto thp_i = detail::findInterpData(thp_array[i], thp_array);
bhp_array[i] = detail::interpolate(table, flo_i, thp_i).value;
}
double retval = detail::findTHP(bhp_array, thp_array, bhp_arg);
return retval;
return detail::findTHP(bhp_array, thp_array, bhp_arg);
}
const VFPInjTable& VFPInjProperties::getTable(const int table_id) const {
template<class Scalar>
const VFPInjTable&
VFPInjProperties<Scalar>::getTable(const int table_id) const
{
return detail::getTable(m_tables, table_id);
}
bool VFPInjProperties::hasTable(const int table_id) const {
template<class Scalar>
bool VFPInjProperties<Scalar>::hasTable(const int table_id) const
{
return detail::hasTable(m_tables, table_id);
}
void VFPInjProperties::addTable(const VFPInjTable& new_table) {
template<class Scalar>
void VFPInjProperties<Scalar>::addTable(const VFPInjTable& new_table)
{
this->m_tables.emplace( new_table.getTableNum(), new_table );
}
template<class Scalar>
template <class EvalWell>
EvalWell VFPInjProperties::bhp(const int table_id,
const EvalWell& aqua,
const EvalWell& liquid,
const EvalWell& vapour,
const double& thp) const
EvalWell VFPInjProperties<Scalar>::bhp(const int table_id,
const EvalWell& aqua,
const EvalWell& liquid,
const EvalWell& vapour,
const Scalar thp) const
{
//Get the table
const VFPInjTable& table = detail::getTable(m_tables, table_id);
@ -116,12 +125,14 @@ EvalWell VFPInjProperties::bhp(const int table_id,
return bhp;
}
template class VFPInjProperties<double>;
#define INSTANCE(...) \
template __VA_ARGS__ VFPInjProperties::bhp<__VA_ARGS__>(const int, \
const __VA_ARGS__&, \
const __VA_ARGS__&, \
const __VA_ARGS__&, \
const double&) const;
template __VA_ARGS__ VFPInjProperties<double>::bhp<__VA_ARGS__>(const int, \
const __VA_ARGS__&, \
const __VA_ARGS__&, \
const __VA_ARGS__&, \
const double) const;
INSTANCE(DenseAd::Evaluation<double, -1, 4u>)
INSTANCE(DenseAd::Evaluation<double, -1, 5u>)
@ -139,4 +150,5 @@ INSTANCE(DenseAd::Evaluation<double, 7, 0u>)
INSTANCE(DenseAd::Evaluation<double, 8, 0u>)
INSTANCE(DenseAd::Evaluation<double, 9, 0u>)
INSTANCE(DenseAd::Evaluation<double, 10, 0u>)
} //Namespace Opm

View File

@ -30,9 +30,9 @@ namespace Opm {
class VFPInjTable;
template<class Scalar>
class VFPInjProperties {
public:
VFPInjProperties() = default;
/**
* Takes *no* ownership of data.
*/
@ -55,11 +55,11 @@ public:
* input ADB objects.
*/
template <class EvalWell>
EvalWell bhp(const int table_id,
EvalWell bhp(const int table_id,
const EvalWell& aqua,
const EvalWell& liquid,
const EvalWell& vapour,
const double& thp) const;
const Scalar thp) const;
/**
* Returns the table associated with the ID, or throws an exception if
@ -75,7 +75,8 @@ public:
/**
* Returns true if no vfp tables are in the current map
*/
bool empty() const {
bool empty() const
{
return m_tables.empty();
}
@ -90,11 +91,11 @@ public:
* @return The bottom hole pressure, interpolated/extrapolated linearly using
* the above parameters from the values in the input table.
*/
double bhp(int table_id,
const double& aqua,
const double& liquid,
const double& vapour,
const double& thp) const;
Scalar bhp(const int table_id,
const Scalar aqua,
const Scalar liquid,
const Scalar vapour,
const Scalar thp) const;
/**
* Linear interpolation of thp as a function of the input parameters
@ -107,19 +108,17 @@ public:
* @return The tubing hole pressure, interpolated/extrapolated linearly using
* the above parameters from the values in the input table.
*/
double thp(int table_id,
const double& aqua,
const double& liquid,
const double& vapour,
const double& bhp) const;
Scalar thp(const int table_id,
const Scalar aqua,
const Scalar liquid,
const Scalar vapour,
const Scalar bhp) const;
protected:
// Map which connects the table number with the table itself
std::map<int, std::reference_wrapper<const VFPInjTable>> m_tables;
};
} //namespace

View File

@ -26,7 +26,6 @@
#include <opm/simulators/wells/VFPHelpers.hpp>
#include <cstddef>
#include <map>
namespace Opm {
@ -61,7 +60,8 @@ public:
/**
* Returns the VFP properties for injection wells
*/
const VFPInjProperties* getInj() const {
const VFPInjProperties<double>* getInj() const
{
return &m_inj;
}
@ -93,13 +93,11 @@ public:
}
private:
VFPInjProperties m_inj;
VFPInjProperties<double> m_inj;
VFPProdProperties m_prod;
const WellState<double>& well_state_;
};
} //Namespace
} // namespace Opm
#endif /* OPM_AUTODIFF_VFPPROPERTIES_HPP_ */