www.mooseframework.org
DiscreteNucleation.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 #include "DiscreteNucleation.h"
10 
11 #include "libmesh/quadrature.h"
12 
13 template <>
14 InputParameters
16 {
17  InputParameters params = validParams<DerivativeFunctionMaterialBase>();
18  params.addClassDescription("Free energy contribution for nucleating discrete particles");
19  params.addRequiredCoupledVar("op_names",
20  "List of variables to force to a target concentration value");
21  params.addRequiredParam<UserObjectName>("map", "DiscreteNucleationMap user object");
22  params.addRequiredParam<std::vector<Real>>("op_values", "List of target concentration values");
23  params.addParam<Real>("penalty", 20.0, "Penalty factor for enforcing the target concentrations");
24  MooseEnum penalty_mode("MATCH MIN MAX", "MATCH");
25  params.addParam<MooseEnum>(
26  "penalty_mode",
27  penalty_mode,
28  "Match the target concentration or take it as a minimum or maximum concentration target");
29  return params;
30 }
31 
32 DiscreteNucleation::DiscreteNucleation(const InputParameters & params)
34  _nvar(coupledComponents("op_names")),
35  _op_index(_nvar),
36  _op_values(getParam<std::vector<Real>>("op_values")),
37  _penalty(getParam<Real>("penalty")),
38  _penalty_mode(getParam<MooseEnum>("penalty_mode")),
39  _map(getUserObject<DiscreteNucleationMap>("map"))
40 {
41  // check inputs
42  if (_nvar != _op_values.size())
43  mooseError("The op_names and op_values parameter vectors must have the same number of entries");
44  if (_nvar != _args.size())
45  mooseError("Internal error.");
46 
47  // get libMesh variable numbers
48  for (unsigned int i = 0; i < _nvar; ++i)
49  _op_index[i] = argIndex(coupled("op_names", i));
50 }
51 
52 void
54 {
55  // check if a nucleation event list is available for the current element
56  const std::vector<Real> & nucleus = _map.nuclei(_current_elem);
57 
58  // calculate penalty
59  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
60  {
61  // clear penalty value
62  if (_prop_F)
63  (*_prop_F)[_qp] = 0.0;
64 
65  for (unsigned int i = 0; i < _nvar; ++i)
66  {
67  const unsigned ii = _op_index[i];
68 
69  // modify the penalty magnitude with the nucleus mask
70  const Real penalty = _penalty * nucleus[_qp];
71 
72  // deviation from the target concentration
73  Real dc = (*_args[ii])[_qp] - _op_values[i];
74 
75  // ignore above/below target values for min/max modes respectively
76  if ((_penalty_mode == 1 && dc > 0.0) || (_penalty_mode == 2 && dc < 0.0))
77  dc = 0.0;
78 
79  // build free energy correction
80  if (_prop_F)
81  (*_prop_F)[_qp] += dc * dc * penalty;
82 
83  // first derivative
84  if (_prop_dF[ii])
85  (*_prop_dF[ii])[_qp] = 2.0 * dc * penalty;
86 
87  // second derivatives
88  for (unsigned int jj = ii; jj < _nvar; ++jj)
89  {
90  if (_prop_d2F[ii][jj])
91  (*_prop_d2F[ii][jj])[_qp] = 2.0 * penalty;
92 
93  // third derivatives
95  for (unsigned int kk = jj; kk < _nvar; ++kk)
96  if (_prop_d3F[ii][jj][kk])
97  (*_prop_d3F[ii][jj][kk])[_qp] = 0.0;
98  }
99  }
100  }
101 }
std::vector< std::vector< MaterialProperty< Real > * > > _prop_d2F
Material properties to store the second derivatives.
This UserObject maintains a per QP map that indicates if a nucleus is present or not.
virtual void computeProperties()
InputParameters validParams< DerivativeFunctionMaterialBase >()
std::vector< std::vector< std::vector< MaterialProperty< Real > * > > > _prop_d3F
Material properties to store the third derivatives.
MaterialProperty< Real > * _prop_F
Material property to store the function value.
Material base class central to compute the a phase free energy and its derivatives.
bool _third_derivatives
Calculate (and allocate memory for) the third derivatives of the free energy.
const unsigned int _penalty_mode
Match concentration exactly or use the target as a minumum or maximum value.
const Real _penalty
Nucleation free energy prefactor.
DiscreteNucleation(const InputParameters &params)
std::vector< MaterialProperty< Real > * > _prop_dF
Material properties to store the derivatives of f with respect to arg[i].
std::vector< const VariableValue * > _args
Coupled variables for function arguments.
const DiscreteNucleationMap & _map
UserObject providing a map of currently active nuclei.
InputParameters validParams< DiscreteNucleation >()
std::vector< unsigned int > _op_index
map op_names indices to _args indices
const std::vector< Real > & nuclei(const Elem *) const
const std::vector< Real > _op_values
Target concentration values.
unsigned int argIndex(unsigned int i_var) const
FunctionMaterialBase keeps an internal list of all the variables the derivatives are taken w...