www.mooseframework.org
SubProblem.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "SubProblem.h"
16 #include "Factory.h"
17 #include "MooseMesh.h"
18 #include "Conversion.h"
19 #include "Function.h"
20 #include "MooseApp.h"
21 #include "MooseVariable.h"
22 #include "MooseArray.h"
23 
24 template <>
27 {
29  return params;
30 }
31 
32 // SubProblem /////
33 
35  : Problem(parameters),
36  _factory(_app.getFactory()),
37  _nonlocal_cm(),
38  _requires_nonlocal_coupling(false),
39  _rz_coord_axis(1) // default to RZ rotation around y-axis
40 {
41  unsigned int n_threads = libMesh::n_threads();
42  _active_elemental_moose_variables.resize(n_threads);
43  _has_active_elemental_moose_variables.resize(n_threads);
44  _active_material_property_ids.resize(n_threads);
45 }
46 
48 
49 void
50 SubProblem::setActiveElementalMooseVariables(const std::set<MooseVariable *> & moose_vars,
51  THREAD_ID tid)
52 {
53  if (!moose_vars.empty())
54  {
56  _active_elemental_moose_variables[tid] = moose_vars;
57  }
58 }
59 
60 const std::set<MooseVariable *> &
62 {
64 }
65 
66 bool
68 {
70 }
71 
72 void
74 {
77 }
78 
79 void
80 SubProblem::setActiveMaterialProperties(const std::set<unsigned int> & mat_prop_ids, THREAD_ID tid)
81 {
82  if (!mat_prop_ids.empty())
83  _active_material_property_ids[tid] = mat_prop_ids;
84 }
85 
86 const std::set<unsigned int> &
88 {
90 }
91 
92 bool
94 {
95  return !_active_material_property_ids[tid].empty();
96 }
97 
98 void
100 {
101  _active_material_property_ids[tid].clear();
102 }
103 
104 std::set<SubdomainID>
105 SubProblem::getMaterialPropertyBlocks(const std::string & prop_name)
106 {
107  std::set<SubdomainID> blocks;
108 
109  for (const auto & it : _map_block_material_props)
110  {
111  const std::set<std::string> & prop_names = it.second;
112  std::set<std::string>::iterator name_it = prop_names.find(prop_name);
113  if (name_it != prop_names.end())
114  blocks.insert(it.first);
115  }
116 
117  return blocks;
118 }
119 
120 std::vector<SubdomainName>
121 SubProblem::getMaterialPropertyBlockNames(const std::string & prop_name)
122 {
123  std::set<SubdomainID> blocks = getMaterialPropertyBlocks(prop_name);
124  std::vector<SubdomainName> block_names;
125  block_names.reserve(blocks.size());
126  for (const auto & block_id : blocks)
127  {
128  SubdomainName name;
129  if (block_id == Moose::ANY_BLOCK_ID)
130  name = "ANY_BLOCK_ID";
131  else
132  {
133  name = mesh().getMesh().subdomain_name(block_id);
134  if (name.empty())
135  {
136  std::ostringstream oss;
137  oss << block_id;
138  name = oss.str();
139  }
140  }
141  block_names.push_back(name);
142  }
143 
144  return block_names;
145 }
146 
147 bool
148 SubProblem::hasBlockMaterialProperty(SubdomainID bid, const std::string & prop_name)
149 {
150  auto it = _map_block_material_props.find(bid);
151  if (it == _map_block_material_props.end())
152  return false;
153 
154  if (it->second.count(prop_name) > 0)
155  return true;
156  else
157  return false;
158 }
159 
160 // TODO: remove code duplication by templating
161 std::set<BoundaryID>
162 SubProblem::getMaterialPropertyBoundaryIDs(const std::string & prop_name)
163 {
164  std::set<BoundaryID> boundaries;
165 
166  for (const auto & it : _map_boundary_material_props)
167  {
168  const std::set<std::string> & prop_names = it.second;
169  std::set<std::string>::iterator name_it = prop_names.find(prop_name);
170  if (name_it != prop_names.end())
171  boundaries.insert(it.first);
172  }
173 
174  return boundaries;
175 }
176 
177 std::vector<BoundaryName>
178 SubProblem::getMaterialPropertyBoundaryNames(const std::string & prop_name)
179 {
180  std::set<BoundaryID> boundaries = getMaterialPropertyBoundaryIDs(prop_name);
181  std::vector<BoundaryName> boundary_names;
182  boundary_names.reserve(boundaries.size());
183  const BoundaryInfo & boundary_info = mesh().getMesh().get_boundary_info();
184 
185  for (const auto & bnd_id : boundaries)
186  {
187  BoundaryName name;
188  if (bnd_id == Moose::ANY_BOUNDARY_ID)
189  name = "ANY_BOUNDARY_ID";
190  else
191  {
192  name = boundary_info.get_sideset_name(bnd_id);
193  if (name.empty())
194  {
195  std::ostringstream oss;
196  oss << bnd_id;
197  name = oss.str();
198  }
199  }
200  boundary_names.push_back(name);
201  }
202 
203  return boundary_names;
204 }
205 
206 bool
207 SubProblem::hasBoundaryMaterialProperty(BoundaryID bid, const std::string & prop_name)
208 {
209  auto it = _map_boundary_material_props.find(bid);
210  if (it == _map_boundary_material_props.end())
211  return false;
212 
213  if (it->second.count(prop_name) > 0)
214  return true;
215  else
216  return false;
217 }
218 
219 void
220 SubProblem::storeMatPropName(SubdomainID block_id, const std::string & name)
221 {
222  _map_block_material_props[block_id].insert(name);
223 }
224 
225 void
226 SubProblem::storeMatPropName(BoundaryID boundary_id, const std::string & name)
227 {
228  _map_boundary_material_props[boundary_id].insert(name);
229 }
230 
231 void
232 SubProblem::storeZeroMatProp(SubdomainID block_id, const MaterialPropertyName & name)
233 {
234  _zero_block_material_props[block_id].insert(name);
235 }
236 
237 void
238 SubProblem::storeZeroMatProp(BoundaryID boundary_id, const MaterialPropertyName & name)
239 {
240  _zero_boundary_material_props[boundary_id].insert(name);
241 }
242 
243 void
244 SubProblem::storeDelayedCheckMatProp(const std::string & requestor,
245  SubdomainID block_id,
246  const std::string & name)
247 {
248  _map_block_material_props_check[block_id].insert(std::make_pair(requestor, name));
249 }
250 
251 void
252 SubProblem::storeDelayedCheckMatProp(const std::string & requestor,
253  BoundaryID boundary_id,
254  const std::string & name)
255 {
256  _map_boundary_material_props_check[boundary_id].insert(std::make_pair(requestor, name));
257 }
258 
259 void
261 {
264 }
265 
266 void
268 {
272 }
273 
274 void
275 SubProblem::markMatPropRequested(const std::string & prop_name)
276 {
277  _material_property_requested.insert(prop_name);
278 }
279 
280 bool
281 SubProblem::isMatPropRequested(const std::string & prop_name) const
282 {
283  return _material_property_requested.find(prop_name) != _material_property_requested.end();
284 }
285 
288 {
289  return _dirac_kernel_info;
290 }
291 
292 Real
294 {
295  return 0;
296 }
297 
298 unsigned int
300 {
301  return 0;
302 }
303 
304 unsigned int
306 {
307  return 0;
308 }
309 
310 void
312 {
313  mooseError("This system does not support changing the mesh");
314 }
315 
316 template <>
317 std::string
318 SubProblem::restrictionTypeName<SubdomainID>()
319 {
320  return "block";
321 }
322 
323 template <>
324 std::string
325 SubProblem::restrictionTypeName<BoundaryID>()
326 {
327  return "boundary";
328 }
329 
330 std::string
332 {
333  // TODO: Put a better a interface in MOOSE
334  std::map<subdomain_id_type, std::string> & name_map = mesh().getMesh().set_subdomain_name_map();
335  std::map<subdomain_id_type, std::string>::const_iterator pos = name_map.find(check_id);
336  if (pos != name_map.end())
337  return pos->second;
338  return "";
339 }
340 
341 std::string
343 {
344  return mesh().getMesh().get_boundary_info().sideset_name(check_id);
345 }
346 
347 template <typename T>
348 void
349 SubProblem::checkMatProps(std::map<T, std::set<std::string>> & props,
350  std::map<T, std::multimap<std::string, std::string>> & check_props,
351  std::map<T, std::set<MaterialPropertyName>> & zero_props)
352 {
353  // Variable for storing the value for ANY_BLOCK_ID/ANY_BOUNDARY_ID
354  T any_id = mesh().getAnyID<T>();
355 
356  // Variable for storing all available blocks/boundaries from the mesh
357  std::set<T> all_ids(mesh().getBlockOrBoundaryIDs<T>());
358 
359  // Loop through the properties to check
360  for (const auto & check_it : check_props)
361  {
362  // The current id for the property being checked (BoundaryID || BlockID)
363  T check_id = check_it.first;
364 
365  // In the case when the material being checked has an ID is set to ANY, then loop through all
366  // the possible ids and verify that the material property is defined.
367  std::set<T> check_ids = {check_id};
368  if (check_id == any_id)
369  check_ids = all_ids;
370 
371  // Loop through all the block/boundary ids
372  for (const auto & id : check_ids)
373  {
374  // Loop through all the stored properties
375  for (const auto & prop_it : check_it.second)
376  {
377  // Produce an error if the material property is not defined on the current block/boundary
378  // and any block/boundary
379  // and not is not a zero material property.
380  if (props[id].count(prop_it.second) == 0 && props[any_id].count(prop_it.second) == 0 &&
381  zero_props[id].count(prop_it.second) == 0 &&
382  zero_props[any_id].count(prop_it.second) == 0)
383  {
384  std::string check_name = restrictionCheckName(id);
385  if (check_name.empty())
386  check_name = std::to_string(id);
387  mooseError("Material property '",
388  prop_it.second,
389  "', requested by '",
390  prop_it.first,
391  "' is not defined on ",
392  restrictionTypeName<T>(),
393  " ",
394  check_name);
395  }
396  }
397  }
398  }
399 }
400 
401 unsigned int
403 {
404  if (_rz_coord_axis == 0)
405  return 1; // if the rotation axis is x (0), then the radial direction is y (1)
406  else
407  return 0; // otherwise the radial direction is assumed to be x, i.e., the rotation axis is y
408 }
409 
410 void
412 {
413  _app.registerRestartableData(this->name() + "/" + name, data, tid);
414 }
415 
416 void
418 {
419  _app.registerRecoverableData(this->name() + "/" + name);
420 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
virtual void storeDelayedCheckMatProp(const std::string &requestor, SubdomainID block_id, const std::string &name)
Adds to a map based on block ids of material properties to validate.
Definition: SubProblem.C:244
virtual void registerRecoverableData(std::string name)
NOTE: This is an internal function meant for MOOSE use only!
Definition: MooseApp.C:678
virtual MooseMesh & mesh()=0
virtual bool hasBoundaryMaterialProperty(BoundaryID boundary_id, const std::string &prop_name)
Check if a material property is defined on a block.
Definition: SubProblem.C:207
std::map< BoundaryID, std::multimap< std::string, std::string > > _map_boundary_material_props_check
Definition: SubProblem.h:447
The DiracKernelInfo object is a place where all the Dirac points added by different DiracKernels are ...
unsigned int _rz_coord_axis
Storage for RZ axis selection.
Definition: SubProblem.h:467
virtual std::set< BoundaryID > getMaterialPropertyBoundaryIDs(const std::string &prop_name)
Get a vector containing the block ids the material property is defined on.
Definition: SubProblem.C:162
virtual bool hasBlockMaterialProperty(SubdomainID block_id, const std::string &prop_name)
Check if a material property is defined on a block.
Definition: SubProblem.C:148
subdomain_id_type SubdomainID
Definition: MooseTypes.h:77
virtual ~SubProblem()
Definition: SubProblem.C:47
virtual unsigned int nNonlinearIterations()
Definition: SubProblem.C:299
Class that hold the whole problem being solved.
Definition: Problem.h:29
virtual bool hasActiveMaterialProperties(THREAD_ID tid)
Method to check whether or not a list of active material roperties has been set.
Definition: SubProblem.C:93
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual const std::set< unsigned int > & getActiveMaterialProperties(THREAD_ID tid)
Get the material properties required by the current computing thread.
Definition: SubProblem.C:87
virtual bool hasActiveElementalMooseVariables(THREAD_ID tid)
Whether or not a list of active elemental moose variables has been set.
Definition: SubProblem.C:67
virtual void markMatPropRequested(const std::string &)
Helper method for adding a material property name to the _material_property_requested set...
Definition: SubProblem.C:275
std::map< BoundaryID, std::set< MaterialPropertyName > > _zero_boundary_material_props
Definition: SubProblem.h:435
virtual void registerRecoverableData(std::string name)
NOTE: This is an internal function meant for MOOSE use only!
Definition: SubProblem.C:417
virtual void registerRestartableData(std::string name, RestartableDataValue *data, THREAD_ID tid)
Definition: MooseApp.C:874
virtual void storeZeroMatProp(SubdomainID block_id, const MaterialPropertyName &name)
Adds to a map based on block ids of material properties for which a zero value can be returned...
Definition: SubProblem.C:232
std::map< BoundaryID, std::set< std::string > > _map_boundary_material_props
Map for boundary material properties (boundary_id -> list of properties)
Definition: SubProblem.h:431
virtual void checkBoundaryMatProps()
Checks boundary material properties integrity.
Definition: SubProblem.C:267
void checkMatProps(std::map< T, std::set< std::string >> &props, std::map< T, std::multimap< std::string, std::string >> &check_props, std::map< T, std::set< MaterialPropertyName >> &zero_props)
Helper method for performing material property checks.
Definition: SubProblem.C:349
std::vector< std::set< MooseVariable * > > _active_elemental_moose_variables
This is the set of MooseVariables that will actually get reinited by a call to reinit(elem) ...
Definition: SubProblem.h:451
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2408
virtual void clearActiveElementalMooseVariables(THREAD_ID tid)
Clear the active elemental MooseVariable.
Definition: SubProblem.C:73
virtual DiracKernelInfo & diracKernelInfo()
Definition: SubProblem.C:287
SubProblem(const InputParameters &parameters)
Definition: SubProblem.C:34
virtual void checkBlockMatProps()
Checks block material properties integrity.
Definition: SubProblem.C:260
std::vector< std::set< unsigned int > > _active_material_property_ids
Set of material property ids that determine whether materials get reinited.
Definition: SubProblem.h:458
virtual std::vector< SubdomainName > getMaterialPropertyBlockNames(const std::string &prop_name)
Get a vector of block id equivalences that the material property is defined on.
Definition: SubProblem.C:121
virtual void registerRestartableData(std::string name, RestartableDataValue *data, THREAD_ID tid)
Register a piece of restartable data.
Definition: SubProblem.C:411
std::string restrictionCheckName(SubdomainID check_id)
Definition: SubProblem.C:331
T getAnyID() const
Templated helper that returns either the ang block or any boundary ID depending on the template argum...
virtual unsigned int nLinearIterations()
Definition: SubProblem.C:305
const SubdomainID ANY_BLOCK_ID
Definition: MooseTypes.h:117
virtual std::set< SubdomainID > getMaterialPropertyBlocks(const std::string &prop_name)
Get a vector containing the block ids the material property is defined on.
Definition: SubProblem.C:105
std::map< SubdomainID, std::set< MaterialPropertyName > > _zero_block_material_props
Set of properties returned as zero properties.
Definition: SubProblem.h:434
virtual std::vector< BoundaryName > getMaterialPropertyBoundaryNames(const std::string &prop_name)
Get a vector of block id equivalences that the material property is defined on.
Definition: SubProblem.C:178
std::vector< unsigned int > _has_active_elemental_moose_variables
Whether or not there is currently a list of active elemental moose variables.
Definition: SubProblem.h:455
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:108
std::set< std::string > _material_property_requested
set containing all material property names that have been requested by getMaterialProperty* ...
Definition: SubProblem.h:438
virtual const std::set< MooseVariable * > & getActiveElementalMooseVariables(THREAD_ID tid)
Get the MOOSE variables to be reinited on each element.
Definition: SubProblem.C:61
InputParameters validParams< Problem >()
Definition: Problem.C:21
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
virtual void setActiveElementalMooseVariables(const std::set< MooseVariable * > &moose_vars, THREAD_ID tid)
Set the MOOSE variables to be reinited on each element.
Definition: SubProblem.C:50
virtual bool isMatPropRequested(const std::string &prop_name) const
Find out if a material property has been requested by any object.
Definition: SubProblem.C:281
std::map< SubdomainID, std::multimap< std::string, std::string > > _map_block_material_props_check
Data structures of the requested material properties.
Definition: SubProblem.h:446
virtual void clearActiveMaterialProperties(THREAD_ID tid)
Clear the active material properties.
Definition: SubProblem.C:99
DiracKernelInfo _dirac_kernel_info
Definition: SubProblem.h:425
std::map< SubdomainID, std::set< std::string > > _map_block_material_props
Map of material properties (block_id -> list of properties)
Definition: SubProblem.h:428
virtual Real finalNonlinearResidual()
Definition: SubProblem.C:293
virtual void storeMatPropName(SubdomainID block_id, const std::string &name)
Adds the given material property to a storage map based on block ids.
Definition: SubProblem.C:220
InputParameters validParams< SubProblem >()
Definition: SubProblem.C:26
virtual void meshChanged()
Definition: SubProblem.C:311
Abstract definition of a RestartableData value.
const BoundaryID ANY_BOUNDARY_ID
Definition: MooseTypes.h:119
boundary_id_type BoundaryID
Definition: MooseTypes.h:75
unsigned int THREAD_ID
Definition: MooseTypes.h:79
virtual void setActiveMaterialProperties(const std::set< unsigned int > &mat_prop_ids, THREAD_ID tid)
Record and set the material properties required by the current computing thread.
Definition: SubProblem.C:80
unsigned int getAxisymmetricRadialCoord()
Returns the desired radial direction for RZ coordinate transformation.
Definition: SubProblem.C:402