Line data Source code
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 : 10 : #include "XFEMCutSwitchingMaterial.h" 11 : 12 : registerMooseObject("XFEMApp", XFEMCutSwitchingMaterialReal); 13 : registerMooseObject("XFEMApp", XFEMCutSwitchingMaterialRankTwoTensor); 14 : registerMooseObject("XFEMApp", XFEMCutSwitchingMaterialRankThreeTensor); 15 : registerMooseObject("XFEMApp", XFEMCutSwitchingMaterialRankFourTensor); 16 : 17 : registerMooseObject("XFEMApp", ADXFEMCutSwitchingMaterialReal); 18 : registerMooseObject("XFEMApp", ADXFEMCutSwitchingMaterialRankTwoTensor); 19 : registerMooseObject("XFEMApp", ADXFEMCutSwitchingMaterialRankThreeTensor); 20 : registerMooseObject("XFEMApp", ADXFEMCutSwitchingMaterialRankFourTensor); 21 : 22 : template <typename T, bool is_ad> 23 : InputParameters 24 80 : XFEMCutSwitchingMaterialTempl<T, is_ad>::validParams() 25 : { 26 80 : InputParameters params = Material::validParams(); 27 80 : params.addClassDescription("Switch the material property based on the CutSubdomainID."); 28 160 : params.addRequiredParam<UserObjectName>("geometric_cut_userobject", 29 : "The geometric cut userobject"); 30 160 : params.addRequiredParam<std::vector<CutSubdomainID>>( 31 : "cut_subdomain_ids", "The CutSubdomainIDs that the geometric_cut_userobject may provide."); 32 160 : params.addRequiredParam<std::vector<std::string>>( 33 : "base_names", "The base_names for each of the cut subdomain."); 34 160 : params.addParam<std::string>("base_name", 35 : "Base name to prepend for the computed material property."); 36 160 : params.addRequiredParam<std::string>("prop_name", "name of the material property to switch"); 37 80 : return params; 38 0 : } 39 : 40 : template <typename T, bool is_ad> 41 60 : XFEMCutSwitchingMaterialTempl<T, is_ad>::XFEMCutSwitchingMaterialTempl( 42 : const InputParameters & parameters) 43 : : Material(parameters), 44 60 : _cut(&getUserObject<GeometricCutUserObject>("geometric_cut_userobject")), 45 120 : _keys(getParam<std::vector<CutSubdomainID>>("cut_subdomain_ids")), 46 120 : _vals(getParam<std::vector<std::string>>("base_names")), 47 120 : _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""), 48 180 : _prop_name(getParam<std::string>("prop_name")), 49 180 : _prop(declareGenericProperty<T, is_ad>(_base_name + _prop_name)) 50 : { 51 60 : FEProblemBase * fe_problem = dynamic_cast<FEProblemBase *>(&_subproblem); 52 60 : if (!fe_problem) 53 0 : mooseError("Problem casting _subproblem to FEProblemBase"); 54 120 : _xfem = MooseSharedNamespace::dynamic_pointer_cast<XFEM>(fe_problem->getXFEM()); 55 60 : if (!_xfem) 56 0 : mooseError(name(), " should be used together with XFEM."); 57 : 58 60 : if (_keys.size() != _vals.size()) 59 0 : mooseError("The number of base_name_keys must be equal to the number of base_name_vals. ", 60 0 : _keys.size(), 61 : " keys are provided, but ", 62 0 : _vals.size(), 63 : " values are provided."); 64 228 : for (unsigned int i = 0; i < _keys.size(); i++) 65 336 : _prop_map.emplace(_keys[i], &getGenericMaterialProperty<T, is_ad>(_vals[i] + "_" + _prop_name)); 66 60 : } 67 : 68 : template <typename T, bool is_ad> 69 : void 70 3159 : XFEMCutSwitchingMaterialTempl<T, is_ad>::computeProperties() 71 : { 72 3159 : 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 3159 : _mapped_prop = _prop_map.at(key); 81 : } 82 0 : catch (std::out_of_range &) 83 : { 84 0 : throw MooseException(name() + ": Unknown CutSubdomainID: " + Moose::stringify(key) + 85 : ", which is not " 86 : "provided in the base_name_keys"); 87 : } 88 : 89 3159 : Material::computeProperties(); 90 3159 : } 91 : 92 : template class XFEMCutSwitchingMaterialTempl<Real, false>; 93 : template class XFEMCutSwitchingMaterialTempl<RankTwoTensor, false>; 94 : template class XFEMCutSwitchingMaterialTempl<RankThreeTensor, false>; 95 : template class XFEMCutSwitchingMaterialTempl<RankFourTensor, false>; 96 : 97 : template class XFEMCutSwitchingMaterialTempl<Real, true>; 98 : template class XFEMCutSwitchingMaterialTempl<RankTwoTensor, true>; 99 : template class XFEMCutSwitchingMaterialTempl<RankThreeTensor, true>; 100 : template class XFEMCutSwitchingMaterialTempl<RankFourTensor, true>;