www.mooseframework.org
EulerAngleProvider2RGBAux.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 /****************************************************************/
8 #include "GrainTracker.h"
9 #include "EulerAngleProvider.h"
10 #include "Euler2RGB.h"
11 
12 template <>
13 InputParameters
15 {
16  InputParameters params = validParams<AuxKernel>();
17  params.addClassDescription("Output RGB representation of crystal orientation from user object to "
18  "an AuxVariable. The entire domain must have the same crystal "
19  "structure.");
20  MooseEnum sd_enum = MooseEnum("100=1 010=2 001=3", "001");
21  params.addParam<MooseEnum>("sd", sd_enum, "Reference sample direction");
22  MooseEnum structure_enum = MooseEnum(
23  "cubic=43 hexagonal=62 tetragonal=42 trigonal=32 orthorhombic=22 monoclinic=2 triclinic=1");
24  params.addRequiredParam<MooseEnum>(
25  "crystal_structure", structure_enum, "Crystal structure of the material");
26  MooseEnum output_types = MooseEnum("red green blue scalar", "scalar");
27  params.addParam<MooseEnum>("output_type", output_types, "Type of value that will be outputted");
28  params.addRequiredParam<UserObjectName>("euler_angle_provider",
29  "Name of Euler angle provider user object");
30  params.addRequiredParam<UserObjectName>("grain_tracker",
31  "The GrainTracker UserObject to get values from.");
32  params.addParam<Point>(
33  "no_grain_color",
34  Point(0, 0, 0),
35  "RGB value of color used to represent area with no grains, defaults to black");
36  return params;
37 }
38 
39 EulerAngleProvider2RGBAux::EulerAngleProvider2RGBAux(const InputParameters & parameters)
40  : AuxKernel(parameters),
41  _sd(getParam<MooseEnum>("sd")),
42  _xtal_class(getParam<MooseEnum>("crystal_structure")),
43  _output_type(getParam<MooseEnum>("output_type")),
44  _euler(getUserObject<EulerAngleProvider>("euler_angle_provider")),
45  _grain_tracker(getUserObject<GrainTracker>("grain_tracker")),
46  _no_grain_color(getParam<Point>("no_grain_color"))
47 {
48 }
49 
50 void
52 {
53  // ID of unique grain at current point
54  const Real grain_id =
55  _grain_tracker.getEntityValue((isNodal() ? _current_node->id() : _current_elem->id()),
57  0);
58 
59  // Recover Euler angles for current grain and assign correct
60  // RGB value either from euler2RGB or from _no_grain_color
61  Point RGB;
62  if (grain_id >= 0 && grain_id < _euler.getGrainNum())
63  {
64  const RealVectorValue & angles = _euler.getEulerAngles(grain_id);
65  RGB = euler2RGB(_sd,
66  angles(0) / 180.0 * libMesh::pi,
67  angles(1) / 180.0 * libMesh::pi,
68  angles(2) / 180.0 * libMesh::pi,
69  1.0,
70  _xtal_class);
71  }
72  else
73  RGB = _no_grain_color;
74 
75  // Create correct scalar output
76  if (_output_type < 3)
77  _value = RGB(_output_type);
78  else if (_output_type == 3)
79  {
80  Real RGBint = 0.0;
81  for (unsigned int i = 0; i < 3; ++i)
82  RGBint = 256 * RGBint + (RGB(i) >= 1 ? 255 : std::floor(RGB(i) * 256.0));
83 
84  _value = RGBint;
85  }
86  else
87  mooseError("Incorrect value for output_type in EulerAngleProvider2RGBAux");
88 }
89 
90 Real
92 {
93  return _value;
94 }
const unsigned int _sd
Reference direction of the sample.
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:43
virtual unsigned int getGrainNum() const =0
InputParameters validParams< EulerAngleProvider2RGBAux >()
const unsigned int _xtal_class
Crystal structure of the sample.
const unsigned int _output_type
Type of value to be outputted.
const Point _no_grain_color
Vector containing values for color in regions without grains.
EulerAngleProvider2RGBAux(const InputParameters &parameters)
const EulerAngleProvider & _euler
Object providing the Euler angles.
Real _value
precalculated element value
virtual Real getEntityValue(dof_id_type node_id, FieldType field_type, std::size_t var_index=0) const override
Definition: GrainTracker.C:84
const GrainTracker & _grain_tracker
Grain tracker object.
Abstract base class for user objects that implement the Euler Angle provider interface.
virtual const EulerAngles & getEulerAngles(unsigned int) const =0