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