www.mooseframework.org
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
EBSDReader Class Reference

A GeneralUserObject that reads an EBSD file and stores the centroid data in a data structure which indexes on element centroids. More...

#include <EBSDReader.h>

Inheritance diagram for EBSDReader:
[legend]

Public Member Functions

 EBSDReader (const InputParameters &params)
 
virtual ~EBSDReader ()
 
virtual void readFile ()
 
virtual void initialize ()
 
virtual void execute ()
 
virtual void finalize ()
 
const EBSDPointData & getData (const Point &p) const
 Get the requested type of data at the point p. More...
 
const EBSDAvgDatagetAvgData (unsigned int i) const
 Get the requested type of average data for (global) grain number i. More...
 
const EBSDAvgDatagetAvgData (unsigned int phase, unsigned int local_id) const
 Get the requested type of average data for a given phase and (local) grain. More...
 
virtual const EulerAnglesgetEulerAngles (unsigned int) const
 EulerAngleProvider interface implementation to fetch a triplet of Euler angles. More...
 
virtual unsigned int getGrainNum () const
 Return the total number of grains. More...
 
virtual unsigned int getPhaseNum () const
 Return the total number of phases. More...
 
virtual unsigned int getGrainNum (unsigned int phase) const
 Return the number of grains in a given phase. More...
 
unsigned int getFeatureID (unsigned int phase, unsigned int local_id) const
 Return the EBSD feature id for a given phase and phase (local) grain number. More...
 
unsigned int getFeatureID (unsigned int global_id) const
 Return the EBSD feature id for a given (global) grain number. More...
 
virtual unsigned int getGlobalID (unsigned int phase, unsigned int local_id) const
 Return the (global) grain id for a given phase and (local) grain number. More...
 
virtual unsigned int getGlobalID (unsigned int feature_id) const
 Return the (global) grain id for a given feature_id. More...
 
MooseSharedPointer< EBSDPointDataFunctorgetPointDataAccessFunctor (const MooseEnum &field_name) const
 Factory function to return a point functor specified by name. More...
 
MooseSharedPointer< EBSDAvgDataFunctorgetAvgDataAccessFunctor (const MooseEnum &field_name) const
 Factory function to return a average functor specified by name. More...
 
const std::map< dof_id_type, std::vector< Real > > & getNodeToGrainWeightMap () const
 Returns a map consisting of the node index followd by a vector of all grain weights for that node. More...
 
const std::map< dof_id_type, std::vector< Real > > & getNodeToPhaseWeightMap () const
 Returns a map consisting of the node index followd by a vector of all phase weights for that node. More...
 
void meshChanged ()
 Maps need to be updated when the mesh changes. More...
 

Static Public Member Functions

static InputParameters validParams ()
 
static MooseEnum getPointDataFieldType ()
 
static MooseEnum getAvgDataFieldType ()
 

Protected Member Functions

unsigned indexFromPoint (const Point &p) const
 Computes a global index in the _data array given an input centroid point. More...
 
unsigned indexFromIndex (unsigned int var) const
 Transfer the index into the _avg_data array from given index. More...
 
void buildNodeWeightMaps ()
 Build grain and phase weight maps. More...
 

Protected Attributes

unsigned int _custom_columns
 number of additional custom data columns More...
 
std::vector< EBSDPointData > _data
 Logically three-dimensional data indexed by geometric points in a 1D vector. More...
 
std::vector< EBSDAvgData_avg_data
 Averages by (global) grain ID. More...
 
std::vector< EulerAngles_avg_angles
 Euler Angles by (global) grain ID. More...
 
std::map< unsigned int, unsigned int > _global_id_map
 map from feature_id to global_id More...
 
std::vector< std::vector< unsigned int > > _global_id
 global ID for given phases and grains More...
 
std::map< dof_id_type, std::vector< Real > > _node_to_grain_weight_map
 Map of grain weights per node. More...
 
std::map< dof_id_type, std::vector< Real > > _node_to_phase_weight_map
 Map of phase weights per node. More...
 
const int & _time_step
 current timestep. Maps are only rebuild on mesh change during time step zero More...
 
unsigned int _mesh_dimension
 Dimension of the problem domain. More...
 
unsigned int _bins
 number of bins for each quaternion component More...
 
unsigned int _L_norm
 L_norm value for averaging. More...
 
unsigned _nx
 The number of values in the x, y and z directions. More...
 
unsigned _ny
 
unsigned _nz
 
Real _dx
 The spacing of the values in x, y and z directions. More...
 
Real _dy
 
Real _dz
 
Real _minx
 Grid origin. More...
 
Real _miny
 
Real _minz
 
Real _maxx
 Maximum grid extent. More...
 
Real _maxy
 
Real _maxz
 
MooseMesh & _mesh
 MooseMesh Variables. More...
 
NonlinearSystemBase & _nl
 
unsigned int _grain_num
 Variables needed to determine reduced order parameter values. More...
 
Point _bottom_left
 
Point _top_right
 
Point _range
 

Detailed Description

A GeneralUserObject that reads an EBSD file and stores the centroid data in a data structure which indexes on element centroids.

Grains are indexed through multiple schemes:

Phases are referred to using the numbers in the EBSD data file. In case the phase number in the data file starts at 1 the phase 0 will simply contain no grains.

Definition at line 36 of file EBSDReader.h.

Constructor & Destructor Documentation

◆ EBSDReader()

EBSDReader::EBSDReader ( const InputParameters &  params)

Definition at line 35 of file EBSDReader.C.

