LCOV - code coverage report
Current view: top level - src/chaincontrols - TerminateChainControl.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 28 29 96.6 %
Date: 2026-05-29 20:35:17 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #include "TerminateChainControl.h"
      11             : #include "FEProblemBase.h"
      12             : 
      13             : registerMooseObject("MooseApp", TerminateChainControl);
      14             : 
      15             : InputParameters
      16        3091 : TerminateChainControl::validParams()
      17             : {
      18        3091 :   InputParameters params = ChainControl::validParams();
      19             : 
      20        6182 :   params.addClassDescription(
      21             :       "Terminates the simulation when a boolean chain control data has a certain value.");
      22             : 
      23       12364 :   params.addRequiredParam<std::string>(
      24             :       "input", "Boolean control data indicating if the simulation should be terminated");
      25        9273 :   params.addParam<bool>("terminate_on_true",
      26        6182 :                         true,
      27             :                         "If set to 'true', termination occurs if the input has a value of 'true'; "
      28             :                         "else termination occurs if the input has a value of 'false'");
      29        9273 :   params.addParam<bool>("throw_error",
      30        6182 :                         false,
      31             :                         "Flag to throw an error on termination; else just signal the problem to "
      32             :                         "terminate the solve.");
      33        9273 :   params.addRequiredParam<std::string>("termination_message",
      34             :                                        "Message to use if termination occurs");
      35        3091 :   return params;
      36           0 : }
      37             : 
      38          15 : TerminateChainControl::TerminateChainControl(const InputParameters & parameters)
      39             :   : ChainControl(parameters),
      40             : 
      41          15 :     _terminate_on_true(getParam<bool>("terminate_on_true")),
      42          30 :     _throw_error(getParam<bool>("throw_error")),
      43          30 :     _termination_message(getParam<std::string>("termination_message")),
      44          45 :     _input(getChainControlData<bool>("input"))
      45             : {
      46          15 : }
      47             : 
      48             : void
      49          39 : TerminateChainControl::execute()
      50             : {
      51          39 :   if (_terminate_on_true && _input)
      52          12 :     terminate();
      53             : 
      54          36 :   if (!_terminate_on_true && !_input)
      55           3 :     terminate();
      56          33 : }
      57             : 
      58             : void
      59          15 : TerminateChainControl::terminate()
      60             : {
      61          15 :   if (_throw_error)
      62           6 :     mooseError(_termination_message);
      63             :   else
      64             :   {
      65           9 :     _console << _termination_message << std::endl;
      66           9 :     _fe_problem.terminateSolve();
      67             :   }
      68           9 : }

Generated by: LCOV version 1.14