Line data Source code
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 :
17 : InputParameters
18 1460545 : UserObjectBase::validParams()
19 : {
20 1460545 : InputParameters params = MooseObject::validParams();
21 1460545 : params += ReporterInterface::validParams();
22 :
23 : // Add the SetupInterface parameter, 'execute_on', and set it to a default of 'timestep_end'
24 1460545 : params += SetupInterface::validParams();
25 2921090 : params.set<ExecFlagEnum>("execute_on", true) = EXEC_TIMESTEP_END;
26 1460545 : ExecFlagEnum & exec_enum = params.set<ExecFlagEnum>("execute_on", true);
27 1460545 : exec_enum.addAvailableFlags(EXEC_TRANSFER);
28 :
29 4381635 : params.addParam<bool>("use_displaced_mesh",
30 2921090 : 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 2921090 : params.addParam<bool>("allow_duplicate_execution_on_initial",
39 2921090 : 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 4381635 : params.declareControllable("enable");
44 :
45 5842180 : params.addParam<bool>("force_preaux", false, "Forces the UserObject to be executed in PREAUX");
46 5842180 : params.addParam<bool>("force_postaux", false, "Forces the UserObject to be executed in POSTAUX");
47 4381635 : params.addParam<bool>(
48 2921090 : "force_preic", false, "Forces the UserObject to be executed in PREIC during initial setup");
49 4381635 : params.addParam<int>(
50 : "execution_order_group",
51 2921090 : 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 5842180 : params.addParamNamesToGroup("execute_on force_preaux force_postaux force_preic "
58 : "allow_duplicate_execution_on_initial execution_order_group",
59 : "Execution scheduling");
60 5842180 : params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
61 :
62 1460545 : params.registerBase("UserObject");
63 :
64 1460545 : return params;
65 0 : }
66 :
67 74911 : UserObjectBase::UserObjectBase(const InputParameters & parameters)
68 : : MooseObject(parameters),
69 : SetupInterface(this),
70 : FunctionInterface(this),
71 : UserObjectInterface(this),
72 : PostprocessorInterface(this),
73 : VectorPostprocessorInterface(this),
74 : ReporterInterface(this),
75 : DistributionInterface(this),
76 : SamplerInterface(this),
77 : Restartable(this, "UserObjects"),
78 : MeshMetaDataInterface(this),
79 : MeshChangedInterface(parameters),
80 : MeshDisplacedInterface(parameters),
81 : PerfGraphInterface(this),
82 74911 : _tid(parameters.get<THREAD_ID>("_tid")),
83 299644 : _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
84 299644 : _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
85 299644 : _sys(*getCheckedPointerParam<SystemBase *>("_sys")),
86 74911 : _assembly(_subproblem.assembly(_tid, 0)),
87 449466 : _duplicate_initial_execution(getParam<bool>("allow_duplicate_execution_on_initial"))
88 : {
89 : // Check the pre/post aux flag
90 225811 : if (getParam<bool>("force_preaux") && getParam<bool>("force_postaux"))
91 0 : paramError("force_preaux",
92 : "A user object may be specified as executing before or after "
93 : "AuxKernels, not both.");
94 :
95 74911 : _supplied_uo.insert(name());
96 74911 : }
97 :
98 : #ifdef MOOSE_KOKKOS_ENABLED
99 7931 : UserObjectBase::UserObjectBase(const UserObjectBase & object,
100 7931 : 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 7931 : _tid(object._tid),
116 7931 : _subproblem(object._subproblem),
117 7931 : _fe_problem(object._fe_problem),
118 7931 : _sys(object._sys),
119 7931 : _assembly(object._assembly),
120 7931 : _duplicate_initial_execution(object._duplicate_initial_execution)
121 : {
122 7931 : }
123 : #endif
124 :
125 : std::set<UserObjectName>
126 5119 : UserObjectBase::getDependObjects() const
127 : {
128 5119 : std::set<UserObjectName> all;
129 5192 : for (auto & v : _depend_uo)
130 : {
131 73 : all.insert(v);
132 73 : auto & uo = UserObjectInterface::getUserObjectBaseByName(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 73 : if (uo.name() != name())
140 : {
141 73 : auto uos = uo.getDependObjects();
142 86 : for (auto & t : uos)
143 13 : all.insert(t);
144 73 : }
145 : }
146 5119 : return all;
147 0 : }
148 :
149 : void
150 779 : UserObjectBase::addUserObjectDependencyHelper(const UserObjectBase & uo) const
151 : {
152 779 : _depend_uo.insert(uo.name());
153 779 : }
154 :
155 : void
156 7166 : UserObjectBase::addPostprocessorDependencyHelper(const PostprocessorName & name) const
157 : {
158 7166 : _depend_uo.insert(name);
159 7166 : }
160 :
161 : void
162 2155 : UserObjectBase::addVectorPostprocessorDependencyHelper(const VectorPostprocessorName & name) const
163 : {
164 2155 : _depend_uo.insert(name);
165 2155 : }
166 :
167 : void
168 761 : UserObjectBase::addReporterDependencyHelper(const ReporterName & reporter_name)
169 : {
170 761 : _depend_uo.insert(reporter_name.getObjectName());
171 761 : }
|