36  : EulerAngleProvider(params),
37  _mesh(_fe_problem.mesh()),
38  _nl(_fe_problem.getNonlinearSystemBase()),
39  _grain_num(0),
40  _custom_columns(getParam<unsigned int>("custom_columns")),
41  _time_step(_fe_problem.timeStep()),
42  _mesh_dimension(_mesh.dimension()),
43  _bins(getParam<unsigned int>("bins")),
44  _L_norm(getParam<Real>("L_norm")),
45  _nx(0),
46  _ny(0),
47  _nz(0),
48  _dx(0.),
49  _dy(0.),
50  _dz(0.)
51 {
52  readFile();
53  // throws an error for zero bins
54  if (_bins == 0)
55  mooseError("One cannot have zero bins");
56 }

◆ ~EBSDReader()

EBSDReader::~EBSDReader ( )
virtual

Definition at line 342 of file EBSDReader.C.

342 {}

Member Function Documentation

◆ buildNodeWeightMaps()

void EBSDReader::buildNodeWeightMaps ( )
protected

Build grain and phase weight maps.

Definition at line 461 of file EBSDReader.C.

462 {
463  // Import nodeToElemMap from MooseMesh for current node
464  // This map consists of the node index followed by a vector of element indices that are associated
465  // with that node
466  const std::map<dof_id_type, std::vector<dof_id_type>> & node_to_elem_map =
467  _mesh.nodeToActiveSemilocalElemMap();
468  libMesh::MeshBase & mesh = _mesh.getMesh();
469 
470  // Loop through each node in mesh and calculate eta values for each grain associated with the node
471  for (const auto & node : as_range(mesh.active_nodes_begin(), mesh.active_nodes_end()))
472  {
473  // Get node_id
474  const dof_id_type node_id = node->id();
475 
476  // Initialize map entries for current node
477  _node_to_grain_weight_map[node_id].assign(getGrainNum(), 0.0);
478  _node_to_phase_weight_map[node_id].assign(getPhaseNum(), 0.0);
479 
480  // Loop through element indices associated with the current node and record weighted eta value
481  // in new map
482  const auto & node_to_elem_pair = node_to_elem_map.find(node_id);
483  if (node_to_elem_pair != node_to_elem_map.end())
484  {
485  unsigned int n_elems =
486  node_to_elem_pair->second
487  .size(); // n_elems can range from 1 to 4 for 2D and 1 to 8 for 3D problems
488 
489  for (unsigned int ne = 0; ne < n_elems; ++ne)
490  {
491  // Current element index
492  unsigned int elem_id = (node_to_elem_pair->second)[ne];
493 
494  // Retrieve EBSD grain number for the current element index
495  const Elem * elem = mesh.elem_ptr(elem_id);
496  const EBSDReader::EBSDPointData & d = getData(elem->centroid());
497 
498  // get the (global) grain ID for the EBSD feature ID
499  const unsigned int global_id = getGlobalID(d._feature_id);
500 
501  // Calculate eta value and add to map
502  _node_to_grain_weight_map[node_id][global_id] += 1.0 / n_elems;
503  _node_to_phase_weight_map[node_id][d._phase] += 1.0 / n_elems;
504  }
505  }
506  }
507 }

Referenced by meshChanged(), and readFile().

◆ execute()

virtual void EBSDReader::execute ( )
inlinevirtual

Definition at line 45 of file EBSDReader.h.

45 {}

◆ finalize()

virtual void EBSDReader::finalize ( )
inlinevirtual

Definition at line 46 of file EBSDReader.h.

46 {}

◆ getAvgData() [1/2]

const EBSDReader::EBSDAvgData & EBSDReader::getAvgData ( unsigned int  i) const

Get the requested type of average data for (global) grain number i.

Definition at line 351 of file EBSDReader.C.

352 {
353  return _avg_data[indexFromIndex(var)];
354 }

Referenced by PolycrystalEBSD::getGrainsBasedOnPoint(), and EBSDReaderAvgDataAux::precalculateValue().

◆ getAvgData() [2/2]

const EBSDReader::EBSDAvgData & EBSDReader::getAvgData ( unsigned int  phase,
unsigned int  local_id 
) const

Get the requested type of average data for a given phase and (local) grain.

Definition at line 363 of file EBSDReader.C.

364 {
365  return _avg_data[indexFromIndex(_global_id[phase][local_id])];
366 }

◆ getAvgDataAccessFunctor()

MooseSharedPointer< EBSDAccessFunctors::EBSDAvgDataFunctor > EBSDReader::getAvgDataAccessFunctor ( const MooseEnum &  field_name) const

Factory function to return a average functor specified by name.

Definition at line 556 of file EBSDReader.C.

557 {
558  EBSDAvgDataFunctor * ret_val = NULL;
559 
560  switch (field_name)
561  {
562  case 0: // phi1
563  ret_val = new EBSDAvgDataPhi1();
564  break;
565  case 1: // phi
566  ret_val = new EBSDAvgDataPhi();
567  break;
568  case 2: // phi2
569  ret_val = new EBSDAvgDataPhi2();
570  break;
571  case 3: // phase
572  ret_val = new EBSDAvgDataPhase();
573  break;
574  case 4: // symmetry
575  ret_val = new EBSDAvgDataSymmetry();
576  break;
577  case 5: // local_id
578  ret_val = new EBSDAvgDataLocalID();
579  break;
580  case 6: // feature_id
581  ret_val = new EBSDAvgDataFeatureID();
582  break;
583  default:
584  {
585  // check for custom columns
586  for (unsigned int i = 0; i < _custom_columns; ++i)
587  if (field_name == "CUSTOM" + Moose::stringify(i))
588  {
589  ret_val = new EBSDAvgDataCustom(i);
590  break;
591  }
592  }
593  }
594 
595  // If ret_val was not set by any of the above cases, throw an error.
596  if (!ret_val)
597  mooseError("Error: Please input supported EBSD_param");
598 
599  // If we made it here, wrap up the the ret_val in a
600  // MooseSharedPointer and ship it off.
601  return MooseSharedPointer<EBSDAvgDataFunctor>(ret_val);
602 }

