www.mooseframework.org
UserObjectInterface.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 #pragma once
11 
12 // MOOSE includes
13 #include "FEProblemBase.h"
14 #include "MooseTypes.h"
15 
16 // Forward declarations
17 class InputParameters;
18 class UserObject;
19 
20 #define adGetUserObject this->template getUserObject
21 
26 {
27 public:
34  UserObjectInterface(const MooseObject * moose_object);
35 
41  template <class T>
42  const T & getUserObject(const std::string & name);
43 
49  template <class T>
50  const T & getUserObjectByName(const std::string & name);
51 
57  const UserObject & getUserObjectBase(const std::string & name);
58 
64  const UserObject & getUserObjectBaseByName(const std::string & name);
65 
66 private:
69 
72 
75 
77  bool needThreadedCopy(const UserObject & uo) const;
78 };
79 
80 template <class T>
81 const T &
82 UserObjectInterface::getUserObject(const std::string & name)
83 {
84  unsigned int tid = needThreadedCopy(getUserObjectBase(name)) ? _uoi_tid : 0;
85  return _uoi_feproblem.getUserObject<T>(_uoi_params.get<UserObjectName>(name), tid);
86 }
87 
88 template <class T>
89 const T &
91 {
92  unsigned int tid = needThreadedCopy(getUserObjectBaseByName(name)) ? _uoi_tid : 0;
93  return _uoi_feproblem.getUserObject<T>(name, tid);
94 }
95 
T & getUserObject(const std::string &name, unsigned int tid=0) const
Get the user object by its name.
const T & getUserObject(const std::string &name)
Get an user object with a given parameter name.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const InputParameters & _uoi_params
Parameters of the object with this interface.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const T & getUserObjectByName(const std::string &name)
Get an user object with a given name.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:42
const UserObject & getUserObjectBaseByName(const std::string &name)
Get an user object with a given name.
Interface for objects that need to use UserObjects.
FEProblemBase & _uoi_feproblem
Reference to the FEProblemBase instance.
THREAD_ID _uoi_tid
Thread ID.
const UserObject & getUserObjectBase(const std::string &name)
Get an user object with a given parameter name.
bool needThreadedCopy(const UserObject &uo) const
Check if the threaded copy of the user object is needed.
Base class for user-specific data.
Definition: UserObject.h:37
unsigned int THREAD_ID
Definition: MooseTypes.h:161
UserObjectInterface(const MooseObject *moose_object)