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 "Weibull.h"
11 : #include "math.h"
12 : #include "libmesh/utility.h"
13 :
14 : registerMooseObject("StochasticToolsApp", Weibull);
15 :
16 : InputParameters
17 338 : Weibull::validParams()
18 : {
19 338 : InputParameters params = Distribution::validParams();
20 338 : params.addClassDescription("Three-parameter Weibull distribution.");
21 676 : params.addRequiredParam<Real>("location", "Location parameter (a or low)");
22 676 : params.addRequiredRangeCheckedParam<Real>("scale", "scale > 0", "Scale parameter (b or lambda)");
23 676 : params.addRequiredRangeCheckedParam<Real>("shape", "shape > 0", "Shape parameter (c or k)");
24 338 : return params;
25 0 : }
26 :
27 169 : Weibull::Weibull(const InputParameters & parameters)
28 : : Distribution(parameters),
29 169 : _a(getParam<Real>("location")),
30 338 : _b(getParam<Real>("scale")),
31 507 : _c(getParam<Real>("shape"))
32 : {
33 169 : }
34 :
35 : Real
36 17 : Weibull::pdf(const Real & x, const Real & location, const Real & scale, const Real & shape)
37 : {
38 17 : if (x <= location)
39 : return 0.0;
40 : else
41 : {
42 17 : const Real y = (x - location) / scale;
43 17 : return shape / scale * std::pow(y, shape - 1.0) * std::exp(-std::pow(y, shape));
44 : }
45 : }
46 :
47 : Real
48 17 : Weibull::cdf(const Real & x, const Real & location, const Real & scale, const Real & shape)
49 : {
50 17 : if (x <= location)
51 : return 0.0;
52 : else
53 : {
54 17 : const Real y = (x - location) / scale;
55 17 : return 1.0 - std::exp(-std::pow(y, shape));
56 : }
57 : }
58 :
59 : Real
60 2187 : Weibull::quantile(const Real & p, const Real & location, const Real & scale, const Real & shape)
61 : {
62 2187 : return location + scale * std::pow(-std::log(1 - p), 1.0 / shape);
63 : }
64 :
65 : Real
66 17 : Weibull::pdf(const Real & x) const
67 : {
68 17 : return pdf(x, _a, _b, _c);
69 : }
70 :
71 : Real
72 17 : Weibull::cdf(const Real & x) const
73 : {
74 17 : return cdf(x, _a, _b, _c);
75 : }
76 :
77 : Real
78 2187 : Weibull::quantile(const Real & p) const
79 : {
80 2187 : return quantile(p, _a, _b, _c);
81 : }
|