forked from idaholab/moose
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a function vector functor material, refs idaholab#16809
- Loading branch information
Showing
3 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
framework/include/materials/GenericFunctionVectorFunctorMaterial.h
This file contains 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,36 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* 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 "FunctorMaterial.h" | ||
|
||
/** | ||
* This material automatically declares as functor material properties whatever is passed to it | ||
* through the parameters 'prop_names' and uses the Functions from 'prop_values' as the values | ||
* for those properties. | ||
*/ | ||
template <bool is_ad> | ||
class GenericFunctionVectorFunctorMaterialTempl : public FunctorMaterial | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
GenericFunctionVectorFunctorMaterialTempl(const InputParameters & parameters); | ||
|
||
protected: | ||
std::vector<std::string> _prop_names; | ||
std::vector<FunctionName> _prop_values; | ||
|
||
unsigned int _num_props; | ||
std::vector<const Function *> _functions; | ||
}; | ||
|
||
typedef GenericFunctionVectorFunctorMaterialTempl<false> GenericFunctionVectorFunctorMaterial; | ||
typedef GenericFunctionVectorFunctorMaterialTempl<true> ADGenericFunctionVectorFunctorMaterial; |
This file contains 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
69 changes: 69 additions & 0 deletions
69
framework/src/materials/GenericFunctionVectorFunctorMaterial.C
This file contains 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,69 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* 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 "GenericFunctionVectorFunctorMaterial.h" | ||
#include "Function.h" | ||
|
||
registerMooseObject("MooseApp", GenericFunctionVectorFunctorMaterial); | ||
registerMooseObject("MooseApp", ADGenericFunctionVectorFunctorMaterial); | ||
|
||
template <bool is_ad> | ||
InputParameters | ||
GenericFunctionVectorFunctorMaterialTempl<is_ad>::validParams() | ||
{ | ||
InputParameters params = FunctorMaterial::validParams(); | ||
params += SetupInterface::validParams(); | ||
params.addClassDescription( | ||
"FunctorMaterial object for declaring vector properties that are populated by " | ||
"evaluation of Function object."); | ||
params.addParam<std::vector<std::string>>("prop_names", | ||
"The names of the properties this material will have"); | ||
params.addParam<std::vector<FunctionName>>("prop_values", | ||
"The corresponding names of the " | ||
"functions that are going to provide " | ||
"the values for the variables"); | ||
return params; | ||
} | ||
|
||
template <bool is_ad> | ||
GenericFunctionVectorFunctorMaterialTempl<is_ad>::GenericFunctionVectorFunctorMaterialTempl( | ||
const InputParameters & parameters) | ||
: FunctorMaterial(parameters), | ||
_prop_names(getParam<std::vector<std::string>>("prop_names")), | ||
_prop_values(getParam<std::vector<FunctionName>>("prop_values")) | ||
{ | ||
unsigned int num_names = _prop_names.size(); | ||
unsigned int num_values = _prop_values.size(); | ||
|
||
if (num_names * LIBMESH_DIM != num_values) | ||
mooseError("Number of prop_names times three must match the number of prop_values for a " | ||
"GenericFunctionVectorFunctorMaterial!"); | ||
|
||
_num_props = num_names; | ||
_functions.resize(num_values); | ||
|
||
for (const auto i : make_range(num_values)) | ||
_functions[i] = &getFunctionByName(_prop_values[i]); | ||
|
||
const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end()); | ||
for (const auto i : make_range(_num_props)) | ||
{ | ||
auto & prop = declareFunctorProperty<GenericRealVectorValue<is_ad>>(_prop_names[i]); | ||
prop.setFunctor( | ||
_mesh, blockIDs(), [this, i](const auto & r, const auto & t) -> GenericRealVectorValue<is_ad> { | ||
return {(*_functions[LIBMESH_DIM * i])(r, t), | ||
(*_functions[LIBMESH_DIM * i + 1])(r, t), | ||
(*_functions[LIBMESH_DIM * i + 2])(r, t)}; | ||
}); | ||
prop.setCacheClearanceSchedule(clearance_schedule); | ||
} | ||
} | ||
|
||
template class GenericFunctionVectorFunctorMaterialTempl<false>; | ||
template class GenericFunctionVectorFunctorMaterialTempl<true>; |