LCOV - code coverage report
Current view: top level - src/chaincontrols - TerminateChainControl.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 28 29 96.6 %
Date: 2025-07-17 01:28:37 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       14301 : TerminateChainControl::validParams()
      17             : {
      18       14301 :   InputParameters params = ChainControl::validParams();
      19             : 
      20       14301 :   params.addClassDescription(
      21             :       "Terminates the simulation when a boolean chain control data has a certain value.");
      22             : 
      23       14301 :   params.addRequiredParam<std::string>(
      24             :       "input", "Boolean control data indicating if the simulation should be terminated");
      25       42903 :   params.addParam<bool>("terminate_on_true",
      26       28602 :                         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       42903 :   params.addParam<bool>("throw_error",
      30       28602 :                         false,
      31             :                         "Flag to throw an error on termination; else just signal the problem to "
      32             :                         "terminate the solve.");
      33       14301 :   params.addRequiredParam<std::string>("termination_message",
      34             :                                        "Message to use if termination occurs");
      35       14301 :   return params;
      36           0 : }
      37             : 
      38          18 : TerminateChainControl::TerminateChainControl(const InputParameters & parameters)
      39             :   : ChainControl(parameters),
      40             : 
      41          18 :     _terminate_on_true(getParam<bool>("terminate_on_true")),
      42          18 :     _throw_error(getParam<bool>("throw_error")),
      43          18 :     _termination_message(getParam<std::string>("termination_message")),
      44          36 :     _input(getChainControlData<bool>("input"))
      45             : {
      46          18 : }
      47             : 
      48             : void
      49          46 : TerminateChainControl::execute()
      50             : {
      51          46 :   if (_terminate_on_true && _input)
      52          14 :     terminate();
      53             : 
      54          42 :   if (!_terminate_on_true && !_input)
      55           4 :     terminate();
      56          38 : }
      57             : 
      58             : void
      59          18 : TerminateChainControl::terminate()
      60             : {
      61          18 :   if (_throw_error)
      62           8 :     mooseError(_termination_message);
      63             :   else
      64             :   {
      65          10 :     _console << _termination_message << std::endl;
      66          10 :     _fe_problem.terminateSolve();
      67             :   }
      68          10 : }

Generated by: LCOV version 1.14