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 5556 : SamplerReporterTransfer::validParams() 24 : { 25 5556 : InputParameters params = StochasticToolsTransfer::validParams(); 26 5556 : params.addClassDescription("Transfers data from Reporters on the sub-application to a " 27 : "StochasticReporter on the main application."); 28 : 29 11112 : params.addRequiredParam<std::vector<ReporterName>>( 30 : "from_reporter", "The name(s) of the Reporter(s) on the sub-app to transfer from."); 31 11112 : params.addRequiredParam<std::string>( 32 : "stochastic_reporter", "The name of the StochasticReporter object to transfer values to."); 33 : 34 11112 : params.addParam<std::string>("prefix", 35 : "Use the supplied string as the prefix for reporter " 36 : "name rather than the transfer name."); 37 : 38 5556 : params.suppressParameter<MultiMooseEnum>("direction"); 39 5556 : params.suppressParameter<MultiAppName>("multi_app"); 40 5556 : return params; 41 0 : } 42 : 43 2762 : SamplerReporterTransfer::SamplerReporterTransfer(const InputParameters & parameters) 44 : : StochasticToolsTransfer(parameters), 45 : ReporterTransferInterface(this), 46 5524 : _sub_reporter_names(getParam<std::vector<ReporterName>>("from_reporter")) 47 : { 48 2762 : if (hasToMultiApp()) 49 0 : paramError("to_multi_app", "To and between multiapp directions are not implemented"); 50 2762 : } 51 : 52 : void 53 2758 : SamplerReporterTransfer::initialSetup() 54 : { 55 : // Get the StochasticResults VPP object to populate 56 5516 : auto & uo = _fe_problem.getUserObject<UserObject>(getParam<std::string>("stochastic_reporter")); 57 2758 : _results = dynamic_cast<StochasticReporter *>(&uo); 58 2758 : if (!_results) 59 0 : paramError("stochastic_reporter", "This object must be a 'StochasticReporter' object."); 60 : 61 2758 : intitializeStochasticReporters(); 62 2750 : } 63 : 64 : void 65 3999 : SamplerReporterTransfer::initializeFromMultiapp() 66 : { 67 3999 : } 68 : 69 : void 70 20762 : SamplerReporterTransfer::executeFromMultiapp() 71 : { 72 41524 : if (getFromMultiApp()->isRootProcessor()) 73 : { 74 20368 : const dof_id_type n = getFromMultiApp()->numGlobalApps(); 75 1068532 : for (MooseIndex(n) i = 0; i < n; i++) 76 1048164 : transferStochasticReporters(_global_index, i); 77 : } 78 20762 : } 79 : 80 : void 81 3999 : SamplerReporterTransfer::finalizeFromMultiapp() 82 : { 83 3999 : } 84 : 85 : void 86 4526 : SamplerReporterTransfer::execute() 87 : { 88 18184 : for (dof_id_type i = _sampler_ptr->getLocalRowBegin(); i < _sampler_ptr->getLocalRowEnd(); ++i) 89 13658 : transferStochasticReporters(i, i); 90 4526 : } 91 : 92 : void 93 2758 : SamplerReporterTransfer::intitializeStochasticReporters() 94 : { 95 2758 : const dof_id_type n = getFromMultiApp()->numGlobalApps(); 96 : 97 7415 : for (const auto & sub_rname : _sub_reporter_names) 98 90825 : for (MooseIndex(n) i = 0; i < n; i++) 99 172336 : if (getFromMultiApp()->hasLocalApp(i)) 100 19510 : addReporterTransferMode( 101 39020 : sub_rname, REPORTER_MODE_ROOT, getFromMultiApp()->appProblemBase(i)); 102 : 103 8683 : const std::string prefix = isParamValid("prefix") ? getParam<std::string>("prefix") : name(); 104 7407 : for (const auto & sub_rname : _sub_reporter_names) 105 11812 : for (MooseIndex(n) i = 0; i < n; i++) 106 23624 : if (getFromMultiApp()->hasLocalApp(i)) 107 : { 108 4657 : const ReporterData & rdata = getFromMultiApp()->appProblemBase(i).getReporterData(); 109 : ReporterName rname = 110 9310 : _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 4649 : _reporter_names.push_back(rname); 119 : break; 120 : } 121 : 122 2750 : _converged = &_results->declareStochasticReporter<bool>( 123 7841 : prefix + (prefix.empty() ? "" : ":") + "converged", *_sampler_ptr); 124 2750 : } 125 : 126 : void 127 1061822 : SamplerReporterTransfer::transferStochasticReporters(dof_id_type global_index, 128 : dof_id_type app_index) 129 : { 130 2123644 : if (getFromMultiApp()->hasLocalApp(app_index)) 131 : { 132 34026 : const dof_id_type local_index = global_index - _sampler_ptr->getLocalRowBegin(); 133 95935 : for (unsigned int r = 0; r < _sub_reporter_names.size(); ++r) 134 61909 : transferToVectorReporter(_sub_reporter_names[r], 135 : _reporter_names[r], 136 123818 : getFromMultiApp()->appProblemBase(app_index), 137 123818 : getFromMultiApp()->problemBase(), 138 : local_index); 139 : 140 68052 : (*_converged)[local_index] = getFromMultiApp()->getExecutioner(app_index)->lastSolveConverged(); 141 : } 142 1061822 : }