https://mooseframework.inl.gov
UserObjectBase.h
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 #pragma once
11 
12 // MOOSE includes
13 #include "DistributionInterface.h"
14 #include "FunctionInterface.h"
15 #include "UserObjectInterface.h"
16 #include "PostprocessorInterface.h"
18 #include "ReporterInterface.h"
19 #include "MeshChangedInterface.h"
20 #include "MeshDisplacedInterface.h"
21 #include "MooseObject.h"
22 #include "MooseTypes.h"
23 #include "Restartable.h"
24 #include "MeshMetaDataInterface.h"
25 #include "ScalarCoupleable.h"
26 #include "SetupInterface.h"
27 #include "PerfGraphInterface.h"
28 #include "SamplerInterface.h"
29 
30 #include "libmesh/parallel.h"
31 
32 class FEProblemBase;
33 class SubProblem;
34 class Assembly;
35 class SystemBase;
36 
37 class UserObjectBase : public MooseObject,
38  public SetupInterface,
39  protected FunctionInterface,
40  public UserObjectInterface,
41  protected PostprocessorInterface,
43  protected ReporterInterface,
44  protected DistributionInterface,
45  protected SamplerInterface,
46  protected Restartable,
47  protected MeshMetaDataInterface,
48  protected MeshChangedInterface,
49  protected MeshDisplacedInterface,
50  protected PerfGraphInterface,
52 {
53 public:
55 
56  UserObjectBase(const InputParameters & params);
57  virtual ~UserObjectBase() = default;
58 
59 #ifdef MOOSE_KOKKOS_ENABLED
60 
63  UserObjectBase(const UserObjectBase & object, const Moose::Kokkos::FunctorCopy & key);
64 #endif
65 
69  virtual void initialize() = 0;
70 
75  virtual void finalize() = 0;
76 
81  SubProblem & getSubProblem() const { return _subproblem; }
82 
88 
95  template <typename T>
96  void gatherSum(T & value)
97  {
99  }
100 
107  template <typename T>
108  void gatherMax(T & value)
109  {
111  }
112 
119  template <typename T>
120  void gatherMin(T & value)
121  {
123  }
124 
131  template <typename T1, typename T2>
132  void gatherProxyValueMax(T1 & proxy, T2 & value);
133 
140  template <typename T1, typename T2>
141  void gatherProxyValueMin(T1 & proxy, T2 & value);
142 
147  std::set<UserObjectName> getDependObjects() const;
148 
149  const std::set<std::string> & getRequestedItems() override { return _depend_uo; }
150 
151  const std::set<std::string> & getSuppliedItems() override { return _supplied_uo; }
152 
156  unsigned int systemNumber() const { return _sys.number(); }
157 
164  virtual bool needThreadedCopy() const { return false; }
165 
166 protected:
167  virtual void addPostprocessorDependencyHelper(const PostprocessorName & name) const override;
168  virtual void
169  addVectorPostprocessorDependencyHelper(const VectorPostprocessorName & name) const override;
170  virtual void addUserObjectDependencyHelper(const UserObjectBase & uo) const override;
171  void addReporterDependencyHelper(const ReporterName & reporter_name) override;
172 
175 
178 
181 
185 
188 
191 
194  mutable std::set<std::string> _depend_uo;
195 
196 private:
198  std::set<std::string> _supplied_uo;
199 };
200 
201 template <typename T1, typename T2>
202 void
203 UserObjectBase::gatherProxyValueMax(T1 & proxy, T2 & value)
204 {
205  // Get all proxy, value pairs. _communicator.maxloc would be faster but leads to
206  // partitioning dependent results if the maximum proxy is not unique.
207  std::vector<std::pair<T1, T2>> all(n_processors());
208  const auto pair = std::make_pair(proxy, value);
209  _communicator.allgather(pair, all);
210 
211  // find maximum, disambiguated by the value
212  const auto it = std::max_element(all.begin(), all.end());
213  proxy = it->first;
214  value = it->second;
215 }
216 
217 template <typename T1, typename T2>
218 void
219 UserObjectBase::gatherProxyValueMin(T1 & proxy, T2 & value)
220 {
221  // get all proxy, value pairs
222  std::vector<std::pair<T1, T2>> all(n_processors());
223  const auto pair = std::make_pair(proxy, value);
224  _communicator.allgather(pair, all);
225 
226  // find minimum, disambiguated by the value
227  const auto it = std::min_element(all.begin(), all.end());
228  proxy = it->first;
229  value = it->second;
230 }
const THREAD_ID _tid
Thread ID of this postprocessor.
void gatherSum(T &value)
Gather the parallel sum of the variable passed in.
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
SubProblem & getSubProblem() const
Returns a reference to the subproblem that this postprocessor is tied to.
const std::set< std::string > & getRequestedItems() override
Return a set containing the names of items requested by the object.
A class for creating restricted objects.
Definition: Restartable.h:28
void gatherMax(T &value)
Gather the parallel max of the variable passed in.
virtual void addVectorPostprocessorDependencyHelper(const VectorPostprocessorName &name) const override
Helper for deriving classes to override to add dependencies when a VectorPostprocessor is requested...
Keeps track of stuff related to assembling.
Definition: Assembly.h:109
virtual void addUserObjectDependencyHelper(const UserObjectBase &uo) const override
Helper for deriving classes to override to add dependencies when a UserObject is requested.
Interface for objects acting when the mesh has been displaced.
static InputParameters validParams()
Interface for objects that need to use samplers.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::set< std::string > & getSuppliedItems() override
Return a set containing the names of items owned by the object.
const Parallel::Communicator & _communicator
std::set< std::string > _depend_uo
Depend UserObjects that to be used both for determining user object sorting and by AuxKernel for find...
Base class for a system (of equations)
Definition: SystemBase.h:85
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
std::set< UserObjectName > getDependObjects() const
Recursively return a set of user objects this user object depends on Note: this can be called only af...
bool shouldDuplicateInitialExecution() const
Returns whether or not this user object should be executed twice during the initial condition when de...
virtual void finalize()=0
Finalize.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
processor_id_type n_processors() const
const bool _duplicate_initial_execution
Whether to execute this object twice on initial.
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
Interface for notifications that the mesh has changed.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
void min(const T &r, T &o, Request &req) const
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
Interface for objects that need to use distributions.
Interface to allow object to consume Reporter values.
void gatherMin(T &value)
Gather the parallel min of the variable passed in.
Interface for objects that need to use UserObjects.
SubProblem & _subproblem
Reference to the Subproblem for this user object.
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1158
Assembly & _assembly
Reference to the assembly object for this user object.
Interface for objects interacting with the PerfGraph.
void addReporterDependencyHelper(const ReporterName &reporter_name) override
A method that can be overridden to update the UO dependencies.
virtual ~UserObjectBase()=default
SystemBase & _sys
Reference to the system object for this user object.
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
std::set< std::string > _supplied_uo
A name of the "supplied" user objects, which is just this object.
void max(const T &r, T &o, Request &req) const
UserObjectBase(const InputParameters &params)
virtual void addPostprocessorDependencyHelper(const PostprocessorName &name) const override
Helper for deriving classes to override to add dependencies when a Postprocessor is requested...
Interface for sorting dependent vectors of objects.
void gatherProxyValueMax(T1 &proxy, T2 &value)
Deteremine the value of a variable according to the parallel maximum of the provided proxy...
virtual void initialize()=0
Called before execute() is ever called so that data can be cleared.
virtual bool needThreadedCopy() const
Whether or not a threaded copy of this object is needed when obtaining it in another object...
The Interface used to retrieve mesh meta data (attributes) set by the MeshGenerator system...
void gatherProxyValueMin(T1 &proxy, T2 &value)
Determine the value of a variable according to which process has the parallel minimum of the provided...
Interface for objects that need to use functions.
The Reporter system is comprised of objects that can contain any number of data values.
Definition: ReporterName.h:30
Interface class for classes which interact with Postprocessors.
unsigned int THREAD_ID
Definition: MooseTypes.h:237
unsigned int systemNumber() const