https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PolycrystalVariablesAction.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 "AddVariableAction.h"
12#include "Conversion.h"
13#include "Factory.h"
14#include "FEProblem.h"
15#include "NonlinearSystemBase.h"
16
17#include "libmesh/string_to_enum.h"
18
19registerMooseAction("PhaseFieldApp", PolycrystalVariablesAction, "add_variable");
20registerMooseAction("PhaseFieldApp", PolycrystalVariablesAction, "copy_nodal_vars");
21registerMooseAction("PhaseFieldApp", PolycrystalVariablesAction, "check_copy_nodal_vars");
22
25{
27 params.addClassDescription("Set up order parameter variables for a polycrystal simulation");
28 // Get MooseEnums for the possible order/family options for this variable
31 params.addParam<MooseEnum>("family",
32 families,
33 "Specifies the family of FE "
34 "shape function to use for the order parameters");
35 params.addParam<MooseEnum>("order",
36 orders,
37 "Specifies the order of the FE "
38 "shape function to use for the order parameters");
39 params.addParam<bool>(
40 "initial_from_file",
41 false,
42 "Take the initial condition of all polycrystal variables from the mesh file");
43 params.addParam<Real>("scaling", 1.0, "Specifies a scaling factor to apply to this variable");
44 params.addRequiredParam<unsigned int>("op_num",
45 "specifies the number of order parameters to create");
46 params.addRequiredParam<std::string>("var_name_base", "specifies the base name of the variables");
47 params.addParam<std::vector<SubdomainName>>(
48 "block", {}, "Block restriction for the variables and kernels");
49 return params;
50}
51
53 : Action(params),
54 _op_num(getParam<unsigned int>("op_num")),
55 _var_name_base(getParam<std::string>("var_name_base"))
56{
57}
58
59void
61{
62 // take initial values from file?
63 bool initial_from_file = getParam<bool>("initial_from_file");
64
65 // Loop through the number of order parameters
66 for (unsigned int op = 0; op < _op_num; op++)
67 {
68 // Create variable names
69 std::string var_name = _var_name_base + Moose::stringify(op);
70
71 // Add the variable
72 if (_current_task == "add_variable")
73 {
74 auto fe_type = AddVariableAction::feType(_pars);
76 auto var_params = _factory.getValidParams(type);
77
78 var_params.applySpecificParameters(_pars, {"order", "family", "block"});
79 var_params.set<std::vector<Real>>("scaling") = {_pars.get<Real>("scaling")};
80 _problem->addVariable(type, var_name, var_params);
81 }
82
83 // Setup initial from file if requested
84 if (initial_from_file)
85 {
86 if (_current_task == "check_copy_nodal_vars")
88
89 if (_current_task == "copy_nodal_vars")
90 {
91 auto * system = &_problem->getNonlinearSystemBase(/*nl_sys_num=*/0);
92 system->addVariableToCopy(var_name, var_name, "LATEST");
93 }
94 }
95 }
96}
registerMooseAction("PhaseFieldApp", PolycrystalVariablesAction, "add_variable")
void ErrorVector unsigned int
static InputParameters validParams()
MooseApp & _app
std::shared_ptr< FEProblemBase > & _problem
const std::string & _current_task
static MooseEnum getNonlinearVariableFamilies()
static libMesh::FEType feType(const InputParameters &params)
static MooseEnum getNonlinearVariableOrders()
static std::string variableType(const libMesh::FEType &fe_type, const bool is_fv=false, const bool is_array=false)
InputParameters getValidParams(const std::string &name) const
void applySpecificParameters(const InputParameters &common, const std::vector< std::string > &include, bool allow_private=false)
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)
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
void addClassDescription(const std::string &doc_string)
void setExodusFileRestart(bool flag)
const std::string & type() const
const InputParameters & _pars
Factory & _factory
Automatically generates all variables to model a polycrystal with op_num orderparameters.
static InputParameters validParams()
PolycrystalVariablesAction(const InputParameters &params)
std::string stringify(const T &t)