Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds postprocessor to track time step number for transient problems #29128

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
anshchaube marked this conversation as resolved.
Show resolved Hide resolved
{
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();
}
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]
GiudGiud marked this conversation as resolved.
Show resolved Hide resolved
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.'
[]
[]