https://mooseframework.inl.gov
MultiAppPositions.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 
10 #include "MultiAppPositions.h"
11 #include "FEProblemBase.h"
12 #include "DisplacedProblem.h"
13 
15 
18 {
20  params.addRequiredParam<std::vector<MultiAppName>>(
21  "multiapps", "Name(s) of the multiapps providing the positions");
22  params.addParam<bool>("use_apps_centroid",
23  false,
24  "Whether to use the mesh centroid offset by the app position rather than "
25  "just the position of each child app");
26 
27  // Execute after multiapps have been created
28  params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL;
29  // Positions of subapps should stay ordered the same as the subapps
30  params.set<bool>("auto_sort") = false;
31  // Subapp positions are known for all processes already
32  params.set<bool>("auto_broadcast") = false;
33 
34  params.addClassDescription(
35  "Obtain positions from MultiApps. This may only be used to set the positions of those same "
36  "multiapps if an 'initial_positions' parameter is used.");
37  return params;
38 }
39 
41  : Positions(parameters), _use_apps_centroid(getParam<bool>("use_apps_centroid"))
42 {
43  // Centroids cannot be computed for non-local apps
45  _need_broadcast = true;
46 }
47 
48 void
50 {
52 
53  const auto & multiapps = getParam<std::vector<MultiAppName>>("multiapps");
54  _positions_2d.resize(multiapps.size());
55 
56  for (const auto m_it : index_range(multiapps))
57  {
58  const std::string & multiapp_name = multiapps[m_it];
59  const auto & multiapp = _fe_problem.getMultiApp(multiapp_name);
60 
61  for (const auto & i_global : make_range(multiapp->numGlobalApps()))
62  {
63  const auto p = multiapp->position(i_global);
64  if (!_use_apps_centroid)
65  {
66  _positions.push_back(p);
67  _positions_2d[m_it].push_back(p);
68  }
69  // Get the centroid of each subapp mesh
70  else
71  {
72  // Cant compute centroid if does not own the mesh
73  if (!multiapp->hasLocalApp(i_global))
74  continue;
75  auto & fe_problem_base = multiapp->appProblemBase(i_global);
76  const MeshBase & mesh = (getParam<bool>("use_displaced_mesh") &&
77  fe_problem_base.getDisplacedProblem().get() != NULL)
78  ? fe_problem_base.getDisplacedProblem()->mesh().getMesh()
79  : fe_problem_base.mesh().getMesh();
80  const Point centroid = MooseMeshUtils::meshCentroidCalculator(mesh);
81 
82  // There's a broadcast after, no need to add on every rank
83  if (multiapp->isFirstLocalRank())
84  {
85  _positions.push_back(p + centroid);
86  _positions_2d[m_it].push_back(p + centroid);
87  }
88  }
89  }
90  }
91  _initialized = true;
92 }
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
static InputParameters validParams()
Definition: Positions.C:15
void clearPositions()
Clear all positions vectors.
Definition: Positions.C:154
Positions objects are under the hood Reporters.
Definition: Positions.h:20
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
registerMooseObject("MooseApp", MultiAppPositions)
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...
std::shared_ptr< MultiApp > getMultiApp(const std::string &multi_app_name) const
Get a MultiApp object by name.
bool _initialized
Whether the positions object has been initialized. This must be set by derived objects.
Definition: Positions.h:116
std::vector< std::vector< Point > > _positions_2d
2D storage for all the positions
Definition: Positions.h:95
std::vector< Point > & _positions
For now, only the 1D vector will be shared across all ranks.
Definition: Positions.h:92
void initialize() override
In charge of computing / loading the positions.
bool _need_broadcast
Whether generation of positions is distributed or not (and therefore needs a broadcast) ...
Definition: Positions.h:108
const bool _use_apps_centroid
Whether to use the subapp mesh centroids to compute the positions, further translated by the position...
Positions from all the MultiApps.
static InputParameters validParams()
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:211
IntRange< T > make_range(T beg, T end)
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 addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
Point meshCentroidCalculator(const MeshBase &mesh)
Calculates the centroid of a MeshBase.
auto index_range(const T &sizable)
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:30
MultiAppPositions(const InputParameters &parameters)