www.mooseframework.org
PolycrystalEBSD.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "PolycrystalEBSD.h"
11 #include "EBSDReader.h"
12 
13 registerMooseObject("PhaseFieldApp", PolycrystalEBSD);
14 
15 template <>
16 InputParameters
18 {
19  InputParameters params = validParams<PolycrystalUserObjectBase>();
20  params.addClassDescription("Object for setting up a polycrystal structure from an EBSD Datafile");
21  params.addParam<unsigned int>("phase", "The phase to use for all queries.");
22  params.addParam<UserObjectName>("ebsd_reader", "EBSD Reader for initial condition");
23  return params;
24 }
25 
26 PolycrystalEBSD::PolycrystalEBSD(const InputParameters & parameters)
27  : PolycrystalUserObjectBase(parameters),
28  _phase(isParamValid("phase") ? getParam<unsigned int>("phase") : libMesh::invalid_uint),
29  _ebsd_reader(getUserObject<EBSDReader>("ebsd_reader")),
30  _node_to_grain_weight_map(_ebsd_reader.getNodeToGrainWeightMap())
31 {
32 }
33 
34 void
36  std::vector<unsigned int> & grains) const
37 {
39 
40  // See if we are in a phase that we are actually tracking
41  if (_phase != libMesh::invalid_uint && _phase != d._phase)
42  {
43  grains.resize(0);
44  return;
45  }
46 
47  // Get the ids from the EBSD reader
48  const auto global_id = _ebsd_reader.getGlobalID(d._feature_id);
49  const auto local_id = _ebsd_reader.getAvgData(global_id)._local_id;
50 
51  grains.resize(1);
52  grains[0] = _phase != libMesh::invalid_uint ? local_id : global_id;
53 }
54 
55 unsigned int
57 {
58  if (_phase != libMesh::invalid_uint)
60  else
61  return _ebsd_reader.getGrainNum();
62 }
63 
64 Real
65 PolycrystalEBSD::getNodalVariableValue(unsigned int op_index, const Node & n) const
66 {
67  // Make sure the _current_node is in the node_to_grain_weight_map (return error if not in map)
68  const auto it = _node_to_grain_weight_map.find(n.id());
69 
70  if (it == _node_to_grain_weight_map.end())
71  mooseError("The following node id is not in the node map: ", n.id());
72 
73  // Increment through all grains at node_index (these are global IDs if consider_phase is false and
74  // local IDs otherwise)
75  const auto num_grains = getNumGrains();
76  for (MooseIndex(num_grains) index = 0; index < num_grains; ++index)
77  {
78  // If the current order parameter index (_op_index) is equal to the assigned index
79  // (_assigned_op),
80  // set the value from node_to_grain_weight_map
81  auto grain_index =
82  _phase != libMesh::invalid_uint ? _ebsd_reader.getGlobalID(_phase, index) : index;
83  mooseAssert(grain_index < it->second.size(), "grain_index out of range");
84  auto value = (it->second)[grain_index];
85  if (_grain_to_op[index] == op_index && value > 0.0)
86  return value;
87  }
88 
89  return 0.0;
90 }
91 
92 Real
93 PolycrystalEBSD::getVariableValue(unsigned int op_index, const Point & p) const
94 {
95  std::vector<unsigned int> grain_ids;
96  getGrainsBasedOnPoint(p, grain_ids);
97 
98  if (grain_ids.empty())
99  return -1.0;
100 
101  mooseAssert(grain_ids.size() == 1, "Expected only one grain at point in EBSDReader");
102  auto index = grain_ids[0];
103  mooseAssert(index < _grain_to_op.size(), "Index out of range");
104 
105  return _grain_to_op[index] == op_index ? 1.0 : 0.0;
106 }
PolycrystalEBSD::getNumGrains
virtual unsigned int getNumGrains() const override
Must be overridden by the deriving class to provide the number of grains in the polycrystal structure...
Definition: PolycrystalEBSD.C:56
PolycrystalEBSD
Definition: PolycrystalEBSD.h:21
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
PolycrystalUserObjectBase::_grain_to_op
std::vector< unsigned int > _grain_to_op
A vector indicating which op is assigned to each grain.
Definition: PolycrystalUserObjectBase.h:150
libMesh
Definition: RANFSNormalMechanicalContact.h:24
PolycrystalEBSD::_node_to_grain_weight_map
const std::map< dof_id_type, std::vector< Real > > & _node_to_grain_weight_map
Definition: PolycrystalEBSD.h:35
PolycrystalEBSD.h
PolycrystalEBSD::_ebsd_reader
const EBSDReader & _ebsd_reader
Definition: PolycrystalEBSD.h:34
PolycrystalEBSD::getGrainsBasedOnPoint
virtual void getGrainsBasedOnPoint(const Point &point, std::vector< unsigned int > &grains) const override
Method for retrieving active grain IDs based on some point in the mesh.
Definition: PolycrystalEBSD.C:35
PolycrystalUserObjectBase
This object provides the base capability for creating proper polycrystal ICs.
Definition: PolycrystalUserObjectBase.h:27
EBSDReader.h
EBSDReader::getGrainNum
virtual unsigned int getGrainNum() const
Return the total number of grains.
Definition: EBSDReader.C:369
PolycrystalEBSD::_phase
const unsigned int _phase
Definition: PolycrystalEBSD.h:33
registerMooseObject
registerMooseObject("PhaseFieldApp", PolycrystalEBSD)
EBSDReader
A GeneralUserObject that reads an EBSD file and stores the centroid data in a data structure which in...
Definition: EBSDReader.h:36
PolycrystalEBSD::getVariableValue
virtual Real getVariableValue(unsigned int op_index, const Point &p) const override
Returns the variable value for a given op_index and mesh point.
Definition: PolycrystalEBSD.C:93
EBSDAccessFunctors::EBSDPointData::_feature_id
unsigned int _feature_id
EBSD feature id, (gklobal) grain number, symmetry, and phase data.
Definition: EBSDAccessFunctors.h:39
EBSDAccessFunctors::EBSDPointData
Per element EBSD data point.
Definition: EBSDAccessFunctors.h:27
EBSDReader::getAvgData
const EBSDAvgData & getAvgData(unsigned int i) const
Get the requested type of average data for (global) grain number i.
Definition: EBSDReader.C:351
validParams< PolycrystalUserObjectBase >
InputParameters validParams< PolycrystalUserObjectBase >()
Definition: PolycrystalUserObjectBase.C:24
EBSDReader::getData
const EBSDPointData & getData(const Point &p) const
Get the requested type of data at the point p.
Definition: EBSDReader.C:345
PolycrystalEBSD::getNodalVariableValue
virtual Real getNodalVariableValue(unsigned int op_index, const Node &n) const override
Similarly to the getVariableValue method, this method also returns values but may be optimized for re...
Definition: PolycrystalEBSD.C:65
EBSDAccessFunctors::EBSDPointData::_phase
unsigned int _phase
Definition: EBSDAccessFunctors.h:40
PolycrystalEBSD::PolycrystalEBSD
PolycrystalEBSD(const InputParameters &parameters)
Definition: PolycrystalEBSD.C:26
validParams< PolycrystalEBSD >
InputParameters validParams< PolycrystalEBSD >()
Definition: PolycrystalEBSD.C:17
EBSDAccessFunctors::EBSDAvgData::_local_id
unsigned int _local_id
Index in the per-phase list of global IDs.
Definition: EBSDAccessFunctors.h:61