www.mooseframework.org
UserObject.h
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 
10 #pragma once
11 
12 // MOOSE includes
13 #include "DistributionInterface.h"
14 #include "FunctionInterface.h"
15 #include "MeshChangedInterface.h"
16 #include "MooseObject.h"
17 #include "MooseTypes.h"
18 #include "Restartable.h"
19 #include "ScalarCoupleable.h"
20 #include "SetupInterface.h"
21 #include "PerfGraphInterface.h"
22 
23 #include "libmesh/parallel.h"
24 
25 // Forward declarations
26 class UserObject;
27 class FEProblemBase;
28 class SubProblem;
29 class Assembly;
30 
31 template <>
33 
37 class UserObject : public MooseObject,
38  public SetupInterface,
39  public FunctionInterface,
40  public DistributionInterface,
41  public Restartable,
42  public MeshChangedInterface,
43  public ScalarCoupleable,
44  public PerfGraphInterface
45 {
46 public:
47  UserObject(const InputParameters & params);
48  virtual ~UserObject() = default;
49 
53  virtual void execute() = 0;
54 
58  virtual void initialize() = 0;
59 
64  virtual void finalize() = 0;
65 
70  SubProblem & getSubProblem() const { return _subproblem; }
71 
77 
83  virtual Real spatialValue(const Point & /*p*/) const
84  {
85  mooseError(name(), " does not satisfy the Spatial UserObject interface!");
86  }
87 
94  virtual void threadJoin(const UserObject & uo) = 0;
95 
102  template <typename T>
103  void gatherSum(T & value)
104  {
105  _communicator.sum(value);
106  }
107 
108  template <typename T>
109  void gatherMax(T & value)
110  {
111  _communicator.max(value);
112  }
113 
114  template <typename T>
115  void gatherMin(T & value)
116  {
117  _communicator.min(value);
118  }
119 
120  template <typename T1, typename T2>
121  void gatherProxyValueMax(T1 & value, T2 & proxy)
122  {
123  unsigned int rank;
124  _communicator.maxloc(value, rank);
125  _communicator.broadcast(proxy, rank);
126  }
127 
129  {
130  if (!_primary_thread_copy && primary != this)
131  _primary_thread_copy = primary;
132  }
133 
135 
136 protected:
139 
142 
146 
149 
151 
152 private:
154 };
155 
const bool _duplicate_initial_execution
Definition: UserObject.h:150
void gatherProxyValueMax(T1 &value, T2 &proxy)
Definition: UserObject.h:121
A class for creating restricted objects.
Definition: Restartable.h:29
Assembly & _assembly
Definition: UserObject.h:145
void setPrimaryThreadCopy(UserObject *primary)
Definition: UserObject.h:128
virtual ~UserObject()=default
Keeps track of stuff related to assembling.
Definition: Assembly.h:62
UserObject * primaryThreadCopy()
Definition: UserObject.h:134
UserObject * _primary_thread_copy
Definition: UserObject.h:153
void gatherMax(T &value)
Definition: UserObject.h:109
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void gatherMin(T &value)
Definition: UserObject.h:115
bool shouldDuplicateInitialExecution() const
Returns whether or not this user object should be executed twice during the initial condition when de...
Definition: UserObject.h:76
THREAD_ID _tid
Thread ID of this postprocessor.
Definition: UserObject.h:144
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
SubProblem & _subproblem
Reference to the Subproblem for this user object.
Definition: UserObject.h:138
virtual void execute()=0
Execute method.
Interface for notifications that the mesh has changed.
void gatherSum(T &value)
Gather the parallel sum of the variable passed in.
Definition: UserObject.h:103
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:42
InputParameters validParams< UserObject >()
Definition: UserObject.C:18
SubProblem & getSubProblem() const
Returns a reference to the subproblem that this postprocessor is tied to.
Definition: UserObject.h:70
Interface for objects that need to use distributions.
virtual void initialize()=0
Called before execute() is ever called so that data can be cleared.
Interface for objects that needs transient capabilities.
CoordinateSystemType
Definition: MooseTypes.h:556
virtual Real spatialValue(const Point &) const
Optional interface function for "evaluating" a UserObject at a spatial position.
Definition: UserObject.h:83
const Moose::CoordinateSystemType & _coord_sys
Coordinate system.
Definition: UserObject.h:148
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:59
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:141
UserObject(const InputParameters &params)
Definition: UserObject.C:48
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
virtual void finalize()=0
Finalize.
Interface for objects that needs scalar coupling capabilities.
Interface for objects that need to use functions.
Base class for user-specific data.
Definition: UserObject.h:37
unsigned int THREAD_ID
Definition: MooseTypes.h:161
virtual void threadJoin(const UserObject &uo)=0
Must override.