From 3ed5525d7727520f9644042d760225c78decce8b Mon Sep 17 00:00:00 2001 From: Guillaume Giudicelli Date: Thu, 10 Feb 2022 20:04:26 -0700 Subject: [PATCH] Switch parameter to to_multiapp from_multiapp --- .../include/transfers/MultiAppTransfer.h | 14 +- framework/include/transfers/Transfer.h | 2 +- framework/src/problems/FEProblemBase.C | 6 +- .../transfers/MultiAppCloneReporterTransfer.C | 51 +++-- .../transfers/MultiAppConservativeTransfer.C | 54 ++--- .../src/transfers/MultiAppCopyTransfer.C | 22 +- .../transfers/MultiAppInterpolationTransfer.C | 26 +-- ...ltiAppPostprocessorInterpolationTransfer.C | 16 +- ...MultiAppPostprocessorToAuxScalarTransfer.C | 19 +- .../transfers/MultiAppPostprocessorTransfer.C | 20 +- .../src/transfers/MultiAppReporterTransfer.C | 30 +-- .../MultiAppScalarToAuxScalarTransfer.C | 16 +- framework/src/transfers/MultiAppTransfer.C | 203 +++++++++--------- .../transfers/MultiAppUserObjectTransfer.C | 50 ++--- ...VariableValueSamplePostprocessorTransfer.C | 10 +- .../MultiAppVariableValueSampleTransfer.C | 27 ++- .../MultiAppVectorPostprocessorTransfer.C | 30 +-- framework/src/transfers/Transfer.C | 6 +- .../between_multiapps/main.i | 2 +- 19 files changed, 322 insertions(+), 282 deletions(-) diff --git a/framework/include/transfers/MultiAppTransfer.h b/framework/include/transfers/MultiAppTransfer.h index 2e84f79250c8..c7d5da377e8f 100644 --- a/framework/include/transfers/MultiAppTransfer.h +++ b/framework/include/transfers/MultiAppTransfer.h @@ -45,14 +45,22 @@ class MultiAppTransfer : public Transfer void variableIntegrityCheck(const AuxVariableName & var_name) const; /// Return the MultiApp that this transfer belongs to - const std::shared_ptr getMultiApp() const { return _multi_app; } + const std::shared_ptr getMultiApp() const + { + if (_from_multi_app && _to_multi_app) + mooseError("Unclear which app you want from Transfer ", name()); + else if (_from_multi_app) + return _from_multi_app; + else if (_to_multi_app) + return _to_multi_app; + } /// Return the execution flags, handling "same_as_multiapp" virtual const std::vector & execFlags() const; protected: - /// The MultiApp this Transfer is transferring data to or from - std::shared_ptr _multi_app; + /// The MultiApps this Transfer is transferring data to or from + std::shared_ptr _from_multi_app; std::shared_ptr _to_multi_app; /** diff --git a/framework/include/transfers/Transfer.h b/framework/include/transfers/Transfer.h index d9abb48ad41f..9c83c1dd1efd 100644 --- a/framework/include/transfers/Transfer.h +++ b/framework/include/transfers/Transfer.h @@ -108,7 +108,7 @@ class Transfer : public MooseObject, public SetupInterface, public Restartable ///@} /// The directions this Transfer is to be executed on - const MultiMooseEnum _directions; + MultiMooseEnum _directions; public: const static Number OutOfMeshValue; diff --git a/framework/src/problems/FEProblemBase.C b/framework/src/problems/FEProblemBase.C index ab9291e20115..5dd501a81f1d 100644 --- a/framework/src/problems/FEProblemBase.C +++ b/framework/src/problems/FEProblemBase.C @@ -4226,9 +4226,9 @@ FEProblemBase::execMultiAppTransfers(ExecFlagType type, Transfer::DIRECTION dire else string_direction = " between "; - const MooseObjectWarehouse & wh = - to_multiapp ? _to_multi_app_transfers[type] - : from_multiapp ? _from_multi_app_transfers[type] : _between_multi_app_transfers; + const MooseObjectWarehouse & wh = to_multiapp ? _to_multi_app_transfers[type] + : from_multiapp ? _from_multi_app_transfers[type] + : _between_multi_app_transfers; if (wh.hasActiveObjects()) { diff --git a/framework/src/transfers/MultiAppCloneReporterTransfer.C b/framework/src/transfers/MultiAppCloneReporterTransfer.C index dad99a9ff826..bd689bb9505c 100644 --- a/framework/src/transfers/MultiAppCloneReporterTransfer.C +++ b/framework/src/transfers/MultiAppCloneReporterTransfer.C @@ -59,7 +59,12 @@ MultiAppCloneReporterTransfer::MultiAppCloneReporterTransfer(const InputParamete void MultiAppCloneReporterTransfer::initialSetup() { - if (!_multi_app->hasApp() && !isParamValid("reporter_type")) + if (_to_multi_app && !_to_multi_app->hasApp() && !isParamValid("reporter_type")) + mooseError("For a direct reporter clone, all processors must be associated with a " + "sub-application. If you know the type of reporter being transferred, please " + "consider using the 'reporter_type' parameter for an indirect clone."); + + if (_from_multi_app && !_from_multi_app->hasApp() && !isParamValid("reporter_type")) mooseError("For a direct reporter clone, all processors must be associated with a " "sub-application. If you know the type of reporter being transferred, please " "consider using the 'reporter_type' parameter for an indirect clone."); @@ -68,31 +73,32 @@ MultiAppCloneReporterTransfer::initialSetup() if (!dynamic_cast(&uo)) paramError("to_reporter", "This object must be a Reporter object."); - const dof_id_type n = _multi_app->numGlobalApps(); + const auto multi_app = _from_multi_app ? _from_multi_app : _to_multi_app; + const dof_id_type n = multi_app->numGlobalApps(); for (unsigned int r = 0; r < _from_reporter_names.size(); ++r) for (MooseIndex(n) i = 0; i < n; i++) - if (_multi_app->hasLocalApp(i)) + if (multi_app->hasLocalApp(i)) addReporterTransferMode( - _from_reporter_names[r], REPORTER_MODE_ROOT, _multi_app->appProblemBase(i)); + _from_reporter_names[r], REPORTER_MODE_ROOT, multi_app->appProblemBase(i)); - if (_multi_app->hasApp()) + if (multi_app->hasApp()) { for (unsigned int r = 0; r < _from_reporter_names.size(); ++r) for (MooseIndex(n) i = 0; i < n; i++) - if (_multi_app->hasLocalApp(i)) + if (multi_app->hasLocalApp(i)) { if (n > 1) declareVectorClone(_from_reporter_names[r], _to_reporter_names[r], - _multi_app->appProblemBase(i), - _multi_app->problemBase(), + multi_app->appProblemBase(i), + multi_app->problemBase(), REPORTER_MODE_DISTRIBUTED); else declareClone(_from_reporter_names[r], _to_reporter_names[r], - _multi_app->appProblemBase(i), - _multi_app->problemBase(), + multi_app->appProblemBase(i), + multi_app->problemBase(), REPORTER_MODE_ROOT); break; } @@ -106,16 +112,15 @@ MultiAppCloneReporterTransfer::initialSetup() { if (n > 1) declareVectorClone( - _to_reporter_names[r], _multi_app->problemBase(), types[r], REPORTER_MODE_DISTRIBUTED); + _to_reporter_names[r], multi_app->problemBase(), types[r], REPORTER_MODE_DISTRIBUTED); else - declareClone( - _to_reporter_names[r], _multi_app->problemBase(), types[r], REPORTER_MODE_ROOT); + declareClone(_to_reporter_names[r], multi_app->problemBase(), types[r], REPORTER_MODE_ROOT); } } - if (n > 1 && _multi_app->isRootProcessor()) + if (n > 1 && multi_app->isRootProcessor()) for (const auto & rn : _to_reporter_names) - resizeReporter(rn, _multi_app->problemBase(), _multi_app->numLocalApps()); + resizeReporter(rn, multi_app->problemBase(), multi_app->numLocalApps()); } void @@ -126,26 +131,26 @@ MultiAppCloneReporterTransfer::executeToMultiapp() void MultiAppCloneReporterTransfer::executeFromMultiapp() { - if (!_multi_app->isRootProcessor()) + if (!_from_multi_app->isRootProcessor()) return; - const dof_id_type begin = _multi_app->firstLocalApp(); - const dof_id_type end = begin + _multi_app->numLocalApps(); + const dof_id_type begin = _from_multi_app->firstLocalApp(); + const dof_id_type end = begin + _from_multi_app->numLocalApps(); for (unsigned int r = 0; r < _from_reporter_names.size(); ++r) for (dof_id_type i = begin; i < end; ++i) { - if (_multi_app->numGlobalApps() > 1) + if (_from_multi_app->numGlobalApps() > 1) transferToVectorReporter(_from_reporter_names[r], _to_reporter_names[r], - _multi_app->appProblemBase(i), - _multi_app->problemBase(), + _from_multi_app->appProblemBase(i), + _from_multi_app->problemBase(), i - begin); else transferReporter(_from_reporter_names[r], _to_reporter_names[r], - _multi_app->appProblemBase(i), - _multi_app->problemBase()); + _from_multi_app->appProblemBase(i), + _from_multi_app->problemBase()); } } diff --git a/framework/src/transfers/MultiAppConservativeTransfer.C b/framework/src/transfers/MultiAppConservativeTransfer.C index aeb98bac1545..de8879077537 100644 --- a/framework/src/transfers/MultiAppConservativeTransfer.C +++ b/framework/src/transfers/MultiAppConservativeTransfer.C @@ -70,7 +70,7 @@ MultiAppConservativeTransfer::MultiAppConservativeTransfer(const InputParameters if (_current_direction == TO_MULTIAPP) { - if (_from_postprocessors_to_be_preserved.size() != _multi_app->numGlobalApps() && + if (_from_postprocessors_to_be_preserved.size() != _to_multi_app->numGlobalApps() && _from_postprocessors_to_be_preserved.size() != 1) paramError("from_postprocessors_to_be_preserved", "Number of from-postprocessors should equal to the number of subapps, or use " @@ -85,7 +85,7 @@ MultiAppConservativeTransfer::MultiAppConservativeTransfer(const InputParameters paramError("from_postprocessors_to_be_preserved", "Number of from Postprocessors should equal to 1"); - if (_to_postprocessors_to_be_preserved.size() != _multi_app->numGlobalApps() && + if (_to_postprocessors_to_be_preserved.size() != _from_multi_app->numGlobalApps() && _to_postprocessors_to_be_preserved.size() != 1) paramError("to_postprocessors_to_be_preserved", "_to_postprocessors_to_be_preserved", @@ -114,7 +114,7 @@ MultiAppConservativeTransfer::initialSetup() { if (_from_postprocessors_to_be_preserved.size() == 1 && _current_direction == TO_MULTIAPP) { - FEProblemBase & from_problem = _multi_app->problemBase(); + FEProblemBase & from_problem = _to_multi_app->problemBase(); auto * pps = dynamic_cast( &(from_problem.getUserObjectBase(_from_postprocessors_to_be_preserved[0]))); if (pps) @@ -122,17 +122,17 @@ MultiAppConservativeTransfer::initialSetup() else { _use_nearestpoint_pps = false; - if (_multi_app->numGlobalApps() > 1) + if (_to_multi_app->numGlobalApps() > 1) mooseError( " You have to specify ", - _multi_app->numGlobalApps(), + _to_multi_app->numGlobalApps(), " regular from-postprocessors, or use NearestPointIntegralVariablePostprocessor "); } } if (_to_postprocessors_to_be_preserved.size() == 1 && _current_direction == FROM_MULTIAPP) { - FEProblemBase & to_problem = _multi_app->problemBase(); + FEProblemBase & to_problem = _from_multi_app->problemBase(); auto * pps = dynamic_cast( &(to_problem.getUserObjectBase(_to_postprocessors_to_be_preserved[0]))); if (pps) @@ -140,17 +140,19 @@ MultiAppConservativeTransfer::initialSetup() else { _use_nearestpoint_pps = false; - if (_multi_app->numGlobalApps() > 1) + if (_from_multi_app->numGlobalApps() > 1) mooseError( " You have to specify ", - _multi_app->numGlobalApps(), + _from_multi_app->numGlobalApps(), " regular to-postprocessors, or use NearestPointIntegralVariablePostprocessor "); } } + const auto multi_app = _from_multi_app ? _from_multi_app : _to_multi_app; + // Let us check execute_on here. Users need to specify execute_on='transfer' in their input // files for the postprocessors that are used to compute conversative qualities Master app - FEProblemBase & master_problem = _multi_app->problemBase(); + FEProblemBase & master_problem = multi_app->problemBase(); std::vector pps_empty; // PPs for master app auto & master_pps = @@ -169,13 +171,13 @@ MultiAppConservativeTransfer::initialSetup() } // Sub apps - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) + for (unsigned int i = 0; i < multi_app->numGlobalApps(); i++) { - // If we dot not have this app, we skip - if (!_multi_app->hasLocalApp(i)) + // If we do not have this app, we skip + if (!multi_app->hasLocalApp(i)) continue; // Sub problem for - FEProblemBase & sub_problem = _multi_app->appProblemBase(i); + FEProblemBase & sub_problem = multi_app->appProblemBase(i); // PPs for this subapp auto & sub_pps = _current_direction == TO_MULTIAPP ? _to_postprocessors_to_be_preserved : pps_empty; @@ -204,50 +206,50 @@ MultiAppConservativeTransfer::postExecute() if (_current_direction == TO_MULTIAPP) { - FEProblemBase & from_problem = _multi_app->problemBase(); + FEProblemBase & from_problem = _to_multi_app->problemBase(); if (_use_nearestpoint_pps) from_problem.computeUserObjectByName( EXEC_TRANSFER, Moose::POST_AUX, _from_postprocessors_to_be_preserved[0]); - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) - if (_multi_app->hasLocalApp(i)) + for (unsigned int i = 0; i < _to_multi_app->numGlobalApps(); i++) + if (_to_multi_app->hasLocalApp(i)) { if (_use_nearestpoint_pps) adjustTransferedSolutionNearestPoint(i, &from_problem, _from_postprocessors_to_be_preserved[0], - _multi_app->appProblemBase(i), + _to_multi_app->appProblemBase(i), _to_postprocessors_to_be_preserved[0]); else adjustTransferedSolution(&from_problem, _from_postprocessors_to_be_preserved[i], - _multi_app->appProblemBase(i), + _to_multi_app->appProblemBase(i), _to_postprocessors_to_be_preserved[0]); } } else if (_current_direction == FROM_MULTIAPP) { - FEProblemBase & to_problem = _multi_app->problemBase(); + FEProblemBase & to_problem = _from_multi_app->problemBase(); if (_use_nearestpoint_pps) to_problem.computeUserObjectByName( EXEC_TRANSFER, Moose::POST_AUX, _to_postprocessors_to_be_preserved[0]); - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) + for (unsigned int i = 0; i < _from_multi_app->numGlobalApps(); i++) { if (_use_nearestpoint_pps) adjustTransferedSolutionNearestPoint( i, - _multi_app->hasLocalApp(i) ? &_multi_app->appProblemBase(i) : nullptr, + _from_multi_app->hasLocalApp(i) ? &_from_multi_app->appProblemBase(i) : nullptr, _from_postprocessors_to_be_preserved[0], to_problem, _to_postprocessors_to_be_preserved[0]); else - adjustTransferedSolution(_multi_app->hasLocalApp(i) ? &_multi_app->appProblemBase(i) - : nullptr, - _from_postprocessors_to_be_preserved[0], - to_problem, - _to_postprocessors_to_be_preserved[i]); + adjustTransferedSolution( + _from_multi_app->hasLocalApp(i) ? &_from_multi_app->appProblemBase(i) : nullptr, + _from_postprocessors_to_be_preserved[0], + to_problem, + _to_postprocessors_to_be_preserved[i]); } // Compute the to-postprocessor again so that it has the right value with the updated solution diff --git a/framework/src/transfers/MultiAppCopyTransfer.C b/framework/src/transfers/MultiAppCopyTransfer.C index a44f37a69e2d..dfd8c6079b83 100644 --- a/framework/src/transfers/MultiAppCopyTransfer.C +++ b/framework/src/transfers/MultiAppCopyTransfer.C @@ -47,32 +47,32 @@ MultiAppCopyTransfer::execute() if (_current_direction == TO_MULTIAPP) { - FEProblemBase & from_problem = _multi_app->problemBase(); - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) - if (_multi_app->hasLocalApp(i)) - transfer(_multi_app->appProblemBase(i), from_problem); + FEProblemBase & from_problem = _to_multi_app->problemBase(); + for (unsigned int i = 0; i < _to_multi_app->numGlobalApps(); i++) + if (_to_multi_app->hasLocalApp(i)) + transfer(_to_multi_app->appProblemBase(i), from_problem); } else if (_current_direction == FROM_MULTIAPP) { - FEProblemBase & to_problem = _multi_app->problemBase(); - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) - if (_multi_app->hasLocalApp(i)) - transfer(to_problem, _multi_app->appProblemBase(i)); + FEProblemBase & to_problem = _from_multi_app->problemBase(); + for (unsigned int i = 0; i < _from_multi_app->numGlobalApps(); i++) + if (_from_multi_app->hasLocalApp(i)) + transfer(to_problem, _from_multi_app->appProblemBase(i)); } else if (_current_direction == BETWEEN_MULTIAPP) { bool transfer_done = false; - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) + for (unsigned int i = 0; i < _from_multi_app->numGlobalApps(); i++) { - if (_multi_app->hasLocalApp(i)) + if (_from_multi_app->hasLocalApp(i)) { for (unsigned int j = 0; j < _to_multi_app->numGlobalApps(); j++) { if (_to_multi_app->hasLocalApp(j)) { - transfer(_to_multi_app->appProblemBase(j), _multi_app->appProblemBase(i)); + transfer(_to_multi_app->appProblemBase(j), _from_multi_app->appProblemBase(i)); transfer_done = true; } } diff --git a/framework/src/transfers/MultiAppInterpolationTransfer.C b/framework/src/transfers/MultiAppInterpolationTransfer.C index 533c3ecf717d..fef959314d55 100644 --- a/framework/src/transfers/MultiAppInterpolationTransfer.C +++ b/framework/src/transfers/MultiAppInterpolationTransfer.C @@ -412,7 +412,9 @@ MultiAppInterpolationTransfer::execute() { _console << "Beginning InterpolationTransfer " << name() << std::endl; - const FEProblemBase & fe_problem = _multi_app->problemBase(); + // CHECK THIS + const FEProblemBase & fe_problem = + _from_multi_app ? _from_multi_app->problemBase() : _to_multi_app->problemBase(); std::unique_ptr> idi; switch (_interp_type) { @@ -433,7 +435,7 @@ MultiAppInterpolationTransfer::execute() { case TO_MULTIAPP: { - FEProblemBase & from_problem = _multi_app->problemBase(); + FEProblemBase & from_problem = _to_multi_app->problemBase(); const auto & from_var = from_problem.getVariable( 0, _from_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD); const Point from_app_position(0); @@ -443,19 +445,19 @@ MultiAppInterpolationTransfer::execute() // We have only set local values - prepare for use by gathering remote gata idi->prepare_for_use(); - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) + for (unsigned int i = 0; i < _to_multi_app->numGlobalApps(); i++) { - if (_multi_app->hasLocalApp(i)) + if (_to_multi_app->hasLocalApp(i)) { - auto & to_problem = _multi_app->appProblemBase(i); + auto & to_problem = _to_multi_app->appProblemBase(i); Moose::ScopedCommSwapper swapper(to_problem.comm().get()); - const auto to_app_position = _multi_app->position(i); + const auto to_app_position = _to_multi_app->position(i); auto & to_var = to_problem.getVariable(0, _to_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD); - auto & to_solution = _multi_app->appTransferVector(i, _to_var_name); + auto & to_solution = _to_multi_app->appTransferVector(i, _to_var_name); interpolateTargetPoints(to_problem, to_var, to_solution, to_app_position, idi); } @@ -466,13 +468,13 @@ MultiAppInterpolationTransfer::execute() case FROM_MULTIAPP: { - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) + for (unsigned int i = 0; i < _from_multi_app->numGlobalApps(); i++) { - if (_multi_app->hasLocalApp(i)) + if (_from_multi_app->hasLocalApp(i)) { - auto & from_problem = _multi_app->appProblemBase(i); + auto & from_problem = _from_multi_app->appProblemBase(i); Moose::ScopedCommSwapper swapper(from_problem.comm().get()); - const auto from_app_position = _multi_app->position(i); + const auto from_app_position = _from_multi_app->position(i); const auto & from_var = from_problem.getVariable(0, _from_var_name, Moose::VarKindType::VAR_ANY, @@ -484,7 +486,7 @@ MultiAppInterpolationTransfer::execute() idi->prepare_for_use(); - FEProblemBase & to_problem = _multi_app->problemBase(); + FEProblemBase & to_problem = _from_multi_app->problemBase(); MooseVariableFieldBase & to_var = to_problem.getVariable( 0, _to_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD); diff --git a/framework/src/transfers/MultiAppPostprocessorInterpolationTransfer.C b/framework/src/transfers/MultiAppPostprocessorInterpolationTransfer.C index f07a4a1bd426..e122887cdead 100644 --- a/framework/src/transfers/MultiAppPostprocessorInterpolationTransfer.C +++ b/framework/src/transfers/MultiAppPostprocessorInterpolationTransfer.C @@ -65,7 +65,7 @@ MultiAppPostprocessorInterpolationTransfer::MultiAppPostprocessorInterpolationTr if (_directions.contains(TO_MULTIAPP)) paramError("Can't interpolate to a MultiApp!"); - auto & to_fe_type = _multi_app->problemBase().getStandardVariable(0, _to_var_name).feType(); + auto & to_fe_type = _from_multi_app->problemBase().getStandardVariable(0, _to_var_name).feType(); if ((to_fe_type.order != CONSTANT || to_fe_type.family != MONOMIAL) && (to_fe_type.order != FIRST || to_fe_type.family != LAGRANGE)) paramError("variable", "Must be either CONSTANT MONOMIAL or FIRST LAGRANGE"); @@ -109,12 +109,12 @@ MultiAppPostprocessorInterpolationTransfer::execute() idi->set_field_variables(field_vars); { - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) + for (unsigned int i = 0; i < _from_multi_app->numGlobalApps(); i++) { - if (_multi_app->hasLocalApp(i) && _multi_app->isRootProcessor()) + if (_from_multi_app->hasLocalApp(i) && _from_multi_app->isRootProcessor()) { - src_pts.push_back(_multi_app->position(i)); - src_vals.push_back(_multi_app->appPostprocessorValue(i, _postprocessor)); + src_pts.push_back(_from_multi_app->position(i)); + src_vals.push_back(_from_multi_app->appPostprocessorValue(i, _postprocessor)); } } } @@ -124,14 +124,14 @@ MultiAppPostprocessorInterpolationTransfer::execute() // Loop over the master nodes and set the value of the variable { - System * to_sys = find_sys(_multi_app->problemBase().es(), _to_var_name); + System * to_sys = find_sys(_from_multi_app->problemBase().es(), _to_var_name); unsigned int sys_num = to_sys->number(); unsigned int var_num = to_sys->variable_number(_to_var_name); NumericVector & solution = *to_sys->solution; - MooseMesh & mesh = _multi_app->problemBase().mesh(); + MooseMesh & mesh = _from_multi_app->problemBase().mesh(); std::vector vars; @@ -189,7 +189,7 @@ MultiAppPostprocessorInterpolationTransfer::execute() solution.close(); } - _multi_app->problemBase().es().update(); + _from_multi_app->problemBase().es().update(); delete idi; diff --git a/framework/src/transfers/MultiAppPostprocessorToAuxScalarTransfer.C b/framework/src/transfers/MultiAppPostprocessorToAuxScalarTransfer.C index 04bcdb5b8411..6b12331198a0 100644 --- a/framework/src/transfers/MultiAppPostprocessorToAuxScalarTransfer.C +++ b/framework/src/transfers/MultiAppPostprocessorToAuxScalarTransfer.C @@ -60,16 +60,16 @@ MultiAppPostprocessorToAuxScalarTransfer::execute() case TO_MULTIAPP: { // Extract the postprocessor that is being transferd - FEProblemBase & from_problem = _multi_app->problemBase(); + FEProblemBase & from_problem = _to_multi_app->problemBase(); Real pp_value = from_problem.getPostprocessorValueByName(_from_pp_name); // Loop through each of the sub apps - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) - if (_multi_app->hasLocalApp(i)) + for (unsigned int i = 0; i < _to_multi_app->numGlobalApps(); i++) + if (_to_multi_app->hasLocalApp(i)) { // Get reference to the AuxVariable where the postprocessor will be passed MooseVariableScalar & scalar = - _multi_app->appProblemBase(i).getScalarVariable(_tid, _to_aux_name); + _to_multi_app->appProblemBase(i).getScalarVariable(_tid, _to_aux_name); scalar.reinit(); @@ -87,11 +87,11 @@ MultiAppPostprocessorToAuxScalarTransfer::execute() case FROM_MULTIAPP: { // The number of sub applications - unsigned int num_apps = _multi_app->numGlobalApps(); + unsigned int num_apps = _from_multi_app->numGlobalApps(); // The AuxVariable for storing the postprocessor values from the sub app MooseVariableScalar & scalar = - _multi_app->problemBase().getScalarVariable(_tid, _to_aux_name); + _from_multi_app->problemBase().getScalarVariable(_tid, _to_aux_name); // Ensure that the variable is up to date scalar.reinit(); @@ -108,12 +108,13 @@ MultiAppPostprocessorToAuxScalarTransfer::execute() ")"); // Loop over each sub-app and populate the AuxVariable values from the postprocessors - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) - if (_multi_app->hasLocalApp(i) && _multi_app->isRootProcessor()) + for (unsigned int i = 0; i < _from_multi_app->numGlobalApps(); i++) + if (_from_multi_app->hasLocalApp(i) && _from_multi_app->isRootProcessor()) // Note: This can't be done using MooseScalarVariable::insert() because different // processors will be setting dofs separately. scalar.sys().solution().set( - dof[i], _multi_app->appProblemBase(i).getPostprocessorValueByName(_from_pp_name)); + dof[i], + _from_multi_app->appProblemBase(i).getPostprocessorValueByName(_from_pp_name)); scalar.sys().solution().close(); diff --git a/framework/src/transfers/MultiAppPostprocessorTransfer.C b/framework/src/transfers/MultiAppPostprocessorTransfer.C index 2eead30b96b2..ffe2357b8e3a 100644 --- a/framework/src/transfers/MultiAppPostprocessorTransfer.C +++ b/framework/src/transfers/MultiAppPostprocessorTransfer.C @@ -67,18 +67,18 @@ MultiAppPostprocessorTransfer::execute() { case TO_MULTIAPP: { - FEProblemBase & from_problem = _multi_app->problemBase(); + FEProblemBase & from_problem = _to_multi_app->problemBase(); const Real & pp_value = from_problem.getPostprocessorValueByName(_from_pp_name); - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) - if (_multi_app->hasLocalApp(i)) - _multi_app->appProblemBase(i).setPostprocessorValueByName(_to_pp_name, pp_value); + for (unsigned int i = 0; i < _to_multi_app->numGlobalApps(); i++) + if (_to_multi_app->hasLocalApp(i)) + _to_multi_app->appProblemBase(i).setPostprocessorValueByName(_to_pp_name, pp_value); break; } case FROM_MULTIAPP: { - FEProblemBase & to_problem = _multi_app->problemBase(); + FEProblemBase & to_problem = _from_multi_app->problemBase(); Real reduced_pp_value; switch (_reduction_type) @@ -98,12 +98,14 @@ MultiAppPostprocessorTransfer::execute() "Can't get here unless someone adds a new enum and fails to add it to this switch"); } - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) + const auto multi_app = _from_multi_app ? _from_multi_app : _to_multi_app; + + for (unsigned int i = 0; i < multi_app->numGlobalApps(); i++) { - if (_multi_app->hasLocalApp(i) && _multi_app->isRootProcessor()) + if (multi_app->hasLocalApp(i) && multi_app->isRootProcessor()) { const Real & curr_pp_value = - _multi_app->appProblemBase(i).getPostprocessorValueByName(_from_pp_name); + multi_app->appProblemBase(i).getPostprocessorValueByName(_from_pp_name); switch (_reduction_type) { case AVERAGE: @@ -127,7 +129,7 @@ MultiAppPostprocessorTransfer::execute() { case AVERAGE: _communicator.sum(reduced_pp_value); - reduced_pp_value /= static_cast(_multi_app->numGlobalApps()); + reduced_pp_value /= static_cast(multi_app->numGlobalApps()); break; case SUM: _communicator.sum(reduced_pp_value); diff --git a/framework/src/transfers/MultiAppReporterTransfer.C b/framework/src/transfers/MultiAppReporterTransfer.C index 4f387ad89b51..cc8ff8bdd00d 100644 --- a/framework/src/transfers/MultiAppReporterTransfer.C +++ b/framework/src/transfers/MultiAppReporterTransfer.C @@ -48,15 +48,16 @@ MultiAppReporterTransfer::MultiAppReporterTransfer(const InputParameters & param if (_directions.size() > 1) paramError("direction", "This transfer only supports a single direction."); + const auto multi_app = _from_multi_app ? _from_multi_app : _to_multi_app; // Errors for sub app index. if (_subapp_index != std::numeric_limits::max() && - _subapp_index >= _multi_app->numGlobalApps()) + _subapp_index >= multi_app->numGlobalApps()) paramError( "subapp_index", "The supplied sub-application index is greater than the number of sub-applications."); else if (_directions.contains(FROM_MULTIAPP) && _subapp_index == std::numeric_limits::max() && - _multi_app->numGlobalApps() > 1) + _from_multi_app->numGlobalApps() > 1) paramError("multi_app", "subapp_index must be provided when more than one subapp is present."); } @@ -68,11 +69,12 @@ MultiAppReporterTransfer::initialSetup() // Find proper FEProblem FEProblemBase * problem_ptr = nullptr; if (_directions.contains(TO_MULTIAPP)) - problem_ptr = &_multi_app->problemBase(); - else if (_subapp_index == std::numeric_limits::max() && _multi_app->hasLocalApp(0)) - problem_ptr = &_multi_app->appProblemBase(0); - else if (_multi_app->hasLocalApp(_subapp_index)) - problem_ptr = &_multi_app->appProblemBase(_subapp_index); + problem_ptr = &_to_multi_app->problemBase(); + else if (_subapp_index == std::numeric_limits::max() && + _from_multi_app->hasLocalApp(0)) + problem_ptr = &_from_multi_app->appProblemBase(0); + else if (_from_multi_app->hasLocalApp(_subapp_index)) + problem_ptr = &_from_multi_app->appProblemBase(_subapp_index); // Tell ReporterData to consume with replicated if (problem_ptr) @@ -86,31 +88,31 @@ MultiAppReporterTransfer::executeToMultiapp() std::vector indices; if (_subapp_index == std::numeric_limits::max()) { - indices.resize(_multi_app->numGlobalApps()); + indices.resize(_to_multi_app->numGlobalApps()); std::iota(indices.begin(), indices.end(), 0); } else indices = {_subapp_index}; for (const auto & ind : indices) - if (_multi_app->hasLocalApp(ind)) + if (_to_multi_app->hasLocalApp(ind)) for (unsigned int n = 0; n < _from_reporter_names.size(); ++n) transferReporter(_from_reporter_names[n], _to_reporter_names[n], - _multi_app->problemBase(), - _multi_app->appProblemBase(ind)); + _to_multi_app->problemBase(), + _to_multi_app->appProblemBase(ind)); } void MultiAppReporterTransfer::executeFromMultiapp() { unsigned int ind = _subapp_index != std::numeric_limits::max() ? _subapp_index : 0; - if (_multi_app->hasLocalApp(ind)) + if (_from_multi_app->hasLocalApp(ind)) for (unsigned int n = 0; n < _from_reporter_names.size(); ++n) transferReporter(_from_reporter_names[n], _to_reporter_names[n], - _multi_app->appProblemBase(ind), - _multi_app->problemBase()); + _from_multi_app->appProblemBase(ind), + _from_multi_app->problemBase()); } void diff --git a/framework/src/transfers/MultiAppScalarToAuxScalarTransfer.C b/framework/src/transfers/MultiAppScalarToAuxScalarTransfer.C index 506e75c78c00..8a75156497e8 100644 --- a/framework/src/transfers/MultiAppScalarToAuxScalarTransfer.C +++ b/framework/src/transfers/MultiAppScalarToAuxScalarTransfer.C @@ -61,17 +61,17 @@ MultiAppScalarToAuxScalarTransfer::execute() case TO_MULTIAPP: { // Extract the scalar variable that is being transferred - FEProblemBase & from_problem = _multi_app->problemBase(); + FEProblemBase & from_problem = _to_multi_app->problemBase(); MooseVariableScalar * from_variable = &from_problem.getScalarVariable(_tid, _from_variable_name); // Loop through each of the sub apps - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) - if (_multi_app->hasLocalApp(i)) + for (unsigned int i = 0; i < _to_multi_app->numGlobalApps(); i++) + if (_to_multi_app->hasLocalApp(i)) { // Get reference to the scalar variable that will be written MooseVariableScalar * to_variable = - &_multi_app->appProblemBase(i).getScalarVariable(_tid, _to_aux_name); + &_to_multi_app->appProblemBase(i).getScalarVariable(_tid, _to_aux_name); to_variable->reinit(); @@ -98,7 +98,7 @@ MultiAppScalarToAuxScalarTransfer::execute() { // The AuxVariable that will be read from the subApp MooseVariableScalar * to_variable = - &_multi_app->problemBase().getScalarVariable(_tid, _to_aux_name); + &_from_multi_app->problemBase().getScalarVariable(_tid, _to_aux_name); // Ensure that the variable is up to date to_variable->reinit(); @@ -107,12 +107,12 @@ MultiAppScalarToAuxScalarTransfer::execute() auto && to_dof = to_variable->dofIndices(); // Loop over each sub-app and populate the AuxVariable values - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) + for (unsigned int i = 0; i < _from_multi_app->numGlobalApps(); i++) { - if (_multi_app->hasLocalApp(i) && _multi_app->isRootProcessor()) + if (_from_multi_app->hasLocalApp(i) && _from_multi_app->isRootProcessor()) { // Extract the scalar variable that is being transferred - FEProblemBase & from_problem = _multi_app->appProblemBase(i); + FEProblemBase & from_problem = _from_multi_app->appProblemBase(i); MooseVariableScalar * from_variable = &from_problem.getScalarVariable(_tid, _from_variable_name); diff --git a/framework/src/transfers/MultiAppTransfer.C b/framework/src/transfers/MultiAppTransfer.C index 17c1060c057a..aba90f620d10 100644 --- a/framework/src/transfers/MultiAppTransfer.C +++ b/framework/src/transfers/MultiAppTransfer.C @@ -25,6 +25,9 @@ InputParameters MultiAppTransfer::validParams() { InputParameters params = Transfer::validParams(); + params.addDeprecatedParam("multi_app", + "The name of the MultiApp to transfer data with", + "Use to_multiapp & from_multiapp parameters now"); params.addParam("from_multi_app", "The name of the MultiApp to receive data from"); params.addParam("to_multi_app", "The name of the MultiApp to transfer the data to"); @@ -50,62 +53,103 @@ MultiAppTransfer::validParams() MultiAppTransfer::MultiAppTransfer(const InputParameters & parameters) : Transfer(parameters), - _multi_app(_fe_problem.getMultiApp(getParam("multi_app"))), - _to_multi_app(isParamValid("to_multi_app") - ? _fe_problem.getMultiApp(getParam("to_multi_app")) - : _fe_problem.getMultiApp(getParam("multi_app"))), _displaced_source_mesh(getParam("displaced_source_mesh")), _displaced_target_mesh(getParam("displaced_target_mesh")) { + // Get the multiapps from their names + if (!isParamValid("multi_app")) + { + if (isParamValid("from_multi_app")) + _from_multi_app = _fe_problem.getMultiApp(getParam("from_multi_app")); + if (isParamValid("to_multi_app")) + _to_multi_app = _fe_problem.getMultiApp(getParam("to_multi_app")); + } + else + { + // Check deprecated direction parameter + for (const auto dir : _directions) + { + if (dir == FROM_MULTIAPP) + _from_multi_app = _fe_problem.getMultiApp(getParam("multi_app")); + else + _to_multi_app = _fe_problem.getMultiApp(getParam("multi_app")); + } + } + if (getParam("check_multiapp_execute_on")) checkMultiAppExecuteOn(); - if (_directions.size() == 0) - paramError("direction", "At least one direction is required"); - - // If we have just one direction in _directions, set it now so that it can be used in the - // constructor - if (_directions.size() == 1) + // Fill direction attributes, for backward compatibility but also convenience + if (!isParamValid("direction")) { - int only_direction = _directions.get(0); - _current_direction = only_direction; - _direction = only_direction; + if (_from_multi_app && (!_to_multi_app || _from_multi_app == _to_multi_app)) + _directions.push_back("from_multiapp"); + else if (_to_multi_app && (!_from_multi_app || _from_multi_app == _to_multi_app)) + _directions.push_back("to_multiapp"); + else + _directions.push_back("between_multiapp"); } - for (auto dir : _directions) - if (dir == BETWEEN_MULTIAPP && !isParamValid("to_multi_app")) - paramError("direction", "Need to specify a to_multi_app for a BETWEEN_MULTIAPP direction"); + // Handle deprecated parameters + if (parameters.isParamSetByUser("directions")) + { + if (!isParamValid("multiapp")) + paramError("directions", + "The deprecated directions parameter is meant to be used in conjunction with the " + "multi_app parameter"); + if (isParamValid("to_multiapp") || isParamValid("from_multiapp")) + paramError("directions", + "The deprecated directions parameter is not meant to be used in conjunction with " + "the from_multi_app or to_multi_app parameters"); + } } void MultiAppTransfer::checkMultiAppExecuteOn() { - if (getExecuteOnEnum() != _multi_app->getExecuteOnEnum()) - mooseDoOnce(mooseWarning("MultiAppTransfer execute_on flags do not match associated Multiapp " - "execute_on flags")); - if (getExecuteOnEnum() != _to_multi_app->getExecuteOnEnum()) - mooseDoOnce( - mooseWarning("MultiAppTransfer execute_on flags do not match associated to_Multiapp " - "execute_on flags")); + if (_from_multi_app) + if (getExecuteOnEnum() != _from_multi_app->getExecuteOnEnum()) + mooseDoOnce( + mooseWarning("MultiAppTransfer execute_on flags do not match associated from_multi_app " + "execute_on flags")); + + if (_to_multi_app) + if (getExecuteOnEnum() != _to_multi_app->getExecuteOnEnum()) + mooseDoOnce( + mooseWarning("MultiAppTransfer execute_on flags do not match associated to_multi_app " + "execute_on flags")); } void MultiAppTransfer::variableIntegrityCheck(const AuxVariableName & var_name) const { - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) - if ((_multi_app->hasLocalApp(i) && !_multi_app->appProblemBase(i).hasVariable(var_name)) && - (_to_multi_app && _to_multi_app->hasLocalApp(i) && - !_to_multi_app->appProblemBase(i).hasVariable(var_name))) - mooseError("Cannot find variable ", var_name, " for ", name(), " Transfer"); + bool variable_found = false; + + // Check the from_multi_app for the variable + if (_from_multi_app) + for (unsigned int i = 0; i < _from_multi_app->numGlobalApps(); i++) + if (_from_multi_app->hasLocalApp(i) && + _from_multi_app->appProblemBase(i).hasVariable(var_name)) + variable_found = true; + + // Check the to_multi_app for the variable + if (_to_multi_app) + for (unsigned int i = 0; i < _to_multi_app->numGlobalApps(); i++) + if (_to_multi_app->hasLocalApp(i) && _to_multi_app->appProblemBase(i).hasVariable(var_name)) + variable_found = true; + + if (!variable_found) + mooseError("Cannot find variable ", var_name, " for ", name(), " Transfer"); } const std::vector & MultiAppTransfer::execFlags() const { - mooseDeprecated("The execFlags() methos is being removed because MOOSE has been updated to use a " - "ExecFlagEnum for execute flags. The current flags should be retrieved from " - "the \"exeucte_on\" parameters of your object or by using the \"_execute_enum\" " - "reference to the parameter or the getExecuteOnEnum() method."); + mooseDeprecated( + "The execFlags() methods is being removed because MOOSE has been updated to use a " + "ExecFlagEnum for execute flags. The current flags should be retrieved from " + "the \"exeucte_on\" parameters of your object or by using the \"_execute_enum\" " + "reference to the parameter or the getExecuteOnEnum() method."); return _exec_flags; } @@ -132,58 +176,32 @@ MultiAppTransfer::getAppInfo() _local2global_map.clear(); // Build the vectors for to problems, from problems, and subapps positions. - switch (_direction) + if (_from_multi_app) { - case TO_MULTIAPP: - _from_problems.push_back(&_multi_app->problemBase()); - _from_positions.push_back(Point(0., 0., 0.)); - for (unsigned int i_app = 0; i_app < _multi_app->numGlobalApps(); i_app++) - { - if (!_multi_app->hasLocalApp(i_app)) - continue; - _local2global_map.push_back(i_app); - _to_problems.push_back(&_multi_app->appProblemBase(i_app)); - _to_positions.push_back(_multi_app->position(i_app)); - } - break; - - case FROM_MULTIAPP: - _to_problems.push_back(&_multi_app->problemBase()); - _to_positions.push_back(Point(0., 0., 0.)); - for (unsigned int i_app = 0; i_app < _multi_app->numGlobalApps(); i_app++) - { - if (!_multi_app->hasLocalApp(i_app)) - continue; - _local2global_map.push_back(i_app); - _from_problems.push_back(&_multi_app->appProblemBase(i_app)); - _from_positions.push_back(_multi_app->position(i_app)); - } - break; - - case BETWEEN_MULTIAPP: - _to_problems.push_back(&_multi_app->problemBase()); - _to_positions.push_back(Point(0., 0., 0.)); - for (unsigned int i_app = 0; i_app < _multi_app->numGlobalApps(); i_app++) - { - if (!_multi_app->hasLocalApp(i_app)) - continue; - for (unsigned int j_app = 0; j_app < _multi_app->numGlobalApps(); j_app++) - { - if (!_multi_app->hasLocalApp(i_app)) - continue; - - if (i_app == j_app) - continue; - - _local2global_map.push_back(i_app); - _from_problems.push_back(&_multi_app->appProblemBase(i_app)); - _from_positions.push_back(_multi_app->position(i_app)); + _to_problems.push_back(&_from_multi_app->problemBase()); + _to_positions.push_back(Point(0., 0., 0.)); + for (unsigned int i_app = 0; i_app < _from_multi_app->numGlobalApps(); i_app++) + { + if (!_from_multi_app->hasLocalApp(i_app)) + continue; + _local2global_map.push_back(i_app); + _from_problems.push_back(&_from_multi_app->appProblemBase(i_app)); + _from_positions.push_back(_from_multi_app->position(i_app)); + } + } - _to_problems.push_back(&_multi_app->appProblemBase(j_app)); - _to_positions.push_back(_multi_app->position(j_app)); - } - } - break; + if (_to_multi_app) + { + _from_problems.push_back(&_to_multi_app->problemBase()); + _from_positions.push_back(Point(0., 0., 0.)); + for (unsigned int i_app = 0; i_app < _to_multi_app->numGlobalApps(); i_app++) + { + if (!_to_multi_app->hasLocalApp(i_app)) + continue; + _local2global_map.push_back(i_app); + _to_problems.push_back(&_to_multi_app->appProblemBase(i_app)); + _to_positions.push_back(_to_multi_app->position(i_app)); + } } // Build the from and to equation systems and mesh vectors. @@ -297,19 +315,12 @@ std::vector MultiAppTransfer::getFromsPerProc() { std::vector froms_per_proc; - switch (_direction) + if (_to_multi_app) + froms_per_proc.resize(n_processors(), 1); + if (_from_multi_app) { - case TO_MULTIAPP: - froms_per_proc.resize(n_processors(), 1); - break; - case FROM_MULTIAPP: - froms_per_proc.resize(n_processors()); - _communicator.allgather(_multi_app->numLocalApps(), froms_per_proc); - break; - case BETWEEN_MULTIAPP: - froms_per_proc.resize(n_processors()); - _communicator.allgather(_multi_app->numLocalApps(), froms_per_proc); - break; + froms_per_proc.resize(n_processors()); + _communicator.allgather(_from_multi_app->numLocalApps(), froms_per_proc); } return froms_per_proc; } @@ -317,9 +328,9 @@ MultiAppTransfer::getFromsPerProc() NumericVector & MultiAppTransfer::getTransferVector(unsigned int i_local, std::string var_name) { - mooseAssert(_direction == TO_MULTIAPP, "getTransferVector only works for transfers to multiapps"); + mooseAssert(!_from_multi_app, "getTransferVector only works for transfers to multiapps"); - return _multi_app->appTransferVector(_local2global_map[i_local], var_name); + return _to_multi_app->appTransferVector(_local2global_map[i_local], var_name); } void diff --git a/framework/src/transfers/MultiAppUserObjectTransfer.C b/framework/src/transfers/MultiAppUserObjectTransfer.C index 0e4608e340d0..3267373ee349 100644 --- a/framework/src/transfers/MultiAppUserObjectTransfer.C +++ b/framework/src/transfers/MultiAppUserObjectTransfer.C @@ -95,26 +95,26 @@ MultiAppUserObjectTransfer::execute() { case TO_MULTIAPP: { - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) + for (unsigned int i = 0; i < _to_multi_app->numGlobalApps(); i++) { - if (_multi_app->hasLocalApp(i)) + if (_to_multi_app->hasLocalApp(i)) { - Moose::ScopedCommSwapper swapper(_multi_app->comm()); + Moose::ScopedCommSwapper swapper(_to_multi_app->comm()); // Loop over the master nodes and set the value of the variable - System * to_sys = find_sys(_multi_app->appProblemBase(i).es(), _to_var_name); + System * to_sys = find_sys(_to_multi_app->appProblemBase(i).es(), _to_var_name); unsigned int sys_num = to_sys->number(); unsigned int var_num = to_sys->variable_number(_to_var_name); - NumericVector & solution = _multi_app->appTransferVector(i, _to_var_name); + NumericVector & solution = _to_multi_app->appTransferVector(i, _to_var_name); MooseMesh * mesh = NULL; - if (_displaced_target_mesh && _multi_app->appProblemBase(i).getDisplacedProblem()) - mesh = &_multi_app->appProblemBase(i).getDisplacedProblem()->mesh(); + if (_displaced_target_mesh && _to_multi_app->appProblemBase(i).getDisplacedProblem()) + mesh = &_to_multi_app->appProblemBase(i).getDisplacedProblem()->mesh(); else - mesh = &_multi_app->appProblemBase(i).mesh(); + mesh = &_to_multi_app->appProblemBase(i).mesh(); _blk_ids.clear(); _bnd_ids.clear(); @@ -141,7 +141,7 @@ MultiAppUserObjectTransfer::execute() mooseError("We don't currently support second order or higher elemental variable "); const UserObject & user_object = - _multi_app->problemBase().getUserObjectBase(_user_object_name); + _to_multi_app->problemBase().getUserObjectBase(_user_object_name); if (is_nodal) { @@ -159,7 +159,7 @@ MultiAppUserObjectTransfer::execute() dof_id_type dof = node->dof_number(sys_num, var_num, 0); swapper.forceSwap(); - Real from_value = user_object.spatialValue(*node + _multi_app->position(i)); + Real from_value = user_object.spatialValue(*node + _to_multi_app->position(i)); swapper.forceSwap(); solution.set(dof, from_value); @@ -208,7 +208,7 @@ MultiAppUserObjectTransfer::execute() dof_id_type dof = elem->dof_number(sys_num, var_num, offset++); swapper.forceSwap(); - Real from_value = user_object.spatialValue(point + _multi_app->position(i)); + Real from_value = user_object.spatialValue(point + _to_multi_app->position(i)); swapper.forceSwap(); solution.set(dof, from_value); @@ -225,7 +225,7 @@ MultiAppUserObjectTransfer::execute() } case FROM_MULTIAPP: { - FEProblemBase & to_problem = _multi_app->problemBase(); + FEProblemBase & to_problem = _from_multi_app->problemBase(); MooseVariableFEBase & to_var = to_problem.getVariable( 0, _to_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD); SystemBase & to_system_base = to_var.sys(); @@ -294,12 +294,12 @@ MultiAppUserObjectTransfer::execute() if (node->n_dofs(to_sys_num, to_var_num) > 0) { unsigned int node_found_in_sub_app = 0; - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) + for (unsigned int i = 0; i < _from_multi_app->numGlobalApps(); i++) { - if (!_multi_app->hasLocalApp(i)) + if (!_from_multi_app->hasLocalApp(i)) continue; - BoundingBox app_box = _multi_app->getBoundingBox(i, _displaced_source_mesh); + BoundingBox app_box = _from_multi_app->getBoundingBox(i, _displaced_source_mesh); if (app_box.contains_point(*node)) ++node_found_in_sub_app; @@ -362,12 +362,12 @@ MultiAppUserObjectTransfer::execute() { unsigned int elem_found_in_sub_app = 0; - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) + for (unsigned int i = 0; i < _from_multi_app->numGlobalApps(); i++) { - if (!_multi_app->hasLocalApp(i)) + if (!_from_multi_app->hasLocalApp(i)) continue; - BoundingBox app_box = _multi_app->getBoundingBox(i, _displaced_source_mesh); + BoundingBox app_box = _from_multi_app->getBoundingBox(i, _displaced_source_mesh); if (app_box.contains_point(point)) ++elem_found_in_sub_app; @@ -391,14 +391,14 @@ MultiAppUserObjectTransfer::execute() } } - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) + for (unsigned int i = 0; i < _from_multi_app->numGlobalApps(); i++) { - if (!_multi_app->hasLocalApp(i)) + if (!_from_multi_app->hasLocalApp(i)) continue; - Point app_position = _multi_app->position(i); - BoundingBox app_box = _multi_app->getBoundingBox(i, _displaced_source_mesh); - const UserObject & user_object = _multi_app->appUserObjectBase(i, _user_object_name); + Point app_position = _from_multi_app->position(i); + BoundingBox app_box = _from_multi_app->getBoundingBox(i, _displaced_source_mesh); + const UserObject & user_object = _from_multi_app->appUserObjectBase(i, _user_object_name); if (is_nodal) { @@ -419,7 +419,7 @@ MultiAppUserObjectTransfer::execute() Real from_value = 0; { - Moose::ScopedCommSwapper swapper(_multi_app->comm()); + Moose::ScopedCommSwapper swapper(_from_multi_app->comm()); from_value = user_object.spatialValue(*node - app_position); } @@ -481,7 +481,7 @@ MultiAppUserObjectTransfer::execute() Real from_value = 0; { - Moose::ScopedCommSwapper swapper(_multi_app->comm()); + Moose::ScopedCommSwapper swapper(_from_multi_app->comm()); from_value = user_object.spatialValue(point - app_position); } diff --git a/framework/src/transfers/MultiAppVariableValueSamplePostprocessorTransfer.C b/framework/src/transfers/MultiAppVariableValueSamplePostprocessorTransfer.C index aa5ca52f508c..091f3857cffc 100644 --- a/framework/src/transfers/MultiAppVariableValueSamplePostprocessorTransfer.C +++ b/framework/src/transfers/MultiAppVariableValueSamplePostprocessorTransfer.C @@ -58,7 +58,7 @@ MultiAppVariableValueSamplePostprocessorTransfer::execute() { case TO_MULTIAPP: { - FEProblemBase & from_problem = _multi_app->problemBase(); + FEProblemBase & from_problem = _to_multi_app->problemBase(); MooseVariableField & from_var = static_cast &>( from_problem.getActualFieldVariable(0, _from_var_name)); SystemBase & from_system_base = from_var.sys(); @@ -70,13 +70,13 @@ MultiAppVariableValueSamplePostprocessorTransfer::execute() pl->enable_out_of_mesh_mode(); - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) + for (unsigned int i = 0; i < _to_multi_app->numGlobalApps(); i++) { Real value = -std::numeric_limits::max(); { // Get the value of the variable at the point where this multiapp is in the master domain - Point multi_app_position = _multi_app->position(i); + Point multi_app_position = _to_multi_app->position(i); std::vector point_vec(1, multi_app_position); @@ -95,8 +95,8 @@ MultiAppVariableValueSamplePostprocessorTransfer::execute() _communicator.max(value); } - if (_multi_app->hasLocalApp(i)) - _multi_app->appProblemBase(i).setPostprocessorValueByName(_postprocessor_name, value); + if (_to_multi_app->hasLocalApp(i)) + _to_multi_app->appProblemBase(i).setPostprocessorValueByName(_postprocessor_name, value); } break; diff --git a/framework/src/transfers/MultiAppVariableValueSampleTransfer.C b/framework/src/transfers/MultiAppVariableValueSampleTransfer.C index ab85ac29afec..5ef2f29514c1 100644 --- a/framework/src/transfers/MultiAppVariableValueSampleTransfer.C +++ b/framework/src/transfers/MultiAppVariableValueSampleTransfer.C @@ -44,7 +44,7 @@ MultiAppVariableValueSampleTransfer::MultiAppVariableValueSampleTransfer( _to_var_name(getParam("variable")), _from_var_name(getParam("source_variable")) { - if (_directions.size() != 1) + if (_directions.size() != 1 || (isParamValid("from_multiapp") && isParamValid("to_multiapp"))) paramError("direction", "This transfer is only unidirectional"); } @@ -53,7 +53,12 @@ MultiAppVariableValueSampleTransfer::initialSetup() { variableIntegrityCheck(_to_var_name); - _multi_app->problemBase().mesh().errorIfDistributedMesh("MultiAppVariableValueSampleTransfer"); + if (isParamValid("from_multiapp")) + _from_multi_app->problemBase().mesh().errorIfDistributedMesh( + "MultiAppVariableValueSampleTransfer"); + if (isParamValid("to_multiapp")) + _to_multi_app->problemBase().mesh().errorIfDistributedMesh( + "MultiAppVariableValueSampleTransfer"); } void @@ -65,7 +70,7 @@ MultiAppVariableValueSampleTransfer::execute() { case TO_MULTIAPP: { - FEProblemBase & from_problem = _multi_app->problemBase(); + FEProblemBase & from_problem = _to_multi_app->problemBase(); MooseVariableField & from_var = static_cast &>( from_problem.getActualFieldVariable(0, _from_var_name)); SystemBase & from_system_base = from_var.sys(); @@ -75,13 +80,13 @@ MultiAppVariableValueSampleTransfer::execute() std::unique_ptr pl = from_mesh.getPointLocator(); - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++) + for (unsigned int i = 0; i < _to_multi_app->numGlobalApps(); i++) { Real value = -std::numeric_limits::max(); { // Get the value of the variable at the point where this multiapp is in the master domain - Point multi_app_position = _multi_app->position(i); + Point multi_app_position = _to_multi_app->position(i); std::vector point_vec(1, multi_app_position); @@ -103,19 +108,19 @@ MultiAppVariableValueSampleTransfer::execute() mooseError("Transfer failed to sample point value at point: ", multi_app_position); } - if (_multi_app->hasLocalApp(i)) + if (_to_multi_app->hasLocalApp(i)) { - Moose::ScopedCommSwapper swapper(_multi_app->comm()); + Moose::ScopedCommSwapper swapper(_to_multi_app->comm()); // Loop over the master nodes and set the value of the variable - System * to_sys = find_sys(_multi_app->appProblemBase(i).es(), _to_var_name); + System * to_sys = find_sys(_to_multi_app->appProblemBase(i).es(), _to_var_name); unsigned int sys_num = to_sys->number(); unsigned int var_num = to_sys->variable_number(_to_var_name); - NumericVector & solution = _multi_app->appTransferVector(i, _to_var_name); + NumericVector & solution = _to_multi_app->appTransferVector(i, _to_var_name); - MooseMesh & mesh = _multi_app->appProblemBase(i).mesh(); + MooseMesh & mesh = _to_multi_app->appProblemBase(i).mesh(); for (const auto & node : as_range(mesh.localNodesBegin(), mesh.localNodesEnd())) { @@ -128,7 +133,7 @@ MultiAppVariableValueSampleTransfer::execute() } } solution.close(); - _multi_app->appProblemBase(i).es().update(); + _to_multi_app->appProblemBase(i).es().update(); } } diff --git a/framework/src/transfers/MultiAppVectorPostprocessorTransfer.C b/framework/src/transfers/MultiAppVectorPostprocessorTransfer.C index f4d733f26fb3..881aaf117578 100644 --- a/framework/src/transfers/MultiAppVectorPostprocessorTransfer.C +++ b/framework/src/transfers/MultiAppVectorPostprocessorTransfer.C @@ -57,44 +57,46 @@ void MultiAppVectorPostprocessorTransfer::executeToMultiapp() { const VectorPostprocessorValue & vpp = - _multi_app->problemBase().getVectorPostprocessorValueByName(_master_vpp_name, _vector_name); + _to_multi_app->problemBase().getVectorPostprocessorValueByName(_master_vpp_name, + _vector_name); - if (vpp.size() != _multi_app->numGlobalApps()) + if (vpp.size() != _to_multi_app->numGlobalApps()) mooseError("VectorPostprocessor ", _master_vpp_name, " and number of sub-apps do not match: ", vpp.size(), "/", - _multi_app->numGlobalApps()); + _to_multi_app->numGlobalApps()); - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); ++i) - if (_multi_app->hasLocalApp(i)) - _multi_app->appProblemBase(i).setPostprocessorValueByName(_sub_pp_name, vpp[i]); + for (unsigned int i = 0; i < _to_multi_app->numGlobalApps(); ++i) + if (_to_multi_app->hasLocalApp(i)) + _to_multi_app->appProblemBase(i).setPostprocessorValueByName(_sub_pp_name, vpp[i]); } void MultiAppVectorPostprocessorTransfer::executeFromMultiapp() { const VectorPostprocessorValue & vpp = - _multi_app->problemBase().getVectorPostprocessorValueByName(_master_vpp_name, _vector_name); + _from_multi_app->problemBase().getVectorPostprocessorValueByName(_master_vpp_name, + _vector_name); - if (vpp.size() != _multi_app->numGlobalApps()) + if (vpp.size() != _from_multi_app->numGlobalApps()) mooseError("VectorPostprocessor ", _master_vpp_name, " and number of sub-apps do not match: ", vpp.size(), "/", - _multi_app->numGlobalApps()); + _from_multi_app->numGlobalApps()); - VectorPostprocessorValue value(_multi_app->numGlobalApps(), 0.0); - for (unsigned int i = 0; i < _multi_app->numGlobalApps(); ++i) - if (_multi_app->hasLocalApp(i)) - value[i] = _multi_app->appProblemBase(i).getPostprocessorValueByName(_sub_pp_name); + VectorPostprocessorValue value(_from_multi_app->numGlobalApps(), 0.0); + for (unsigned int i = 0; i < _from_multi_app->numGlobalApps(); ++i) + if (_from_multi_app->hasLocalApp(i)) + value[i] = _from_multi_app->appProblemBase(i).getPostprocessorValueByName(_sub_pp_name); for (auto & v : value) _communicator.sum(v); - _multi_app->problemBase().setVectorPostprocessorValueByName( + _from_multi_app->problemBase().setVectorPostprocessorValueByName( _master_vpp_name, _vector_name, value); } diff --git a/framework/src/transfers/Transfer.C b/framework/src/transfers/Transfer.C index 2b6da906520b..d0203f46065d 100644 --- a/framework/src/transfers/Transfer.C +++ b/framework/src/transfers/Transfer.C @@ -38,7 +38,7 @@ Transfer::validParams() params += SetupInterface::validParams(); params.set("execute_on", true) = EXEC_TIMESTEP_BEGIN; - MultiMooseEnum possible_directions(Transfer::possibleDirections()); + MultiMooseEnum possible_directions(Transfer::possibleDirections(), ""); params.addDeprecatedParam( "direction", possible_directions, @@ -63,9 +63,9 @@ Transfer::Transfer(const InputParameters & parameters) _tid(parameters.get("_tid")), _direction(possibleDirections()), _current_direction(possibleDirections()), - _directions(isParamValid ? getParam("direction") : {}) + _directions(getParam("direction")) { - if (_directions.size() == 0) + if (parameters.isParamSetByUser("direction") && _directions.size() == 0) paramError("direction", "At least one direction is required"); // If we have just one direction in _directions, set it now so that it can be used in the diff --git a/test/tests/transfers/multiapp_copy_transfer/between_multiapps/main.i b/test/tests/transfers/multiapp_copy_transfer/between_multiapps/main.i index b319ab46c539..4ac2de75a109 100644 --- a/test/tests/transfers/multiapp_copy_transfer/between_multiapps/main.i +++ b/test/tests/transfers/multiapp_copy_transfer/between_multiapps/main.i @@ -20,7 +20,7 @@ [Transfers/from_sub1_to_sub2] type = MultiAppCopyTransfer direction = between_multiapp - multi_app = sub1 + from_multi_app = sub1 to_multi_app = sub2 source_variable = x1 variable = x2