HermesCommon
3.0
|
Base class for defining interface for nonlinear solvers. More...
#include <nonlinear_matrix_solver.h>
Public Member Functions | |
virtual void | solve (Scalar *coeff_vec) |
void | set_max_allowed_iterations (int max_allowed_iterations) |
Set the maximum number of iterations, thus co-determine when to stop iterations. | |
virtual void | clear_tolerances () |
Clear (reset) all tolerances. | |
void | set_max_allowed_residual_norm (double max_allowed_residual_norm_to_set) |
void | set_tolerance (double newton_tol, NonlinearConvergenceMeasurementType toleranceType, bool handleMultipleTolerancesAnd=false) |
int | get_num_iters () const |
Get the number of iterations. | |
void | set_min_allowed_damping_coeff (double min_allowed_damping_coeff_to_set) |
void | set_manual_damping_coeff (bool onOff, double coeff) |
void | set_initial_auto_damping_coeff (double coeff) |
void | set_auto_damping_ratio (double ratio) |
void | set_sufficient_improvement_factor (double ratio) |
void | set_necessary_successful_steps_to_increase (unsigned int steps) |
void | set_sufficient_improvement_factor_jacobian (double ratio) |
void | set_max_steps_with_reused_jacobian (unsigned int steps) |
virtual void | free () |
Frees the instances. | |
![]() | |
MatrixSolver (bool force_use_direct_solver=false) | |
virtual Scalar * | get_sln_vector () |
Return the solution vector. | |
void | set_jacobian_constant (bool to_set=true) |
Sets the jacobian to be constant, i.e. reused whenever possible. | |
virtual LinearMatrixSolver < Scalar > * | get_linear_matrix_solver () |
virtual void | set_UMFPACK_output (bool to_set=true, bool with_output=false) |
virtual double | get_UMFPACK_reporting_data (UMFPACK_reporting_data_value data_value) |
SparseMatrix< Scalar > * | get_jacobian () |
Only a shortcut for algebraic solver (->) get_matrix(). | |
Vector< Scalar > * | get_residual () |
Only a shortcut for algebraic solver (->) get_rhs(). | |
virtual void | set_verbose_output (bool to_set) |
Verbose output. | |
![]() | |
Loggable (bool verbose_output=false, callbackFn verbose_callback=NULL, bool add_newline=true) | |
void | set_file_output_only (bool onOff) |
void | set_timestamps (bool onOff) |
Sets the addition of a time stamp on each line in the log file. By default it is on. | |
void | set_erase_on_beginning (bool onOff) |
Sets the logFile being always erased before logging. | |
void | set_logFile_name (const char *filename) |
void | set_logFile_name (std::string filename) |
void | info (const char *msg,...) const |
void | info_if (bool cond, const char *msg,...) const |
void | warn (const char *msg,...) const |
void | warn_if (bool cond, const char *msg,...) const |
void | error (const char *msg,...) const |
void | error_if (bool cond, const char *msg,...) const |
bool | get_verbose_output () const |
Returns the current value of verbose_output;. | |
virtual void | set_verbose_callback (callbackFn callback) |
callbackFn | get_verbose_callback () const |
Returns the current value of verbose_callback;. | |
![]() | |
virtual bool | on_initialization () |
virtual bool | on_step_begin () |
virtual bool | on_initial_step_end () |
virtual bool | on_step_end () |
virtual bool | on_finish () |
template<typename T > | |
const T & | get_parameter_value (const Parameter< T > ¶meter) |
template<typename T > | |
T & | get_parameter_value (Parameter< T > ¶meter) |
![]() | |
void | check () const |
Method to handle the state. | |
![]() | |
TimeMeasurable (const char *name=nullptr) | |
Constructs internal structures and starts measuring. | |
const TimeMeasurable & | reset () |
Resets accumulated time. | |
const TimeMeasurable & | tick_reset () |
Starts a new_ period and resets accumulated time. | |
const TimeMeasurable & | tick (TimeMeasurable::TimerPeriodTickType type=HERMES_ACCUMULATE) |
Starts/ends a new_ period. | |
const std::string & | name () const |
Returns a name of the time period if any. | |
double | accumulated () const |
Returns accumulated time (in seconds). | |
std::string | accumulated_str () const |
Returns accumulated time in human readable form. | |
double | last () const |
Returns last measured period (in seconds). More... | |
std::string | last_str () const |
Returns last measured period in human readable form. | |
Protected Member Functions | |
bool | force_reuse_jacobian_values (unsigned int &successful_steps_with_reused_jacobian) |
For deciding if the jacobian is reused at this point. | |
bool | jacobian_reused_okay (unsigned int &successful_steps_with_reused_jacobian) |
For deciding if the reused jacobian did not bring residual increase at this point. | |
virtual void | assemble_residual (bool store_previous_residual)=0 |
virtual bool | assemble_jacobian (bool store_previous_jacobian)=0 |
virtual bool | assemble (bool store_previous_jacobian, bool store_previous_residual)=0 |
virtual void | on_damping_factor_updated () |
virtual void | on_reused_jacobian_step_begin () |
virtual void | on_reused_jacobian_step_end () |
virtual bool | handle_convergence_state_return_finished (NonlinearConvergenceState state) |
virtual void | init_solving (Scalar *coeff_vec) |
virtual NonlinearConvergenceState | get_convergence_state () |
Find out the convergence state. | |
bool | do_initial_step_return_finished () |
Initial step. | |
virtual void | solve_linear_system () |
Solve the step's linear system. | |
virtual double | update_solution_return_change_norm (Scalar *linear_system_solution)=0 |
void | finalize_solving () |
Internal. | |
virtual void | deinit_solving () |
Internal. | |
bool | calculate_damping_factor (unsigned int &successful_steps) |
Calculates the new_ damping coefficient. | |
virtual bool | damping_factor_condition () |
Returns iff the damping factor condition is fulfilled. | |
int | get_current_iteration_number () |
Shortcut method for getting the current iteration. | |
void | step_info () |
Output info about the step. | |
virtual double | calculate_residual_norm () |
Norm for convergence. | |
virtual bool | isOkay () const |
State querying helpers. | |
std::string | getClassName () const |
Get class name, for the purpose of messaging. | |
void | init_nonlinear () |
Shared code for constructors. | |
const OutputParameterUnsignedInt & | iteration () const |
const OutputParameterDoubleVector & | residual_norms () const |
const OutputParameterDoubleVector & | solution_norms () const |
const OutputParameterDoubleVector & | solution_change_norms () const |
const OutputParameterUnsignedInt & | successful_steps_damping () const |
const OutputParameterUnsignedInt & | successful_steps_jacobian () const |
const OutputParameterDoubleVector & | damping_factors () const |
const OutputParameterBool & | residual_norm_drop () const |
const OutputParameterBoolVector & | iterations_with_recalculated_jacobian () const |
![]() | |
void | handle_UMFPACK_reports () |
This is not used now. | |
![]() | |
void | hermes_fwrite (const void *ptr, size_t size, size_t nitems, FILE *stream) const |
void | hermes_fread (void *ptr, size_t size, size_t nitems, FILE *stream) const |
![]() | |
template<typename T > | |
void | set_parameter_value (Parameter< T > ¶meter, T *value) |
Protected Attributes | |
bool | manual_damping |
Manual / auto. | |
double | manual_damping_factor |
Manual. | |
double | auto_damping_ratio |
double | initial_auto_damping_factor |
The initial (and maximum) damping coefficient. | |
double | sufficient_improvement_factor |
Sufficient improvement for continuing. | |
unsigned int | necessary_successful_steps_to_increase |
necessary number of steps to increase back the damping coeff. | |
double | min_allowed_damping_coeff |
Minimum allowed damping coeff. | |
double | sufficient_improvement_factor_jacobian |
unsigned int | max_steps_with_reused_jacobian |
Vector< Scalar > * | residual_back |
Backup vector for unsuccessful reuse of Jacobian. | |
double | max_allowed_residual_norm |
int | max_allowed_iterations |
Maximum number of iterations allowed. | |
double | tolerance [NonlinearConvergenceMeasurementTypeCount] |
Tolerances for all NonlinearConvergenceMeasurementType numbered sequentially as the enum NonlinearConvergenceMeasurementType is. | |
bool | tolerance_set [NonlinearConvergenceMeasurementTypeCount] |
info about set tolerances. | |
bool | handleMultipleTolerancesAnd |
int | num_iters |
To be filled and returned on demand. | |
SparseMatrix< Scalar > * | previous_jacobian |
Previous structures (e.g. in Picard's residual calculation) | |
Vector< Scalar > * | previous_residual |
OutputParameterDoubleVector | p_residual_norms |
OutputParameterDoubleVector | p_solution_norms |
OutputParameterDoubleVector | p_solution_change_norms |
OutputParameterBoolVector | p_iterations_with_recalculated_jacobian |
OutputParameterUnsignedInt | p_successful_steps_damping |
OutputParameterUnsignedInt | p_successful_steps_jacobian |
OutputParameterDoubleVector | p_damping_factors |
OutputParameterBool | p_residual_norm_drop |
OutputParameterUnsignedInt | p_iteration |
Scalar * | previous_sln_vector |
bool | use_initial_guess_for_iterative_solvers |
![]() | |
Hermes::Solvers::LinearMatrixSolver < Scalar > * | linear_matrix_solver |
Linear solver. | |
bool | constant_jacobian |
Jacobian can be reused if possible. | |
bool | jacobian_reusable |
Jacobian is ready to be reused if desirable. | |
int | problem_size |
Number of equations. | |
bool | do_UMFPACK_reporting |
double | UMFPACK_reporting_data [3] |
Friends | |
class | NonlinearConvergenceMeasurement< Scalar > |
Additional Inherited Members | |
![]() | |
enum | UMFPACK_reporting_data_value { FactorizationSize = 0, PeakMemoryUsage = 1, Flops = 2 } |
Data values (types) for UMFPACK reporting. | |
![]() | |
enum | TimerPeriodTickType { HERMES_ACCUMULATE, HERMES_SKIP } |
Tick type. Used by the class Hermes::TimePeriod. More... | |
![]() | |
static void | set_static_logFile_name (const char *filename) |
static void | set_static_logFile_name (std::string filename) |
![]() | |
Scalar * | sln_vector |
The solution vector. | |
![]() | |
char * | logFileName |
Logfile name. | |
![]() | |
static char * | staticLogFileName = nullptr |
Base class for defining interface for nonlinear solvers.
Definition at line 32 of file nonlinear_convergence_measurement.h.
|
protectedvirtual |
Act upon the convergence state.
Definition at line 286 of file nonlinear_matrix_solver.cpp.
|
protectedvirtual |
Initialization - called at the beginning of solving. Very important e.g. for assigning DOFs before assembling.
Definition at line 92 of file nonlinear_matrix_solver.cpp.
Referenced by Hermes::Solvers::PicardMatrixSolver< Scalar >::init_solving().
|
protectedvirtual |
Definition at line 699 of file nonlinear_matrix_solver.cpp.
|
protectedvirtual |
Definition at line 704 of file nonlinear_matrix_solver.cpp.
|
protectedvirtual |
Definition at line 709 of file nonlinear_matrix_solver.cpp.
void Hermes::Solvers::NonlinearMatrixSolver< Scalar >::set_auto_damping_ratio | ( | double | ratio | ) |
Set the ratio to the automatic damping. When the damping coefficient is decided to be descreased or increased, this is the ratio how it will be changed (this is the bigger ( > 1.0 ) of the two possible values). I.e. when the damping coefficient is shortened 3 times if deemed too big, make the parameter not 0.333333, but 3.0. Default: 2.0
[in] | ratio | The ratio (again, it must be > 1.0, and it represents the inverse of the shortening factor). |
Definition at line 256 of file nonlinear_matrix_solver.cpp.
void Hermes::Solvers::NonlinearMatrixSolver< Scalar >::set_initial_auto_damping_coeff | ( | double | coeff | ) |
Make the automatic damping start with this coefficient. This will also be the top bound for the coefficient. Default: 1.0
[in] | coeff | The initial damping coefficient. Must be > 0 and <= 1.0. |
Definition at line 245 of file nonlinear_matrix_solver.cpp.
void Hermes::Solvers::NonlinearMatrixSolver< Scalar >::set_manual_damping_coeff | ( | bool | onOff, |
double | coeff | ||
) |
Turn on or off manual damping (default is the automatic) and optionally sets manual damping coefficient. Default: default is the automatic damping, default coefficient if manual damping used is set by this method.
[in] | onOff | on(true)-manual damping, off(false)-automatic damping. |
[in] | coeff | The (perpetual) damping coefficient in the case of manual damping. Ignored in the case of automatic damping. |
Definition at line 231 of file nonlinear_matrix_solver.cpp.
void Hermes::Solvers::NonlinearMatrixSolver< Scalar >::set_max_allowed_residual_norm | ( | double | max_allowed_residual_norm_to_set | ) |
Sets the maximum allowed norm of the residual during the calculation. Default: 1E9
Definition at line 173 of file nonlinear_matrix_solver.cpp.
void Hermes::Solvers::NonlinearMatrixSolver< Scalar >::set_max_steps_with_reused_jacobian | ( | unsigned int | steps | ) |
Set maximum number of steps (Newton iterations) that a jacobian can be reused if it is deemed a 'successful' reusal with respect to the improvement factor.
Definition at line 217 of file nonlinear_matrix_solver.cpp.
void Hermes::Solvers::NonlinearMatrixSolver< Scalar >::set_min_allowed_damping_coeff | ( | double | min_allowed_damping_coeff_to_set | ) |
Sets minimum damping coefficient. Default: 1E-4
Definition at line 223 of file nonlinear_matrix_solver.cpp.
void Hermes::Solvers::NonlinearMatrixSolver< Scalar >::set_necessary_successful_steps_to_increase | ( | unsigned int | steps | ) |
Set how many successful steps are necessary for the damping coefficient to be increased, by multiplication by the parameter set by set_auto_damping_ratio(). The coefficient is then increased after each 'successful' step, if the sequence of such is not interrupted by an 'unsuccessful' step. Default: 1
[in] | steps | Number of steps. |
Definition at line 276 of file nonlinear_matrix_solver.cpp.
void Hermes::Solvers::NonlinearMatrixSolver< Scalar >::set_sufficient_improvement_factor | ( | double | ratio | ) |
Set the ratio of the current residual norm and the previous residual norm necessary to deem a step 'successful'. It can be either > 1.0, meaning that even if the norm increased, the step will be 'successful', or < 1.0, meaning that even though the residual norm goes down, we will further decrease the damping coefficient. Default: 0.95 param[in] ratio The ratio, must be positive.
Definition at line 266 of file nonlinear_matrix_solver.cpp.
void Hermes::Solvers::NonlinearMatrixSolver< Scalar >::set_sufficient_improvement_factor_jacobian | ( | double | ratio | ) |
Set the ratio of the current residual norm and the previous residual norm necessary to deem a step 'successful'. IMPORTANT: it is truly a FACTOR, i.e. the two successive residual norms are put in a fraction and this number is then compared to the ratio set by this method.
Definition at line 209 of file nonlinear_matrix_solver.cpp.
void Hermes::Solvers::NonlinearMatrixSolver< Scalar >::set_tolerance | ( | double | newton_tol, |
NonlinearConvergenceMeasurementType | toleranceType, | ||
bool | handleMultipleTolerancesAnd = false |
||
) |
Set the residual norm tolerance for ending the Newton's loop. Default: this->set_tolerance(1e-8, ResidualNormAbsolute);
[in] | handleMultipleTolerancesAnd | If true, multiple tolerances defined will have to be all fulfilled in order to proclaim solution as a correct one. If false, only one will be enough. |
Definition at line 122 of file nonlinear_matrix_solver.cpp.
|
virtual |
Solve.
[in] | coeff_vec | initiall guess as a vector of coefficients wrt. basis functions. |
Definition at line 481 of file nonlinear_matrix_solver.cpp.
|
protectedpure virtual |
Update the solution. This is a method that serves the purpose of distinguishing methods that solve for increment (Newton), or for solution (Picard).
Implemented in Hermes::Solvers::PicardMatrixSolver< Scalar >, and Hermes::Solvers::NewtonMatrixSolver< Scalar >.
|
protected |
Auto. The ratio between two damping coeffs when changing.
Definition at line 167 of file nonlinear_matrix_solver.h.
|
protected |
If true, multiple tolerances defined will have to be all fulfilled in order to proclaim solution as a correct one. If false, only one will be enough.
Definition at line 267 of file nonlinear_matrix_solver.h.
Referenced by Hermes::Solvers::NonlinearConvergenceMeasurement< Scalar >::converged().
|
protected |
Maximum allowed residual norm. If this number is exceeded, the methods solve() return 'false'. By default set to 1E6. Possible to change via method set_max_allowed_residual_norm().
Definition at line 254 of file nonlinear_matrix_solver.h.
|
protected |
Parameters for OutputAttachable mixin. Should be private, but then it does not work.
Definition at line 286 of file nonlinear_matrix_solver.h.