Skip to content
Permalink
Browse files

Merge pull request #13448 from fdkong/conservative_transfers_1

Supports conservative transfer in MultiAppUserObjectTransfer
  • Loading branch information...
permcody committed May 30, 2019
2 parents 0d89f79 + dde9f8c commit 66c8f009c0b699c0d50c472f606d34558153366f
@@ -10,7 +10,7 @@
#pragma once

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

// Forward declarations
class MultiAppUserObjectTransfer;
@@ -23,17 +23,14 @@ InputParameters validParams<MultiAppUserObjectTransfer>();
* the MultiApp is. Copies that value into a postprocessor in the
* MultiApp.
*/
class MultiAppUserObjectTransfer : public MultiAppTransfer
class MultiAppUserObjectTransfer : public MultiAppFieldTransfer
{
public:
MultiAppUserObjectTransfer(const InputParameters & parameters);

virtual void initialSetup() override;

virtual void execute() override;

protected:
AuxVariableName _to_var_name;
std::string _user_object_name;

/**
@@ -42,4 +39,3 @@ class MultiAppUserObjectTransfer : public MultiAppTransfer
**/
const bool _all_master_nodes_contained_in_sub_app;
};

@@ -42,9 +42,9 @@ MultiAppFieldTransfer::MultiAppFieldTransfer(const InputParameters & parameters)
_to_var_names(getParam<std::vector<AuxVariableName>>("variable")),
_preserve_transfer(isParamValid("from_postprocessors_to_be_preserved")),
_from_postprocessors_to_be_preserved(
parameters.get<std::vector<PostprocessorName>>("from_postprocessors_to_be_preserved")),
getParam<std::vector<PostprocessorName>>("from_postprocessors_to_be_preserved")),
_to_postprocessors_to_be_preserved(
parameters.get<std::vector<PostprocessorName>>("to_postprocessors_to_be_preserved")),
getParam<std::vector<PostprocessorName>>("to_postprocessors_to_be_preserved")),
_use_nearestpoint_pps(false)
{
if (_preserve_transfer)
@@ -53,8 +53,8 @@ MultiAppFieldTransfer::MultiAppFieldTransfer(const InputParameters & parameters)
* 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_names.size() != 1)
paramError("source_variable",
if (_to_var_names.size() != 1)
paramError("variable",
" Support single variable only when the conservative capability is on ");

if (_direction == TO_MULTIAPP)
@@ -83,19 +83,16 @@ MultiAppFieldTransfer::MultiAppFieldTransfer(const InputParameters & parameters)
}
}

if (_to_var_names.size() != _from_var_names.size())
paramError("source_variable",
"Number of target variable should equal to the number of source variables ");

/* Have to specify at least one to-variable */
if (_to_var_names.size() == 0)
paramError("variable", "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())
{
if (_to_var_names.size() == 1)
_to_var_name = _to_var_names[0];

if (_from_var_names.size() == 1)
_from_var_name = _from_var_names[0];
}
}

void
@@ -57,8 +57,11 @@ MultiAppInterpolationTransfer::MultiAppInterpolationTransfer(const InputParamete
// This transfer does not work with DistributedMesh
_fe_problem.mesh().errorIfDistributedMesh("MultiAppInterpolationTransfer");

if (_to_var_names.size() != 1 || _from_var_names.size() != 1)
mooseError(" Support single variable only ");
if (_to_var_names.size() != 1)
paramError("variable", " Support single to-variable only ");

if (_from_var_names.size() != 1)
paramError("source_variable", " Support single from-variable only ");
}

void
@@ -43,7 +43,7 @@ MultiAppMeshFunctionTransfer::MultiAppMeshFunctionTransfer(const InputParameters
if (_to_var_names.size() == _from_var_names.size())
_var_size = _to_var_names.size();
else
mooseError("The number of variables to transfer to and from should be equal");
paramError("variable", "The number of variables to transfer to and from should be equal");
}

void
@@ -59,8 +59,11 @@ MultiAppNearestNodeTransfer::MultiAppNearestNodeTransfer(const InputParameters &
declareRestartableData<std::map<dof_id_type, unsigned int>>("cached_from_ids")),
_cached_qp_inds(declareRestartableData<std::map<dof_id_type, unsigned int>>("cached_qp_inds"))
{
if (_to_var_names.size() != 1 && _from_var_names.size() != 1)
mooseError(" Support single variable only");
if (_to_var_names.size() != 1)
paramError("variable", " Support single to-variable only");

if (_from_var_names.size() != 1)
paramError("source_variable", " Support single from-variable only");
}

