-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,9 @@ | ||
[Tests] | ||
[./variable_residual_test] | ||
type = 'CSVDiff' | ||
input = 'variable_residual.i' | ||
csvdiff = 'variable_residual_out.csv' | ||
max_threads = 1 | ||
max_parallel = 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
104
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,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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
[../] | ||
[] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...