Skip to content

Commit

Permalink
Conservative transfer: clean up user interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
fdkong committed May 17, 2019
1 parent 26d2934 commit 4f67b6c
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 128 deletions.
8 changes: 4 additions & 4 deletions framework/include/problems/FEProblemBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1478,10 +1478,6 @@ 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);

/**
* Compute an user object with the given name
*/
Expand Down Expand Up @@ -1793,6 +1789,10 @@ class FEProblemBase : public SubProblem, public Restartable
/// Helper to check for duplicate variable names across systems or within a single system
bool duplicateVariableCheck(const std::string & var_name, const FEType & type, bool is_aux);

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

/// Verify that SECOND order mesh uses SECOND order displacements.
void checkDisplacementOrders();

Expand Down
12 changes: 6 additions & 6 deletions framework/include/transfers/MultiAppFieldTransferInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
//* 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
#pragma once

#include "MultiAppTransfer.h"

Expand Down Expand Up @@ -36,8 +35,11 @@ class MultiAppFieldTransferInterface : public MultiAppTransfer
virtual void postExecute();

protected:
std::vector<VariableName> _from_var_name;
std::vector<AuxVariableName> _to_var_name;
std::vector<VariableName> _from_var_names;
std::vector<AuxVariableName> _to_var_names;

VariableName _from_var_name;
AuxVariableName _to_var_name;

// If this transfer is going to conserve the physics
bool _preserve_transfer;
Expand All @@ -60,5 +62,3 @@ class MultiAppFieldTransferInterface : public MultiAppTransfer

bool _use_nearestpoint_pps;
};

#endif // MULTIAPPFIELDTRANSFERINTERFACE_H
2 changes: 0 additions & 2 deletions framework/include/transfers/MultiAppInterpolationTransfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class MultiAppInterpolationTransfer : public MultiAppFieldTransferInterface
public:
MultiAppInterpolationTransfer(const InputParameters & parameters);

virtual void initialSetup() override;

virtual void execute() override;

protected:
Expand Down
2 changes: 0 additions & 2 deletions framework/include/transfers/MultiAppMeshFunctionTransfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class MultiAppMeshFunctionTransfer : public MultiAppFieldTransferInterface
public:
MultiAppMeshFunctionTransfer(const InputParameters & parameters);

virtual void initialSetup() override;

virtual void execute() override;

protected:
Expand Down
2 changes: 0 additions & 2 deletions framework/include/transfers/MultiAppNearestNodeTransfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class MultiAppNearestNodeTransfer : public MultiAppFieldTransferInterface
public:
MultiAppNearestNodeTransfer(const InputParameters & parameters);

virtual void initialSetup() override;

virtual void execute() override;

protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#ifndef NEARESTPOINTINTEGRALVARIABLEPOSTPROCESSOR_H
#define NEARESTPOINTINTEGRALVARIABLEPOSTPROCESSOR_H
#pragma once

// MOOSE includes
#include "NearestPointBase.h"
Expand Down Expand Up @@ -38,5 +37,3 @@ class NearestPointIntegralVariablePostprocessor

std::shared_ptr<ElementIntegralVariablePostprocessor> userObject(unsigned int i) const;
};

#endif /* NEARESTPOINTINTEGRALVARIABLEPOSTPROCESSOR_H */
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#ifndef NEARESTPOINTLAYEREDSIDEAVERAGE_H
#define NEARESTPOINTLAYEREDSIDEAVERAGE_H
#pragma once

// MOOSE includes
#include "SideIntegralVariableUserObject.h"
Expand All @@ -34,5 +33,3 @@ class NearestPointLayeredSideAverage
public:
NearestPointLayeredSideAverage(const InputParameters & parameters);
};

#endif
4 changes: 2 additions & 2 deletions framework/src/transfers/MultiAppDTKInterpolationTransfer.C
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ MultiAppDTKInterpolationTransfer::MultiAppDTKInterpolationTransfer(
const InputParameters & parameters)
: MultiAppFieldTransferInterface(parameters)
{
mooseAssert(_to_var_name.size() == 1 && _from_var_name.size() == 1,
" Support single variable only ");
if (_to_var_name.size() != 1 && _from_var_name.size() != 1)
mooseError(" Support single variable only ");
}

