forked from idaholab/moose
/
SubProblem.h
462 lines (380 loc) · 17.5 KB
/
SubProblem.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/
#ifndef SUBPROBLEM_H
#define SUBPROBLEM_H
#include "ParallelUniqueId.h"
#include "Problem.h"
#include "DiracKernelInfo.h"
#include "GeometricSearchData.h"
#include "MooseVariableBase.h" // VariableValue
// libMesh includes
#include "libmesh/coupling_matrix.h"
class MooseMesh;
class SubProblem;
class Factory;
class Assembly;
class MooseVariable;
class MooseVariableScalar;
class RestartableDataValue;
// libMesh forward declarations
namespace libMesh
{
class EquationSystems;
class DofMap;
class CouplingMatrix;
template <typename T> class SparseMatrix;
template <typename T> class NumericVector;
}
template<>
InputParameters validParams<SubProblem>();
/**
* Generic class for solving transient nonlinear problems
*
*/
class SubProblem : public Problem
{
public:
SubProblem(const InputParameters & parameters);
virtual ~SubProblem();
virtual EquationSystems & es() = 0;
virtual MooseMesh & mesh() = 0;
virtual bool checkNonlocalCouplingRequirement() { return _requires_nonlocal_coupling; }
/**
* Whether or not this problem should utilize FE shape function caching.
*
* @param fe_cache True for using the cache false for not.
*/
virtual void useFECache(bool fe_cache) = 0;
virtual void solve() = 0;
virtual bool converged() = 0;
virtual void onTimestepBegin() = 0;
virtual void onTimestepEnd() = 0;
virtual bool isTransient() const = 0;
// Variables /////
virtual bool hasVariable(const std::string & var_name) = 0;
virtual MooseVariable & getVariable(THREAD_ID tid, const std::string & var_name) = 0;
virtual bool hasScalarVariable(const std::string & var_name) = 0;
virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid, const std::string & var_name) = 0;
/**
* Set the MOOSE variables to be reinited on each element.
* @param moose_vars A set of variables that need to be reinited each time reinit() is called.
*
* @param tid The thread id
*/
virtual void setActiveElementalMooseVariables(const std::set<MooseVariable *> & moose_vars, THREAD_ID tid);
/**
* Get the MOOSE variables to be reinited on each element.
*
* @param tid The thread id
*/
virtual const std::set<MooseVariable *> & getActiveElementalMooseVariables(THREAD_ID tid);
/**
* Whether or not a list of active elemental moose variables has been set.
*
* @return True if there has been a list of active elemental moose variables set, False otherwise
*/
virtual bool hasActiveElementalMooseVariables(THREAD_ID tid);
/**
* Clear the active elemental MooseVariable. If there are no active variables then they will all be reinited.
* Call this after finishing the computation that was using a restricted set of MooseVariables
*
* @param tid The thread id
*/
virtual void clearActiveElementalMooseVariables(THREAD_ID tid);
/**
* Record and set the material properties required by the current computing thread.
* @param mat_prop_ids The set of material properties required by the current computing thread.
*
* @param tid The thread id
*/
virtual void setActiveMaterialProperties(const std::set<unsigned int> & mat_prop_ids, THREAD_ID tid);
/**
* Get the material properties required by the current computing thread.
*
* @param tid The thread id
*/
virtual const std::set<unsigned int> & getActiveMaterialProperties(THREAD_ID tid);
/**
* Method to check whether or not a list of active material roperties has been set. This method
* is called by reinitMaterials to determine whether Material computeProperties methods need to be
* called. If the return is False, this check prevents unnecessary material property computation
* @param tid The thread id
*
* @return True if there has been a list of active material properties set, False otherwise
*/
virtual bool hasActiveMaterialProperties(THREAD_ID tid);
/**
* Clear the active material properties. Should be called at the end of every computing thread
*
* @param tid The thread id
*/
virtual void clearActiveMaterialProperties(THREAD_ID tid);
virtual Assembly & assembly(THREAD_ID tid) = 0;
virtual void prepareShapes(unsigned int var, THREAD_ID tid) = 0;
virtual void prepareFaceShapes(unsigned int var, THREAD_ID tid) = 0;
virtual void prepareNeighborShapes(unsigned int var, THREAD_ID tid) = 0;
virtual Moose::CoordinateSystemType getCoordSystem(SubdomainID sid) = 0;
/**
* Returns the desired radial direction for RZ coordinate transformation
* @return The coordinate direction for the radial direction
*/
unsigned int getAxisymmetricRadialCoord();
virtual DiracKernelInfo & diracKernelInfo();
virtual Real finalNonlinearResidual();
virtual unsigned int nNonlinearIterations();
virtual unsigned int nLinearIterations();
virtual void addResidual(THREAD_ID tid) = 0;
virtual void addResidualNeighbor(THREAD_ID tid) = 0;
virtual void cacheResidual(THREAD_ID tid) = 0;
virtual void cacheResidualNeighbor(THREAD_ID tid) = 0;
virtual void addCachedResidual(THREAD_ID tid) = 0;
virtual void setResidual(NumericVector<Number> & residual, THREAD_ID tid) = 0;
virtual void setResidualNeighbor(NumericVector<Number> & residual, THREAD_ID tid) = 0;
virtual void addJacobian(SparseMatrix<Number> & jacobian, THREAD_ID tid) = 0;
virtual void addJacobianNeighbor(SparseMatrix<Number> & jacobian, THREAD_ID tid) = 0;
virtual void addJacobianBlock(SparseMatrix<Number> & jacobian, unsigned int ivar, unsigned int jvar, const DofMap & dof_map, std::vector<dof_id_type> & dof_indices, THREAD_ID tid) = 0;
virtual void addJacobianNeighbor(SparseMatrix<Number> & jacobian, unsigned int ivar, unsigned int jvar, const DofMap & dof_map, std::vector<dof_id_type> & dof_indices, std::vector<dof_id_type> & neighbor_dof_indices, THREAD_ID tid) = 0;
virtual void cacheJacobian(THREAD_ID tid) = 0;
virtual void cacheJacobianNeighbor(THREAD_ID tid) = 0;
virtual void addCachedJacobian(SparseMatrix<Number> & jacobian, THREAD_ID tid) = 0;
virtual void prepare(const Elem * elem, THREAD_ID tid) = 0;
virtual void prepareFace(const Elem * elem, THREAD_ID tid) = 0;
virtual void prepare(const Elem * elem, unsigned int ivar, unsigned int jvar, const std::vector<dof_id_type> & dof_indices, THREAD_ID tid) = 0;
virtual void prepareAssembly(THREAD_ID tid) = 0;
virtual void reinitElem(const Elem * elem, THREAD_ID tid) = 0;
virtual void reinitElemPhys(const Elem * elem, std::vector<Point> phys_points_in_elem, THREAD_ID tid) = 0;
virtual void reinitElemFace(const Elem * elem, unsigned int side, BoundaryID bnd_id, THREAD_ID tid) = 0;
virtual void reinitNode(const Node * node, THREAD_ID tid) = 0;
virtual void reinitNodeFace(const Node * node, BoundaryID bnd_id, THREAD_ID tid) = 0;
virtual void reinitNodes(const std::vector<dof_id_type> & nodes, THREAD_ID tid) = 0;
virtual void reinitNodesNeighbor(const std::vector<dof_id_type> & nodes, THREAD_ID tid) = 0;
virtual void reinitNeighbor(const Elem * elem, unsigned int side, THREAD_ID tid) = 0;
virtual void reinitNeighborPhys(const Elem * neighbor, unsigned int neighbor_side, const std::vector<Point> & physical_points, THREAD_ID tid) = 0;
virtual void reinitNeighborPhys(const Elem * neighbor, const std::vector<Point> & physical_points, THREAD_ID tid) = 0;
virtual void reinitNodeNeighbor(const Node * node, THREAD_ID tid) = 0;
virtual void reinitScalars(THREAD_ID tid) = 0;
virtual void reinitOffDiagScalars(THREAD_ID tid) = 0;
/**
* Returns true if the Problem has Dirac kernels it needs to compute on elem.
*/
virtual bool reinitDirac(const Elem * elem, THREAD_ID tid) = 0;
/**
* Fills "elems" with the elements that should be looped over for Dirac Kernels
*/
virtual void getDiracElements(std::set<const Elem *> & elems) = 0;
/**
* Gets called before Dirac Kernels are asked to add the points they are supposed to be evaluated in
*/
virtual void clearDiracInfo() = 0;
// Geom Search
virtual void updateGeomSearch(GeometricSearchData::GeometricSearchType type = GeometricSearchData::ALL) = 0;
virtual GeometricSearchData & geomSearchData() = 0;
virtual void meshChanged();
/**
* Adds the given material property to a storage map based on block ids
*
* This is method is called from within the Material class when the property
* is first registered.
* @param block_id The block id for the MaterialProperty
* @param name The name of the property
*/
virtual void storeMatPropName(SubdomainID block_id, const std::string & name);
/**
* Adds the given material property to a storage map based on boundary ids
*
* This is method is called from within the Material class when the property
* is first registered.
* @param boundary_id The block id for the MaterialProperty
* @param name The name of the property
*/
virtual void storeMatPropName(BoundaryID boundary_id, const std::string & name);
/**
* Adds to a map based on block ids of material properties for which a zero
* value can be returned. Thes properties are optional and will not trigger a
* missing material property error.
*
* @param block_id The block id for the MaterialProperty
* @param name The name of the property
*/
virtual void storeZeroMatProp(SubdomainID block_id, const MaterialPropertyName & name);
/**
* Adds to a map based on boundary ids of material properties for which a zero
* value can be returned. Thes properties are optional and will not trigger a
* missing material property error.
*
* @param boundary_id The block id for the MaterialProperty
* @param name The name of the property
*/
virtual void storeZeroMatProp(BoundaryID boundary_id, const MaterialPropertyName & name);
/**
* Adds to a map based on block ids of material properties to validate
*
* @param block_id The block id for the MaterialProperty
* @param name The name of the property
*/
virtual void storeDelayedCheckMatProp(const std::string & requestor, SubdomainID block_id, const std::string & name);
/**
* Adds to a map based on boundary ids of material properties to validate
*
* @param requestor The MOOSE object name requesting the material property
* @param boundary_id The block id for the MaterialProperty
* @param name The name of the property
*/
virtual void storeDelayedCheckMatProp(const std::string & requestor, BoundaryID boundary_id, const std::string & name);
/**
* Checks block material properties integrity
*
* \see FEProblemBase::checkProblemIntegrity
*/
virtual void checkBlockMatProps();
/**
* Checks boundary material properties integrity
*
* \see FEProblemBase::checkProblemIntegrity
*/
virtual void checkBoundaryMatProps();
/**
* Helper method for adding a material property name to the _material_property_requested set
*/
virtual void markMatPropRequested(const std::string &);
/**
* Find out if a material property has been requested by any object
*/
virtual bool isMatPropRequested(const std::string & prop_name) const;
/**
* Will make sure that all dofs connected to elem_id are ghosted to this processor
*/
virtual void addGhostedElem(dof_id_type elem_id) = 0;
/**
* Will make sure that all necessary elements from boundary_id are ghosted to this processor
*/
virtual void addGhostedBoundary(BoundaryID boundary_id) = 0;
/**
* Causes the boundaries added using addGhostedBoundary to actually be ghosted.
*/
virtual void ghostGhostedBoundaries() = 0;
/**
* Get a vector containing the block ids the material property is defined on.
*/
virtual std::set<SubdomainID> getMaterialPropertyBlocks(const std::string & prop_name);
/**
* Get a vector of block id equivalences that the material property is defined on.
*/
virtual std::vector<SubdomainName> getMaterialPropertyBlockNames(const std::string & prop_name);
/**
* Get a vector containing the block ids the material property is defined on.
*/
virtual std::set<BoundaryID> getMaterialPropertyBoundaryIDs(const std::string & prop_name);
/**
* Get a vector of block id equivalences that the material property is defined on.
*/
virtual std::vector<BoundaryName> getMaterialPropertyBoundaryNames(const std::string & prop_name);
/**
* Returns true if the problem is in the process of computing it's initial residual.
* @return Whether or not the problem is currently computing the initial residual.
*/
virtual bool computingInitialResidual() = 0;
/**
* Return the list of elements that should have their DoFs ghosted to this processor.
* @return The list
*/
virtual std::set<dof_id_type> & ghostedElems() { return _ghosted_elems; }
/**
* Register a piece of restartable data. This is data that will get
* written / read to / from a restart file.
*
* @param name The full (unique) name.
* @param data The actual data object.
* @param tid The thread id of the object. Use 0 if the object is not threaded.
*/
virtual void registerRestartableData(std::string name, RestartableDataValue * data, THREAD_ID tid);
std::map<std::string, std::vector<dof_id_type> > _var_dof_map;
const CouplingMatrix & nonlocalCouplingMatrix() const { return _nonlocal_cm; }
protected:
/// The Factory for building objects
Factory & _factory;
CouplingMatrix _nonlocal_cm; /// nonlocal coupling matrix;
/// Type of coordinate system per subdomain
std::map<SubdomainID, Moose::CoordinateSystemType> _coord_sys;
DiracKernelInfo _dirac_kernel_info;
/// Map of material properties (block_id -> list of properties)
std::map<SubdomainID, std::set<std::string> > _map_block_material_props;
/// Map for boundary material properties (boundary_id -> list of properties)
std::map<BoundaryID, std::set<std::string> > _map_boundary_material_props;
/// Set of properties returned as zero properties
std::map<SubdomainID, std::set<MaterialPropertyName> > _zero_block_material_props;
std::map<BoundaryID, std::set<MaterialPropertyName> > _zero_boundary_material_props;
/// set containing all material property names that have been requested by getMaterialProperty*
std::set<std::string> _material_property_requested;
///@{
/**
* Data structures of the requested material properties. We store them in a map
* from boudnary/block id to multimap. Each of the multimaps is a list of
* requestor object names to material property names.
*/
std::map<SubdomainID, std::multimap<std::string, std::string> > _map_block_material_props_check;
std::map<BoundaryID, std::multimap<std::string, std::string> > _map_boundary_material_props_check;
///@}
/// This is the set of MooseVariables that will actually get reinited by a call to reinit(elem)
std::vector<std::set<MooseVariable *> > _active_elemental_moose_variables;
/// Whether or not there is currently a list of active elemental moose variables
/* This needs to remain <unsigned int> for threading purposes */
std::vector<unsigned int> _has_active_elemental_moose_variables;
/// Set of material property ids that determine whether materials get reinited
std::vector<std::set<unsigned int>> _active_material_property_ids;
/// True if _active_material_property_ids is not empty
std::vector<unsigned int> _has_active_material_property_ids;
/// nonlocal coupling requirement flag
bool _requires_nonlocal_coupling;
/// Elements that should have Dofs ghosted to the local processor
std::set<dof_id_type> _ghosted_elems;
/// Storage for RZ axis selection
unsigned int _rz_coord_axis;
private:
/**
* Helper method for performing material property checks
* @param props Reference to the map of properties known
* @param check_props Reference to the map of properties to check
* @param type - string describing the type of the material property being checked
* \see checkBlockMatProps
* \see checkBoundaryMatProps
*/
template <typename T>
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);
/**
* NOTE: This is an internal function meant for MOOSE use only!
*
* Register a piece of recoverable data. This is data that will get
* written / read to / from a restart file.
*
* However, this data will ONLY get read from the restart file during a RECOVERY operation!
*
* @param name The full (unique) name.
*/
virtual void registerRecoverableData(std::string name);
///@{ Helper functions for checkMatProps
template <typename T>
std::string restrictionTypeName();
std::string restrictionCheckName(SubdomainID check_id);
std::string restrictionCheckName(BoundaryID check_id);
///@}
friend class Restartable;
};
namespace Moose
{
void initial_condition(EquationSystems & es, const std::string & system_name);
} // namespace Moose
#endif /* SUBPROBLEM_H */