Skip to content

Commit

Permalink
Update modules' transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
GiudGiud committed Feb 19, 2022
1 parent 3ed5525 commit 65aec0c
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 68 deletions.
Expand Up @@ -50,23 +50,25 @@ MultiAppFXTransfer::MultiAppFXTransfer(const InputParameters & parameters)
void
MultiAppFXTransfer::initialSetup()
{
const auto multi_app = _from_multi_app ? _from_multi_app : _to_multi_app;

// Search for the _this_app_object_name in the LocalApp
getMultiAppObject =
scanProblemBaseForObject(_multi_app->problemBase(), _this_app_object_name, "MultiApp");
scanProblemBaseForObject(multi_app->problemBase(), _this_app_object_name, "MultiApp");
if (getMultiAppObject == NULL)
mooseError(
"Transfer '", name(), "': Cannot find object '", _this_app_object_name, "' in MultiApp");

// Search for the _multi_app_object_name in each of the MultiApps
for (std::size_t i = 0; i < _multi_app->numGlobalApps(); ++i)
if (_multi_app->hasLocalApp(i))
for (std::size_t i = 0; i < multi_app->numGlobalApps(); ++i)
if (multi_app->hasLocalApp(i))
{
if (i == 0) // First time through, assign without checking against previous values
getSubAppObject = scanProblemBaseForObject(
_multi_app->appProblemBase(i), _multi_app_object_name, _multi_app->name());
else if (getSubAppObject != scanProblemBaseForObject(_multi_app->appProblemBase(i),
multi_app->appProblemBase(i), _multi_app_object_name, multi_app->name());
else if (getSubAppObject != scanProblemBaseForObject(multi_app->appProblemBase(i),
_multi_app_object_name,
_multi_app->name()))
multi_app->name()))
mooseError("The name '",
_multi_app_object_name,
"' is assigned to two different object types. Please modify your input file and "
Expand Down Expand Up @@ -164,16 +166,16 @@ MultiAppFXTransfer::execute()
{
// Get a reference to the object in the LocalApp
const MutableCoefficientsInterface & from_object =
(this->*getMultiAppObject)(_multi_app->problemBase(), _this_app_object_name, 0);
(this->*getMultiAppObject)(_to_multi_app->problemBase(), _this_app_object_name, 0);

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))
for (THREAD_ID t = 0; t < libMesh::n_threads(); ++t)
{
// Get a reference to the object in each MultiApp
MutableCoefficientsInterface & to_object =
(this->*getSubAppObject)(_multi_app->appProblemBase(i), _multi_app_object_name, t);
MutableCoefficientsInterface & to_object = (this->*getSubAppObject)(
_to_multi_app->appProblemBase(i), _multi_app_object_name, t);

if (to_object.isCompatibleWith(from_object))
to_object.importCoefficients(from_object);
Expand All @@ -196,17 +198,17 @@ MultiAppFXTransfer::execute()
* among all instances, thus we only need to grab the set of coefficients from the first
* SubApp.
*/
if (_multi_app->hasLocalApp(0))
if (_from_multi_app->hasLocalApp(0))
{
// Get a reference to the first thread object in the first MultiApp
const MutableCoefficientsInterface & from_object =
(this->*getSubAppObject)(_multi_app->appProblemBase(0), _multi_app_object_name, 0);
(this->*getSubAppObject)(_from_multi_app->appProblemBase(0), _multi_app_object_name, 0);

for (THREAD_ID t = 0; t < libMesh::n_threads(); ++t)
{
// Get a reference to the object in each LocalApp instance
MutableCoefficientsInterface & to_object =
(this->*getMultiAppObject)(_multi_app->problemBase(), _this_app_object_name, t);
(this->*getMultiAppObject)(_from_multi_app->problemBase(), _this_app_object_name, t);

if (to_object.isCompatibleWith(from_object))
to_object.importCoefficients(from_object);
Expand Down
14 changes: 7 additions & 7 deletions modules/level_set/src/transfers/LevelSetMeshRefinementTransfer.C
Expand Up @@ -45,11 +45,11 @@ LevelSetMeshRefinementTransfer::LevelSetMeshRefinementTransfer(const InputParame
void
LevelSetMeshRefinementTransfer::initialSetup()
{
FEProblemBase & from_problem = _multi_app->problemBase();
for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
if (_multi_app->hasLocalApp(i))
FEProblemBase & from_problem = _to_multi_app->problemBase();
for (unsigned int i = 0; i < _to_multi_app->numGlobalApps(); i++)
if (_to_multi_app->hasLocalApp(i))
{
FEProblemBase & to_problem = _multi_app->appProblemBase(i);
FEProblemBase & to_problem = _to_multi_app->appProblemBase(i);
MooseVariable & to_var = to_problem.getStandardVariable(0, _to_var_name);
Adaptivity & adapt = to_problem.adaptivity();
adapt.setMarkerVariableName(to_var.name());
Expand All @@ -69,10 +69,10 @@ LevelSetMeshRefinementTransfer::execute()

else if (_current_execute_flag == LevelSet::EXEC_ADAPT_MESH)
{
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))
{
FEProblemBase & to_problem = _multi_app->appProblemBase(i);
FEProblemBase & to_problem = _to_multi_app->appProblemBase(i);
Adaptivity & adapt = to_problem.adaptivity();
adapt.setAdaptivityOn(true);
to_problem.adaptMesh();
Expand Down
4 changes: 2 additions & 2 deletions modules/stochastic_tools/src/transfers/PODResidualTransfer.C
Expand Up @@ -36,7 +36,7 @@ PODResidualTransfer::execute()

// Looping over sub-apps
for (unsigned int base_i = 0; base_i < total_base_num; ++base_i)
if (_multi_app->hasLocalApp(base_i))
if (_from_multi_app->hasLocalApp(base_i))
transferResidual(base_i, base_i);
}

Expand All @@ -54,7 +54,7 @@ PODResidualTransfer::transferResidual(dof_id_type base_i, dof_id_type multi_app_
const std::vector<std::string> & tag_types = _trainer.getTagTypes();

// Getting reference to the non-linear system
FEProblemBase & app_problem = _multi_app->appProblemBase(multi_app_i);
FEProblemBase & app_problem = _from_multi_app->appProblemBase(multi_app_i);
NonlinearSystemBase & nl = app_problem.getNonlinearSystemBase();

// Looping over the residual tags and extracting the corresponding vector.
Expand Down
26 changes: 15 additions & 11 deletions modules/stochastic_tools/src/transfers/PODSamplerSolutionTransfer.C
Expand Up @@ -29,7 +29,9 @@ PODSamplerSolutionTransfer::validParams()
PODSamplerSolutionTransfer::PODSamplerSolutionTransfer(const InputParameters & parameters)
: StochasticToolsTransfer(parameters),
SurrogateModelInterface(this),
_pod_multi_app(std::dynamic_pointer_cast<PODFullSolveMultiApp>(_multi_app)),
_pod_multi_app(_from_multi_app
? std::dynamic_pointer_cast<PODFullSolveMultiApp>(_from_multi_app)
: std::dynamic_pointer_cast<PODFullSolveMultiApp>(_to_multi_app)),
_trainer(getSurrogateTrainer<PODReducedBasisTrainer>("trainer_name"))
{
if (!_pod_multi_app)
Expand All @@ -39,14 +41,16 @@ PODSamplerSolutionTransfer::PODSamplerSolutionTransfer(const InputParameters & p
void
PODSamplerSolutionTransfer::initialSetup()
{
const auto multi_app = _from_multi_app ? _from_multi_app : _to_multi_app;

// Checking if the subapplication has the requested variables
const std::vector<std::string> & var_names = _trainer.getVarNames();
const dof_id_type n = _multi_app->numGlobalApps();
const dof_id_type n = multi_app->numGlobalApps();
for (MooseIndex(n) i = 0; i < n; i++)
{
if (_multi_app->hasLocalApp(i))
if (multi_app->hasLocalApp(i))
for (auto var_name : var_names)
if (!_multi_app->appProblemBase(i).hasVariable(var_name))
if (!multi_app->appProblemBase(i).hasVariable(var_name))
mooseError("Variable '" + var_name + "' not found on sub-application ", i, "!");
}
}
Expand All @@ -67,7 +71,7 @@ PODSamplerSolutionTransfer::execute()
++i)
{
// Getting reference to the solution vector of the sub-app.
FEProblemBase & app_problem = _multi_app->appProblemBase(i);
FEProblemBase & app_problem = _from_multi_app->appProblemBase(i);
NonlinearSystemBase & nl = app_problem.getNonlinearSystemBase();
NumericVector<Number> & solution = nl.solution();

Expand Down Expand Up @@ -101,10 +105,10 @@ PODSamplerSolutionTransfer::execute()
unsigned int var_base_num = _trainer.getBaseSize(var_i);
for (unsigned int base_i = 0; base_i < var_base_num; ++base_i)
{
if (_multi_app->hasLocalApp(counter))
if (_to_multi_app->hasLocalApp(counter))
{
// Getting the reference to the solution vector in the subapp.
FEProblemBase & app_problem = _multi_app->appProblemBase(counter);
FEProblemBase & app_problem = _to_multi_app->appProblemBase(counter);
NonlinearSystemBase & nl = app_problem.getNonlinearSystemBase();
NumericVector<Number> & solution = nl.solution();

Expand Down Expand Up @@ -144,14 +148,14 @@ PODSamplerSolutionTransfer::executeFromMultiapp()
{
const std::vector<std::string> & var_names = _trainer.getVarNames();

const dof_id_type n = _multi_app->numGlobalApps();
const dof_id_type n = _from_multi_app->numGlobalApps();

for (MooseIndex(n) i = 0; i < n; i++)
{
if (_multi_app->hasLocalApp(i))
if (_from_multi_app->hasLocalApp(i))
{
// Getting reference to the solution vector of the sub-app.
FEProblemBase & app_problem = _multi_app->appProblemBase(i);
FEProblemBase & app_problem = _from_multi_app->appProblemBase(i);
NonlinearSystemBase & nl = app_problem.getNonlinearSystemBase();
NumericVector<Number> & solution = nl.solution();

Expand Down Expand Up @@ -194,7 +198,7 @@ PODSamplerSolutionTransfer::executeToMultiapp()
dof_id_type var_i = _trainer.getVariableIndex(_global_index);

// Getting the reference to the solution vector in the subapp.
FEProblemBase & app_problem = _multi_app->appProblemBase(processor_id());
FEProblemBase & app_problem = _to_multi_app->appProblemBase(processor_id());
NonlinearSystemBase & nl = app_problem.getNonlinearSystemBase();
NumericVector<Number> & solution = nl.solution();

Expand Down
Expand Up @@ -49,15 +49,15 @@ void
SamplerParameterTransfer::execute()
{
mooseAssert((_sampler_ptr->getNumberOfLocalRows() == 0) ||
(_sampler_ptr->getNumberOfLocalRows() == _multi_app->numLocalApps()),
(_sampler_ptr->getNumberOfLocalRows() == _to_multi_app->numLocalApps()),
"The number of MultiApps and the number of sample rows must be the same.");

// Loop over all sub-apps
for (dof_id_type row_index = _sampler_ptr->getLocalRowBegin();
row_index < _sampler_ptr->getLocalRowEnd();
row_index++)
{
mooseAssert(_multi_app->hasLocalApp(row_index),
mooseAssert(_to_multi_app->hasLocalApp(row_index),
"The current sample row index is not a valid global MultiApp index.");

// Get the sub-app SamplerReceiver object and perform error checking
Expand All @@ -74,7 +74,7 @@ SamplerParameterTransfer::execute()
void
SamplerParameterTransfer::executeToMultiapp()
{
if (_multi_app->isRootProcessor())
if (_to_multi_app->isRootProcessor())
{
SamplerReceiver * ptr = getReceiver(_app_index);
ptr->transfer(_parameter_names, _row_data);
Expand All @@ -85,11 +85,11 @@ SamplerReceiver *
SamplerParameterTransfer::getReceiver(unsigned int app_index)
{
// Test that the sub-application has the given Control object
FEProblemBase & to_problem = _multi_app->appProblemBase(app_index);
FEProblemBase & to_problem = _to_multi_app->appProblemBase(app_index);
ExecuteMooseObjectWarehouse<Control> & control_wh = to_problem.getControlWarehouse();
if (!control_wh.hasActiveObject(_receiver_name))
mooseError("The sub-application (",
_multi_app->name(),
_to_multi_app->name(),
") does not contain a Control object with the name '",
_receiver_name,
"'.");
Expand All @@ -100,7 +100,7 @@ SamplerParameterTransfer::getReceiver(unsigned int app_index)
if (!ptr)
mooseError(
"The sub-application (",
_multi_app->name(),
_to_multi_app->name(),
") Control object for the 'to_control' parameter must be of type 'SamplerReceiver'.");

return ptr;
Expand Down
Expand Up @@ -87,18 +87,18 @@ SamplerPostprocessorTransfer::initialSetup()
mooseError("The 'results' object must be a 'StochasticResults' object.");

// Check that postprocessor on sub-application exists and create vectors on results VPP
const dof_id_type n = _multi_app->numGlobalApps();
const dof_id_type n = _from_multi_app->numGlobalApps();
for (MooseIndex(n) i = 0; i < n; i++)
{
if (_multi_app->hasLocalApp(i))
if (_from_multi_app->hasLocalApp(i))
{
FEProblemBase & app_problem = _multi_app->appProblemBase(i);
FEProblemBase & app_problem = _from_multi_app->appProblemBase(i);
for (const auto & sub_pp_name : _sub_pp_names)
if (!app_problem.hasPostprocessorValueByName(sub_pp_name))
mooseError("Unknown postprocesssor name '",
sub_pp_name,
"' on sub-application '",
_multi_app->name(),
_from_multi_app->name(),
"'");
}
}
Expand All @@ -120,14 +120,14 @@ SamplerPostprocessorTransfer::initializeFromMultiapp()
void
SamplerPostprocessorTransfer::executeFromMultiapp()
{
if (_multi_app->isRootProcessor())
if (_from_multi_app->isRootProcessor())
{
const dof_id_type n = _multi_app->numGlobalApps();
const dof_id_type n = _from_multi_app->numGlobalApps();
for (MooseIndex(n) i = 0; i < n; i++)
{
if (_multi_app->hasLocalApp(i))
if (_from_multi_app->hasLocalApp(i))
{
FEProblemBase & app_problem = _multi_app->appProblemBase(i);
FEProblemBase & app_problem = _from_multi_app->appProblemBase(i);
if (app_problem.converged() || _keep_diverge)
for (std::size_t j = 0; j < _sub_pp_names.size(); ++j)
_current_data[j].emplace_back(
Expand Down Expand Up @@ -159,7 +159,7 @@ SamplerPostprocessorTransfer::execute()
current.reserve(_sampler_ptr->getNumberOfLocalRows());
for (dof_id_type i = _sampler_ptr->getLocalRowBegin(); i < _sampler_ptr->getLocalRowEnd(); ++i)
{
FEProblemBase & app_problem = _multi_app->appProblemBase(i);
FEProblemBase & app_problem = _from_multi_app->appProblemBase(i);
if (app_problem.converged() || _keep_diverge)
current.emplace_back(app_problem.getPostprocessorValueByName(_sub_pp_names[j]));
else
Expand Down
22 changes: 11 additions & 11 deletions modules/stochastic_tools/src/transfers/SamplerReporterTransfer.C
Expand Up @@ -66,9 +66,9 @@ SamplerReporterTransfer::initializeFromMultiapp()
void
SamplerReporterTransfer::executeFromMultiapp()
{
if (_multi_app->isRootProcessor())
if (_from_multi_app->isRootProcessor())
{
const dof_id_type n = _multi_app->numGlobalApps();
const dof_id_type n = _from_multi_app->numGlobalApps();
for (MooseIndex(n) i = 0; i < n; i++)
transferStochasticReporters(_global_index, i);
}
Expand All @@ -89,19 +89,19 @@ SamplerReporterTransfer::execute()
void
SamplerReporterTransfer::intitializeStochasticReporters()
{
const dof_id_type n = _multi_app->numGlobalApps();
const dof_id_type n = _from_multi_app->numGlobalApps();

for (const auto & sub_rname : _sub_reporter_names)
for (MooseIndex(n) i = 0; i < n; i++)
if (_multi_app->hasLocalApp(i))
addReporterTransferMode(sub_rname, REPORTER_MODE_ROOT, _multi_app->appProblemBase(i));
if (_from_multi_app->hasLocalApp(i))
addReporterTransferMode(sub_rname, REPORTER_MODE_ROOT, _from_multi_app->appProblemBase(i));

const std::string prefix = isParamValid("prefix") ? getParam<std::string>("prefix") : name();
for (const auto & sub_rname : _sub_reporter_names)
for (MooseIndex(n) i = 0; i < n; i++)
if (_multi_app->hasLocalApp(i))
if (_from_multi_app->hasLocalApp(i))
{
const ReporterData & rdata = _multi_app->appProblemBase(i).getReporterData();
const ReporterData & rdata = _from_multi_app->appProblemBase(i).getReporterData();
ReporterName rname =
_results->declareStochasticReporterClone(*_sampler_ptr, rdata, sub_rname, prefix);
if (rname.empty())
Expand All @@ -122,16 +122,16 @@ void
SamplerReporterTransfer::transferStochasticReporters(dof_id_type global_index,
dof_id_type app_index)
{
if (_multi_app->hasLocalApp(app_index))
if (_from_multi_app->hasLocalApp(app_index))
{
const dof_id_type local_index = global_index - _sampler_ptr->getLocalRowBegin();
for (unsigned int r = 0; r < _sub_reporter_names.size(); ++r)
transferToVectorReporter(_sub_reporter_names[r],
_reporter_names[r],
_multi_app->appProblemBase(app_index),
_multi_app->problemBase(),
_from_multi_app->appProblemBase(app_index),
_from_multi_app->problemBase(),
local_index);

(*_converged)[local_index] = _multi_app->appProblemBase(app_index).converged();
(*_converged)[local_index] = _from_multi_app->appProblemBase(app_index).converged();
}
}

0 comments on commit 65aec0c

Please sign in to comment.