◆ getAvgDataFieldType()

MooseEnum EBSDAccessFunctors::getAvgDataFieldType ( )
staticinherited

Definition at line 19 of file EBSDAccessFunctors.C.

20 {
21  return MooseEnum("phi1 phi phi2 phase symmetry local_id feature_id", "", true);
22 }

Referenced by validParams< EBSDReaderAvgDataAux >().

◆ getData()

const EBSDReader::EBSDPointData & EBSDReader::getData ( const Point &  p) const

Get the requested type of data at the point p.

Definition at line 345 of file EBSDReader.C.

346 {
347  return _data[indexFromPoint(p)];
348 }

Referenced by buildNodeWeightMaps(), PolycrystalEBSD::getGrainsBasedOnPoint(), and EBSDReaderPointDataAux::precalculateValue().

◆ getEulerAngles()

const EulerAngles & EBSDReader::getEulerAngles ( unsigned int  var) const
virtual

EulerAngleProvider interface implementation to fetch a triplet of Euler angles.

Implements EulerAngleProvider.

Definition at line 357 of file EBSDReader.C.

358 {
359  return _avg_angles[indexFromIndex(var)];
360 }

◆ getFeatureID() [1/2]

unsigned int EBSDReader::getFeatureID ( unsigned int  global_id) const
inline

Return the EBSD feature id for a given (global) grain number.

Definition at line 89 of file EBSDReader.h.

90  {
91  return _avg_data[global_id]._feature_id;
92  }

◆ getFeatureID() [2/2]

unsigned int EBSDReader::getFeatureID ( unsigned int  phase,
unsigned int  local_id 
) const
inline

Return the EBSD feature id for a given phase and phase (local) grain number.

Definition at line 84 of file EBSDReader.h.

85  {
86  return _avg_data[_global_id[phase][local_id]]._feature_id;
87  }

◆ getGlobalID() [1/2]

unsigned int EBSDReader::getGlobalID ( unsigned int  feature_id) const
virtual

Return the (global) grain id for a given feature_id.

Definition at line 444 of file EBSDReader.C.

445 {
446  auto it = _global_id_map.find(feature_id);
447  if (it == _global_id_map.end())
448  mooseError("Invalid Feature ID");
449  return it->second;
450 }

◆ getGlobalID() [2/2]

virtual unsigned int EBSDReader::getGlobalID ( unsigned int  phase,
unsigned int  local_id 
) const
inlinevirtual

Return the (global) grain id for a given phase and (local) grain number.

Definition at line 95 of file EBSDReader.h.

96  {
97  return _global_id[phase][local_id];
98  }

Referenced by buildNodeWeightMaps(), PolycrystalEBSD::getGrainsBasedOnPoint(), PolycrystalEBSD::getNodalVariableValue(), and EulerAngleProvider2RGBAux::precalculateValue().

◆ getGrainNum() [1/2]

unsigned int EBSDReader::getGrainNum ( ) const
virtual

Return the total number of grains.

Implements EulerAngleProvider.

Definition at line 369 of file EBSDReader.C.

370 {
371  return _grain_num;
372 }

Referenced by buildNodeWeightMaps(), PolycrystalEBSD::getNumGrains(), and EulerAngleProvider2RGBAux::getNumGrains().

◆ getGrainNum() [2/2]

unsigned int EBSDReader::getGrainNum ( unsigned int  phase) const
virtual

Return the number of grains in a given phase.

Definition at line 375 of file EBSDReader.C.

376 {
377  return _global_id[phase].size();
378 }

◆ getNodeToGrainWeightMap()

const std::map< dof_id_type, std::vector< Real > > & EBSDReader::getNodeToGrainWeightMap ( ) const

Returns a map consisting of the node index followd by a vector of all grain weights for that node.

Needed by ReconVarIC

Definition at line 432 of file EBSDReader.C.

433 {
435 }

◆ getNodeToPhaseWeightMap()

const std::map< dof_id_type, std::vector< Real > > & EBSDReader::getNodeToPhaseWeightMap ( ) const

Returns a map consisting of the node index followd by a vector of all phase weights for that node.

Needed by ReconPhaseVarIC

Definition at line 438 of file EBSDReader.C.

439 {
441 }

◆ getPhaseNum()

virtual unsigned int EBSDReader::getPhaseNum ( ) const
inlinevirtual

Return the total number of phases.

Definition at line 76 of file EBSDReader.h.

76 { return _global_id.size(); }

Referenced by buildNodeWeightMaps().

◆ getPointDataAccessFunctor()

MooseSharedPointer< EBSDAccessFunctors::EBSDPointDataFunctor > EBSDReader::getPointDataAccessFunctor ( const MooseEnum &  field_name) const

Factory function to return a point functor specified by name.

Definition at line 510 of file EBSDReader.C.

