LCOV - code coverage report
Current view: top level - src/materials - ElectromagneticHeatingMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose heat_transfer: #32971 (54bef8) with base c6cf66 Lines: 49 58 84.5 %
Date: 2026-05-29 20:37:03 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://www.mooseframework.org
       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 "ElectromagneticHeatingMaterial.h"
      11             : #include "FormulationEnums.h"
      12             : 
      13             : registerMooseObject("HeatTransferApp", ElectromagneticHeatingMaterial);
      14             : 
      15             : InputParameters
      16         183 : ElectromagneticHeatingMaterial::validParams()
      17             : {
      18         183 :   InputParameters params = ADMaterial::validParams();
      19         183 :   params.addClassDescription(
      20             :       "Material class used to provide the electric field as a material property and computes the "
      21             :       "residual contributions for electromagnetic/electrostatic heating objects.");
      22         366 :   params.addCoupledVar(
      23             :       "electric_field",
      24             :       "The electric field vector or electrostatic potential scalar to produce the field.");
      25         366 :   params.addCoupledVar(
      26             :       "complex_electric_field",
      27             :       "The complex component of the electric field vector for the time-harmonic formulation.");
      28         366 :   params.addParam<std::string>("electric_field_material_name",
      29             :                                "electric_field",
      30             :                                "User-specified material property name for the field.");
      31         366 :   params.addParam<std::string>("electric_field_heating_name",
      32             :                                "electric_field_heating",
      33             :                                "User-specified material property name for the Joule heating.");
      34         366 :   params.addParam<Real>("heating_scaling", 1.0, "Coefficient to multiply by heating term.");
      35         366 :   params.addParam<MaterialPropertyName>(
      36             :       "electrical_conductivity",
      37             :       "electrical_conductivity",
      38             :       "Material property providing electrical conductivity of the material.");
      39         366 :   MooseEnum formulation("time frequency", "time");
      40         366 :   MooseEnum solver("electrostatic electromagnetic", "electrostatic");
      41         366 :   params.addParam<MooseEnum>(
      42             :       "formulation",
      43             :       formulation,
      44             :       "The domain formulation of the Joule heating, time or frequency (default = time).");
      45         366 :   params.addParam<MooseEnum>(
      46             :       "solver", solver, "Electrostatic or electromagnetic field solver (default = electrostatic).");
      47         183 :   return params;
      48         183 : }
      49             : 
      50         141 : ElectromagneticHeatingMaterial::ElectromagneticHeatingMaterial(const InputParameters & parameters)
      51             :   : ADMaterial(parameters),
      52         141 :     _electric_field_var(*getFieldVar("electric_field", 0)),
      53         141 :     _is_vector(_electric_field_var.isVector()),
      54         141 :     _efield(_is_vector ? adCoupledVectorValue("electric_field") : _ad_grad_zero),
      55         141 :     _efield_complex(_is_vector ? adCoupledVectorValue("complex_electric_field") : _ad_grad_zero),
      56         141 :     _grad_potential(_is_vector ? _ad_grad_zero : adCoupledGradient("electric_field")),
      57         141 :     _electric_field(
      58         282 :         declareADProperty<RealVectorValue>(getParam<std::string>("electric_field_material_name"))),
      59         141 :     _electric_field_complex(declareADProperty<RealVectorValue>(
      60         282 :         getParam<std::string>("electric_field_material_name") + "_complex")),
      61         141 :     _electric_field_heating(
      62         282 :         declareADProperty<Real>(getParam<std::string>("electric_field_heating_name"))),
      63         282 :     _heating_scaling(getParam<Real>("heating_scaling")),
      64         282 :     _elec_cond(getADMaterialProperty<Real>("electrical_conductivity")),
      65         282 :     _formulation(getParam<MooseEnum>("formulation")),
      66         423 :     _solver(getParam<MooseEnum>("solver"))
      67             : {
      68         141 :   if ((_formulation == ElectromagneticFormulation::FREQUENCY) &&
      69           0 :       (_solver == ElectromagneticFormulation::ELECTROSTATIC))
      70             :   {
      71           0 :     mooseError("The frequency domain is selected, but the solver type is electrostatic! Please "
      72             :                "check input file.");
      73             :   }
      74             : 
      75         141 :   if ((_solver == ElectromagneticFormulation::ELECTROMAGNETIC) && !_is_vector)
      76             :   {
      77           0 :     mooseError("The solver type is electromagnetic, but only a scalar potential is provided! "
      78             :                "Please check input file.");
      79             :   }
      80             : 
      81         141 :   if ((_formulation == ElectromagneticFormulation::FREQUENCY) && !_is_vector)
      82             :   {
      83           0 :     mooseError("The frequency domain is selected, but only a scalar potential is provided! "
      84             :                "Please check input file.");
      85             :   }
      86         141 : }
      87             : 
      88             : void
      89      600000 : ElectromagneticHeatingMaterial::computeQpProperties()
      90             : {
      91      600000 :   computeFieldValue();
      92      600000 :   computeJouleHeating();
      93      600000 : }
      94             : 
      95             : void
      96      600000 : ElectromagneticHeatingMaterial::computeFieldValue()
      97             : {
      98      600000 :   if (_solver == ElectromagneticFormulation::ELECTROSTATIC)
      99     1200000 :     _electric_field[_qp] = -_grad_potential[_qp];
     100             :   else
     101           0 :     _electric_field[_qp] = _efield[_qp];
     102             : 
     103      600000 :   if (_formulation == ElectromagneticFormulation::FREQUENCY)
     104           0 :     _electric_field_complex[_qp] = _efield_complex[_qp];
     105      600000 : }
     106             : 
     107             : void
     108      600000 : ElectromagneticHeatingMaterial::computeJouleHeating()
     109             : {
     110      600000 :   if (_formulation == ElectromagneticFormulation::FREQUENCY)
     111           0 :     _electric_field_heating[_qp] = _heating_scaling * 0.5 * _elec_cond[_qp] *
     112           0 :                                    (_electric_field[_qp] * _electric_field[_qp] +
     113           0 :                                     _electric_field_complex[_qp] * _electric_field_complex[_qp]);
     114             :   else
     115      600000 :     _electric_field_heating[_qp] =
     116     1200000 :         _heating_scaling * _elec_cond[_qp] * _electric_field[_qp] * _electric_field[_qp];
     117      600000 : }

Generated by: LCOV version 1.14