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 : #include "StochasticToolsTransfer.h" 10 : #include "MultiApp.h" 11 : #include "Sampler.h" 12 : #include "SamplerTransientMultiApp.h" 13 : #include "SamplerFullSolveMultiApp.h" 14 : 15 : InputParameters 16 15536 : StochasticToolsTransfer::validParams() 17 : { 18 15536 : InputParameters params = MultiAppTransfer::validParams(); 19 15536 : params.set<bool>("check_multiapp_execute_on", true) = false; // see comments in constructor 20 31072 : params.addParam<SamplerName>("sampler", "A the Sampler object that Transfer is associated.."); 21 15536 : return params; 22 0 : } 23 : 24 7706 : StochasticToolsTransfer::StochasticToolsTransfer(const InputParameters & parameters) 25 7706 : : MultiAppTransfer(parameters), SamplerInterface(this) 26 : { 27 : // Since sampler lives in the main app, it's unclear what sibling transfer should look like 28 7706 : if (hasFromMultiApp() && hasToMultiApp()) 29 4 : mooseError("Transfers between multiapp are not currently supported for this transfer type"); 30 : 31 7702 : const auto multi_app = hasFromMultiApp() ? getFromMultiApp() : getToMultiApp(); 32 : 33 : // When the MultiApp is running in batch mode the execute flags for the transfer object must 34 : // be removed. If not the 'regular' transfer that occurs will potentially destroy data 35 : // populated during the calls from the MultiApp in batch mode. To prevent the Transfer from 36 : // running the execute flags must be removed. This is done automatically here, unless 37 : // 'execute_on' was modified by the user, which an error is produced. 38 30800 : if (multi_app->isParamValid("mode") && 39 23090 : (multi_app->getParam<MooseEnum>("mode") == "batch-reset" || 40 19502 : multi_app->getParam<MooseEnum>("mode") == "batch-restore")) 41 : { 42 8660 : if (parameters.isParamSetByUser("execute_on")) 43 4 : paramError("execute_on", 44 : "The 'execute_on' parameter for the '", 45 : name(), 46 : "' transfer was set, but the parent MultiApp object (", 47 4 : multi_app->name(), 48 : ") is running in 'batch' mode. For this case the 'execute_on' parameter must not " 49 : "be set by the user or set to NONE."); 50 : else 51 : { 52 4326 : ExecFlagEnum & exec_flags = const_cast<ExecFlagEnum &>(getParam<ExecFlagEnum>("execute_on")); 53 4326 : exec_flags = EXEC_NONE; 54 : } 55 : } 56 : 57 : // In the validParams method above the 'check_multiapp_execute_on' is disabled. This is required 58 : // to allow for the error above to be triggered. If the 'execute_on' is set by the without 59 : // the 'check_multiapp_execute_on' flag the above if statement may not be reached. Therefore, 60 : // a bit of a trick is performed to allow the above check to run first and then the regular 61 : // check. 62 : // 63 : // If the else statement is reached then the user is not running in batch mode, so the 64 : // 'check_multiapp_execute_on' is a valid check to perform. If the 'check_multiapp_execute_on' 65 : // has not been set, then the user wants the check to be performed, so do it. 66 6744 : else if (!parameters.isParamSetByUser("check_multiapp_execute_on")) 67 2842 : checkMultiAppExecuteOn(); 68 : 69 : // Determine the Sampler 70 15388 : if (isParamValid("sampler")) 71 : { 72 7694 : _sampler_ptr = &(getSampler("sampler")); 73 : 74 : SamplerTransientMultiApp * ptr_transient = 75 7694 : dynamic_cast<SamplerTransientMultiApp *>(multi_app.get()); 76 : SamplerFullSolveMultiApp * ptr_fullsolve = 77 7694 : dynamic_cast<SamplerFullSolveMultiApp *>(multi_app.get()); 78 : 79 7694 : if (!ptr_transient && !ptr_fullsolve) 80 8 : mooseError("The 'multi_app' parameter must provide either a 'SamplerTransientMultiApp' or " 81 : "'SamplerFullSolveMultiApp' object."); 82 : 83 15372 : if ((ptr_transient && &(ptr_transient->getSampler("sampler")) != _sampler_ptr) || 84 14132 : (ptr_fullsolve && &(ptr_fullsolve->getSampler("sampler")) != _sampler_ptr)) 85 4 : mooseError("The supplied 'multi_app' must have the same Sampler object as this Transfer."); 86 : } 87 : 88 : else 89 : { 90 0 : paramWarning("sampler", 91 : "Support for the 'StochasticToolsTransfer' objects without the 'sampler' input " 92 : "parameter is being removed, please update your input file(s)."); 93 : 94 : std::shared_ptr<SamplerTransientMultiApp> ptr_transient = 95 0 : std::dynamic_pointer_cast<SamplerTransientMultiApp>(multi_app); 96 : std::shared_ptr<SamplerFullSolveMultiApp> ptr_fullsolve = 97 0 : std::dynamic_pointer_cast<SamplerFullSolveMultiApp>(multi_app); 98 : 99 0 : if (!ptr_transient && !ptr_fullsolve) 100 0 : mooseError("The 'multi_app' parameter must provide either a 'SamplerTransientMultiApp' or " 101 : "'SamplerFullSolveMultiApp' object."); 102 : 103 0 : if (ptr_transient) 104 0 : _sampler_ptr = &(ptr_transient->getSampler("sampler")); 105 : else 106 0 : _sampler_ptr = &(ptr_fullsolve->getSampler("sampler")); 107 : } 108 7682 : } 109 : 110 : void 111 0 : StochasticToolsTransfer::initializeFromMultiapp() 112 : { 113 0 : } 114 : 115 : void 116 0 : StochasticToolsTransfer::executeFromMultiapp() 117 : { 118 0 : } 119 : 120 : void 121 0 : StochasticToolsTransfer::finalizeFromMultiapp() 122 : { 123 0 : } 124 : 125 : void 126 4546 : StochasticToolsTransfer::initializeToMultiapp() 127 : { 128 4546 : } 129 : 130 : void 131 0 : StochasticToolsTransfer::executeToMultiapp() 132 : { 133 0 : } 134 : 135 : void 136 4546 : StochasticToolsTransfer::finalizeToMultiapp() 137 : { 138 4546 : }