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 "AnalysisStepUserObject.h" 11 : #include "MooseUtils.h" 12 : #include <limits> 13 : #include <algorithm> 14 : 15 : registerMooseObject("SolidMechanicsApp", AnalysisStepUserObject); 16 : 17 : InputParameters 18 250 : AnalysisStepUserObject::validParams() 19 : { 20 250 : InputParameters params = GeneralUserObject::validParams(); 21 250 : params.addClassDescription( 22 : "Maps the time steps and the load step simulation times. It can be " 23 : "used in either direction depending on the simulation setup. It " 24 : "generates steps to be used in StepPeriod to control the enabled/disabled state of objects " 25 : "with user-provided simulation steps."); 26 500 : params.addParam<std::vector<Real>>( 27 : "step_start_times", 28 : "The beginning of step times. The number of steps is inferred from the number of times. One " 29 : "step is defined by its start time; and its end time is taken from the start time of the " 30 : "next step (if it exists). This list needs to be in ascending value order."); 31 500 : params.addParam<std::vector<Real>>( 32 : "step_end_times", 33 : "The end of step times. The number of steps is inferred from the number of times. One " 34 : "step is defined by the interval between previous start time and the next. The first step " 35 : "is assumed to start at time zero. This list needs to be in ascending value order."); 36 500 : params.addParam<Real>("total_time_interval", 37 : "The total time interval in which the steps take place. This option needs " 38 : "to be used together with the 'number_steps'."); 39 500 : params.addParam<unsigned int>( 40 : "number_steps", 41 : "Total number of steps in the total time inteval (provided as total_time_interval)."); 42 : 43 500 : params.addParam<std::vector<Real>>( 44 : "step_durations", 45 : "The durations of the steps. 'n' of step time intervals define 'n+1' steps " 46 : "starting at time equals zero."); 47 : 48 500 : params.addParam<bool>( 49 500 : "set_sync_times", false, "Whether to make the output times include the step times."); 50 : 51 250 : return params; 52 0 : } 53 : 54 125 : AnalysisStepUserObject::AnalysisStepUserObject(const InputParameters & parameters) 55 : : GeneralUserObject(parameters), 56 250 : _times(0), 57 125 : _step_durations(0), 58 125 : _total_time_interval(0), 59 125 : _number_steps(0) 60 : { 61 125 : const bool is_step_start_times = isParamSetByUser("step_start_times"); 62 125 : const bool is_step_end_times = isParamSetByUser("step_end_times"); 63 : const bool is_interval_and_steps = 64 264 : isParamSetByUser("total_time_interval") && isParamSetByUser("number_steps"); 65 125 : const bool is_step_durations = isParamSetByUser("step_durations"); 66 : 67 : // check for valid user input 68 125 : if (int(is_step_start_times) + int(is_step_end_times) + int(is_interval_and_steps) + 69 125 : int(is_step_durations) > 70 : 1) 71 0 : mooseError("In AnalysisStepUserObject, only one of 'step_start_times', 'step_end_times', " 72 : "'total_time_interval', and 'step_durations' can be set"); 73 507 : if ((isParamSetByUser("total_time_interval") && !isParamSetByUser("number_steps")) || 74 611 : (!isParamSetByUser("total_time_interval") && isParamSetByUser("number_steps"))) 75 0 : mooseError("In AnalysisStepUserObject, both 'total_time_interval' and 'number_steps' need both " 76 : "be set."); 77 : 78 : // define step times 79 125 : if (is_step_start_times) 80 : { 81 312 : _times = getParam<std::vector<Real>>("step_start_times"); 82 104 : if (!std::is_sorted(_times.begin(), _times.end())) 83 0 : paramError("step_start_times", 84 : "start times for AnalysisStepUserObject are not provided in ascending order. " 85 : "Please revise " 86 : "your input."); 87 : 88 104 : mooseInfo("Step start times are used to define simulation steps in ", name(), "."); 89 : } 90 21 : else if (is_step_end_times) 91 : { 92 21 : _times = getParam<std::vector<Real>>("step_end_times"); 93 7 : if (!std::is_sorted(_times.begin(), _times.end())) 94 0 : paramError( 95 : "step_end_times", 96 : "end times for AnalysisStepUserObject are not provided in ascending order. Please revise " 97 : "your input."); 98 7 : _times.insert(_times.begin(), 0.0); 99 : 100 7 : mooseInfo("Step start times are used to define simulation steps in ", name(), "."); 101 : } 102 14 : else if (is_interval_and_steps) 103 : { 104 14 : _total_time_interval = getParam<Real>("total_time_interval"); 105 14 : _number_steps = getParam<unsigned int>("number_steps"); 106 7 : _times.resize(_number_steps + 1); 107 : 108 28 : for (const auto i : index_range(_times)) 109 : { 110 21 : if (i == 0) 111 7 : _times[0] = 0.0; 112 : else 113 14 : _times[i] = _total_time_interval / _number_steps + _times[i - 1]; 114 : } 115 : 116 7 : mooseInfo("The total time interval and the provided number of steps are used to define " 117 : "simulation steps in ", 118 : name(), 119 : "."); 120 : } 121 7 : else if (is_step_durations) 122 : { 123 21 : _step_durations = getParam<std::vector<Real>>("step_durations"); 124 7 : _times.resize(_step_durations.size() + 1); 125 21 : for (const auto i : index_range(_times)) 126 : { 127 14 : if (i == 0) 128 7 : _times[i] = 0.0; 129 : else 130 7 : _times[i] = _step_durations[i - 1] + _times[i - 1]; 131 : } 132 7 : mooseInfo("Step durations are used to define simulation steps in ", name(), "."); 133 : } 134 : else 135 0 : paramError("step_start_times", 136 : "Plese provide 'step_start_times' or 'step_durations' or 'total_time_interval' and " 137 : "'number_steps' to define simulation loading steps."); 138 : 139 : // set sync times 140 250 : if (getParam<bool>("set_sync_times")) 141 : { 142 7 : std::set<Real> & sync_times = _app.getOutputWarehouse().getSyncTimes(); 143 28 : for (const auto t : _times) 144 21 : sync_times.insert(t); 145 : } 146 125 : } 147 : 148 : Real 149 2046 : AnalysisStepUserObject::getStartTime(const unsigned int & step) const 150 : { 151 2046 : if (_times.size() <= step) 152 0 : mooseError("AnalysisStepUserObject was called with a wrong step number"); 153 : 154 2046 : return _times[step]; 155 : } 156 : 157 : Real 158 84 : AnalysisStepUserObject::getEndTime(const unsigned int & step) const 159 : { 160 : Real end_time(0); 161 : 162 84 : if (_times.size() > step + 1) 163 56 : end_time = _times[step + 1]; 164 28 : else if (_times.size() == step + 1) 165 : end_time = std::numeric_limits<double>::max(); 166 : else 167 0 : mooseError("AnalysisStepUserObject was called with a wrong step number"); 168 : 169 84 : return end_time; 170 : } 171 : 172 : unsigned int 173 2325 : AnalysisStepUserObject::getStep(const Real & time) const 174 : { 175 : int which_step = 0; 176 : 177 4296 : for (const auto i : index_range(_times)) 178 : { 179 4296 : if (i + 1 == _times.size()) 180 1262 : return i; 181 : 182 3034 : which_step = i; 183 3034 : if (MooseUtils::absoluteFuzzyGreaterEqual(time, _times[i]) && 184 : MooseUtils::absoluteFuzzyLessThan(time, _times[i + 1])) 185 1063 : return which_step; 186 : } 187 : 188 0 : return which_step; 189 : } 190 : 191 : void 192 772 : AnalysisStepUserObject::initialize() 193 : { 194 772 : } 195 : void 196 772 : AnalysisStepUserObject::execute() 197 : { 198 772 : } 199 : void 200 772 : AnalysisStepUserObject::finalize() 201 : { 202 772 : }