Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows StochasticResults to be replicated or distributed #14437

Merged
merged 15 commits into from Dec 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions framework/include/utils/MooseTypes.h
Expand Up @@ -541,6 +541,7 @@ typedef VectorVariableTestSecond ADVectorVariableTestSecond;

namespace Moose
{
extern const processor_id_type INVALID_PROCESSOR_ID;
extern const SubdomainID ANY_BLOCK_ID;
extern const SubdomainID INVALID_BLOCK_ID;
extern const BoundaryID ANY_BOUNDARY_ID;
Expand Down
4 changes: 2 additions & 2 deletions framework/src/base/Moose.C
Expand Up @@ -290,10 +290,10 @@ addActionTypes(Syntax & syntax)
"(setup_variable_complete)"
"(setup_quadrature)"
"(add_function)"
"(add_distribution)"
"(add_sampler)"
"(add_periodic_bc)"
"(add_user_object)"
"(add_distribution)"
"(add_sampler)"
"(setup_function_complete)"
"(setup_adaptivity)"
"(set_adaptivity_options)"
Expand Down
1 change: 1 addition & 0 deletions framework/src/utils/MooseTypes.C
Expand Up @@ -13,6 +13,7 @@

namespace Moose
{
const processor_id_type INVALID_PROCESSOR_ID = libMesh::DofObject::invalid_processor_id;
const SubdomainID ANY_BLOCK_ID = libMesh::Elem::invalid_subdomain_id - 1;
const SubdomainID INVALID_BLOCK_ID = libMesh::Elem::invalid_subdomain_id;
const BoundaryID ANY_BOUNDARY_ID = static_cast<BoundaryID>(-1);
Expand Down
Expand Up @@ -52,7 +52,7 @@ creates and runs a sub-application for each sample provided by the sampler objec

!listing modules/stochastic_tools/test/tests/transfers/monte_carlo/monte_carlo.i block=MultiApps

Finally, the [SamplerTransfer](/SamplerTransfer.md) is utilized to communicate the
Finally, the [SamplerParameterTransfer](/SamplerParameterTransfer.md) is utilized to communicate the
sampler data to the sub-application. The 'parameters' input lists the parameters on the
sub-applications to perturb and the 'to_control' specifies the
[SamplerReceiver](/SamplerReceiver.md) object in the sub-application.
Expand Down
@@ -0,0 +1,13 @@
# SamplerParameterTransfer

The SamplerParameterTransfer works in union with the [Samplers] and [Controls] systems to transfer data to
sub-applications to perform stochastic simulations.

The use of this object is explained in detail in stochastic_tools module
example: [Monte Carlo Example](stochastic_tools/examples/monte_carlo.md).

!syntax parameters /Transfers/SamplerParameterTransfer

!syntax inputs /Transfers/SamplerParameterTransfer

!syntax children /Transfers/SamplerParameterTransfer

This file was deleted.

2 changes: 1 addition & 1 deletion modules/stochastic_tools/examples/batch/full_solve.i
Expand Up @@ -39,7 +39,7 @@

[Transfers]
[runner]
type = SamplerTransfer
type = SamplerParameterTransfer
multi_app = runner
parameters = 'BCs/left/value BCs/right/value'
to_control = receiver
Expand Down
2 changes: 1 addition & 1 deletion modules/stochastic_tools/examples/batch/transient.i
Expand Up @@ -41,7 +41,7 @@

[Transfers]
[runner]
type = SamplerTransfer
type = SamplerParameterTransfer
multi_app = runner
parameters = 'BCs/left/value BCs/right/value'
to_control = receiver
Expand Down
2 changes: 2 additions & 0 deletions modules/stochastic_tools/include/base/StochasticToolsApp.h
Expand Up @@ -19,6 +19,8 @@ InputParameters validParams<StochasticToolsApp>();
class StochasticToolsApp : public MooseApp
{
public:
static InputParameters validParams();

StochasticToolsApp(InputParameters parameters);
virtual ~StochasticToolsApp();

Expand Down
Expand Up @@ -29,6 +29,8 @@ InputParameters validParams<MultiAppCommandLineControl>();
class MultiAppCommandLineControl : public Control, public SamplerInterface
{
public:
static InputParameters validParams();

MultiAppCommandLineControl(const InputParameters & parameters);

/**
Expand Down
7 changes: 4 additions & 3 deletions modules/stochastic_tools/include/controls/SamplerReceiver.h
Expand Up @@ -25,6 +25,8 @@ InputParameters validParams<SamplerReceiver>();
class SamplerReceiver : public Control
{
public:
static InputParameters validParams();

SamplerReceiver(const InputParameters & parameters);
virtual void execute() override;

Expand All @@ -40,8 +42,7 @@ class SamplerReceiver : public Control
/// Values to use when modifying parameters
std::vector<Real> _values;

/// Allows the SamplerTransfer to call the transfer method, which
/// Allows the SamplerParameterTransfer to call the transfer method, which
/// should only be called by that object so making it public is dangerous.
friend class SamplerTransfer;
friend class SamplerParameterTransfer;
};

Expand Up @@ -23,6 +23,8 @@ class BoostLognormalDistribution
: public BoostDistribution<boost::math::lognormal_distribution<Real>>
{
public:
static InputParameters validParams();

BoostLognormalDistribution(const InputParameters & parameters);
};

Expand Up @@ -22,6 +22,8 @@ InputParameters validParams<BoostNormalDistribution>();
class BoostNormalDistribution : public BoostDistribution<boost::math::normal_distribution<Real>>
{
public:
static InputParameters validParams();

BoostNormalDistribution(const InputParameters & parameters);
};

Expand Up @@ -22,6 +22,8 @@ InputParameters validParams<BoostWeibullDistribution>();
class BoostWeibullDistribution : public BoostDistribution<boost::math::weibull_distribution<Real>>
{
public:
static InputParameters validParams();

BoostWeibullDistribution(const InputParameters & parameters);
};

Expand Up @@ -22,27 +22,20 @@ InputParameters validParams<JohnsonSBDistribution>();
class JohnsonSBDistribution : public NormalDistribution
{
public:
static InputParameters validParams();

JohnsonSBDistribution(const InputParameters & parameters);

virtual Real pdf(const Real & x) const override;
virtual Real cdf(const Real & x) const override;
virtual Real quantile(const Real & p) const override;

Real pdf(const Real & x,
const Real & a,
const Real & b,
const Real & alpha_1,
const Real & alpha_2) const;
Real cdf(const Real & x,
const Real & a,
const Real & b,
const Real & alpha_1,
const Real & alpha_2) const;
Real quantile(const Real & p,
const Real & a,
const Real & b,
const Real & alpha_1,
const Real & alpha_2) const;
static Real
pdf(const Real & x, const Real & a, const Real & b, const Real & alpha_1, const Real & alpha_2);
static Real
cdf(const Real & x, const Real & a, const Real & b, const Real & alpha_1, const Real & alpha_2);
static Real quantile(
const Real & p, const Real & a, const Real & b, const Real & alpha_1, const Real & alpha_2);

protected:
/// The lower location parameter, a
Expand All @@ -57,4 +50,3 @@ class JohnsonSBDistribution : public NormalDistribution
/// The second shape parameter, alpha_2
const Real & _alpha_2;
};

Expand Up @@ -22,15 +22,17 @@ InputParameters validParams<LogisticDistribution>();
class LogisticDistribution : public Distribution
{
public:
static InputParameters validParams();

LogisticDistribution(const InputParameters & parameters);

virtual Real pdf(const Real & x) const override;
virtual Real cdf(const Real & x) const override;
virtual Real quantile(const Real & p) const override;

Real pdf(const Real & x, const Real & location, const Real & shape) const;
Real cdf(const Real & x, const Real & location, const Real & shape) const;
Real quantile(const Real & p, const Real & location, const Real & shape) const;
static Real pdf(const Real & x, const Real & location, const Real & shape);
static Real cdf(const Real & x, const Real & location, const Real & shape);
static Real quantile(const Real & p, const Real & location, const Real & shape);

protected:
/// The location or mean of the distribution (alpha or mu)
Expand All @@ -39,4 +41,3 @@ class LogisticDistribution : public Distribution
/// The shape of the distribution (beta or s)
const Real & _shape;
};

Expand Up @@ -22,24 +22,24 @@ InputParameters validParams<NormalDistribution>();
class NormalDistribution : public Distribution
{
public:
static InputParameters validParams();

NormalDistribution(const InputParameters & parameters);

virtual Real pdf(const Real & x) const override;
virtual Real cdf(const Real & x) const override;
virtual Real quantile(const Real & p) const override;

Real pdf(const Real & x, const Real & mean, const Real & std_dev) const;
Real cdf(const Real & x, const Real & mean, const Real & std_dev) const;
Real quantile(const Real & p, const Real & mean, const Real & std_dev) const;
static Real pdf(const Real & x, const Real & mean, const Real & std_dev);
static Real cdf(const Real & x, const Real & mean, const Real & std_dev);
static Real quantile(const Real & p, const Real & mean, const Real & std_dev);

protected:
///@{
/// Coefficients for the rational function used to approximate the quantile
const std::vector<Real> _a = {
-0.322232431088, -1.0, -0.342242088547, -0.0204231210245, -0.0000453642210148};
static const std::array<Real, 6> _a;

const std::vector<Real> _b = {
0.099348462606, 0.588581570495, 0.531103462366, 0.10353775285, 0.0038560700634};
static const std::array<Real, 6> _b;
///@}

/// The mean (or expectation) of the distribution (mu)
Expand All @@ -48,4 +48,3 @@ class NormalDistribution : public Distribution
/// The standard deviation of the distribution (sigma)
const Real & _standard_deviation;
};

Expand Up @@ -22,27 +22,29 @@ InputParameters validParams<TruncatedNormalDistribution>();
class TruncatedNormalDistribution : public NormalDistribution
{
public:
static InputParameters validParams();

TruncatedNormalDistribution(const InputParameters & parameters);

virtual Real pdf(const Real & x) const override;
virtual Real cdf(const Real & x) const override;
virtual Real quantile(const Real & p) const override;

Real pdf(const Real & x,
const Real & mean,
const Real & std_dev,
const Real & lower_bound,
const Real & upper_bound) const;
Real cdf(const Real & x,
const Real & mean,
const Real & std_dev,
const Real & lower_bound,
const Real & upper_bound) const;
Real quantile(const Real & p,
const Real & mean,
const Real & std_dev,
const Real & lower_bound,
const Real & upper_bound) const;
static Real pdf(const Real & x,
const Real & mean,
const Real & std_dev,
const Real & lower_bound,
const Real & upper_bound);
static Real cdf(const Real & x,
const Real & mean,
const Real & std_dev,
const Real & lower_bound,
const Real & upper_bound);
static Real quantile(const Real & p,
const Real & mean,
const Real & std_dev,
const Real & lower_bound,
const Real & upper_bound);

protected:
/// The lower bound for the distribution
Expand All @@ -51,4 +53,3 @@ class TruncatedNormalDistribution : public NormalDistribution
/// The upper bound for the distribution
const Real & _upper_bound;
};

Expand Up @@ -21,11 +21,13 @@ InputParameters validParams<UniformDistribution>();
class UniformDistribution : public Distribution
{
public:
static InputParameters validParams();

UniformDistribution(const InputParameters & parameters);

Real pdf(const Real & x, const Real & lower_bound, const Real & upper_bound) const;
Real cdf(const Real & x, const Real & lower_bound, const Real & upper_bound) const;
Real quantile(const Real & y, const Real & lower_bound, const Real & upper_bound) const;
static Real pdf(const Real & x, const Real & lower_bound, const Real & upper_bound);
static Real cdf(const Real & x, const Real & lower_bound, const Real & upper_bound);
static Real quantile(const Real & y, const Real & lower_bound, const Real & upper_bound);

virtual Real pdf(const Real & x) const override;
virtual Real cdf(const Real & x) const override;
Expand All @@ -38,4 +40,3 @@ class UniformDistribution : public Distribution
/// The upper bound for the uniform distribution
const Real & _upper_bound;
};

Expand Up @@ -22,16 +22,18 @@ InputParameters validParams<WeibullDistribution>();
class WeibullDistribution : public Distribution
{
public:
static InputParameters validParams();

WeibullDistribution(const InputParameters & parameters);

virtual Real pdf(const Real & x) const override;
virtual Real cdf(const Real & x) const override;
virtual Real quantile(const Real & p) const override;

Real pdf(const Real & x, const Real & location, const Real & scale, const Real & shape) const;
Real cdf(const Real & x, const Real & location, const Real & scale, const Real & shape) const;
Real
quantile(const Real & p, const Real & location, const Real & scale, const Real & shape) const;
static Real pdf(const Real & x, const Real & location, const Real & scale, const Real & shape);
static Real cdf(const Real & x, const Real & location, const Real & scale, const Real & shape);
static Real
quantile(const Real & p, const Real & location, const Real & scale, const Real & shape);

protected:
/// The location parameter (a or low)
Expand All @@ -43,4 +45,3 @@ class WeibullDistribution : public Distribution
/// The shape parameter (c or k)
const Real & _c;
};

Expand Up @@ -25,12 +25,9 @@ InputParameters validParams<SamplerFullSolveMultiApp>();
class SamplerFullSolveMultiApp : public FullSolveMultiApp, public SamplerInterface
{
public:
SamplerFullSolveMultiApp(const InputParameters & parameters);
static InputParameters validParams();

/**
* Return the Sampler object for this MultiApp.
*/
Sampler & getSampler() const { return _sampler; }
SamplerFullSolveMultiApp(const InputParameters & parameters);

virtual bool solveStep(Real dt, Real target_time, bool auto_advance = true) override;

Expand Down
Expand Up @@ -25,12 +25,9 @@ InputParameters validParams<SamplerTransientMultiApp>();
class SamplerTransientMultiApp : public TransientMultiApp, public SamplerInterface
{
public:
SamplerTransientMultiApp(const InputParameters & parameters);
static InputParameters validParams();

/**
* Return the Sampler object for this MultiApp.
*/
Sampler & getSampler() const { return _sampler; }
SamplerTransientMultiApp(const InputParameters & parameters);

/**
* Override solveStep to allow for batch execution.
Expand Down
Expand Up @@ -21,6 +21,8 @@ InputParameters validParams<MonteCarloSampler>();
class MonteCarloSampler : public Sampler
{
public:
static InputParameters validParams();

MonteCarloSampler(const InputParameters & parameters);

protected:
Expand Down