LCOV - code coverage report
Current view: top level - src/transfers - SamplerPostprocessorTransfer.C (source / functions) Hit Total Coverage
Test: stochastic_tools Test Coverage Lines: 37 38 97.4 %
Date: 2017-11-21 09:46:39 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /****************************************************************/
       2             : /* MOOSE - Multiphysics Object Oriented Simulation Environment  */
       3             : /*                                                              */
       4             : /*          All contents are licensed under LGPL V2.1           */
       5             : /*             See LICENSE for full restrictions                */
       6             : /****************************************************************/
       7             : 
       8             : // StochasticTools includes
       9             : #include "SamplerPostprocessorTransfer.h"
      10             : #include "SamplerMultiApp.h"
      11             : #include "SamplerReceiver.h"
      12             : #include "StochasticResults.h"
      13             : 
      14             : template <>
      15             : InputParameters
      16           3 : validParams<SamplerPostprocessorTransfer>()
      17             : {
      18           3 :   InputParameters params = validParams<MultiAppTransfer>();
      19           6 :   params.addClassDescription("Transfers data to and from Postprocessors on the sub-application.");
      20           9 :   params.addParam<VectorPostprocessorName>(
      21             :       "results",
      22           3 :       "Name of the StochasticResults object that the results are to be stored or extracted.");
      23           9 :   params.addParam<std::string>(
      24           3 :       "postprocessor", "Name of the Postprocessor on the sub-application to transfer to or from.");
      25           9 :   params.set<MooseEnum>("direction") = "from_multiapp";
      26           6 :   params.suppressParameter<MooseEnum>("direction");
      27           3 :   return params;
      28             : }
      29             : 
      30           2 : SamplerPostprocessorTransfer::SamplerPostprocessorTransfer(const InputParameters & parameters)
      31             :   : MultiAppTransfer(parameters),
      32           4 :     _results_name(getParam<VectorPostprocessorName>("results")),
      33           4 :     _sampler_multi_app(std::dynamic_pointer_cast<SamplerMultiApp>(_multi_app).get()),
      34           2 :     _sampler(_sampler_multi_app->getSampler()),
      35          12 :     _sub_pp_name(getParam<std::string>("postprocessor"))
      36             : {
      37           2 :   if (!_sampler_multi_app)
      38           0 :     mooseError("The 'multi_app' must be a 'SamplerMultiApp.'");
      39           2 : }
      40             : 
      41             : void
      42           2 : SamplerPostprocessorTransfer::initialSetup()
      43             : {
      44           2 :   const ExecuteMooseObjectWarehouse<UserObject> & user_objects = _fe_problem.getUserObjects();
      45           4 :   UserObject * uo = user_objects.getActiveObject(_results_name).get();
      46           2 :   _results = dynamic_cast<StochasticResults *>(uo);
      47             : 
      48           2 :   if (!_results)
      49           1 :     mooseError("The 'results' object must be a 'StochasticResults' object.");
      50             : 
      51           1 :   _results->init(_sampler);
      52           1 : }
      53             : 
      54             : void
      55           5 : SamplerPostprocessorTransfer::execute()
      56             : {
      57             :   // Number of PP is equal to the number of MultiApps
      58             :   const unsigned int n = _multi_app->numGlobalApps();
      59             : 
      60             :   // Collect the PP values for this processor
      61             :   std::vector<PostprocessorValue> values;
      62           5 :   values.reserve(_multi_app->numLocalApps());
      63         125 :   for (unsigned int i = 0; i < n; i++)
      64             :   {
      65          60 :     if (_multi_app->hasLocalApp(i))
      66             :     {
      67          60 :       FEProblemBase & app_problem = _multi_app->appProblemBase(i);
      68             : 
      69             :       // use reserve and push_back b/c access to FEProblemBase is based on global id
      70         180 :       values.push_back(app_problem.getPostprocessorValue(_sub_pp_name));
      71             :     }
      72             :   }
      73             : 
      74             :   // Gather the PP values from all ranks
      75           5 :   _communicator.allgather<PostprocessorValue>(values);
      76             : 
      77             :   // Update VPP
      78         125 :   for (unsigned int i = 0; i < n; i++)
      79             :   {
      80          60 :     Sampler::Location loc = _sampler.getLocation(i);
      81          60 :     VectorPostprocessorValue & vpp = _results->getVectorPostprocessorValueByGroup(loc.sample());
      82         180 :     vpp[loc.row()] = values[i];
      83             :   }
      84        1817 : }

Generated by: LCOV version 1.11