Skip to content

Commit

Permalink
Added a field transfer interface so that
Browse files Browse the repository at this point in the history
the caculations can be reused for several interpolation transfers

Refs idaholab#12948
  • Loading branch information
fdkong committed Mar 21, 2019
1 parent fd4508b commit f8f1a6f
Show file tree
Hide file tree
Showing 23 changed files with 199 additions and 146 deletions.
2 changes: 1 addition & 1 deletion framework/include/base/Moose.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extern const ExecFlagType EXEC_SUBDOMAIN;
extern const ExecFlagType EXEC_PRE_DISPLACE;
extern const ExecFlagType EXEC_SAME_AS_MULTIAPP;
extern const ExecFlagType EXEC_PRE_MULTIAPP_SETUP;
extern const ExecFlagType EXEC_POST_TRANSFER;
extern const ExecFlagType EXEC_TRANSFER;

namespace Moose
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#ifdef LIBMESH_TRILINOS_HAVE_DTK

#include "MultiAppTransfer.h"
#include "MultiAppFieldTransferInterface.h"
#include "DTKInterpolationHelper.h"

// Forward declarations
Expand All @@ -26,17 +26,14 @@ InputParameters validParams<MultiAppDTKInterpolationTransfer>();
/**
* Transfers from spatially varying Interpolations in a MultiApp to the "master" system.
*/
class MultiAppDTKInterpolationTransfer : public MultiAppTransfer
class MultiAppDTKInterpolationTransfer : public MultiAppFieldTransferInterface
{
public:
MultiAppDTKInterpolationTransfer(const InputParameters & parameters);

virtual void execute() override;

protected:
VariableName _from_var_name;
AuxVariableName _to_var_name;

DTKInterpolationHelper _helper;
Point _master_position;
};
Expand Down
51 changes: 51 additions & 0 deletions framework/include/transfers/MultiAppFieldTransferInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#ifndef MULTIAPPFIELDTRANSFERINTERFACE_H
#define MULTIAPPFIELDTRANSFERINTERFACE_H

#include "MultiAppTransfer.h"

// Forward declarations
class MultiAppFieldTransferInterface;

template <>
InputParameters validParams<MultiAppFieldTransferInterface>();

