diff --git a/framework/doc/content/source/postprocessors/NumTimeSteps.md b/framework/doc/content/source/postprocessors/NumTimeSteps.md new file mode 100644 index 000000000000..2ef891e81e8b --- /dev/null +++ b/framework/doc/content/source/postprocessors/NumTimeSteps.md @@ -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 diff --git a/framework/include/postprocessors/NumTimeSteps.h b/framework/include/postprocessors/NumTimeSteps.h new file mode 100644 index 000000000000..fc6b7b2b43c5 --- /dev/null +++ b/framework/include/postprocessors/NumTimeSteps.h @@ -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; +}; diff --git a/framework/src/postprocessors/NumTimeSteps.C b/framework/src/postprocessors/NumTimeSteps.C new file mode 100644 index 000000000000..63897f5381bf --- /dev/null +++ b/framework/src/postprocessors/NumTimeSteps.C @@ -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(_subproblem)) +{ +} + +Real +NumTimeSteps::getValue() const +{ + return _feproblem.timeStep(); +} diff --git a/test/tests/postprocessors/num_time_steps/gold/numtimesteps_out.csv b/test/tests/postprocessors/num_time_steps/gold/numtimesteps_out.csv new file mode 100644 index 000000000000..2c892a836f9e --- /dev/null +++ b/test/tests/postprocessors/num_time_steps/gold/numtimesteps_out.csv @@ -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 diff --git a/test/tests/postprocessors/num_time_steps/numtimesteps.i b/test/tests/postprocessors/num_time_steps/numtimesteps.i new file mode 100644 index 000000000000..2991ea9ff690 --- /dev/null +++ b/test/tests/postprocessors/num_time_steps/numtimesteps.i @@ -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 +[] diff --git a/test/tests/postprocessors/num_time_steps/tests b/test/tests/postprocessors/num_time_steps/tests new file mode 100644 index 000000000000..729f02d937b6 --- /dev/null +++ b/test/tests/postprocessors/num_time_steps/tests @@ -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.' + [] +[]