Skip to content

Correct handling of overlapping NNC and EDITNNC#6875

Merged
blattms merged 2 commits intoOPM:masterfrom
daavid00:nncs
Mar 27, 2026
Merged

Correct handling of overlapping NNC and EDITNNC#6875
blattms merged 2 commits intoOPM:masterfrom
daavid00:nncs

Conversation

@daavid00
Copy link
Copy Markdown
Member

@daavid00 daavid00 commented Feb 24, 2026

Avoid writing twice to the INIT the NNCTRANS.

Before merging, adding this deck to the regression tests:

OPM/opm-tests#1502

Depends on OPM/opm-common#5025

Closes #6865
Closes OPM/opm-common#3470

@daavid00 daavid00 added the manual:irrelevant This PR is a minor fix and should not appear in the manual label Feb 24, 2026
|| directVerticalNeighbors(*cartDims, cartesianToActive, cellIdx1, cellIdx2);
};

auto alreadyAssigned = [outputNnc = &this->outputNnc_]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why capture as pointer? capture as ref, ie, [&outputNnc = this->outputNnc_]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, PR updated.

@daavid00 daavid00 marked this pull request as draft February 25, 2026 06:14
@daavid00
Copy link
Copy Markdown
Member Author

In draft mode until how to handle this is decided in #6865

@blattms
Copy link
Copy Markdown
Member

blattms commented Feb 25, 2026

I don't think this correct if the value in EDITNNC is not 0.

Because we apply and internalize EDITNNC for an input NNC in OPM/opm-common#5025, we will reapply the value in EDITNNC in the EDIT section another time in Transmissibility::applyEditNncToGridTrans. Note that there we apply one factor that incorporates all EDITNNC internalized from the GRID/EDIT section and specified in the SCHEDULE section.

I don't have the complete picture, yet, but maybe we should not apply EDITNNC to input NNCs in opm-common and always internalize. Then all NNCs are treated equal. Not sure whether we need to do something addtional for output, though,

}

if (isNumAquConn(cc1, cc2) || ! isDirectNeighbours(cc1, cc2)) {
if (isNumAquConn(cc1, cc2) || (! isDirectNeighbours(cc1, cc2) && ! alreadyAssigned(cc1, cc2))) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure what this change does and whether it is correct.

For each cell pair in (at least) CpGrid there is only one intersection, even if there is an explicitly specified NNC and one that is created because of the grid topology. (Because of this and the additional output of those NNCs, we substract the transmissibility of the explicitly specified NNC below).

If I understand this change correctly. then `alreadyAssigned returns true if there was an NNC in the deck for this cell pair. Doesn't this mean that the transmissibility of an NNC created by the topology of the grid is not output at all if there was also an explicit NNC in the deck?

Copy link
Copy Markdown
Member Author

@daavid00 daavid00 Feb 26, 2026

Choose a reason for hiding this comment

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

In master using the test case in OPM/opm-tests#1502 (i.e., internally the generated NNC has a value of 0.10000000E+01) with:

NNC 1 1 1 2 1 2 6666, EDITNNCR 1 1 1 2 1 2 9999 -> TRANNNC 0.99990000E+04 0.33330000E+04
NNC 1 1 1 2 1 2 6666, EDITNNC   1 1 1 2 1 2 10 -> TRANNNC 0.66661000E+05 0.10000000E+01

Here in EclGenericWriter_impl.hpp the total transmissibility is assigned, and with this PR we avoid writing duplicated values, i.e., with these PRs:

NNC 1 1 1 2 1 2 6666, EDITNNCR 1 1 1 2 1 2 9999 -> TRANNNC 0.99990000E+04
NNC 1 1 1 2 1 2 6666, EDITNNC 1 1 1 2 1 2 10 -> TRANNNC 0.66760000E+04

On a related note I still think EDITNNC/EDITNNCR should be applied only to internally generated NNCs and not the ones given in the deck using the keyword NNC. I would be happy to update the code in different PRs if that is the case.

@daavid00
Copy link
Copy Markdown
Member Author

Marking the PR as ready to review. Two decks are added to the tests for these OPM/opm-tests#1502 (planning on adding them to the regression tests prior merging).

@daavid00 daavid00 marked this pull request as ready for review March 11, 2026 16:05
@daavid00 daavid00 requested a review from blattms March 11, 2026 16:06
@blattms
Copy link
Copy Markdown
Member

blattms commented Mar 17, 2026

jenkins build this please.

Copy link
Copy Markdown
Member

@blattms blattms left a comment

Choose a reason for hiding this comment

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

I am not finished (transmissibility is missing), but I need a break.

The logic during output is now really complicated and has a lot of (linear) searches in it. This might degrade performance quite a bit and we might need to find a better way.

Comment thread opm/simulators/flow/EclGenericWriter_impl.hpp
Comment thread opm/simulators/flow/EclGenericWriter_impl.hpp
if (level == 0) {
auto candidate = std::lower_bound(nncData.begin(), nncData.end(),
NNCdata { originCartIdxIn, originCartIdxOut, 0.0 });
const auto transMlt = transMult.getRegionMultiplierNNC(originCartIdxIn, originCartIdxOut);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This might be expensive please only do it if we found a matching nnc.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Looking at other places where getRegionMultiplierNNC is called (e.g., here), then we also do not check for matching nncs, but instead this is done once inside the method.

Comment thread opm/simulators/flow/EclGenericWriter_impl.hpp
}
}
if (foundNncEditr) {
break;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't understand this break. Where is the connection to editNNC below, that is skipped.
If this is needed then please add a comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added a comment

Comment thread opm/simulators/flow/EclGenericWriter_impl.hpp
Comment thread opm/simulators/flow/EclGenericWriter_impl.hpp
break;
}
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should prevent this linear search. It would take a lot of time.

Do you see a way?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not really, but this search happens only once before writing the INIT and looping for nncData, then after updating all binary search as you suggested, then having this linear search should be fine.

@blattms
Copy link
Copy Markdown
Member

blattms commented Mar 17, 2026

jenkins build this please

@blattms
Copy link
Copy Markdown
Member

blattms commented Mar 17, 2026

Sorry somehow github messed my comments made on multiple lines.

@blattms
Copy link
Copy Markdown
Member

blattms commented Mar 17, 2026

benchmark please

Comment thread opm/simulators/flow/Transmissibility_impl.hpp
Comment thread opm/simulators/flow/EclGenericWriter_impl.hpp
@daavid00 daavid00 force-pushed the nncs branch 2 times, most recently from 882b99f to c7aa24a Compare March 18, 2026 16:50
@daavid00
Copy link
Copy Markdown
Member Author

Thanks @blattms for your review, I have updated the PR and tried to answer your comments. Let me know if this need further changes.

@blattms
Copy link
Copy Markdown
Member

blattms commented Mar 19, 2026

jenkins build this please

@blattms
Copy link
Copy Markdown
Member

blattms commented Mar 19, 2026

I think we will need to investigate the currently failing regression tests once @daavid00 is back:

In addition we might want to add further regression tests before merging.

Copy link
Copy Markdown
Member

@blattms blattms left a comment

Choose a reason for hiding this comment

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

🙈 my fault. Should have added the opm-common companion PR when calling jenkins.

I am running jenkins another time in opm-common and will merge if this succeeds as expected.

@blattms blattms merged commit 5145ab5 into OPM:master Mar 27, 2026
1 of 2 checks passed
@daavid00 daavid00 deleted the nncs branch March 27, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

manual:irrelevant This PR is a minor fix and should not appear in the manual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible BUG with NNC and EDITNNC Possible bug when internalizing EDITNNC

3 participants