Skip to content
Permalink
Browse files

Merge pull request #13120 from jiangwen84/sampler_transfer

Add full-solve type sampler multi-app
  • Loading branch information...
permcody committed Apr 5, 2019
2 parents fb4d8db + ca595e2 commit 3c232a44d108ac3453b3b2aa9890451b68dff60f
Showing with 257 additions and 79 deletions.
  1. +5 −4 framework/include/samplers/Sampler.h
  2. +1 −1 modules/stochastic_tools/doc/content/modules/stochastic_tools/examples/monte_carlo.md
  3. +1 −1 modules/stochastic_tools/doc/content/modules/stochastic_tools/index.md
  4. +14 −0 modules/stochastic_tools/doc/content/source/multiapps/SamplerFullSolveMultiApp.md
  5. +0 −14 modules/stochastic_tools/doc/content/source/multiapps/SamplerMultiApp.md
  6. +14 −0 modules/stochastic_tools/doc/content/source/multiapps/SamplerTransientMultiApp.md
  7. +38 −0 modules/stochastic_tools/include/multiapps/SamplerFullSolveMultiApp.h
  8. +6 −6 modules/stochastic_tools/include/multiapps/{SamplerMultiApp.h → SamplerTransientMultiApp.h}
  9. +3 −6 modules/stochastic_tools/include/transfers/SamplerPostprocessorTransfer.h
  10. +1 −1 modules/stochastic_tools/include/transfers/SamplerTransfer.h
  11. +2 −1 modules/stochastic_tools/include/vectorpostprocessors/StochasticResults.h
  12. +41 −0 modules/stochastic_tools/src/multiapps/SamplerFullSolveMultiApp.C
  13. +4 −4 modules/stochastic_tools/src/multiapps/{SamplerMultiApp.C → SamplerTransientMultiApp.C}
  14. +19 −8 modules/stochastic_tools/src/transfers/SamplerPostprocessorTransfer.C
  15. +15 −5 modules/stochastic_tools/src/transfers/SamplerTransfer.C
  16. +1 −0 modules/stochastic_tools/src/vectorpostprocessors/StochasticResults.C
  17. +37 −0 modules/stochastic_tools/test/tests/multiapps/sampler_multiapp/master_full_solve.i
  18. +1 −6 modules/stochastic_tools/test/tests/multiapps/sampler_multiapp/{master.i → master_transient.i}
  19. +1 −1 modules/stochastic_tools/test/tests/multiapps/sampler_multiapp/sub.i
  20. +13 −3 modules/stochastic_tools/test/tests/multiapps/sampler_multiapp/tests
  21. +1 −1 modules/stochastic_tools/test/tests/transfers/errors/master_missing_control.i
  22. +1 −1 modules/stochastic_tools/test/tests/transfers/errors/master_num_parameters_wrong.i
  23. +1 −1 modules/stochastic_tools/test/tests/transfers/errors/master_wrong_control.i
  24. +10 −1 modules/stochastic_tools/test/tests/transfers/errors/tests
  25. +1 −1 modules/stochastic_tools/test/tests/transfers/monte_carlo.i
  26. +1 −1 ...s/stochastic_tools/test/tests/transfers/sampler_postprocessor/errors/require_stochastic_results.i
  27. +5 −1 modules/stochastic_tools/test/tests/transfers/sampler_postprocessor/errors/tests
  28. +1 −1 modules/stochastic_tools/test/tests/transfers/sampler_postprocessor/master.i
  29. +1 −1 modules/stochastic_tools/test/tests/transfers/sampler_transfer/errors/master_missing_control.i
  30. +1 −1 modules/stochastic_tools/test/tests/transfers/sampler_transfer/errors/master_num_parameters_wrong.i
  31. +1 −1 modules/stochastic_tools/test/tests/transfers/sampler_transfer/errors/master_wrong_control.i
  32. +10 −1 modules/stochastic_tools/test/tests/transfers/sampler_transfer/errors/tests
  33. +1 −1 modules/stochastic_tools/test/tests/transfers/sampler_transfer/monte_carlo.i
  34. +1 −1 modules/stochastic_tools/test/tests/transfers/sampler_transfer/sobol.i
  35. +1 −1 modules/stochastic_tools/test/tests/transfers/sampler_transfer_vector/master.i
  36. +1 −1 modules/stochastic_tools/test/tests/transfers/sampler_transfer_vector/master_not_enough_data.i
  37. +1 −1 modules/stochastic_tools/test/tests/transfers/sampler_transfer_vector/master_size_mismatch.i
  38. +1 −1 modules/stochastic_tools/test/tests/transfers/sobol.i