void
@@ -66,8 +66,11 @@ MultiAppProjectionTransfer::MultiAppProjectionTransfer(const InputParameters & p
_fixed_meshes(getParam<bool>("fixed_meshes")),
_qps_cached(false)
{
if (_to_var_names.size() != 1 || _from_var_names.size() != 1)
mooseError(" Support single variable only ");
if (_to_var_names.size() != 1)
paramError("variable", " Support single to-variable only ");

if (_from_var_names.size() != 1)
paramError("source_variable", " Support single from-variable only ");
}

void
@@ -32,9 +32,10 @@ template <>
InputParameters
validParams<MultiAppUserObjectTransfer>()
{
InputParameters params = validParams<MultiAppTransfer>();
params.addRequiredParam<AuxVariableName>(
"variable", "The auxiliary variable to store the transferred values in.");
InputParameters params = validParams<MultiAppFieldTransfer>();
// MultiAppUserObjectTransfer does not need source variable since it query values from user
// objects
params.suppressParameter<std::vector<VariableName>>("source_variable");
params.addRequiredParam<UserObjectName>(
"user_object",
"The UserObject you want to transfer values from. Note: This might be a "
@@ -49,20 +50,20 @@ validParams<MultiAppUserObjectTransfer>()
}

MultiAppUserObjectTransfer::MultiAppUserObjectTransfer(const InputParameters & parameters)
: MultiAppTransfer(parameters),
_to_var_name(getParam<AuxVariableName>("variable")),
: MultiAppFieldTransfer(parameters),
_user_object_name(getParam<UserObjectName>("user_object")),
_all_master_nodes_contained_in_sub_app(getParam<bool>("all_master_nodes_contained_in_sub_app"))
{
// This transfer does not work with DistributedMesh
_fe_problem.mesh().errorIfDistributedMesh("MultiAppUserObjectTransfer");
}

void
MultiAppUserObjectTransfer::initialSetup()
{
if (_direction == TO_MULTIAPP)
variableIntegrityCheck(_to_var_name);
if (_to_var_names.size() != 1)
paramError("variable", " Support single to-variable only ");

if (_from_var_names.size() > 0)
paramError("source_variable",
" You should not provide any source variables since the transfer takes values from "
"user objects ");
}

void
@@ -329,4 +330,6 @@ MultiAppUserObjectTransfer::execute()
}

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

postExecute();
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
np_post_processor_values
0.017563311980171
0.017563311980171
@@ -0,0 +1,3 @@
np_post_processor_values
0.017563311980171
0.017563311980171
@@ -0,0 +1,116 @@
[Mesh]
type = GeneratedMesh
dim = 3
nx = 20
ny = 20
nz = 20
# The MultiAppUserObjectTransfer object only works with ReplicatedMesh
parallel_type = replicated
[]

[Variables]
[./u]
[../]
[]

[AuxVariables]
[./multi_layered_average]
[../]
[./element_multi_layered_average]
order = CONSTANT
family = MONOMIAL
[../]
[]

[Kernels]
[./diff]
type = Diffusion
variable = u
[../]
[./td]
type = TimeDerivative
variable = u
[../]
[]

[BCs]
[./left]
type = DirichletBC
variable = u
boundary = left
value = 0
[../]
[./right]
type = DirichletBC
variable = u
boundary = right
value = 1
[../]
[]

[Executioner]
type = Transient
num_steps = 1
dt = 0.001 # This will be constrained by the multiapp

solve_type = 'PJFNK'

petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
l_tol = 1e-8
nl_rel_tol = 1e-10
[]


[Outputs]
exodus = true
csv = true
[]

[VectorPostprocessors]
[to_nearest_point]
type = NearestPointIntegralVariablePostprocessor
variable = multi_layered_average
points = '0.3 0.1 0.3 0.7 0.1 0.3'
execute_on = 'transfer nonlinear TIMESTEP_END'
[]

[to_nearest_point_element]
type = NearestPointIntegralVariablePostprocessor
variable = element_multi_layered_average
points = '0.3 0.1 0.3 0.7 0.1 0.3'
execute_on = 'transfer nonlinear TIMESTEP_END'
[]
[]

[MultiApps]
[./sub_app]
positions = '0.3 0.1 0.3 0.7 0.1 0.3'
type = TransientMultiApp
input_files = sub_userobject.i
app_type = MooseTestApp
[../]
[]

[Transfers]
[./layered_transfer]
direction = from_multiapp
user_object = layered_average
variable = multi_layered_average
type = MultiAppUserObjectTransfer
multi_app = sub_app

from_postprocessors_to_be_preserved = 'from_postprocessor'
to_postprocessors_to_be_preserved = 'to_nearest_point'
[../]
[./element_layered_transfer]
direction = from_multiapp
user_object = layered_average
variable = element_multi_layered_average
type = MultiAppUserObjectTransfer
multi_app = sub_app

from_postprocessors_to_be_preserved = 'from_postprocessor'
to_postprocessors_to_be_preserved = 'to_nearest_point_element'
[../]
[]

0 comments on commit 66c8f00

Please sign in to comment.
You can’t perform that action at this time.