LCOV - code coverage report
Current view: top level - src/actions - AdaptiveSamplerAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: #31405 (292dce) with base fef103 Lines: 28 30 93.3 %
Date: 2025-09-04 07:57:52 Functions: 3 3 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 "AdaptiveSamplerAction.h"
      11             : #include "AddSamplerAction.h"
      12             : #include "FEProblem.h"
      13             : 
      14             : registerMooseAction("StochasticToolsApp", AdaptiveSamplerAction, "add_user_object");
      15             : registerMooseAction("StochasticToolsApp", AdaptiveSamplerAction, "add_postprocessor");
      16             : 
      17             : InputParameters
      18       11830 : AdaptiveSamplerAction::validParams()
      19             : {
      20       11830 :   InputParameters params = Action::validParams();
      21       11830 :   params.addClassDescription("Adds extra objects pertaining to adaptive samplers.");
      22       11830 :   return params;
      23           0 : }
      24             : 
      25       11830 : AdaptiveSamplerAction::AdaptiveSamplerAction(const InputParameters & params) : Action(params) {}
      26             : 
      27             : void
      28       11706 : AdaptiveSamplerAction::act()
      29             : {
      30       11706 :   const auto samplers = _app.actionWarehouse().getActions<AddSamplerAction>();
      31             :   SamplerName sampler_name;
      32             : 
      33             :   // determine whether the sampler is an adaptive sampler
      34       25514 :   for (auto & sampler : samplers)
      35       27616 :     if (adaptiveSamplerNames().count(sampler->getMooseObjectType()) > 0)
      36             :     {
      37         314 :       if (!sampler_name.empty())
      38           0 :         mooseError("The case with multiple adaptive samplers is not currently supported");
      39         628 :       sampler_name = sampler->name();
      40             :     }
      41             : 
      42       11706 :   if (sampler_name.empty())
      43             :     return;
      44             : 
      45         314 :   if (_current_task == "add_user_object")
      46             :   {
      47         314 :     InputParameters params = _factory.getValidParams("Terminator");
      48         314 :     params.set<std::string>("expression") = adaptiveSamplingCompletedPostprocessorName() + " > 0";
      49         157 :     params.set<std::string>("message") = "Sampling completed!";
      50         471 :     params.set<ExecFlagEnum>("execute_on") = {EXEC_TIMESTEP_END};
      51         314 :     _problem->addUserObject("Terminator", "_terminate" + sampler_name, params);
      52         157 :   }
      53         157 :   else if (_current_task == "add_postprocessor")
      54             :   {
      55         157 :     InputParameters params = _factory.getValidParams("AdaptiveSamplingCompletedPostprocessor");
      56         157 :     params.set<SamplerName>("sampler") = sampler_name;
      57         471 :     params.set<ExecFlagEnum>("execute_on") = {EXEC_TIMESTEP_END};
      58         471 :     params.set<std::vector<OutputName>>("outputs") = {"none"};
      59         314 :     _problem->addUserObject("AdaptiveSamplingCompletedPostprocessor",
      60         157 :                             adaptiveSamplingCompletedPostprocessorName(),
      61             :                             params);
      62         157 :   }
      63       12020 : }

Generated by: LCOV version 1.14