www.mooseframework.org
GrainDataTracker.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 #ifndef GRAINDATATRACKER_H
9 #define GRAINDATATRACKER_H
10 
11 #include "GrainTracker.h"
12 
17 template <typename T>
19 {
20 public:
21  GrainDataTracker(const InputParameters & parameters);
22 
24  const T & getData(unsigned int grain_id) const;
25 
26 protected:
28  virtual T newGrain(unsigned int new_grain_id) = 0;
29 
30  virtual void newGrainCreated(unsigned int new_grain_id);
31 
33  std::vector<T> _grain_data;
34 };
35 
36 template <typename T>
37 GrainDataTracker<T>::GrainDataTracker(const InputParameters & parameters) : GrainTracker(parameters)
38 {
39 }
40 
41 template <typename T>
42 const T &
43 GrainDataTracker<T>::getData(unsigned int grain_id) const
44 {
45  mooseAssert(grain_id < _grain_data.size(), "Requested data for invalid grain index.");
46  return _grain_data[grain_id];
47 }
48 
49 template <typename T>
50 void
51 GrainDataTracker<T>::newGrainCreated(unsigned int new_grain_id)
52 {
53  if (_grain_data.size() <= new_grain_id)
54  _grain_data.resize(new_grain_id + 1);
55 
56  _grain_data[new_grain_id] = newGrain(new_grain_id);
57 }
58 
59 #endif // GRAINDATATRACKER_H
std::vector< T > _grain_data
per grain data
virtual void newGrainCreated(unsigned int new_grain_id)
This method is called when a new grain is detected.
const T & getData(unsigned int grain_id) const
return data for selected grain
GrainDataTracker(const InputParameters &parameters)
virtual T newGrain(unsigned int new_grain_id)=0
implement this method to initialize the data for the new grain
GrainTracker derived class template to base objects on which maintain physical parameters for individ...