Skip to content

Commit

Permalink
parsing WELLSTRE and WINJGAS
Browse files Browse the repository at this point in the history
  • Loading branch information
GitPaean committed Nov 12, 2024
1 parent c52d807 commit 0eb6da9
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 13 deletions.
1 change: 1 addition & 0 deletions opm/input/eclipse/Schedule/ScheduleState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ bool ScheduleState::operator==(const ScheduleState& other) const {
&& this->bhp_defaults.get() == other.bhp_defaults.get()
&& this->source.get() == other.source.get()
&& this->wells == other.wells
&& this->inj_streams == other.inj_streams
&& this->groups == other.groups
&& this->vfpprod == other.vfpprod
&& this->vfpinj == other.vfpinj
Expand Down
8 changes: 8 additions & 0 deletions opm/input/eclipse/Schedule/ScheduleState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ namespace Opm {
return (ptr != nullptr);
}

void update(const K& key, std::shared_ptr<T> value) {
this->m_data[key] = value;
}


void update(T object) {
auto key = object.name();
Expand Down Expand Up @@ -500,6 +504,9 @@ namespace Opm {
// constant flux aquifers
std::unordered_map<int, SingleAquiferFlux> aqufluxs;
BCProp bcprop;
// injection streams for compostional STREAM injection using WINJGAS
map_member<std::string, std::vector<double>> inj_streams;

std::unordered_map<std::string, double> target_wellpi;
std::optional<NextStep> next_tstep;

Expand Down Expand Up @@ -535,6 +542,7 @@ namespace Opm {
serializer(wells);
serializer(aqufluxs);
serializer(bcprop);
serializer(inj_streams);
serializer(target_wellpi);
serializer(this->next_tstep);
serializer(m_start_time);
Expand Down
7 changes: 7 additions & 0 deletions opm/input/eclipse/Schedule/Well/Well.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ class Well {

double rsRvInj;

// injection stream compostion for compositional simulation
std::optional<std::vector<double>> gas_inj_composition{};

bool operator==(const WellInjectionProperties& other) const;
bool operator!=(const WellInjectionProperties& other) const;

Expand Down Expand Up @@ -226,6 +229,8 @@ class Well {
void update_uda(const UDQConfig& udq_config, UDQActive& udq_active, UDAControl control, const UDAValue& value);
void handleWTMULT(Well::WELTARGCMode cmode, double factor);

void setGasInjComposition(const std::vector<double>& composition);

template<class Serializer>
void serializeOp(Serializer& serializer)
{
Expand All @@ -244,6 +249,7 @@ class Well {
serializer(injectorType);
serializer(controlMode);
serializer(rsRvInj);
serializer(gas_inj_composition);
}
};

Expand Down Expand Up @@ -562,6 +568,7 @@ class Well {
double inj_temperature() const;
bool hasInjTemperature() const;
void setWellInjTemperature(const double temp);
void setGasInjComposition(const std::vector<double>& composition);
bool hasInjected( ) const;
bool hasProduced( ) const;
bool updateHasInjected( );
Expand Down
13 changes: 11 additions & 2 deletions opm/input/eclipse/Schedule/Well/WellInjectionProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ namespace Opm {
injectionControls(0),
injectorType(InjectorType::WATER),
controlMode(InjectorCMode::CMODE_UNDEFINED),
rsRvInj(0.0)
rsRvInj(0.0),
gas_inj_composition(std::nullopt)
{
}

Expand All @@ -82,6 +83,7 @@ namespace Opm {
result.injectorType = InjectorType::OIL;
result.controlMode = InjectorCMode::BHP;
result.rsRvInj = 11;
result.gas_inj_composition = std::vector<double>{1.0, 2.0, 3.0};

return result;
}
Expand Down Expand Up @@ -284,7 +286,8 @@ namespace Opm {
(injectionControls == other.injectionControls) &&
(injectorType == other.injectorType) &&
(controlMode == other.controlMode) &&
(rsRvInj == other.rsRvInj))
(rsRvInj == other.rsRvInj) &&
(gas_inj_composition == other.gas_inj_composition))
return true;
else
return false;
Expand Down Expand Up @@ -324,6 +327,7 @@ namespace Opm {
<< "injector type: " << InjectorType2String(wp.injectorType) << ", "
<< "control mode: " << WellInjectorCMode2String(wp.controlMode) << " , "
<< "rs/rv concentration: " << wp.rsRvInj << " }";
// TODO: add gas_inj_composition
}


Expand All @@ -344,6 +348,7 @@ namespace Opm {
controls.vfp_table_number = this->VFPTableNumber;
controls.prediction_mode = this->predictionMode;
controls.rs_rv_inj = this->rsRvInj;
// TODO: should we add gas_inj_composition here?

return controls;
}
Expand Down Expand Up @@ -491,5 +496,9 @@ namespace Opm {
else throw std::invalid_argument("Invalid keyword (MODE) supplied");
}

void Well::WellInjectionProperties::setGasInjComposition(const std::vector<double>& composition) {
gas_inj_composition = composition;
}


}
55 changes: 55 additions & 0 deletions opm/input/eclipse/Schedule/Well/WellKeywordHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,24 @@ void handleWCONPROD(HandlerContext& handlerContext)
}
}

void handleWELLSTRE(HandlerContext& handlerContext)
{
auto& inj_streams = handlerContext.state().inj_streams;
for (const auto& record : handlerContext.keyword) {
const std::string& stream_name = record.getItem("STREAM").getTrimmedString(0);
const auto& compostion = record.getItem("COMPOSITIONS").getData<double>();
// TODO: we need to check the number of the values in the composition is the same as the number of components

const double sum = std::accumulate(compostion.begin(), compostion.end(), 0.0);
if (std::abs(sum - 1.0) > std::numeric_limits<double>::epsilon()) {
std::string msg = fmt::format("The sum of the composition values for stream '{}' is not 1.0, but {}.", stream_name, sum);
throw OpmInputError(msg, handlerContext.keyword.location());
}
auto composition_ptr = std::make_shared<std::vector<double>>(std::move(compostion));
inj_streams.update(stream_name, composition_ptr);
}
}

void handleWELOPEN(HandlerContext& handlerContext)
{
const auto& keyword = handlerContext.keyword;
Expand Down Expand Up @@ -497,6 +515,41 @@ void handleWELOPEN(HandlerContext& handlerContext)
}
}

void handleWINJGAS(HandlerContext& HandlerContext)
{
for (const auto& record : HandlerContext.keyword) {
const std::string& wellNamePattern = record.getItem("WELL").getTrimmedString(0);
const auto well_names = HandlerContext.wellNames(wellNamePattern, false);
const std::string& fluid_nature = record.getItem("FLUID").getTrimmedString(0);
// TODO: technically, only the firt two characters are significant
// TODO: we need to test it out whether only the first two characters matter
if (fluid_nature != "STREAM") {
std::string msg = fmt::format("The fluid nature '{}' is not supported in WINJGAS keyword.", fluid_nature);
throw OpmInputError(msg, HandlerContext.keyword.location());
}
const std::string& stream_name = record.getItem("STREAM").getTrimmedString(0);
// TODO: we do not handle other records for now

// we make sure the stream is defined in WELLSTRE keyword
const auto& inj_streams = HandlerContext.state().inj_streams;
if (!inj_streams.has(stream_name)) {
std::string msg = fmt::format("The stream '{}' is not defined in WELLSTRE keyword.", stream_name);
throw OpmInputError(msg, HandlerContext.keyword.location());
}

auto well2 = HandlerContext.state().wells.get(well_names[0]);
// if (well2.isProducer()) {
// std::string msg = fmt::format("The well '{}' is a producer, not an injector.", well_names[0]);
// throw OpmInputError(msg, HandlerContext.keyword.location());
// }
auto injection = std::make_shared<Well::WellInjectionProperties>(well2.getInjectionProperties());

// TODO: should we make it a injection event?
const auto& inj_stream = inj_streams.get(stream_name);
injection->setGasInjComposition(inj_stream);
}
}

void handleWELSPECS(HandlerContext& handlerContext)
{
using Kw = ParserKeywords::WELSPECS;
Expand Down Expand Up @@ -892,7 +945,9 @@ getWellHandlers()
{ "WCONINJE", &handleWCONINJE },
{ "WCONINJH", &handleWCONINJH },
{ "WCONPROD", &handleWCONPROD },
{ "WINJGAS", &handleWINJGAS },
{ "WELOPEN" , &handleWELOPEN },
{ "WELLSTRE", &handleWELLSTRE },
{ "WELSPECS", &handleWELSPECS },
{ "WELTARG" , &handleWELTARG },
{ "WELTRAJ" , &handleWELTRAJ },
Expand Down
17 changes: 6 additions & 11 deletions opm/input/eclipse/share/keywords/001_Eclipse300/W/WELLSTRE
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@
"value_type": "STRING"
},
{
"item": 2,
"name": "XMOLE1",
"value_type": "DOUBLE",
"dimension": "1"
},
{
"item": 3,
"name": "XMOLE2",
"value_type": "DOUBLE",
"dimension": "1"
}
"item": 2,
"name": "COMPOSITIONS",
"value_type": "DOUBLE",
"dimension": "1",
"size_type": "ALL"
}
]
}

0 comments on commit 0eb6da9

Please sign in to comment.