Skip to content

Commit

Permalink
Allow skipping adjustment without error and allow two negative adjust…
Browse files Browse the repository at this point in the history
…ers in conservative transfers (idaholab#15952)
  • Loading branch information
schuseba authored and jain651 committed Apr 19, 2021
1 parent 2ccc74a commit 85de18c
Show file tree
Hide file tree
Showing 8 changed files with 295 additions and 23 deletions.
3 changes: 3 additions & 0 deletions framework/include/transfers/MultiAppConservativeTransfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class MultiAppConservativeTransfer : public MultiAppFieldTransfer
virtual std::vector<VariableName> getFromVarNames() const override { return _from_var_names; }
virtual std::vector<AuxVariableName> getToVarNames() const override { return _to_var_names; }

bool performAdjustment(const PostprocessorValue & from, const PostprocessorValue & to) const;

/// Name of variables transfering from
const std::vector<VariableName> _from_var_names;
/// Name of variables transfering to
Expand Down Expand Up @@ -69,4 +71,5 @@ class MultiAppConservativeTransfer : public MultiAppFieldTransfer
PostprocessorName & to_postprocessor);

bool _use_nearestpoint_pps;
bool _allow_skipped_adjustment;
};
61 changes: 38 additions & 23 deletions framework/src/transfers/MultiAppConservativeTransfer.C
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ MultiAppConservativeTransfer::validParams()
params.addParam<std::vector<PostprocessorName>>(
"to_postprocessors_to_be_preserved",
"The name of the Postprocessor in the to-app to evaluate an adjusting factor.");
params.addParam<bool>("allow_skipped_adjustment",
false,
"If set to true, the transfer skips adjustment when from or to "
"postprocessor values are either zero or have different signs. If set to "
"false, an error is thrown when encountering these conditions.");
return params;
}

Expand All @@ -47,7 +52,8 @@ MultiAppConservativeTransfer::MultiAppConservativeTransfer(const InputParameters
getParam<std::vector<PostprocessorName>>("from_postprocessors_to_be_preserved")),
_to_postprocessors_to_be_preserved(
getParam<std::vector<PostprocessorName>>("to_postprocessors_to_be_preserved")),
_use_nearestpoint_pps(false)
_use_nearestpoint_pps(false),
_allow_skipped_adjustment(getParam<bool>("allow_skipped_adjustment"))
{
if (_directions.size() != 1)
paramError("direction", "This transfer is only unidirectional");
Expand Down Expand Up @@ -236,10 +242,6 @@ MultiAppConservativeTransfer::adjustTransferedSolutionNearestPoint(
comm().min(from_adjuster_tmp);
from_adjuster = from_adjuster_tmp;
}

/* We should not have a zero value */
if (MooseUtils::absoluteFuzzyLessEqual(from_adjuster, 0.))
mooseError("from_adjuster must be nonzero");
}

