https://mooseframework.inl.gov
Weibull.C
Go to the documentation of this file.
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 
18 {
20  params.addClassDescription("Three-parameter Weibull distribution.");
21  params.addRequiredParam<Real>("location", "Location parameter (a or low)");
22  params.addRequiredRangeCheckedParam<Real>("scale", "scale > 0", "Scale parameter (b or lambda)");
23  params.addRequiredRangeCheckedParam<Real>("shape", "shape > 0", "Shape parameter (c or k)");
24  return params;
25 }
26 
27 Weibull::Weibull(const InputParameters & parameters)
28  : Distribution(parameters),
29  _a(getParam<Real>("location")),
30  _b(getParam<Real>("scale")),
31  _c(getParam<Real>("shape"))
32 {
33 }
34 
35 Real
36 Weibull::pdf(const Real & x, const Real & location, const Real & scale, const Real & shape)
37 {
38  if (x <= location)
39  return 0.0;
40  else
41  {
42  const Real y = (x - location) / scale;
43  return shape / scale * std::pow(y, shape - 1.0) * std::exp(-std::pow(y, shape));
44  }
45 }
46 
47 Real
48 Weibull::cdf(const Real & x, const Real & location, const Real & scale, const Real & shape)
49 {
50  if (x <= location)
51  return 0.0;
52  else
53  {
54  const Real y = (x - location) / scale;
55  return 1.0 - std::exp(-std::pow(y, shape));
56  }
57 }
58 
59 Real
60 Weibull::quantile(const Real & p, const Real & location, const Real & scale, const Real & shape)
61 {
62  return location + scale * std::pow(-std::log(1 - p), 1.0 / shape);
63 }
64 
65 Real
66 Weibull::pdf(const Real & x) const
67 {
68  return pdf(x, _a, _b, _c);
69 }
70 
71 Real
72 Weibull::cdf(const Real & x) const
73 {
74  return cdf(x, _a, _b, _c);
75 }
76 
77 Real
78 Weibull::quantile(const Real & p) const
79 {
80  return quantile(p, _a, _b, _c);
81 }
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
void scale(MeshBase &mesh, const Real xs, const Real ys=0., const Real zs=0.)
virtual Real cdf(const Real &x) const override
Definition: Weibull.C:72
virtual Real pdf(const Real &x) const override
Definition: Weibull.C:66
const std::vector< double > y
const Real & _c
The shape parameter (c or k)
Definition: Weibull.h:41
void addRequiredParam(const std::string &name, const std::string &doc_string)
const Real & _a
The location parameter (a or low)
Definition: Weibull.h:35
const std::vector< double > x
Weibull(const InputParameters &parameters)
Definition: Weibull.C:27
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Real & _b
The scale parameter (b or lambda)
Definition: Weibull.h:38
static InputParameters validParams()
void addClassDescription(const std::string &doc_string)
virtual Real quantile(const Real &p) const override
Definition: Weibull.C:78
registerMooseObject("StochasticToolsApp", Weibull)
MooseUnits pow(const MooseUnits &, int)
static InputParameters validParams()
Definition: Weibull.C:17
A class used to generate a three-parameter Weibull distribution.
Definition: Weibull.h:17