From c9159488642b55db612c5210484baec4439f4467 Mon Sep 17 00:00:00 2001 From: Ansh Chaube Date: Sat, 23 Nov 2024 14:18:27 -0500 Subject: [PATCH 1/3] Adds postprocessor to track time step number for transient problems Minor quality-of-life improvement for users who want to track time step counts during their MOOSE simulations. closes #29127 --- .../source/postprocessors/NumTimeSteps.md | 17 ++++ .../include/postprocessors/NumTimeSteps.h | 31 ++++++ framework/src/postprocessors/NumTimeSteps.C | 32 ++++++ .../num_time_steps/gold/moose_out.csv | 12 +++ .../postprocessors/num_time_steps/moose.i | 98 +++++++++++++++++++ .../tests/postprocessors/num_time_steps/tests | 9 ++ 6 files changed, 199 insertions(+) create mode 100644 framework/doc/content/source/postprocessors/NumTimeSteps.md create mode 100644 framework/include/postprocessors/NumTimeSteps.h create mode 100644 framework/src/postprocessors/NumTimeSteps.C create mode 100644 test/tests/postprocessors/num_time_steps/gold/moose_out.csv create mode 100644 test/tests/postprocessors/num_time_steps/moose.i create mode 100644 test/tests/postprocessors/num_time_steps/tests diff --git a/framework/doc/content/source/postprocessors/NumTimeSteps.md b/framework/doc/content/source/postprocessors/NumTimeSteps.md new file mode 100644 index 000000000000..aa02c0df56c0 --- /dev/null +++ b/framework/doc/content/source/postprocessors/NumTimeSteps.md @@ -0,0 +1,17 @@ +# TimestepSize + +!syntax description /Postprocessors/NumTimeSteps + +## Description + +`NumTimeSteps` reports the timestep size. + +## 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 diff --git a/framework/include/postprocessors/NumTimeSteps.h b/framework/include/postprocessors/NumTimeSteps.h new file mode 100644 index 000000000000..58f5c90190bc --- /dev/null +++ b/framework/include/postprocessors/NumTimeSteps.h @@ -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 +{ +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/moose_out.csv b/test/tests/postprocessors/num_time_steps/gold/moose_out.csv new file mode 100644 index 000000000000..d7a5fc759cf3 --- /dev/null +++ b/test/tests/postprocessors/num_time_steps/gold/moose_out.csv @@ -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 diff --git a/test/tests/postprocessors/num_time_steps/moose.i b/test/tests/postprocessors/num_time_steps/moose.i new file mode 100644 index 000000000000..d7e6d3b3f5a9 --- /dev/null +++ b/test/tests/postprocessors/num_time_steps/moose.i @@ -0,0 +1,98 @@ +[Mesh] + 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 + num_steps = 10 +[] + +[Outputs] + exodus = false + csv = true + hide = 'source temperature' +[] + diff --git a/test/tests/postprocessors/num_time_steps/tests b/test/tests/postprocessors/num_time_steps/tests new file mode 100644 index 000000000000..4b7be1e6a7e1 --- /dev/null +++ b/test/tests/postprocessors/num_time_steps/tests @@ -0,0 +1,9 @@ +[Tests] + [num_time_steps] + type = 'CSVDiff' + input = 'numtimesteps.i' + csvdiff = 'numtimesteps_out.csv' + requirement = 'The postprocessor `NumTimeSteps` shall count the number of time-steps accurately' + 'over the course of a transient solve' + [] +[] From 20aa5b1b8830d37be393986afcb9e56dc3c6840d Mon Sep 17 00:00:00 2001 From: Ansh Chaube <31393012+anshchaube@users.noreply.github.com> Date: Sun, 24 Nov 2024 07:11:15 -0500 Subject: [PATCH 2/3] address review - updated wording, file names based on suggestions - added docstrings - simplified test, changed dt --- .../source/postprocessors/NumTimeSteps.md | 8 +- .../include/postprocessors/NumTimeSteps.h | 3 + .../num_time_steps/gold/moose_out.csv | 12 --- .../num_time_steps/gold/numtimesteps_out.csv | 12 +++ .../postprocessors/num_time_steps/moose.i | 98 ------------------- .../num_time_steps/numtimesteps.i | 23 +++++ .../tests/postprocessors/num_time_steps/tests | 4 +- 7 files changed, 42 insertions(+), 118 deletions(-) delete mode 100644 test/tests/postprocessors/num_time_steps/gold/moose_out.csv create mode 100644 test/tests/postprocessors/num_time_steps/gold/numtimesteps_out.csv delete mode 100644 test/tests/postprocessors/num_time_steps/moose.i create mode 100644 test/tests/postprocessors/num_time_steps/numtimesteps.i diff --git a/framework/doc/content/source/postprocessors/NumTimeSteps.md b/framework/doc/content/source/postprocessors/NumTimeSteps.md index aa02c0df56c0..a64b5b6b9014 100644 --- a/framework/doc/content/source/postprocessors/NumTimeSteps.md +++ b/framework/doc/content/source/postprocessors/NumTimeSteps.md @@ -1,14 +1,10 @@ -# TimestepSize +# NumTimeSteps !syntax description /Postprocessors/NumTimeSteps -## Description - -`NumTimeSteps` reports the timestep size. - ## Example Input Syntax -!listing /Users/achaube/tools/moose/test/tests/postprocessors/num_time_steps/moose.i block=Postprocessors +!listing /Users/achaube/tools/moose/test/tests/postprocessors/num_time_steps/numtimesteps.i block=Postprocessors !syntax parameters /Postprocessors/NumTimeSteps diff --git a/framework/include/postprocessors/NumTimeSteps.h b/framework/include/postprocessors/NumTimeSteps.h index 58f5c90190bc..fc6b7b2b43c5 100644 --- a/framework/include/postprocessors/NumTimeSteps.h +++ b/framework/include/postprocessors/NumTimeSteps.h @@ -11,6 +11,9 @@ #include "GeneralPostprocessor.h" +/** + * Reports on the number of time steps already taken in the transient + */ class NumTimeSteps : public GeneralPostprocessor { public: diff --git a/test/tests/postprocessors/num_time_steps/gold/moose_out.csv b/test/tests/postprocessors/num_time_steps/gold/moose_out.csv deleted file mode 100644 index d7a5fc759cf3..000000000000 --- a/test/tests/postprocessors/num_time_steps/gold/moose_out.csv +++ /dev/null @@ -1,12 +0,0 @@ -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 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/moose.i b/test/tests/postprocessors/num_time_steps/moose.i deleted file mode 100644 index d7e6d3b3f5a9..000000000000 --- a/test/tests/postprocessors/num_time_steps/moose.i +++ /dev/null @@ -1,98 +0,0 @@ -[Mesh] - 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 - num_steps = 10 -[] - -[Outputs] - exodus = false - csv = true - hide = 'source temperature' -[] - 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 index 4b7be1e6a7e1..c62c3b549d23 100644 --- a/test/tests/postprocessors/num_time_steps/tests +++ b/test/tests/postprocessors/num_time_steps/tests @@ -3,7 +3,7 @@ type = 'CSVDiff' input = 'numtimesteps.i' csvdiff = 'numtimesteps_out.csv' - requirement = 'The postprocessor `NumTimeSteps` shall count the number of time-steps accurately' - 'over the course of a transient solve' + 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.' [] [] From 36121e860e9aece06cd8e66bb1e8998ea15d0fea Mon Sep 17 00:00:00 2001 From: Guillaume Giudicelli Date: Sun, 1 Dec 2024 16:31:48 -0700 Subject: [PATCH 3/3] Add SQA items to test configuration Apply suggestions from code review corrects code listing path --- framework/doc/content/source/postprocessors/NumTimeSteps.md | 2 +- test/tests/postprocessors/num_time_steps/tests | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/framework/doc/content/source/postprocessors/NumTimeSteps.md b/framework/doc/content/source/postprocessors/NumTimeSteps.md index a64b5b6b9014..2ef891e81e8b 100644 --- a/framework/doc/content/source/postprocessors/NumTimeSteps.md +++ b/framework/doc/content/source/postprocessors/NumTimeSteps.md @@ -4,7 +4,7 @@ ## Example Input Syntax -!listing /Users/achaube/tools/moose/test/tests/postprocessors/num_time_steps/numtimesteps.i block=Postprocessors +!listing /test/tests/postprocessors/num_time_steps/numtimesteps.i block=Postprocessors !syntax parameters /Postprocessors/NumTimeSteps diff --git a/test/tests/postprocessors/num_time_steps/tests b/test/tests/postprocessors/num_time_steps/tests index c62c3b549d23..729f02d937b6 100644 --- a/test/tests/postprocessors/num_time_steps/tests +++ b/test/tests/postprocessors/num_time_steps/tests @@ -1,4 +1,6 @@ [Tests] + issues = '#29127' + design = 'NumTimeSteps.md' [num_time_steps] type = 'CSVDiff' input = 'numtimesteps.i'