Skip to content

Commit

Permalink
Get the right thread copy when requesting ThreadedGeneralUserObject
Browse files Browse the repository at this point in the history
When ThreadedGeneralUserObject is requested via UserObjectInterface, we
respect the thread ID and give users back the corresponding thread copy.

Refs idaholab#11834
  • Loading branch information
andrsd committed Aug 16, 2018
1 parent 49ec9ce commit 02862ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions framework/include/userobject/UserObjectInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,23 @@ class UserObjectInterface
/// Thread ID
THREAD_ID _uoi_tid;

/// Check if the user object is a DiscreteElementUserObject
bool isDiscreteUserObject(const UserObject & uo) const;
/// Check if the threaded copy of the user object is needed
bool needThreadedCopy(const UserObject & uo) const;
};

template <class T>
const T &
UserObjectInterface::getUserObject(const std::string & name)
{
unsigned int tid = isDiscreteUserObject(getUserObjectBase(name)) ? _uoi_tid : 0;
unsigned int tid = needThreadedCopy(getUserObjectBase(name)) ? _uoi_tid : 0;
return _uoi_feproblem.getUserObject<T>(_uoi_params.get<UserObjectName>(name), tid);
}

template <class T>
const T &
UserObjectInterface::getUserObjectByName(const std::string & name)
{
unsigned int tid = isDiscreteUserObject(getUserObjectBaseByName(name)) ? _uoi_tid : 0;
unsigned int tid = needThreadedCopy(getUserObjectBaseByName(name)) ? _uoi_tid : 0;
return _uoi_feproblem.getUserObject<T>(name, tid);
}

Expand Down
5 changes: 3 additions & 2 deletions framework/src/userobject/UserObjectInterface.C
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ UserObjectInterface::getUserObjectBaseByName(const std::string & name)
}

bool
UserObjectInterface::isDiscreteUserObject(const UserObject & uo) const
UserObjectInterface::needThreadedCopy(const UserObject & uo) const
{
return dynamic_cast<const DiscreteElementUserObject *>(&uo) != NULL;
return (dynamic_cast<const DiscreteElementUserObject *>(&uo) != NULL) ||
(dynamic_cast<const ThreadedGeneralUserObject *>(&uo) != NULL);
}

0 comments on commit 02862ae

Please sign in to comment.