PostprocessorValue to_adjuster = 0;
Expand Down Expand Up @@ -273,17 +275,15 @@ MultiAppConservativeTransfer::adjustTransferedSolutionNearestPoint(
if (_current_direction == FROM_MULTIAPP)
{
auto ii = pps.nearestPointIndex(*node);
if (ii != i)
if (ii != i || !performAdjustment(from_adjuster, pps.userObjectValue(i)))
continue;
if (MooseUtils::absoluteFuzzyLessEqual(pps.userObjectValue(i), 0.))
mooseError("to_adjuster must be nonzero");

scale = from_adjuster / pps.userObjectValue(i);
}
else
{
if (MooseUtils::absoluteFuzzyLessEqual(to_adjuster, 0.))
mooseError("to_adjuster must be nonzero");
if (!performAdjustment(pps.userObjectValue(i), to_adjuster))
continue;

scale = pps.userObjectValue(i) / to_adjuster;
}
Expand All @@ -305,18 +305,15 @@ MultiAppConservativeTransfer::adjustTransferedSolutionNearestPoint(
if (_current_direction == FROM_MULTIAPP)
{
unsigned int ii = pps.nearestPointIndex(elem->centroid());
if (ii != i)
if (ii != i || !performAdjustment(from_adjuster, pps.userObjectValue(i)))
continue;

if (MooseUtils::absoluteFuzzyLessEqual(pps.userObjectValue(i), 0.))
mooseError("to_adjuster must be nonzero");

scale = from_adjuster / pps.userObjectValue(i);
}
else
{
if (MooseUtils::absoluteFuzzyLessEqual(to_adjuster, 0.))
mooseError("to_adjuster must be nonzero");
if (!performAdjustment(pps.userObjectValue(i), to_adjuster))
continue;

scale = pps.userObjectValue(i) / to_adjuster;
}
Expand Down Expand Up @@ -357,19 +354,17 @@ MultiAppConservativeTransfer::adjustTransferedSolution(FEProblemBase * from_prob
comm().min(from_adjuster_tmp);
from_adjuster = from_adjuster_tmp;
}

/* We should not have a zero value */
if (MooseUtils::absoluteFuzzyLessEqual(from_adjuster, 0.))
mooseError("from_adjuster must be nonzero");
}

// Compute to-postproessor to have the adjuster
to_problem.computeUserObjectByName(EXEC_TRANSFER, to_postprocessor);

// Now we should have the right adjuster based on the transfered solution
const PostprocessorValue & to_adjuster = to_problem.getPostprocessorValueByName(to_postprocessor);
if (MooseUtils::absoluteFuzzyLessEqual(to_adjuster, 0.))
mooseError("To postprocessor has a zero value ");
PostprocessorValue & to_adjuster = to_problem.getPostprocessorValue(to_postprocessor);

// decide if the adjustment should be performed
if (!performAdjustment(from_adjuster, to_adjuster))
return;

auto & to_var = to_problem.getVariable(
0, _to_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD);
Expand Down Expand Up @@ -461,3 +456,23 @@ MultiAppConservativeTransfer::adjustTransferedSolution(FEProblemBase * from_prob
// Compute again so that the post-processor has the value with the updated solution
to_problem.computeUserObjectByName(EXEC_TRANSFER, to_postprocessor);
}

bool
MultiAppConservativeTransfer::performAdjustment(const PostprocessorValue & from,
const PostprocessorValue & to) const
{
if (from * to > 0)
return true;
else if (_allow_skipped_adjustment)
{
_console << COLOR_CYAN << "MultiApp '" << name()
<< ", skipping adjustment in conservative transfer " << std::endl;
return false;
}
else
mooseError("Adjustment postprocessors from: ",
from,
" to: ",
to,
" must both have the same sign and be different from 0");
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 1
ny = 1
[]

[Variables]
[u]
[]
[]

[Kernels]
[diff]
type = Diffusion
variable = u
[]
[]

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

[AuxVariables]
[var]
family = MONOMIAL
order = THIRD
[]
[]

[ICs]
[var_ic]
type = FunctionIC
variable = var
function = '-exp(x * y)'
[]
[]

[Executioner]
type = Steady
solve_type = 'PJFNK'
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[MultiApps]
[sub]
type = FullSolveMultiApp
input_files = secondary_negative_adjuster.i
execute_on = timestep_end
[]
[]

[Postprocessors]
[from_postprocessor]
type = ElementIntegralVariablePostprocessor
variable = var
execute_on = 'TIMESTEP_BEGIN'
[]
[]

[Transfers]
[to_sub]
type = MultiAppMeshFunctionTransfer
direction = to_multiapp
source_variable = var
variable = var
multi_app = sub
from_postprocessors_to_be_preserved = 'from_postprocessor'
to_postprocessors_to_be_preserved = 'to_postprocessor'
[]
[]

[Outputs]
exodus = true
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 1
ny = 1
[]

[Variables]
[u]
[]
[]

[Kernels]
[diff]
type = Diffusion
variable = u
[]
[]

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

[AuxVariables]
[var]
family = MONOMIAL
order = THIRD
[]
[]

[ICs]
[var_ic]
type = FunctionIC
variable = var
function = '-exp(x * y)'
[]
[]

[Executioner]
type = Steady
solve_type = 'PJFNK'
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[MultiApps]
[sub]
type = FullSolveMultiApp
input_files = secondary_negative_adjuster.i
execute_on = timestep_begin
[]
[]

[Postprocessors]
[from_postprocessor]
type = ElementIntegralVariablePostprocessor
variable = var
execute_on = 'TIMESTEP_BEGIN'
[]
[]

[Transfers]
[to_sub]
type = MultiAppMeshFunctionTransfer
direction = to_multiapp
source_variable = var
variable = var
multi_app = sub
from_postprocessors_to_be_preserved = 'from_postprocessor'
to_postprocessors_to_be_preserved = 'to_postprocessor'
allow_skipped_adjustment = true
[]
[]

[Outputs]
exodus = true
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 20
ny = 20
[]

[Variables]
[u]
[]
[]

[Kernels]
[diff]
type = Diffusion
variable = u
[]
[]

[AuxVariables]
[var]
family = MONOMIAL
order = CONSTANT
[]
[]

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

[Postprocessors]
[to_postprocessor]
type = ElementIntegralVariablePostprocessor
variable = var
execute_on = 'transfer nonlinear TIMESTEP_END'
[]
[]

[Problem]
type = FEProblem
[]

[Executioner]
type = Steady
solve_type = 'PJFNK'
nl_abs_tol = 1e-12
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[Outputs]
exodus = true
[]

0 comments on commit 85de18c

Please sign in to comment.