511 {
512  EBSDPointDataFunctor * ret_val = NULL;
513 
514  switch (field_name)
515  {
516  case 0: // phi1
517  ret_val = new EBSDPointDataPhi1();
518  break;
519  case 1: // phi
520  ret_val = new EBSDPointDataPhi();
521  break;
522  case 2: // phi2
523  ret_val = new EBSDPointDataPhi2();
524  break;
525  case 3: // grain
526  ret_val = new EBSDPointDataFeatureID();
527  break;
528  case 4: // phase
529  ret_val = new EBSDPointDataPhase();
530  break;
531  case 5: // symmetry
532  ret_val = new EBSDPointDataSymmetry();
533  break;
534  default:
535  {
536  // check for custom columns
537  for (unsigned int i = 0; i < _custom_columns; ++i)
538  if (field_name == "CUSTOM" + Moose::stringify(i))
539  {
540  ret_val = new EBSDPointDataCustom(i);
541  break;
542  }
543  }
544  }
545 
546  // If ret_val was not set by any of the above cases, throw an error.
547  if (!ret_val)
548  mooseError("Error: Please input supported EBSD_param");
549 
550  // If we made it here, wrap up the the ret_val in a
551  // MooseSharedPointer and ship it off.
552  return MooseSharedPointer<EBSDPointDataFunctor>(ret_val);
553 }

◆ getPointDataFieldType()

MooseEnum EBSDAccessFunctors::getPointDataFieldType ( )
staticinherited

Definition at line 13 of file EBSDAccessFunctors.C.

14 {
15  return MooseEnum("phi1 phi phi2 feature_id phase symmetry", "", true);
16 }

Referenced by validParams< EBSDReaderPointDataAux >().

◆ indexFromIndex()

unsigned int EBSDReader::indexFromIndex ( unsigned int  var) const
protected

Transfer the index into the _avg_data array from given index.

Definition at line 415 of file EBSDReader.C.

416 {
417 
418  // Transfer the index into the _avg_data array.
419  unsigned avg_index = var;
420 
421  // Don't access out of range!
422  if (avg_index >= _avg_data.size())
423  mooseError("Error! Index out of range in EBSDReader::indexFromIndex(), index: ",
424  avg_index,
425  " size: ",
426  _avg_data.size());
427 
428  return avg_index;
429 }

Referenced by getAvgData(), and getEulerAngles().

◆ indexFromPoint()

unsigned int EBSDReader::indexFromPoint ( const Point &  p) const
protected

Computes a global index in the _data array given an input centroid point.

Definition at line 381 of file EBSDReader.C.

382 {
383  // Don't assume an ordering on the input data, use the (x, y,
384  // z) values of this centroid to determine the index.
385  unsigned int x_index, y_index, z_index, global_index;
386 
387  x_index = (unsigned int)((p(0) - _minx) / _dx);
388  y_index = (unsigned int)((p(1) - _miny) / _dy);
389  if (p(0) <= _minx || p(0) >= _maxx || p(1) <= _miny || p(1) >= _maxy)
390  mooseError("Data points must be on the interior of the mesh elements. In EBSDReader ", name());
391 
392  if (_mesh_dimension == 3)
393  {
394  z_index = (unsigned int)((p(2) - _minz) / _dz);
395  global_index = z_index * _ny;
396  if (p(2) <= _minz || p(2) >= _maxz)
397  mooseError("Data points must be on the interior of the mesh elements. In EBSDReader ",
398  name());
399  }
400  else
401  global_index = 0;
402 
403  // Compute the global index into the _data array. This stores points
404  // in a [z][y][x] ordering.
405  global_index = (global_index + y_index) * _nx + x_index;
406 
407  // Don't access out of range!
408  mooseAssert(global_index < _data.size(),
409  "global_index " << global_index << " points out of _data range: " << _data.size());
410 
411  return global_index;
412 }

Referenced by getData(), and readFile().

◆ initialize()

virtual void EBSDReader::initialize ( )
inlinevirtual

Definition at line 44 of file EBSDReader.h.

44 {}

◆ meshChanged()

void EBSDReader::meshChanged ( )

Maps need to be updated when the mesh changes.

Definition at line 453 of file EBSDReader.C.

454 {
455  // maps are only rebuild for use in initial conditions, which happens in time step zero
456  if (_time_step == 0)
458 }

◆ readFile()

void EBSDReader::readFile ( )
virtual

Markley, F. Landis, Yang Cheng, John Lucas Crassidis, and Yaakov Oshman. "Averaging quaternions." Journal of Guidance, Control, and Dynamics 30, no. 4 (2007): 1193-1197. A 4 by N matrix (Q) is constructed, where N is the number of quaternions. A weight matrix (W) is created. The eigen vector corresponding to the maximum eigen value of Q*W*Q' is the weighted average quaternion

If no bin exists which has atleast 50% of total quaternions in a grain then the EBSD data may not be reliable Note: The limit 50% is arbitrary

Definition at line 59 of file EBSDReader.C.

