LCOV - code coverage report
Current view: top level - src/userobjects - GroundMotionReader.C (source / functions) Hit Total Coverage
Test: idaholab/mastodon: 55510a Lines: 48 54 88.9 %
Date: 2025-08-26 23:09:31 Functions: 7 9 77.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // MOOSE includes
       2             : #include "DelimitedFileReader.h"
       3             : 
       4             : // MASTODON includes
       5             : #include "GroundMotionReader.h"
       6             : #include "MastodonUtils.h"
       7             : 
       8             : registerMooseObject("MastodonApp", GroundMotionReader);
       9             : 
      10             : InputParameters
      11          33 : GroundMotionReader::validParams()
      12             : {
      13          33 :   InputParameters params = GeneralUserObject::validParams();
      14          33 :   params.addClassDescription("Reads ground motion data from files.");
      15          33 :   params.set<ExecFlagEnum>("execute_on") = EXEC_NONE;
      16          33 :   params.suppressParameter<ExecFlagEnum>("execute_on");
      17          66 :   params.addRequiredParam<std::string>(
      18             :       "pattern", "The filename pattern (glob) for the ground motions to read.");
      19          33 :   return params;
      20           0 : }
      21             : 
      22          17 : GroundMotionReader::GroundMotionReader(const InputParameters & parameters)
      23          34 :   : GeneralUserObject(parameters), _pattern(getParam<std::string>("pattern"))
      24             : {
      25          17 :   execute();
      26          16 : }
      27             : 
      28             : void
      29          17 : GroundMotionReader::execute()
      30             : {
      31          17 :   _readers = execute(name(), _pattern);
      32          16 : }
      33             : 
      34             : const std::vector<double> &
      35           0 : GroundMotionReader::getData(const std::size_t & index, Component comp) const
      36             : {
      37           0 :   return getData(name(), _readers, index, comp);
      38             : }
      39             : 
      40             : GroundMotionReader::Data
      41           0 : GroundMotionReader::getData(const Real & scale, const Real & offset) const
      42             : {
      43           0 :   return getData(name(), _readers, scale, offset);
      44             : }
      45             : 
      46             : std::vector<std::unique_ptr<MooseUtils::DelimitedFileReader>>
      47          21 : GroundMotionReader::execute(const std::string & name, const std::string & pattern)
      48             : {
      49          21 :   std::vector<std::string> names = MastodonUtils::glob(pattern);
      50          21 :   if (names.empty())
      51           2 :     ::mooseError("Unable to locate files with the given pattern (",
      52             :                  pattern,
      53             :                  ") in the GroundMotionReader object '",
      54             :                  name,
      55             :                  "'.");
      56             : 
      57             :   std::vector<std::unique_ptr<MooseUtils::DelimitedFileReader>> readers;
      58          19 :   readers.reserve(names.size());
      59         185 :   for (const std::string & filename : names)
      60             :   {
      61             :     std::unique_ptr<MooseUtils::DelimitedFileReader> reader =
      62         166 :         libmesh_make_unique<MooseUtils::DelimitedFileReader>(filename);
      63         166 :     reader->read();
      64         166 :     readers.emplace_back(std::move(reader));
      65         166 :   }
      66          19 :   return readers;
      67          20 : }
      68             : 
      69             : unsigned int
      70         348 : GroundMotionReader::count() const
      71             : {
      72         348 :   return _readers.size();
      73             : }
      74             : 
      75             : const std::vector<double> &
      76        1374 : GroundMotionReader::getData(
      77             :     const std::string & name,
      78             :     const std::vector<std::unique_ptr<MooseUtils::DelimitedFileReader>> & readers,
      79             :     const std::size_t & index,
      80             :     Component comp)
      81             : {
      82        1374 :   if (readers.empty())
      83           1 :     ::mooseError("The GroundMotionReader object '",
      84             :                  name,
      85             :                  "' must execute prior to accessing data, check the "
      86             :                  "'execute_on' settings for this object.");
      87             : 
      88        1373 :   if (index >= readers.size())
      89           1 :     ::mooseError("The GroundMotionReader object '",
      90             :                  name,
      91             :                  "' contains ",
      92           1 :                  readers.size(),
      93             :                  " ground motions, but an index of ",
      94             :                  index,
      95             :                  " was requested.");
      96             : 
      97        1372 :   return readers[index]->getData()[static_cast<std::size_t>(comp)];
      98             : }
      99             : 
     100             : GroundMotionReader::Data
     101          40 : GroundMotionReader::getData(
     102             :     const std::string & name,
     103             :     const std::vector<std::unique_ptr<MooseUtils::DelimitedFileReader>> & readers,
     104             :     const Real & scale,
     105             :     const Real & offset)
     106             : {
     107          40 :   if (readers.empty())
     108           1 :     ::mooseError("The GroundMotionReader object '",
     109             :                  name,
     110             :                  "' must execute prior to accessing data, check the "
     111             :                  "'execute_on' settings for this object.");
     112             : 
     113          39 :   Data output(readers.size());
     114         381 :   for (std::size_t i = 0; i < readers.size(); ++i)
     115             :   {
     116         342 :     output[i][Component::TIME] = getData(name, readers, i, Component::TIME);
     117         342 :     output[i][Component::X] =
     118         684 :         MastodonUtils::adjust(getData(name, readers, i, Component::X), scale, offset);
     119         342 :     output[i][Component::Y] =
     120         684 :         MastodonUtils::adjust(getData(name, readers, i, Component::Y), scale, offset);
     121         342 :     output[i][Component::Z] =
     122         684 :         MastodonUtils::adjust(getData(name, readers, i, Component::Z), scale, offset);
     123             :   }
     124          39 :   return output;
     125           0 : }

Generated by: LCOV version 1.14