Skip to content

Commit

Permalink
Merge pull request idaholab#100 from somu15/timePP
Browse files Browse the repository at this point in the history
Time integrated reporter value PP
  • Loading branch information
rpodgorney authored Jul 13, 2022
2 parents c1ee3f3 + e6301bc commit b1b9616
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 0 deletions.
17 changes: 17 additions & 0 deletions doc/content/source/postprocessors/TimeIntegratedReporterValue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# TimeIntegratedReporterValue

!syntax description /Postprocessors/TimeIntegratedReporterValue

## Description

`TimeIntegratedReporterValue` computes the time integrated value of a reporter object.

## Example Input Syntax

!listing test/tests/time_integrated_reporter/main.i block=Postprocessors

!syntax parameters /Postprocessors/TimeIntegratedReporterValue

!syntax inputs /Postprocessors/TimeIntegratedReporterValue

!syntax children /Postprocessors/TimeIntegratedReporterValue
43 changes: 43 additions & 0 deletions include/postprocessors/TimeIntegratedReporterValue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "GeneralPostprocessor.h"

/**
* Integrate a reporter value over time using trapezoidal rule
*/
class TimeIntegratedReporterValue : public GeneralPostprocessor
{
public:
static InputParameters validParams();

TimeIntegratedReporterValue(const InputParameters & parameters);

virtual void initialize() override;
virtual void execute() override;
virtual Real getValue() override;

protected:
/// The total value of the variable
Real _value;

/// My old value
Real _value_old;

/// The current post-processor value
std::vector<Real> _pps_value;

/// The old post-processor value
Real _pps_value_old;

/// Return negative value of the output
const bool & _use_negative_value;
};
52 changes: 52 additions & 0 deletions src/postprocessors/TimeIntegratedReporterValue.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "TimeIntegratedReporterValue.h"

registerMooseObject("FalconApp", TimeIntegratedReporterValue);

InputParameters
TimeIntegratedReporterValue::validParams()
{
InputParameters params = GeneralPostprocessor::validParams();
params.addClassDescription("Integrate a Postprocessor value over time using trapezoidal rule.");
params.addRequiredParam<ReporterName>("reporter", "Reporter with the value.");
params.addParam<bool>("use_negative_value", false, "Return negative value of the output.");
return params;
}

TimeIntegratedReporterValue::TimeIntegratedReporterValue(const InputParameters & parameters)
: GeneralPostprocessor(parameters),
_value(0),
_value_old(0),
_pps_value(getReporterValue<std::vector<Real>>("reporter")),
_pps_value_old(0),
_use_negative_value(getParam<bool>("use_negative_value"))
{
}

void
TimeIntegratedReporterValue::initialize()
{
}

void
TimeIntegratedReporterValue::execute()
{
_pps_value = getReporterValue<std::vector<Real>>("reporter");
_value = _value_old + 0.5 * (_pps_value[0] + _pps_value_old) * _dt;
_pps_value_old = _pps_value[0];
_value_old = _value;
}

Real
TimeIntegratedReporterValue::getValue()
{
return _use_negative_value ? (-_value) : _value;
}
7 changes: 7 additions & 0 deletions test/tests/time_integrated_reporter/gold/main_out.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
time,int_value,pp
0,0,1
1,-0.5,1
2,-1.5,1
3,-2.5,1
4,-3.5,1
5,-4.5,1
54 changes: 54 additions & 0 deletions test/tests/time_integrated_reporter/main.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[Mesh/mesh]
type = GeneratedMeshGenerator
dim = 1
[]

[Problem]
kernel_coverage_check = false
solve = false
[]

[Functions/fun]
type = ParsedFunction
value = '1'
[]

[Postprocessors/pp]
type = FunctionValuePostprocessor
function = fun
point = '1 0 0'
execute_on = 'initial timestep_end'
[]

[Reporters]
[accumulate]
type = AccumulateReporter
reporters = 'pp/value'
[]
[]

[Executioner]
type = Transient
num_steps = 5

fixed_point_max_its = 1
custom_pp = pp
direct_pp_value = true
disable_fixed_point_residual_norm_check = true
accept_on_max_fixed_point_iteration = true
[]

[Postprocessors]
[int_value]
type = TimeIntegratedReporterValue
reporter = 'accumulate/pp:value'
use_negative_value = true
[]
[]

[Outputs]
[out]
type = CSV
execute_system_information_on = none
[]
[]
10 changes: 10 additions & 0 deletions test/tests/time_integrated_reporter/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Tests]
[timeintegratedreporter]
type = 'CSVDiff'
input = 'main.i'
csvdiff = 'main_out.csv'
abs_zero = 1.0e-07
rel_err = 1.0e-04
[]
[]

0 comments on commit b1b9616

Please sign in to comment.