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 : // MOOSE includes 11 : #include "MultiAppCopyTransfer.h" 12 : #include "FEProblemBase.h" 13 : #include "MultiApp.h" 14 : #include "SystemBase.h" 15 : 16 : #include "libmesh/id_types.h" 17 : #include "libmesh/string_to_enum.h" 18 : 19 : registerMooseObject("MooseApp", MultiAppCopyTransfer); 20 : 21 : InputParameters 22 15555 : MultiAppCopyTransfer::validParams() 23 : { 24 15555 : InputParameters params = MultiAppDofCopyTransfer::validParams(); 25 15555 : params.addRequiredParam<std::vector<AuxVariableName>>( 26 : "variable", "The auxiliary variable to store the transferred values in."); 27 15555 : params.addRequiredParam<std::vector<VariableName>>("source_variable", 28 : "The variable to transfer from."); 29 : 30 15555 : params.addClassDescription( 31 : "Copies variables (nonlinear and auxiliary) between multiapps that have identical meshes."); 32 15555 : return params; 33 0 : } 34 : 35 651 : MultiAppCopyTransfer::MultiAppCopyTransfer(const InputParameters & parameters) 36 : : MultiAppDofCopyTransfer(parameters), 37 639 : _from_var_names(getParam<std::vector<VariableName>>("source_variable")), 38 1290 : _to_var_names(getParam<std::vector<AuxVariableName>>("variable")) 39 : { 40 : /* Right now, most of derived transfers support one variable only */ 41 639 : _to_var_name = _to_var_names.size() ? _to_var_names[0] : "INVALID"; 42 639 : _from_var_name = _from_var_names.size() ? _from_var_names[0] : "INVALID"; 43 639 : } 44 : 45 : void 46 2167 : MultiAppCopyTransfer::execute() 47 : { 48 2167 : TIME_SECTION("MultiAppCopyTransfer::execute()", 5, "Copies variables"); 49 : 50 2167 : if (_current_direction == TO_MULTIAPP) 51 : { 52 1034 : FEProblemBase & from_problem = getToMultiApp()->problemBase(); 53 2056 : for (unsigned int i = 0; i < getToMultiApp()->numGlobalApps(); i++) 54 1034 : if (getToMultiApp()->hasLocalApp(i)) 55 1034 : transfer(getToMultiApp()->appProblemBase(i), from_problem); 56 : } 57 : 58 1133 : else if (_current_direction == FROM_MULTIAPP) 59 : { 60 1067 : FEProblemBase & to_problem = getFromMultiApp()->problemBase(); 61 2134 : for (unsigned int i = 0; i < getFromMultiApp()->numGlobalApps(); i++) 62 1067 : if (getFromMultiApp()->hasLocalApp(i)) 63 1067 : transfer(to_problem, getFromMultiApp()->appProblemBase(i)); 64 : } 65 : 66 66 : else if (_current_direction == BETWEEN_MULTIAPP) 67 : { 68 66 : int transfers_done = 0; 69 132 : for (unsigned int i = 0; i < getFromMultiApp()->numGlobalApps(); i++) 70 : { 71 66 : if (getFromMultiApp()->hasLocalApp(i)) 72 : { 73 66 : if (getToMultiApp()->hasLocalApp(i)) 74 : { 75 66 : transfer(getToMultiApp()->appProblemBase(i), getFromMultiApp()->appProblemBase(i)); 76 66 : transfers_done++; 77 : } 78 : } 79 : } 80 66 : if (!transfers_done) 81 0 : mooseError("BETWEEN_MULTIAPP transfer not supported if there is not at least one subapp " 82 : "per multiapp involved on each rank"); 83 : } 84 2155 : } 85 : 86 : void 87 11 : MultiAppCopyTransfer::checkSiblingsTransferSupported() const 88 : { 89 : // Check that we are in the supported configuration: same number of source and target apps 90 : // The allocation of the child apps on the processors must be the same 91 11 : if (getFromMultiApp()->numGlobalApps() == getToMultiApp()->numGlobalApps()) 92 : { 93 22 : for (const auto i : make_range(getToMultiApp()->numGlobalApps())) 94 11 : if (getFromMultiApp()->hasLocalApp(i) + getToMultiApp()->hasLocalApp(i) == 1) 95 0 : mooseError("Child application allocation on parallel processes must be the same to support " 96 : "siblings variable field copy transfer"); 97 : } 98 : else 99 0 : mooseError("Number of source and target child apps must match for siblings transfer"); 100 11 : }