@@ -44,7 +44,8 @@ class Sampler : public MooseObject, public SetupInterface, public DistributionIn
Sampler(const InputParameters & parameters);

/**
* Simple object for storing the sampler location (see SamplerMultiApp).
* Simple object for storing the sampler location (see SamplerTransientMultiApp and
* SamplerFullSolveMultiApp).
* @param s Sample index (index associated with DenseMatrix returned by Sampler::getSamples())
* @param r Row index (index associated with the row in the DenseMatrix defined by s).
*/
@@ -109,9 +110,9 @@ class Sampler : public MooseObject, public SetupInterface, public DistributionIn

/**
* Return the Sample::Location for the given multi app index.
* @param global_index The global row, which is the row if all the DenseMatrix objects
* were stacked in order in a single object. When using SamplerMultiApp
* the global_index is the MultiApp global index.
* @param global_index The global row, which is the row if all the DenseMatrix objects were
* stacked in order in a single object. When using SamplerTransientMultiApp or
* SamplerFullSolveMultiApp the global_index is the MultiApp global index.
* @return The location which includes the DenseMatrix index and the row within that matrix.
*/
Sampler::Location getLocation(unsigned int global_index);
@@ -47,7 +47,7 @@ two distributions and creates the Monte Carlo samples.
Notice, that this sampler only executes on "initial", which means that the random numbers are
created once during the initial setup of the problem and not changed again during the simulation.

Next, a [SamplerMultiApp](/SamplerMultiApp.md) object is created. This object
Next, a [SamplerTransientMultiApp](/SamplerTransientMultiApp.md) object is created. This object
creates and runs a sub-application for each sample provided by the sampler object.

!listing modules/stochastic_tools/test/tests/transfers/monte_carlo.i block=MultiApps
@@ -60,7 +60,7 @@ 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](/SamplerMultiApp.md).
[SamplerTransientMultiApp](/SamplerTransientMultiApp.md).

## Objects, Actions, and Syntax

@@ -0,0 +1,14 @@
# SamplerFullSolveMultiApp

