https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MultiAppPostprocessorToAuxScalarTransfer.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
11
12// MOOSE includes
13#include "FEProblem.h"
14#include "MooseTypes.h"
15#include "MooseVariableScalar.h"
16#include "MultiApp.h"
17#include "SystemBase.h"
18
19#include "libmesh/meshfree_interpolation.h"
20#include "libmesh/system.h"
21
22// Define the input parameters
24
27{
29 params.addClassDescription("Transfers from a postprocessor to a scalar auxiliary variable.");
30 params.addRequiredParam<PostprocessorName>(
31 "from_postprocessor", "The name of the Postprocessor to transfer the value from.");
32 params.addRequiredParam<VariableName>(
33 "to_aux_scalar", "The name of the scalar AuxVariable to transfer the value to.");
35
36 return params;
37}
38
40 const InputParameters & parameters)
41 : MultiAppTransfer(parameters),
42 _from_pp_name(getParam<PostprocessorName>("from_postprocessor")),
43 _to_aux_name(getParam<VariableName>("to_aux_scalar"))
44{
45 if (_directions.size() != 1)
46 paramError("direction", "This transfer is only unidirectional");
47}
48
49void
51{
52 TIME_SECTION("MultiAppPostprocessorToAuxScalarTransfer::execute()",
53 5,
54 "Performing transfer between a scalar variable and a postprocessor");
55
56 // Execute the postprocessor if it was specified to execute on TRANSFER
57 switch (_current_direction)
58 {
59 case TO_MULTIAPP:
60 {
64 break;
65 }
66 case FROM_MULTIAPP:
68 }
69
70 // Perform action based on the transfer direction
71 switch (_current_direction)
72 {
73 // MultiApp -> MultiApp
75 {
76 for (unsigned int i = 0; i < getFromMultiApp()->numGlobalApps(); i++)
77 {
78 if (getFromMultiApp()->hasLocalApp(i))
79 {
80 // Extract the postprocessor that is being transferred
81 FEProblemBase & from_problem = getFromMultiApp()->appProblemBase(i);
82 Real pp_value = from_problem.getPostprocessorValueByName(_from_pp_name);
83
84 if (getToMultiApp()->hasLocalApp(i))
85 {
86 // Get reference to the AuxVariable where the postprocessor will be passed
87 MooseVariableScalar & scalar =
88 getToMultiApp()->appProblemBase(i).getScalarVariable(_tid, _to_aux_name);
89
90 scalar.reinit();
91
92 // Set all values of the AuxVariable to the value of the postprocessor
93 scalar.setValues(pp_value);
94
95 // Update the solution
96 scalar.insert(scalar.sys().solution());
97 scalar.sys().solution().close();
98 }
99 }
100 }
101 break;
102 }
103
104 // main app -> MultiApp
105 case TO_MULTIAPP:
106 {
107 // Extract the postprocessor that is being transferred
108 FEProblemBase & from_problem = getToMultiApp()->problemBase();
109 Real pp_value = from_problem.getPostprocessorValueByName(_from_pp_name);
110
111 // Loop through each of the sub apps
112 for (unsigned int i = 0; i < getToMultiApp()->numGlobalApps(); i++)
113 if (getToMultiApp()->hasLocalApp(i))
114 {
115 // Get reference to the AuxVariable where the postprocessor will be passed
116 MooseVariableScalar & scalar =
117 getToMultiApp()->appProblemBase(i).getScalarVariable(_tid, _to_aux_name);
118
119 scalar.reinit();
120
121 // Set all values of the AuxVariable to the value of the postprocessor
122 scalar.setValues(pp_value);
123
124 // Update the solution
125 scalar.insert(scalar.sys().solution());
126 scalar.sys().solution().close();
127 }
128 break;
129 }
130
131 // MultiApp -> main app
132 case FROM_MULTIAPP:
133 {
134 // The number of sub applications
135 unsigned int num_apps = getFromMultiApp()->numGlobalApps();
136
137 // The AuxVariable for storing the postprocessor values from the sub app
138 MooseVariableScalar & scalar =
139 getFromMultiApp()->problemBase().getScalarVariable(_tid, _to_aux_name);
140
141 // Ensure that the variable is up to date
142 scalar.reinit();
143
144 // The dof indices for the scalar variable of interest
145 auto && dof = scalar.dofIndices();
146
147 // Error if there is a size mismatch between the scalar AuxVariable and the number of sub apps
148 if (num_apps != scalar.sln().size())
149 mooseError("The number of sub apps (",
150 num_apps,
151 ") must be equal to the order of the scalar AuxVariable (",
152 scalar.order(),
153 ")");
154
155 // Loop over each sub-app and populate the AuxVariable values from the postprocessors
156 for (unsigned int i = 0; i < getFromMultiApp()->numGlobalApps(); i++)
157 if (getFromMultiApp()->hasLocalApp(i) && getFromMultiApp()->isRootProcessor())
158 // Note: This can't be done using MooseScalarVariable::insert() because different
159 // processors will be setting dofs separately.
160 scalar.sys().solution().set(
161 dof[i],
162 getFromMultiApp()->appProblemBase(i).getPostprocessorValueByName(_from_pp_name));
163
164 scalar.sys().solution().close();
165
166 break;
167 }
168 }
169}
170
171void
173{
174 // Check that we are in the supported configuration: same number of source and target apps
175 // The allocation of the child apps on the processors must be the same
176 if (getFromMultiApp()->numGlobalApps() == getToMultiApp()->numGlobalApps())
177 {
178 for (const auto i : make_range(getToMultiApp()->numGlobalApps()))
179 if (getFromMultiApp()->hasLocalApp(i) + getToMultiApp()->hasLocalApp(i) == 1)
180 mooseError("Child application allocation on parallel processes must be the same to support "
181 "siblings postprocessor to scalar variable transfer");
182 }
183 else
184 mooseError("Number of source and target child apps must match for siblings transfer");
185}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
const ExecFlagType EXEC_TRANSFER
Definition Moose.C:57
registerMooseObject("MooseApp", MultiAppPostprocessorToAuxScalarTransfer)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name, std::size_t t_index=0) const
Get a read-only reference to the value associated with a Postprocessor that exists.
virtual void computeUserObjectByName(const ExecFlagType &type, const Moose::AuxGroup &group, const std::string &name)
Compute an user object with the given name.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
virtual const std::vector< dof_id_type > & dofIndices() const
Get local DoF indices.
SystemBase & sys()
Get the system this variable is part of.
libMesh::Order order() const
Get the order of this variable Note: Order enum can be implicitly converted to unsigned int.
Class for scalar variables (they are different).
const VariableValue & sln() const
void insert(NumericVector< Number > &soln)
void reinit(bool reinit_for_derivative_reordering=false)
Fill out the VariableValue arrays from the system solution vector.
void setValues(Number value)
Set all of the values of this scalar variable to the same value.
Copies the value of a Postprocessor from one app to a scalar AuxVariable in another.
VariableName _to_aux_name
The name of the field variable to which the postprocessor is being transferred.
virtual void execute() override
Execute the transfer.
virtual void checkSiblingsTransferSupported() const override
Whether the transfer supports siblings transfer.
MultiAppPostprocessorToAuxScalarTransfer(const InputParameters &parameters)
PostprocessorName _from_pp_name
The name of the postprocessor that the transfer originates.
Base class for all MultiAppTransfer objects.
void errorIfObjectExecutesOnTransferInSourceApp(const std::string &object_name) const
Error if executing this MooseObject on EXEC_TRANSFER in a source multiapp (from_multiapp,...
static void addUserObjectExecutionCheckParam(InputParameters &params)
Add the execution order check parameter (to skip the warning if needed)
void checkParentAppUserObjectExecuteOn(const std::string &object_name) const
Checks the execute_on flags for user object transfers with user objects on the source app which is al...
const std::shared_ptr< MultiApp > getToMultiApp() const
Get the MultiApp to transfer data to.
static InputParameters validParams()
const std::shared_ptr< MultiApp > getFromMultiApp() const
Get the MultiApp to transfer data from.
unsigned int size() const
Return the number of active items in the MultiMooseEnum.
NumericVector< Number > & solution()
Definition SystemBase.h:203
@ FROM_MULTIAPP
Definition Transfer.h:71
@ TO_MULTIAPP
Definition Transfer.h:70
@ BETWEEN_MULTIAPP
Definition Transfer.h:72
MultiMooseEnum _directions
The directions this Transfer is to be executed on.
Definition Transfer.h:110
THREAD_ID _tid
Definition Transfer.h:100
FEProblemBase & _fe_problem
Definition Transfer.h:97
MooseEnum _current_direction
Definition Transfer.h:106
virtual void set(const numeric_index_type i, const T value)=0
virtual void close()=0
@ POST_AUX
Definition MooseTypes.h:761
@ PRE_AUX
Definition MooseTypes.h:760