Skip to content

feat: oscillation scaling #3745

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

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open

feat: oscillation scaling #3745

wants to merge 18 commits into from

Conversation

paveltomin
Copy link
Contributor

@paveltomin paveltomin commented Jul 29, 2025

an option to scale the solution changes when oscillations (on Newton iteration level) are detected:
oscillationScaling - 0 or 1 - enables the feature
oscillationScalingFactor - between 0 and 1 - scaling factor to be applied when oscillations are detected
oscillationCheckDepth - 2 or larger - how many iterations down the solution change history will be checked
oscillationTolerance - check tolerance, used both to trim-out small solution changes and to check that oscillatory changes are close to each other in magnitude
oscillationFraction - between 0 and 1 - fraction of total cells that have oscillations

@paveltomin paveltomin changed the title oscillation scaling feat: oscillation scaling Jul 31, 2025
@paveltomin paveltomin self-assigned this Jul 31, 2025
@paveltomin paveltomin added flag: ready for review ci: run integrated tests Allows to run the integrated tests in GEOS CI labels Jul 31, 2025
@paveltomin paveltomin marked this pull request as ready for review July 31, 2025 19:17
@paveltomin paveltomin added flag: requires rebaseline Requires rebaseline branch in integratedTests and removed ci: run integrated tests Allows to run the integrated tests in GEOS CI labels Jul 31, 2025
localIndex const historySize = m_solutionHistory.size();

RAJA::forall< parallelDevicePolicy<> >( RAJA::TypedRangeSegment< localIndex >( 0, numDofs ),
[&] GEOS_HOST ( localIndex const dof )
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
[&] GEOS_HOST ( localIndex const dof )
[=] GEOS_HOST_DEVICE ( localIndex const dof )

GEOS_ERROR_IF_LT_MSG( m_oscillationCheckDepth, 2,
getWrapperDataContext( viewKeysStruct::oscillationCheckDepthString() ) << ": can not be less than 2" );
GEOS_ERROR_IF_LE_MSG( m_oscillationTolerance, 0.0,
getWrapperDataContext( viewKeysStruct::oscillationToleranceString() ) << ": should be positive" );
Copy link
Contributor

Choose a reason for hiding this comment

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

Should also be less than 1?

}
} );

real64 const f = static_cast< real64 >( MpiWrapper::sum( oscillationCount.get() ) ) / numDofs;
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 we should also mpi sum numDofs here.

GEOS_FMT( " {}: oscillation detected, scaling factor set to {}", getName(), scalingFactor ) );
}

m_solutionHistory.appendArray( localSolution.begin(), localSolution.end());
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to populate of m_nonlinearSolverParameters.m_oscillationScaling is false.

@paveltomin
Copy link
Contributor Author

@dkachuma all your comments should be fixed now, thanks

@paveltomin paveltomin requested a review from Guotong-Ren as a code owner August 8, 2025 19:39
@paveltomin
Copy link
Contributor Author

@dkachuma example how it helps a bit for dome case:

                oscillationScalingFactor="0.66"
                oscillationCheckDepth="2"

image

Copy link
Contributor

Choose a reason for hiding this comment

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

A unit test or integrated test to exercise the detection logic would be good. Ideally this could be exercised in isolation from a full simulation run, but this isn't always possible..

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 enabled it for one example from integrated tests

@paveltomin paveltomin requested a review from rasimHZ as a code owner August 12, 2025 17:43
@paveltomin paveltomin requested a review from Copilot August 15, 2025 20:56
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 introduces oscillation detection and scaling functionality for Newton iteration levels in physics solvers. The feature helps stabilize convergence by automatically scaling solution changes when oscillatory behavior is detected.

Key changes include:

  • Addition of oscillation detection logic with configurable parameters for scaling factor, check depth, tolerance, and fraction thresholds
  • Integration of oscillation scaling into the solver hierarchy through proper base class method calls
  • Update of solver scaling methods to utilize the new oscillation detection framework

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
PhysicsSolverBase.hpp Adds oscillation detection method declaration and solution history storage
PhysicsSolverBase.cpp Implements oscillation detection algorithm and integrates scaling logic into solution methods
NonlinearSolverParameters.hpp Defines new oscillation-related configuration parameters
NonlinearSolverParameters.cpp Implements parameter registration, validation, and display for oscillation settings
CompositionalMultiphaseBase.cpp Updates methods to call parent class for proper oscillation handling
CompositionalMultiphaseFVM.cpp Modifies scaling method to use base class oscillation detection
CoupledSolver.hpp Updates scaling method to use base class implementation
LinearSolverParameters.cpp Refactors table formatting for consistency
lockExchange_rho.xml Adds example configuration with oscillation detection enabled

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flag: ready for review flag: requires rebaseline Requires rebaseline branch in integratedTests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants