https://mooseframework.inl.gov
CurrentDensity.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 
10 #include "CurrentDensity.h"
11 
12 registerMooseObject("ElectromagneticsApp", CurrentDensity);
13 registerMooseObject("ElectromagneticsApp", ADCurrentDensity);
14 
15 template <bool is_ad>
18 {
20  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  params.addParam<bool>("electrostatic",
24  true,
25  "Whether the electric field is based on electrostatic potential or is "
26  "fully electromagnetic (default = TRUE)");
27  params.addCoupledVar("potential", "Electrostatic potential variable");
28  params.addCoupledVar("electric_field", "Electric field variable (electromagnetic)");
29  return params;
30 }
31 
32 template <bool is_ad>
34  : VectorAuxKernel(parameters),
35 
36  _is_es(getParam<bool>("electrostatic")),
37  _grad_potential(isParamValid("potential") ? coupledGradient("potential") : _grad_zero),
38  _electric_field(isParamValid("electric_field") ? coupledVectorValue("electric_field")
39  : _vector_zero),
40 
41  _conductivity(getGenericMaterialProperty<Real, is_ad>("electrical_conductivity"))
42 {
43  if (_is_es && !isParamValid("potential") && isParamValid("electric_field"))
44  {
45  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  else if (!_is_es && isParamValid("potential") && !isParamValid("electric_field"))
52  {
53  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  else if (isParamValid("potential") && isParamValid("electric_field"))
60  {
61  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 }
67 
68 template <bool is_ad>
71 {
72  if (_is_es)
73  return MetaPhysicL::raw_value(_conductivity[_qp]) * -_grad_potential[_qp];
74  else
75  return MetaPhysicL::raw_value(_conductivity[_qp]) * _electric_field[_qp];
76 }
77 
78 template class CurrentDensityTempl<false>;
79 template class CurrentDensityTempl<true>;
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
Calculates the current density vector field (in A/m^2) when given electrostatic potential (electrosta...
auto raw_value(const Eigen::Map< T > &in)
const bool & _is_es
Is the current density based on electrostatic potential?
virtual const std::string & name() const
CurrentDensityTempl(const InputParameters &parameters)
bool isParamValid(const std::string &name) const
void addCoupledVar(const std::string &name, const std::string &doc_string)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual RealVectorValue computeValue() override
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()
registerMooseObject("ElectromagneticsApp", CurrentDensity)
static InputParameters validParams()