20#ifndef OPM_OUTPUT_WELLS_HPP
21#define OPM_OUTPUT_WELLS_HPP
25#include <initializer_list>
30#include <unordered_map>
51 enum class opt : uint32_t {
58 dissolved_gas = (1 << 6),
59 vaporized_oil = (1 << 7),
60 reservoir_water = (1 << 8),
61 reservoir_oil = (1 << 9),
62 reservoir_gas = (1 << 10),
63 productivity_index_water = (1 << 11),
64 productivity_index_oil = (1 << 12),
65 productivity_index_gas = (1 << 13),
66 well_potential_water = (1 << 14),
67 well_potential_oil = (1 << 15),
68 well_potential_gas = (1 << 16),
71 using enum_size = std::underlying_type< opt >::type;
74 inline bool has(
opt )
const;
78 inline double get(
opt m )
const;
81 inline double get(
opt m,
double default_value )
const;
90 template <
class MessageBufferType>
92 template <
class MessageBufferType>
98 double& get_ref(
opt );
99 const double& get_ref(
opt )
const;
101 opt mask =
static_cast< opt >( 0 );
106 double polymer = 0.0;
107 double solvent = 0.0;
109 double dissolved_gas = 0.0;
110 double vaporized_oil = 0.0;
111 double reservoir_water = 0.0;
112 double reservoir_oil = 0.0;
113 double reservoir_gas = 0.0;
114 double productivity_index_water = 0.0;
115 double productivity_index_oil = 0.0;
116 double productivity_index_gas = 0.0;
117 double well_potential_water = 0.0;
118 double well_potential_oil = 0.0;
119 double well_potential_gas = 0.0;
147 template <
class MessageBufferType>
149 template <
class MessageBufferType>
156 Pressure, PDrop, PDropHydrostatic, PDropAccel, PDropFriction,
161 return this->values_[this->index(i)];
166 return this->values_[this->index(i)];
171 return this->values_ == segpres2.values_;
174 template <
class MessageBufferType>
177 for (
const auto&
value : this->values_) {
182 template <
class MessageBufferType>
185 for (
auto&
value : this->values_) {
191 constexpr static std::size_t numvals = 5;
193 std::array<double, numvals> values_;
195 std::size_t index(
const Value ix)
const
197 return static_cast<std::size_t
>(ix);
213 template <
class MessageBufferType>
216 template <
class MessageBufferType>
238 template <
class MessageBufferType>
241 template <
class MessageBufferType>
255 inline bool flowing() const noexcept;
256 template <class MessageBufferType>
258 template <class MessageBufferType>
262 const auto connection = std::find_if( this->connections.begin() ,
263 this->connections.end() ,
265 return c.index == connection_grid_index; });
267 if( connection == this->connections.end() )
274 auto connection = std::find_if( this->connections.begin() ,
275 this->connections.end() ,
277 return c.index == connection_grid_index; });
279 if( connection == this->connections.end() )
303 const auto&
well = this->find( well_name );
304 if(
well == this->
end() )
return 0.0;
306 return well->second.rates.get( m, 0.0 );
311 const auto& witr = this->find( well_name );
312 if( witr == this->
end() )
return 0.0;
314 const auto&
well = witr->second;
315 const auto& connection = std::find_if(
well.connections.begin() ,
316 well.connections.end() ,
318 return c.index == connection_grid_index; });
320 if( connection ==
well.connections.end() )
323 return connection->rates.get( m, 0.0 );
326 template <
class MessageBufferType>
328 unsigned int size = this->size();
330 for (
const auto& witr : *
this) {
338 template <
class MessageBufferType>
342 for (
size_t i = 0; i < size; ++i) {
358 const auto mand =
static_cast< enum_size >( this->mask )
361 return static_cast< opt >( mand ) == m;
365 if( !this->
has( m ) )
366 throw std::invalid_argument(
"Uninitialized value." );
368 return this->get_ref( m );
372 if( !this->
has( m ) )
return default_value;
374 return this->get_ref( m );
378 this->get_ref( m ) =
value;
380 this->mask =
static_cast< opt >(
390 return mask == rate.mask &&
394 polymer == rate.polymer &&
395 solvent == rate.solvent &&
396 energy == rate.energy &&
397 dissolved_gas == rate.dissolved_gas &&
398 vaporized_oil == rate.vaporized_oil &&
399 reservoir_water == rate.reservoir_water &&
400 reservoir_oil == rate.reservoir_oil &&
401 reservoir_gas == rate.reservoir_gas &&
402 productivity_index_water == rate.productivity_index_water &&
403 productivity_index_gas == rate.productivity_index_gas &&
404 productivity_index_oil == rate.productivity_index_oil &&
405 well_potential_water == rate.well_potential_water &&
406 well_potential_oil == rate.well_potential_oil &&
407 well_potential_gas == rate.well_potential_gas;
420 inline const double& Rates::get_ref( opt m )
const {
441 throw std::invalid_argument(
442 "Unknown value type '"
443 + std::to_string(
static_cast< enum_size >( m ) )
448 inline double& Rates::get_ref( opt m ) {
449 return const_cast< double&
>(
450 static_cast< const Rates*
>( this )->get_ref( m )
456 return ((this->wat != 0) ||
465 template <
class MessageBufferType>
471 buffer.write(this->polymer);
472 buffer.write(this->solvent);
473 buffer.write(this->energy);
474 buffer.write(this->dissolved_gas);
475 buffer.write(this->vaporized_oil);
476 buffer.write(this->reservoir_water);
477 buffer.write(this->reservoir_oil);
478 buffer.write(this->reservoir_gas);
479 buffer.write(this->productivity_index_water);
480 buffer.write(this->productivity_index_oil);
481 buffer.write(this->productivity_index_gas);
482 buffer.write(this->well_potential_water);
483 buffer.write(this->well_potential_oil);
484 buffer.write(this->well_potential_gas);
487 template <
class MessageBufferType>
499 template <
class MessageBufferType>
506 template <
class MessageBufferType>
511 buffer.write(this->
prod);
514 buffer.write(this->
inj);
518 template <
class MessageBufferType>
522 buffer.write(this->
thp);
532 static_cast<unsigned int>(this->
segments.size());
535 for (
const auto& seg : this->
segments) {
543 template <
class MessageBufferType>
549 buffer.read(this->polymer);
550 buffer.read(this->solvent);
551 buffer.read(this->energy);
552 buffer.read(this->dissolved_gas);
553 buffer.read(this->vaporized_oil);
554 buffer.read(this->reservoir_water);
555 buffer.read(this->reservoir_oil);
556 buffer.read(this->reservoir_gas);
557 buffer.read(this->productivity_index_water);
558 buffer.read(this->productivity_index_oil);
559 buffer.read(this->productivity_index_gas);
560 buffer.read(this->well_potential_water);
561 buffer.read(this->well_potential_oil);
562 buffer.read(this->well_potential_gas);
565 template <
class MessageBufferType>
577 template <
class MessageBufferType>
584 template <
class MessageBufferType>
589 buffer.read(this->
prod);
592 buffer.read(this->
inj);
596 template <
class MessageBufferType>
600 buffer.read(this->
thp);
605 unsigned int size = 0.0;
608 for (
size_t i = 0; i < size; ++i)
615 const auto nSeg = [&
buffer]() ->
unsigned int
623 for (
auto segID = 0*nSeg; segID < nSeg; ++segID) {
627 const auto segNumber = seg.segNumber;
628 this->
segments.emplace(segNumber, std::move(seg));
const char *const name
Definition: cJSON.h:258
const char *const string
Definition: cJSON.h:170
char * buffer
Definition: cJSON.h:161
ProducerCMode
Definition: custom-opm-common/opm-common/opm/parser/eclipse/EclipseState/Schedule/Well/well.hpp:101
InjectorCMode
Definition: custom-opm-common/opm-common/opm/parser/eclipse/EclipseState/Schedule/Well/well.hpp:78
bool flowing() const
Returns true if any of the rates oil, gas, water is nonzero.
Definition: Wells.hpp:455
double get(opt m) const
Definition: Wells.hpp:364
void read(MessageBufferType &buffer)
Definition: Wells.hpp:544
bool operator==(const Rates &rat2) const
Definition: Wells.hpp:388
Rates & set(opt m, double value)
Definition: Wells.hpp:377
std::underlying_type< opt >::type enum_size
Definition: Wells.hpp:71
void write(MessageBufferType &buffer) const
Definition: Wells.hpp:466
opt
Definition: Wells.hpp:51
@ productivity_index_water
bool has(opt) const
Query if a value is set.
Definition: Wells.hpp:357
Definition: Wells.hpp:153
bool operator==(const SegmentPressures &segpres2) const
Definition: Wells.hpp:169
Value
Definition: Wells.hpp:155
double operator[](const Value i) const
Definition: Wells.hpp:164
double & operator[](const Value i)
Definition: Wells.hpp:159
void read(MessageBufferType &buffer)
Definition: Wells.hpp:183
void write(MessageBufferType &buffer) const
Definition: Wells.hpp:175
Definition: Wells.hpp:299
double get(const std::string &well_name, Rates::opt m) const
Definition: Wells.hpp:302
void write(MessageBufferType &buffer) const
Definition: Wells.hpp:327
double get(const std::string &well_name, Connection::global_index connection_grid_index, Rates::opt m) const
Definition: Wells.hpp:310
void read(MessageBufferType &buffer)
Definition: Wells.hpp:339
std::vector< typename std::result_of< F(typename C::const_iterator::value_type &) >::type > map(F f, const C &src)
Definition: Functional.hpp:84
@ end
Definition: ActionValue.hpp:20
T value(details::expression_node< T > *n)
Definition: exprtk.hpp:12955
Definition: Wells.hpp:122
double cell_saturation_water
Definition: Wells.hpp:131
bool operator==(const Connection &conn2) const
Definition: Wells.hpp:135
Rates rates
Definition: Wells.hpp:127
void write(MessageBufferType &buffer) const
Definition: Wells.hpp:488
double effective_Kh
Definition: Wells.hpp:133
double cell_pressure
Definition: Wells.hpp:130
size_t global_index
Definition: Wells.hpp:123
void read(MessageBufferType &buffer)
Definition: Wells.hpp:566
static const constexpr int restart_size
Definition: Wells.hpp:124
double cell_saturation_gas
Definition: Wells.hpp:132
double reservoir_rate
Definition: Wells.hpp:129
global_index index
Definition: Wells.hpp:126
double pressure
Definition: Wells.hpp:128
Definition: Wells.hpp:220
void write(MessageBufferType &buffer) const
Definition: Wells.hpp:507
bool operator==(const CurrentControl &rhs) const
Definition: Wells.hpp:231
::Opm::Well::InjectorCMode inj
Definition: Wells.hpp:227
void read(MessageBufferType &buffer)
Definition: Wells.hpp:585
bool isProducer
Definition: Wells.hpp:221
::Opm::Well::ProducerCMode prod
Definition: Wells.hpp:223
Definition: Wells.hpp:201
bool operator==(const Segment &seg2) const
Definition: Wells.hpp:206
SegmentPressures pressures
Definition: Wells.hpp:203
Rates rates
Definition: Wells.hpp:202
std::size_t segNumber
Definition: Wells.hpp:204
void read(MessageBufferType &buffer)
Definition: Wells.hpp:578
void write(MessageBufferType &buffer) const
Definition: Wells.hpp:500
Definition: Wells.hpp:245
double bhp
Definition: Wells.hpp:247
Connection * find_connection(Connection::global_index connection_grid_index)
Definition: Wells.hpp:273
bool operator==(const Well &well2) const
Definition: Wells.hpp:285
Rates rates
Definition: Wells.hpp:246
std::vector< Connection > connections
Definition: Wells.hpp:251
const Connection * find_connection(Connection::global_index connection_grid_index) const
Definition: Wells.hpp:261
double thp
Definition: Wells.hpp:248
int control
Definition: Wells.hpp:250
bool flowing() const noexcept
Definition: Wells.hpp:461
std::unordered_map< std::size_t, Segment > segments
Definition: Wells.hpp:252
void write(MessageBufferType &buffer) const
Definition: Wells.hpp:519
void read(MessageBufferType &buffer)
Definition: Wells.hpp:597
CurrentControl current_control
Definition: Wells.hpp:253
double temperature
Definition: Wells.hpp:249