https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
14#include "FunctionInterface.h"
15#include "UserObjectInterface.h"
18#include "ReporterInterface.h"
21#include "MooseObject.h"
22#include "MooseTypes.h"
23#include "Restartable.h"
25#include "ScalarCoupleable.h"
26#include "SetupInterface.h"
27#include "PerfGraphInterface.h"
28#include "SamplerInterface.h"
29
30#include "libmesh/parallel.h"
31
32class FEProblemBase;
33class SubProblem;
34class Assembly;
35class SystemBase;
36
38 public SetupInterface,
39 protected FunctionInterface,
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{
53public:
55
56 UserObjectBase(const InputParameters & params);
57 virtual ~UserObjectBase() = default;
58
59#ifdef MOOSE_KOKKOS_ENABLED
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 {
98 _communicator.sum(value);
99 }
100
107 template <typename T>
108 void gatherMax(T & value)
109 {
110 _communicator.max(value);
111 }
112
119 template <typename T>
120 void gatherMin(T & value)
121 {
122 _communicator.min(value);
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
166protected:
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
196private:
198 std::set<std::string> _supplied_uo;
199};
200
201template <typename T1, typename T2>
202void
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
217template <typename T1, typename T2>
218void
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}
unsigned int THREAD_ID
Definition MooseTypes.h:237
Keeps track of stuff related to assembling.
Definition Assembly.h:110
Interface for sorting dependent vectors of objects.
Interface for objects that need to use distributions.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Interface for objects that need to use functions.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Interface for notifications that the mesh has changed.
Interface for objects acting when the mesh has been displaced.
The Interface used to retrieve mesh meta data (attributes) set by the MeshGenerator system.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
Interface for objects interacting with the PerfGraph.
Interface class for classes which interact with Postprocessors.
Interface to allow object to consume Reporter values.
The Reporter system is comprised of objects that can contain any number of data values.
A class for creating restricted objects.
Definition Restartable.h:29
Interface for objects that need to use samplers.
Generic class for solving transient nonlinear problems.
Definition SubProblem.h:79
Base class for a system (of equations)
Definition SystemBase.h:87
unsigned int number() const
Gets the number of this system.
void max(const T &r, T &o, Request &req) const
void min(const T &r, T &o, Request &req) const
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
void gatherSum(T &value)
Gather the parallel sum of the variable passed in.
SubProblem & _subproblem
Reference to the Subproblem for this user object.
const std::set< std::string > & getSuppliedItems() override
Return a set containing the names of items owned by the object.
virtual void addPostprocessorDependencyHelper(const PostprocessorName &name) const override
Helper for deriving classes to override to add dependencies when a Postprocessor is requested.
void gatherMin(T &value)
Gather the parallel min of the variable passed in.
bool shouldDuplicateInitialExecution() const
Returns whether or not this user object should be executed twice during the initial condition when de...
std::set< std::string > _depend_uo
Depend UserObjects that to be used both for determining user object sorting and by AuxKernel for find...
void gatherProxyValueMax(T1 &proxy, T2 &value)
Deteremine the value of a variable according to the parallel maximum of the provided proxy.
void gatherMax(T &value)
Gather the parallel max of the variable passed in.
virtual void initialize()=0
Called before execute() is ever called so that data can be cleared.
Assembly & _assembly
Reference to the assembly object for this user object.
std::set< std::string > _supplied_uo
A name of the "supplied" user objects, which is just this object.
virtual bool needThreadedCopy() const
Whether or not a threaded copy of this object is needed when obtaining it in another object,...
static InputParameters validParams()
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
void gatherProxyValueMin(T1 &proxy, T2 &value)
Determine the value of a variable according to which process has the parallel minimum of the provided...
virtual void addVectorPostprocessorDependencyHelper(const VectorPostprocessorName &name) const override
Helper for deriving classes to override to add dependencies when a VectorPostprocessor is requested.
virtual void addUserObjectDependencyHelper(const UserObjectBase &uo) const override
Helper for deriving classes to override to add dependencies when a UserObject is requested.
const std::set< std::string > & getRequestedItems() override
Return a set containing the names of items requested by the object.
SubProblem & getSubProblem() const
Returns a reference to the subproblem that this postprocessor is tied to.
const bool _duplicate_initial_execution
Whether to execute this object twice on initial.
virtual void finalize()=0
Finalize.
void addReporterDependencyHelper(const ReporterName &reporter_name) override
A method that can be overridden to update the UO dependencies.
const THREAD_ID _tid
Thread ID of this postprocessor.
virtual ~UserObjectBase()=default
unsigned int systemNumber() const
std::set< UserObjectName > getDependObjects() const
Recursively return a set of user objects this user object depends on Note: this can be called only af...
SystemBase & _sys
Reference to the system object for this user object.
Interface for objects that need to use UserObjects.
const Parallel::Communicator & _communicator
processor_id_type n_processors() const