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 "CurrentDensity.h" 11 : 12 : registerMooseObject("ElectromagneticsApp", CurrentDensity); 13 : registerMooseObject("ElectromagneticsApp", ADCurrentDensity); 14 : 15 : template <bool is_ad> 16 : InputParameters 17 129 : CurrentDensityTempl<is_ad>::validParams() 18 : { 19 129 : InputParameters params = VectorAuxKernel::validParams(); 20 129 : params.addClassDescription( 21 : "Calculates the current density vector field (in A/m^2) when given electrostatic " 22 : "potential (electrostatic = true, default) or electric field."); 23 258 : params.addParam<bool>("electrostatic", 24 258 : true, 25 : "Whether the electric field is based on electrostatic potential or is " 26 : "fully electromagnetic (default = TRUE)"); 27 258 : params.addCoupledVar("potential", "Electrostatic potential variable"); 28 258 : params.addCoupledVar("electric_field", "Electric field variable (electromagnetic)"); 29 129 : return params; 30 0 : } 31 : 32 : template <bool is_ad> 33 72 : CurrentDensityTempl<is_ad>::CurrentDensityTempl(const InputParameters & parameters) 34 : : VectorAuxKernel(parameters), 35 : 36 72 : _is_es(getParam<bool>("electrostatic")), 37 192 : _grad_potential(isParamValid("potential") ? coupledGradient("potential") : _grad_zero), 38 170 : _electric_field(isParamValid("electric_field") ? coupledVectorValue("electric_field") 39 : : _vector_zero), 40 : 41 144 : _conductivity(getGenericMaterialProperty<Real, is_ad>("electrical_conductivity")) 42 : { 43 172 : if (_is_es && !isParamValid("potential") && isParamValid("electric_field")) 44 : { 45 2 : mooseError( 46 : "In ", 47 : name(), 48 : ", an electric field vector variable has been provided when `electrostatic = TRUE`. Please " 49 : "either provide an electrostatic potential variable only or set `electrostatic = FALSE`!"); 50 : } 51 122 : else if (!_is_es && isParamValid("potential") && !isParamValid("electric_field")) 52 : { 53 2 : mooseError("In ", 54 : name(), 55 : ", an electrostatic potential variable has been provided when `electrostatic = " 56 : "FALSE`. Please either provide an electric field vector variable only or set " 57 : "`electrostatic = TRUE`!"); 58 : } 59 228 : else if (isParamValid("potential") && isParamValid("electric_field")) 60 : { 61 2 : mooseError("In ", 62 : name(), 63 : ", both electrostatic potential and electric field variables have been provided. " 64 : "Please only provide one or the other!"); 65 : } 66 66 : } 67 : 68 : template <bool is_ad> 69 : RealVectorValue 70 3218400 : CurrentDensityTempl<is_ad>::computeValue() 71 : { 72 3218400 : if (_is_es) 73 3175200 : return MetaPhysicL::raw_value(_conductivity[_qp]) * -_grad_potential[_qp]; 74 : else 75 43200 : return MetaPhysicL::raw_value(_conductivity[_qp]) * _electric_field[_qp]; 76 : } 77 : 78 : template class CurrentDensityTempl<false>; 79 : template class CurrentDensityTempl<true>;