Skip to content

Commit 5d09705

Browse files
committed
made it possible to output any of the three kinematic variables - there's no good reason why this shouldn't be allowed
(refs idaholab#296)
1 parent f0d7d7b commit 5d09705

File tree

2 files changed

+48
-28
lines changed

2 files changed

+48
-28
lines changed

include/functions/BaselineCorrection.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class BaselineCorrection;
2626

2727
/**
2828
* Applies a baseline correction to an accceleration time history using least squares polynomial
29-
* fits and outputs the adjusted acceleration with linear interpolation.
29+
* fits and outputs adjusted values for the specified kinematic variable.
3030
*/
3131
class BaselineCorrection : public Function
3232
{
@@ -38,31 +38,31 @@ class BaselineCorrection : public Function
3838
virtual Real value(Real t, const Point & /*P*/) const override;
3939

4040
protected:
41+
/// adjusted time series to evaluate - can be 'acceleration', 'velocity', or 'displacement'
42+
const MooseEnum _series;
43+
4144
/// Newmark integration parameters
4245
const Real & _gamma;
4346
const Real & _beta;
4447

45-
/// order used for the least squares polynomial fit
46-
unsigned int _order;
47-
4848
/// acceleration time history variables from input
4949
std::vector<Real> _time;
5050
std::vector<Real> _accel;
5151

52-
/// adjusted (corrected) acceleration ordinates
53-
std::vector<Real> _adj_accel;
52+
/// vector storing adjusted (corrected) time series values
53+
std::vector<Real> _adj_series;
5454

5555
/// linear interpolation object is applied over adjusted acceleration, i.e., AFTER correction
5656
std::unique_ptr<LinearInterpolation> _linear_interp;
5757

58-
/// function value scale factor - final output is scale_factor * _linear_interp(_time, _adj_accel)
58+
/// function multiplier - final output is 'scale_factor * _linear_interp(_time, _adj_series)'
5959
const Real & _scale_factor;
6060

6161
private:
62-
/// Applies baseline correction to raw acceleration time history
62+
/// Applies baseline correction to raw acceleration and copies adjusted ordinates to '_adj_series'
6363
void applyCorrection();
6464

65-
/// Reads and builds data from supplied CSV file
65+
/// Reads and builds data from supplied file using MooseUtils::DelimitedFileReader()
6666
void buildFromFile();
6767

6868
/// Builds data from pairs of `time_values` and `acceleration_values'

src/functions/BaselineCorrection.C

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ InputParameters
2828
BaselineCorrection::validParams()
2929
{
3030
InputParameters params = Function::validParams();
31-
params.addClassDescription("Applies a baseline correction to an accceleration time history "
32-
"using least squares polynomial fits and outputs the adjusted "
33-
"acceleration with linear interpolation.");
31+
params.addClassDescription("Applies a baseline correction to an accceleration time history using "
32+
"least squares polynomial fits and outputs adjusted values for the "
33+
"specified kinematic variable.");
34+
35+
MooseEnum series_type("acceleration velocity displacement", "acceleration");
36+
params.addParam<MooseEnum>(
37+
"series_type",
38+
series_type,
39+
"The kineamtic variable whose corrected time history is to be evaluated. The default is "
40+
"'acceleration'.");
3441

3542
params.addParam<FileName>(
3643
"data_file", "The name of a CSV file containing raw acceleration time history data.");
@@ -78,6 +85,7 @@ BaselineCorrection::validParams()
7885

7986
BaselineCorrection::BaselineCorrection(const InputParameters & parameters)
8087
: Function(parameters),
88+
_series(getParam<MooseEnum>("series_type")),
8189
_gamma(getParam<Real>("gamma")),
8290
_beta(getParam<Real>("beta")),
8391
_scale_factor(getParam<Real>("scale_factor"))
@@ -119,7 +127,7 @@ BaselineCorrection::BaselineCorrection(const InputParameters & parameters)
119127
// try building a linear interpolation object
120128
try
121129
{
122-
_linear_interp = libmesh_make_unique<LinearInterpolation>(_time, _adj_accel);
130+
_linear_interp = libmesh_make_unique<LinearInterpolation>(_time, _adj_series);
123131
}
124132
catch (std::domain_error & e)
125133
{
@@ -154,22 +162,22 @@ BaselineCorrection::applyCorrection()
154162
_accel[i], _accel[i + 1], vel[i], disp[i], _beta, dt));
155163
}
156164

157-
// initialize polyfits and adjusted time history arrays as the nominal ones
165+
// initialize polyfits and adjusted time history arrays with nominal ones
166+
unsigned int order;
158167
DenseVector<Real> coeffs;
159-
_adj_accel = _accel;
160-
std::vector<Real> p_fit, adj_vel = vel, adj_disp = disp;
168+
std::vector<Real> p_fit, adj_accel = _accel, adj_vel = vel, adj_disp = disp;
161169

162170
// adjust time histories with acceleration fit if desired
163171
if (isParamValid("accel_fit_order"))
164172
{
165-
_order = getParam<unsigned int>("accel_fit_order");
173+
order = getParam<unsigned int>("accel_fit_order");
166174
coeffs = BaselineCorrectionUtils::getAccelerationFitCoeffs(
167-
_order, _adj_accel, _time, index_end, _gamma);
175+
order, adj_accel, _time, index_end, _gamma);
168176

169177
for (unsigned int i = 0; i <= index_end; ++i)
170178
{
171-
p_fit = BaselineCorrectionUtils::computePolynomials(_order, coeffs, _time[i]);
172-
_adj_accel[i] -= p_fit[0];
179+
p_fit = BaselineCorrectionUtils::computePolynomials(order, coeffs, _time[i]);
180+
adj_accel[i] -= p_fit[0];
173181
adj_vel[i] -= p_fit[1];
174182
adj_disp[i] -= p_fit[2];
175183
}
@@ -178,30 +186,42 @@ BaselineCorrection::applyCorrection()
178186
// adjust with velocity fit
179187
if (isParamValid("vel_fit_order"))
180188
{
181-
_order = getParam<unsigned int>("vel_fit_order");
189+
order = getParam<unsigned int>("vel_fit_order");
182190
coeffs = BaselineCorrectionUtils::getVelocityFitCoeffs(
183-
_order, _adj_accel, adj_vel, _time, index_end, _beta);
191+
order, adj_accel, adj_vel, _time, index_end, _beta);
184192

185193
for (unsigned int i = 0; i <= index_end; ++i)
186194
{
187-
p_fit = BaselineCorrectionUtils::computePolynomials(_order, coeffs, _time[i]);
188-
_adj_accel[i] -= p_fit[0];
195+
p_fit = BaselineCorrectionUtils::computePolynomials(order, coeffs, _time[i]);
196+
adj_accel[i] -= p_fit[0];
197+
adj_vel[i] -= p_fit[1];
189198
adj_disp[i] -= p_fit[2];
190199
}
191200
}
192201

