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 : #pragma once 11 : 12 : // MOOSE includes 13 : #include "InputParameters.h" 14 : #include "ParallelUniqueId.h" 15 : #include "MaterialData.h" 16 : #include "MooseObject.h" 17 : 18 : #define usingBlockRestrictableMembers using BlockRestrictable::getBlockCoordSystem 19 : 20 : class FEProblemBase; 21 : class MooseMesh; 22 : 23 : class MooseVariableFieldBase; 24 : 25 : /** 26 : * \class BlockRestrictable BlockRestrictable.h 27 : * \brief An interface that restricts an object to subdomains via the 'blocks' input parameter 28 : * 29 : * This class adds the 'blocks' input parameter and checks that it is populated, if it is not 30 : * populated 31 : * it will be populated with all valid block ids via two methods: 32 : * -# If a 'variable' parameter is present in the input parameters then by default the 'block' 33 : * input is set to all blocks associated with the variable. 34 : * -# If no 'variable' parameter is present then it utilizes all available blocks for the 35 : * associated mesh. 36 : * 37 : * When using with an object with a 'variable' parameter (e.g., Kernel), the following must also 38 : * exist within 39 : * the input parameters for the class to operate correctly 40 : * - '_fe_problem' = pointer to FEProblemBase 41 : * - '_tid' = THREAD_ID for the class 42 : * - '_sys' = pointer to the SystemBase 43 : * 44 : * In the general case (i.e., no 'variable') \b either \b one of the following must also exist 45 : * within the 46 : * input parameters for proper operation of the class: 47 : * - '_fe_problem' = a pointer to FEProblemBase 48 : * - '_mesh' = a pointer to MooseMesh 49 : * 50 : * When creating a new object, generally, this class should be inherited following MooseObject. 51 : * Also, the BlockRestricted::validParams() must be added to any other parameters for the 52 : * the class being created, since this is where the 'blocks' input parameter is created. 53 : * 54 : * \see Kernel 55 : * \see SideSetsAroundSubdomain 56 : */ 57 : class BlockRestrictable 58 : { 59 : public: 60 : /** 61 : * Class constructor 62 : * Populates the 'block' input parameters, see the general class documentation for details. 63 : * @param parameters The input parameters (see the detailed help for additional information) 64 : * @param initialize Disable initialization, MooseVariableBase was converted to a MooseObject, 65 : * this flag allows it to be constructed as if it wasn't to maintain backward compatibility, this 66 : * will be removed in the fugure. 67 : * TODO:MooseVariableToMooseObject (see #10601) 68 : */ 69 : BlockRestrictable(const MooseObject * moose_object, bool initialize = true); 70 : 71 : static InputParameters validParams(); 72 : 73 : /** 74 : * Class constructor 75 : * Populates the 'block' input parameters when an object is also boundary restricted, 76 : * see the general class documentation for details. 77 : * @param parameters The input parameters (see the detailed help for additional information) 78 : * @param boundary_ids The boundary ids that the object is restricted to 79 : */ 80 : BlockRestrictable(const MooseObject * moose_object, const std::set<BoundaryID> & boundary_ids); 81 : 82 : /** 83 : * Destructor: does nothing but needs to be marked as virtual since 84 : * this class defines virtual functions. 85 : */ 86 426372 : virtual ~BlockRestrictable() {} 87 : 88 : /** 89 : * Return the block names for this object 90 : * 91 : * Note, if the 'blocks' input parameter was not utilized this will return an 92 : * empty vector. 93 : * 94 : * @return vector of SubdomainNames that are valid for this object 95 : */ 96 : const std::vector<SubdomainName> & blocks() const; 97 : 98 : /** 99 : * Return the number of blocks for this object 100 : * @return The number of subdomains 101 : */ 102 : unsigned int numBlocks() const; 103 : 104 : /** 105 : * Return the block subdomain ids for this object 106 : * Note, if this is not block restricted, this function returns all mesh subdomain ids. 107 : * @return a set of SubdomainIDs that are valid for this object 108 : */ 109 : virtual const std::set<SubdomainID> & blockIDs() const; 110 : 111 : /** 112 : * Return the largest mesh dimension of the elements in the blocks for this object 113 : */ 114 : unsigned int blocksMaxDimension() const; 115 : 116 : /** 117 : * Test if the supplied block name is valid for this object 118 : * @param name A SubdomainName to check 119 : * @return True if the given id is valid for this object 120 : */ 121 : bool hasBlocks(const SubdomainName & name) const; 122 : 123 : /** 124 : * Test if the supplied vector of block names are valid for this object 125 : * @param names A vector of SubdomainNames to check 126 : * @return True if the given ids are valid for this object 127 : */ 128 : bool hasBlocks(const std::vector<SubdomainName> & names) const; 129 : 130 : /** 131 : * Test if the supplied set of block names are valid for this object 132 : * @param names A set of SubdomainNames to check 133 : * @return True if the given ids are valid for this object 134 : */ 135 : bool hasBlocks(const std::set<SubdomainName> & names) const; 136 : 137 : /** 138 : * Test if the supplied block ids are valid for this object 139 : * @param id A SubdomainID to check 140 : * @return True if the given id is valid for this object 141 : */ 142 : bool hasBlocks(SubdomainID id) const; 143 : 144 : /** 145 : * Test if the supplied vector block ids are valid for this object 146 : * @param ids A vector of SubdomainIDs ids to check 147 : * @return True if all of the given ids are found within the ids for this object 148 : */ 149 : bool hasBlocks(const std::vector<SubdomainID> & ids) const; 150 : 151 : /** 152 : * Test if the supplied set of block ids are valid for this object 153 : * @param ids A std::set of SubdomainIDs to check 154 : * @return True if all of the given ids are found within the ids for this object 155 : * \see isSubset 156 : */ 157 : bool hasBlocks(const std::set<SubdomainID> & ids) const; 158 : 159 : /** 160 : * Test if the class block ids are a subset of the supplied objects 161 : * @param ids A std::set of Subdomains to check 162 : * @return True if all of the block ids for this class are found within the given ids (opposite of 163 : * hasBlocks) 164 : * \see hasBlocks 165 : */ 166 : bool isBlockSubset(const std::set<SubdomainID> & ids) const; 167 : 168 : /** 169 : * Test if the class block ids are a subset of the supplied objects 170 : * @param ids A std::vector of Subdomains to check 171 : * @return True if all of the block ids for this class are found within the given ids (opposite of 172 : * hasBlocks) 173 : * \see hasBlocks 174 : */ 175 : bool isBlockSubset(const std::vector<SubdomainID> & ids) const; 176 : 177 : /** 178 : * Check if a material property is valid for all blocks of this object 179 : * 180 : * This method returns true if the supplied property name has been declared 181 : * in a Material object on the block ids for this object. 182 : * 183 : * @tparam T The type of material property 184 : * @param prop_name the name of the property to query 185 : * @return true if the property exists for all block ids of the object, otherwise false 186 : * 187 : * @see Material::hasBlockMaterialProperty 188 : */ 189 : template <typename T, bool is_ad = false> 190 : bool hasBlockMaterialProperty(const std::string & prop_name); 191 : 192 : /** 193 : * Return all of the SubdomainIDs for the mesh 194 : * @return A set of all subdomians for the entire mesh 195 : */ 196 : const std::set<SubdomainID> & meshBlockIDs() const; 197 : 198 : /** 199 : * Returns true if this object has been restricted to a block 200 : * @see MooseObject 201 : */ 202 : virtual bool blockRestricted() const; 203 : 204 : /** 205 : * Helper for checking that the ids for this object are in agreement with the variables 206 : * on the supplied variable. 207 : * 208 : * @param variable The variable to check against. 209 : */ 210 : virtual void checkVariable(const MooseVariableFieldBase & variable) const; 211 : 212 : protected: 213 : /// Pointer to the MaterialData class for this object 214 : const MaterialData * _blk_material_data; 215 : 216 : /** 217 : * A helper method to allow the Material object to specialize the behavior 218 : * of hasBlockMaterialProperty. It also avoid circular \#include problems. 219 : * @see hasBlockMaterialProperty 220 : */ 221 : virtual bool hasBlockMaterialPropertyHelper(const std::string & prop_name); 222 : 223 : /** 224 : * An initialization routine needed for dual constructors 225 : */ 226 : void initializeBlockRestrictable(const MooseObject * moose_object); 227 : 228 : /** 229 : * Check if the blocks this object operates on all have the same coordinate system, 230 : * and if so return it. 231 : */ 232 : Moose::CoordinateSystemType getBlockCoordSystem(); 233 : 234 : private: 235 : /// Set of block ids supplied by the user via the input file (for error checking) 236 : std::set<SubdomainID> _blk_ids; 237 : 238 : /// Vector of block ids supplied by the user via the input file (for error reporting) 239 : std::vector<SubdomainID> _vec_ids; 240 : 241 : /// Vector the block names supplied by the user via the input file 242 : std::vector<SubdomainName> _blocks; 243 : 244 : /// Flag for allowing dual restriction 245 : const bool _blk_dual_restrictable; 246 : 247 : /// Pointer to FEProblemBase 248 : FEProblemBase * _blk_feproblem; 249 : 250 : /// Pointer to Mesh 251 : const MooseMesh * _blk_mesh; 252 : 253 : /// An empty set for referencing when boundary_ids is not included 254 : const std::set<BoundaryID> _empty_boundary_ids; 255 : 256 : /// Reference to the boundary_ids, defaults to an empty set if not provided 257 : const std::set<BoundaryID> & _boundary_ids; 258 : 259 : /// Thread id for this object 260 : THREAD_ID _blk_tid; 261 : 262 : /// Name of the object 263 : const std::string & _blk_name; 264 : 265 : /// Largest mesh dimension of the elements in the blocks for this object 266 : unsigned int _blk_dim; 267 : }; 268 : 269 : template <typename T, bool is_ad> 270 : bool 271 13558 : BlockRestrictable::hasBlockMaterialProperty(const std::string & prop_name) 272 : { 273 : mooseAssert(_blk_material_data != NULL, "MaterialData pointer is not defined"); 274 14238 : return hasBlockMaterialPropertyHelper(prop_name) && 275 14238 : _blk_material_data->haveGenericProperty<T, is_ad>(prop_name); 276 : }