# Stochastic Tools

The stochastic tools module is a toolbox designed for performing stochastic analysis for MOOSE-based applications. The following sections detail the various aspects of this module that can be used independently or in combination to meet the needs of the application developer.

## Examples

## Distributions

Distribution objects in MOOSE are function-like in that they have methods that are called on-demand by other objects and do not maintain any state. A custom Distribution object is created in the typical fashion, by creating a C++ class that inherits from the Distribution base class. Three functions are required to be overridden: "pdf", "cdf", and "quantile".

The "pdf" method must return the value of the probability density function (PDF) of the distribution. Similarly, the "cdf" method must return the value of the cumulative distribution function (CDF). Finally, the "quantile" method must return the inverse of the CDF, which is commonly referred to as the quantile function.

For example Listing 1 is the header for the UniformDistribution, which overrides the aforementioned methods.

```
#ifndef UNIFORMDISTRIBUTION_H
#define UNIFORMDISTRIBUTION_H
#include "Distribution.h"
class UniformDistribution;
template <>
InputParameters validParams<UniformDistribution>();
/**
* A class used to generate uniform distribution
*/
class UniformDistribution : public Distribution
{
public:
UniformDistribution(const InputParameters & parameters);
virtual Real pdf(const Real & x) override;
virtual Real cdf(const Real & x) override;
virtual Real quantile(const Real & y) override;
protected:
/// The lower bound for the uniform distribution
const Real & _lower_bound;
/// The upper bound for the uniform distribution
const Real & _upper_bound;
};
#endif /* UNIFORMDISTRIBUTION_H */
```

(modules/stochastic_tools/include/distributions/UniformDistribution.h)To utilize a Distribution object within an input file, first the object must be created and secondly an object must be defined to use the distribution. Distribution objects may be created in the input file within the Distributions block, as shown below.

```
[Distributions]
[./uniform]
type = UniformDistribution
lower_bound = 5
upper_bound = 10
[../]
[]
```

(modules/stochastic_tools/test/tests/distributions/uniform.i)To use a distribution an object must inherit from the DistributionInterface, which provides to methods:

**getDistribution**

This method accepts the name of an input parameter added via a call with the`addParam<DistributionName>`

method. In general, application developers will use this method.**getDistributionByName**

This method accepts the explicitly defined name of a distribution. In general, application developers*will not*utilize this method.

Each of these methods return a reference to Distribution object, from which you call the various methods on the object as discussed previously.

## Samplers

Sampler objects in MOOSE are designed to generate an arbitrary set of data sampled from any number of Distribution objects.

The sampler operators by returning a vector of matrices (`std::vector<DenseMatrix>`

) from the `getSamples`

method. The application developer is responsible for creating this output as needed depending on the type of sampler.

However, in general, the system is designed such that each row in the matrices represents a complete set of samples that could be passed to sub-applications via the SamplerMultiApp.

## Objects, Actions, and Syntax

## Controls

- Moose App
- AddControlAction
- RealFunctionControlSets the value of a 'Real' input parameters to the value of a provided function.
- TimePeriodControl the enabled/disabled state of objects with time.
- Stochastic Tools App
- SamplerReceiverControl for receiving data from a Sampler via SamplerTransfer.

## Distributions

- Moose App
- AddDistributionAction
- Stochastic Tools App
- LognormalDistributionBoost Lognormal distribution.
- NormalDistributionBoost Normal distribution.
- UniformDistributionContinuous uniform distribution.
- WeibullDistributionBoost Weibull distribution.

## MultiApps

- Moose App
- AddMultiAppAction
- AutoPositionsMultiApp
- CentroidMultiApp
- FullSolveMultiApp
- TransientMultiApp
- Level Set App
- LevelSetReinitializationMultiAppMultiApp capable of performing repeated complete solves for level set reinitialization.
- Stochastic Tools App
- SamplerMultiAppCreates a sub-application for each row of each Sampler matrix.

## Samplers

- Moose App
- AddSamplerAction
- Stochastic Tools App
- MonteCarloSamplerMonte Carlo Sampler.
- SobolSamplerSobol variance-based sensitivity analysis Sampler.

