Skip to content

Commit

Permalink
give threaded general user objects their own subclass
Browse files Browse the repository at this point in the history
Since a threaded (vs not) object requires very specific code handling,
we do not generally want the ability for objects to be dynamically
toggled between threaded vs not handling - this could easily result in
unintentional, subtle errors.  Also, the new general warehouse handling
of user objects will be much better served by this as an explicit
separate class.

ref idaholab#11834
  • Loading branch information
rwcarlsen committed Aug 10, 2018
1 parent 9d425eb commit 41962b4
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 16 deletions.
10 changes: 10 additions & 0 deletions framework/include/userobject/GeneralUserObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,14 @@ class GeneralUserObject : public UserObject,
std::set<std::string> _supplied_vars;
};

/// An instance of this object type has one copy per thread that runs on each thread.
class ThreadedGeneralUserObject : public GeneralUserObject
{
public:
ThreadedGeneralUserObject(const InputParameters & parameters) : GeneralUserObject(parameters) {}
virtual ~ThreadedGeneralUserObject() = default;
virtual void threadJoin(const UserObject &) override;
virtual void subdomainSetup() override{};
};

#endif
15 changes: 7 additions & 8 deletions framework/src/problems/FEProblemBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -2632,6 +2632,8 @@ FEProblemBase::addUserObject(std::string user_object_name,
std::shared_ptr<NodalUserObject> nuo = std::dynamic_pointer_cast<NodalUserObject>(user_object);
std::shared_ptr<GeneralUserObject> guo =
std::dynamic_pointer_cast<GeneralUserObject>(user_object);
std::shared_ptr<GeneralUserObject> tguo =
std::dynamic_pointer_cast<ThreadedGeneralUserObject>(user_object);

// Account for displaced mesh use
if (_displaced_problem != NULL && parameters.get<bool>("use_displaced_mesh"))
Expand All @@ -2643,15 +2645,12 @@ FEProblemBase::addUserObject(std::string user_object_name,
}

// Add the object to the correct warehouse
if (guo)
if (tguo)
_threaded_general_user_objects.addObject(guo, tid);
else if (guo)
{
if (guo->getParam<bool>("threaded"))
_threaded_general_user_objects.addObject(guo, tid);
else
{
_general_user_objects.addObject(guo);
break;
}
_general_user_objects.addObject(guo);
break;
}
else if (nuo)
_nodal_user_objects.addObject(nuo, tid);
Expand Down
8 changes: 6 additions & 2 deletions framework/src/userobject/GeneralUserObject.C
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ validParams<GeneralUserObject>()
{
InputParameters params = validParams<UserObject>();
params += validParams<MaterialPropertyInterface>();
params.addParam<bool>(
"threaded", false, "true if there should be threaded copies of this user object.");
params.addParam<bool>(
"force_preaux", false, "Forces the GeneralUserObject to be executed in PREAUX");
params.addParamNamesToGroup("force_preaux", "Advanced");
Expand Down Expand Up @@ -116,3 +114,9 @@ GeneralUserObject::subdomainSetup()
mooseError("GeneralUserObjects do not execute subdomainSetup method, this function does nothing "
"and should not be used.");
}

void
ThreadedGeneralUserObject::threadJoin(const UserObject &)
{
mooseError("ThreadedGeneralUserObject failed to override threadJoin");
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FluidProperties;
template <>
InputParameters validParams<FluidProperties>();

class FluidProperties : public GeneralUserObject
class FluidProperties : public ThreadedGeneralUserObject
{
public:
FluidProperties(const InputParameters & parameters);
Expand Down
4 changes: 2 additions & 2 deletions modules/fluid_properties/src/userobjects/FluidProperties.C
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ validParams<FluidProperties>()
{
InputParameters params = validParams<GeneralUserObject>();
params.registerBase("FluidProperties");
params.set<bool>("threaded") = true;
return params;
}

FluidProperties::FluidProperties(const InputParameters & parameters) : GeneralUserObject(parameters)
FluidProperties::FluidProperties(const InputParameters & parameters)
: ThreadedGeneralUserObject(parameters)
{
}

Expand Down
2 changes: 1 addition & 1 deletion test/include/userobjects/PrimeProductUserObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ InputParameters validParams<PrimeProductUserObject>();
* its thread ID. Then when threads join the product of all prime numbers is computed, which is the
* final value provided by this user object.
*/
class PrimeProductUserObject : public GeneralUserObject
class PrimeProductUserObject : public ThreadedGeneralUserObject
{
public:
PrimeProductUserObject(const InputParameters & params);
Expand Down
2 changes: 1 addition & 1 deletion test/src/userobjects/PrimeProductUserObject.C
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ validParams<PrimeProductUserObject>()
}

PrimeProductUserObject::PrimeProductUserObject(const InputParameters & params)
: GeneralUserObject(params)
: ThreadedGeneralUserObject(params)
{
if (libMesh::n_threads() > 20)
mooseError("This object works only with up to 20 threads. If you need more, add more prime "
Expand Down
1 change: 0 additions & 1 deletion test/tests/userobjects/threaded_general_user_object/test.i
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
[UserObjects]
[./prime_product]
type = PrimeProductUserObject
threaded = true
execute_on = timestep_end
[../]
[]
Expand Down

0 comments on commit 41962b4

Please sign in to comment.