Line data Source code
1 : // MOOSE includes 2 : #include "HousnerSpectrumIntensity.h" 3 : #include "PostprocessorInterface.h" 4 : #include "VectorPostprocessorInterface.h" 5 : #include "MastodonUtils.h" 6 : #include "LinearInterpolation.h" 7 : #include "ResponseHistoryBuilder.h" 8 : 9 : registerMooseObject("MastodonApp", HousnerSpectrumIntensity); 10 : 11 : InputParameters 12 32 : HousnerSpectrumIntensity::validParams() 13 : { 14 32 : InputParameters params = GeneralVectorPostprocessor::validParams(); 15 64 : params.addRequiredParam<VectorPostprocessorName>( 16 : "vectorpostprocessor", 17 : "Name of the ResponseHistoryBuilder vectorpostprocessor, for which " 18 : "HSIs are calculated."); 19 64 : params.addParam<Real>("damping_ratio", 0.05, "Damping ratio for HSI calculation."); 20 64 : params.addParam<Real>("start_period", 0.25, "Start period for the HSI calculation."); 21 64 : params.addParam<Real>("end_period", 2.5, "End period for the HSI calculation."); 22 64 : params.addParam<unsigned int>( 23 64 : "num_periods", 140, "Number of frequencies for the HSI calculation."); 24 64 : params.addRequiredRangeCheckedParam<Real>("regularize_dt", 25 : "regularize_dt>0.0", 26 : "dt for HSI calculation. The acceleration " 27 : "response will be regularized to this dt prior to " 28 : "the HSI calculation."); 29 : // Make sure that csv files are created only at the final timestep 30 32 : params.set<bool>("contains_complete_history") = true; 31 32 : params.suppressParameter<bool>("contains_complete_history"); 32 : 33 96 : params.set<ExecFlagEnum>("execute_on") = {EXEC_FINAL}; 34 32 : params.suppressParameter<ExecFlagEnum>("execute_on"); 35 32 : params.addClassDescription("Calculate the HSI for the requested acceleration variables."); 36 32 : return params; 37 32 : } 38 : 39 16 : HousnerSpectrumIntensity::HousnerSpectrumIntensity(const InputParameters & parameters) 40 : : GeneralVectorPostprocessor(parameters), 41 16 : _xi(getParam<Real>("damping_ratio")), 42 32 : _per_start(getParam<Real>("start_period")), 43 32 : _per_end(getParam<Real>("end_period")), 44 32 : _per_num(getParam<unsigned int>("num_periods")), 45 32 : _reg_dt(getParam<Real>("regularize_dt")), 46 : // Time vector from the ResponseHistoryBuilder vectorpostprocessor. 47 32 : _history_time(getVectorPostprocessorValue("vectorpostprocessor", "time")) 48 : 49 : { 50 : // Check for starting and ending period 51 16 : if (_per_start >= _per_end) 52 0 : mooseError("Error in " + name() + ". Starting period must be less than the ending period."); 53 : 54 : // Check for damping 55 16 : if (_xi <= 0) 56 0 : mooseError("Error in " + name() + ". Damping ratio must be positive."); 57 16 : } 58 : 59 : void 60 16 : HousnerSpectrumIntensity::initialSetup() 61 : { 62 16 : const ResponseHistoryBuilder & history_vpp = getUserObjectByName<ResponseHistoryBuilder>( 63 16 : getParam<VectorPostprocessorName>("vectorpostprocessor")); 64 : std::vector<std::string> history_names = 65 16 : history_vpp.getHistoryNames(); // names of the vectors in responsehistorybuilder 66 16 : _history_acc.resize(history_names.size()); 67 80 : for (unsigned int i = 0; i < history_names.size(); ++i) 68 : { 69 : // Acceleration vectors corresponding to the variables from the 70 : // ResponseHistoryBuilder vectorpostprocessor. 71 64 : _history_acc[i] = history_vpp.getHistories()[i]; 72 128 : _hsi_vec.push_back(&declareVector(history_names[i] + "_hsi")); 73 : } 74 16 : } 75 : 76 : void 77 16 : HousnerSpectrumIntensity::initialize() 78 : { 79 80 : for (std::size_t i = 0; i < _hsi_vec.size(); ++i) 80 64 : _hsi_vec[i]->clear(); 81 16 : } 82 : 83 : void 84 16 : HousnerSpectrumIntensity::execute() 85 : { 86 : std::vector<Real> period; 87 : std::vector<Real> vel_spectrum; 88 16 : Real freq_start = 1 / _per_end; 89 16 : Real freq_end = 1 / _per_start; 90 80 : for (unsigned int i = 0; i < _hsi_vec.size(); ++i) 91 : { 92 : // The acceleration responses may or may not have a constant time step. 93 : // Therefore, they are regularized by default to a constant time step by the 94 : // regularize function before performing the HSI calculations. 95 : std::vector<std::vector<Real>> reg_vector = 96 64 : MastodonUtils::regularize(*_history_acc[i], _history_time, _reg_dt); 97 : // Calculation of the response spectrum. 98 : std::vector<std::vector<Real>> var_spectrum = MastodonUtils::responseSpectrum( 99 64 : freq_start, freq_end, _per_num, reg_vector[1], _xi, _reg_dt); 100 64 : period = var_spectrum[1]; 101 64 : vel_spectrum = var_spectrum[3]; 102 64 : std::reverse(period.begin(), period.end()); 103 64 : std::reverse(vel_spectrum.begin(), vel_spectrum.end()); 104 64 : LinearInterpolation hsi_calc(period, vel_spectrum); 105 : // HSI is calculated as the area below the vel_spectrum curve. HSI is output 106 : // into the csv file in the same order as the variables in the .i file. 107 64 : _hsi_vec[i]->push_back(hsi_calc.integrate()); 108 64 : } 109 16 : }