Skip to content

Conversation

paveltomin
Copy link
Collaborator

@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
Collaborator Author

@dkachuma all your comments should be fixed now, thanks

@paveltomin
Copy link
Collaborator 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
Collaborator 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.

{
string const dofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() );
real64 scalingFactor = 1.0;
real64 scalingFactor = CompositionalMultiphaseBase::scalingForSystemSolution( domain, dofManager, localSolution );
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this feature be extended for singlePhase flow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i think it should work for single phase as is now, although i didn't have a change to test

@paveltomin paveltomin added ci: run CUDA builds Allows to triggers (costly) CUDA jobs ci: run integrated tests Allows to run the integrated tests in GEOS CI labels Sep 12, 2025
@paveltomin paveltomin merged commit 9c556db into develop Sep 14, 2025
25 of 26 checks passed
@paveltomin paveltomin deleted the pt/detect-oscillations branch September 14, 2025 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci: run CUDA builds Allows to triggers (costly) CUDA jobs ci: run integrated tests Allows to run the integrated tests in GEOS CI 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.

4 participants