Skip to content
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

Merged
merged 2 commits into from
Dec 29, 2016
Merged

Fully internalized the JFUNC keyword #970

merged 2 commits into from
Dec 29, 2016

Conversation

pgdr
Copy link
Contributor

@pgdr pgdr commented Nov 9, 2016

  • Fully internalized the JFUNC keyword into class JFuncTable.hpp
  • Added JFUNC flag, getJFuncColumn() and getJFuncTable() in TableManager
  • 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
  • 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.

@pgdr pgdr changed the title Fully internalized the JFUNC keyword WIP Fully internalized the JFUNC keyword Nov 9, 2016
@pgdr
Copy link
Contributor Author

pgdr commented Nov 9, 2016

See #956 for prior discussions around the JFUNC keyword.

@pgdr pgdr changed the title WIP Fully internalized the JFUNC keyword Fully internalized the JFUNC keyword Nov 9, 2016
{
public:

enum Flag {
Copy link
Member

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")) {
Copy link
Member

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) {
Copy link
Member

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?

Copy link
Member

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
Copy link
Member

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"))
Copy link
Member

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
Copy link
Member

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.

@pgdr
Copy link
Contributor Author

pgdr commented Nov 10, 2016

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.

@pgdr
Copy link
Contributor Author

pgdr commented Nov 10, 2016

Thanks for the review, Joakim. I've fixed all of the items.

@jokva
Copy link
Contributor

jokva commented Nov 10, 2016

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.

@pgdr
Copy link
Contributor Author

pgdr commented Nov 10, 2016

Yeah, I just let emacs do the job. :)

else if (kw_flag == "WATER")
flag = Flag::WATER;
else if (kw_flag == "GAS")
flag = Flag::GAS;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@pgdr
Copy link
Contributor Author

pgdr commented Nov 17, 2016

@andlaus ping

@andlaus
Copy link
Contributor

andlaus commented Nov 17, 2016

pong: I had no time for this this week. (have been busy with making flow_ebos merge-ready.)

@pgdr
Copy link
Contributor Author

pgdr commented Nov 24, 2016

@andlaus ping

@andlaus
Copy link
Contributor

andlaus commented Nov 24, 2016

pong. on it: probably next week. (if you want to speed things up, you may also do the opm-material part.)

@pgdr
Copy link
Contributor Author

pgdr commented Nov 28, 2016

@andlaus ping

(This will probably be merged pretty soon.)

@andlaus
Copy link
Contributor

andlaus commented Nov 28, 2016

(This will probably be merged pretty soon.)

if flow_ebos (and flow_legacy) continue to work for Model 2.2 after the merge, I don't have any objections.

@andlaus
Copy link
Contributor

andlaus commented Dec 7, 2016

@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.

@pgdr
Copy link
Contributor Author

pgdr commented Dec 7, 2016

Why are you not so sure about the tables?

@andlaus
Copy link
Contributor

andlaus commented Dec 7, 2016

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.

@pgdr
Copy link
Contributor Author

pgdr commented Dec 27, 2016

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.

Pål Grønås Drange added 2 commits December 28, 2016 19:20
* 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
@pgdr
Copy link
Contributor Author

pgdr commented Dec 28, 2016

@andlaus @jokva @joakim-hove I'm merging this tomorrow if I don't hear anything from you.

@jokva
Copy link
Contributor

jokva commented Dec 28, 2016

Go for it.

@andlaus
Copy link
Contributor

andlaus commented Dec 28, 2016

go ahead. I'll convert opm-material to the internalized version of the keyword shortly thereafter.

@pgdr pgdr merged commit 69c26c7 into OPM:master Dec 29, 2016
@pgdr pgdr deleted the jfunc-pt2 branch December 29, 2016 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants