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

Stop Processing if COPYing From Undefined Source Array #4109

Merged
merged 5 commits into from
Aug 20, 2024

Conversation

bska
Copy link
Member

@bska bska commented Jun 17, 2024

This PR adds defined value checking to the source array from which we're copying in a COPY operation–either with the COPY or with the COPYREG keywords. We count the number of source array values which do not have the status of deck_value and if this count is positive, then we throw an OpmInputError exception which halts further input processing.

As an example of this behaviour, the (deliberately faulty) setup

EQUALS
-- SGL not defined prior to this point
  'SGL' 0.0 2* 2* 1 5 /
/

COPY
  SGL SWL 2* 2* 4 7 /
/

will generate an "Error" of the form

Error: Problem with keyword COPY
In USER_ERR_COPY_BOX_PARTIALLY_UNDEF.DATA line 195
Copying from source array SGL in BOX (1-13, 1-22, 4-7)
would generate an undefined result in 572 blocks of target array SWL.

and stop input processing.

Similarly, For operations other than assignment (EQUALS keyword), this PR ensures that the array being mutated already exists in the input. In particular, this means that a request of the form

ADD
  SGU 0.123 /
/

will halt input processing and generate an "Error" of the form

Error: Problem with keyword ADD
In USER_ERR_ADD.DATA line 202
Target array SGU must already exist when operated upon in ADD.

unless the SGU array has already been assigned earlier.

To this end, repurpose the second parameter to member function

FieldProps::try_get<>()

and make this a bitmask of flags instead of a single bool. The currently supported flags are AllowUnsupported and MustExist
with the former representing the original 'bool' parameter and the second requesting that the property array must already exist for the request to succeed.

@bska
Copy link
Member Author

bska commented Jun 17, 2024

Note: I am creating this PR in draft mode because it depends on, and contains, the earlier PR #4103. I will keep the PR in a draft state until it is ready for review and merging.

@bska bska force-pushed the copy-undef-src-array branch 5 times, most recently from ce5ee02 to 5d323c5 Compare June 18, 2024 18:14
@bska
Copy link
Member Author

bska commented Jun 18, 2024

jenkins build this please

@bska bska force-pushed the copy-undef-src-array branch 8 times, most recently from 3553c46 to aebab88 Compare June 26, 2024 07:37
@bska bska force-pushed the copy-undef-src-array branch 10 times, most recently from 4d7b24a to fced603 Compare July 2, 2024 16:05
@bska bska force-pushed the copy-undef-src-array branch 5 times, most recently from 1699f86 to 67b9603 Compare July 9, 2024 10:58
@bska bska force-pushed the copy-undef-src-array branch 4 times, most recently from 66ff822 to bcf1e6a Compare August 19, 2024 10:27
@bska
Copy link
Member Author

bska commented Aug 19, 2024

jenkins build this please

@bska
Copy link
Member Author

bska commented Aug 19, 2024

I have corrected the unexpected PORV related problem that presented the last time I updated this PR. I now consider this to be functionally complete and I'm marking it as "ready for review".

@bska bska marked this pull request as ready for review August 19, 2024 14:31
@bska
Copy link
Member Author

bska commented Aug 20, 2024

jenkins build this please

Copy link
Member

@akva2 akva2 left a comment

Choose a reason for hiding this comment

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

Two small suggestions that you may or may not take.

