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 May 17, 2019
1 parent c27b98b commit 672f542
Show file tree
Hide file tree
Showing 25 changed files with 210 additions and 150 deletions.
2 changes: 1 addition & 1 deletion framework/include/base/Moose.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,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
4 changes: 3 additions & 1 deletion framework/include/problems/FEProblemBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,9 @@ class FEProblemBase : public SubProblem, public Restartable
*/
virtual void computeUserObjects(const ExecFlagType & type, const Moose::AuxGroup & group);

void computeUserObjectsInternal(const ExecFlagType & type, const Moose::AuxGroup & group, TheWarehouse::Query & query);
void computeUserObjectsInternal(const ExecFlagType & type,
const Moose::AuxGroup & group,
TheWarehouse::Query & query);

/**
* Compute an user object with the given name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#ifdef LIBMESH_TRILINOS_HAVE_DTK

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

// Forward declarations
Expand All @@ -25,17 +25,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 @@ -10,7 +10,7 @@
#pragma once

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

#include "libmesh/mesh_base.h"

Expand All @@ -23,7 +23,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 @@ -46,9 +46,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 @@ -10,7 +10,7 @@
#pragma once

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

// Forward declarations
class MultiAppNearestNodeTransfer;
Expand All @@ -25,7 +25,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 @@ -69,9 +69,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 @@ -9,7 +9,7 @@

#pragma once

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

// Forward declarations
namespace libMesh
Expand All @@ -25,7 +25,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 @@ -42,9 +42,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 @@ -60,15 +60,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 @@ -120,13 +111,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;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions framework/src/base/Moose.C
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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");

void
MooseVecView(NumericVector<Number> & vector)
Expand Down Expand Up @@ -377,7 +377,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
11 changes: 8 additions & 3 deletions framework/src/problems/FEProblemBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -3071,8 +3071,11 @@ FEProblemBase::joinAndFinalize(TheWarehouse::Query query, bool isgen)
void
FEProblemBase::computeUserObjectByName(const ExecFlagType & type, const std::string & name)
{
TheWarehouse::Query query =
theWarehouse().query().condition<AttribSystem>("UserObject").condition<AttribExecOns>(type).condition<AttribName>(name);
TheWarehouse::Query query = theWarehouse()
.query()
.condition<AttribSystem>("UserObject")
.condition<AttribExecOns>(type)
.condition<AttribName>(name);
computeUserObjectsInternal(type, Moose::POST_AUX, query);
}

Expand All @@ -3085,7 +3088,9 @@ FEProblemBase::computeUserObjects(const ExecFlagType & type, const Moose::AuxGro
}

void
FEProblemBase::computeUserObjectsInternal(const ExecFlagType & type, const Moose::AuxGroup & group, TheWarehouse::Query & query)
FEProblemBase::computeUserObjectsInternal(const ExecFlagType & type,
const Moose::AuxGroup & group,
TheWarehouse::Query & query)
{
if (group == Moose::PRE_IC)
query.condition<AttribPreIC>(true);
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();
}

0 comments on commit 672f542

Please sign in to comment.