https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CHPFCRFFSplitVariablesAction.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 "Factory.h"
12#include "FEProblem.h"
13#include "Conversion.h"
14#include "AddVariableAction.h"
15
16#include "libmesh/string_to_enum.h"
17
18registerMooseAction("PhaseFieldApp", CHPFCRFFSplitVariablesAction, "add_variable");
19
22{
25 params.addClassDescription("Creates the L auxiliary variables, as well as a MultiApp along with "
26 "transfers to set the variables, for the Cahn-Hilliard equation for "
27 "the RFF form of the phase field crystal model");
28 params.addParam<MooseEnum>(
29 "family",
30 familyEnum,
31 "Specifies the family of FE shape functions to use for the L variables");
33 params.addParam<MooseEnum>(
34 "order",
35 orderEnum,
36 "Specifies the order of the FE shape function to use for the L variables");
37 params.addParam<Real>("scaling", 1.0, "Specifies a scaling factor to apply to the L variables");
38 params.addRequiredParam<unsigned int>(
39 "num_L", "specifies the number of complex L variables will be solved for");
40 params.addRequiredParam<std::string>("L_name_base", "Base name for the complex L variables");
41 params.addRequiredParam<std::vector<FileName>>("sub_filenames",
42 "This is the filename of the sub.i file");
43 params.addRequiredParam<AuxVariableName>("n_name", "Name of atomic density variable");
44
45 return params;
46}
47
49 : Action(params),
50 _num_L(getParam<unsigned int>("num_L")),
51 _L_name_base(getParam<std::string>("L_name_base")),
52 _sub_filenames(getParam<std::vector<FileName>>("sub_filenames")),
53 _n_name(getParam<AuxVariableName>("n_name"))
54{
55}
56
57void
59{
61 execute_options = EXEC_TIMESTEP_BEGIN;
62
63 // Setup MultiApp
64 InputParameters poly_params = _factory.getValidParams("TransientMultiApp");
65 poly_params.set<MooseEnum>("app_type") = "PhaseFieldApp";
66 poly_params.set<ExecFlagEnum>("execute_on") = execute_options;
67 poly_params.set<std::vector<FileName>>("input_files") = _sub_filenames;
68 poly_params.set<unsigned int>("max_procs_per_app") = 1;
69 poly_params.set<std::vector<Point>>("positions") = {Point()};
70 _problem->addMultiApp("TransientMultiApp", "HHEquationSolver", poly_params);
71
72 poly_params = _factory.getValidParams("MultiAppNearestNodeTransfer");
73 poly_params.set<ExecFlagEnum>("execute_on") = execute_options;
74 poly_params.set<std::vector<AuxVariableName>>("variable") = {_n_name};
75 poly_params.set<std::vector<VariableName>>("source_variable") = {_n_name};
76 poly_params.set<MultiAppName>("to_multi_app") = "HHEquationSolver";
77 _problem->addTransfer("MultiAppNearestNodeTransfer", _n_name + "_trans", poly_params);
78
79 // Loop through the number of L variables
80 for (unsigned int l = 0; l < _num_L; ++l)
81 {
82 // Create L base name
83 std::string L_name = _L_name_base + Moose::stringify(l);
84
85 // Create real L variable
86 std::string real_name = L_name + "_real";
87
88 // Get string name for specified L variable type
89 std::string var_type = AddVariableAction::variableType(
90 FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
91 Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family"))),
92 /* is_fv = */ false,
93 /* is_array = */ false);
94
95 // Get params for specified L variable type
96 InputParameters var_params = _factory.getValidParams(var_type);
97
98 _problem->addAuxVariable(var_type, real_name, var_params);
99
100 poly_params = _factory.getValidParams("MultiAppNearestNodeTransfer");
101 poly_params.set<std::vector<AuxVariableName>>("variable") = {real_name};
102 poly_params.set<std::vector<VariableName>>("source_variable") = {real_name};
103 poly_params.set<MultiAppName>("from_multi_app") = "HHEquationSolver";
104 _problem->addTransfer("MultiAppNearestNodeTransfer", real_name + "_trans", poly_params);
105
106 if (l > 0)
107 {
108 // Create imaginary L variable IF l > 0
109 std::string imag_name = L_name + "_imag";
110
111 _problem->addAuxVariable(var_type, imag_name, var_params);
112
113 poly_params = _factory.getValidParams("MultiAppNearestNodeTransfer");
114 poly_params.set<std::vector<AuxVariableName>>("variable") = {imag_name};
115 poly_params.set<std::vector<VariableName>>("source_variable") = {imag_name};
116 poly_params.set<MultiAppName>("from_multi_app") = "HHEquationSolver";
117 _problem->addTransfer("MultiAppNearestNodeTransfer", imag_name + "_trans", poly_params);
118 }
119 }
120}
registerMooseAction("PhaseFieldApp", CHPFCRFFSplitVariablesAction, "add_variable")
const ExecFlagType EXEC_TIMESTEP_BEGIN
void ErrorVector unsigned int
static InputParameters validParams()
std::shared_ptr< FEProblemBase > & _problem
static MooseEnum getNonlinearVariableFamilies()
static MooseEnum getNonlinearVariableOrders()
static std::string variableType(const libMesh::FEType &fe_type, const bool is_fv=false, const bool is_array=false)
Automatically generates all the L variables for the RFF phase field crystal model.
const std::vector< FileName > _sub_filenames
CHPFCRFFSplitVariablesAction(const InputParameters &params)
InputParameters getValidParams(const std::string &name) const
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)
T & set(const std::string &name, bool quiet_mode=false)
Factory & _factory
ExecFlagEnum getDefaultExecFlagEnum()
std::string stringify(const T &t)