60 {
61  // No need to re-read data upon recovery
62  if (_app.isRecovering())
63  return;
64 
65  // Fetch and check mesh
66  EBSDMesh * mesh = dynamic_cast<EBSDMesh *>(&_mesh);
67  if (mesh == NULL)
68  mooseError("Please use an EBSDMesh in your simulation.");
69  std::ifstream stream_in(mesh->getEBSDFilename().c_str());
70  if (!stream_in)
71  mooseError("Can't open EBSD file: ", mesh->getEBSDFilename());
72 
73  const EBSDMesh::EBSDMeshGeometry & g = mesh->getEBSDGeometry();
74  // Copy file header data from the EBSDMesh
75  _dx = g.d[0];
76  _nx = g.n[0];
77  _minx = g.min[0];
78  _maxx = _minx + _dx * _nx;
79 
80  _dy = g.d[1];
81  _ny = g.n[1];
82  _miny = g.min[1];
83  _maxy = _miny + _dy * _ny;
84 
85  _dz = g.d[2];
86  _nz = g.n[2];
87  _minz = g.min[2];
88  _maxz = _minz + _dz * _nz;
89 
90  // Resize the _data array
91  unsigned total_size = g.dim < 3 ? _nx * _ny : _nx * _ny * _nz;
92  _data.resize(total_size);
93 
94  std::string line;
95  while (std::getline(stream_in, line))
96  {
97  if (line.find("#") != 0)
98  {
99  // Temporary variables to read in on each line
100  EBSDPointData d;
101  Real x, y, z;
102 
103  std::istringstream iss(line);
104  iss >> d._phi1 >> d._Phi >> d._phi2 >> x >> y >> z >> d._feature_id >> d._phase >>
105  d._symmetry;
106 
107  // Transform angles to degrees
108  d._phi1 *= 180.0 / libMesh::pi;
109  d._Phi *= 180.0 / libMesh::pi;
110  d._phi2 *= 180.0 / libMesh::pi;
111 
112  // Custom columns
113  d._custom.resize(_custom_columns);
114  for (unsigned int i = 0; i < _custom_columns; ++i)
115  if (!(iss >> d._custom[i]))
116  mooseError("Unable to read in EBSD custom data column #", i);
117 
118  if (x < _minx || y < _miny || x > _maxx || y > _maxy ||
119  (g.dim == 3 && (z < _minz || z > _maxz)))
120  mooseError("EBSD Data ouside of the domain declared in the header ([",
121  _minx,
122  ':',
123  _maxx,
124  "], [",
125  _miny,
126  ':',
127  _maxy,
128  "], [",
129  _minz,
130  ':',
131  _maxz,
132  "]) dim=",
133  g.dim,
134  "\n",
135  line);
136 
137  d._p = Point(x, y, z);
138 
139  // determine number of grains in the dataset
140  if (_global_id_map.find(d._feature_id) == _global_id_map.end())
141  _global_id_map[d._feature_id] = _grain_num++;
142 
143  unsigned int global_index = indexFromPoint(Point(x, y, z));
144  _data[global_index] = d;
145  }
146  }
147  stream_in.close();
148 
149  // Resize the variables
150  _avg_data.resize(_grain_num);
151  _avg_angles.resize(_grain_num);
152 
153  // clear the averages
154  for (unsigned int i = 0; i < _grain_num; ++i)
155  {
156  EBSDAvgData & a = _avg_data[i];
157  a._symmetry = a._phase = a._n = 0;
158  a._p = 0.0;
159  a._custom.assign(_custom_columns, 0.0);
160 
161  EulerAngles & b = _avg_angles[i];
162  b.phi1 = b.Phi = b.phi2 = 0.0;
163  }
164 
165  // Array of vectors to store quaternions of each grain
166  std::vector<std::vector<Eigen::Quaternion<Real>>> quat(_grain_num);
167 
168  // Iterate through data points to store orientation information for each grain
169  for (auto & j : _data)
170  {
171  EBSDAvgData & a = _avg_data[_global_id_map[j._feature_id]];
172  EulerAngles angles;
173 
174  angles.phi1 = j._phi1;
175  angles.Phi = j._Phi;
176  angles.phi2 = j._phi2;
177 
178  // convert Euler angles to quaternions
179  Eigen::Quaternion<Real> q = angles.toQuaternion();
180 
181  quat[_global_id_map[j._feature_id]].push_back(q);
182 
183  if (a._n == 0)
184  a._phase = j._phase;
185  else if (a._phase != j._phase)
186  mooseError("An EBSD feature needs to have a uniform phase.");
187 
188  if (a._n == 0)
189  a._symmetry = j._symmetry;
190  else if (a._symmetry != j._symmetry)
191  mooseError("An EBSD feature needs to have a uniform symmetry parameter.");
192 
193  for (unsigned int i = 0; i < _custom_columns; ++i)
194  a._custom[i] += j._custom[i];
195 
196  // store the feature (or grain) ID
197  a._feature_id = j._feature_id;
198 
199  a._p += j._p;
200  a._n++;
201  }
202  // creating a vector of maps to store the quaternion count for each bin index
203  std::vector<
204  std::map<std::tuple<unsigned int, unsigned int, unsigned int, unsigned int>, unsigned int>>
205  feature_weights(_grain_num);
206  // creating a vector of vectors to store the bin index corresponding to a quaternion
207  std::vector<std::vector<std::tuple<unsigned int, unsigned int, unsigned int, unsigned int>>>
208  quat_to_bin(_grain_num);
209 
210  for (unsigned int i = 0; i < _grain_num; i++)
211  {
212  EBSDAvgData & a = _avg_data[i];
213  EulerAngles & b = _avg_angles[i];
214 
215  if (a._n == 0)
216  continue;
217 
218  Real w_index, x_index, y_index, z_index;
219  Real w, x, y, z;
220  std::vector<std::tuple<double, Eigen::VectorXd>> eigen_vectors_and_values;
221 
222  // creating an empty map
223  feature_weights.push_back(
224  std::map<std::tuple<unsigned int, unsigned int, unsigned int, unsigned int>,
225  unsigned int>());
226 
227  // looping through quaternions of each grain
228  for (unsigned int k = 0; k < quat[i].size(); k++)
229  {
230  std::tuple<unsigned int, unsigned int, unsigned int, unsigned int> bin;
231  w_index = int((quat[i][k].w() + 1) * 0.5 * _bins);
232  x_index = int((quat[i][k].x() + 1) * 0.5 * _bins);
233  y_index = int((quat[i][k].y() + 1) * 0.5 * _bins);
234  z_index = int((quat[i][k].z() + 1) * 0.5 * _bins);
235 
236  bin = std::make_tuple(w_index, x_index, y_index, z_index);
237 
238  // storing the bincorresponding to the quaternion quat[i][k]
239  quat_to_bin[i].push_back(bin);
240 
241  // storing the bin name and its corresponding size value
242  auto j = feature_weights[i].find(bin);
243  if (j == feature_weights[i].end())
244  feature_weights[i].emplace_hint(j, bin, 1);
245  else
246  j->second++;
247  }
248 
258  // creating a quaternion matrix
259  Eigen::MatrixXd quat_mat(4, quat[i].size());
260  // creating the weight matrix
261  Eigen::MatrixXd weight = Eigen::MatrixXd::Identity(quat[i].size(), quat[i].size());
262 
263  unsigned int bin_size;
264  bool data_quality_ok = false;
265  Real total_weight = 0.0;
266 
267  for (unsigned int j = 0; j < quat[i].size(); j++)
268  {
269  bin_size = feature_weights[i][quat_to_bin[i][j]];
270  w = quat[i][j].w();
271  x = quat[i][j].x();
272  y = quat[i][j].y();
273  z = quat[i][j].z();
274 
275  // instantiating columns of the matrix
276  quat_mat.col(j) << w, x, y, z;
277  // assigning weights to each quaternion
278  weight(j, j) = std::pow(bin_size, _L_norm);
279  total_weight += weight(j, j);
285  if (bin_size / quat[i].size() > 0.5)
286  data_quality_ok = true;
287  }
288 
289  weight = weight / total_weight;
290 
291  // throws a warning if EBSD data is not reliable
292  if (!data_quality_ok)
293  _console << COLOR_YELLOW << "EBSD data may not be reliable"
294  << "\n"
295  << COLOR_DEFAULT;
296 
297  // compute eigen values and eigen vectors
298  Eigen::EigenSolver<Eigen::MatrixXd> EigenSolver(quat_mat * weight * quat_mat.transpose());
299  Eigen::VectorXd eigen_values = EigenSolver.eigenvalues().real();
300  Eigen::MatrixXd eigen_vectors = EigenSolver.eigenvectors().real();
301 
302  // creating a tuple of eigen values and eigen vectors
303  for (unsigned int i = 0; i < eigen_values.size(); i++)
304  {
305  std::tuple<double, Eigen::VectorXd> vec_and_val(eigen_values[i], eigen_vectors.col(i));
306  eigen_vectors_and_values.push_back(vec_and_val);
307  }
308  // Sorting the eigen values and vectors in ascending order of eigen values
309  auto j = std::max_element(eigen_vectors_and_values.begin(),
310  eigen_vectors_and_values.end(),
311  [&](const std::tuple<double, Eigen::VectorXd> & a,
312  const std::tuple<double, Eigen::VectorXd> & b) -> bool {
313  return std::get<0>(a) < std::get<0>(b);
314  });
315  // Selecting eigen vector corresponding to max eigen value to compute average euler angle
316  Eigen::Quaternion<Real> q(
317  std::get<1>(*j)(0), std::get<1>(*j)(1), std::get<1>(*j)(2), std::get<1>(*j)(3));
318 
319  b = EulerAngles(q);
320 
321  // link the EulerAngles into the EBSDAvgData for access via the functors
322  a._angles = &b;
323 
324  if (a._phase >= _global_id.size())
325  _global_id.resize(a._phase + 1);
326 
327  // The averaged per grain data locally contains the phase id, local id, and
328  // original feature id. It is stored contiguously indexed by global id.
329  a._local_id = _global_id[a._phase].size();
330  _global_id[a._phase].push_back(i);
331 
332  a._p *= 1.0 / Real(a._n);
333 
334  for (unsigned int i = 0; i < _custom_columns; ++i)
335  a._custom[i] /= Real(a._n);
336  }
337  // Build maps to indicate the weights with which grain and phase data
338  // from the surrounding elements contributes to a node fo IC purposes
340 }

