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

Smspec cmp + correct padding of ecl_kw string keywords #146

Merged
merged 9 commits into from
Aug 5, 2017

Conversation

joakim-hove
Copy link
Contributor

@joakim-hove joakim-hove commented Jul 28, 2017

Task
This was mostly a wild goose chase trying to find a problem with the summary files generated by OPM. The third commit turned out to be the crucial one. The sorting is also valuable - although not as essential.

Approach

  1. Make sure every item in ecl_kw of type ECL_STRING is space padded to correct length.
  2. Implemented function to compare smspec node instances.

Pre un-WIP checklist

  • Statoil tests pass locally

@joakim-hove joakim-hove force-pushed the smspec-cmp branch 9 times, most recently from b05cb72 to 484cc4a Compare July 31, 2017 06:03
@joakim-hove joakim-hove changed the title WIP: Smspec cmp Smspec cmp Jul 31, 2017
@joakim-hove joakim-hove changed the title Smspec cmp Smspec cmp + correct padding of ecl_kw string keywords Jul 31, 2017
ecl_string[i] = ' ';

ecl_string[type_len] = '\0';
}
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 the following is more readable:

for (int i = 0; i < type_len; ++i) {
  ecl_string[i] = (i < input_len) ? s[i] : ' ';
}

And also, you don't need the { and the } guards here.

if (node2_early) {
if (!node1_early)
return 1;
}
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 the following is more readable:

  if (node1_early && !node2_early)
    return -1;
  if (!node1_early && node2_early)
    return 1;

smspec_node_free( well_node1_2 );
smspec_node_free( well_node2_2 );
//smspec_node_free( well_node_dummy );
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple of out-commented lines here, should they be removed? (Perhaps they are removed in a later commit.)

return True
else:
return False

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be

    return self.cmp(other) < 0

if cmp > 0:
return True
else:
return False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above, but with >

if cmp == 0:
return True
else:
return False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return self.cmp(other) == 0

self.assertEqual( node3.getNum( ) , 1 )
self.assertTrue( node3.isTotal( ))

self.assertTrue( node1 < node3 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer self.assertLess(node1, node3)

self.assertTrue( node1 < node3 )
self.assertTrue( node2 > node3 )
self.assertTrue( node1 == node1 )
self.assertFalse( node1 == node2 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertEqual and assertNotEqual.

if (cmp == 0)
return true;
else
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not

return smspec_node_cmp(node1, node2) == 0;

?

@@ -23,6 +23,17 @@

#include <ert/ecl/ecl_smspec.h>

void test_sort( ecl_smspec_type * smspec )
{
ecl_smspec_sort( smspec );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my paranoia speaking, but could you add

test_assert_true(ecl_smspec_num_nodes(smspec) == 10);

for 10 being the correct size of smspec?

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 quite frankly do not know the number of nodes, but I have added a check verifying that is not changed by the sort.

Copy link
Contributor

@pgdr pgdr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some comments, but they are all based on taste.

Merge at will, but please at least consider my comments.

@joakim-hove
Copy link
Contributor Author

Thank you for the review - of course I will consider your comments.

@joakim-hove
Copy link
Contributor Author

OK - I have addressed all the comments except: #146 (review) - where I really thought my initial version was more readable. Will merge when/if the rebased tests are green.

Due to the on-disk format the strings in ecl_kw instances of type
ECL_STRING and ECL_CHAR must be space padded to the correct length.
We will now create smspec nodes with WGNAME == DUMMY_WELL, however these
smspec nodes will be marked with the valid flag set to false, and they
will be ignored in the index.
The smspec_node_equal( ) function is implemented on top of the
smspec_node_cmp( ) function. One important change from this is that the
internal stoarge index - param_index  - is no longer taken into account
when comparing smspec nodes.
@pgdr
Copy link
Contributor

pgdr commented Aug 4, 2017

Fair enough, thanks for addressing!

Please merge at will.

@pgdr pgdr merged commit 26ff6d7 into equinor:master Aug 5, 2017
@pgdr
Copy link
Contributor

pgdr commented Aug 5, 2017

Thar she blows!

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.

None yet

2 participants