You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While working on PR #684 I noticed again that there are a lot of enums defined in the rest of OPM that also exist (at least in a similar way) already in opm-parser. To construct the former we always use a switch statement on the original enum. Somehow this seems like a lot of unneeded branching and code to me.
Take for example the following:
from opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp
Mode Opm::InjectionControl::mode(Opm::WellInjector::ControlModeEnum controlMode)
{
switch ( controlMode ) {
case Opm::WellProducer::ORAT:
return ORAT;
case Opm::WellProducer::WRAT:
return WRAT;
case Opm::WellProducer::GRAT:
return GRAT;
case Opm::WellProducer::LRAT:
return LRAT;
case Opm::WellProducer::CRAT:
return CRAT;
case Opm::WellProducer::RESV:
return RESV;
case Opm::WellProducer::BHP:
return BHP;
case Opm::WellProducer::THP:
default:
throwstd::invalid_argument("unhandled enum value");
}
At least in this special case the only feature here is checking that
the enum is not CMODE_UNDEFINED. (But maybe I am missing something
here.) What I am wondering is, if this check is not done by opm-parser
anyway.
This could be achieved a lot easier (if we want to keep the different
enums).
We just make sure that the values are the same and skip the undefined one:
Being a dardevil, might I even suggest to get rid of the duplicate ones in OPM that only exist for historic reasons (read pre-opm-parser times).
BTW: I am aware that there are other enums that are a little bit different (e.g. 0 starting in core, and starting with 1 in dune-cornerpoint). Still I would think that for most of them there is a formula to convert between them that should be used rather than a switch statement.
The text was updated successfully, but these errors were encountered:
I agree with your issue, but you should be aware that it stems from a combination of historical baggage and dependency inversion: opm-parser is much newer than the wells code in opm-core so it could not have used the opm-parser enums when it was written. On the other hand opm-parser currently cannot use anything in opm-core because of the dependency order so new enums needed to be created. If you want to reduce these redundancies: perfect! patches are very welcome :)
I agree that this is weird - and in my opinion the enums in opm-parser should be used. At the time opm-parser was shoehorned in we tried to make the changes as non-obtrusive as possible for the other modules; that is at least the recent background.
Hi,
While working on PR #684 I noticed again that there are a lot of enums defined in the rest of OPM that also exist (at least in a similar way) already in opm-parser. To construct the former we always use a switch statement on the original enum. Somehow this seems like a lot of unneeded branching and code to me.
Take for example the following:
from opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp
from opm/core/wells/WellsManager_iml.hpp:
from opm/core/wells/WellsManager.cpp:
At least in this special case the only feature here is checking that
the enum is not CMODE_UNDEFINED. (But maybe I am missing something
here.) What I am wondering is, if this check is not done by opm-parser
anyway.
This could be achieved a lot easier (if we want to keep the different
enums).
We just make sure that the values are the same and skip the undefined one:
and use a simple static cast for the conversion:
Being a dardevil, might I even suggest to get rid of the duplicate ones in OPM that only exist for historic reasons (read pre-opm-parser times).
BTW: I am aware that there are other enums that are a little bit different (e.g. 0 starting in core, and starting with 1 in dune-cornerpoint). Still I would think that for most of them there is a formula to convert between them that should be used rather than a switch statement.
The text was updated successfully, but these errors were encountered: