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 febebd4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions framework/include/userobject/UserObjectInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class UserObjectInterface
*/
const UserObject & getUserObjectBaseByName(const std::string & name);

protected:
/// Check if the threaded copy of the user object is needed
virtual bool needThreadedCopy(const UserObject & uo) const;

private:
/// Parameters of the object with this interface
const InputParameters & _uoi_params;
Expand All @@ -71,24 +75,21 @@ class UserObjectInterface

/// Thread ID
THREAD_ID _uoi_tid;

/// Check if the user object is a DiscreteElementUserObject
bool isDiscreteUserObject(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 febebd4

Please sign in to comment.