193202
// adjust with displacement fit
194203
if (isParamValid("disp_fit_order"))
195204
{
196-
_order = getParam<unsigned int>("disp_fit_order");
197-
coeffs = BaselineCorrectionUtils::getDisplacementFitCoeffs(_order, adj_disp, _time, index_end);
205+
order = getParam<unsigned int>("disp_fit_order");
206+
coeffs = BaselineCorrectionUtils::getDisplacementFitCoeffs(order, adj_disp, _time, index_end);
198207

199208
for (unsigned int i = 0; i <= index_end; ++i)
200209
{
201-
p_fit = BaselineCorrectionUtils::computePolynomials(_order, coeffs, _time[i]);
202-
_adj_accel[i] -= p_fit[0];
210+
p_fit = BaselineCorrectionUtils::computePolynomials(order, coeffs, _time[i]);
211+
adj_accel[i] -= p_fit[0];
212+
adj_vel[i] -= p_fit[1];
213+
adj_disp[i] -= p_fit[2];
203214
}
204215
}
216+
217+
// copy adjusted values for specified time series to a global variable (would it be faster to set
218+
// _adj_series with a std::map that pairs '_series' with 'adj_accel', etc.? Probably not...)
219+
if (_series == "acceleration")
220+
_adj_series = adj_accel;
221+
else if (_series == "velocity")
222+
_adj_series = adj_vel;
223+
else
224+
_adj_series = adj_disp;
205225
}
206226

207227
void

0 commit comments

Comments
 (0)