LCOV - code coverage report
Current view: top level - src/vectorpostprocessors - ResponseSpectraCalculator.C (source / functions) Hit Total Coverage
Test: idaholab/mastodon: 55510a Lines: 59 62 95.2 %
Date: 2025-08-26 23:09:31 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // MOOSE includes
       2             : #include "ResponseSpectraCalculator.h"
       3             : #include "PostprocessorInterface.h"
       4             : #include "VectorPostprocessorInterface.h"
       5             : #include "MastodonUtils.h"
       6             : #include "ResponseHistoryBuilder.h"
       7             : 
       8             : registerMooseObject("MastodonApp", ResponseSpectraCalculator);
       9             : 
      10             : InputParameters
      11         140 : ResponseSpectraCalculator::validParams()
      12             : {
      13         140 :   InputParameters params = GeneralVectorPostprocessor::validParams();
      14         280 :   params.addRequiredParam<VectorPostprocessorName>(
      15             :       "vectorpostprocessor",
      16             :       "Name of the ResponseHistoryBuilder vectorpostprocessor, for which "
      17             :       "response spectra are calculated.");
      18         280 :   params.addParam<Real>("damping_ratio", 0.05, "Damping ratio for response spectra calculation.");
      19         280 :   params.addParam<Real>(
      20         280 :       "start_frequency", 0.01, "Start frequency for the response spectra calculation.");
      21         280 :   params.addParam<Real>(
      22         280 :       "end_frequency", 100.0, "End frequency for the response spectra calculation.");
      23         280 :   params.addParam<unsigned int>(
      24         280 :       "num_frequencies", 401, "Number of frequencies for the response spectra calculation.");
      25         280 :   params.addRequiredRangeCheckedParam<Real>("regularize_dt",
      26             :                                             "regularize_dt>0.0",
      27             :                                             "dt for response spectra calculation. The "
      28             :                                             "acceleration response will be regularized to this dt "
      29             :                                             "prior to the response spectrum calculation.");
      30             :   // Make sure that csv files are created only at the final timestep
      31         140 :   params.set<bool>("contains_complete_history") = true;
      32         140 :   params.suppressParameter<bool>("contains_complete_history");
      33             : 
      34         420 :   params.set<ExecFlagEnum>("execute_on") = {EXEC_FINAL};
      35         140 :   params.suppressParameter<ExecFlagEnum>("execute_on");
      36             : 
      37         140 :   params.addClassDescription("Calculate the response spectrum at the requested nodes or points.");
      38         140 :   return params;
      39         140 : }
      40             : 
      41          70 : ResponseSpectraCalculator::ResponseSpectraCalculator(const InputParameters & parameters)
      42             :   : GeneralVectorPostprocessor(parameters),
      43          70 :     _xi(getParam<Real>("damping_ratio")),
      44         140 :     _freq_start(getParam<Real>("start_frequency")),
      45         140 :     _freq_end(getParam<Real>("end_frequency")),
      46         140 :     _freq_num(getParam<unsigned int>("num_frequencies")),
      47         140 :     _reg_dt(getParam<Real>("regularize_dt")),
      48          70 :     _frequency(declareVector("frequency")),
      49          70 :     _period(declareVector("period")),
      50             :     // Time vector from the response history builder vector postprocessor
      51         140 :     _history_time(getVectorPostprocessorValue("vectorpostprocessor", "time"))
      52             : 
      53             : {
      54             :   // Check for starting and ending frequency
      55          70 :   if (_freq_start >= _freq_end)
      56           0 :     mooseError("Error in " + name() +
      57             :                ". Starting frequency must be less than the ending frequency.");
      58             :   // Check that frequencies are positive
      59          70 :   if (_freq_start <= 0.0)
      60           0 :     mooseError("Error in " + name() + ". Start and end frequencies must be positive.");
      61             :   // Check for damping
      62          70 :   if (_xi <= 0)
      63           0 :     mooseError("Error in " + name() + ". Damping ratio must be positive.");
      64          70 : }
      65             : 
      66             : void
      67          25 : ResponseSpectraCalculator::initialSetup()
      68             : {
      69          25 :   const ResponseHistoryBuilder & history_vpp = getUserObjectByName<ResponseHistoryBuilder>(
      70          25 :       getParam<VectorPostprocessorName>("vectorpostprocessor"));
      71             :   std::vector<std::string> history_names =
      72          25 :       history_vpp.getHistoryNames(); // names of the vectors in responsehistorybuilder
      73          25 :   _history_acc.resize(history_names.size());
      74             : 
      75             :   // Declaring three spectrum vectors: displacement, velocity and acceleration
      76             :   // for each vector in history VPP.
      77             :   // for (const std::string & name : _varnames)
      78          98 :   for (std::size_t i = 0; i < history_names.size(); i++)
      79             :   {
      80          73 :     _history_acc[i] = history_vpp.getHistories()[i];
      81         146 :     _spectrum.push_back(&declareVector(history_names[i] + "_sd"));
      82         146 :     _spectrum.push_back(&declareVector(history_names[i] + "_sv"));
      83         146 :     _spectrum.push_back(&declareVector(history_names[i] + "_sa"));
      84             :   }
      85          25 : }
      86             : 
      87             : void
      88          25 : ResponseSpectraCalculator::initialize()
      89             : {
      90          25 :   _frequency.clear();
      91          25 :   _period.clear();
      92         244 :   for (VectorPostprocessorValue * ptr : _spectrum)
      93         219 :     ptr->clear();
      94          25 : }
      95             : 
      96             : void
      97          25 : ResponseSpectraCalculator::execute()
      98             : {
      99          98 :   for (std::size_t i = 0; i < _history_acc.size(); ++i)
     100             :   {
     101             :     // The acceleration responses may or may not have a constant time step.
     102             :     // Therefore, they are regularized by default to a constant time step by the
     103             :     // regularize function before performing the response spectrum calculations.
     104             :     std::vector<std::vector<Real>> reg_vector =
     105          73 :         MastodonUtils::regularize(*_history_acc[i], _history_time, _reg_dt);
     106             :     // Calculation of the response spectrum. All three spectra: displacmeent,
     107             :     // velocity and acceleration, are calculated and output into a csv file.
     108             :     std::vector<std::vector<Real>> var_spectrum = MastodonUtils::responseSpectrum(
     109          73 :         _freq_start, _freq_end, _freq_num, reg_vector[1], _xi, _reg_dt);
     110          73 :     _frequency = var_spectrum[0];
     111          73 :     _period = var_spectrum[1];
     112          73 :     *_spectrum[3 * i] = var_spectrum[2];
     113          73 :     *_spectrum[3 * i + 1] = var_spectrum[3];
     114          73 :     *_spectrum[3 * i + 2] = var_spectrum[4];
     115          73 :   }
     116          25 : }

Generated by: LCOV version 1.14