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 "KokkosMatCoupledForce.h" 11 : 12 : #include "MooseVariable.h" 13 : 14 : registerMooseObject("MooseApp", KokkosMatCoupledForce); 15 : 16 : InputParameters 17 9134 : KokkosMatCoupledForce::validParams() 18 : { 19 9134 : InputParameters params = Kernel::validParams(); 20 : 21 18268 : params.addClassDescription( 22 : "Implements a forcing term RHS of the form PDE = RHS, where RHS = Sum_j c_j * m_j * v_j. " 23 : "c_j, m_j, and v_j are provided as real coefficients, material properties, and coupled " 24 : "variables, respectively."); 25 36536 : params.addRequiredCoupledVar("v", "The coupled variables which provide the force"); 26 36536 : params.addParam<std::vector<Real>>( 27 : "coef", "Coefficents ($\\sigma$) multiplier for the coupled force term."); 28 27402 : params.addParam<std::vector<MaterialPropertyName>>("material_properties", 29 : "The coupled material properties."); 30 9134 : return params; 31 0 : } 32 : 33 48 : KokkosMatCoupledForce::KokkosMatCoupledForce(const InputParameters & parameters) 34 : : Kernel(parameters), 35 9 : _n_coupled(coupledComponents("v")), 36 18 : _coupled_props(isParamValid("material_properties")), 37 18 : _v_var(coupledIndices("v")), 38 18 : _v(kokkosCoupledValues("v")), 39 36 : _coef(isParamValid("coef") ? getParam<std::vector<Real>>("coef") 40 18 : : std::vector<Real>(_n_coupled, 1)) 41 : { 42 36 : for (const auto j : make_range(_n_coupled)) 43 : { 44 24 : _v_var_to_index[_v_var[j]] = j; 45 : 46 24 : if (_var.number() == _v_var[j]) 47 0 : paramError("v", 48 : "Coupled variable 'v' needs to be different from 'variable', consider using " 49 : "KokkosReaction or something similar"); 50 : } 51 : 52 12 : _v_var_to_index.copyToDevice(); 53 : 54 36 : if (isParamValid("coef") && _coef.size() != _n_coupled) 55 0 : paramError("coef", "Size of coef must be equal to size of v"); 56 : 57 12 : if (_coupled_props) 58 : { 59 12 : _mat_props.create(_n_coupled); 60 24 : const auto & names = getParam<std::vector<MaterialPropertyName>>("material_properties"); 61 12 : if (names.size() != _n_coupled) 62 0 : paramError("material_properties", "Size must be equal to number of coupled variables"); 63 36 : for (const auto j : make_range(_n_coupled)) 64 24 : _mat_props[j] = getKokkosMaterialPropertyByName<Real>(names[j]); 65 : } 66 12 : }