KratosMultiphysics / Kratos

Kratos Multiphysics (A.K.A Kratos) is a framework for building parallel multi-disciplinary simulation software. Modularity, extensibility and HPC are the main objectives. Kratos has BSD license and is written in C++ with extensive Python interface.
https://kratosmultiphysics.github.io/Kratos/
Other
991 stars 244 forks source link

[CoSim] Incorrect residuals in `ConvergenceCriteria` #12394

Open juancamarotti opened 1 month ago

juancamarotti commented 1 month ago

Issue

During coupled simulations, the initial residual of subdomains is not updated between coupling iterations. The convergence criterion is using incorrect residuals.

Reproducer

To reproduce, run the FSI mok example setting the structural domain echo level to 4 and looking at how the initial residual norm changes between coupling iterations (Spoiler alert: it does not change).

Bug

The initial residual of ConvergenceCriteria is updated in ConvergenceCriteria::InitializeSolutionStep, which is in turn called when the structural solver's InitializeSolutionStep is called.

In the GaussSeidelStrongCoupledSolver, the ConvergenceCriteria of the structural domain is initialized once per time step (and not once per coupling iteration).

FYI @philbucher @KratosMultiphysics/technical-committee

philbucher commented 1 month ago

nice catch!

No wonder it never really worked for us, we basically always used the other criteria

juancamarotti commented 1 month ago

Yes! This issue is causing slow convergence with the non-linear shell elements we are using in our coupled simulations.

matekelemen commented 1 month ago

The question is how to fix the bug. As far as I can tell, calling the solver's InitializeSolutionStep and FinalizeSolutionStep during coupling iterations is a no-go because it would flush the solution buffer and thus break time stepping.

A hackish solution I can think of is storing the initial residual in ProcessInfo or ModelPart's DataValueContainer and manually overriding it during coupling iterations, but I don't particularly like this fix.

Any other ideas?

juancamarotti commented 1 month ago

After further analysis of the problem, I have concluded that this is not a CoSim issue. The bug is related to the strategy used. Let's consider the ResidualBasedNewtonRaphsonStrategy as an example:

1) In ResidualBasedNewtonRaphsonStrategy::SolveSolutionStep, the method ConvergenceCriteria::InilitializeNonLinearIteration is called with the LHS and RHS even before invoking the BuilderAndSolver. This implies that the method is called with zero LHS and RHS vectors.

2) The second issue is that inside ResidualCriteria, the ConvergenceCriteria::InitializeNonLinearIteration method is not overriden. The residual is calculated just once per time step inside ResidualCriteria::InitializeSolutionStep and not once per coupling iteration.

@KratosMultiphysics/technical-committee Why the ConvergenceCriteria::InilitializeNonLinearIteration is called before the BuilderAndSolver?

FYI @matekelemen @philbucher

yagofx commented 2 weeks ago

Hi,

Has this been solved? I've been working on FSI simulations using shell elements and encountered problems with convergence.

loumalouomega commented 2 weeks ago

Hi,

Has this been solved? I've been working on FSI simulations using shell elements and encountered problems with convergence.

@philbucher @matekelemen

yagofx commented 2 weeks ago

What I have seen is that at the end of the non-linear iterations in the FSI solver the residual norm is computed, so it is updated every coupling iteration. I'm no expert just started in Kratos recently for my Bachelor's 😃

rubenzorrilla commented 2 weeks ago

As far as I understand, @yagofx is not using the CoSimulationApplication so I don't think that his troubles have something to do with the issue @juancamarotti is referring to.