-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Move CoupledGradientMaterial into framework and increase capabilities #30006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
GiudGiud
merged 10 commits into
idaholab:next
from
tophmatthews:coupled_grad_mat_ad_15915
Mar 31, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c860c61
move coupledgradientmaterial out of test
tophmatthews 9d45f26
flesh out coupledgradientmaterial
tophmatthews e300a74
simplify and rename params
tophmatthews c0331e6
fix test requirements
tophmatthews e61b0e3
review comments
tophmatthews 42be17d
doco update and finite volume protection
tophmatthews 0fd05b1
fix check for fv
tophmatthews 6687e9b
remove FV check
tophmatthews d6d6b0d
small fixups
tophmatthews 2b64a97
small review chnages
tophmatthews File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
framework/doc/content/source/materials/CoupledGradientMaterial.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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")) | ||
| { | ||
| } | ||
GiudGiud marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| template <bool is_ad> | ||
| void | ||
| CoupledGradientMaterialTempl<is_ad>::computeQpProperties() | ||
| { | ||
| _grad_mat_prop[_qp] = _grad_u[_qp] * _scalar_property_factor[_qp]; | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| [] |
1 change: 1 addition & 0 deletions
1
test/tests/materials/coupled_gradient_material/gold/ad_exact_out.e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| exact_out.e |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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." | ||
| [] | ||
| [] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.