https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ADArrayReaction.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 "ADArrayReaction.h"
11#include "FEProblemBase.h"
13
15
18{
21 params.addRequiredParam<MaterialPropertyName>(
22 "reaction_coefficient",
23 "The name of the reaction (can be either a scalar, vector, or matrix) material property.");
25 "An automatic differentiation kernel for the array reaction operator ($r * u$)");
26 return params;
27}
28
30 : ADArrayKernel(parameters),
31 _r(hasADMaterialProperty<Real>("reaction_coefficient")
32 ? &getADMaterialProperty<Real>("reaction_coefficient")
33 : nullptr),
34 _r_array(hasADMaterialProperty<RealEigenVector>("reaction_coefficient")
35 ? &getADMaterialProperty<RealEigenVector>("reaction_coefficient")
36 : nullptr),
37 _r_2d_array(hasADMaterialProperty<RealEigenMatrix>("reaction_coefficient")
38 ? &getADMaterialProperty<RealEigenMatrix>("reaction_coefficient")
39 : nullptr)
40{
41 if (!_r && !_r_array && !_r_2d_array)
42 {
43 MaterialPropertyName mat = getParam<MaterialPropertyName>("reaction_coefficient");
44 mooseError("Property '" + mat + "' is of unsupported type for ADArrayReaction");
45 }
46}
47
48void
59
60void
61ADArrayReaction::computeQpResidual(ADRealEigenVector & residual)
62{
63 if (_r)
64 residual = (*_r)[_qp] * _u[_qp] * _test[_i][_qp];
65 else if (_r_array)
66 residual.noalias() = (*_r_array)[_qp].cwiseProduct(_u[_qp]) * _test[_i][_qp];
67 else
68 residual.noalias() = (*_r_2d_array)[_qp] * _u[_qp] * _test[_i][_qp];
69}
registerMooseObject("MooseApp", ADArrayReaction)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Base class for array variable (equation) kernels using automatic differentiation.
const unsigned int _count
Number of components of the array variable.
const ADArrayVariableValue & _u
Holds the solution at current quadrature points.
const ArrayVariableTestValue & _test
the current test function
static InputParameters validParams()
Array kernel for adding a reaction term.
virtual void computeQpResidual(ADRealEigenVector &residual) override
Compute this Kernel's contribution to the residual at the current quadrature point,...
const ADMaterialProperty< RealEigenVector > *const _r_array
array reaction coefficient
static InputParameters validParams()
const ADMaterialProperty< RealEigenMatrix > *const _r_2d_array
matrix of reaction coefficients (for cross reaction terms between array variables)
ADArrayReaction(const InputParameters &parameters)
const ADMaterialProperty< Real > * _r
scalar reaction coefficient
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
static InputParameters validParams()
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted,...
const std::set< SubdomainID > & meshBlockIDs() const
Return all of the SubdomainIDs for the mesh.
virtual bool blockRestricted() const
Returns true if this object has been restricted to a block.
const MaterialWarehouse & getMaterialWarehouse() const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
unsigned int _qp
The current quadrature point index.
Definition KernelBase.h:43
unsigned int _i
current index for the test function
Definition KernelBase.h:58
FEProblemBase & _fe_problem
Reference to this kernel's FEProblemBase.
void checkArrayMaterialPropertySize(const MooseObject &object, const MaterialWarehouse &warehouse, const std::set< SubdomainID > &blocks, const std::string &param_name, std::size_t count, bool is_matrix)
Check during setup that an array material property used as a coefficient has one entry per component ...