https://mooseframework.inl.gov
UserObject.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 "UserObject.h"
11 #include "SubProblem.h"
12 #include "Assembly.h"
13 #include "NonlinearSystemBase.h"
14 
15 #include "libmesh/sparse_matrix.h"
16 
19 {
22 
23  // Add the SetupInterface parameter, 'execute_on', and set it to a default of 'timestep_end'
24  params += SetupInterface::validParams();
25  params.set<ExecFlagEnum>("execute_on", true) = EXEC_TIMESTEP_END;
26  ExecFlagEnum & exec_enum = params.set<ExecFlagEnum>("execute_on", true);
28 
29  params.addParam<bool>("use_displaced_mesh",
30  false,
31  "Whether or not this object should use the "
32  "displaced mesh for computation. Note that "
33  "in the case this is true but no "
34  "displacements are provided in the Mesh block "
35  "the undisplaced mesh will still be used.");
36 
37  // Execution parameters
38  params.addParam<bool>("allow_duplicate_execution_on_initial",
39  false,
40  "In the case where this UserObject is depended upon by an initial "
41  "condition, allow it to be executed twice during the initial setup (once "
42  "before the IC and again after mesh adaptivity (if applicable).");
43  params.declareControllable("enable");
44 
45  params.addParam<bool>("force_preaux", false, "Forces the UserObject to be executed in PREAUX");
46  params.addParam<bool>("force_postaux", false, "Forces the UserObject to be executed in POSTAUX");
47  params.addParam<bool>(
48  "force_preic", false, "Forces the UserObject to be executed in PREIC during initial setup");
49  params.addParam<int>(
50  "execution_order_group",
51  0,
52  "Execution order groups are executed in increasing order (e.g., the lowest "
53  "number is executed first). Note that negative group numbers may be used to execute groups "
54  "before the default (0) group. Please refer to the user object documentation "
55  "for ordering of user object execution within a group.");
56 
57  params.registerBase("UserObject");
58  params.registerSystemAttributeName("UserObject");
59 
60  params.addParamNamesToGroup("execute_on force_preaux force_postaux force_preic "
61  "allow_duplicate_execution_on_initial execution_order_group",
62  "Execution scheduling");
63  params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
64  return params;
65 }
66 
68  : MooseObject(parameters),
69  SetupInterface(this),
70  FunctionInterface(this),
71  UserObjectInterface(this),
74  ReporterInterface(this),
76  SamplerInterface(this),
77  Restartable(this, "UserObjects"),
79  MeshChangedInterface(parameters),
80  MeshDisplacedInterface(parameters),
81  PerfGraphInterface(this),
82  _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
83  _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
84  _sys(*getCheckedPointerParam<SystemBase *>("_sys")),
85  _tid(parameters.get<THREAD_ID>("_tid")),
86  _assembly(_subproblem.assembly(_tid, 0)),
87  _coord_sys(_assembly.coordSystem()),
88  _duplicate_initial_execution(getParam<bool>("allow_duplicate_execution_on_initial"))
89 {
90  // Check the pre/post aux flag
91  if (getParam<bool>("force_preaux") && getParam<bool>("force_postaux"))
92  paramError("force_preaux",
93  "A user object may be specified as executing before or after "
94  "AuxKernels, not both.");
95 
96  _supplied_uo.insert(name());
97 }
98 
99 std::set<UserObjectName>
101 {
102  std::set<UserObjectName> all;
103  for (auto & v : _depend_uo)
104  {
105  all.insert(v);
107 
108  // Add dependencies of other objects, but don't allow it to call itself. This can happen
109  // through the PostprocessorInterface if a Postprocessor calls getPostprocessorValueByName
110  // with it's own name. This happens in the Receiver, which could use the FEProblem version of
111  // the get method, but this is a fix that prevents an infinite loop occurring by accident for
112  // future objects.
113  if (uo.name() != name())
114  {
115  auto uos = uo.getDependObjects();
116  for (auto & t : uos)
117  all.insert(t);
118  }
119  }
120  return all;
121 }
122 
123 void
125 {
126  _depend_uo.insert(uo.name());
127 }
128 
129 void
130 UserObject::addPostprocessorDependencyHelper(const PostprocessorName & name) const
131 {
132  _depend_uo.insert(name);
133 }
134 
135 void
136 UserObject::addVectorPostprocessorDependencyHelper(const VectorPostprocessorName & name) const
137 {
138  _depend_uo.insert(name);
139 }
140 
141 void
143 {
144  _depend_uo.insert(reporter_name.getObjectName());
145 }
146 
147 void
149 {
150  if (!_primary_thread_copy && primary != this)
151  _primary_thread_copy = primary;
152 }
153 
154 unsigned int
156 {
157  return _sys.number();
158 }
const ExecFlagType EXEC_TRANSFER
Definition: Moose.C:55
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
A class for creating restricted objects.
Definition: Restartable.h:28
void setPrimaryThreadCopy(UserObject *primary)
Definition: UserObject.C:148
static InputParameters validParams()
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:435
Interface for objects acting when the mesh has been displaced.
std::set< std::string > _supplied_uo
A name of the "supplied" user objects, which is just this object.
Definition: UserObject.h:234
UserObject * _primary_thread_copy
Definition: UserObject.h:231
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1155
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Interface for objects that need to use samplers.
void registerSystemAttributeName(const std::string &value)
This method is used to define the MOOSE system name that is used by the TheWarehouse object for stori...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addAvailableFlags(const ExecFlagType &flag, Args... flags)
Add additional execute_on flags to the list of possible flags.
Definition: ExecFlagEnum.h:82
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:36
Base class for a system (of equations)
Definition: SystemBase.h:84
virtual void addVectorPostprocessorDependencyHelper(const VectorPostprocessorName &name) const override
Helper for deriving classes to override to add dependencies when a VectorPostprocessor is requested...
Definition: UserObject.C:136
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:99
Interface for notifications that the mesh has changed.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:27
Interface for objects that need to use distributions.
Interface to allow object to consume Reporter values.
SystemBase & _sys
Reference to the system object for this user object.
Definition: UserObject.h:215
Interface for objects that need to use UserObjects.
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1149
const std::string & getObjectName() const
Return the object name that produces the Reporter value.
Definition: ReporterName.C:41
std::set< UserObjectName > getDependObjects() const
Recursively return a set of user objects this user object depends on Note: this can be called only af...
Definition: UserObject.C:100
static InputParameters validParams()
Interface for objects interacting with the PerfGraph.
std::set< std::string > _depend_uo
Depend UserObjects that to be used both for determining user object sorting and by AuxKernel for find...
Definition: UserObject.h:228
virtual void addUserObjectDependencyHelper(const UserObject &uo) const override
Helper for deriving classes to override to add dependencies when a UserObject is requested.
Definition: UserObject.C:124
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
UserObject(const InputParameters &params)
Definition: UserObject.C:67
void addReporterDependencyHelper(const ReporterName &reporter_name) override
A method that can be overridden to update the UO dependencies.
Definition: UserObject.C:142
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...
The Interface used to retrieve mesh meta data (attributes) set by the MeshGenerator system...
const UserObject & getUserObjectBaseByName(const UserObjectName &object_name, bool is_dependency=true) const
Get an user object with the name object_name.
static InputParameters validParams()
Definition: MooseObject.C:25
virtual void addPostprocessorDependencyHelper(const PostprocessorName &name) const override
Helper for deriving classes to override to add dependencies when a Postprocessor is requested...
Definition: UserObject.C:130
unsigned int systemNumber() const
Definition: UserObject.C:155
Interface for objects that need to use functions.
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
Declare the given parameters as controllable.
Base class for user-specific data.
Definition: UserObject.h:40
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:209
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
static InputParameters validParams()
Definition: UserObject.C:18