Referenced by EBSDReader().

◆ validParams()

InputParameters EulerAngleProvider::validParams ( )
staticinherited

Definition at line 15 of file EulerAngleProvider.C.

16 {
18 }

Referenced by EulerAngleFileReader::validParams().

Member Data Documentation

◆ _avg_angles

std::vector<EulerAngles> EBSDReader::_avg_angles
protected

Euler Angles by (global) grain ID.

Definition at line 147 of file EBSDReader.h.

Referenced by getEulerAngles(), and readFile().

◆ _avg_data

std::vector<EBSDAvgData> EBSDReader::_avg_data
protected

Averages by (global) grain ID.

Definition at line 144 of file EBSDReader.h.

Referenced by getAvgData(), getFeatureID(), indexFromIndex(), and readFile().

◆ _bins

unsigned int EBSDReader::_bins
protected

number of bins for each quaternion component

Definition at line 168 of file EBSDReader.h.

Referenced by EBSDReader(), and readFile().

◆ _bottom_left

Point EBSDReader::_bottom_left
protected

Definition at line 132 of file EBSDReader.h.

◆ _custom_columns

unsigned int EBSDReader::_custom_columns
protected

number of additional custom data columns

Definition at line 138 of file EBSDReader.h.

Referenced by getAvgDataAccessFunctor(), getPointDataAccessFunctor(), and readFile().

