https://mooseframework.inl.gov
GrandPotentialKernelAction.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 "Parser.h"
13 #include "Conversion.h"
14 #include "FEProblem.h"
15 
16 registerMooseAction("PhaseFieldApp", GrandPotentialKernelAction, "add_kernel");
17 
20 {
23  "Automatically generate most or all of the kernels for the grand potential model");
24  parameters.addRequiredParam<std::vector<NonlinearVariableName>>(
25  "chemical_potentials", "List of chemical potential variables");
26  parameters.addRequiredParam<std::vector<MaterialPropertyName>>(
27  "susceptibilities", "List of susceptibilities that correspond to chemical_potentials");
28  parameters.addRequiredParam<std::vector<MaterialPropertyName>>(
29  "free_energies_gr",
30  "List of free energies for each phase. Place in same order as switching_function_names.");
31  parameters.addRequiredParam<std::vector<MaterialPropertyName>>(
32  "free_energies_w",
33  "List of functions for each phase. Length should be length of chemical_potentials * length "
34  "of switching_function_names.");
35  parameters.addRequiredParam<std::vector<MaterialPropertyName>>(
36  "switching_function_names",
37  "Switching function materials that provide switching function for free_energies_*.");
38  parameters.addRequiredParam<std::vector<MaterialPropertyName>>(
39  "mobilities", "Vector of mobilities that must match chemical_potentials");
40  parameters.addRequiredParam<unsigned int>("op_num", "specifies the number of grains to create");
41  parameters.addRequiredParam<std::string>("var_name_base",
42  "specifies the base name of the grain variables");
43  parameters.addParam<std::vector<NonlinearVariableName>>(
44  "additional_ops", "List of any additional order parameters which are not grains");
45  parameters.addParam<std::vector<MaterialPropertyName>>("free_energies_op",
46  "List of free energies used by additional "
47  "order parameters. Places in same order "
48  "as switching_function_names.");
49  parameters.addParam<MaterialPropertyName>("kappa_gr", "kappa", "The kappa used with the grains");
50  parameters.addParam<MaterialPropertyName>(
51  "kappa_op", "kappa", "The kappa used with additional_ops");
52  parameters.addParam<MaterialPropertyName>(
53  "gamma_gr", "gamma", "Name of the gamma used with grains");
54  parameters.addParam<MaterialPropertyName>(
55  "gamma_op", "gamma", "Name of the gamma used with additional order parameters");
56  parameters.addParam<MaterialPropertyName>(
57  "gamma_grxop",
58  "gamma",
59  "Name of the gamma used when grains interact with other order parameters");
60  parameters.addParam<MaterialPropertyName>(
61  "mobility_name_gr", "L", "Name of mobility to be used with grains");
62  parameters.addParam<MaterialPropertyName>(
63  "mobility_name_op", "L", "Name of mobility to be used with additional_ops");
64  parameters.addParam<bool>("implicit", true, "Whether kernels are implicit or not");
65  parameters.addParam<bool>(
66  "use_displaced_mesh", false, "Whether to use displaced mesh in the kernels");
67  MultiMooseEnum anisotropy("true=1 false=0", "false");
68  parameters.addParam<bool>(
69  "mass_conservation", false, "Whether strict mass conservation formulation is used or not");
71  "anisotropic", anisotropy, "Whether or not each mobility is anisotropic");
72  parameters.addParam<std::vector<NonlinearVariableName>>(
73  "concentrations", "List of concentration variables for strict mass conservation");
74  parameters.addParam<std::vector<MaterialPropertyName>>(
75  "hj_c_min",
76  {},
77  "List of body forces coefficients for strict mass conservation formulation that indicates "
78  "the minima in concentration free energy."
79  "Place in same order as switching_function_names.");
80  parameters.addParam<std::vector<MaterialPropertyName>>(
81  "hj_over_kVa",
82  {},
83  "List of MatReaction coefficients for strict mass conservation formulation that relates "
84  "chemical potential with switching functionj between phases"
85  "Place in same order as switching_function_names.");
86  return parameters;
87 }
88 
90  : Action(parameters)
91 {
92 }
93 
94 void
96 {
97  // Get Variables from parameters
98  const auto w_names = getParam<std::vector<NonlinearVariableName>>("chemical_potentials");
99  const auto chis = getParam<std::vector<MaterialPropertyName>>("susceptibilities");
100  const auto Fj_gr = getParam<std::vector<MaterialPropertyName>>("free_energies_gr");
101  const auto Fj_w = getParam<std::vector<MaterialPropertyName>>("free_energies_w");
102  const auto hj = getParam<std::vector<MaterialPropertyName>>("switching_function_names");
103  const auto M = getParam<std::vector<MaterialPropertyName>>("mobilities");
104  auto n_grs = getParam<unsigned int>("op_num");
105  const auto var_name_base = getParam<std::string>("var_name_base");
106  const auto Fj_op = getParam<std::vector<MaterialPropertyName>>("free_energies_op");
107  const auto kappa_gr = getParam<MaterialPropertyName>("kappa_gr");
108  const auto kappa_op = getParam<MaterialPropertyName>("kappa_op");
109  const auto gamma_gr = getParam<MaterialPropertyName>("gamma_gr");
110  const auto gamma_op = getParam<MaterialPropertyName>("gamma_op");
111  const auto gamma_xx = getParam<MaterialPropertyName>("gamma_grxop");
112  const auto gr_mob = getParam<MaterialPropertyName>("mobility_name_gr");
113  const auto op_mob = getParam<MaterialPropertyName>("mobility_name_op");
114  auto implicity = getParam<bool>("implicit");
115  auto displaced_mesh = getParam<bool>("use_displaced_mesh");
116  auto aniso = getParam<MultiMooseEnum>("anisotropic");
117  const auto hj_over_kVa = getParam<std::vector<MaterialPropertyName>>("hj_over_kVa");
118  const auto hj_c_min = getParam<std::vector<MaterialPropertyName>>("hj_c_min");
119  auto mass_conservation = getParam<bool>("mass_conservation");
120 
121  // Size definitions and checks
122  unsigned int n_w = w_names.size();
123  unsigned int n_hj = hj.size();
124  std::vector<NonlinearVariableName> etas;
125  std::vector<NonlinearVariableName> c_names;
126  unsigned int n_etas = 0;
127  std::string kernel_name;
128  if (isParamValid("additional_ops"))
129  {
130  etas = getParam<std::vector<NonlinearVariableName>>("additional_ops");
131  n_etas = etas.size();
132  }
133 
134  if (chis.size() != n_w)
135  mooseError("susceptibilities and chemical_potentials should be vectors of the same length.");
136  if (Fj_w.size() != n_w * n_hj)
137  mooseError("free_energies_w should be length of chemcial_potentials * length of "
138  "switching_function_names");
139  if (M.size() != n_w)
140  mooseError("M and chemical_potentials should be vectors of the same length.");
141  if (aniso.size() != n_w)
142  paramError("anisotropic", "Provide as many values as entries in 'chemical_potentials'.");
143 
144  // Define additional vectors
145  std::vector<std::string> grs; // vector of all grain variable names
146  grs.resize(n_grs);
147  for (unsigned int i = 0; i < n_grs; ++i)
148  grs[i] = var_name_base + Moose::stringify(i);
149 
150  std::vector<NonlinearVariableName> all_etas; // vector of all grain variables and order parameters
151  all_etas.reserve(n_etas + n_grs);
152  all_etas.insert(all_etas.end(), etas.begin(), etas.end());
153  all_etas.insert(all_etas.end(), grs.begin(), grs.end());
154 
155  std::vector<std::string> all_vars; // vector of all variables
156  all_vars.reserve(n_etas + n_grs + n_w);
157  all_vars.insert(all_vars.end(), all_etas.begin(), all_etas.end());
158  all_vars.insert(all_vars.end(), w_names.begin(), w_names.end());
159 
160  std::vector<MaterialPropertyName> fj_temp;
161  fj_temp.resize(n_hj);
162  std::vector<VariableName> notarealvector;
163  notarealvector.resize(1);
164  std::vector<VariableName> v0;
165  v0.resize(n_etas + n_grs + n_w);
166  for (unsigned int i = 0; i < n_etas + n_grs + n_w; ++i)
167  v0[i] = all_vars[i];
168  std::vector<VariableName> v1;
169  v1.resize(n_etas + n_grs);
170  for (unsigned int i = 0; i < n_etas + n_grs; ++i)
171  v1[i] = all_etas[i];
172  std::vector<VariableName> v2;
173  v2.resize(n_etas + n_grs - 1);
174 
175  // Grains and order parameters
176  NonlinearVariableName var_name;
177  MaterialPropertyName kappa;
178  MaterialPropertyName mob_name;
179  std::vector<MaterialPropertyName> Fj_names;
180 
181  for (unsigned int i = 0; i < n_etas + n_grs; ++i)
182  {
183  var_name = all_etas[i];
184  // Distinguish between grains and the additional order parameters
185  if (i < n_etas) // First part of list is grain variables
186  {
187  kappa = kappa_op;
188  mob_name = op_mob;
189  Fj_names.resize(Fj_op.size());
190  Fj_names = Fj_op;
191  }
192  else // Second part of list is additional order parameters
193  {
194  kappa = kappa_gr;
195  mob_name = gr_mob;
196  Fj_names.resize(Fj_gr.size());
197  Fj_names = Fj_gr;
198  }
199 
200  // Remove var_name from coupled variables
201  std::vector<MaterialPropertyName> gam;
202  gam.resize(n_etas + n_grs - 1);
203  unsigned int op = 0;
204  for (unsigned int j = 0; j < n_etas + n_grs; ++j)
205  {
206  if (i != j)
207  {
208  v2[op] = all_etas[j];
209  if (j < n_etas)
210  gam[op] = gamma_op;
211  else
212  gam[op] = gamma_gr;
213  if (i < n_etas && j < n_etas)
214  gam[op] = gamma_op;
215  else if (i >= n_etas && j >= n_etas)
216  gam[op] = gamma_gr;
217  else
218  gam[op] = gamma_xx;
219  ++op;
220  }
221  }
222 
223  // TimeDerivative Kernel
224  InputParameters params = _factory.getValidParams("TimeDerivative");
225  params.set<NonlinearVariableName>("variable") = var_name;
226  params.set<bool>("implicit") = implicity;
227  params.set<bool>("use_displaced_mesh") = displaced_mesh;
228  kernel_name = "DT_" + var_name;
229  _problem->addKernel("TimeDerivative", kernel_name, params);
230 
231  // ACInterface Kernel
232  params = _factory.getValidParams("ACInterface");
233  params.set<NonlinearVariableName>("variable") = var_name;
234  params.set<bool>("implicit") = implicity;
235  params.set<bool>("use_displaced_mesh") = displaced_mesh;
236  params.set<MaterialPropertyName>("kappa_name") = kappa;
237  params.set<MaterialPropertyName>("mob_name") = mob_name;
238  params.set<std::vector<VariableName>>("coupled_variables") = v2;
239  kernel_name = "ACInt_" + var_name;
240  _problem->addKernel("ACInterface", kernel_name, params);
241 
242  // ACSwitching Kernel
243  params = _factory.getValidParams("ACSwitching");
244  params.set<NonlinearVariableName>("variable") = var_name;
245  params.set<bool>("implicit") = implicity;
246  params.set<bool>("use_displaced_mesh") = displaced_mesh;
247  params.set<std::vector<MaterialPropertyName>>("Fj_names") = Fj_names;
248  params.set<std::vector<MaterialPropertyName>>("hj_names") = hj;
249  params.set<MaterialPropertyName>("mob_name") = mob_name;
250  params.set<std::vector<VariableName>>("coupled_variables") = v0;
251  kernel_name = "ACSwitch_" + var_name;
252  _problem->addKernel("ACSwitching", kernel_name, params);
253 
254  // ACGrGrMulti Kernel
255  params = _factory.getValidParams("ACGrGrMulti");
256  params.set<NonlinearVariableName>("variable") = var_name;
257  params.set<bool>("implicit") = implicity;
258  params.set<bool>("use_displaced_mesh") = displaced_mesh;
259  params.set<MaterialPropertyName>("mob_name") = mob_name;
260  params.set<std::vector<VariableName>>("v") = v2;
261  params.set<std::vector<MaterialPropertyName>>("gamma_names") = gam;
262  kernel_name = "AcGrGr_" + var_name;
263  _problem->addKernel("ACGrGrMulti", kernel_name, params);
264  } // for (unsigned int i = 0; i < n_etas + n_grs; ++i)
265 
266  if (mass_conservation) // mass conservation kernels with conc and chempot coupling
267  {
268  c_names = getParam<std::vector<NonlinearVariableName>>("concentrations");
269  std::vector<VariableName> v3;
270  v3.resize(n_w);
271  for (unsigned int i = 0; i < n_w; ++i)
272  v3[i] = w_names[i];
273 
274  std::vector<VariableName> v4;
275  unsigned int n_c = c_names.size();
276  v4.resize(n_c);
277  for (unsigned int i = 0; i < n_c; ++i)
278  v4[i] = c_names[i];
279 
280  for (unsigned int i = 0; i < n_c; ++i)
281  {
282  // TimeDerivative concentration Kernel
283  InputParameters params = _factory.getValidParams("TimeDerivative");
284  params.set<NonlinearVariableName>("variable") = c_names[i];
285  params.set<bool>("implicit") = implicity;
286  params.set<bool>("use_displaced_mesh") = displaced_mesh;
287  kernel_name = "DT_" + c_names[i];
288  _problem->addKernel("TimeDerivative", kernel_name, params);
289 
290  // MatDiffusion concentration (coupled with chempot)
291  params = _factory.getValidParams("MatDiffusion");
292  params.set<NonlinearVariableName>("variable") = c_names[i];
293  params.set<std::vector<VariableName>>("v") = v3;
294  params.set<bool>("implicit") = implicity;
295  params.set<bool>("use_displaced_mesh") = displaced_mesh;
296  params.set<MaterialPropertyName>("diffusivity") = M[i];
297  kernel_name = "MatDif_" + w_names[i];
298  if (aniso.get(i))
299  {
300  params.set<std::vector<VariableName>>("args") = v1;
301  _problem->addKernel("MatAnisoDiffusion", kernel_name, params);
302  }
303  else
304  {
305  params.set<std::vector<VariableName>>("args") = v0;
306  _problem->addKernel("MatDiffusion", kernel_name, params);
307  }
308  }
309 
310  // Chemical Potentials
311  for (unsigned int i = 0; i < n_w; ++i)
312  {
313  // coupling of c and w
314  InputParameters params = _factory.getValidParams("MatReaction");
315  params.set<NonlinearVariableName>("variable") = w_names[i];
316  params.set<std::vector<VariableName>>("v") = v4;
317  params.set<MaterialPropertyName>("mob_name") = "-1";
318  kernel_name = "MR_c" + w_names[i];
319  _problem->addKernel("MatReaction", kernel_name, params);
320 
321  // contribution between chempot and each grains to concentration
322  // Summations of MatReaction and MaskedBodyForce
323 
324  for (unsigned int j = 0; j < n_hj; ++j)
325  {
326  // MatReaction
327  params = _factory.getValidParams("MatReaction");
328  params.set<NonlinearVariableName>("variable") = w_names[i];
329  params.set<std::vector<VariableName>>("args") = v1;
330  params.set<MaterialPropertyName>("mob_name") = hj_over_kVa[j];
331  params.set<bool>("implicit") = implicity;
332  params.set<bool>("use_displaced_mesh") = displaced_mesh;
333  kernel_name = "MR_" + w_names[i] + "_" + all_etas[j];
334  _problem->addKernel("MatReaction", kernel_name, params);
335 
336  // MaskedBodyForce
337  InputParameters params = _factory.getValidParams("MaskedBodyForce");
338  params.set<NonlinearVariableName>("variable") = w_names[i];
339  params.set<std::vector<VariableName>>("coupled_variables") = v1;
340  params.set<MaterialPropertyName>("mask") = hj_c_min[j];
341  params.set<bool>("implicit") = implicity;
342  params.set<bool>("use_displaced_mesh") = displaced_mesh;
343  kernel_name = "MBD_" + w_names[i] + "_" + all_etas[j];
344  _problem->addKernel("MaskedBodyForce", kernel_name, params);
345  }
346  }
347  }
348  else
349  {
350  // Chemical Potentials
351  for (unsigned int i = 0; i < n_w; ++i)
352  {
353  // SusceptibilityTimeDerivative
354  InputParameters params = _factory.getValidParams("SusceptibilityTimeDerivative");
355  params.set<NonlinearVariableName>("variable") = w_names[i];
356  params.set<MaterialPropertyName>("f_name") = chis[i];
357  params.set<std::vector<VariableName>>("coupled_variables") = v0;
358  params.set<bool>("implicit") = implicity;
359  params.set<bool>("use_displaced_mesh") = displaced_mesh;
360  kernel_name = "ChiDt_" + w_names[i];
361  _problem->addKernel("SusceptibilityTimeDerivative", kernel_name, params);
362 
363  // MatDiffusion
364  params = _factory.getValidParams("MatDiffusion");
365  params.set<NonlinearVariableName>("variable") = w_names[i];
366  params.set<bool>("implicit") = implicity;
367  params.set<bool>("use_displaced_mesh") = displaced_mesh;
368  params.set<MaterialPropertyName>("diffusivity") = M[i];
369  kernel_name = "MatDif_" + w_names[i];
370  if (aniso.get(i))
371  _problem->addKernel("MatAnisoDiffusion", kernel_name, params);
372  else
373  {
374  params.set<std::vector<VariableName>>("args") = v0;
375  _problem->addKernel("MatDiffusion", kernel_name, params);
376  }
377 
378  // CoupledSwitchingTimeDerivative
379  for (unsigned int j = 0; j < n_hj; ++j)
380  fj_temp[j] = Fj_w[i * n_hj + j];
381  for (unsigned int j = 0; j < n_etas + n_grs; ++j)
382  {
383  notarealvector[0] = all_etas[j];
384  params = _factory.getValidParams("CoupledSwitchingTimeDerivative");
385  params.set<NonlinearVariableName>("variable") = w_names[i];
386  params.set<std::vector<VariableName>>("v") = notarealvector;
387  params.set<std::vector<VariableName>>("coupled_variables") = v0;
388  params.set<std::vector<MaterialPropertyName>>("Fj_names") = fj_temp;
389  params.set<std::vector<MaterialPropertyName>>("hj_names") = hj;
390  params.set<bool>("implicit") = implicity;
391  params.set<bool>("use_displaced_mesh") = displaced_mesh;
392  kernel_name = "Coupled_" + w_names[i] + "_" + all_etas[j];
393  _problem->addKernel("CoupledSwitchingTimeDerivative", kernel_name, params);
394  }
395  }
396  }
397 } // GrandPotentialKernelAction::act()
GrandPotentialKernelAction(const InputParameters &parameters)
registerMooseAction("PhaseFieldApp", GrandPotentialKernelAction, "add_kernel")
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)
Generates the necessary kernels for the Grand Potential Function for any number of order parameters a...
InputParameters getValidParams(const std::string &name) const
void addRequiredParam(const std::string &name, const std::string &doc_string)
bool isParamValid(const std::string &name) const
Factory & _factory
static InputParameters validParams()
static InputParameters validParams()
void paramError(const std::string &param, Args... args) const
std::string stringify(const T &t)
static const std::string kappa
Definition: NS.h:116
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
std::shared_ptr< FEProblemBase > & _problem
const InputParameters & parameters() const
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")