https://mooseframework.inl.gov
UserObjectBase.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.addParamNamesToGroup("execute_on force_preaux force_postaux force_preic "
58  "allow_duplicate_execution_on_initial execution_order_group",
59  "Execution scheduling");
60  params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
61 
62  params.registerBase("UserObject");
63 
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  _tid(parameters.get<THREAD_ID>("_tid")),
83  _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
84  _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
85  _sys(*getCheckedPointerParam<SystemBase *>("_sys")),
86  _assembly(_subproblem.assembly(_tid, 0)),
87  _duplicate_initial_execution(getParam<bool>("allow_duplicate_execution_on_initial"))
88 {
89  // Check the pre/post aux flag
90  if (getParam<bool>("force_preaux") && getParam<bool>("force_postaux"))
91  paramError("force_preaux",
92  "A user object may be specified as executing before or after "
93  "AuxKernels, not both.");
94 
95  _supplied_uo.insert(name());
96 }
97 
98 #ifdef MOOSE_KOKKOS_ENABLED
100  const Moose::Kokkos::FunctorCopy & key)
101  : MooseObject(object, key),
102  SetupInterface(object, key),
103  FunctionInterface(object, key),
104  UserObjectInterface(object, key),
105  PostprocessorInterface(object, key),
106  VectorPostprocessorInterface(object, key),
107  ReporterInterface(object, key),
108  DistributionInterface(object, key),
109  SamplerInterface(object, key),
110  Restartable(object, key),
111  MeshMetaDataInterface(object, key),
112  MeshChangedInterface(object, key),
113  MeshDisplacedInterface(object, key),
114  PerfGraphInterface(object, key),
115  _tid(object._tid),
116  _subproblem(object._subproblem),
117  _fe_problem(object._fe_problem),
118  _sys(object._sys),
119  _assembly(object._assembly),
120  _duplicate_initial_execution(object._duplicate_initial_execution)
121 {
122 }
123 #endif
124 
125 std::set<UserObjectName>
127 {
128  std::set<UserObjectName> all;
129  for (auto & v : _depend_uo)
130  {
131  all.insert(v);
133 
134  // Add dependencies of other objects, but don't allow it to call itself. This can happen
135  // through the PostprocessorInterface if a Postprocessor calls getPostprocessorValueByName
136  // with it's own name. This happens in the Receiver, which could use the FEProblem version of
137  // the get method, but this is a fix that prevents an infinite loop occurring by accident for
138  // future objects.
139  if (uo.name() != name())
140  {
141  auto uos = uo.getDependObjects();
142  for (auto & t : uos)
143  all.insert(t);
144  }
145  }
146  return all;
147 }
148 
149 void
151 {
152  _depend_uo.insert(uo.name());
153 }
154 
155 void
156 UserObjectBase::addPostprocessorDependencyHelper(const PostprocessorName & name) const
157 {
158  _depend_uo.insert(name);
159 }
160 
161 void
162 UserObjectBase::addVectorPostprocessorDependencyHelper(const VectorPostprocessorName & name) const
163 {
164  _depend_uo.insert(name);
165 }
166 
167 void
169 {
170  _depend_uo.insert(reporter_name.getObjectName());
171 }
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
virtual void addVectorPostprocessorDependencyHelper(const VectorPostprocessorName &name) const override
Helper for deriving classes to override to add dependencies when a VectorPostprocessor is requested...
static InputParameters validParams()
virtual void addUserObjectDependencyHelper(const UserObjectBase &uo) const override
Helper for deriving classes to override to add dependencies when a UserObject is requested.
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:467
Interface for objects acting when the mesh has been displaced.
static InputParameters validParams()
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.
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
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...
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:103
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.
const UserObjectBase & getUserObjectBaseByName(const UserObjectName &object_name, bool is_dependency=true) const
Get an user object with the name object_name.
Interface for objects that need to use UserObjects.
const std::string & getObjectName() const
Return the object name that produces the Reporter value.
Definition: ReporterName.C:41
static InputParameters validParams()
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.
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.
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...
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...
static InputParameters validParams()
Definition: MooseObject.C:25
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.
const Elem & get(const ElemType type_in)
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
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...