Skip to content

Conversation

@GitPaean
Copy link
Member

@GitPaean GitPaean commented Aug 6, 2025

The main purpose of this PR is to be able to create a DynamicEvaluation directly/implicitly from a constant, like 0.0 or 1.0 or 0.5, without specifying the number of the derivatives.

For example, for the following code,

EvalWell cq_s_zfrac_effective{this->primary_variables_.numWellEq() + Indices::numEq, 0.0};

now we can do

EvalWell cq_s_zfrac_effective{0.0};

To do this, we represent constants with DynamicEvaluation without derivatives. And the operators are updated to incorporate this change.

The main motivation was that we have a lot of material related calculation using implicit conversion from scalar values. When we tried to do more material related calculation (similar to flash calculation for black oil) inside the wellbore in Standard Well, it appeared that lacking of implicit conversion caused issues. We can (tried to) update the material calculations to handle DyanmiceEvaluation, while it will affect many files and the approach introduced this PR is the more confined manner.

@GitPaean GitPaean added the manual:irrelevant This PR is a minor fix and should not appear in the manual label Aug 6, 2025
@GitPaean
Copy link
Member Author

GitPaean commented Aug 6, 2025

jenkins build this please

1 similar comment
@GitPaean
Copy link
Member Author

GitPaean commented Aug 6, 2025

jenkins build this please

@GitPaean GitPaean requested a review from Copilot August 6, 2025 14:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for scalar dynamic evaluation by implementing constant evaluation handling in the DynamicEvaluation class. The changes allow operations between evaluations with different derivative sizes, where one can be a constant (size 0).

  • Adds a new constructor for creating constant evaluations with zero derivatives
  • Implements logic to handle operations between evaluations of different sizes when one is constant
  • Updates createConstant method to return a proper constant evaluation instead of throwing

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 12 comments.

File Description
opm/material/densead/DynamicEvaluation.hpp Adds constant evaluation support and mixed-size operation handling
opm/material/common/FastSmallVector.hpp Adds expandSize method to support dynamic resizing of evaluation storage
jenkins/pre-build.sh Comments out code generation script (temporary test change)

@GitPaean
Copy link
Member Author

GitPaean commented Aug 6, 2025

jenkins build this please

@GitPaean GitPaean force-pushed the scalar_dynamic_evaluation branch 2 times, most recently from 558307a to 64de5a2 Compare August 7, 2025 08:53
@GitPaean
Copy link
Member Author

GitPaean commented Aug 7, 2025

jenkins build this please

@GitPaean
Copy link
Member Author

GitPaean commented Aug 7, 2025

It looks like some rounding error or other mistakes jumping in caused regression. Working on recovering it.

@GitPaean
Copy link
Member Author

GitPaean commented Aug 7, 2025

jenkins build this please

Copy link
Member

@atgeirr atgeirr left a comment

Choose a reason for hiding this comment

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

Just commenting on the expandSize() method now.

I generally support the improved flexibility for the DynamicEvaluation, but have not looked at that yet.

@GitPaean GitPaean force-pushed the scalar_dynamic_evaluation branch from 935b81b to 1b92264 Compare August 8, 2025 08:43
@GitPaean
Copy link
Member Author

GitPaean commented Aug 8, 2025

jenkins build this please

@GitPaean GitPaean force-pushed the scalar_dynamic_evaluation branch from 1b92264 to 70c0f1e Compare August 13, 2025 13:53
@GitPaean
Copy link
Member Author

jenkins build this please

@GitPaean GitPaean force-pushed the scalar_dynamic_evaluation branch from 70c0f1e to 2e9da52 Compare October 6, 2025 11:15
@GitPaean
Copy link
Member Author

GitPaean commented Oct 6, 2025

jenkins build this please

@GitPaean GitPaean changed the title [test]Scalar dynamic evaluation Scalar dynamic evaluation Oct 7, 2025
@GitPaean
Copy link
Member Author

GitPaean commented Oct 7, 2025

With some discussion, it looks like this is an helpful/useful things to do. I am removing the [test] from the title of the PR.

@atgeirr , I have updated the PR, please have a look. I will migrate the implementation to the .py file.

@GitPaean
Copy link
Member Author

GitPaean commented Oct 7, 2025

I have updated the genEvalSpecializations.py to generate the changes introduced in this PR and marking the PR is ready for review.

I updated the description for this PR and mark it as ready for review.

@GitPaean GitPaean marked this pull request as ready for review October 7, 2025 10:25
@GitPaean GitPaean force-pushed the scalar_dynamic_evaluation branch from 8e2c080 to 0796fd1 Compare October 7, 2025 10:28
@GitPaean
Copy link
Member Author

