Skip to content

Commit

Permalink
Merge pull request #29128 from anshchaube/num_time_steps
Browse files Browse the repository at this point in the history
Adds postprocessor to track time step number for transient problems
  • Loading branch information
GiudGiud authored Dec 3, 2024
2 parents 4a6a925 + 36121e8 commit 586fdf5
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 0 deletions.
13 changes: 13 additions & 0 deletions framework/doc/content/source/postprocessors/NumTimeSteps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# NumTimeSteps

!syntax description /Postprocessors/NumTimeSteps

## Example Input Syntax

!listing /test/tests/postprocessors/num_time_steps/numtimesteps.i block=Postprocessors

!syntax parameters /Postprocessors/NumTimeSteps

!syntax inputs /Postprocessors/NumTimeSteps

!syntax children /Postprocessors/NumTimeSteps
34 changes: 34 additions & 0 deletions framework/include/postprocessors/NumTimeSteps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//* 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"

/**
* Reports on the number of time steps already taken in the transient
*/
class NumTimeSteps : public GeneralPostprocessor
{
public:
static InputParameters validParams();

NumTimeSteps(const InputParameters & parameters);

virtual void initialize() override {}
virtual void execute() override {}

/**
* This will return the current time step number.
*/
virtual Real getValue() const override;

protected:
FEProblemBase & _feproblem;
};
32 changes: 32 additions & 0 deletions framework/src/postprocessors/NumTimeSteps.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//* 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 "NumTimeSteps.h"
#include "FEProblem.h"

registerMooseObject("MooseApp", NumTimeSteps);

InputParameters
NumTimeSteps::validParams()
{
InputParameters params = GeneralPostprocessor::validParams();
params.addClassDescription("Reports the timestep number");
return params;
}

NumTimeSteps::NumTimeSteps(const InputParameters & parameters)
: GeneralPostprocessor(parameters), _feproblem(dynamic_cast<FEProblemBase &>(_subproblem))
{
}

Real
NumTimeSteps::getValue() const
{
return _feproblem.timeStep();
}
12 changes: 12 additions & 0 deletions test/tests/postprocessors/num_time_steps/gold/numtimesteps_out.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
time,timestep_ctr
0,0
0.001,1
0.002,2
0.003,3
0.004,4
0.005,5
0.006,6
0.007,7
0.008,8
0.009,9
0.01,10
23 changes: 23 additions & 0 deletions test/tests/postprocessors/num_time_steps/numtimesteps.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[Mesh/gmg]
type = GeneratedMeshGenerator
dim = 1
[]

[Postprocessors/timestep_ctr]
type = NumTimeSteps
[]

[Problem]
solve = False
[]

[Executioner]
type = Transient
dt = 0.001
num_steps = 10
[]

[Outputs]
csv = true
exodus = false
[]
11 changes: 11 additions & 0 deletions test/tests/postprocessors/num_time_steps/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Tests]
issues = '#29127'
design = 'NumTimeSteps.md'
[num_time_steps]
type = 'CSVDiff'
input = 'numtimesteps.i'
csvdiff = 'numtimesteps_out.csv'
requirement = 'The postprocessor shall be able to count the number of time-steps that have been taken '
'over the course of the simulation of a transient.'
[]
[]

0 comments on commit 586fdf5

Please sign in to comment.