20#ifndef OPM_OUTPUT_WELLS_HPP
21#define OPM_OUTPUT_WELLS_HPP
23#include <opm/output/data/GuideRateValue.hpp>
24#include <opm/input/eclipse/Schedule/Well/WellEnums.hpp>
26#include <opm/json/JsonObject.hpp>
36#include <unordered_map>
39namespace Opm {
namespace data {
53 enum class opt : uint32_t {
60 dissolved_gas = (1 << 6),
61 vaporized_oil = (1 << 7),
62 reservoir_water = (1 << 8),
63 reservoir_oil = (1 << 9),
64 reservoir_gas = (1 << 10),
65 productivity_index_water = (1 << 11),
66 productivity_index_oil = (1 << 12),
67 productivity_index_gas = (1 << 13),
68 well_potential_water = (1 << 14),
69 well_potential_oil = (1 << 15),
70 well_potential_gas = (1 << 16),
75 vaporized_water = (1 << 21),
79 using enum_size = std::underlying_type< opt >::type;
82 inline bool has( opt )
const;
86 inline double get( opt m )
const;
89 inline double get( opt m,
double default_value )
const;
90 inline double get( opt m,
double default_value ,
const std::string& tracer_name )
const;
94 inline Rates&
set( opt m,
double value );
95 inline Rates&
set( opt m,
double value ,
const std::string& tracer_name );
100 template <
class MessageBufferType>
101 void write(MessageBufferType& buffer)
const;
102 template <
class MessageBufferType>
103 void read(MessageBufferType& buffer);
105 bool operator==(
const Rates& rat2)
const;
109 template<
class Serializer>
119 serializer(dissolved_gas);
120 serializer(vaporized_oil);
121 serializer(reservoir_water);
122 serializer(reservoir_oil);
123 serializer(reservoir_gas);
124 serializer(productivity_index_water);
125 serializer(productivity_index_oil);
126 serializer(productivity_index_gas);
127 serializer(well_potential_water);
128 serializer(well_potential_oil);
129 serializer(well_potential_gas);
134 serializer(vaporized_water);
135 serializer(mass_gas);
138 static Rates serializationTestObject()
141 rat1.
set(opt::wat, 1.0);
142 rat1.
set(opt::oil, 2.0);
143 rat1.
set(opt::gas, 3.0);
144 rat1.
set(opt::polymer, 4.0);
145 rat1.
set(opt::solvent, 5.0);
146 rat1.
set(opt::energy, 6.0);
147 rat1.
set(opt::dissolved_gas, 7.0);
148 rat1.
set(opt::vaporized_oil, 8.0);
149 rat1.
set(opt::reservoir_water, 9.0);
150 rat1.
set(opt::reservoir_oil, 10.0);
151 rat1.
set(opt::reservoir_gas, 11.0);
152 rat1.
set(opt::productivity_index_water, 12.0);
153 rat1.
set(opt::productivity_index_oil, 13.0);
154 rat1.
set(opt::productivity_index_gas, 14.0);
155 rat1.
set(opt::well_potential_water, 15.0);
156 rat1.
set(opt::well_potential_oil, 16.0);
157 rat1.
set(opt::well_potential_gas, 17.0);
158 rat1.
set(opt::brine, 18.0);
159 rat1.
set(opt::alq, 19.0);
160 rat1.
set(opt::micp, 21.0);
161 rat1.
set(opt::vaporized_water, 22.0);
162 rat1.
set(opt::mass_gas, 23.0);
163 rat1.tracer.insert({
"test_tracer", 1.0});
169 double& get_ref( opt );
170 double& get_ref( opt,
const std::string& tracer_name );
171 const double& get_ref( opt )
const;
172 const double& get_ref( opt,
const std::string& tracer_name )
const;
174 opt mask =
static_cast< opt
>( 0 );
179 double polymer = 0.0;
180 double solvent = 0.0;
182 double dissolved_gas = 0.0;
183 double vaporized_oil = 0.0;
184 double reservoir_water = 0.0;
185 double reservoir_oil = 0.0;
186 double reservoir_gas = 0.0;
187 double productivity_index_water = 0.0;
188 double productivity_index_oil = 0.0;
189 double productivity_index_gas = 0.0;
190 double well_potential_water = 0.0;
191 double well_potential_oil = 0.0;
192 double well_potential_gas = 0.0;
195 std::map<std::string, double> tracer{};
197 double vaporized_water = 0.0;
198 double mass_gas = 0.0;
212 template<
class Serializer>
216 serializer(skin_factor);
217 serializer(thickness);
221 serializer(area_of_flow);
226 return this->rate == filtrate.rate &&
227 this->total == filtrate.total &&
228 this->skin_factor == filtrate.skin_factor &&
229 this->thickness == filtrate.thickness &&
230 this->perm == filtrate.perm &&
231 this->poro == filtrate.poro &&
232 this->radius == filtrate.radius &&
233 this->area_of_flow == filtrate.area_of_flow;
238 return {0.8, 100., -1., 2., 1.e-9,
242 template <
class MessageBufferType>
243 void write(MessageBufferType& buffer)
const;
245 template <
class MessageBufferType>
246 void read(MessageBufferType& buffer);
273 12.34, 56.78, 9.10, 11.12
282 template <
class Serializer>
285 serializer(this->
avg);
286 serializer(this->
max);
287 serializer(this->
min);
288 serializer(this->
stdev);
300 return (this->
avg == that.
avg)
301 && (this->
max == that.
max)
302 && (this->
min == that.
min)
308 template <
class MessageBufferType>
309 void write(MessageBufferType& buffer)
const
311 buffer.write(this->
avg);
312 buffer.write(this->
max);
313 buffer.write(this->
min);
314 buffer.write(this->
stdev);
318 template <
class MessageBufferType>
319 void read(MessageBufferType& buffer)
321 buffer.read(this->
avg);
322 buffer.read(this->
max);
323 buffer.read(this->
min);
324 buffer.read(this->
stdev);
360 template <
class Serializer>
364 serializer(this->
press);
365 serializer(this->
rate);
366 serializer(this->
width);
386 template <
class MessageBufferType>
387 void write(MessageBufferType& buffer)
const
390 buffer.write(this->
press);
391 buffer.write(this->
rate);
392 buffer.write(this->
width);
396 template <
class MessageBufferType>
397 void read(MessageBufferType& buffer)
400 buffer.read(this->
press);
401 buffer.read(this->
rate);
402 buffer.read(this->
width);
408 using global_index = std::size_t;
409 static const constexpr int restart_size = 6;
411 global_index index{};
414 double reservoir_rate{};
415 double cell_pressure{};
416 double cell_saturation_water{};
417 double cell_saturation_gas{};
418 double effective_Kh{};
419 double trans_factor{};
421 double compact_mult{1.0};
428 bool operator==(
const Connection& conn2)
const
430 return (index == conn2.index)
431 && (rates == conn2.rates)
432 && (pressure == conn2.pressure)
433 && (reservoir_rate == conn2.reservoir_rate)
434 && (cell_pressure == conn2.cell_pressure)
435 && (cell_saturation_water == conn2.cell_saturation_water)
436 && (cell_saturation_gas == conn2.cell_saturation_gas)
437 && (effective_Kh == conn2.effective_Kh)
438 && (trans_factor == conn2.trans_factor)
439 && (d_factor == conn2.d_factor)
440 && (compact_mult == conn2.compact_mult)
441 && (filtrate == conn2.filtrate)
446 template <
class MessageBufferType>
447 void write(MessageBufferType& buffer)
const;
448 template <
class MessageBufferType>
449 void read(MessageBufferType& buffer);
453 template<
class Serializer>
458 serializer(pressure);
459 serializer(reservoir_rate);
460 serializer(cell_pressure);
461 serializer(cell_saturation_water);
462 serializer(cell_saturation_gas);
463 serializer(effective_Kh);
464 serializer(trans_factor);
465 serializer(d_factor);
466 serializer(compact_mult);
467 serializer(filtrate);
468 serializer(this->
fract);
471 static Connection serializationTestObject()
474 1, Rates::serializationTestObject(),
476 6.0, 7.0, 8.0, 9.0, 0.987,
477 ConnectionFiltrate::serializationTestObject(),
486 enum class Value : std::size_t {
487 Pressure, PDrop, PDropHydrostatic, PDropAccel, PDropFriction,
490 double& operator[](
const Value i)
492 return this->values_[this->index(i)];
495 double operator[](
const Value i)
const
497 return this->values_[this->index(i)];
502 return this->values_ == segpres2.values_;
505 template <
class MessageBufferType>
506 void write(MessageBufferType& buffer)
const
508 for (
const auto& value : this->values_) {
513 template <
class MessageBufferType>
514 void read(MessageBufferType& buffer)
516 for (
auto& value : this->values_) {
521 template<
class Serializer>
530 spres[Value::Pressure] = 1.0;
531 spres[Value::PDrop] = 2.0;
532 spres[Value::PDropHydrostatic] = 3.0;
533 spres[Value::PDropAccel] = 4.0;
534 spres[Value::PDropFriction] = 5.0;
540 constexpr static std::size_t numvals = 5;
542 std::array<double, numvals> values_ = {0};
544 std::size_t index(
const Value ix)
const
546 return static_cast<std::size_t
>(ix);
550 template <
typename Items>
554 using Item =
typename Items::Item;
558 this->has_ =
static_cast<unsigned char>(0);
559 this->value_.fill(0.0);
562 constexpr bool has(
const Item p)
const
564 const auto i = this->index(p);
566 return (i < Size) && this->hasItem(i);
571 return (this->has_ == that.has_)
572 && (this->value_ == that.value_);
575 double get(
const Item p)
const
577 if (! this->has(p)) {
578 throw std::invalid_argument {
579 "Request for Unset Item Value for " + Items::itemName(p)
583 return this->value_[ this->index(p) ];
588 const auto i = this->index(p);
591 throw std::invalid_argument {
592 "Cannot Assign Item Value for Unsupported Item '"
593 + Items::itemName(p) +
'\''
597 this->has_ |= 1 << i;
598 this->value_[i] = value;
603 template <
class MessageBufferType>
604 void write(MessageBufferType& buffer)
const
606 buffer.write(this->has_);
608 for (
const auto& x : this->value_) {
613 template <
class MessageBufferType>
614 void read(MessageBufferType& buffer)
617 buffer.read(this->has_);
619 for (
auto& x : this->value_) {
624 template <
class Serializer>
627 serializer(this->has_);
628 serializer(this->value_);
635 for (
const auto& [item, value] : Items::serializationTestItems()) {
636 quant.set(item, value);
643 enum { Size =
static_cast<std::size_t
>(Item::NumItems) };
645 static_assert(Size <= static_cast<std::size_t>(CHAR_BIT),
646 "Number of items must not exceed CHAR_BIT");
650 unsigned char has_{};
653 std::array<double, Size> value_{};
655 constexpr std::size_t index(
const Item p)
const noexcept
657 return static_cast<std::size_t
>(p);
660 bool hasItem(
const std::size_t i)
const
662 return (this->has_ & (1 << i)) != 0;
675 static std::string itemName(
const Item p)
678 case Item::Oil:
return "Oil";
679 case Item::Gas:
return "Gas";
680 case Item::Water:
return "Water";
683 return "Out of bounds (NumItems)";
686 return "Unknown (" + std::to_string(
static_cast<int>(p)) +
')';
689 static auto serializationTestItems()
692 std::pair { Item::Oil , 1.0 },
693 std::pair { Item::Gas , 7.0 },
694 std::pair { Item::Water, 2.9 },
702 Oil, Gas, Water, Mixture, MixtureWithExponents,
708 static std::string itemName(
const Item p)
711 case Item::Oil:
return "Oil";
712 case Item::Gas:
return "Gas";
713 case Item::Water:
return "Water";
714 case Item::Mixture:
return "Mixture";
715 case Item::MixtureWithExponents:
return "MixtureWithExponents";
718 return "Out of bounds (NumItems)";
721 return "Unknown (" + std::to_string(
static_cast<int>(p)) +
')';
724 static auto serializationTestItems()
727 std::pair { Item::Oil , 876.54 },
728 std::pair { Item::Gas , 321.09 },
729 std::pair { Item::Water , 987.65 },
730 std::pair { Item::Mixture , 975.31 },
731 std::pair { Item::MixtureWithExponents, 765.43 },
747 std::size_t segNumber{};
749 bool operator==(
const Segment& seg2)
const
751 return (rates == seg2.rates)
752 && (pressures == seg2.pressures)
753 && (velocity == seg2.velocity)
754 && (holdup == seg2.holdup)
755 && (viscosity == seg2.viscosity)
756 && (density == seg2.density)
757 && (segNumber == seg2.segNumber);
760 template <
class MessageBufferType>
761 void write(MessageBufferType& buffer)
const;
763 template <
class MessageBufferType>
764 void read(MessageBufferType& buffer);
766 template <
class Serializer>
769 serializer(this->rates);
770 serializer(this->pressures);
771 serializer(this->velocity);
772 serializer(this->holdup);
773 serializer(this->viscosity);
774 serializer(this->density);
775 serializer(this->segNumber);
778 static Segment serializationTestObject()
781 Rates::serializationTestObject(),
782 SegmentPressures::serializationTestObject(),
783 SegmentPhaseQuantity::serializationTestObject(),
784 SegmentPhaseQuantity::serializationTestObject(),
785 SegmentPhaseQuantity::serializationTestObject(),
786 SegmentPhaseDensity::serializationTestObject(),
794 bool isProducer{
true};
796 ::Opm::WellProducerCMode prod {
797 ::Opm::WellProducerCMode::CMODE_UNDEFINED
800 ::Opm::WellInjectorCMode inj {
801 ::Opm::WellInjectorCMode::CMODE_UNDEFINED
806 return (this->isProducer == rhs.isProducer)
807 && ((this->isProducer && (this->prod == rhs.prod)) ||
808 (!this->isProducer && (this->inj == rhs.inj)));
813 if (this->inj == ::Opm::WellInjectorCMode::CMODE_UNDEFINED)
814 json_data.add_item(
"inj",
"CMODE_UNDEFINED");
816 json_data.add_item(
"inj", ::Opm::WellInjectorCMode2String(this->inj));
818 if (this->prod == ::Opm::WellProducerCMode::CMODE_UNDEFINED)
819 json_data.add_item(
"prod",
"CMODE_UNDEFINED");
821 json_data.add_item(
"prod", ::Opm::WellProducerCMode2String(this->prod));
824 template <
class MessageBufferType>
825 void write(MessageBufferType& buffer)
const;
827 template <
class MessageBufferType>
828 void read(MessageBufferType& buffer);
830 template<
class Serializer>
833 serializer(isProducer);
841 ::Opm::WellProducerCMode::BHP,
842 ::Opm::WellInjectorCMode::GRUP
850 enum class Quantity { WBP, WBP4, WBP5, WBP9 };
852 double& operator[](
const Quantity q)
854 return this->wbp_[
static_cast<std::size_t
>(q)];
857 double operator[](
const Quantity q)
const
859 return this->wbp_[
static_cast<std::size_t
>(q)];
864 return this->wbp_ == that.wbp_;
867 template <
class MessageBufferType>
868 void write(MessageBufferType& buffer)
const;
870 template <
class MessageBufferType>
871 void read(MessageBufferType& buffer);
873 template <
class Serializer>
876 serializer(this->wbp_);
883 wbp[Quantity::WBP] = 17.29;
884 wbp[Quantity::WBP4] = 2.718;
885 wbp[Quantity::WBP5] = 3.1415;
886 wbp[Quantity::WBP9] = 1.618;
892 static constexpr auto NumQuantities =
893 static_cast<std::size_t
>(Quantity::WBP9) + 1;
895 std::array<double, NumQuantities> wbp_{};
902 double concentration{0.};
904 template<
class Serializer>
908 serializer(concentration);
912 return this->rate == filtrate.rate
913 && this->total == filtrate.total
914 && this->concentration == filtrate.concentration;
921 res.concentration = 0.;
925 template <
class MessageBufferType>
926 void write(MessageBufferType& buffer)
const;
928 template <
class MessageBufferType>
929 void read(MessageBufferType& buffer);
935 Bhp, OilRate, WaterRate, GasRate, ResVRate, LiquidRate,
941 static std::string itemName(
const Item p)
944 case Item::Bhp:
return "Bhp";
945 case Item::OilRate:
return "OilRate";
946 case Item::WaterRate:
return "WaterRate";
947 case Item::GasRate:
return "GasRate";
948 case Item::ResVRate:
return "ResVRate";
949 case Item::LiquidRate:
return "LiquidRate";
952 return "Out of bounds (NumItems)";
955 return "Unknown (" + std::to_string(
static_cast<int>(p)) +
')';
958 static auto serializationTestItems()
961 std::pair { Item::Bhp , 321.09 },
962 std::pair { Item::OilRate , 987.65 },
963 std::pair { Item::WaterRate , 975.31 },
964 std::pair { Item::GasRate , 765.43 },
965 std::pair { Item::ResVRate , 876.54 },
966 std::pair { Item::LiquidRate, 54.32 },
979 double temperature{0.0};
981 double efficiency_scaling_factor{1.0};
985 ::Opm::WellStatus dynamicStatus { Opm::WellStatus::OPEN };
987 std::vector<Connection> connections{};
988 std::unordered_map<std::size_t, Segment> segments{};
993 inline bool flowing()
const noexcept;
995 template <
class MessageBufferType>
996 void write(MessageBufferType& buffer)
const;
998 template <
class MessageBufferType>
999 void read(MessageBufferType& buffer);
1004 find_connection(
const Connection::global_index connection_grid_index)
const
1006 auto connection = std::find_if(this->connections.begin(),
1007 this->connections.end(),
1009 { return c.index == connection_grid_index; });
1011 if (connection == this->connections.end()) {
1015 return &*connection;
1019 find_connection(
const Connection::global_index connection_grid_index)
1021 auto connection = std::find_if(this->connections.begin(),
1022 this->connections.end(),
1024 { return c.index == connection_grid_index; });
1026 if (connection == this->connections.end()) {
1030 return &*connection;
1033 bool operator==(
const Well& well2)
const
1035 return (this->rates == well2.rates)
1036 && (this->bhp == well2.bhp)
1037 && (this->thp == well2.thp)
1038 && (this->temperature == well2.temperature)
1039 && (this->filtrate == well2.filtrate)
1040 && (this->control == well2.control)
1041 && (this->dynamicStatus == well2.dynamicStatus)
1042 && (this->connections == well2.connections)
1043 && (this->segments == well2.segments)
1044 && (this->current_control == well2.current_control)
1045 && (this->guide_rates == well2.guide_rates)
1046 && (this->limits == well2.limits)
1050 template<
class Serializer>
1056 serializer(temperature);
1057 serializer(control);
1058 serializer(efficiency_scaling_factor);
1059 serializer(filtrate);
1060 serializer(dynamicStatus);
1061 serializer(connections);
1062 serializer(segments);
1063 serializer(current_control);
1064 serializer(guide_rates);
1068 static Well serializationTestObject()
1071 Rates::serializationTestObject(),
1077 WellFiltrate::serializationTestObject(),
1078 ::Opm::WellStatus::SHUT,
1079 {Connection::serializationTestObject()},
1080 {{0, Segment::serializationTestObject()}},
1081 CurrentControl::serializationTestObject(),
1082 GuideRateValue::serializationTestObject(),
1083 WellControlLimits::serializationTestObject()
1088 class Wells:
public std::map<std::string , Well> {
1091 double get(
const std::string& well_name , Rates::opt m)
const {
1092 const auto& well = this->find( well_name );
1093 if( well == this->end() )
return 0.0;
1095 return well->second.rates.get( m, 0.0 );
1098 double get(
const std::string& well_name , Rates::opt m,
const std::string& tracer_name)
const {
1099 const auto& well = this->find( well_name );
1100 if( well == this->end() )
return 0.0;
1102 return well->second.rates.get( m, 0.0, tracer_name);
1105 double get(
const std::string& well_name , Connection::global_index connection_grid_index, Rates::opt m)
const {
1106 const auto& witr = this->find( well_name );
1107 if( witr == this->end() )
return 0.0;
1109 const auto& well = witr->second;
1110 const auto& connection = std::find_if( well.connections.begin() ,
1111 well.connections.end() ,
1113 return c.index == connection_grid_index; });
1115 if( connection == well.connections.end() )
1118 return connection->rates.get( m, 0.0 );
1121 template <
class MessageBufferType>
1122 void write(MessageBufferType& buffer)
const {
1123 unsigned int size = this->size();
1125 for (
const auto& witr : *
this) {
1126 const std::string& name = witr.first;
1128 const Well& well = witr.second;
1133 template <
class MessageBufferType>
1134 void read(MessageBufferType& buffer) {
1137 for (
size_t i = 0; i < size; ++i) {
1142 this->emplace(name, well);
1147 for (
const auto& [wname, well] : *
this) {
1148 auto json_well = json_data.add_object(wname);
1149 well.init_json(json_well);
1156 this->init_json(json_data);
1160 template<
class Serializer>
1163 serializer(
static_cast<std::map<std::string,Well>&
>(*
this));
1166 static Wells serializationTestObject()
1169 w.insert({
"test_well", Well::serializationTestObject()});
1177 std::unordered_map<std::string, WellBlockAvgPress> values{};
1179 template <
class MessageBufferType>
1180 void write(MessageBufferType& buffer)
const;
1182 template <
class MessageBufferType>
1183 void read(MessageBufferType& buffer);
1187 return this->values == that.values;
1190 template <
class Serializer>
1193 serializer(this->values);
1199 { {
"I-45", WellBlockAvgPress::serializationTestObject() } },
1207 const auto mand =
static_cast< enum_size
>( this->mask )
1208 &
static_cast< enum_size
>( m );
1210 return static_cast< opt
>( mand ) == m;
1214 if( !this->
has( m ) )
1215 throw std::invalid_argument(
"Uninitialized value." );
1217 return this->get_ref( m );
1221 if( !this->
has( m ) )
return default_value;
1223 return this->get_ref( m );
1226 inline double Rates::get( opt m,
double default_value,
const std::string& tracer_name)
const {
1227 if( !this->
has( m ) )
return default_value;
1229 if( m == opt::tracer && this->tracer.find(tracer_name) == this->tracer.end())
return default_value;
1231 return this->get_ref( m, tracer_name);
1235 this->get_ref( m ) = value;
1238 this->mask =
static_cast< opt
>(
1239 static_cast< enum_size
>( this->mask ) |
1240 static_cast< enum_size
>( m )
1246 inline Rates&
Rates::set( opt m,
double value ,
const std::string& tracer_name ) {
1247 this->get_ref( m , tracer_name) = value;
1250 this->mask =
static_cast< opt
>(
1251 static_cast< enum_size
>( this->mask ) |
1252 static_cast< enum_size
>( m )
1258 inline bool Rates::operator==(
const Rates& rate)
const
1260 return mask == rate.mask &&
1264 polymer == rate.polymer &&
1265 solvent == rate.solvent &&
1266 energy == rate.energy &&
1267 dissolved_gas == rate.dissolved_gas &&
1268 vaporized_oil == rate.vaporized_oil &&
1269 reservoir_water == rate.reservoir_water &&
1270 reservoir_oil == rate.reservoir_oil &&
1271 reservoir_gas == rate.reservoir_gas &&
1272 productivity_index_water == rate.productivity_index_water &&
1273 productivity_index_gas == rate.productivity_index_gas &&
1274 productivity_index_oil == rate.productivity_index_oil &&
1275 well_potential_water == rate.well_potential_water &&
1276 well_potential_oil == rate.well_potential_oil &&
1277 well_potential_gas == rate.well_potential_gas &&
1278 brine == rate.brine &&
1280 tracer == rate.tracer &&
1281 micp == rate.micp &&
1282 vaporized_water == rate.vaporized_water &&
1283 mass_gas == rate.mass_gas;
1296 inline const double& Rates::get_ref( opt m )
const {
1298 case opt::wat:
return this->wat;
1299 case opt::oil:
return this->oil;
1300 case opt::gas:
return this->gas;
1301 case opt::polymer:
return this->polymer;
1302 case opt::solvent:
return this->solvent;
1303 case opt::energy:
return this->energy;
1304 case opt::dissolved_gas:
return this->dissolved_gas;
1305 case opt::vaporized_oil:
return this->vaporized_oil;
1306 case opt::reservoir_water:
return this->reservoir_water;
1307 case opt::reservoir_oil:
return this->reservoir_oil;
1308 case opt::reservoir_gas:
return this->reservoir_gas;
1309 case opt::productivity_index_water:
return this->productivity_index_water;
1310 case opt::productivity_index_oil:
return this->productivity_index_oil;
1311 case opt::productivity_index_gas:
return this->productivity_index_gas;
1312 case opt::well_potential_water:
return this->well_potential_water;
1313 case opt::well_potential_oil:
return this->well_potential_oil;
1314 case opt::well_potential_gas:
return this->well_potential_gas;
1315 case opt::brine:
return this->brine;
1316 case opt::alq:
return this->alq;
1319 case opt::micp:
return this->micp;
1320 case opt::vaporized_water:
return this->vaporized_water;
1321 case opt::mass_gas:
return this->mass_gas;
1324 throw std::invalid_argument(
1325 "Unknown value type '"
1326 + std::to_string(
static_cast< enum_size
>( m ) )
1331 inline const double& Rates::get_ref( opt m,
const std::string& tracer_name )
const {
1332 if (m != opt::tracer)
1333 throw std::logic_error(
"Logic error - should be called with tracer argument");
1335 return this->tracer.at(tracer_name);
1338 inline double& Rates::get_ref( opt m ) {
1339 return const_cast< double&
>(
1340 static_cast< const Rates*
>( this )->get_ref( m )
1344 inline double& Rates::get_ref( opt m,
const std::string& tracer_name ) {
1345 if (m == opt::tracer) this->tracer.emplace(tracer_name, 0.0);
1346 return this->tracer.at(tracer_name);
1351 if (this->
has(opt::wat))
1352 json_data.add_item(
"wat", this->
get(opt::wat));
1354 if (this->
has(opt::oil))
1355 json_data.add_item(
"oil", this->
get(opt::oil));
1357 if (this->
has(opt::gas))
1358 json_data.add_item(
"gas", this->
get(opt::gas));
1363 return ((this->wat != 0) ||
1368 inline bool Well::flowing() const noexcept {
1372 template <
class MessageBufferType>
1373 void Rates::write(MessageBufferType& buffer)
const {
1374 buffer.write(this->mask);
1375 buffer.write(this->wat);
1376 buffer.write(this->oil);
1377 buffer.write(this->gas);
1378 buffer.write(this->polymer);
1379 buffer.write(this->solvent);
1380 buffer.write(this->energy);
1381 buffer.write(this->dissolved_gas);
1382 buffer.write(this->vaporized_oil);
1383 buffer.write(this->reservoir_water);
1384 buffer.write(this->reservoir_oil);
1385 buffer.write(this->reservoir_gas);
1386 buffer.write(this->productivity_index_water);
1387 buffer.write(this->productivity_index_oil);
1388 buffer.write(this->productivity_index_gas);
1389 buffer.write(this->well_potential_water);
1390 buffer.write(this->well_potential_oil);
1391 buffer.write(this->well_potential_gas);
1392 buffer.write(this->brine);
1393 buffer.write(this->alq);
1396 unsigned int size = this->tracer.size();
1398 for (
const auto& [name, rate] : this->tracer) {
1403 buffer.write(this->micp);
1404 buffer.write(this->vaporized_water);
1405 buffer.write(this->mass_gas);
1408 template <
class MessageBufferType>
1409 void ConnectionFiltrate::write(MessageBufferType& buffer)
const {
1410 buffer.write(this->rate);
1411 buffer.write(this->total);
1412 buffer.write(this->skin_factor);
1413 buffer.write(this->thickness);
1414 buffer.write(this->perm);
1415 buffer.write(this->poro);
1416 buffer.write(this->radius);
1417 buffer.write(this->area_of_flow);
1420 template <
class MessageBufferType>
1421 void Connection::write(MessageBufferType& buffer)
const {
1422 buffer.write(this->index);
1423 this->rates.write(buffer);
1424 buffer.write(this->pressure);
1425 buffer.write(this->reservoir_rate);
1426 buffer.write(this->cell_pressure);
1427 buffer.write(this->cell_saturation_water);
1428 buffer.write(this->cell_saturation_gas);
1429 buffer.write(this->effective_Kh);
1430 buffer.write(this->trans_factor);
1431 buffer.write(this->d_factor);
1432 buffer.write(this->compact_mult);
1433 this->filtrate.write(buffer);
1438 auto json_rates = json_data.add_object(
"rates");
1439 this->rates.init_json(json_rates);
1441 json_data.add_item(
"global_index",
static_cast<int>(this->index));
1442 json_data.add_item(
"pressure", this->pressure);
1443 json_data.add_item(
"reservoir_rate", this->reservoir_rate);
1444 json_data.add_item(
"cell_pressure", this->cell_pressure);
1445 json_data.add_item(
"swat", this->cell_saturation_water);
1446 json_data.add_item(
"sgas", this->cell_saturation_gas);
1447 json_data.add_item(
"Kh", this->effective_Kh);
1448 json_data.add_item(
"trans_factor", this->trans_factor);
1449 json_data.add_item(
"d_factor", this->d_factor);
1450 json_data.add_item(
"compact_mult", this->compact_mult);
1453 template <
class MessageBufferType>
1454 void Segment::write(MessageBufferType& buffer)
const
1456 buffer.write(this->segNumber);
1457 this->rates.write(buffer);
1458 this->pressures.write(buffer);
1459 this->velocity.write(buffer);
1460 this->holdup.write(buffer);
1461 this->viscosity.write(buffer);
1462 this->density.write(buffer);
1465 template <
class MessageBufferType>
1466 void CurrentControl::write(MessageBufferType& buffer)
const
1468 buffer.write(this->isProducer);
1469 if (this->isProducer) {
1470 buffer.write(this->prod);
1473 buffer.write(this->inj);
1477 template <
class MessageBufferType>
1478 void WellBlockAvgPress::write(MessageBufferType& buffer)
const
1480 for (
const auto& quantity : this->wbp_) {
1481 buffer.write(quantity);
1485 template <
class MessageBufferType>
1486 void WellFiltrate::write(MessageBufferType& buffer)
const
1488 buffer.write(this->rate);
1489 buffer.write(this->total);
1490 buffer.write(this->concentration);
1493 template <
class MessageBufferType>
1494 void Well::write(MessageBufferType& buffer)
const
1496 this->rates.write(buffer);
1498 buffer.write(this->bhp);
1499 buffer.write(this->thp);
1500 buffer.write(this->temperature);
1501 buffer.write(this->control);
1502 buffer.write(this->efficiency_scaling_factor);
1504 this->filtrate.write(buffer);
1507 const auto status = ::Opm::WellStatus2String(this->dynamicStatus);
1508 buffer.write(status);
1512 const unsigned int size = this->connections.size();
1515 for (
const Connection& comp : this->connections) {
1522 static_cast<unsigned int>(this->segments.size());
1525 for (
const auto& seg : this->segments) {
1526 seg.second.write(buffer);
1530 this->current_control.write(buffer);
1531 this->guide_rates.write(buffer);
1532 this->limits.write(buffer);
1535 template <
class MessageBufferType>
1536 void WellBlockAveragePressures::write(MessageBufferType& buffer)
const
1538 buffer.write(this->values.size());
1540 for (
const auto& [well, value] : this->values) {
1542 value.write(buffer);
1546 template <
class MessageBufferType>
1547 void Rates::read(MessageBufferType& buffer) {
1548 buffer.read(this->mask);
1549 buffer.read(this->wat);
1550 buffer.read(this->oil);
1551 buffer.read(this->gas);
1552 buffer.read(this->polymer);
1553 buffer.read(this->solvent);
1554 buffer.read(this->energy);
1555 buffer.read(this->dissolved_gas);
1556 buffer.read(this->vaporized_oil);
1557 buffer.read(this->reservoir_water);
1558 buffer.read(this->reservoir_oil);
1559 buffer.read(this->reservoir_gas);
1560 buffer.read(this->productivity_index_water);
1561 buffer.read(this->productivity_index_oil);
1562 buffer.read(this->productivity_index_gas);
1563 buffer.read(this->well_potential_water);
1564 buffer.read(this->well_potential_oil);
1565 buffer.read(this->well_potential_gas);
1566 buffer.read(this->brine);
1567 buffer.read(this->alq);
1572 for (
size_t i = 0; i < size; ++i) {
1573 std::string tracer_name;
1574 buffer.read(tracer_name);
1576 buffer.read(tracer_rate);
1577 this->tracer.emplace(tracer_name, tracer_rate);
1580 buffer.read(this->micp);
1581 buffer.read(this->vaporized_water);
1582 buffer.read(this->mass_gas);
1585 template <
class MessageBufferType>
1586 void ConnectionFiltrate::read(MessageBufferType& buffer) {
1587 buffer.read(this->rate);
1588 buffer.read(this->total);
1589 buffer.read(this->skin_factor);
1590 buffer.read(this->thickness);
1591 buffer.read(this->perm);
1592 buffer.read(this->poro);
1593 buffer.read(this->radius);
1594 buffer.read(this->area_of_flow);
1597 template <
class MessageBufferType>
1598 void Connection::read(MessageBufferType& buffer) {
1599 buffer.read(this->index);
1600 this->rates.read(buffer);
1601 buffer.read(this->pressure);
1602 buffer.read(this->reservoir_rate);
1603 buffer.read(this->cell_pressure);
1604 buffer.read(this->cell_saturation_water);
1605 buffer.read(this->cell_saturation_gas);
1606 buffer.read(this->effective_Kh);
1607 buffer.read(this->trans_factor);
1608 buffer.read(this->d_factor);
1609 buffer.read(this->compact_mult);
1610 this->filtrate.read(buffer);
1614 template <
class MessageBufferType>
1615 void Segment::read(MessageBufferType& buffer)
1617 buffer.read(this->segNumber);
1618 this->rates.read(buffer);
1619 this->pressures.read(buffer);
1620 this->velocity.read(buffer);
1621 this->holdup.read(buffer);
1622 this->viscosity.read(buffer);
1623 this->density.read(buffer);
1626 template <
class MessageBufferType>
1627 void CurrentControl::read(MessageBufferType& buffer)
1629 buffer.read(this->isProducer);
1630 if (this->isProducer) {
1631 buffer.read(this->prod);
1634 buffer.read(this->inj);
1638 template <
class MessageBufferType>
1639 void WellBlockAvgPress::read(MessageBufferType& buffer)
1641 for (
auto& quantity : this->wbp_) {
1642 buffer.read(quantity);
1646 template <
class MessageBufferType>
1647 void WellFiltrate::read(MessageBufferType& buffer)
1649 buffer.read(this->rate);
1650 buffer.read(this->total);
1651 buffer.read(this->concentration);
1654 template <
class MessageBufferType>
1655 void Well::read(MessageBufferType& buffer)
1657 this->rates.read(buffer);
1659 buffer.read(this->bhp);
1660 buffer.read(this->thp);
1661 buffer.read(this->temperature);
1662 buffer.read(this->control);
1663 buffer.read(this->efficiency_scaling_factor);
1665 this->filtrate.read(buffer);
1668 auto status = std::string{};
1669 buffer.read(status);
1670 this->dynamicStatus = ::Opm::WellStatusFromString(status);
1675 unsigned int size = 0;
1678 this->connections.resize(size);
1679 for (
auto& connection : this->connections) {
1680 connection.read(buffer);
1685 const auto nSeg = [&buffer]() ->
unsigned int
1693 for (
auto segID = 0*nSeg; segID < nSeg; ++segID) {
1694 auto seg = Segment{};
1697 const auto segNumber = seg.segNumber;
1698 this->segments.emplace(segNumber, std::move(seg));
1701 this->current_control.read(buffer);
1702 this->guide_rates.read(buffer);
1703 this->limits.read(buffer);
1706 template <
class MessageBufferType>
1707 void WellBlockAveragePressures::read(MessageBufferType& buffer)
1709 const auto numWells = [&buffer,
this]()
1711 auto size = 0*this->values.size();
1717 auto wellName = std::string{};
1718 for (
auto well = 0*numWells; well < numWells; ++well) {
1719 buffer.read(wellName);
1721 this->values[wellName].read(buffer);
1726 auto json_connections = json_data.add_array(
"connections");
1727 for (
const auto& conn : this->connections) {
1728 auto json_conn = json_connections.add_object();
1729 conn.init_json(json_conn);
1731 auto json_rates = json_data.add_object(
"rates");
1732 this->rates.init_json(json_rates);
1734 json_data.add_item(
"bhp", this->bhp);
1735 json_data.add_item(
"thp", this->thp);
1736 json_data.add_item(
"temperature", this->temperature);
1737 json_data.add_item(
"status", ::Opm::WellStatus2String(this->dynamicStatus));
1739 auto json_control = json_data.add_object(
"control");
1740 this->current_control.init_json(json_control);
1742 auto json_guiderate = json_data.add_object(
"guiderate");
1743 this->guide_rates.init_json(json_guiderate);
Definition JsonObject.hpp:31
Class for (de-)serializing.
Definition Serializer.hpp:94
Definition GuideRateValue.hpp:32
bool flowing() const
Returns true if any of the rates oil, gas, water is nonzero.
Definition Wells.hpp:1362
double get(opt m) const
Read the value indicated by m.
Definition Wells.hpp:1213
Rates & set(opt m, double value)
Set the value specified by m.
Definition Wells.hpp:1234
bool has(opt) const
Query if a value is set.
Definition Wells.hpp:1206
Definition Wells.hpp:1088
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Statistics collection for a single quantity.
Definition Wells.hpp:254
void serializeOp(Serializer &serializer)
Convert between byte array and object representation.
Definition Wells.hpp:283
void write(MessageBufferType &buffer) const
MPI communication protocol–serialisation operation.
Definition Wells.hpp:309
double stdev
Unbiased sample standard deviation.
Definition Wells.hpp:267
double avg
Arithmetic average.
Definition Wells.hpp:256
double min
Minimum value.
Definition Wells.hpp:262
void read(MessageBufferType &buffer)
MPI communication protocol–deserialisation operation.
Definition Wells.hpp:319
double max
Maximum value.
Definition Wells.hpp:259
bool operator==(const Statistics &that) const
Equality predicate.
Definition Wells.hpp:298
static Statistics serializationTestObject()
Create a serialization test object.
Definition Wells.hpp:270
Connection Level Fracturing Statistics.
Definition Wells.hpp:251
void read(MessageBufferType &buffer)
MPI communication protocol–deserialisation operation.
Definition Wells.hpp:397
void write(MessageBufferType &buffer) const
MPI communication protocol–serialisation operation.
Definition Wells.hpp:387
static ConnectionFracturing serializationTestObject()
Create a serialisation test object.
Definition Wells.hpp:343
std::size_t numCells
Sample size.
Definition Wells.hpp:331
bool operator==(const ConnectionFracturing &that) const
Equality predicate.
Definition Wells.hpp:376
Statistics width
Statistical measures for connection's fracture fracture width.
Definition Wells.hpp:340
void serializeOp(Serializer &serializer)
Convert between byte array and object representation.
Definition Wells.hpp:361
Statistics rate
Statistical measures for connection's fracture fracture flow rate.
Definition Wells.hpp:337
Statistics press
Statistical measures for connection's fracture pressures.
Definition Wells.hpp:334
ConnectionFracturing fract
Connection level fracturing statistics.
Definition Wells.hpp:426
Definition Wells.hpp:1176