Skip to content

Commit

Permalink
Added the ability to print automatic scaling factors
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahansel committed Jul 25, 2019
1 parent 9253713 commit d3daaeb
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 14 deletions.
10 changes: 9 additions & 1 deletion framework/include/executioners/Executioner.h
Expand Up @@ -113,6 +113,12 @@ class Executioner : public MooseObject,
/// Augmented Picard convergence check that to be called by PicardSolve and can be overridden by derived executioners
virtual bool augmentedPicardConvergenceCheck() const { return false; }

/**
* Get the verbose output flag
* @return The verbose output flag
*/
bool & verbose() { return _verbose; }

protected:
/**
* Adds a postprocessor to report a Real class attribute
Expand All @@ -131,5 +137,7 @@ class Executioner : public MooseObject,

// Restart
std::string _restart_file_base;
};

/// True if printing out additional information
bool _verbose;
};
10 changes: 0 additions & 10 deletions framework/include/executioners/Transient.h
Expand Up @@ -171,12 +171,6 @@ class Transient : public Executioner
*/
Real & timestepTol() { return _timestep_tolerance; }

/**
* Get the verbose output flag
* @return The verbose output flag
*/
bool & verbose() { return _verbose; }

/**
* Is the current step at a sync point (sync times, time interval, target time, etc)?
* @return Bool indicataing whether we are at a sync point
Expand Down Expand Up @@ -254,9 +248,6 @@ class Transient : public Executioner
Real & _target_time;
bool _use_multiapp_dt;

///should detailed diagnostic output be printed
bool _verbose;

Real _solution_change_norm;

/// The difference of current and old solutions
Expand All @@ -266,4 +257,3 @@ class Transient : public Executioner

PerfID _final_timer;
};

3 changes: 3 additions & 0 deletions framework/include/systems/NonlinearSystemBase.h
Expand Up @@ -643,6 +643,9 @@ class NonlinearSystemBase : public SystemBase,
unsigned int _current_nl_its;
bool _compute_initial_residual_before_preset_bcs;

/// True if printing out additional information
bool _verbose;

protected:
/**
* Compute the residual for a given tag
Expand Down
3 changes: 2 additions & 1 deletion framework/src/executioners/Executioner.C
Expand Up @@ -51,7 +51,8 @@ Executioner::Executioner(const InputParameters & parameters)
"_fe_problem_base", "This might happen if you don't have a mesh")),
_feproblem_solve(this),
_picard_solve(this),
_restart_file_base(getParam<FileNameNoExtension>("restart_file_base"))
_restart_file_base(getParam<FileNameNoExtension>("restart_file_base")),
_verbose(getParam<bool>("verbose"))
{
if (!_restart_file_base.empty())
_fe_problem.setRestartFile(_restart_file_base);
Expand Down
3 changes: 3 additions & 0 deletions framework/src/executioners/FEProblemSolve.C
Expand Up @@ -76,6 +76,7 @@ validParams<FEProblemSolve>()
"Whether the scaling factors should only be computed once at the beginning of the simulation "
"through an extra Jacobian evaluation. If this is set to false, then the scaling factors "
"will be computed during an extra Jacobian evaluation at the beginning of every time step.");
params.addParam<bool>("verbose", false, "Set to true to print additional information");

params.addParamNamesToGroup("l_tol l_abs_step_tol l_max_its nl_max_its nl_max_funcs "
"nl_abs_tol nl_rel_tol nl_abs_step_tol nl_rel_step_tol "
Expand Down Expand Up @@ -127,6 +128,8 @@ FEProblemSolve::FEProblemSolve(Executioner * ex)

_nl._l_abs_step_tol = getParam<Real>("l_abs_step_tol");

_nl._verbose = getParam<bool>("verbose");

_problem.setSNESMFReuseBase(getParam<bool>("snesmf_reuse_base"),
_pars.isParamSetByUser("snesmf_reuse_base"));

Expand Down
2 changes: 0 additions & 2 deletions framework/src/executioners/Transient.C
Expand Up @@ -124,7 +124,6 @@ validParams<Transient>()

params.addParamNamesToGroup("time_periods time_period_starts time_period_ends", "Time Periods");

params.addParam<bool>("verbose", false, "Print detailed diagnostics on timestep calculation");
return params;
}

Expand Down Expand Up @@ -159,7 +158,6 @@ Transient::Transient(const InputParameters & parameters)
_timestep_tolerance(getParam<Real>("timestep_tolerance")),
_target_time(declareRecoverableData<Real>("target_time", -1)),
_use_multiapp_dt(getParam<bool>("use_multiapp_dt")),
_verbose(getParam<bool>("verbose")),
_sln_diff(_nl.addVector("sln_diff", false, PARALLEL)),
_final_timer(registerTimedSection("final", 1))
{
Expand Down
19 changes: 19 additions & 0 deletions framework/src/systems/NonlinearSystemBase.C
Expand Up @@ -114,6 +114,7 @@ NonlinearSystemBase::NonlinearSystemBase(FEProblemBase & fe_problem,
_initial_residual_after_preset_bcs(0.),
_current_nl_its(0),
_compute_initial_residual_before_preset_bcs(true),
_verbose(false),
_current_solution(NULL),
_residual_ghosted(NULL),
_serialized_solution(*NumericVector<Number>::build(_communicator).release()),
Expand Down Expand Up @@ -3254,6 +3255,24 @@ NonlinearSystemBase::computeScalingJacobian(NonlinearImplicitSystem & sys)
if (scaling_factor < std::numeric_limits<Real>::epsilon())
scaling_factor = 1;

if (_verbose)
{
_console << "Automatic scaling factors:\n";
for (MooseIndex(field_variables) i = 0; i < field_variables.size(); ++i)
{
auto & field_variable = *field_variables[i];
_console << " " << field_variable.name() << ": " << 1.0 / inverse_scaling_factors[i]
<< "\n";
}
for (MooseIndex(scalar_variables) i = 0; i < scalar_variables.size(); ++i)
{
auto & scalar_variable = *scalar_variables[i];
_console << " " << scalar_variable.name() << ": "
<< 1.0 / inverse_scaling_factors[offset + i] << "\n";
}
_console << "\n\n";
}

// Now set the scaling factors for the variables
applyScalingFactors(inverse_scaling_factors);
if (auto displaced_problem = _fe_problem.getDisplacedProblem().get())
Expand Down
17 changes: 17 additions & 0 deletions test/tests/executioners/executioner/tests
Expand Up @@ -31,4 +31,21 @@
group = 'requirements'
requirement = "MOOSE shall be capable of solving a transient diffusion problem."
[../]

[./test_print_automatic_scaling_factors_true]
type = 'RunApp'
input = 'steady.i'
cli_args = "Executioner/automatic_scaling=true Executioner/verbose=true"
expect_out = "Automatic scaling factors:
u: 0.175781"
requirement = "MOOSE shall print automatic scaling factors if specified."
[../]

[./test_print_automatic_scaling_factors_false]
type = 'RunApp'
input = 'steady.i'
cli_args = "Executioner/automatic_scaling=true"
absent_out = "Automatic scaling factors:"
requirement = "MOOSE shall not print automatic scaling factors if not specified."
[../]
[]

0 comments on commit d3daaeb

Please sign in to comment.