Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions framework/doc/content/source/materials/CoupledGradientMaterial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# CoupledGradientMaterial / ADCoupledGradientMaterial

!syntax description /Materials/CoupledGradientMaterial

This material provides the ability to create a material property from the gradient of a variable. In addition, the gradient can be scaled with a scalar material property allows for additional flexibility. This gradient material property can then be used in kernels such as [ADConservativeAdvection](/ADConservativeAdvection.md).

## Example Input File Syntax

In this example, `CoupledGradientMaterial` is used to define a gradient material from the variable u, which is then multiplied by a scalar.

!listing test/tests/materials/coupled_gradient_material/exact.i block=Materials/mat

!syntax parameters /Materials/CoupledGradientMaterial

!syntax inputs /Materials/CoupledGradientMaterial

!syntax children /Materials/CoupledGradientMaterial
38 changes: 38 additions & 0 deletions framework/include/materials/CoupledGradientMaterial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//* This file is part of the MOOSE framework
//* https://mooseframework.inl.gov
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "Material.h"

/**
* A material that creates a gradient material equal to the gradient of the coupled variable
* times a scalar material property
*/
template <bool is_ad>
class CoupledGradientMaterialTempl : public Material
{
public:
static InputParameters validParams();

CoupledGradientMaterialTempl(const InputParameters & parameters);

protected:
virtual void computeQpProperties() override;

/// Material property computed, equal to the gradient of the variable times a scalar
GenericMaterialProperty<RealVectorValue, is_ad> & _grad_mat_prop;
/// A scalar material property that acts as a factor in the computed property
const GenericMaterialProperty<Real, is_ad> & _scalar_property_factor;
/// Gradient of the variable
const GenericVariableGradient<is_ad> & _grad_u;
};

typedef CoupledGradientMaterialTempl<false> CoupledGradientMaterial;
typedef CoupledGradientMaterialTempl<true> ADCoupledGradientMaterial;
51 changes: 51 additions & 0 deletions framework/src/materials/CoupledGradientMaterial.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//* This file is part of the MOOSE framework
//* https://mooseframework.inl.gov
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "CoupledGradientMaterial.h"

registerMooseObject("MooseApp", CoupledGradientMaterial);
registerMooseObject("MooseApp", ADCoupledGradientMaterial);

template <bool is_ad>
InputParameters
CoupledGradientMaterialTempl<is_ad>::validParams()
{
InputParameters params = Material::validParams();
params.addClassDescription("Creates a gradient material equal to the gradient of the coupled "
"variable times a scalar material property.");
params.addRequiredParam<MaterialPropertyName>(
"grad_mat_prop",
"Name of gradient material property equal to the gradient of the coupled variable gradient "
"times the scalar.");
params.deprecateParam("grad_mat_prop", "gradient_material_name", "12/12/25");
params.addParam<MaterialPropertyName>(
"scalar_property_factor",
1.0,
"Scalar material property acting as a factor in the output gradient material property.");
params.addRequiredCoupledVar("u", "The coupled variable to take the gradient of");
params.deprecateCoupledVar("u", "coupled_variable", "12/12/25");
return params;
}

template <bool is_ad>
CoupledGradientMaterialTempl<is_ad>::CoupledGradientMaterialTempl(
const InputParameters & parameters)
: Material(parameters),
_grad_mat_prop(declareGenericProperty<RealVectorValue, is_ad>("grad_mat_prop")),
_scalar_property_factor(getGenericMaterialProperty<Real, is_ad>("scalar_property_factor")),
_grad_u(coupledGenericGradient<is_ad>("u"))
{
}

template <bool is_ad>
void
CoupledGradientMaterialTempl<is_ad>::computeQpProperties()
{
_grad_mat_prop[_qp] = _grad_u[_qp] * _scalar_property_factor[_qp];
}
34 changes: 0 additions & 34 deletions test/include/materials/ADCoupledGradientMaterial.h

This file was deleted.

44 changes: 0 additions & 44 deletions test/src/materials/ADCoupledGradientMaterial.C

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@ diff=1.1
[]

[Materials]
[mat]
[mat_grad_u]
type = ADCoupledGradientMaterial
mat_prop = 'mat_u'
grad_mat_prop = 'mat_grad_u'
u = v
[]
[mat_u]
type = ADParsedMaterial
property_name = mat_u
coupled_variables = v
expression = v
[]
[]

[Functions]
Expand Down
9 changes: 7 additions & 2 deletions test/tests/fvkernels/mms/grad-reconstruction/mat-rz.i
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ diff=1.1
[]

[Materials]
[mat]
[mat_grad_u]
type = ADCoupledGradientMaterial
mat_prop = 'mat_u'
grad_mat_prop = 'mat_grad_u'
u = v
[]
[mat_u]
type = ADParsedMaterial
property_name = mat_u
coupled_variables = v
expression = v
[]
[]

[Functions]
Expand Down
93 changes: 93 additions & 0 deletions test/tests/materials/coupled_gradient_material/exact.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
AD = ''

[Mesh]
[gen]
type = GeneratedMeshGenerator
dim = 3
nx = 4
ny = 4
nz = 4
[]
[]

[Problem]
solve = false
[]

[AuxVariables]
[u]
[]
[u_gradient_x]
family = MONOMIAL
[]
[u_gradient_y]
family = MONOMIAL
[]
[u_gradient_z]
family = MONOMIAL
[]
[]

[AuxKernels]
[u_aux]
type = ParsedAux
variable = u
expression = 'x + y * 2 + z * 3'
use_xyzt = true
[]
[u_gradient_x]
type = ${AD}MaterialRealVectorValueAux
variable = u_gradient_x
property = gradient
component = 0
[]
[u_gradient_y]
type = ${AD}MaterialRealVectorValueAux
variable = u_gradient_y
property = gradient
component = 1
[]
[u_gradient_z]
type = ${AD}MaterialRealVectorValueAux
variable = u_gradient_z
property = gradient
component = 2
[]
[]

[Materials]
[mat]
type = ${AD}CoupledGradientMaterial
coupled_variable = u
gradient_material_name = gradient
outputs = all
scalar_property_factor = 0.5
[]
[]

[Postprocessors]
[u_avg]
type = ElementAverageValue
variable = u
[]
[u_gradient_x_avg]
type = ElementAverageValue
variable = u_gradient_x
[]
[u_gradient_y_avg]
type = ElementAverageValue
variable = u_gradient_y
[]
[u_gradient_z_avg]
type = ElementAverageValue
variable = u_gradient_z
[]
[]

[Executioner]
type = Steady
[]

[Outputs]
exodus = true
[]
Binary file not shown.
17 changes: 17 additions & 0 deletions test/tests/materials/coupled_gradient_material/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Tests]
design = 'CoupledGradientMaterial.md'
issues = '#15915'
[nonad]
type = Exodiff
input = exact.i
exodiff = exact_out.e
requirement = "The system shall be able to make a scalar and a gradient material property from a coupled variable."
[]
[ad]
type = Exodiff
input = exact.i
exodiff = ad_exact_out.e
cli_args = 'AD=AD Outputs/file_base=ad_exact_out'
requirement = "The system shall be able to make a scalar and a gradient material property from a coupled variable using automatic differentiation."
[]
[]