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

Generated by: LCOV version 1.14