Skip to content

Commit

Permalink
Merge pull request #28163 from SudiptaBiswas/abs_pp
Browse files Browse the repository at this point in the history
Adding option to use absolute value in ElementIntegralPostprocessor.
  • Loading branch information
GiudGiud authored Jul 17, 2024
2 parents dc50da0 + bd9d205 commit 9353c8c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ class ElementIntegralVariablePostprocessor : public ElementIntegralPostprocessor
const VariableValue & _u;
/// Holds the solution gradient at the current quadrature points
const VariableGradient & _grad_u;
/// Option to use absolute variable value
bool _use_abs_value;
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ ElementIntegralVariablePostprocessor::validParams()
InputParameters params = ElementIntegralPostprocessor::validParams();
params.addRequiredCoupledVar("variable", "The name of the variable that this object operates on");
params.addClassDescription("Computes a volume integral of the specified variable");
params.addParam<bool>(
"use_absolute_value", false, "Whether to use abolsute value of the variable or not");
return params;
}

Expand All @@ -29,13 +31,17 @@ ElementIntegralVariablePostprocessor::ElementIntegralVariablePostprocessor(
Moose::VarKindType::VAR_ANY,
Moose::VarFieldType::VAR_FIELD_STANDARD),
_u(coupledValue("variable")),
_grad_u(coupledGradient("variable"))
_grad_u(coupledGradient("variable")),
_use_abs_value(getParam<bool>("use_absolute_value"))
{
addMooseVariableDependency(&mooseVariableField());
}

Real
ElementIntegralVariablePostprocessor::computeQpIntegral()
{
return _u[_qp];
if (_use_abs_value)
return std::abs(_u[_qp]);
else
return _u[_qp];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[Mesh]
[./square]
type = GeneratedMeshGenerator
nx = 2
ny = 2
dim = 2
[../]
[]

[Variables]
active = 'u'

[./u]
order = FIRST
family = LAGRANGE
[../]
[]

[Kernels]
active = 'diff'

[./diff]
type = Diffusion
variable = u
[../]
[]

[BCs]
active = 'left right'

[./left]
type = DirichletBC
variable = u
boundary = 3
value = 0
[../]

[./right]
type = DirichletBC
variable = u
boundary = 1
value = -1
[../]
[]

[Executioner]
type = Steady

solve_type = 'PJFNK'
[]

[Postprocessors]
[./integral]
type = ElementIntegralVariablePostprocessor
variable = u
use_absolute_value = true
[../]
[]

[Outputs]
file_base = out
exodus = false
csv = true
[]
12 changes: 10 additions & 2 deletions test/tests/postprocessors/element_integral/tests
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@
input = 'element_integral_test.i'
csvdiff = 'out.csv'

detail = 'over the whole domain and'
detail = 'over the whole domain, and'
[]

[block_test]
type = 'CSVDiff'
input = 'element_block_integral_test.i'
csvdiff = 'out_block.csv'

detail = 'over a subset of the domain.'
detail = 'over a subset of the domain,'
[]

[test_abs]
type = 'CSVDiff'
input = 'element_integral_absolute_test.i'
csvdiff = 'out.csv'

detail = 'and also optionally, using the absolute variable value.'
[]
[]
[]

0 comments on commit 9353c8c

Please sign in to comment.