www.mooseframework.org
MultiAppVariableValueSamplePostprocessorTransfer.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
16 
17 // MOOSE includes
18 #include "FEProblem.h"
19 #include "MooseMesh.h"
20 #include "MooseTypes.h"
21 #include "MooseVariable.h"
22 #include "MultiApp.h"
23 #include "SystemBase.h"
24 
25 #include "libmesh/meshfree_interpolation.h"
26 #include "libmesh/system.h"
27 
28 template <>
31 {
33  params.addRequiredParam<PostprocessorName>(
34  "postprocessor",
35  "The name of the postprocessor in the MultiApp to transfer the value to. "
36  "This should most likely be a Reporter Postprocessor.");
37  params.addRequiredParam<VariableName>("source_variable", "The variable to transfer from.");
38  return params;
39 }
40 
42  const InputParameters & parameters)
43  : MultiAppTransfer(parameters),
44  _postprocessor_name(getParam<PostprocessorName>("postprocessor")),
45  _from_var_name(getParam<VariableName>("source_variable"))
46 {
47 }
48 
49 void
51 {
52  _console << "Beginning VariableValueSamplePostprocessorTransfer " << name() << std::endl;
53 
54  switch (_direction)
55  {
56  case TO_MULTIAPP:
57  {
58  FEProblemBase & from_problem = _multi_app->problemBase();
59  MooseVariable & from_var = from_problem.getVariable(0, _from_var_name);
60  SystemBase & from_system_base = from_var.sys();
61  SubProblem & from_sub_problem = from_system_base.subproblem();
62 
63  MooseMesh & from_mesh = from_problem.mesh();
64 
65  std::unique_ptr<PointLocatorBase> pl = from_mesh.getPointLocator();
66 
67  pl->enable_out_of_mesh_mode();
68 
69  for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
70  {
71  Real value = -std::numeric_limits<Real>::max();
72 
73  { // Get the value of the variable at the point where this multiapp is in the master domain
74 
75  Point multi_app_position = _multi_app->position(i);
76 
77  std::vector<Point> point_vec(1, multi_app_position);
78 
79  // First find the element the hit lands in
80  const Elem * elem = (*pl)(multi_app_position);
81 
82  if (elem && elem->processor_id() == from_mesh.processor_id())
83  {
84  from_sub_problem.reinitElemPhys(elem, point_vec, 0);
85 
86  mooseAssert(from_var.sln().size() == 1, "No values in u!");
87  value = from_var.sln()[0];
88  }
89 
90  _communicator.max(value);
91  }
92 
93  if (_multi_app->hasLocalApp(i))
94  _multi_app->appProblemBase(i).getPostprocessorValue(_postprocessor_name) = value;
95  }
96 
97  break;
98  }
99  case FROM_MULTIAPP:
100  {
101  mooseError(
102  "Can't transfer a variable value from a MultiApp to a Postprocessor in the Master.");
103  break;
104  }
105  }
106 
107  _console << "Finished VariableValueSamplePostprocessorTransfer " << name() << std::endl;
108 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
Class for stuff related to variables.
Definition: MooseVariable.h:43
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Base class for a system (of equations)
Definition: SystemBase.h:91
std::shared_ptr< MultiApp > _multi_app
The MultiApp this Transfer is transferring data to or from.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
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...
MooseEnum _direction
Whether we&#39;re transferring to or from the MultiApp.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
virtual SubProblem & subproblem()
Definition: SystemBase.h:103
virtual void reinitElemPhys(const Elem *elem, std::vector< Point > phys_points_in_elem, THREAD_ID tid)=0
virtual std::unique_ptr< PointLocatorBase > getPointLocator() const
Proxy function to get a (sub)PointLocator from either the underlying libmesh mesh (default)...
Definition: MooseMesh.C:2601
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:53
InputParameters validParams< MultiAppTransfer >()
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:250
Base class for all MultiAppTransfer objects.
const VariableValue & sln()
virtual MooseMesh & mesh() override
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
InputParameters validParams< MultiAppVariableValueSamplePostprocessorTransfer >()
SystemBase & sys()
Get the system this variable is part of.
virtual MooseVariable & getVariable(THREAD_ID tid, const std::string &var_name) override
Returns the variable reference for requested variable which may be in any system. ...