UserObjectInterface
The UserObjectInterface defines the methods used for retrieving const references to the specific types of UserObjects. This is done with templated methods so that use of the UserObject does not require a dynamic cast. Many objects in MOOSE support the retrieval of these references so that custom UserObject APIs may be used in calculations. UserObjects are generally executed after most other systems in MOOSE so these values are often lagged when being used in another calculation.
End Use API
Most objects in MOOSE will retrieve UserObjects through special macro functions found here:
#define getUserObjectByName this->template getUserObjectByNameTempl
#define getUserObject this->template getUserObjectTempl
(framework/include/utils/MemberTemplateMacros.h)/opt/civet/build_0/moose/framework/include/utils/MemberTemplateMacros.h
// 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
// MooseObject
#define adGetParam \
_Pragma("GCC warning \"adGetParam is deprecated. Simply use getParam\"") this \
->template getParamTempl
#define getParam this->template getParamTempl
// UserObjectInterface
#define adGetUserObject \
_Pragma("GCC warning \"adGetUserObject is deprecated. Simply use getUserObject\"") this \
->template getUserObjectTempl
#define adGetUserObjectByName \
_Pragma( \
"GCC warning \"adGetUserObjectByName is deprecated. Simply use getUserObjectByName\"") this \
->template getUserObjectByNameTempl
// doco-user-object-interface-begin
#define getUserObjectByName this->template getUserObjectByNameTempl
#define getUserObject this->template getUserObjectTempl
// doco-user-object-interface-end
// MaterialPropertyInterface
#define adGetMaterialProperty \
_Pragma( \
"GCC warning \"adGetMaterialProperty is deprecated. Simply use getMaterialProperty\"") this \
->template getMaterialPropertyTempl
// clang-format off
#define adGetMaterialPropertyOld \
_Pragma( \
"GCC warning \"adGetMaterialPropertyOld is deprecated. Simply use getMaterialPropertyOld\"") \
this->template getMaterialPropertyOldTempl
#define adGetMaterialPropertyOlder \
_Pragma( \
"GCC warning \"adGetMaterialPropertyOlder is deprecated. Simply use getMaterialPropertyOlder\"") \
this->template getMaterialPropertyOlderTempl
#define adGetADMaterialProperty \
_Pragma( \
"GCC warning \"adGetADMaterialProperty is deprecated. Simply use getADMaterialProperty\"") \
this->template getADMaterialPropertyTempl
#define adGetADMaterialPropertyByName \
_Pragma( \
"GCC warning \"adGetADMaterialPropertyByName is deprecated. Simply use getADMaterialPropertyByName\"") \
this->template getADMaterialPropertyByNameTempl
#define adGetMaterialPropertyByName \
_Pragma( \
"GCC warning \"adGetMaterialPropertyByName is deprecated. Simply use getMaterialPropertyByName\"") \
this->template getMaterialPropertyByNameTempl
#define adGetMaterialPropertyOldByName \
_Pragma( \
"GCC warning \"adGetMaterialPropertyOldByName is deprecated. Simply use getMaterialPropertyOldByName\"") \
this->template getMaterialPropertyOldByNameTempl
#define adGetMaterialPropertyOlderByName \
_Pragma( \
"GCC warning \"adGetMaterialPropertyOlderByName is deprecated. Simply use getMaterialPropertyOlderByName\"") \
this->template getMaterialPropertyOlderByNameTempl
#define adHasMaterialProperty \
_Pragma( \
"GCC warning \"adHasMaterialProperty is deprecated. Simply use hasMaterialProperty\"") \
this->template hasMaterialPropertyTempl
#define adHasMaterialPropertyByName \
_Pragma( \
"GCC warning \"adHasMaterialPropertyByName is deprecated. Simply use hasMaterialPropertyByName\"") \
this->template hasMaterialPropertyByNameTempl
// clang-format on
#define adDeclareADProperty \
_Pragma("GCC warning \"adDeclareADProperty is deprecated. Simply use declareADProperty\"") this \
->template declareADPropertyTempl
#define adDeclareProperty \
_Pragma("GCC warning \"adDeclareProperty is deprecated. Simply use declareProperty\"") this \
->template declarePropertyTempl
#define getMaterialProperty this->template getMaterialPropertyTempl
#define getMaterialPropertyOld this->template getMaterialPropertyOldTempl
#define getMaterialPropertyOlder this->template getMaterialPropertyOlderTempl
#define declareADProperty this->template declareADPropertyTempl
#define declareProperty this->template declarePropertyTempl
#define getADMaterialProperty this->template getADMaterialPropertyTempl
#define getADMaterialPropertyByName this->template getADMaterialPropertyByNameTempl
#define getMaterialPropertyByName this->template getMaterialPropertyByNameTempl
#define getMaterialPropertyOldByName this->template getMaterialPropertyOldByNameTempl
#define getMaterialPropertyOlderByName this->template getMaterialPropertyOlderByNameTempl
#define hasMaterialProperty this->template hasMaterialPropertyTempl
#define hasMaterialPropertyByName this->template hasMaterialPropertyByNameTempl
// TwoMaterialPropertyInterface
// clang-format off
#define adGetNeighborMaterialProperty \
_Pragma( \
"GCC warning \"adGetNeighborMaterialProperty is deprecated. Simply use getNeighborMaterialProperty\"") \
this->template getNeighborMaterialPropertyTempl
#define adGetNeighborADMaterialProperty \
_Pragma( \
"GCC warning \"adGetNeighborADMaterialProperty is deprecated. Simply use getNeighborADMaterialProperty\"") \
this->template getNeighborADMaterialPropertyTempl
// clang-format on
#define getNeighborMaterialProperty this->template getNeighborMaterialPropertyTempl
#define getNeighborADMaterialProperty this->template getNeighborADMaterialPropertyTempl
#define getNeighborMaterialPropertyByName this->template getNeighborMaterialPropertyByNameTempl
// Restartable
// clang-format off
#define adDeclareRestartableData \
_Pragma( \
"GCC warning \"adDeclareRestartableData is deprecated. Simply use declareRestartableData\"") \
this->template declareRestartableDataTempl
// clang-format on
#define declareRestartableData this->template declareRestartableDataTempl
Typical usage looks like this:
_elem_uo(getUserObject<ElementUOProvider>("element_user_object")),
(test/src/auxkernels/ElementUOAux.C)/opt/civet/build_0/moose/test/src/auxkernels/ElementUOAux.C
// 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 "ElementUOAux.h"
#include "ElementUOProvider.h"
registerMooseObject("MooseTestApp", ElementUOAux);
InputParameters
ElementUOAux::validParams()
{
InputParameters params = AuxKernel::validParams();
params.addRequiredParam<UserObjectName>("element_user_object",
"The ElementUOProvider where this Aux pulls values from");
params.addParam<std::string>("field_name",
"The field name to retrieve from the ElementUOProvider");
MooseEnum field_type("long Real", "long");
params.addParam<MooseEnum>("field_type", field_type, "The type of field to retrieve");
params.set<ExecFlagEnum>("execute_on") = EXEC_TIMESTEP_BEGIN;
params.addClassDescription("Aux Kernel to display generic spatial (elemental) information from a "
"UserObject that satisfies the underlying ElementUOProvider "
"interface.");
return params;
}
ElementUOAux::ElementUOAux(const InputParameters & params)
: AuxKernel(params),
// doco-get-user-object-begin
_elem_uo(getUserObject<ElementUOProvider>("element_user_object")),
// doco-get-user-object-end
_field_name(isParamValid("field_name") ? getParam<std::string>("field_name") : "default"),
_field_type(getParam<MooseEnum>("field_type"))
{
if (isNodal())
mooseError("This AuxKernel only supports Elemental fields");
}
Real
ElementUOAux::computeValue()
{
if (_field_type == "long")
{
auto value = _elem_uo.getElementalValueLong(_current_elem->id(), _field_name);
if (value == std::numeric_limits<unsigned long>::max())
return -1.0;
else
return value;
}
else
return _elem_uo.getElementalValueReal(_current_elem->id(), _field_name);
}