Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding VariableResidualNorm postprocessor #8518

Merged
merged 1 commit into from Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions framework/include/postprocessors/VariableResidual.h
@@ -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
3 changes: 2 additions & 1 deletion framework/src/base/Moose.C
Expand Up @@ -229,6 +229,7 @@
#include "RelativeSolutionDifferenceNorm.h"
#include "AxisymmetricCenterlineAverageValue.h"
#include "VariableInnerProduct.h"
#include "VariableResidual.h"

// vector PPS
#include "ConstantVectorPostprocessor.h"
Expand Down Expand Up @@ -661,6 +662,7 @@ registerObjects(Factory & factory)
registerPostprocessor(RelativeSolutionDifferenceNorm);
registerPostprocessor(AxisymmetricCenterlineAverageValue);
registerPostprocessor(VariableInnerProduct);
registerPostprocessor(VariableResidual);

// vector PPS
registerVectorPostprocessor(ConstantVectorPostprocessor);
Expand Down Expand Up @@ -1204,4 +1206,3 @@ bool _throw_on_error = false;

// TODO: delete this after migration to new error/warn funcs is complete
OStreamProxy & _console = Moose::out;

50 changes: 50 additions & 0 deletions framework/src/postprocessors/VariableResidual.C
@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any desire to support more than L2? We could make an enum if there might be and default it to L2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think L2 for residual is all we need. If somebody wanted something like H1, we would need a gradient of the residual and I do not think we can compute that...

}

PostprocessorValue
VariableResidual::getValue()
{
return _var_residual;
}
@@ -0,0 +1,4 @@
time,u_res_l2,v_res_l2
0,0,0
1,1.8140133821974e-06,0.00058473832580092

9 changes: 9 additions & 0 deletions test/tests/postprocessors/variable_residual_norm/tests
@@ -0,0 +1,9 @@
[Tests]
[./variable_residual_test]
type = 'CSVDiff'
input = 'variable_residual.i'
csvdiff = 'variable_residual_out.csv'
max_threads = 1
max_parallel = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the restrictions? I know it's a small test but it should still run in parallel right?

[../]
[]
104 changes: 104 additions & 0 deletions test/tests/postprocessors/variable_residual_norm/variable_residual.i
@@ -0,0 +1,104 @@
[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. This also means this test can run only
# in serial, since parallel runs yield different convergence history.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Here's the reason it's restricted

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
[../]
[]