void
Expand Down
47 changes: 26 additions & 21 deletions framework/src/transfers/MultiAppFieldTransferInterface.C
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,22 @@ validParams<MultiAppFieldTransferInterface>()
"variable", "The auxiliary variable to store the transferred values in.");
params.addRequiredParam<std::vector<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");

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

std::vector<PostprocessorName> to_postprocessor = {"to_postprocessor"};
params.addParam<std::vector<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<std::vector<VariableName>>("source_variable")),
_to_var_name(getParam<std::vector<AuxVariableName>>("variable")),
_preserve_transfer(parameters.get<bool>("preserve_transfer")),
_from_var_names(getParam<std::vector<VariableName>>("source_variable")),
_to_var_names(getParam<std::vector<AuxVariableName>>("variable")),
_preserve_transfer(isParamValid("from_postprocessor_to_be_preserved")),
_from_postprocessor_to_be_preserved(
parameters.get<std::vector<PostprocessorName>>("from_postprocessor_to_be_preserved")),
_to_postprocessor_to_be_preserved(
Expand All @@ -62,7 +53,7 @@ MultiAppFieldTransferInterface::MultiAppFieldTransferInterface(const InputParame
* Not sure how important to support multi variables
* Let us handle the single variable case only right now if the conservative capability is on
*/
if (_to_var_name.size() != 1 && _from_var_name.size() != 1)
if (_to_var_name.size() != 1 && _from_var_names.size() != 1)
mooseError(" Support single variable only when the conservative capability is on ");

if (_direction == TO_MULTIAPP)
Expand All @@ -86,16 +77,30 @@ MultiAppFieldTransferInterface::MultiAppFieldTransferInterface(const InputParame
}
}

if (_to_var_name.size() != _from_var_name.size())
if (_to_var_names.size() != _from_var_names.size())
mooseError("Number of target variable should equal to the number of source variables ");

if (_to_var_name.size() == 0)
if (_to_var_names.size() == 0)
mooseError("You need to specify at least one variable");

/* Right now, most of transfers support one variable only */
if (_to_var_names.size() == 1 && _from_var_names.size())
{
_to_var_name = _to_var_names[0];
_from_var_name = _from_var_names[0];
}
}

void
MultiAppFieldTransferInterface::initialSetup()
{
if (_direction == TO_MULTIAPP)
for (auto & to_var : _to_var_names)
variableIntegrityCheck(to_var);
else
for (auto & from_var : _from_var_names)
variableIntegrityCheck(from_var);

if (_preserve_transfer)
{
if (_from_postprocessor_to_be_preserved.size() == 1 && _direction == TO_MULTIAPP)
Expand All @@ -112,7 +117,7 @@ MultiAppFieldTransferInterface::initialSetup()
mooseError(
" You have to specify ",
_multi_app->numGlobalApps(),
" regular from-postproessors, or use NearestPointIntegralVariablePostprocessor ");
" regular from-postprocessors, or use NearestPointIntegralVariablePostprocessor ");
}
}

Expand All @@ -130,7 +135,7 @@ MultiAppFieldTransferInterface::initialSetup()
mooseError(
" You have to specify ",
_multi_app->numGlobalApps(),
" regular to-postproessors, or use NearestPointIntegralVariablePostprocessor ");
" regular to-postprocessors, or use NearestPointIntegralVariablePostprocessor ");
}
}
}
Expand Down Expand Up @@ -228,9 +233,9 @@ MultiAppFieldTransferInterface::adjustTransferedSolutionNearestPoint(
}

auto & to_var = to_problem.getVariable(
0, _to_var_name[0], Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD);
0, _to_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD);
auto & to_sys = to_var.sys().system();
auto var_num = to_sys.variable_number(_to_var_name[0]);
auto var_num = to_sys.variable_number(_to_var_name);
auto sys_num = to_sys.number();
auto & pps = static_cast<const NearestPointIntegralVariablePostprocessor &>(
_direction == FROM_MULTIAPP ? (to_problem.getUserObjectBase(to_postprocessor))
Expand Down Expand Up @@ -326,9 +331,9 @@ MultiAppFieldTransferInterface::adjustTransferedSolution(FEProblemBase * from_pr
}

auto & to_var = to_problem.getVariable(
0, _to_var_name[0], Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD);
0, _to_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD);
auto & to_sys = to_var.sys().system();
auto var_num = to_sys.variable_number(_to_var_name[0]);
auto var_num = to_sys.variable_number(_to_var_name);
auto sys_num = to_sys.number();
auto * pps =
dynamic_cast<const BlockRestrictable *>(&(to_problem.getUserObjectBase(to_postprocessor)));
Expand Down
40 changes: 13 additions & 27 deletions framework/src/transfers/MultiAppInterpolationTransfer.C
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,8 @@ MultiAppInterpolationTransfer::MultiAppInterpolationTransfer(const InputParamete
// This transfer does not work with DistributedMesh
_fe_problem.mesh().errorIfDistributedMesh("MultiAppInterpolationTransfer");

mooseAssert(_to_var_name.size() == 1 && _from_var_name.size() == 1,
" Support single variable only ");
}