GitPaean commented Oct 7, 2025

jenkins build this please

@GitPaean GitPaean requested a review from atgeirr October 7, 2025 11:14
@GitPaean
Copy link
Member Author

GitPaean commented Oct 7, 2025

I will make an accompanying PR in the opm-simulators to test how it works. Currently only test it with a development PR while not tested the usage in the master branch, so I am converting this PR to be draft again.

@GitPaean
Copy link
Member Author

GitPaean commented Oct 7, 2025

The failure (https://ci.opm-project.org/job/opm-simulators-PR-builder/8802/testReport/junit/(root)/mpi/compareECLFiles_flow_GASCONDENSATE_VAPWAT_PRECSALT_REGRESSION/) is due to the following code

in here is a DynamicEvalution initialized with scalar 0., so it does not have any derivatives. We will not be able to get any derivative to copy for the following code.

    template <class EvalWell>
    Eval restrictEval(const EvalWell& in) const
    {
        Eval out = 0.0;
        out.setValue(in.value());
        for (int eqIdx = 0; eqIdx < Indices::numEq; ++eqIdx) {
            out.setDerivative(eqIdx, in.derivative(eqIdx));
        }
        return out;
    }

@GitPaean
Copy link
Member Author

GitPaean commented Oct 8, 2025

jenkins build this opm-simulators=6520 please

@GitPaean GitPaean force-pushed the scalar_dynamic_evaluation branch from 3ae1a67 to 411dbf8 Compare October 16, 2025 07:32
@GitPaean
Copy link
Member Author

jenkins build this opm-simulators=6520 please

@GitPaean GitPaean force-pushed the scalar_dynamic_evaluation branch 2 times, most recently from 6e29d46 to 2a6da66 Compare October 17, 2025 09:03
@GitPaean
Copy link
Member Author

jenkins build this opm-simulators=6520 please

@GitPaean GitPaean force-pushed the scalar_dynamic_evaluation branch from 2a6da66 to 8bca924 Compare October 20, 2025 11:28
@GitPaean
Copy link
Member Author

jenkins build this opm-simulators=6520 please

Copy link
Member

@atgeirr atgeirr left a comment

Choose a reason for hiding this comment

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

The comment on the DynamicEvaluation is made in that source file because it was simpler for me, but you would have to make changes in the generating .py file instead.

return *this;
}

if (thisSize == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

I think that instead of extending this object's derivatives with the appendDerivativesToConstant() function, you could do:

const T value_copy = value();
*this = other;
*this /= value_copy;

I think this pattern is a lot simpler, and should be done for all the arithmetic operations here.

Copy link
Member Author

@GitPaean GitPaean Oct 28, 2025

Choose a reason for hiding this comment

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

I think the original comment was wrong. if this is a constant, we divide all values and derivatives by the value.

I corrected the comment to be // if *this is a constant, extend to hold derivatives before division.

Sorry about that.

your suggestion will be the other way around,

other /= *this

Let me know if I read it wrong. I worked on it some time ago, I might be confused here.

Copy link
Member

Choose a reason for hiding this comment

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

No you are right, sorry for adding confusion! I do think that for the other operators the pattern I suggested would work, but of course not for division, a/b is not equal to b/a, I do not know what hit me.

@GitPaean GitPaean force-pushed the scalar_dynamic_evaluation branch from 8bca924 to 4e06dd4 Compare October 27, 2025 22:27
@GitPaean
Copy link
Member Author

jenkins build this opm-simulators=6520 please

@GitPaean
Copy link
Member Author

Thanks for the approval.

The PR can go in independently. Let me test it only itself without the downstream PR.

@GitPaean
Copy link
Member Author

jenkins build this please

1 similar comment
@GitPaean
Copy link
Member Author

jenkins build this please

@GitPaean GitPaean force-pushed the scalar_dynamic_evaluation branch from e88d8bd to 78ec692 Compare October 28, 2025 12:37
@GitPaean
Copy link
Member Author

jenkins build this please

@GitPaean
Copy link
Member Author

the nonnull warming is silenced.

@GitPaean
Copy link
Member Author

jenkins build this please

@GitPaean
Copy link
Member Author

approved and jenkins passed. I am getting the PR in now.

@GitPaean GitPaean merged commit ae78571 into OPM:master Oct 28, 2025
2 checks passed
@GitPaean GitPaean deleted the scalar_dynamic_evaluation branch October 28, 2025 15:45
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.

2 participants