14 #include "libmesh/int_range.h" 25 template <
typename T,
unsigned int state>
34 return &mpi.template getGenericMaterialProperty<T, false>(
name, state);
51 return &coupleable.coupledValue(
name);
63 return &coupleable.coupledValueOld(
name);
71 template <
typename... Args>
72 using type = std::tuple<Args...>;
75 template <
int N,
typename T>
76 static auto &
get(T && t)
78 return std::get<N>(t);
83 using size = std::tuple_size<T>;
86 template <
int I,
typename T>
87 using element =
typename std::tuple_element<I, T>::type;
91 template <
typename Tuple,
typename Output,
typename... Input>
98 template <
int I,
typename T,
typename... Names>
103 void copy(
const unsigned int nqp);
108 template <
typename... Names>
112 construct<0, Names...>(std::forward<Names>(names)...);
183 template <
typename Tuple,
typename Output,
typename... Input>
184 template <
int I,
typename T,
typename... Names>
189 typedef typename std::tuple_element<I, std::tuple<Input...>>::type CurrentElement;
190 std::get<I>(_input_ptr) = CurrentElement::getPointer(*
this,
name);
193 if constexpr (
sizeof...(Names) > 0)
194 construct<I + 1, Names...>(std::forward<Names>(names)...);
197 template <
typename Tuple,
typename Output,
typename... Input>
204 Tuple::template get<I>(_input_data[_index + qp]) = (*std::get<I>(_input_ptr))[qp];
207 if constexpr (I + 1 <
sizeof...(Input))
211 template <
typename Tuple,
typename Output,
typename... Input>
215 const auto it = _index_map.find(elem_id);
216 if (it == _index_map.end())
217 mooseError(
"Element ", elem_id,
" was not found in the index map for ",
name(),
".");
221 template <
typename Tuple,
typename Output,
typename... Input>
228 _output_ready =
false;
231 template <
typename Tuple,
typename Output,
typename... Input>
239 _index_map[_current_elem->id()] = _index;
242 const auto nqp = _qrule->n_points();
243 if (_input_data.size() < _index + nqp)
244 _input_data.resize(_index + nqp);
251 template <
typename Tuple,
typename Output,
typename... Input>
260 for (
const auto & [
id, index] : bm._index_map)
261 _index_map[id] = index + _index;
264 const auto capacity = _input_data.capacity();
265 if (capacity < _index + bm._index)
266 _input_data.reserve(_index + bm._index);
269 _input_data.insert(std::begin(_input_data) + _index,
270 std::begin(bm._input_data),
271 std::begin(bm._input_data) + bm._index);
275 template <
typename Tuple,
typename Output,
typename... Input>
284 _input_data.resize(_index);
285 _output_data.resize(_index);
288 _output_ready =
true;
std::string name(const ElemQuality q)
void initialize() override final
data structures are initialized here
virtual void batchCompute()=0
override this method to implement the computation on the batch data
static gather_type * getPointer(const C &coupleable, const VariableName &name)
void threadJoin(const UserObject &uo) override final
Assemble data from all threads.
std::size_t _index
current element index
const MaterialProperty< T > gather_type
static gather_type * getPointer(M &mpi, const MaterialPropertyName &name)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
const InputVector & getInputData() const
get a reference to the input data
static InputParameters validParams()
OutputVector & setOutputData()
Get a writable reference to the output data.
bool shouldCompute(const SubProblem &)
Determine whether the NEML2 material model should be evaluated.
const VariableValue gather_type
OutputVector _output_data
Output data, written to in batchCompute()
virtual const std::string & name() const
Get the name of the class.
void construct(T &&name, Names &&... names)
Helper template for obtainig all variable and material property references.
bool outputReady() const
check if the output is fully computed and ready to be fetched
Based class for output objects.
std::tuple< typename Input::gather_type *... > _input_ptr
Output OutputType
The output type is directly specified as a template parameter.
BatchMaterial(const InputParameters ¶ms, Names &&... names)
const std::string & type() const
Get the type of this class.
Tuple::template type< typename Input::type... > InputType
input data needs to use a flexible tuple type (std::tuple or cuda::std::tuple)
std::map< dof_id_type, std::size_t > _index_map
map from element ID to index
const VariableValue gather_type
void execute() override final
All data is automatically gathered here.
std::tuple_size< T > size
std::vector< OutputType > OutputVector
The serialized batch data is stored in a vector.
OutputTools< Real >::VariableValue VariableValue
bool _output_ready
flag that indicates if _output_data has been fully computed
std::size_t getIndex(dof_id_type elem_id) const
get the index for the first qp of a specified element (other qps are at the following indices) ...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
BatchMaterial< Tuple, Output, Input... > BatchMaterialType
shorthand for the instantiated template type
IntRange< T > make_range(T beg, T end)
const OutputVector & getOutputData() const
Get a read-only reference to the output data.
static InputParameters validParams()
void copy(const unsigned int nqp)
Helper template for gathering all items into the input data tuples.
typename std::tuple_element< I, T >::type element
static gather_type * getPointer(const C &coupleable, const VariableName &name)
virtual bool shouldCompute()
Whether we should perform a batch compute.
void finalize() override final
we call batchCompute() from here
InputVector _input_data
Input data, utilized in batchCompute()
Base class for user-specific data.
std::tuple< Args... > type
std::vector< InputType > InputVector
The serialized batch data is stored in a vector.