◆ _data

std::vector<EBSDPointData> EBSDReader::_data
protected

Logically three-dimensional data indexed by geometric points in a 1D vector.

Definition at line 141 of file EBSDReader.h.

Referenced by getData(), indexFromPoint(), and readFile().

◆ _dx

Real EBSDReader::_dx
protected

The spacing of the values in x, y and z directions.

Definition at line 177 of file EBSDReader.h.

Referenced by indexFromPoint(), and readFile().

◆ _dy

Real EBSDReader::_dy
protected

Definition at line 177 of file EBSDReader.h.

Referenced by indexFromPoint(), and readFile().

◆ _dz

Real EBSDReader::_dz
protected

Definition at line 177 of file EBSDReader.h.

Referenced by indexFromPoint(), and readFile().

◆ _global_id

std::vector<std::vector<unsigned int> > EBSDReader::_global_id
protected

global ID for given phases and grains

Definition at line 153 of file EBSDReader.h.

Referenced by getAvgData(), getFeatureID(), getGlobalID(), getGrainNum(), getPhaseNum(), and readFile().

◆ _global_id_map

std::map<unsigned int, unsigned int> EBSDReader::_global_id_map
protected

map from feature_id to global_id

Definition at line 150 of file EBSDReader.h.

Referenced by getGlobalID(), and readFile().

◆ _grain_num

unsigned int EBSDReader::_grain_num
protected

Variables needed to determine reduced order parameter values.

Definition at line 131 of file EBSDReader.h.

Referenced by getGrainNum(), and readFile().

◆ _L_norm

unsigned int EBSDReader::_L_norm
protected

L_norm value for averaging.

Definition at line 171 of file EBSDReader.h.

Referenced by readFile().

◆ _maxx

Real EBSDReader::_maxx
protected

Maximum grid extent.

Definition at line 183 of file EBSDReader.h.

Referenced by indexFromPoint(), and readFile().

◆ _maxy

Real EBSDReader::_maxy
protected

Definition at line 183 of file EBSDReader.h.

Referenced by indexFromPoint(), and readFile().

◆ _maxz

Real EBSDReader::_maxz
protected

Definition at line 183 of file EBSDReader.h.

Referenced by indexFromPoint(), and readFile().

◆ _mesh

MooseMesh& EBSDReader::_mesh
protected

MooseMesh Variables.

Definition at line 126 of file EBSDReader.h.

Referenced by buildNodeWeightMaps(), and readFile().

◆ _mesh_dimension

unsigned int EBSDReader::_mesh_dimension
protected

Dimension of the problem domain.

Definition at line 165 of file EBSDReader.h.

Referenced by indexFromPoint().

◆ _minx

Real EBSDReader::_minx
protected

Grid origin.

Definition at line 180 of file EBSDReader.h.

Referenced by indexFromPoint(), and readFile().

◆ _miny

Real EBSDReader::_miny
protected

Definition at line 180 of file EBSDReader.h.

Referenced by indexFromPoint(), and readFile().

◆ _minz

Real EBSDReader::_minz
protected

Definition at line 180 of file EBSDReader.h.

Referenced by indexFromPoint(), and readFile().

◆ _nl

NonlinearSystemBase& EBSDReader::_nl
protected

Definition at line 127 of file EBSDReader.h.

◆ _node_to_grain_weight_map

std::map<dof_id_type, std::vector<Real> > EBSDReader::_node_to_grain_weight_map
protected

Map of grain weights per node.

Definition at line 156 of file EBSDReader.h.

Referenced by buildNodeWeightMaps(), and getNodeToGrainWeightMap().

◆ _node_to_phase_weight_map

std::map<dof_id_type, std::vector<Real> > EBSDReader::_node_to_phase_weight_map
protected

Map of phase weights per node.

Definition at line 159 of file EBSDReader.h.

Referenced by buildNodeWeightMaps(), and getNodeToPhaseWeightMap().

◆ _nx

unsigned EBSDReader::_nx
protected

The number of values in the x, y and z directions.

Definition at line 174 of file EBSDReader.h.

Referenced by indexFromPoint(), and readFile().

◆ _ny

unsigned EBSDReader::_ny
protected

Definition at line 174 of file EBSDReader.h.

Referenced by indexFromPoint(), and readFile().

◆ _nz

unsigned EBSDReader::_nz
protected

Definition at line 174 of file EBSDReader.h.

Referenced by readFile().

◆ _range

Point EBSDReader::_range
protected

Definition at line 134 of file EBSDReader.h.

◆ _time_step

const int& EBSDReader::_time_step
protected

current timestep. Maps are only rebuild on mesh change during time step zero

Definition at line 162 of file EBSDReader.h.

Referenced by meshChanged().

◆ _top_right

Point EBSDReader::_top_right
protected

Definition at line 133 of file EBSDReader.h.


