https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PolycrystalEBSD.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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
14
17{
19 params.addClassDescription("Object for setting up a polycrystal structure from an EBSD Datafile");
20 params.addParam<unsigned int>("phase", "The phase to use for all queries.");
21 params.addParam<UserObjectName>("ebsd_reader", "EBSD Reader for initial condition");
22 return params;
23}
24
26 : PolycrystalUserObjectBase(parameters),
27 _phase(isParamValid("phase") ? getParam<unsigned int>("phase") : libMesh::invalid_uint),
28 _ebsd_reader(getUserObject<EBSDReader>("ebsd_reader")),
29 _node_to_grain_weight_map(_ebsd_reader.getNodeToGrainWeightMap())
30{
31}
32
33void
35 std::vector<unsigned int> & grains) const
36{
38
39 // See if we are in a phase that we are actually tracking
40 if (_phase != libMesh::invalid_uint && _phase != d._phase)
41 {
42 grains.resize(0);
43 return;
44 }
45
46 // Get the ids from the EBSD reader
47 const auto global_id = _ebsd_reader.getGlobalID(d._feature_id);
48 const auto local_id = _ebsd_reader.getAvgData(global_id)._local_id;
49
50 grains.resize(1);
51 grains[0] = _phase != libMesh::invalid_uint ? local_id : global_id;
52}
53
54unsigned int
62
63Real
64PolycrystalEBSD::getNodalVariableValue(unsigned int op_index, const Node & n) const
65{
66 // Make sure the _current_node is in the node_to_grain_weight_map (return error if not in map)
67 const auto it = _node_to_grain_weight_map.find(n.id());
68
69 if (it == _node_to_grain_weight_map.end())
70 mooseError("The following node id is not in the node map: ", n.id());
71
72 // Increment through all grains at node_index (these are global IDs if consider_phase is false and
73 // local IDs otherwise)
74 const auto num_grains = getNumGrains();
75 for (MooseIndex(num_grains) index = 0; index < num_grains; ++index)
76 {
77 // If the current order parameter index (_op_index) is equal to the assigned index
78 // (_assigned_op),
79 // set the value from node_to_grain_weight_map
80 auto grain_index =
82 mooseAssert(grain_index < it->second.size(), "grain_index out of range");
83 auto value = (it->second)[grain_index];
84 if (_grain_to_op.at(index) == op_index && value > 0.0)
85 return value;
86 }
87
88 return 0.0;
89}
90
91Real
92PolycrystalEBSD::getVariableValue(unsigned int op_index, const Point & p) const
93{
94 std::vector<unsigned int> grain_ids;
95 getGrainsBasedOnPoint(p, grain_ids);
96
97 if (grain_ids.empty())
98 return -1.0;
99
100 mooseAssert(grain_ids.size() == 1, "Expected only one grain at point in EBSDReader");
101 auto index = grain_ids[0];
102
103 return _grain_to_op.at(index) == op_index ? 1.0 : 0.0;
104}
const Real p
registerMooseObject("PhaseFieldApp", PolycrystalEBSD)
void ErrorVector unsigned int
A GeneralUserObject that reads an EBSD file and stores the centroid data in a data structure which in...
Definition EBSDReader.h:32
const EBSDPointData & getData(const Point &p) const
Get the requested type of data at the point p.
Definition EBSDReader.C:350
virtual unsigned int getGrainNum() const
Return the total number of grains.
Definition EBSDReader.C:374
const EBSDAvgData & getAvgData(unsigned int i) const
Get the requested type of average data for (global) grain number i.
Definition EBSDReader.C:356
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:92
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void mooseError(Args &&... args) const
static InputParameters validParams()
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 Real getVariableValue(unsigned int op_index, const Point &p) const override
Returns the variable value for a given op_index and mesh point.
virtual unsigned int getNumGrains() const override
Must be overridden by the deriving class to provide the number of grains in the polycrystal structure...
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...
const EBSDReader & _ebsd_reader
const std::map< dof_id_type, std::vector< Real > > & _node_to_grain_weight_map
const unsigned int _phase
PolycrystalEBSD(const InputParameters &parameters)
This object provides the base capability for creating proper polycrystal ICs.
std::map< unsigned int, unsigned int > _grain_to_op
A map of the grain_id to op.
static InputParameters validParams()
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
const unsigned int invalid_uint
unsigned int _local_id
Index in the per-phase list of global IDs.
Per element EBSD data point.