const T scalar_value,
const std::vector<Box::cell_index>& index_list)
{
if (op == Fieldprops::ScalarOperation::EQUAL) {
Copy link
Member

Choose a reason for hiding this comment

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

switch?

const Fieldprops::FieldData<T>& field_data() const
{
this->verify_status();
return *this->data_ptr;
}

/// Property validity predicate.
///
/// Returns true if propery exists and has well defined data
Copy link
Member

@akva2 akva2 Aug 20, 2024

Choose a reason for hiding this comment

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

suggestion: s/well/properly or the likes. the term 'well' is a bit reserved in the context. also 'property'

@@ -492,7 +492,7 @@ class FieldProps {

/// Property validity predicate.
///
/// Returns true if propery exists and has well defined data
/// Returns true if propery exists and has fully defined data
Copy link
Member

Choose a reason for hiding this comment

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

properTy

@bska
Copy link
Member Author

bska commented Aug 20, 2024

Two small suggestions that you may or may not take.

Thanks a lot for looking at this. I've pushed an update to address your comments. I'm always a little on the fence when it comes to switching on enums because while the set of valid enumerators is fixed, and typically small, the possible enumeration values are of course all of the values allowed by the underlying arithmetic type. That said, I replaced the if/else chain with a switch and a throw for unsupported enumeration values.

@bska
Copy link
Member Author

bska commented Aug 20, 2024

jenkins build this please

@bska
Copy link
Member Author

bska commented Aug 20, 2024

jenkins build this please

1 similar comment
@akva2
Copy link
Member

akva2 commented Aug 20, 2024

jenkins build this please

This overload includes more context and enables generating more
descriptive diagnostic messages.
This commit makes the backend implementations of ADD, MULTIPLY, &c
capable of halting processing if we encounter any undefined source
elements.  We nevertheless maintain the definition of "defined" as

    value::has_value()

(from the value_status.hpp header), at least for the time being, as
changing the definition requires making more parts of the array
processing aware of the currently active section.

The new helper function reject_undefined_operation() will throw an
OpmInputError exception with (hopefully) enough context that fixing
the input will be easier.

While here, make the apply() function private to the FieldProps.cpp
implementation file.  It was already marked 'static' and does not
need access to any of the FieldProps data members.
This commit adds defined value checking to the source array from
which we're copying in a COPY operation--either with the COPY or
with the COPYREG keywords.  We count the number of source array
values which do not have the status of 'deck_value' and if this
count is positive, then we throw an OpmInputError exception which
halts further input processing.

As an example of this behaviour, the (deliberately faulty) setup

    EQUALS
    -- SGL not defined prior to this point
     'SGL' 0.0 2* 2* 1 5 /
    /

    COPY
      SGL SWL 2* 2* 4 7 /
    /

will generate an "Error" of the form

    Error: Problem with keyword COPY
    In USER_ERR_COPY_BOX_PARTIALLY_UNDEF.DATA line 195
    Copying from source array SGL in BOX (1-13, 1-22, 4-7)
    would generate an undefined result in 572 blocks of target array SWL.

and stop input processing.
For operations other than assignment (EQUALS keyword), this commit
ensures that the array being mutated already exists in the input.
In particular, this means that a request of the form

    ADD
      SGU 0.123 /
    /

will halt input processing and generate an "Error" of the form

    Error: Problem with keyword ADD
    In USER_ERR_ADD.DATA line 202
    Target array SGU must already exist when operated upon in ADD.

unless the 'SGU' array has already been assigned earlier.

To this end, repurpose the second parameter to member function

    FieldProps::try_get<>()

and make this a bitmask of flags instead of a single 'bool'.  The
currently supported flags are 'AllowUnsupported' and 'MustExist'
with the former representing the original 'bool' parameter and the
second requesting that the property array must already exist for the
request to succeed.
In particular,

  1. Replace if/else chain by switch
  2. Replace 'well formed' with 'fully defined' in documentation
@bska
Copy link
Member Author

bska commented Aug 20, 2024

jenkins build this please

@bska
Copy link
Member Author

bska commented Aug 20, 2024

PR approved and build check is green. I'll merge into master.

@bska bska merged commit db97e3f into OPM:master Aug 20, 2024
1 check passed
@bska bska deleted the copy-undef-src-array branch August 20, 2024 18:05
bska added a commit to bska/opm-common that referenced this pull request Sep 26, 2024
The existence checks introduced in commit 90be0956d0 (PR OPM#4109)
turned out to be a little too restrictive.  Recent experience
suggests that we need to permit array operations like ADD or
MULTIPLY on the MULT* arrays (MULT[XYZ] and MULT[XYZ]-) even if
these arrays have not yet been explicitly defined in the input deck.

This commit re-enables those array operations for property arrays
whose 'multiplier' flag is 'true'.
bska added a commit to bska/opm-common that referenced this pull request Sep 26, 2024
The existence checks introduced in commit 90be095 (PR OPM#4109)
turned out to be a little too restrictive.  Recent experience
suggests that we need to permit array operations like ADD or
MULTIPLY on the MULT* arrays (MULT[XYZ] and MULT[XYZ]-) even if
these arrays have not yet been explicitly defined in the input deck.

This commit re-enables those array operations for property arrays
whose 'multiplier' flag is 'true'.
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.

2 participants