The documentation for this class was generated from the following files:
EBSDReader::_bins
unsigned int _bins
number of bins for each quaternion component
Definition: EBSDReader.h:168
EBSDReader::_maxz
Real _maxz
Definition: EBSDReader.h:183
EBSDReader::_data
std::vector< EBSDPointData > _data
Logically three-dimensional data indexed by geometric points in a 1D vector.
Definition: EBSDReader.h:141
pow
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
Definition: ExpressionBuilder.h:673
EulerAngles::phi1
Real phi1
Definition: EulerAngles.h:25
EBSDReader::getGlobalID
virtual unsigned int getGlobalID(unsigned int phase, unsigned int local_id) const
Return the (global) grain id for a given phase and (local) grain number.
Definition: EBSDReader.h:95
EulerAngles::toQuaternion
Eigen::Quaternion< Real > toQuaternion()
Definition: EulerAngles.C:44
EBSDReader::_mesh
MooseMesh & _mesh
MooseMesh Variables.
Definition: EBSDReader.h:126
EulerAngles::Phi
Real Phi
Definition: EulerAngles.h:25
EBSDReader::indexFromIndex
unsigned indexFromIndex(unsigned int var) const
Transfer the index into the _avg_data array from given index.
Definition: EBSDReader.C:415
EBSDReader::_time_step
const int & _time_step
current timestep. Maps are only rebuild on mesh change during time step zero
Definition: EBSDReader.h:162
EBSDReader::_dz
Real _dz
Definition: EBSDReader.h:177
EBSDReader::_node_to_grain_weight_map
std::map< dof_id_type, std::vector< Real > > _node_to_grain_weight_map
Map of grain weights per node.
Definition: EBSDReader.h:156
EBSDReader::_ny
unsigned _ny
Definition: EBSDReader.h:174
EBSDReader::_dy
Real _dy
Definition: EBSDReader.h:177
EBSDReader::_custom_columns
unsigned int _custom_columns
number of additional custom data columns
Definition: EBSDReader.h:138
EBSDReader::_mesh_dimension
unsigned int _mesh_dimension
Dimension of the problem domain.
Definition: EBSDReader.h:165
EBSDReader::getGrainNum
virtual unsigned int getGrainNum() const
Return the total number of grains.
Definition: EBSDReader.C:369
EBSDReader::_nl
NonlinearSystemBase & _nl
Definition: EBSDReader.h:127
EBSDReader::_avg_angles
std::vector< EulerAngles > _avg_angles
Euler Angles by (global) grain ID.
Definition: EBSDReader.h:147
EBSDReader::_global_id
std::vector< std::vector< unsigned int > > _global_id
global ID for given phases and grains
Definition: EBSDReader.h:153
EBSDReader::_maxx
Real _maxx
Maximum grid extent.
Definition: EBSDReader.h:183
EBSDReader::_grain_num
unsigned int _grain_num
Variables needed to determine reduced order parameter values.
Definition: EBSDReader.h:131
EBSDMesh
Mesh generated from parameters.
Definition: EBSDMesh.h:24
EBSDReader::_minx
Real _minx
Grid origin.
Definition: EBSDReader.h:180
EBSDReader::readFile
virtual void readFile()
Definition: EBSDReader.C:59
EBSDReader::_maxy
Real _maxy
Definition: EBSDReader.h:183
EBSDReader::buildNodeWeightMaps
void buildNodeWeightMaps()
Build grain and phase weight maps.
Definition: EBSDReader.C:461
EBSDReader::getPhaseNum
virtual unsigned int getPhaseNum() const
Return the total number of phases.
Definition: EBSDReader.h:76
EBSDReader::_nz
unsigned _nz
Definition: EBSDReader.h:174
validParams
InputParameters validParams()
name
const std::string name
Definition: Setup.h:21
EBSDMesh::getEBSDFilename
const std::string & getEBSDFilename() const
Definition: EBSDMesh.h:46
EBSDReader::_minz
Real _minz
Definition: EBSDReader.h:180
EBSDReader::_miny
Real _miny
Definition: EBSDReader.h:180
EBSDAccessFunctors::EBSDPointData::_feature_id
unsigned int _feature_id
EBSD feature id, (gklobal) grain number, symmetry, and phase data.
Definition: EBSDAccessFunctors.h:39
EBSDMesh::EBSDMeshGeometry
Definition: EBSDMesh.h:32
EBSDAccessFunctors::EBSDPointData
Per element EBSD data point.
Definition: EBSDAccessFunctors.h:27
EBSDReader::getData
const EBSDPointData & getData(const Point &p) const
Get the requested type of data at the point p.
Definition: EBSDReader.C:345
EBSDReader::_dx
Real _dx
The spacing of the values in x, y and z directions.
Definition: EBSDReader.h:177
EBSDReader::_nx
unsigned _nx
The number of values in the x, y and z directions.
Definition: EBSDReader.h:174
EBSDReader::_node_to_phase_weight_map
std::map< dof_id_type, std::vector< Real > > _node_to_phase_weight_map
Map of phase weights per node.
Definition: EBSDReader.h:159
EulerAngles
Euler angle triplet.
Definition: EulerAngles.h:22
EulerAngles::phi2
Real phi2
Definition: EulerAngles.h:25
EBSDAccessFunctors::EBSDPointData::_phase
unsigned int _phase
Definition: EBSDAccessFunctors.h:40
EBSDReader::indexFromPoint
unsigned indexFromPoint(const Point &p) const
Computes a global index in the _data array given an input centroid point.
Definition: EBSDReader.C:381
EulerAngleProvider::EulerAngleProvider
EulerAngleProvider(const InputParameters &parameters)
Definition: EulerAngleProvider.h:29
EBSDReader::_L_norm
unsigned int _L_norm
L_norm value for averaging.
Definition: EBSDReader.h:171
EBSDReader::_avg_data
std::vector< EBSDAvgData > _avg_data
Averages by (global) grain ID.
Definition: EBSDReader.h:144
EBSDMesh::getEBSDGeometry
const EBSDMeshGeometry & getEBSDGeometry() const
Definition: EBSDMesh.h:45
EBSDReader::_global_id_map
std::map< unsigned int, unsigned int > _global_id_map
map from feature_id to global_id
Definition: EBSDReader.h:150