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