www.mooseframework.org
MultiAppVariableValueSamplePostprocessorTransfer.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "MooseMesh.h"
15 #include "MooseTypes.h"
16 #include "MooseVariableFE.h"
17 #include "MultiApp.h"
18 #include "SystemBase.h"
19 
20 #include "libmesh/meshfree_interpolation.h"
21 #include "libmesh/system.h"
22 
24 
25 template <>
28 {
30  params.addRequiredParam<PostprocessorName>(
31  "postprocessor",
32  "The name of the postprocessor in the MultiApp to transfer the value to. "
33  "This should most likely be a Reporter Postprocessor.");
34  params.addRequiredParam<VariableName>("source_variable", "The variable to transfer from.");
35  return params;
36 }
37 
39  const InputParameters & parameters)
40  : MultiAppTransfer(parameters),
41  _postprocessor_name(getParam<PostprocessorName>("postprocessor")),
42  _from_var_name(getParam<VariableName>("source_variable"))
43 {
44 }
45 
46 void
48 {
49  _console << "Beginning VariableValueSamplePostprocessorTransfer " << name() << std::endl;
50 
51  switch (_direction)
52  {
53  case TO_MULTIAPP:
54  {
55  FEProblemBase & from_problem = _multi_app->problemBase();
56  MooseVariable & from_var = from_problem.getStandardVariable(0, _from_var_name);
57  SystemBase & from_system_base = from_var.sys();
58  SubProblem & from_sub_problem = from_system_base.subproblem();
59 
60  MooseMesh & from_mesh = from_problem.mesh();
61 
62  std::unique_ptr<PointLocatorBase> pl = from_mesh.getPointLocator();
63 
64  pl->enable_out_of_mesh_mode();
65 
66  for (unsigned int i = 0; i < _multi_app->numGlobalApps(); i++)
67  {
68  Real value = -std::numeric_limits<Real>::max();
69 
70  { // Get the value of the variable at the point where this multiapp is in the master domain
71 
72  Point multi_app_position = _multi_app->position(i);
73 
74  std::vector<Point> point_vec(1, multi_app_position);
75 
76  // First find the element the hit lands in
77  const Elem * elem = (*pl)(multi_app_position);
78 
79  if (elem && elem->processor_id() == from_mesh.processor_id())
80  {
81  from_sub_problem.reinitElemPhys(elem, point_vec, 0);
82 
83  mooseAssert(from_var.sln().size() == 1, "No values in u!");
84  value = from_var.sln()[0];
85  }
86 
87  _communicator.max(value);
88  }
89 
90  if (_multi_app->hasLocalApp(i))
91  _multi_app->appProblemBase(i).getPostprocessorValue(_postprocessor_name) = value;
92  }
93 
94  break;
95  }
96  case FROM_MULTIAPP:
97  {
98  mooseError(
99  "Can't transfer a variable value from a MultiApp to a Postprocessor in the Master.");
100  break;
101  }
102  }
103 
104  _console << "Finished VariableValueSamplePostprocessorTransfer " << name() << std::endl;
105 }
registerMooseObject("MooseApp", MultiAppVariableValueSamplePostprocessorTransfer)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const FieldVariableValue & sln() const
element solutions
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
Base class for a system (of equations)
Definition: SystemBase.h:92
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...
Samples a variable&#39;s value in the Master domain at the point where the MultiApp is.
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:259
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:105
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:59
InputParameters validParams< MultiAppTransfer >()
Base class for all MultiAppTransfer objects.
virtual MooseMesh & mesh() override
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
virtual MooseVariable & getStandardVariable(THREAD_ID tid, const std::string &var_name) override
Returns the variable reference for requested MooseVariable which may be in any system.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
const MooseEnum _direction
Whether we&#39;re transferring to or from the MultiApp.
InputParameters validParams< MultiAppVariableValueSamplePostprocessorTransfer >()
SystemBase & sys()
Get the system this variable is part of.
virtual std::unique_ptr< PointLocatorBase > getPointLocator() const
Proxy function to get a (sub)PointLocator from either the underlying libMesh mesh (default)...
Definition: MooseMesh.C:2730
virtual void reinitElemPhys(const Elem *elem, const std::vector< Point > &phys_points_in_elem, THREAD_ID tid, bool suppress_displaced_init=false)=0