From bd9d205f831a0eddfa265f91c57813f32edb13f6 Mon Sep 17 00:00:00 2001 From: SudiptaBiswas Date: Wed, 17 Jul 2024 11:17:40 -0700 Subject: [PATCH] Add option to use absolute value in ElementIntegralVariablePostprocessor #28162` --- .../ElementIntegralVariablePostprocessor.h | 2 + .../ElementIntegralVariablePostprocessor.C | 10 ++- .../element_integral_absolute_test.i | 64 +++++++++++++++++++ .../postprocessors/element_integral/tests | 12 +++- 4 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 test/tests/postprocessors/element_integral/element_integral_absolute_test.i diff --git a/framework/include/postprocessors/ElementIntegralVariablePostprocessor.h b/framework/include/postprocessors/ElementIntegralVariablePostprocessor.h index 62aa13d01f4d..e3012a9f4a19 100644 --- a/framework/include/postprocessors/ElementIntegralVariablePostprocessor.h +++ b/framework/include/postprocessors/ElementIntegralVariablePostprocessor.h @@ -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; }; diff --git a/framework/src/postprocessors/ElementIntegralVariablePostprocessor.C b/framework/src/postprocessors/ElementIntegralVariablePostprocessor.C index 3075d92e96d2..2dcad08538e3 100644 --- a/framework/src/postprocessors/ElementIntegralVariablePostprocessor.C +++ b/framework/src/postprocessors/ElementIntegralVariablePostprocessor.C @@ -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( + "use_absolute_value", false, "Whether to use abolsute value of the variable or not"); return params; } @@ -29,7 +31,8 @@ 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("use_absolute_value")) { addMooseVariableDependency(&mooseVariableField()); } @@ -37,5 +40,8 @@ ElementIntegralVariablePostprocessor::ElementIntegralVariablePostprocessor( Real ElementIntegralVariablePostprocessor::computeQpIntegral() { - return _u[_qp]; + if (_use_abs_value) + return std::abs(_u[_qp]); + else + return _u[_qp]; } diff --git a/test/tests/postprocessors/element_integral/element_integral_absolute_test.i b/test/tests/postprocessors/element_integral/element_integral_absolute_test.i new file mode 100644 index 000000000000..13c9f01166d8 --- /dev/null +++ b/test/tests/postprocessors/element_integral/element_integral_absolute_test.i @@ -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 +[] diff --git a/test/tests/postprocessors/element_integral/tests b/test/tests/postprocessors/element_integral/tests index 1751be3b67ea..fba50656ed0d 100644 --- a/test/tests/postprocessors/element_integral/tests +++ b/test/tests/postprocessors/element_integral/tests @@ -10,7 +10,7 @@ input = 'element_integral_test.i' csvdiff = 'out.csv' - detail = 'over the whole domain and' + detail = 'over the whole domain, and' [] [block_test] @@ -18,7 +18,15 @@ 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.' [] [] []