Skip to content

Commit

Permalink
Add a function vector functor material, refs idaholab#16809
Browse files Browse the repository at this point in the history
  • Loading branch information
GiudGiud committed Nov 16, 2021
1 parent 342a9f4 commit 2763a1f
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
36 changes: 36 additions & 0 deletions framework/include/materials/GenericFunctionVectorFunctorMaterial.h
@@ -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;
2 changes: 1 addition & 1 deletion framework/src/materials/GenericFunctionFunctorMaterial.C
Expand Up @@ -42,7 +42,7 @@ GenericFunctionFunctorMaterialTempl<is_ad>::GenericFunctionFunctorMaterialTempl(
unsigned int num_values = _prop_values.size();

if (num_names != num_values)
mooseError("Number of prop_names much match the number of prop_values for a "
mooseError("Number of prop_names must match the number of prop_values for a "
"GenericFunctionFunctorMaterial!");

_num_props = num_names;
Expand Down
69 changes: 69 additions & 0 deletions framework/src/materials/GenericFunctionVectorFunctorMaterial.C
@@ -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>;

0 comments on commit 2763a1f

Please sign in to comment.