https://mooseframework.inl.gov
Loading...
Searching...
No Matches
NEML2BatchIndexGenerator.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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
11#include "NEML2Utils.h"
12
14
17{
18 auto params = ElementUserObject::validParams();
19 params.addClassDescription("Generates the element to batch index map for MOOSEToNEML2 gatherers, "
20 "NEML2ToMOOSE retrievers, and the NEML2 executor");
21
22 // Since we use the NEML2 model to evaluate the residual AND the Jacobian at the same time, we
23 // want to execute this user object only at execute_on = LINEAR (i.e. during residual evaluation).
24 // The NONLINEAR exec flag below is for computing Jacobian during automatic scaling.
26 execute_options = {EXEC_INITIAL, EXEC_LINEAR, EXEC_NONLINEAR};
27 params.set<ExecFlagEnum>("execute_on") = execute_options;
28
29 return params;
30}
31
33 : ElementUserObject(params), _outdated(true)
34{
35}
36
37void
42
43void
56
57void
59{
61 return;
62
63 if (!_outdated)
64 return;
65
67 _batch_index += _qrule->n_points();
68}
69
70void
72{
74 return;
75
76 if (!_outdated)
77 return;
78
79 const auto & m2n = static_cast<const NEML2BatchIndexGenerator &>(uo);
80
81 // append and renumber maps
82 for (const auto & [elem_id, batch_index] : m2n._elem_to_batch_index)
83 _elem_to_batch_index[elem_id] = _batch_index + batch_index;
84
86}
87
88void
93
94std::size_t
96{
97 // return cached map lookup if applicable
98 if (_elem_to_batch_index_cache.first == elem_id)
99 return _elem_to_batch_index_cache.second;
100
101 // else, search the map
102 const auto it = _elem_to_batch_index.find(elem_id);
103 if (it == _elem_to_batch_index.end())
104 mooseError("No batch index found for element id ", elem_id);
106 return it->second;
107}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
const ExecFlagType EXEC_INITIAL
Definition Moose.C:30
const ExecFlagType EXEC_LINEAR
Definition Moose.C:31
const ExecFlagType EXEC_NONLINEAR
Definition Moose.C:33
registerMooseObject("MooseApp", NEML2BatchIndexGenerator)
static InputParameters validParams()
const QBase *const & _qrule
const Elem *const & _current_elem
The current element pointer (available during execute())
A MultiMooseEnum object to hold "execute_on" flags.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
NEML2BatchIndexGenerator iterates over the mesh and generates a map from element ID to batch index wh...
void finalize() override
Finalize.
std::size_t _batch_index
Highest current batch index.
std::map< dof_id_type, std::size_t > _elem_to_batch_index
Map from element IDs to batch indices.
void initialize() override
Called before execute() is ever called so that data can be cleared.
void execute() override
Execute method.
void threadJoin(const UserObject &) override
Must override.
static InputParameters validParams()
std::size_t getBatchIndex() const
Get the current batch index (in almost all cases this is the total batch size)
void meshChanged() override
Called on this object when the mesh changes.
NEML2BatchIndexGenerator(const InputParameters &params)
bool _outdated
Whether the batch index map is outdated.
std::pair< dof_id_type, std::size_t > _elem_to_batch_index_cache
cache the index for the current element
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Base class for user-specific data.
Definition UserObject.h:20
ExecFlagEnum getDefaultExecFlagEnum()
Definition MooseUtils.C:972
bool shouldCompute(const SubProblem &)
Determine whether the NEML2 material model should be evaluated.
Definition NEML2Utils.C:53
const unsigned int invalid_uint