## Transfers

- Moose App
- AddTransferAction
- MultiAppCopyTransferCopies variables (nonlinear and auxiliary) between multiapps that have identical meshes.
- MultiAppInterpolationTransferTransfers the value to the target domain from the nearest node in the source domain.
- MultiAppMeshFunctionTransfer
- MultiAppNearestNodeTransfer
- MultiAppPostprocessorInterpolationTransfer
- MultiAppPostprocessorToAuxScalarTransfer
- MultiAppPostprocessorTransfer
- MultiAppProjectionTransfer
- MultiAppScalarToAuxScalarTransfer
- MultiAppUserObjectTransfer
- MultiAppVariableValueSamplePostprocessorTransfer
- MultiAppVariableValueSampleTransfer
- MultiAppVectorPostprocessorTransferThis transfer distributes the N values of a VectorPostprocessor to Postprocessors located in N sub-apps or collects Postprocessor values from N sub-apps into a VectorPostprocessor
- Level Set App
- LevelSetMeshRefinementTransferTransfers the mesh from the master application to the sub application for the purposes of level set reinitialization problems with mesh adaptivity.
- Stochastic Tools App
- SamplerPostprocessorTransferTransfers data to and from Postprocessors on the sub-application.
- SamplerTransferCopies Sampler data to a SamplerReceiver object.
- Functional Expansion Tools App
- MultiAppFXTransferTransfers coefficient arrays between objects that are derived from MutableCoefficientsInterface; currently includes the following types: FunctionSeries, FXBoundaryUserObject, and FXVolumeUserObject

## VectorPostprocessors

- Moose App
- AddVectorPostprocessorAction
- CSVReaderConverts columns of a CSV file into vectors of a VectorPostprocessor.
- ConstantVectorPostprocessor
- Eigenvalues
- ElementValueSamplerSamples values of elemental variable(s).
- ElementVariablesDifferenceMax
- ElementsAlongLineOutputs the IDs of every element intersected by a user-defined line
- ElementsAlongPlaneOutputs the IDs of every element intersected by a user-defined plane
- HistogramVectorPostprocessorCompute a histogram for each column of a VectorPostprocessor
- IntersectionPointsAlongLine
- LeastSquaresFitPerforms a polynomial least squares fit on the data contained in another VectorPostprocessor
- LeastSquaresFitHistoryPerforms a polynomial least squares fit on the data contained in another VectorPostprocessor and stores the full time history of the coefficients
- LineFunctionSampler
- LineMaterialRealSampler
- LineValueSampler
- MaterialVectorPostprocessor
- NodalValueSamplerSamples values of nodal variable(s).
- PointValueSampler
- SideValueSampler
- SphericalAverage
- StatisticsVectorPostprocessorCompute statistical values of a given VectorPostprocessor. The statistics are computed for each column.
- VectorMemoryUsageGet memory stats for all ranks in the simulation
- VectorOfPostprocessorsOutputs the values of an arbitrary user-specified set of postprocessors as a vector in the order specified by the user
- VolumeHistogram
- WorkBalanceComputes several metrics for workload balance per processor
- Solid Mechanics App
- LineMaterialSymmTensorSampler
- Tensor Mechanics App
- CrackDataSamplerOutputs the values of a set of domain integral postprocessors as a vector, along with their positions along the crack front.
- LineMaterialRankTwoSamplerAccess a component of a RankTwoTensor
- LineMaterialRankTwoScalarSamplerCompute a scalar property of a RankTwoTensor
- Stochastic Tools App
- SamplerDataTool for extracting Sampler object data and storing in VectorPostprocessor vectors.
- StochasticResultsStorage container for stochastic simulation results coming from a Postprocessor.
- Phase Field App
- EulerAngleUpdaterCheckProvide updated euler angles after rigid body rotation of the grains.
- FeatureVolumeVectorPostprocessorThis object is designed to pull information from the data structures of a "FeatureFloodCount" or derived object (e.g. individual feature volumes)
- GrainForcesPostprocessorOutputs the values from GrainForcesPostprocessor
- GrainTextureVectorPostprocessorGives out info on the grain boundary properties