The [SamplerFullSolveMultiApp](#) simply creates a full-solve type sub application (see [MultiApps]) for each row of
each matrix returned from the [Sampler](stochastic_tools/index.md#samplers) object.

## Example Syntax

!listing modules/stochastic_tools/test/tests/multiapps/sampler_multiapp/master_full_solve.i block=MultiApps

!syntax parameters /MultiApps/SamplerFullSolveMultiApp

!syntax inputs /MultiApps/SamplerFullSolveMultiApp

!syntax children /MultiApps/SamplerFullSolveMultiApp

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,14 @@
# SamplerTransientMultiApp

The [SamplerTransientMultiApp](#) simply creates a transient-type sub application (see [MultiApps]) for each row of
each matrix returned from the [Sampler](stochastic_tools/index.md#samplers) object.

## Example Syntax

!listing modules/stochastic_tools/test/tests/multiapps/sampler_multiapp/master_transient.i block=MultiApps

!syntax parameters /MultiApps/SamplerTransientMultiApp

!syntax inputs /MultiApps/SamplerTransientMultiApp

!syntax children /MultiApps/SamplerTransientMultiApp
@@ -0,0 +1,38 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#ifndef SAMPLERFULLSOLVEMULTIAPP_H
#define SAMPLERFULLSOLVEMULTIAPP_H

// MOOSE includes
#include "FullSolveMultiApp.h"
#include "SamplerInterface.h"

class SamplerFullSolveMultiApp;
class Sampler;

template <>
InputParameters validParams<SamplerFullSolveMultiApp>();

class SamplerFullSolveMultiApp : public FullSolveMultiApp, public SamplerInterface
{
public:
SamplerFullSolveMultiApp(const InputParameters & parameters);

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

protected:
/// Sampler to utilize for creating MultiApps
Sampler & _sampler;
};

#endif
@@ -7,23 +7,23 @@
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#ifndef SAMPLERMULTIAPP_H
#define SAMPLERMULTIAPP_H
#ifndef SAMPLERTRANSIENTMULTIAPP_H
#define SAMPLERTRANSIENTMULTIAPP_H

// MOOSE includes
#include "TransientMultiApp.h"
#include "SamplerInterface.h"

class SamplerMultiApp;
class SamplerTransientMultiApp;
class Sampler;

template <>
InputParameters validParams<SamplerMultiApp>();
InputParameters validParams<SamplerTransientMultiApp>();

class SamplerMultiApp : public TransientMultiApp, public SamplerInterface
class SamplerTransientMultiApp : public TransientMultiApp, public SamplerInterface
{
public:
SamplerMultiApp(const InputParameters & parameters);
SamplerTransientMultiApp(const InputParameters & parameters);

/**
* Return the Sampler object for this MultiApp.
@@ -17,7 +17,7 @@
// Forward declarations
class SamplerPostprocessorTransfer;
class SamplerReceiver;
class SamplerMultiApp;
class SamplerFullSolveMultiApp;
class StochasticResults;

template <>
@@ -35,11 +35,8 @@ class SamplerPostprocessorTransfer : public MultiAppVectorPostprocessorTransfer
protected:
virtual void executeFromMultiapp() override;

/// SamplerMultiApp that this transfer is working with
SamplerMultiApp * _sampler_multi_app;

/// Sampler object that is retrieved from the SamplerMultiApp
Sampler & _sampler;
/// Sampler object that is retrieved from the SamplerTransientMultiApp or SamplerFullSolveMultiApp
Sampler * _sampler;

/// Storage for StochasticResults object that data will be transferred to/from
StochasticResults * _results;
@@ -40,7 +40,7 @@ class SamplerTransfer : public MultiAppTransfer
/// Storage for the list of parameters to control
const std::vector<std::string> & _parameter_names;

/// Pointer to the Sampler object used by the SamplerMultiApp
/// Pointer to the Sampler object used by the SamplerTransientMultiApp or SamplerFullSolveMultiApp
Sampler * _sampler_ptr;

/// The name of the SamplerReceiver Control object on the sub-application
@@ -31,7 +31,8 @@ class StochasticResults : public GeneralVectorPostprocessor, SamplerInterface
void virtual execute() override {}

/**
* Initialize storage based on the Sampler returned by the SamplerMultiApp.
* Initialize storage based on the Sampler returned by the SamplerTransientMultiApp or
* SamplerFullSolveMultiApp.
* @param sampler The Sampler associated with the MultiApp that this VPP is working with.
*
* This method is called by the SamplerPostprocessorTransfer.
@@ -0,0 +1,41 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

// StochasticTools includes
#include "SamplerFullSolveMultiApp.h"
#include "Sampler.h"

registerMooseObject("StochasticToolsApp", SamplerFullSolveMultiApp);

template <>
InputParameters
validParams<SamplerFullSolveMultiApp>()
{
InputParameters params = validParams<FullSolveMultiApp>();
params += validParams<SamplerInterface>();
params.addClassDescription(
"Creates a full-solve type sub-application for each row of each Sampler matrix.");
params.addParam<SamplerName>("sampler", "The Sampler object to utilize for creating MultiApps.");
params.suppressParameter<std::vector<Point>>("positions");
params.suppressParameter<bool>("output_in_position");
params.suppressParameter<std::vector<FileName>>("positions_file");
params.suppressParameter<Real>("move_time");
params.suppressParameter<std::vector<Point>>("move_positions");
params.suppressParameter<std::vector<unsigned int>>("move_apps");
params.set<bool>("use_positions") = false;
return params;
}

SamplerFullSolveMultiApp::SamplerFullSolveMultiApp(const InputParameters & parameters)
: FullSolveMultiApp(parameters),
SamplerInterface(this),
_sampler(SamplerInterface::getSampler("sampler"))
{
init(_sampler.getTotalNumberOfRows());
}
@@ -8,14 +8,14 @@
//* https://www.gnu.org/licenses/lgpl-2.1.html

// StochasticTools includes
#include "SamplerMultiApp.h"
#include "SamplerTransientMultiApp.h"
#include "Sampler.h"

registerMooseObject("StochasticToolsApp", SamplerMultiApp);
registerMooseObject("StochasticToolsApp", SamplerTransientMultiApp);

template <>
InputParameters
validParams<SamplerMultiApp>()
validParams<SamplerTransientMultiApp>()
{
InputParameters params = validParams<TransientMultiApp>();
params += validParams<SamplerInterface>();
@@ -31,7 +31,7 @@ validParams<SamplerMultiApp>()
return params;
}

SamplerMultiApp::SamplerMultiApp(const InputParameters & parameters)
SamplerTransientMultiApp::SamplerTransientMultiApp(const InputParameters & parameters)
: TransientMultiApp(parameters),
SamplerInterface(this),
_sampler(SamplerInterface::getSampler("sampler"))
@@ -9,7 +9,8 @@

// StochasticTools includes
#include "SamplerPostprocessorTransfer.h"
#include "SamplerMultiApp.h"
#include "SamplerFullSolveMultiApp.h"
#include "SamplerTransientMultiApp.h"
#include "SamplerReceiver.h"
#include "StochasticResults.h"

@@ -29,12 +30,22 @@ validParams<SamplerPostprocessorTransfer>()
}

SamplerPostprocessorTransfer::SamplerPostprocessorTransfer(const InputParameters & parameters)
: MultiAppVectorPostprocessorTransfer(parameters),
_sampler_multi_app(std::dynamic_pointer_cast<SamplerMultiApp>(_multi_app).get()),
_sampler(_sampler_multi_app->getSampler())
: MultiAppVectorPostprocessorTransfer(parameters)
{
if (!_sampler_multi_app)
mooseError("The 'multi_app' must be a 'SamplerMultiApp.'");
// Determine the Sampler
std::shared_ptr<SamplerTransientMultiApp> ptr_transient =
std::dynamic_pointer_cast<SamplerTransientMultiApp>(_multi_app);
std::shared_ptr<SamplerFullSolveMultiApp> ptr_fullsolve =
std::dynamic_pointer_cast<SamplerFullSolveMultiApp>(_multi_app);

if (!ptr_transient && !ptr_fullsolve)
mooseError("The 'multi_app' parameter must provide either a 'SamplerTransientMultiApp' or "
"'SamplerFullSolveMultiApp' object.");

if (ptr_transient)
_sampler = &(ptr_transient->getSampler());
else
_sampler = &(ptr_fullsolve->getSampler());
}

void
@@ -46,7 +57,7 @@ SamplerPostprocessorTransfer::initialSetup()
if (!_results)
mooseError("The 'results' object must be a 'StochasticResults' object.");

_results->init(_sampler);
_results->init(*_sampler);
}

void
@@ -75,7 +86,7 @@ SamplerPostprocessorTransfer::executeFromMultiapp()
// Update VPP
for (unsigned int i = 0; i < n; i++)
{
Sampler::Location loc = _sampler.getLocation(i);
Sampler::Location loc = _sampler->getLocation(i);
VectorPostprocessorValue & vpp = _results->getVectorPostprocessorValueByGroup(loc.sample());
vpp[loc.row()] = values[i];
}
@@ -9,7 +9,8 @@

// MOOSE includes
#include "SamplerTransfer.h"
#include "SamplerMultiApp.h"
#include "SamplerTransientMultiApp.h"
#include "SamplerFullSolveMultiApp.h"
#include "SamplerReceiver.h"

registerMooseObject("StochasticToolsApp", SamplerTransfer);
@@ -40,10 +41,19 @@ SamplerTransfer::SamplerTransfer(const InputParameters & parameters)
{

// Determine the Sampler
std::shared_ptr<SamplerMultiApp> ptr = std::dynamic_pointer_cast<SamplerMultiApp>(_multi_app);
if (!ptr)
mooseError("The 'multi_app' parameter must provide a 'SamplerMultiApp' object.");
_sampler_ptr = &(ptr->getSampler());
std::shared_ptr<SamplerTransientMultiApp> ptr_transient =
std::dynamic_pointer_cast<SamplerTransientMultiApp>(_multi_app);
std::shared_ptr<SamplerFullSolveMultiApp> ptr_fullsolve =
std::dynamic_pointer_cast<SamplerFullSolveMultiApp>(_multi_app);

if (!ptr_transient && !ptr_fullsolve)
mooseError("The 'multi_app' parameter must provide either a 'SamplerTransientMultiApp' or "
"'SamplerFullSolveMultiApp' object.");

if (ptr_transient)
_sampler_ptr = &(ptr_transient->getSampler());
else
_sampler_ptr = &(ptr_fullsolve->getSampler());

// Compute the matrix and row for each
std::vector<DenseMatrix<Real>> out = _sampler_ptr->getSamples();
@@ -46,6 +46,7 @@ StochasticResults::initialize()
VectorPostprocessorValue &
StochasticResults::getVectorPostprocessorValueByGroup(unsigned int group)
{
StochasticResults::initialize();
if (group >= _sample_vectors.size())
mooseError("The supplied sample index ", group, " does not exist.");
return *_sample_vectors[group];
Oops, something went wrong.

0 comments on commit 3c232a4

Please sign in to comment.
You can’t perform that action at this time.