/**
* This serves an interface for MultiAppInterpolationTransfer, MultiAppNearestNodeTransfer and so
* on.
*/
class MultiAppFieldTransferInterface : public MultiAppTransfer
{
public:
MultiAppFieldTransferInterface(const InputParameters & parameters);

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

protected:
VariableName _from_var_name;
AuxVariableName _to_var_name;

// 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;

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

#endif // MULTIAPPFIELDTRANSFERINTERFACE_H
7 changes: 2 additions & 5 deletions framework/include/transfers/MultiAppInterpolationTransfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define MULTIAPPINTERPOLATIONTRANSFER_H

// MOOSE includes
#include "MultiAppTransfer.h"
#include "MultiAppFieldTransferInterface.h"

#include "libmesh/mesh_base.h"

Expand All @@ -24,7 +24,7 @@ InputParameters validParams<MultiAppInterpolationTransfer>();
/**
* Copy the value to the target domain from the nearest node in the source domain.
*/
class MultiAppInterpolationTransfer : public MultiAppTransfer
class MultiAppInterpolationTransfer : public MultiAppFieldTransferInterface
{
public:
MultiAppInterpolationTransfer(const InputParameters & parameters);
Expand All @@ -47,9 +47,6 @@ class MultiAppInterpolationTransfer : public MultiAppTransfer
const MeshBase::const_node_iterator & nodes_begin,
const MeshBase::const_node_iterator & nodes_end);

AuxVariableName _to_var_name;
VariableName _from_var_name;

unsigned int _num_points;
Real _power;
MooseEnum _interp_type;
Expand Down
7 changes: 2 additions & 5 deletions framework/include/transfers/MultiAppNearestNodeTransfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define MULTIAPPNEARESTNODETRANSFER_H

// MOOSE includes
#include "MultiAppTransfer.h"
#include "MultiAppFieldTransferInterface.h"

// Forward declarations
class MultiAppNearestNodeTransfer;
Expand All @@ -26,7 +26,7 @@ InputParameters validParams<MultiAppNearestNodeTransfer>();
/**
* Copy the value to the target domain from the nearest node in the source domain.
*/
class MultiAppNearestNodeTransfer : public MultiAppTransfer
class MultiAppNearestNodeTransfer : public MultiAppFieldTransferInterface
{
public:
MultiAppNearestNodeTransfer(const InputParameters & parameters);
Expand Down Expand Up @@ -70,9 +70,6 @@ class MultiAppNearestNodeTransfer : public MultiAppTransfer
std::vector<std::pair<Point, DofObject *>> & local_entities,
bool nodal);

AuxVariableName _to_var_name;
VariableName _from_var_name;

/// If true then node connections will be cached
bool _fixed_meshes;

Expand Down
7 changes: 2 additions & 5 deletions framework/include/transfers/MultiAppProjectionTransfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef MULTIAPPPROJECTIONTRANSFER_H
#define MULTIAPPPROJECTIONTRANSFER_H

#include "MultiAppTransfer.h"
#include "MultiAppFieldTransferInterface.h"

// Forward declarations
namespace libMesh
Expand All @@ -26,7 +26,7 @@ InputParameters validParams<MultiAppProjectionTransfer>();
/**
* Project values from one domain to another
*/
class MultiAppProjectionTransfer : public MultiAppTransfer
class MultiAppProjectionTransfer : public MultiAppFieldTransferInterface
{
public:
MultiAppProjectionTransfer(const InputParameters & parameters);
Expand All @@ -43,9 +43,6 @@ class MultiAppProjectionTransfer : public MultiAppTransfer

void projectSolution(unsigned int to_problem);

AuxVariableName _to_var_name;
VariableName _from_var_name;

MooseEnum _proj_type;

/// True, if we need to recompute the projection matrix
Expand Down
16 changes: 0 additions & 16 deletions framework/include/transfers/MultiAppTransfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@ 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 @@ -121,13 +112,6 @@ 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 */
4 changes: 2 additions & 2 deletions framework/src/base/Moose.C
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const ExecFlagType EXEC_SUBDOMAIN("SUBDOMAIN", 0x200); // 512
const ExecFlagType EXEC_PRE_DISPLACE("PRE_DISPLACE");
const ExecFlagType EXEC_SAME_AS_MULTIAPP("SAME_AS_MULTIAPP");
const ExecFlagType EXEC_PRE_MULTIAPP_SETUP("PRE_MULTIAPP_SETUP");
const ExecFlagType EXEC_POST_TRANSFER("POST_TRANSFER");
const ExecFlagType EXEC_TRANSFER("TRANSFER");

namespace Moose
{
Expand Down Expand Up @@ -351,7 +351,7 @@ registerExecFlags(Factory & factory)
registerExecFlag(EXEC_FORCED);
registerExecFlag(EXEC_FAILED);
registerExecFlag(EXEC_CUSTOM);
registerExecFlag(EXEC_POST_TRANSFER);
registerExecFlag(EXEC_TRANSFER);
registerExecFlag(EXEC_SUBDOMAIN);
registerExecFlag(EXEC_PRE_DISPLACE);
registerExecFlag(EXEC_SAME_AS_MULTIAPP);
Expand Down
2 changes: 0 additions & 2 deletions framework/src/transfers/MultiAppCopyTransfer.C
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,4 @@ MultiAppCopyTransfer::execute()
}

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

postExecute();
}
9 changes: 2 additions & 7 deletions framework/src/transfers/MultiAppDTKInterpolationTransfer.C
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,13 @@ template <>
InputParameters
validParams<MultiAppDTKInterpolationTransfer>()
{
InputParameters params = validParams<MultiAppTransfer>();
params.addRequiredParam<AuxVariableName>(
"variable", "The auxiliary variable to store the transferred values in.");
params.addRequiredParam<VariableName>("source_variable", "The variable to transfer from.");
InputParameters params = validParams<MultiAppFieldTransferInterface>();
return params;
}

MultiAppDTKInterpolationTransfer::MultiAppDTKInterpolationTransfer(
const InputParameters & parameters)
: MultiAppTransfer(parameters),
_from_var_name(getParam<VariableName>("source_variable")),
_to_var_name(getParam<AuxVariableName>("variable"))
: MultiAppFieldTransferInterface(parameters)
{
}

Expand Down
102 changes: 102 additions & 0 deletions framework/src/transfers/MultiAppFieldTransferInterface.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

// MOOSE includes
#include "MultiAppFieldTransferInterface.h"
#include "MooseTypes.h"
#include "FEProblem.h"
#include "MultiApp.h"
#include "MooseMesh.h"

template <>
InputParameters
validParams<MultiAppFieldTransferInterface>()
{
InputParameters params = validParams<MultiAppTransfer>();
params.addRequiredParam<AuxVariableName>(
"variable", "The auxiliary variable to store the transferred values in.");
params.addRequiredParam<VariableName>("source_variable", "The variable to transfer from.");
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;
}

MultiAppFieldTransferInterface::MultiAppFieldTransferInterface(const InputParameters & parameters)
: MultiAppTransfer(parameters),
_from_var_name(getParam<VariableName>("source_variable")),
_to_var_name(getParam<AuxVariableName>("variable")),
_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"))
{
}

void
MultiAppFieldTransferInterface::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
MultiAppFieldTransferInterface::adjustTransferedSolution(FEProblemBase & from_problem,
FEProblemBase & to_problem)
{
PostprocessorValue & from_adjuster =
from_problem.getPostprocessorValue(_from_postprocessor_to_be_preserved);
// Compute to-postproessor to have the adjuster
to_problem.computeUserObjectByName(EXEC_TRANSFER, _to_postprocessor_to_be_preserved);

// Now we should have the right adjuster based on the transfered solution
PostprocessorValue & to_adjuster =
to_problem.getPostprocessorValue(_to_postprocessor_to_be_preserved);

auto & to_var = to_problem.getVariable(
0, _to_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD);

// Scale the solution.
to_var.sys().solution().scale(from_adjuster / to_adjuster);
// Update the local solution
to_var.sys().update();
}
10 changes: 2 additions & 8 deletions framework/src/transfers/MultiAppInterpolationTransfer.C
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ template <>
InputParameters
validParams<MultiAppInterpolationTransfer>()
{
InputParameters params = validParams<MultiAppTransfer>();
InputParameters params = validParams<MultiAppFieldTransferInterface>();
params.addClassDescription(
"Transfers the value to the target domain from the nearest node in the source domain.");
params.addRequiredParam<AuxVariableName>(
"variable", "The auxiliary variable to store the transferred values in.");
params.addRequiredParam<VariableName>("source_variable", "The variable to transfer from.");

params.addParam<unsigned int>(
"num_points", 3, "The number of nearest points to use for interpolation.");
params.addParam<Real>(
Expand All @@ -52,9 +48,7 @@ validParams<MultiAppInterpolationTransfer>()
}

MultiAppInterpolationTransfer::MultiAppInterpolationTransfer(const InputParameters & parameters)
: MultiAppTransfer(parameters),
_to_var_name(getParam<AuxVariableName>("variable")),
_from_var_name(getParam<VariableName>("source_variable")),
: MultiAppFieldTransferInterface(parameters),
_num_points(getParam<unsigned int>("num_points")),
_power(getParam<Real>("power")),
_interp_type(getParam<MooseEnum>("interp_type")),
Expand Down
6 changes: 2 additions & 4 deletions framework/src/transfers/MultiAppNearestNodeTransfer.C
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ template <>
InputParameters
validParams<MultiAppNearestNodeTransfer>()
{
InputParameters params = validParams<MultiAppTransfer>();
InputParameters params = validParams<MultiAppFieldTransferInterface>();

params.addRequiredParam<AuxVariableName>(
"variable", "The auxiliary variable to store the transferred values in.");
Expand All @@ -50,9 +50,7 @@ validParams<MultiAppNearestNodeTransfer>()
}

MultiAppNearestNodeTransfer::MultiAppNearestNodeTransfer(const InputParameters & parameters)
: MultiAppTransfer(parameters),
_to_var_name(getParam<AuxVariableName>("variable")),
_from_var_name(getParam<VariableName>("source_variable")),
: MultiAppFieldTransferInterface(parameters),
_fixed_meshes(getParam<bool>("fixed_meshes")),
_node_map(declareRestartableData<std::map<dof_id_type, Node *>>("node_map")),
_distance_map(declareRestartableData<std::map<dof_id_type, Real>>("distance_map")),
Expand Down

0 comments on commit f8f1a6f

Please sign in to comment.