-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fully internalized the JFUNC keyword #970
Conversation
See #956 for prior discussions around the JFUNC keyword. |
{ | ||
public: | ||
|
||
enum Flag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should start using the "new" enum class
consistently: http://www.cprogramming.com/c++11/c++11-nullptr-strongly-typed-enum-class.html
|
||
inline void init(const DeckKeyword& kw) { | ||
const auto& rec = kw.getRecord(0); | ||
if (rec.hasItem("FLAG")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as the DeckKeyword
instance indeed corresponds to JFUNC
keyword this test will always return true; and if it returns false that is not because a default has been applied - but rather because the wrong keyword has been passed in - which is throw material.
XY, X, Y, Z | ||
}; | ||
|
||
inline void init(const DeckKeyword& kw) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could just be constructor - no need to go through a separate init
function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could maybe implement operator bool( )
in the Jfunc
class, then the instance could be constructed as part of the TableManager
initialization list, and the Jfunc
member instance could just evaluate to false if the Deck
does not have the JFUNC
keyword.
|
||
class DeckKeyword; | ||
|
||
class JFuncTable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not really a table - just the JFunc
keyword - which will be used when interpreting tables.
if (flag != GAS) | ||
owSurfaceTension = rec.getItem("OW_SURFACE_TENSION").get<double>(0); | ||
|
||
if (rec.hasItem("ALPHA_FACTOR")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about hasItem
- it is in my opinion not necessary, but if you want to check for default behavior it is the item
which should be checked:
const auto item = rec.getItem("ALPHA_FACTOR"):
// Check if the ALPHA_FACTOR has a value - as long a default is specified in the Json this will *always* return true:
if ( item.hasValue(0))
alphaFactor = item.get<double>( 0 );
// Check a value has been set explicitly:
if (!item.defaultApplied(0))
alphaFactor = item.get<double>( 0 );
} | ||
|
||
private: | ||
Flag flag = BOTH; // JFUNC flag: WATER, GAS, or BOTH. Default BOTH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if these default values were removed - they are already specified in the Json configuration, and if the values are requested unconditionally from the deck we will correctly get either the default or the value entered explicitly.
Thanks for the review, Joakim. I've fixed all of the items, except the one where you request deleting the default values. Hold off merging anyway until we synchronize efforts with Andreas. |
Thanks for the review, Joakim. I've fixed all of the items. |
A quick note about commit --fixup: If you have multiple fixups all destined to be squashed into one commit you need to fixup into the same base commit, not the children, for autosquash to pick up on them. |
Yeah, I just let emacs do the job. :) |
else if (kw_flag == "WATER") | ||
flag = Flag::WATER; | ||
else if (kw_flag == "GAS") | ||
flag = Flag::GAS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is flag mandatory, or is it optional (defaulted to BOTH maybe)? If the former you need to set it unconditionally, ideally through its declaration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in JFUNC
, flag
is optional and defaulted to BOTH
. Meaning that if it is not specified in deck, through the JFUNC
json, it will be given as BOTH
.
There is a potential issue here, namely if a user specifies JFUNC GARBAGE/
in the deck. Then we might reach a state where we read an uninitialized flag
.
I could add a final else throw unrecognized flag GARBAGE
if you'd like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a good idea yeah, otherwise we potentially reach a much more subtle wrong state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm now throwing on garbage FLAG
or DIRECTION
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess throwing on invalid FLAG / DIRECTION is a good idea.
@andlaus ping |
pong: I had no time for this this week. (have been busy with making flow_ebos merge-ready.) |
@andlaus ping |
pong. on it: probably next week. (if you want to speed things up, you may also do the opm-material part.) |
@andlaus ping (This will probably be merged pretty soon.) |
if |
@pgdr: could you please split the JFUNC-keyword internalization part into a separate PR where the tables are left as they are? I think that the JFUNC internalization is a good thing to have, whereas I'm not so sure about the tables. |
Why are you not so sure about the tables? |
I'm not sure on whether the table stuff is worth it because adapting the opm-material side to the table semantics is quite a bit of non-obvious work (as you've already discovered yourself?), most likely it does not make the resulting code easier to understand and the result may be even a bit slower than the current hack. Finally, it makes the semantics on the opm-parser side more complicated. (a.k.a. "when am I allowed to call getPcwoColumn() again?") anyway, the JFUNC internalization is uncontroversial, so let's do this step-by-step. |
Third time's the charm. We do now not throw on incorrect reading (or lack) of JFUNC column. This will be reversed later when opm-material is updated. |
* Fully internalized JFUNC * Added JFunc.cpp, throw on wrong FLAG/DIR in JFUNC kw * added tests for JFUNC in TableManagerTests * added protected member m_jfunc to SimpleTable * Added getJFuncColumn to accompany getPcowColumn * Throws if pressure or jfunc is accessed inappropriately * ... meaning if getPcowColumn is called when JFUNC is in deck, or * getJFuncColumn is called when JFUNC is not in deck * added tests for throwing and for getJFuncColumn * SimpleTable.getColumn("PCOW/PCOG") throws if JFUNC * In the event that one tries to get "PCOW" or "PCOG" via getColumn * ... this will throw if JFUNC is present in the deck. * Added tests.
* no throw on JFUNC abuse, std::cerr * removed 'get' from function names
@andlaus @jokva @joakim-hove I'm merging this tomorrow if I don't hear anything from you. |
Go for it. |
go ahead. I'll convert opm-material to the internalized version of the keyword shortly thereafter. |
JFuncTable.hpp
getJFuncColumn()
andgetJFuncTable()
in TableManager