https://mooseframework.inl.gov
EulerAngle2RGBAction.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 "EulerAngle2RGBAction.h"
11 #include "Factory.h"
12 #include "FEProblem.h"
13 
14 #include "libmesh/string_to_enum.h"
15 
16 registerMooseAction("PhaseFieldApp", EulerAngle2RGBAction, "add_aux_kernel");
17 
18 registerMooseAction("PhaseFieldApp", EulerAngle2RGBAction, "add_aux_variable");
19 
22 {
24  params.addParam<std::string>("auxvariable_name_base", "RGB", "Base name of the auxvariables");
25  params.addClassDescription("Set up auxvariables and auxkernels to output Euler angles as RGB "
26  "values interpolated across inverse pole figure");
27  params.addParam<unsigned int>("phase", "The phase to use for all queries.");
28  MooseEnum sd_enum = MooseEnum("100=1 010=2 001=3", "001");
29  params.addParam<MooseEnum>("sd", sd_enum, "Reference sample direction");
30  MooseEnum structure_enum = MooseEnum(
31  "cubic=43 hexagonal=62 tetragonal=42 trigonal=32 orthorhombic=22 monoclinic=2 triclinic=1");
33  "crystal_structure", structure_enum, "Crystal structure of the material");
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  params.addParam<std::vector<SubdomainName>>(
43  "block", {}, "Block restriction for the variables and kernels");
44  return params;
45 }
46 
48  : Action(params), _var_name_base(getParam<std::string>("auxvariable_name_base"))
49 {
50 }
51 
52 void
54 {
55  // Auxvariable suffix names that will automatically become a vector in Paraview
56  std::vector<std::string> suffixes = {"_x", "_y", "_z"};
57 
58  // Three color types that will be outputted
59  std::vector<std::string> colors = {"red", "green", "blue"};
60 
61  for (unsigned int i = 0; i < 3; ++i)
62  {
63  // Create the auxvariable name
64  std::string var_name = _var_name_base + suffixes[i];
65 
66  if (_current_task == "add_aux_variable")
67  {
68  auto var_params = _factory.getValidParams("MooseVariableConstMonomial");
69  var_params.applySpecificParameters(_pars, {"block"});
70  // Create scalar auxvariables for the three components of the RGB vector
71  _problem->addAuxVariable("MooseVariableConstMonomial", var_name, var_params);
72  }
73  else if (_current_task == "add_aux_kernel")
74  {
75  // Create auxkernels corresponding to each auxvariable
76  InputParameters params = _factory.getValidParams("EulerAngleProvider2RGBAux");
77  params.set<AuxVariableName>("variable") = var_name;
78  params.set<MooseEnum>("sd") = getParam<MooseEnum>("sd");
79  params.set<MooseEnum>("crystal_structure") = getParam<MooseEnum>("crystal_structure");
80  params.set<MooseEnum>("output_type") = colors[i];
81  params.set<UserObjectName>("euler_angle_provider") =
82  getParam<UserObjectName>("euler_angle_provider");
83  params.set<UserObjectName>("grain_tracker") = getParam<UserObjectName>("grain_tracker");
84  params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
85  params.set<Point>("no_grain_color") = getParam<Point>("no_grain_color");
86  if (isParamValid("phase"))
87  params.set<unsigned int>("phase") = getParam<unsigned int>("phase");
88  _problem->addAuxKernel("EulerAngleProvider2RGBAux", var_name, params);
89  }
90  else
91  mooseError("Internal error in EulerAngle2RGBAction.");
92  }
93 }
const std::string _var_name_base
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void applySpecificParameters(const InputParameters &common, const std::vector< std::string > &include, bool allow_private=false)
T & set(const std::string &name, bool quiet_mode=false)
InputParameters getValidParams(const std::string &name) const
const ExecFlagType EXEC_TIMESTEP_END
void addRequiredParam(const std::string &name, const std::string &doc_string)
EulerAngle2RGBAction(const InputParameters &params)
bool isParamValid(const std::string &name) const
Factory & _factory
static InputParameters validParams()
const std::string & _current_task
void mooseError(Args &&... args) const
const InputParameters & _pars
Automatically generates all variables, Kernels, and Materials to ensure the correct derivatives of th...
void addClassDescription(const std::string &doc_string)
std::shared_ptr< FEProblemBase > & _problem
registerMooseAction("PhaseFieldApp", EulerAngle2RGBAction, "add_aux_kernel")
const ExecFlagType EXEC_INITIAL