https://mooseframework.inl.gov
XFEMCutSwitchingMaterial.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 
16 
21 
22 template <typename T, bool is_ad>
25 {
27  params.addClassDescription("Switch the material property based on the CutSubdomainID.");
28  params.addRequiredParam<UserObjectName>("geometric_cut_userobject",
29  "The geometric cut userobject");
30  params.addRequiredParam<std::vector<CutSubdomainID>>(
31  "cut_subdomain_ids", "The CutSubdomainIDs that the geometric_cut_userobject may provide.");
32  params.addRequiredParam<std::vector<std::string>>(
33  "base_names", "The base_names for each of the cut subdomain.");
34  params.addParam<std::string>("base_name",
35  "Base name to prepend for the computed material property.");
36  params.addRequiredParam<std::string>("prop_name", "name of the material property to switch");
37  return params;
38 }
39 
40 template <typename T, bool is_ad>
42  const InputParameters & parameters)
43  : Material(parameters),
44  _cut(&getUserObject<GeometricCutUserObject>("geometric_cut_userobject")),
45  _keys(getParam<std::vector<CutSubdomainID>>("cut_subdomain_ids")),
46  _vals(getParam<std::vector<std::string>>("base_names")),
47  _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
48  _prop_name(getParam<std::string>("prop_name")),
49  _prop(declareGenericProperty<T, is_ad>(_base_name + _prop_name))
50 {
51  FEProblemBase * fe_problem = dynamic_cast<FEProblemBase *>(&_subproblem);
52  if (!fe_problem)
53  mooseError("Problem casting _subproblem to FEProblemBase");
54  _xfem = MooseSharedNamespace::dynamic_pointer_cast<XFEM>(fe_problem->getXFEM());
55  if (!_xfem)
56  mooseError(name(), " should be used together with XFEM.");
57 
58  if (_keys.size() != _vals.size())
59  mooseError("The number of base_name_keys must be equal to the number of base_name_vals. ",
60  _keys.size(),
61  " keys are provided, but ",
62  _vals.size(),
63  " values are provided.");
64  for (unsigned int i = 0; i < _keys.size(); i++)
65  _prop_map.emplace(_keys[i], &getGenericMaterialProperty<T, is_ad>(_vals[i] + "_" + _prop_name));
66 }
67 
68 template <typename T, bool is_ad>
69 void
71 {
72  CutSubdomainID key = _xfem->getCutSubdomainID(_cut, _current_elem);
73 
74  // We may run into situations where the key doesn't exist in the base_name_map. This may happen
75  // when the problem is not well defined, or the level-set variables are very nonlinear, so that
76  // the combination of levelset signs are not provided. Cutting the timestep may help, so we throw
77  // an exception in this case.
78  try
79  {
80  _mapped_prop = _prop_map.at(key);
81  }
82  catch (std::out_of_range &)
83  {
84  throw MooseException(name() + ": Unknown CutSubdomainID: " + Moose::stringify(key) +
85  ", which is not "
86  "provided in the base_name_keys");
87  }
88 
90 }
91 
96 
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
registerMooseObject("XFEMApp", XFEMCutSwitchingMaterialReal)
SubProblem & _subproblem
virtual void computeProperties() override
virtual void computeProperties() override
std::shared_ptr< XFEM > _xfem
shared pointer to XFEM
This is the XFEM class.
Definition: XFEM.h:107
virtual const std::string & name() const
void addRequiredParam(const std::string &name, const std::string &doc_string)
unsigned int CutSubdomainID
Definition: XFEMAppTypes.h:18
Switches between materials in a multi-material system where the interfaces are defined by multiple ge...
static InputParameters validParams()
std::unordered_map< unsigned int, const GenericMaterialProperty< T, is_ad > * > _prop_map
map of keys to material property
const std::string _prop_name
property name
const std::string name
Definition: Setup.h:20
XFEMCutSwitchingMaterialTempl(const InputParameters &parameters)
std::string stringify(const T &t)
std::shared_ptr< XFEMInterface > getXFEM()
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
const std::vector< CutSubdomainID > _keys
{@ map keys and values
const std::vector< std::string > _vals