www.mooseframework.org
PolycrystalEBSD.C
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 #include "PolycrystalEBSD.h"
9 #include "EBSDReader.h"
10 
11 template <>
12 InputParameters
14 {
15  InputParameters params = validParams<PolycrystalUserObjectBase>();
16  params.addClassDescription("Object for setting up a polycrystal structure from an EBSD Datafile");
17  params.addParam<UserObjectName>("ebsd_reader", "EBSD Reader for initial condition");
18  params.addParam<unsigned int>("phase", 0, "The phase to use for all queries. (Default: 0 ALL)");
19  return params;
20 }
21 
22 PolycrystalEBSD::PolycrystalEBSD(const InputParameters & parameters)
23  : PolycrystalUserObjectBase(parameters),
24  _phase(getParam<unsigned int>("phase")),
25  _ebsd_reader(getUserObject<EBSDReader>("ebsd_reader")),
26  _node_to_grain_weight_map(_ebsd_reader.getNodeToGrainWeightMap())
27 {
28 }
29 
30 void
32  std::vector<unsigned int> & grains) const
33 {
35 
36  // See if we are in a phase that we are actually tracking
37  if (_phase && _phase != d._phase)
38  {
39  grains.resize(0);
40  return;
41  }
42 
43  // Get the ids from the EBSD reader
44  const auto global_id = _ebsd_reader.getGlobalID(d._feature_id);
45  const auto local_id = _ebsd_reader.getAvgData(global_id)._local_id;
46 
47  grains.resize(1);
48  grains[0] = _phase ? local_id : global_id;
49 }
50 
51 unsigned int
53 {
54  if (_phase)
56  else
57  return _ebsd_reader.getGrainNum();
58 }
59 
60 Real
61 PolycrystalEBSD::getNodalVariableValue(unsigned int op_index, const Node & n) const
62 {
63  // Make sure the _current_node is in the node_to_grain_weight_map (return error if not in map)
64  const auto it = _node_to_grain_weight_map.find(n.id());
65 
66  if (it == _node_to_grain_weight_map.end())
67  mooseError("The following node id is not in the node map: ", n.id());
68 
69  // Increment through all grains at node_index (these are global IDs if consider_phase is false and
70  // local IDs otherwise)
71  const auto num_grains = getNumGrains();
72  for (auto index = decltype(num_grains)(0); index < num_grains; ++index)
73  {
74  // If the current order parameter index (_op_index) is equal to the assigned index
75  // (_assigned_op),
76  // set the value from node_to_grain_weight_map
77  auto grain_index = _phase ? _ebsd_reader.getGlobalID(_phase, index) : index;
78  mooseAssert(grain_index < it->second.size(), "grain_index out of range");
79  auto value = (it->second)[grain_index];
80  if (_grain_to_op[index] == op_index && value > 0.0)
81  return value;
82  }
83 
84  return 0.0;
85 }
86 
87 Real
88 PolycrystalEBSD::getVariableValue(unsigned int op_index, const Point & p) const
89 {
90  std::vector<unsigned int> grain_ids;
91  getGrainsBasedOnPoint(p, grain_ids);
92 
93  if (grain_ids.empty())
94  return -1.0;
95 
96  mooseAssert(grain_ids.size() == 1, "Expected only one grain at point in EBSDReader");
97  auto index = grain_ids[0];
98  mooseAssert(index < _grain_to_op.size(), "Index out of range");
99 
100  return _grain_to_op[index] == op_index ? 1.0 : 0.0;
101 }
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:93
virtual Real getVariableValue(unsigned int op_index, const Point &p) const override
Returns the variable value for a given op_index and mesh point.
const unsigned int _phase
This object provides the base capability for creating proper polycrystal ICs.
const std::map< dof_id_type, std::vector< Real > > & _node_to_grain_weight_map
const EBSDReader & _ebsd_reader
unsigned int _feature_id
EBSD feature id, (gklobal) grain number, symmetry, and phase data.
std::vector< unsigned int > _grain_to_op
A vector indicating which op is assigned to each grain.
InputParameters validParams< PolycrystalEBSD >()
Per element EBSD data point.
const EBSDPointData & getData(const Point &p) const
Get the requested type of data at the point p.
Definition: EBSDReader.C:224
A GeneralUserObject that reads an EBSD file and stores the centroid data in a data structure which in...
Definition: EBSDReader.h:34
virtual unsigned int getGrainNum() const
Return the total number of grains.
Definition: EBSDReader.C:248
InputParameters validParams< PolycrystalUserObjectBase >()
const EBSDAvgData & getAvgData(unsigned int i) const
Get the requested type of average data for (global) grain number i.
Definition: EBSDReader.C:230
PolycrystalEBSD(const InputParameters &parameters)
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...
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.
virtual unsigned int getNumGrains() const override
Must be overridden by the deriving class to provide the number of grains in the polycrystal structure...