Skip to content

Commit

Permalink
The first simple implementation of a conservative transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
fdkong committed Mar 22, 2019
1 parent 75a7724 commit 136e353
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 1 deletion.
16 changes: 16 additions & 0 deletions framework/include/transfers/MultiAppTransfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ class MultiAppTransfer : public Transfer
/// Return the execution flags, handling "same_as_multiapp"
virtual const std::vector<ExecFlagType> & execFlags() const;

/**
* Add some extra work if necessary after execute(). For example, adjust the solution
* to preserve some physics quality of interest.
*/
virtual void postExecute();

private:
void adjustTransferedSolution(FEProblemBase & from_problem, FEProblemBase & to_problem);

protected:
/// The MultiApp this Transfer is transferring data to or from
std::shared_ptr<MultiApp> _multi_app;
Expand Down Expand Up @@ -112,6 +121,13 @@ class MultiAppTransfer : public Transfer

// Given local app index, returns global app index.
std::vector<unsigned int> _local2global_map;

// If this transfer is going to conserve the physics
bool _preserve_transfer;
// Postprocessor evaluates an adjuster for the source physics
PostprocessorName _from_postprocessor_to_be_preserved;
// Postprocessor evaluates an adjuster for the target physics
PostprocessorName _to_postprocessor_to_be_preserved;
};

#endif /* MULTIAPPTRANSFER_H */
2 changes: 2 additions & 0 deletions framework/src/transfers/MultiAppCopyTransfer.C
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,6 @@ MultiAppCopyTransfer::execute()
}

_console << "Finished MultiAppCopyTransfer " << name() << std::endl;

postExecute();
}
2 changes: 2 additions & 0 deletions framework/src/transfers/MultiAppDTKInterpolationTransfer.C
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ MultiAppDTKInterpolationTransfer::execute()
_multi_app->appProblemBase(i).es().update();
}
}

postExecute();
}

#endif // LIBMESH_TRILINOS_HAVE_DTK
2 changes: 2 additions & 0 deletions framework/src/transfers/MultiAppInterpolationTransfer.C
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ MultiAppInterpolationTransfer::execute()
}

_console << "Finished InterpolationTransfer " << name() << std::endl;

postExecute();
}

Node *
Expand Down
2 changes: 2 additions & 0 deletions framework/src/transfers/MultiAppNearestNodeTransfer.C
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,8 @@ MultiAppNearestNodeTransfer::execute()
}

_console << "Finished NearestNodeTransfer " << name() << std::endl;

postExecute();
}

Node *
Expand Down
66 changes: 65 additions & 1 deletion framework/src/transfers/MultiAppTransfer.C
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ validParams<MultiAppTransfer>()
false,
"Whether or not to use the displaced mesh for the target mesh.");

params.addParam<bool>("preserve_transfer",
false,
"Whether or not to conserve the transfered field, "
" if true, the transfered variables will be adjusted "
"according to the pps value");

params.addParam<PostprocessorName>(
"from_postprocessor_to_be_preserved",
"from_postprocessor",
"The name of the Postprocessor in the from-app to evaluate an adjusting factor.");

params.addParam<PostprocessorName>(
"to_postprocessor_to_be_preserved",
"to_postprocessor",
"The name of the Postprocessor in the to-app to evaluate an adjusting factor.");

return params;
}

Expand All @@ -56,7 +72,12 @@ MultiAppTransfer::MultiAppTransfer(const InputParameters & parameters)
_multi_app(_fe_problem.getMultiApp(getParam<MultiAppName>("multi_app"))),
_direction(getParam<MooseEnum>("direction")),
_displaced_source_mesh(getParam<bool>("displaced_source_mesh")),
_displaced_target_mesh(getParam<bool>("displaced_target_mesh"))
_displaced_target_mesh(getParam<bool>("displaced_target_mesh")),
_preserve_transfer(parameters.get<bool>("preserve_transfer")),
_from_postprocessor_to_be_preserved(
parameters.get<PostprocessorName>("from_postprocessor_to_be_preserved")),
_to_postprocessor_to_be_preserved(
parameters.get<PostprocessorName>("to_postprocessor_to_be_preserved"))
{
bool check = getParam<bool>("check_multiapp_execute_on");
if (check && (getExecuteOnEnum() != _multi_app->getExecuteOnEnum()))
Expand Down Expand Up @@ -259,3 +280,46 @@ MultiAppTransfer::getTransferVector(unsigned int i_local, std::string var_name)

return _multi_app->appTransferVector(_local2global_map[i_local], var_name);
}

void
MultiAppTransfer::postExecute()
{
if (_preserve_transfer)
{
_console << "Beginning MultiAppCopyTransfer postExecute " << name() << std::endl;

if (_direction == TO_MULTIAPP)
{
FEProblemBase & from_problem = _multi_app->problemBase();
for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
if (_multi_app->hasLocalApp(i))
adjustTransferedSolution(from_problem, _multi_app->appProblemBase(i));
}

else if (_direction == FROM_MULTIAPP)
{
FEProblemBase & to_problem = _multi_app->problemBase();
for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
if (_multi_app->hasLocalApp(i))
adjustTransferedSolution(_multi_app->appProblemBase(i), to_problem);
}

_console << "Finished MultiAppCopyTransfer postExecute " << name() << std::endl;
}
}

void
MultiAppTransfer::adjustTransferedSolution(FEProblemBase & from_problem, FEProblemBase & to_problem)
{
PostprocessorValue & from_adjuster =
from_problem.getPostprocessorValue(_from_postprocessor_to_be_preserved);
// Init problem so that to_postprocessor_to_be_preserved is set correctly
to_problem.execute(EXEC_INITIAL);
// Now we should have the right adjuster based on the transfered solution
PostprocessorValue & to_adjuster =
to_problem.getPostprocessorValue(_to_postprocessor_to_be_preserved);
// Scale the solution. Allow scale for selected variables???
to_problem.getNonlinearSystemBase().solution().scale(from_adjuster / to_adjuster);
// Update the local solution
to_problem.getNonlinearSystemBase().update();
}

0 comments on commit 136e353

Please sign in to comment.