Line data Source code
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 : // StochasticTools includes 11 : #include "SamplerReporterTransfer.h" 12 : #include "SamplerFullSolveMultiApp.h" 13 : #include "SamplerTransientMultiApp.h" 14 : #include "SamplerReceiver.h" 15 : #include "StochasticResults.h" 16 : #include "Sampler.h" 17 : #include "StochasticReporter.h" 18 : #include "Executioner.h" 19 : 20 : registerMooseObject("StochasticToolsApp", SamplerReporterTransfer); 21 : 22 : InputParameters 23 5716 : SamplerReporterTransfer::validParams() 24 : { 25 5716 : InputParameters params = StochasticToolsTransfer::validParams(); 26 5716 : params.addClassDescription("Transfers data from Reporters on the sub-application to a " 27 : "StochasticReporter on the main application."); 28 : 29 11432 : params.addRequiredParam<std::vector<ReporterName>>( 30 : "from_reporter", "The name(s) of the Reporter(s) on the sub-app to transfer from."); 31 11432 : params.addRequiredParam<std::string>( 32 : "stochastic_reporter", "The name of the StochasticReporter object to transfer values to."); 33 : 34 11432 : params.addParam<std::string>("prefix", 35 : "Use the supplied string as the prefix for reporter " 36 : "name rather than the transfer name."); 37 : 38 5716 : params.suppressParameter<MultiMooseEnum>("direction"); 39 5716 : params.suppressParameter<MultiAppName>("multi_app"); 40 5716 : return params; 41 0 : } 42 : 43 2842 : SamplerReporterTransfer::SamplerReporterTransfer(const InputParameters & parameters) 44 : : StochasticToolsTransfer(parameters), 45 : ReporterTransferInterface(this), 46 5684 : _sub_reporter_names(getParam<std::vector<ReporterName>>("from_reporter")) 47 : { 48 2842 : if (hasToMultiApp()) 49 0 : paramError("to_multi_app", "To and between multiapp directions are not implemented"); 50 2842 : } 51 : 52 : void 53 2838 : SamplerReporterTransfer::initialSetup() 54 : { 55 : // Get the StochasticResults VPP object to populate 56 5676 : auto & uo = _fe_problem.getUserObject<UserObject>(getParam<std::string>("stochastic_reporter")); 57 2838 : _results = dynamic_cast<StochasticReporter *>(&uo); 58 2838 : if (!_results) 59 0 : paramError("stochastic_reporter", "This object must be a 'StochasticReporter' object."); 60 : 61 2838 : intitializeStochasticReporters(); 62 2830 : } 63 : 64 : void 65 9009 : SamplerReporterTransfer::initializeFromMultiapp() 66 : { 67 : // Initialize vectors so they are the proper size before transfer 68 9009 : if (_results->getExecuteOnEnum().contains(EXEC_TRANSFER)) 69 484 : _results->initialize(); 70 9009 : } 71 : 72 : void 73 21805 : SamplerReporterTransfer::executeFromMultiapp() 74 : { 75 43610 : if (getFromMultiApp()->isRootProcessor()) 76 : { 77 21376 : const dof_id_type n = getFromMultiApp()->numGlobalApps(); 78 1075564 : for (MooseIndex(n) i = 0; i < n; i++) 79 1054188 : transferStochasticReporters(_global_index, i); 80 : } 81 21805 : } 82 : 83 : void 84 9009 : SamplerReporterTransfer::finalizeFromMultiapp() 85 : { 86 : // Execute reporter so that things are gathered after transfer properly 87 9009 : _fe_problem.computeUserObjectByName(EXEC_TRANSFER, Moose::PRE_AUX, _results->name()); 88 9009 : _fe_problem.computeUserObjectByName(EXEC_TRANSFER, Moose::POST_AUX, _results->name()); 89 9009 : } 90 : 91 : void 92 4628 : SamplerReporterTransfer::execute() 93 : { 94 4628 : initializeFromMultiapp(); 95 : 96 18602 : for (dof_id_type i = _sampler_ptr->getLocalRowBegin(); i < _sampler_ptr->getLocalRowEnd(); ++i) 97 13974 : transferStochasticReporters(i, i); 98 : 99 4628 : finalizeFromMultiapp(); 100 4628 : } 101 : 102 : void 103 2838 : SamplerReporterTransfer::intitializeStochasticReporters() 104 : { 105 2838 : const dof_id_type n = getFromMultiApp()->numGlobalApps(); 106 : 107 7607 : for (const auto & sub_rname : _sub_reporter_names) 108 91049 : for (MooseIndex(n) i = 0; i < n; i++) 109 172560 : if (getFromMultiApp()->hasLocalApp(i)) 110 19622 : addReporterTransferMode( 111 39244 : sub_rname, REPORTER_MODE_ROOT, getFromMultiApp()->appProblemBase(i)); 112 : 113 9003 : const std::string prefix = isParamValid("prefix") ? getParam<std::string>("prefix") : name(); 114 7599 : for (const auto & sub_rname : _sub_reporter_names) 115 11924 : for (MooseIndex(n) i = 0; i < n; i++) 116 23848 : if (getFromMultiApp()->hasLocalApp(i)) 117 : { 118 4769 : const ReporterData & rdata = getFromMultiApp()->appProblemBase(i).getReporterData(); 119 : ReporterName rname = 120 9534 : _results->declareStochasticReporterClone(*_sampler_ptr, rdata, sub_rname, prefix); 121 : if (rname.empty()) 122 4 : paramError("from_reporter", 123 : "Reporter value ", 124 : sub_rname, 125 : " is of unsupported type ", 126 4 : rdata.getReporterContextBase(sub_rname).type(), 127 : ". Contact MOOSE developers on how to transfer this type of reporter value."); 128 4761 : _reporter_names.push_back(rname); 129 : break; 130 : } 131 : 132 2830 : _converged = &_results->declareStochasticReporter<bool>( 133 8001 : prefix + (prefix.empty() ? "" : ":") + "converged", *_sampler_ptr); 134 2830 : } 135 : 136 : void 137 1068162 : SamplerReporterTransfer::transferStochasticReporters(dof_id_type global_index, 138 : dof_id_type app_index) 139 : { 140 2136324 : if (getFromMultiApp()->hasLocalApp(app_index)) 141 : { 142 35350 : const dof_id_type local_index = global_index - _sampler_ptr->getLocalRowBegin(); 143 99095 : for (unsigned int r = 0; r < _sub_reporter_names.size(); ++r) 144 63745 : transferToVectorReporter(_sub_reporter_names[r], 145 : _reporter_names[r], 146 127490 : getFromMultiApp()->appProblemBase(app_index), 147 127490 : getFromMultiApp()->problemBase(), 148 : local_index); 149 : 150 70700 : (*_converged)[local_index] = getFromMultiApp()->getExecutioner(app_index)->lastSolveConverged(); 151 : } 152 1068162 : }