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 committed Oct 16, 2020
1 parent 0317b51 commit 73f57ff
Show file tree
Hide file tree
Showing 11 changed files with 297 additions and 25 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;
};
59 changes: 37 additions & 22 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
PostprocessorValue & to_adjuster = to_problem.getPostprocessorValue(to_postprocessor);
if (MooseUtils::absoluteFuzzyLessEqual(to_adjuster, 0.))
mooseError("To postprocessor has a zero value ");

// 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");
}
2 changes: 1 addition & 1 deletion large_media
Submodule large_media updated 98 files
+ combined/disp.png
+ combined/dispx.png
+ combined/dispx_center_inner_hist.png
+ combined/dispx_center_inner_sobol.png
+ combined/dispx_center_outer_hist.png
+ combined/dispx_center_outer_sobol.png
+ combined/dispx_end_inner_hist.png
+ combined/dispx_end_inner_sobol.png
+ combined/dispx_end_outer_hist.png
+ combined/dispx_end_outer_sobol.png
+ combined/dispy.png
+ combined/dispz.png
+ combined/dispz_inner_hist.png
+ combined/dispz_inner_sobol.png
+ combined/dispz_outer_hist.png
+ combined/dispz_outer_sobol.png
+ combined/geom.png
+ combined/qoi.png
+ combined/sobol_total.png
+ combined/temp.png
+ combined/temp_center_inner_hist.png
+ combined/temp_center_inner_sobol.png
+ combined/temp_center_outer_hist.png
+ combined/temp_center_outer_sobol.png
+ combined/temp_end_inner_hist.png
+ combined/temp_end_inner_sobol.png
+ combined/temp_end_outer_hist.png
+ combined/temp_end_outer_sobol.png
+ framework/image_function/large_adapt.png
+ framework/image_function/small_3d.png
+ framework/image_function/small_adapt.png
+ framework/image_function/small_raw.png
+ framework/image_function/small_uniform.png
+ framework/scalar_constraint_kernel.pdf
+ gallery/soil.gif
+ hpc/hpcondemand_terminal.png
+ level_set/vortex_modified.gif
+ level_set/vortex_original.gif
+ multi_apps/multiapp_hierarchy.png
+ multi_apps/multiapp_hierarchy.pptx
+ parsed_subdomain_mesh/parsed_subdomain_mesh.png
+0 −323 stochastic_tools/cc_grid.svg
+0 −1,467 stochastic_tools/full_solve_memory_mpi.svg
+0 −1,278 stochastic_tools/full_solve_memory_serial.svg
+0 −1,074 stochastic_tools/full_solve_serial_time.svg
+0 −1,231 stochastic_tools/full_solve_time_mpi.svg
+0 −1,086 stochastic_tools/full_solve_time_serial.svg
+0 −1 stochastic_tools/nearest_point_normal_hist.svg
+0 −1 stochastic_tools/nearest_point_uniform_hist.svg
+0 −5,001 stochastic_tools/parameter_study/master_out_results_0002.csv
+0 −5,001 stochastic_tools/parameter_study/master_out_samples_0002.csv
+0 −5,001 stochastic_tools/parameter_study/nonlin_diff_react/nonlin_diff_react_master_normal_out_results_0002.csv
+0 −5,001 stochastic_tools/parameter_study/nonlin_diff_react/nonlin_diff_react_master_uniform_out_results_0002.csv
+0 −1 stochastic_tools/poly_chaos_normal_hist.svg
+0 −1 stochastic_tools/poly_chaos_uniform_hist.svg
+0 −683 stochastic_tools/smolyak_grid.svg
+ stochastic_tools/surrogates/combined/diff_trans_2d/animated.gif
+ stochastic_tools/surrogates/combined/diff_trans_2d/geometry.png
+0 −1 stochastic_tools/surrogates/combined/diff_trans_2d/np_max.svg
+0 −1 stochastic_tools/surrogates/combined/diff_trans_2d/np_min.svg
+0 −1 stochastic_tools/surrogates/combined/diff_trans_2d/pc_max.svg
+0 −1 stochastic_tools/surrogates/combined/diff_trans_2d/pc_min.svg
+0 −1 stochastic_tools/surrogates/combined/diff_trans_2d/pr_max.svg
+0 −1 stochastic_tools/surrogates/combined/diff_trans_2d/pr_min.svg
+0 −1 stochastic_tools/surrogates/pod_rb/2d_multireg_1.svg
+0 −1 stochastic_tools/surrogates/pod_rb/2d_multireg_8.svg
+ stochastic_tools/surrogates/pod_rb/2d_multiregion_geometry.png
+ stochastic_tools/surrogates/pod_rb/2d_multiregion_sol0.png
+ stochastic_tools/surrogates/pod_rb/2d_multiregion_sol1.png
+ stochastic_tools/surrogates/pod_rb/2d_multiregion_sol2.png
+0 −1 stochastic_tools/surrogates/poly_reg/poly_reg_example_normal_hist.svg
+0 −1 stochastic_tools/surrogates/poly_reg/poly_reg_example_normal_hist_outlier.svg
+0 −1 stochastic_tools/surrogates/poly_reg/poly_reg_example_uniform_hist.svg
+0 −443 stochastic_tools/tensor_grid.svg
+0 −1,335 stochastic_tools/transient_memory_mpi.svg
+0 −1,209 stochastic_tools/transient_memory_serial.svg
+0 −1,122 stochastic_tools/transient_mpi_time.svg
+0 −1,125 stochastic_tools/transient_serial_time.svg
+0 −0 stochatic_tools/memory_per_proc.svg
+0 −0 stochatic_tools/memory_total.svg
+ testing/training-webinar.png
+ tutorials/moose_add_del.png
+ tutorials/moose_contributors.png
+ tutorials/moose_team.png
+ tutorials/moose_users.png
+ tutorials/multiapp_hierarchy.png
+ tutorials/multiapp_hierarchy.png
+ xfem/efa1.png
+ xfem/efa2.png
+ xfem/efa3.png
+ xfem/efa_flow.png
+ xfem/image21.gif
+ xfem/image78.gif
+ xfem/image79.gif
+ xfem/merging.png
+ xfem/phantom_node_a.png
+ xfem/phantom_node_b.png
+ xfem/splitting.png
+ xfem/virtual_edge_merge.png
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[cnode]
type = ExtraNodesetGenerator
coord = '0.0 0.0 0.0'
new_boundary = 6
new_boundary = new_boundary_name
input = generated_mesh
[]
[snode]
Expand Down
2 changes: 1 addition & 1 deletion petsc
Submodule petsc updated from 9fa37e to 5ea3ab
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 73f57ff

Please sign in to comment.