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 5204 : SamplerReporterTransfer::validParams() 24 : { 25 5204 : InputParameters params = StochasticToolsTransfer::validParams(); 26 5204 : params.addClassDescription("Transfers data from Reporters on the sub-application to a " 27 : "StochasticReporter on the main application."); 28 : 29 10408 : params.addRequiredParam<std::vector<ReporterName>>( 30 : "from_reporter", "The name(s) of the Reporter(s) on the sub-app to transfer from."); 31 10408 : params.addRequiredParam<std::string>( 32 : "stochastic_reporter", "The name of the StochasticReporter object to transfer values to."); 33 : 34 10408 : params.addParam<std::string>("prefix", 35 : "Use the supplied string as the prefix for reporter " 36 : "name rather than the transfer name."); 37 : 38 5204 : params.suppressParameter<MultiMooseEnum>("direction"); 39 5204 : params.suppressParameter<MultiAppName>("multi_app"); 40 5204 : return params; 41 0 : } 42 : 43 2586 : SamplerReporterTransfer::SamplerReporterTransfer(const InputParameters & parameters) 44 : : StochasticToolsTransfer(parameters), 45 : ReporterTransferInterface(this), 46 5172 : _sub_reporter_names(getParam<std::vector<ReporterName>>("from_reporter")) 47 : { 48 2586 : if (hasToMultiApp()) 49 0 : paramError("to_multi_app", "To and between multiapp directions are not implemented"); 50 2586 : } 51 : 52 : void 53 2582 : SamplerReporterTransfer::initialSetup() 54 : { 55 : // Get the StochasticResults VPP object to populate 56 5164 : auto & uo = _fe_problem.getUserObject<UserObject>(getParam<std::string>("stochastic_reporter")); 57 2582 : _results = dynamic_cast<StochasticReporter *>(&uo); 58 2582 : if (!_results) 59 0 : paramError("stochastic_reporter", "This object must be a 'StochasticReporter' object."); 60 : 61 2582 : intitializeStochasticReporters(); 62 2574 : } 63 : 64 : void 65 3738 : SamplerReporterTransfer::initializeFromMultiapp() 66 : { 67 3738 : } 68 : 69 : void 70 19070 : SamplerReporterTransfer::executeFromMultiapp() 71 : { 72 38140 : if (getFromMultiApp()->isRootProcessor()) 73 : { 74 18690 : const dof_id_type n = getFromMultiApp()->numGlobalApps(); 75 974060 : for (MooseIndex(n) i = 0; i < n; i++) 76 955370 : transferStochasticReporters(_global_index, i); 77 : } 78 19070 : } 79 : 80 : void 81 3738 : SamplerReporterTransfer::finalizeFromMultiapp() 82 : { 83 3738 : } 84 : 85 : void 86 4176 : SamplerReporterTransfer::execute() 87 : { 88 16606 : for (dof_id_type i = _sampler_ptr->getLocalRowBegin(); i < _sampler_ptr->getLocalRowEnd(); ++i) 89 12430 : transferStochasticReporters(i, i); 90 4176 : } 91 : 92 : void 93 2582 : SamplerReporterTransfer::intitializeStochasticReporters() 94 : { 95 2582 : const dof_id_type n = getFromMultiApp()->numGlobalApps(); 96 : 97 6952 : for (const auto & sub_rname : _sub_reporter_names) 98 85518 : for (MooseIndex(n) i = 0; i < n; i++) 99 162296 : if (getFromMultiApp()->hasLocalApp(i)) 100 17854 : addReporterTransferMode( 101 35708 : sub_rname, REPORTER_MODE_ROOT, getFromMultiApp()->appProblemBase(i)); 102 : 103 5964 : const std::string prefix = isParamValid("prefix") ? getParam<std::string>("prefix") : name(); 104 6944 : for (const auto & sub_rname : _sub_reporter_names) 105 11336 : for (MooseIndex(n) i = 0; i < n; i++) 106 22672 : if (getFromMultiApp()->hasLocalApp(i)) 107 : { 108 4370 : const ReporterData & rdata = getFromMultiApp()->appProblemBase(i).getReporterData(); 109 : ReporterName rname = 110 8736 : _results->declareStochasticReporterClone(*_sampler_ptr, rdata, sub_rname, prefix); 111 : if (rname.empty()) 112 4 : paramError("from_reporter", 113 : "Reporter value ", 114 : sub_rname, 115 : " is of unsupported type ", 116 4 : rdata.getReporterContextBase(sub_rname).type(), 117 : ". Contact MOOSE developers on how to transfer this type of reporter value."); 118 4362 : _reporter_names.push_back(rname); 119 : break; 120 : } 121 : 122 2574 : _converged = &_results->declareStochasticReporter<bool>( 123 7322 : prefix + (prefix.empty() ? "" : ":") + "converged", *_sampler_ptr); 124 2574 : } 125 : 126 : void 127 967800 : SamplerReporterTransfer::transferStochasticReporters(dof_id_type global_index, 128 : dof_id_type app_index) 129 : { 130 1935600 : if (getFromMultiApp()->hasLocalApp(app_index)) 131 : { 132 31120 : const dof_id_type local_index = global_index - _sampler_ptr->getLocalRowBegin(); 133 87670 : for (unsigned int r = 0; r < _sub_reporter_names.size(); ++r) 134 56550 : transferToVectorReporter(_sub_reporter_names[r], 135 : _reporter_names[r], 136 113100 : getFromMultiApp()->appProblemBase(app_index), 137 113100 : getFromMultiApp()->problemBase(), 138 : local_index); 139 : 140 62240 : (*_converged)[local_index] = getFromMultiApp()->getExecutioner(app_index)->lastSolveConverged(); 141 : } 142 967800 : }