www.mooseframework.org
EulerAngleProvider2RGBAux.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 
11 #include "GrainTracker.h"
12 #include "EulerAngleProvider.h"
13 #include "Euler2RGB.h"
14 #include "EBSDReader.h"
15 
17 
18 template <>
19 InputParameters
21 {
22  InputParameters params = validParams<AuxKernel>();
23  params.addClassDescription("Output RGB representation of crystal orientation from user object to "
24  "an AuxVariable. The entire domain must have the same crystal "
25  "structure.");
26  params.addParam<unsigned int>("phase", "The phase to use for all queries.");
27  MooseEnum sd_enum = MooseEnum("100=1 010=2 001=3", "001");
28  params.addParam<MooseEnum>("sd", sd_enum, "Reference sample direction");
29  MooseEnum structure_enum = MooseEnum(
30  "cubic=43 hexagonal=62 tetragonal=42 trigonal=32 orthorhombic=22 monoclinic=2 triclinic=1");
31  params.addRequiredParam<MooseEnum>(
32  "crystal_structure", structure_enum, "Crystal structure of the material");
33  MooseEnum output_types = MooseEnum("red green blue scalar", "scalar");
34  params.addParam<MooseEnum>("output_type", output_types, "Type of value that will be outputted");
35  params.addRequiredParam<UserObjectName>("euler_angle_provider",
36  "Name of Euler angle provider user object");
37  params.addRequiredParam<UserObjectName>("grain_tracker",
38  "The GrainTracker UserObject to get values from.");
39  params.addParam<Point>(
40  "no_grain_color",
41  Point(0, 0, 0),
42  "RGB value of color used to represent area with no grains, defaults to black");
43  return params;
44 }
45 
46 EulerAngleProvider2RGBAux::EulerAngleProvider2RGBAux(const InputParameters & parameters)
47  : AuxKernel(parameters),
48  _phase(isParamValid("phase") ? getParam<unsigned int>("phase") : libMesh::invalid_uint),
49  _sd(getParam<MooseEnum>("sd")),
50  _xtal_class(getParam<MooseEnum>("crystal_structure")),
51  _output_type(getParam<MooseEnum>("output_type")),
52  _euler(getUserObject<EulerAngleProvider>("euler_angle_provider")),
53  _ebsd_reader(isParamValid("phase") ? dynamic_cast<const EBSDReader *>(&_euler) : nullptr),
54  _grain_tracker(getUserObject<GrainTrackerInterface>("grain_tracker")),
55  _no_grain_color(getParam<Point>("no_grain_color"))
56 {
57 }
58 
59 unsigned int
61 {
62  if (_phase != libMesh::invalid_uint)
64  else
65  return _euler.getGrainNum();
66 }
67 
68 void
70 {
71  const auto grain_id =
72  _grain_tracker.getEntityValue(isNodal() ? _current_node->id() : _current_elem->id(),
74  0);
75 
76  // Recover Euler angles for current grain and assign correct RGB value either
77  // from Euler2RGB or from _no_grain_color
78  Point RGB;
79  if (grain_id < 0)
80  RGB = _no_grain_color;
81  else
82  {
83  /* The grain index retrieved from FeatureFloodCount is the "global_id" unless
84  the "phase" option is used in the simulation. For the phase dependent case,
85  the returned grain index is the "local_id." This must be converted to a
86  "global_id" using the getGlobalID function of EBSDREader before the Euler
87  Angles are retrieved. */
88 
89  auto global_id =
90  _phase != libMesh::invalid_uint ? _ebsd_reader->getGlobalID(_phase, grain_id) : grain_id;
91  const auto num_grns = getNumGrains();
92  if (global_id > num_grns)
93  mooseError(" global_id ", global_id, " out of index range");
94 
95  // Retrieve Euler Angle values from the EulerAngleProvider
96  const RealVectorValue & angles = _euler.getEulerAngles(global_id);
97 
98  // Convert Euler Angle values to RGB colorspace for visualization purposes
99  RGB = euler2RGB(_sd,
100  angles(0) / 180.0 * libMesh::pi,
101  angles(1) / 180.0 * libMesh::pi,
102  angles(2) / 180.0 * libMesh::pi,
103  1.0,
104  _xtal_class);
105  }
106 
107  // Create correct scalar output
108  if (_output_type < 3)
109  _value = RGB(_output_type);
110  else if (_output_type == 3)
111  {
112  Real RGBint = 0.0;
113  for (unsigned int i = 0; i < 3; ++i)
114  RGBint = 256 * RGBint + (RGB(i) >= 1 ? 255 : std::floor(RGB(i) * 256.0));
115  _value = RGBint;
116  }
117  else
118  mooseError("Incorrect value for output_type in EulerAngleProvider2RGBAux");
119 }
120 
121 Real
123 {
124  return _value;
125 }
GrainTrackerInterface
This class defines the interface for the GrainTracking objects.
Definition: GrainTrackerInterface.h:24
EulerAngleProvider2RGBAux::_grain_tracker
const GrainTrackerInterface & _grain_tracker
Grain tracker object.
Definition: EulerAngleProvider2RGBAux.h:56
FeatureFloodCount::FieldType::UNIQUE_REGION
EulerAngleProvider2RGBAux::getNumGrains
virtual unsigned int getNumGrains() const
Definition: EulerAngleProvider2RGBAux.C:60
validParams< EulerAngleProvider2RGBAux >
InputParameters validParams< EulerAngleProvider2RGBAux >()
Definition: EulerAngleProvider2RGBAux.C:20
EulerAngleProvider.h
EulerAngleProvider2RGBAux::_ebsd_reader
const EBSDReader * _ebsd_reader
EBSDReader Object.
Definition: EulerAngleProvider2RGBAux.h:53
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
libMesh
Definition: RANFSNormalMechanicalContact.h:24
EulerAngleProvider2RGBAux::_no_grain_color
const Point _no_grain_color
Vector containing values for color in regions without grains.
Definition: EulerAngleProvider2RGBAux.h:62
EulerAngleProvider2RGBAux::_output_type
const unsigned int _output_type
Type of value to be outputted.
Definition: EulerAngleProvider2RGBAux.h:47
EBSDReader.h
EulerAngleProvider2RGBAux::_phase
const unsigned int _phase
Optional phase number needed for global grain index retrieval.
Definition: EulerAngleProvider2RGBAux.h:38
registerMooseObject
registerMooseObject("PhaseFieldApp", EulerAngleProvider2RGBAux)
EBSDReader::getGrainNum
virtual unsigned int getGrainNum() const
Return the total number of grains.
Definition: EBSDReader.C:369
EulerAngleProvider
Abstract base class for user objects that implement the Euler Angle provider interface.
Definition: EulerAngleProvider.h:24
EBSDReader
A GeneralUserObject that reads an EBSD file and stores the centroid data in a data structure which in...
Definition: EBSDReader.h:36
EulerAngleProvider2RGBAux::_value
Real _value
precalculated element value
Definition: EulerAngleProvider2RGBAux.h:59
EulerAngleProvider::getGrainNum
virtual unsigned int getGrainNum() const =0
EulerAngleProvider2RGBAux::computeValue
virtual Real computeValue()
Definition: EulerAngleProvider2RGBAux.C:122
Euler2RGB.h
EulerAngleProvider2RGBAux::_xtal_class
const unsigned int _xtal_class
Crystal structure of the sample.
Definition: EulerAngleProvider2RGBAux.h:44
EulerAngleProvider2RGBAux.h
euler2RGB
Point euler2RGB(unsigned int sd, Real phi1, Real PHI, Real phi2, unsigned int phase, unsigned int sym)
This function rotates a set of three Bunge Euler angles into the standard Stereographic triangle,...
Definition: Euler2RGB.C:46
GrainTrackerInterface::getEntityValue
virtual Real getEntityValue(dof_id_type entity_id, FeatureFloodCount::FieldType, std::size_t var_index=0) const =0
Accessor for retrieving either nodal or elemental information (unique grains or variable indicies)
EulerAngleProvider2RGBAux
Output euler angles from user object to an AuxVariable.
Definition: EulerAngleProvider2RGBAux.h:27
EulerAngleProvider2RGBAux::EulerAngleProvider2RGBAux
EulerAngleProvider2RGBAux(const InputParameters &parameters)
Definition: EulerAngleProvider2RGBAux.C:46
GrainTracker.h
EulerAngleProvider2RGBAux::_euler
const EulerAngleProvider & _euler
Object providing the Euler angles.
Definition: EulerAngleProvider2RGBAux.h:50
EulerAngleProvider2RGBAux::_sd
const unsigned int _sd
Reference direction of the sample.
Definition: EulerAngleProvider2RGBAux.h:41
EulerAngleProvider::getEulerAngles
virtual const EulerAngles & getEulerAngles(unsigned int) const =0
EulerAngleProvider2RGBAux::precalculateValue
virtual void precalculateValue()
Definition: EulerAngleProvider2RGBAux.C:69