20 #ifndef OPM_OUTPUT_WELLS_HPP
21 #define OPM_OUTPUT_WELLS_HPP
23 #include <initializer_list>
28 #include <type_traits>
47 enum class opt : uint32_t {
55 using enum_size = std::underlying_type< opt >::type;
58 inline bool has( opt )
const;
62 inline double get( opt m )
const;
65 inline double get( opt m,
double default_value )
const;
69 inline Rates&
set( opt m,
double value );
72 inline bool any()
const noexcept;
75 double& get_ref( opt );
76 const double& get_ref( opt )
const;
78 opt mask =
static_cast< opt
>( 0 );
88 using active_index = size_t;
89 static const constexpr
int restart_size = 2;
94 double reservoir_rate;
103 std::vector< Completion > completions;
105 inline bool flowing()
const noexcept;
112 double get(
const std::string& well_name , Rates::opt m)
const {
113 const auto& well = this->find( well_name );
114 if( well == this->end() )
return 0.0;
116 return well->second.rates.get( m, 0.0 );
120 double get(
const std::string& well_name , Completion::active_index completion_grid_index, Rates::opt m)
const {
121 const auto& witr = this->find( well_name );
122 if( witr == this->end() )
return 0.0;
124 const auto& well = witr->second;
125 const auto& completion = std::find_if( well.completions.begin() ,
126 well.completions.end() ,
128 return c.index == completion_grid_index; });
130 if( completion == well.completions.end() )
133 return completion->rates.get( m, 0.0 );
143 const auto mand =
static_cast< enum_size
>( this->mask )
144 & static_cast< enum_size >( m );
146 return static_cast< opt
>( mand ) == m;
150 if( !this->
has( m ) )
151 throw std::invalid_argument(
"Uninitialized value." );
153 return this->get_ref( m );
156 inline double Rates::get( opt m,
double default_value )
const {
157 if( !this->
has( m ) )
return default_value;
159 return this->get_ref( m );
163 this->get_ref( m ) = value;
165 this->mask =
static_cast< opt
>(
166 static_cast< enum_size
>( this->mask ) |
167 static_cast< enum_size >( m )
183 inline const double& Rates::get_ref( opt m )
const {
185 case opt::wat:
return this->wat;
186 case opt::oil:
return this->oil;
187 case opt::gas:
return this->gas;
188 case opt::polymer:
return this->polymer;
189 case opt::solvent:
return this->solvent;
192 throw std::invalid_argument(
193 "Unknown value type '"
194 + std::to_string( static_cast< enum_size >( m ) )
199 inline double& Rates::get_ref( opt m ) {
200 return const_cast< double&
>(
201 static_cast< const Rates*
>( this )->get_ref( m )
206 return static_cast< enum_size
>( this->mask ) != 0;
209 inline bool Well::flowing() const noexcept {
210 return this->rates.any();
216 #endif //OPM_OUTPUT_WELLS_HPP
Rates & set(opt m, double value)
Set the value specified by m.
Definition: Wells.hpp:162
bool has(opt) const
Query if a value is set.
Definition: Wells.hpp:142
double get(opt m) const
Read the value indicated by m.
Definition: Wells.hpp:149
bool any() const noexcept
true if any option is set; false otherwise
Definition: Wells.hpp:205
Definition: Wells.hpp:109