-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
102 additions
and
0 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
include/aspect/time_stepping/repeat_on_nonlinear_fail.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
Copyright (C) 2018 - 2023 by the authors of the ASPECT code. | ||
This file is part of ASPECT. | ||
ASPECT is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2, or (at your option) | ||
any later version. | ||
ASPECT is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with ASPECT; see the file LICENSE. If not see | ||
<http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#ifndef _aspect_time_stepping_repeat_on_nonlinear_fail_h | ||
#define _aspect_time_stepping_repeat_on_nonlinear_fail_h | ||
|
||
#include <aspect/time_stepping/interface.h> | ||
|
||
namespace aspect | ||
{ | ||
namespace TimeStepping | ||
{ | ||
using namespace dealii; | ||
|
||
/** | ||
* A class that implements a time stepping plugin to repeat a time step if the | ||
* nonlinear solver failed to converge in the specified number of iterations. | ||
* This class is automatically enabled if the user specifies that he/she wants | ||
* to do this. | ||
* | ||
* @ingroup TimeStepping | ||
*/ | ||
template <int dim> | ||
class RepeatOnNonlinearFail : public Interface<dim>, public SimulatorAccess<dim> | ||
{ | ||
public: | ||
/** | ||
* Constructor. | ||
*/ | ||
RepeatOnNonlinearFail () = default; | ||
|
||
/** | ||
* @copydoc aspect::TimeStepping::Interface<dim>::execute() | ||
*/ | ||
double | ||
execute() override; | ||
|
||
/** | ||
* This function notifies the plugin that the nonlinear solver | ||
* failed. | ||
*/ | ||
void nonlinear_solver_has_failed() const; | ||
|
||
/** | ||
* The main execute() function. | ||
*/ | ||
std::pair<Reaction, double> | ||
determine_reaction(const TimeStepInfo &info) override; | ||
|
||
static | ||
void | ||
declare_parameters (ParameterHandler &prm); | ||
|
||
void | ||
parse_parameters (ParameterHandler &prm) override; | ||
|
||
private: | ||
/** | ||
* Parameter to determine how much smaller the time step should be | ||
* repeated as. | ||
*/ | ||
double cut_back_amount = 0.5; | ||
|
||
/** | ||
* Enabled by nonlinear_solver_has_failed() to signal that this | ||
* plugin needs to act. | ||
*/ | ||
mutable bool nonlinear_solver_just_failed = false; | ||
|
||
/** | ||
* How many times should we try cutting the timestep size? | ||
*/ | ||
unsigned int maximum_number_of_repeats = 10; | ||
|
||
/** | ||
* How many times have we been repeating already right now? | ||
*/ | ||
unsigned int current_number_of_repeats = 0; | ||
}; | ||
} | ||
} | ||
|
||
|
||
#endif |