https://mooseframework.inl.gov
Loading...
Searching...
No Matches
DistributedPositions.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
13
16{
18
19 params.addRequiredParam<std::vector<PositionsName>>(
20 "positions",
21 "Positions object. The last Positions is distributed over all the Positions prior in the "
22 "vector parameter.");
23
24 // Use position ordering from the distribution
25 params.set<bool>("auto_sort") = false;
26 // If the base position is broadcast already we do not need to
27 params.set<bool>("auto_broadcast") = false;
28 // Keep as up-to-date as possible given that the incoming position to distribute could be changing
29 params.set<ExecFlagEnum>("execute_on") = {EXEC_LINEAR, EXEC_TIMESTEP_BEGIN};
30
32 "Distribute positions, using translations, over one or more positions");
33 return params;
34}
35
37 : Positions(parameters)
38{
39 const auto & base_names = getParam<std::vector<PositionsName>>("positions");
40 for (const auto & base_name : base_names)
41 if (_fe_problem.hasUserObject(base_name))
42 _positions_objs.push_back(&_fe_problem.getPositionsObject(base_name));
43 else
44 mooseError("Positions ",
45 base_name,
46 " has not been created yet. If it exists, re-order Positions in the input "
47 "file or implement automated construction ordering");
48
49 // Obtain the positions from the nested positions objects, then transform them
50 initialize();
51 // Sort if needed (user-specified)
52 finalize();
53}
54
55void
57{
59 const bool initial = _fe_problem.getCurrentExecuteOnFlag() == EXEC_INITIAL;
60
61 // Check that everything is initialized
62 for (const auto * const pos_obj : _positions_objs)
63 if (!pos_obj->initialized(initial))
64 mooseError("Positions '", pos_obj->name(), "' is not initialized.");
65
66 // Size new positions vector
67 unsigned int n_positions = 1;
68 for (const auto * const pos_obj : _positions_objs)
69 {
70 const auto n_pos_obj = pos_obj->getNumPositions(initial);
71 if (n_pos_obj == 0)
72 paramError("positions", "Positions " + pos_obj->name() + " has 0 positions.");
73 n_positions *= pos_obj->getNumPositions(initial);
74 }
75 _positions.resize(n_positions);
76
77 // Fill _positions by distributing using translations
78 _positions[0] = Point(0, 0, 0);
79 unsigned int current_index = 1;
80 for (const auto pos_i : index_range(_positions_objs))
81 {
82 const auto * const current_positions = _positions_objs[_positions_objs.size() - 1 - pos_i];
83 for (const auto i : make_range(current_index))
84 {
85 unsigned int j = 0;
86 for (const auto & translation : current_positions->getPositions(initial))
87 _positions[i + (j++) * current_index] += translation;
88 }
89 current_index *= current_positions->getNumPositions(initial);
90 }
91
92 _initialized = true;
93}
registerMooseObject("MooseApp", DistributedPositions)
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_TIMESTEP_BEGIN
Definition Moose.C:37
const ExecFlagType EXEC_INITIAL
Definition Moose.C:30
const ExecFlagType EXEC_LINEAR
Definition Moose.C:31
Positions created by distributing Positions objects onto one another.
DistributedPositions(const InputParameters &parameters)
virtual void initialize() override
In charge of computing / loading the positions.
std::vector< const Positions * > _positions_objs
Pointers to positions objects that will be distributed.
static InputParameters validParams()
A MultiMooseEnum object to hold "execute_on" flags.
const Positions & getPositionsObject(const std::string &name) const
Get the Positions object by its name.
bool hasUserObject(const std::string &name) const
Check if there if a user object of given name.
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
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
Positions objects are under the hood Reporters.
Definition Positions.h:21
void clearPositions()
Clear all positions vectors.
Definition Positions.C:154
std::vector< Point > & _positions
For now, only the 1D vector will be shared across all ranks.
Definition Positions.h:92
static InputParameters validParams()
Definition Positions.C:15
virtual void finalize() override
In charge of reduction across all ranks & sorting for consistent output.
Definition Positions.C:220
bool _initialized
Whether the positions object has been initialized. This must be set by derived objects.
Definition Positions.h:116
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.