Line data Source code
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 :
10 : #include "KokkosAuxKernel.h"
11 :
12 : namespace Moose
13 : {
14 : namespace Kokkos
15 : {
16 :
17 : InputParameters
18 55948 : AuxKernel::validParams()
19 : {
20 55948 : InputParameters params = AuxKernelBase::validParams();
21 55948 : params.addPrivateParam<bool>(MooseBase::kokkos_object_param, true);
22 55948 : params.registerBase("KokkosAuxKernel");
23 55948 : return params;
24 0 : }
25 :
26 280 : AuxKernel::AuxKernel(const InputParameters & parameters)
27 : : ::AuxKernelBase(parameters),
28 202 : MeshHolder(*_mesh.getKokkosMesh()),
29 202 : AssemblyHolder(_sys.feProblem().kokkosAssembly()),
30 202 : SystemHolder(_sys.feProblem().getKokkosSystems()),
31 404 : _nodal(_var.isNodal()),
32 : _test(),
33 202 : _u(_var, Moose::SOLUTION_TAG, _var.isNodal()),
34 202 : _t(TransientInterface::_t),
35 202 : _t_old(TransientInterface::_t_old),
36 202 : _t_step(TransientInterface::_t_step),
37 202 : _dt(TransientInterface::_dt),
38 606 : _dt_old(TransientInterface::_dt_old)
39 : {
40 280 : if (!_nodal && _bnd)
41 0 : mooseError("Boundary restriction of a Kokkos AuxKernel is only supported for nodal variables.");
42 :
43 280 : auto tag = _sys.feProblem().addVectorTag("parallel_solution", Moose::VECTOR_TAG_SOLUTION);
44 :
45 280 : _kokkos_var.init(_var, tag);
46 280 : }
47 :
48 12747 : AuxKernel::AuxKernel(const AuxKernel & object)
49 : : ::AuxKernelBase(object, {}),
50 : MeshHolder(object),
51 : AssemblyHolder(object),
52 : SystemHolder(object),
53 10349 : _nodal(object._nodal),
54 10349 : _kokkos_var(object._kokkos_var),
55 10349 : _test(object._test),
56 10349 : _u(object._u),
57 10349 : _t(object._t),
58 10349 : _t_old(object._t_old),
59 10349 : _t_step(object._t_step),
60 10349 : _dt(object._dt),
61 20698 : _dt_old(object._dt_old)
62 : {
63 12747 : }
64 :
65 : void
66 12495 : AuxKernel::compute()
67 : {
68 12495 : if (_var.isNodal())
69 : {
70 8341 : Policy policy = _bnd ? Policy(0, numKokkosBoundaryNodes()) : Policy(0, numKokkosBlockNodes());
71 :
72 8341 : if (!_node_dispatcher)
73 140 : _node_dispatcher = DispatcherRegistry::build<NodeLoop>(this, type());
74 :
75 8341 : _node_dispatcher->parallelFor(policy);
76 8341 : }
77 : else
78 : {
79 4154 : Policy policy = Policy(0, numKokkosBlockElements());
80 :
81 4154 : if (!_element_dispatcher)
82 112 : _element_dispatcher = DispatcherRegistry::build<ElementLoop>(this, type());
83 :
84 4154 : _element_dispatcher->parallelFor(policy);
85 4154 : }
86 12495 : }
87 :
88 : VariableValue
89 24 : AuxKernel::uOld() const
90 : {
91 24 : _var.sys().needSolutionState(1);
92 :
93 24 : return VariableValue(_var, Moose::OLD_SOLUTION_TAG, isNodal());
94 : }
95 :
96 : VariableValue
97 12 : AuxKernel::uOlder() const
98 : {
99 12 : _var.sys().needSolutionState(2);
100 :
101 12 : return VariableValue(_var, Moose::OLDER_SOLUTION_TAG, isNodal());
102 : }
103 :
104 : void
105 112 : AuxKernel::getKokkosMaterialPropertyHook(const std::string & prop_name_in,
106 : const unsigned int /* state */)
107 : {
108 112 : if (isNodal())
109 0 : mooseError("Nodal KokkosAuxKernel '",
110 0 : name(),
111 : "' attempted to reference material property '",
112 : prop_name_in,
113 : "'\nConsider using an elemental auxiliary variable for '",
114 0 : _var.name(),
115 : "'.");
116 112 : }
117 :
118 : } // namespace Kokkos
119 : } // namespace Moose
|