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 1 commit
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
17 changes: 17 additions & 0 deletions framework/doc/content/source/postprocessors/NumTimeSteps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# TimestepSize
anshchaube marked this conversation as resolved.
Show resolved Hide resolved

!syntax description /Postprocessors/NumTimeSteps

## Description

`NumTimeSteps` reports the timestep size.

anshchaube marked this conversation as resolved.
Show resolved Hide resolved
## Example Input Syntax

!listing /Users/achaube/tools/moose/test/tests/postprocessors/num_time_steps/moose.i block=Postprocessors

!syntax parameters /Postprocessors/NumTimeSteps

!syntax inputs /Postprocessors/NumTimeSteps

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

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();
}
12 changes: 12 additions & 0 deletions test/tests/postprocessors/num_time_steps/gold/moose_out.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
time,timestep_ctr
0,0
1,1
2,2
3,3
4,4
5,5
6,6
7,7
8,8
9,9
10,10
98 changes: 98 additions & 0 deletions test/tests/postprocessors/num_time_steps/moose.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
[Mesh]
loganharbour marked this conversation as resolved.
Show resolved Hide resolved
type = GeneratedMesh
dim = 3
nx = 30
ny = 30
nz = 30
[]

[Variables]
[temperature]
initial_condition = 500.0
[]
[]

[AuxVariables]
[source]
[]
[]

[Kernels]
[conduction]
type = HeatConduction
variable = temperature
[]
[source]
type = CoupledForce
variable = temperature
v = source
[]
[]

[AuxKernels]
[source]
type = ParsedAux
variable = source
function = 'temperature*7*t'
coupled_variables = 'temperature'
execute_on = 'linear'
use_xyzt = true
[]
[]

[BCs]
[left]
type = DirichletBC
variable = temperature
boundary = 'left'
value = 500.0
[]
[right]
type = DirichletBC
variable = temperature
boundary = 'right'
value = 600.0
[]
[top]
type = DirichletBC
variable = temperature
boundary = 'top'
value = 650.0
[]
[front]
type = DirichletBC
variable = temperature
boundary = 'front'
value = 650.0
[]
[]

[Materials]
[k]
type = GenericConstantMaterial
prop_names = 'thermal_conductivity'
prop_values = '1.5'
[]
[]

[Postprocessors]
[timestep_ctr]
type = NumTimeSteps
[]
[]


[Executioner]
type = Transient
nl_abs_tol = 1e-10
nl_rel_tol = 1e-4
dt = 1
loganharbour marked this conversation as resolved.
Show resolved Hide resolved
num_steps = 10
[]

[Outputs]
exodus = false
csv = true
hide = 'source temperature'
[]

9 changes: 9 additions & 0 deletions test/tests/postprocessors/num_time_steps/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Tests]
GiudGiud marked this conversation as resolved.
Show resolved Hide resolved
[num_time_steps]
type = 'CSVDiff'
input = 'numtimesteps.i'
csvdiff = 'numtimesteps_out.csv'
requirement = 'The postprocessor `NumTimeSteps` shall count the number of time-steps accurately'
anshchaube marked this conversation as resolved.
Show resolved Hide resolved
'over the course of a transient solve'
anshchaube marked this conversation as resolved.
Show resolved Hide resolved
[]
[]