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

}
}

void expandSize(size_t numElem)
Copy link
Member

Choose a reason for hiding this comment

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

I suggest a more general resize() method, avoiding the assert() below and letting it both grow and shrink. Like std::vector, I suggest that when shrinking we do not actually deallocate, or switch back to the smallBuf_ if size decreases to <= N, but just stay with the representation we have (that would also preserve iterators when shrinking).

Copy link
Member Author

Choose a reason for hiding this comment

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

If we do not switch back from std::vector<ValueType> data_ to std::array<ValueType, N> smallBuf, when size_ decreases to <=N, there will be other functions need to be changed for consistency.

Let me done update it first.

assert(numElem >= size_);
if (size_ <= N) {
if (numElem > N) {
data_.resize(numElem, 0);
Copy link
Member

Choose a reason for hiding this comment

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

There should be no second argument. 0 will work for numbers but not for strings for example, or vectors.

Also on line 211.

if (size_ <= N) {
if (numElem > N) {
data_.resize(numElem, 0);
data_.assign(smallBuf_.begin(), smallBuf_.begin() + size_);
Copy link
Member

Choose a reason for hiding this comment

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

This call will make the contents of data_ equal to the current contents of the object, making the resize() above pointless. I.e. if N is 10 and the object has size_ == 7, then we call this function with numElem == 12, we will end up with a data_ vector of size 7!

I suggest using a single resize() and instead of assign() just copy() the existing elements to the start of data_.

Copy link
Member Author

Choose a reason for hiding this comment

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

assign indeed changes the size of the vector. thanks for pointing it out.

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

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