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 
27  params.addParam<bool>("use_displaced_mesh",
28  false,
29  "Whether or not this object should use the "
30  "displaced mesh for computation. Note that "
31  "in the case this is true but no "
32  "displacements are provided in the Mesh block "
33  "the undisplaced mesh will still be used.");
34 
35  // Execution parameters
36  params.addParam<bool>("allow_duplicate_execution_on_initial",
37  false,
38  "In the case where this UserObject is depended upon by an initial "
39  "condition, allow it to be executed twice during the initial setup (once "
40  "before the IC and again after mesh adaptivity (if applicable).");
41  params.declareControllable("enable");
42 
43  params.addParam<bool>("force_preaux", false, "Forces the UserObject to be executed in PREAUX");
44  params.addParam<bool>("force_postaux", false, "Forces the UserObject to be executed in POSTAUX");
45  params.addParam<bool>(
46  "force_preic", false, "Forces the UserObject to be executed in PREIC during initial setup");
47  params.addParam<int>(
48  "execution_order_group",
49  0,
50  "Execution order groups are executed in increasing order (e.g., the lowest "
51  "number is executed first). Note that negative group numbers may be used to execute groups "
52  "before the default (0) group. Please refer to the user object documentation "
53  "for ordering of user object execution within a group.");
54 
55  params.registerBase("UserObject");
56  params.registerSystemAttributeName("UserObject");
57 
58  params.addParamNamesToGroup("execute_on force_preaux force_postaux force_preic "
59  "allow_duplicate_execution_on_initial execution_order_group",
60  "Execution scheduling");
61  params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
62  return params;
63 }
64 
66  : MooseObject(parameters),
67  SetupInterface(this),
68  FunctionInterface(this),
69  UserObjectInterface(this),
72  ReporterInterface(this),
74  SamplerInterface(this),
75  Restartable(this, "UserObjects"),
77  MeshChangedInterface(parameters),
78  MeshDisplacedInterface(parameters),
79  PerfGraphInterface(this),
80  _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
81  _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
82  _sys(*getCheckedPointerParam<SystemBase *>("_sys")),
83  _tid(parameters.get<THREAD_ID>("_tid")),
84  _assembly(_subproblem.assembly(_tid, 0)),
85  _coord_sys(_assembly.coordSystem()),
86  _duplicate_initial_execution(getParam<bool>("allow_duplicate_execution_on_initial"))
87 {
88  // Check the pre/post aux flag
89  if (getParam<bool>("force_preaux") && getParam<bool>("force_postaux"))
90  paramError("force_preaux",
91  "A user object may be specified as executing before or after "
92  "AuxKernels, not both.");
93 
94  _supplied_uo.insert(name());
95 }
96 
97 std::set<UserObjectName>
99 {
100  std::set<UserObjectName> all;
101  for (auto & v : _depend_uo)
102  {
103  all.insert(v);
105 
106  // Add dependencies of other objects, but don't allow it to call itself. This can happen
107  // through the PostprocessorInterface if a Postprocessor calls getPostprocessorValueByName
108  // with it's own name. This happens in the Receiver, which could use the FEProblem version of
109  // the get method, but this is a fix that prevents an infinite loop occurring by accident for
110  // future objects.
111  if (uo.name() != name())
112  {
113  auto uos = uo.getDependObjects();
114  for (auto & t : uos)
115  all.insert(t);
116  }
117  }
118  return all;
119 }
120 
121 void
123 {
124  _depend_uo.insert(uo.name());
125 }
126 
127 void
128 UserObject::addPostprocessorDependencyHelper(const PostprocessorName & name) const
129 {
130  _depend_uo.insert(name);
131 }
132 
133 void
134 UserObject::addVectorPostprocessorDependencyHelper(const VectorPostprocessorName & name) const
135 {
136  _depend_uo.insert(name);
137 }
138 
139 void
141 {
142  _depend_uo.insert(reporter_name.getObjectName());
143 }
144 
145 void
147 {
148  if (!_primary_thread_copy && primary != this)
149  _primary_thread_copy = primary;
150 }
151 
152 unsigned int
154 {
155  return _sys.number();
156 }
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:146
static InputParameters validParams()
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...
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:34
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:134
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
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:28
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.
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 ...
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1159
const std::string & getObjectName() const
Return the object name that produces the Reporter value.
Definition: ReporterName.C:35
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:98
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:122
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
UserObject(const InputParameters &params)
Definition: UserObject.C:65
void addReporterDependencyHelper(const ReporterName &reporter_name) override
A method that can be overridden to update the UO dependencies.
Definition: UserObject.C:140
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:128
unsigned int systemNumber() const
Definition: UserObject.C:153
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