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