Skip to content

Commit

Permalink
Switch parameter to to_multiapp from_multiapp
Browse files Browse the repository at this point in the history
  • Loading branch information
GiudGiud committed Feb 18, 2022
1 parent 5eb5c61 commit 3ed5525
Show file tree
Hide file tree
Showing 19 changed files with 322 additions and 282 deletions.
14 changes: 11 additions & 3 deletions framework/include/transfers/MultiAppTransfer.h
Expand Up @@ -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<MultiApp> getMultiApp() const { return _multi_app; }
const std::shared_ptr<MultiApp> 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<ExecFlagType> & execFlags() const;

protected:
/// The MultiApp this Transfer is transferring data to or from
std::shared_ptr<MultiApp> _multi_app;
/// The MultiApps this Transfer is transferring data to or from
std::shared_ptr<MultiApp> _from_multi_app;
std::shared_ptr<MultiApp> _to_multi_app;

/**
Expand Down
2 changes: 1 addition & 1 deletion framework/include/transfers/Transfer.h
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions framework/src/problems/FEProblemBase.C
Expand Up @@ -4226,9 +4226,9 @@ FEProblemBase::execMultiAppTransfers(ExecFlagType type, Transfer::DIRECTION dire
else
string_direction = " between ";

const MooseObjectWarehouse<Transfer> & wh =
to_multiapp ? _to_multi_app_transfers[type]
: from_multiapp ? _from_multi_app_transfers[type] : _between_multi_app_transfers;
const MooseObjectWarehouse<Transfer> & wh = to_multiapp ? _to_multi_app_transfers[type]
: from_multiapp ? _from_multi_app_transfers[type]
: _between_multi_app_transfers;

if (wh.hasActiveObjects())
{
Expand Down
51 changes: 28 additions & 23 deletions framework/src/transfers/MultiAppCloneReporterTransfer.C
Expand Up @@ -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.");
Expand All @@ -68,31 +73,32 @@ MultiAppCloneReporterTransfer::initialSetup()
if (!dynamic_cast<const Reporter *>(&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;
}
Expand All @@ -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
Expand All @@ -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());
}
}

Expand Down
54 changes: 28 additions & 26 deletions framework/src/transfers/MultiAppConservativeTransfer.C
Expand Up @@ -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 "
Expand All @@ -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",
Expand Down Expand Up @@ -114,43 +114,45 @@ 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<const NearestPointIntegralVariablePostprocessor *>(
&(from_problem.getUserObjectBase(_from_postprocessors_to_be_preserved[0])));
if (pps)
_use_nearestpoint_pps = true;
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<const NearestPointIntegralVariablePostprocessor *>(
&(to_problem.getUserObjectBase(_to_postprocessors_to_be_preserved[0])));
if (pps)
_use_nearestpoint_pps = true;
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<PostprocessorName> pps_empty;
// PPs for master app
auto & master_pps =
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions framework/src/transfers/MultiAppCopyTransfer.C
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 3ed5525

Please sign in to comment.