void
MultiAppInterpolationTransfer::initialSetup()
{
MultiAppFieldTransferInterface::initialSetup();

if (_direction == TO_MULTIAPP)
variableIntegrityCheck(_to_var_name[0]);
else
variableIntegrityCheck(_from_var_name[0]);
if (_to_var_names.size() != 1 || _from_var_names.size() != 1)
mooseError(" Support single variable only ");
}

void
Expand All @@ -82,11 +71,8 @@ MultiAppInterpolationTransfer::execute()
case TO_MULTIAPP:
{
FEProblemBase & from_problem = _multi_app->problemBase();
MooseVariableFEBase & from_var =
from_problem.getVariable(0,
_from_var_name[0],
Moose::VarKindType::VAR_ANY,
Moose::VarFieldType::VAR_FIELD_STANDARD);
MooseVariableFEBase & from_var = from_problem.getVariable(
0, _from_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD);

MeshBase * from_mesh = NULL;

Expand Down Expand Up @@ -125,11 +111,11 @@ MultiAppInterpolationTransfer::execute()
std::vector<Number> & src_vals(idi->get_source_vals());

std::vector<std::string> field_vars;
field_vars.push_back(_to_var_name[0]);
field_vars.push_back(_to_var_name);
idi->set_field_variables(field_vars);

std::vector<std::string> vars;
vars.push_back(_to_var_name[0]);
vars.push_back(_to_var_name);

if (from_is_nodal)
{
Expand Down Expand Up @@ -168,11 +154,11 @@ MultiAppInterpolationTransfer::execute()
Moose::ScopedCommSwapper swapper(_multi_app->comm());

// Loop over the master nodes and set the value of the variable
System * to_sys = find_sys(_multi_app->appProblemBase(i).es(), _to_var_name[0]);
System * to_sys = find_sys(_multi_app->appProblemBase(i).es(), _to_var_name);

unsigned int sys_num = to_sys->number();
unsigned int var_num = to_sys->variable_number(_to_var_name[0]);
NumericVector<Real> & solution = _multi_app->appTransferVector(i, _to_var_name[0]);
unsigned int var_num = to_sys->variable_number(_to_var_name);
NumericVector<Real> & solution = _multi_app->appTransferVector(i, _to_var_name);

MeshBase * mesh = NULL;

Expand Down Expand Up @@ -250,7 +236,7 @@ MultiAppInterpolationTransfer::execute()
{
FEProblemBase & to_problem = _multi_app->problemBase();
MooseVariableFEBase & to_var = to_problem.getVariable(
0, _to_var_name[0], Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD);
0, _to_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD);
SystemBase & to_system_base = to_var.sys();

System & to_sys = to_system_base.system();
Expand Down Expand Up @@ -294,11 +280,11 @@ MultiAppInterpolationTransfer::execute()
std::vector<Number> & src_vals(idi->get_source_vals());

std::vector<std::string> field_vars;
field_vars.push_back(_to_var_name[0]);
field_vars.push_back(_to_var_name);
idi->set_field_variables(field_vars);

std::vector<std::string> vars;
vars.push_back(_to_var_name[0]);
vars.push_back(_to_var_name);

for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
{
Expand All @@ -310,7 +296,7 @@ MultiAppInterpolationTransfer::execute()
FEProblemBase & from_problem = _multi_app->appProblemBase(i);
MooseVariableFEBase & from_var =
from_problem.getVariable(0,
_from_var_name[0],
_from_var_name,
Moose::VarKindType::VAR_ANY,
Moose::VarFieldType::VAR_FIELD_STANDARD);
SystemBase & from_system_base = from_var.sys();
Expand Down

0 comments on commit 4f67b6c

Please sign in to comment.