-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding VariableResidualNorm postprocessor
For doing convergence studies, it is useful to be able to plot the residual norm of variables of the interest. MOOSE computes these values, but we want to be able to store them as postprocessor values, so we can plot them easily without postprocessing the console output. Closes #7206
- Loading branch information
Showing
6 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
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,43 @@ | ||
/****************************************************************/ | ||
/* DO NOT MODIFY THIS HEADER */ | ||
/* MOOSE - Multiphysics Object Oriented Simulation Environment */ | ||
/* */ | ||
/* (c) 2010 Battelle Energy Alliance, LLC */ | ||
/* ALL RIGHTS RESERVED */ | ||
/* */ | ||
/* Prepared by Battelle Energy Alliance, LLC */ | ||
/* Under Contract No. DE-AC07-05ID14517 */ | ||
/* With the U. S. Department of Energy */ | ||
/* */ | ||
/* See COPYRIGHT for full restrictions */ | ||
/****************************************************************/ | ||
|
||
#ifndef VARIABLERESIDUAL_H | ||
#define VARIABLERESIDUAL_H | ||
|
||
#include "GeneralPostprocessor.h" | ||
|
||
//Forward Declarations | ||
class VariableResidual; | ||
|
||
template<> | ||
InputParameters validParams<VariableResidual>(); | ||
|
||
class VariableResidual : public GeneralPostprocessor | ||
{ | ||
public: | ||
VariableResidual(const InputParameters & parameters); | ||
|
||
virtual void initialize() override; | ||
virtual void execute() override; | ||
|
||
virtual PostprocessorValue getValue() override; | ||
|
||
protected: | ||
/// MOOSE variable we compute the residual for | ||
MooseVariable & _var; | ||
/// The residual of the variable | ||
Real _var_residual; | ||
}; | ||
|
||
#endif //VARIABLERESIDUAL_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
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,50 @@ | ||
/****************************************************************/ | ||
/* DO NOT MODIFY THIS HEADER */ | ||
/* MOOSE - Multiphysics Object Oriented Simulation Environment */ | ||
/* */ | ||
/* (c) 2010 Battelle Energy Alliance, LLC */ | ||
/* ALL RIGHTS RESERVED */ | ||
/* */ | ||
/* Prepared by Battelle Energy Alliance, LLC */ | ||
/* Under Contract No. DE-AC07-05ID14517 */ | ||
/* With the U. S. Department of Energy */ | ||
/* */ | ||
/* See COPYRIGHT for full restrictions */ | ||
/****************************************************************/ | ||
|
||
#include "VariableResidual.h" | ||
|
||
template<> | ||
InputParameters validParams<VariableResidual>() | ||
{ | ||
InputParameters params = validParams<GeneralPostprocessor>(); | ||
params.addRequiredParam<VariableName>("variable", "The name of the variable to compute the residual for"); | ||
return params; | ||
} | ||
|
||
VariableResidual::VariableResidual(const InputParameters & parameters) | ||
: GeneralPostprocessor(parameters), | ||
_var(_fe_problem.getVariable(_tid, getParam<VariableName>("variable"))) | ||
{ | ||
if (_var.kind() != Moose::VAR_NONLINEAR) | ||
mooseError2(name(), ": Residual can be computed only for nonlinear variables."); | ||
} | ||
|
||
void | ||
VariableResidual::initialize() | ||
{ | ||
_var_residual = 0; | ||
} | ||
|
||
void | ||
VariableResidual::execute() | ||
{ | ||
NonlinearSystemBase & nl = _fe_problem.getNonlinearSystemBase(); | ||
_var_residual = nl.system().calculate_norm(nl.RHS(), _var.number(), DISCRETE_L2); | ||
} | ||
|
||
PostprocessorValue | ||
VariableResidual::getValue() | ||
{ | ||
return _var_residual; | ||
} |
4 changes: 4 additions & 0 deletions
4
test/tests/postprocessors/variable_residual_norm/gold/variable_residual_out.csv
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,4 @@ | ||
time,u_res_l2,v_res_l2 | ||
0,0,0 | ||
1,1.8140133821974e-06,0.00058473832580092 | ||
|
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,8 @@ | ||
[Tests] | ||
[./variable_residual_test] | ||
type = 'CSVDiff' | ||
input = 'variable_residual.i' | ||
csvdiff = 'variable_residual_out.csv' | ||
max_threads = 1 | ||
[../] | ||
[] |
103 changes: 103 additions & 0 deletions
103
test/tests/postprocessors/variable_residual_norm/variable_residual.i
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,103 @@ | ||
[Mesh] | ||
type = GeneratedMesh | ||
dim = 2 | ||
nx = 2 | ||
ny = 2 | ||
xmin = -1 | ||
xmax = 1 | ||
ymin = 0 | ||
ymax = 1 | ||
elem_type = QUAD4 | ||
[] | ||
|
||
[Variables] | ||
[./u] | ||
[../] | ||
|
||
[./v] | ||
[../] | ||
[] | ||
|
||
[Kernels] | ||
[./diff_u] | ||
type = Diffusion | ||
variable = u | ||
[../] | ||
|
||
[./diff_v] | ||
type = Diffusion | ||
variable = v | ||
[../] | ||
[] | ||
|
||
[Functions] | ||
[./leg1] | ||
type = ParsedFunction | ||
value = 'x' | ||
[../] | ||
|
||
[./leg2] | ||
type = ParsedFunction | ||
value = '0.5*(3.0*x*x-1.0)' | ||
[../] | ||
[] | ||
|
||
[BCs] | ||
[./left_u] | ||
type = DirichletBC | ||
variable = u | ||
boundary = 1 | ||
value = 0 | ||
[../] | ||
|
||
[./right_u] | ||
type = DirichletBC | ||
variable = u | ||
boundary = 2 | ||
value = 1 | ||
[../] | ||
|
||
[./left_v] | ||
type = DirichletBC | ||
variable = v | ||
boundary = 1 | ||
value = 200 | ||
[../] | ||
|
||
[./right_v] | ||
type = DirichletBC | ||
variable = v | ||
boundary = 2 | ||
value = 100 | ||
[../] | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
solve_type = 'PJFNK' | ||
|
||
# this is large on purpose so we don't reduce the variable residual to machine zero | ||
# and so that we can compare to larger numbers | ||
nl_rel_tol = 1e-4 | ||
[] | ||
|
||
[Postprocessors] | ||
[./u_res_l2] | ||
type = VariableResidual | ||
variable = u | ||
[../] | ||
|
||
[./v_res_l2] | ||
type = VariableResidual | ||
variable = v | ||
[../] | ||
[] | ||
|
||
[Outputs] | ||
csv = true | ||
[./console] | ||
type = Console | ||
# turn this on, so we can visually compare the postprocessor value with what is computed by the Console object | ||
all_variable_norms = true | ||
[../] | ||
[] |