LCOV - code coverage report
Current view: top level - src/transfers - HazardCurveTransfer.C (source / functions) Hit Total Coverage
Test: idaholab/mastodon: 55510a Lines: 26 28 92.9 %
Date: 2025-08-26 23:09:31 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // MOOSE includes
       2             : #include "FEProblemBase.h"
       3             : #include "MultiApp.h"
       4             : #include "PiecewiseLinearBase.h"
       5             : #include "Conversion.h"
       6             : 
       7             : // MASTODON includes
       8             : #include "HazardCurveMultiApp.h"
       9             : #include "HazardCurveTransfer.h"
      10             : 
      11             : registerMooseObject("MastodonApp", HazardCurveTransfer);
      12             : 
      13             : InputParameters
      14          12 : HazardCurveTransfer::validParams()
      15             : {
      16          12 :   InputParameters params = MultiAppTransfer::validParams();
      17          12 :   params.addClassDescription("Transfers scaled ground motion data from a HazardCurve object to "
      18             :                              "a PiecewiseLinear function on the sub application.");
      19          24 :   params.addRequiredParam<std::string>(
      20             :       "function",
      21             :       "The name of the function on the sub application to which data will be transferred");
      22          24 :   params.addParam<MooseEnum>(
      23             :       "component",
      24          36 :       MooseEnum("x=1 y=2 z=3", "x"), // These enums must correspond to GroundMotionReader::component
      25             :       "The (x, y, z) component of the ground motion that will be "
      26             :       "transfered to the sub application.");
      27          12 :   return params;
      28           0 : }
      29             : 
      30           6 : HazardCurveTransfer::HazardCurveTransfer(const InputParameters & parameters)
      31           6 :   : MultiAppTransfer(parameters), UserObjectInterface(this)
      32             : {
      33           6 : }
      34             : 
      35             : void
      36          39 : HazardCurveTransfer::execute()
      37             : {
      38             :   // Require HazardCurveMultiApp
      39             :   std::shared_ptr<HazardCurveMultiApp> ptr =
      40          78 :       std::dynamic_pointer_cast<HazardCurveMultiApp>(getMultiApp());
      41          39 :   if (!ptr)
      42           0 :     mooseError(
      43             :         "The HazardCurveTransfer '", name(), "' will only work with a HazardCurveMultiApp object.");
      44             : 
      45             :   // Get input required for transfer
      46          39 :   const HazardCurve & hazard_curve = ptr->getUserObject<HazardCurve>("hazard");
      47          39 :   const std::string & function_name = getParam<std::string>("function");
      48             :   GroundMotionReader::Component comp =
      49          78 :       getParam<MooseEnum>("component").getEnum<GroundMotionReader::Component>();
      50             : 
      51             :   // Double check sizes, this really shouldn't be possible to trip
      52             :   mooseAssert(getMultiApp()->numGlobalApps() == hazard_curve.count(),
      53             :               "The number of apps does not match the number of hazard curves.");
      54             : 
      55             :   // Loop over
      56             :   unsigned int global_index = 0;
      57         117 :   for (std::size_t bin = 0; bin < hazard_curve.bins(); ++bin)
      58         330 :     for (std::size_t index = 0; index < hazard_curve.count(bin); ++index)
      59             :     {
      60         504 :       if (getMultiApp()->hasLocalApp(global_index))
      61             :       {
      62             :         const std::vector<Real> & t =
      63         168 :             hazard_curve.getData(bin, index, GroundMotionReader::Component::TIME);
      64         168 :         const std::vector<Real> & a = hazard_curve.getData(bin, index, comp);
      65             : 
      66         168 :         FEProblemBase & problem = getMultiApp()->appProblemBase(global_index);
      67             :         PiecewiseLinearBase & function =
      68         168 :             dynamic_cast<PiecewiseLinearBase &>(problem.getFunction(function_name));
      69         168 :         function.setData(t, a);
      70             :       }
      71         252 :       global_index++;
      72             :     }
      73          39 : }

Generated by: LCOV version 1.14