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