www.mooseframework.org
CHPFCRFF.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 "CHPFCRFF.h"
9 #include "MathUtils.h"
10 
11 template <>
12 InputParameters
14 {
15  InputParameters params = validParams<Kernel>();
16  params.addClassDescription(
17  "Cahn-Hilliard residual for the RFF form of the phase field crystal model");
18  params.addRequiredCoupledVar("v", "Array of names of the real parts of the L variables");
19  MooseEnum log_options("tolerance cancelation expansion nothing");
20  params.addRequiredParam<MooseEnum>(
21  "log_approach", log_options, "Which approach will be used to handle the natural log");
22  params.addParam<Real>("tol", 1.0e-9, "Tolerance used when the tolerance approach is chosen");
23  params.addParam<Real>(
24  "n_exp_terms", 4, "Number of terms used in the Taylor expansion of the natural log term");
25  params.addParam<MaterialPropertyName>("mob_name", "M", "The mobility used with the kernel");
26  params.addParam<MaterialPropertyName>("Dmob_name", "DM", "The D mobility used with the kernel");
27  params.addParam<bool>("has_MJac", false, "Jacobian information for the mobility is defined");
28  params.addParam<Real>("a", 1.0, "Constants on Taylor Series");
29  params.addParam<Real>("b", 1.0, "Constants on Taylor Series");
30  params.addParam<Real>("c", 1.0, "Constants on Taylor Series");
31  return params;
32 }
33 
34 CHPFCRFF::CHPFCRFF(const InputParameters & parameters)
35  : Kernel(parameters),
36  _M(getMaterialProperty<Real>("mob_name")),
37  _has_MJac(getParam<bool>("has_MJac")),
38  _DM(_has_MJac ? &getMaterialProperty<Real>("Dmob_name") : NULL),
39  _log_approach(getParam<MooseEnum>("log_approach")),
40  _tol(getParam<Real>("tol")),
41  _num_L(coupledComponents("v")),
42  _vals_var(_num_L),
43  _grad_vals(_num_L),
44  _n_exp_terms(getParam<Real>("n_exp_terms")),
45  _a(getParam<Real>("a")),
46  _b(getParam<Real>("b")),
47  _c(getParam<Real>("c"))
48 {
49  // Loop through grains and load coupled gradients into the arrays
50  for (unsigned int i = 0; i < _num_L; ++i)
51  {
52  _vals_var[i] = coupled("v", i);
53  _grad_vals[i] = &coupledGradient("v", i);
54  }
55 }
56 
57 Real
59 {
60  Real c = _u[_qp];
61  RealGradient grad_c = _grad_u[_qp];
62  RealGradient sum_grad_L;
63 
64  for (unsigned int i = 0; i < _num_L; ++i)
65  sum_grad_L += (*_grad_vals[i])[_qp] * 0.5;
66 
67  Real frac;
68  Real ln_expansion = 0.0;
69 
70  switch (_log_approach)
71  {
72  case 0: // approach using tolerance
73  if (1.0 + c < _tol)
74  frac = 1.0 / _tol;
75  else
76  frac = 1.0 / (1.0 + c);
77  break;
78 
79  case 2:
80  for (unsigned int i = 2; i < (_n_exp_terms + 2.0); ++i)
81  {
82  // Apply Coefficents to Taylor Series defined in input file
83  Real temp_coeff;
84  if (i == 2)
85  temp_coeff = _c;
86  else if (i == 3)
87  temp_coeff = _a;
88  else if (i == 4)
89  temp_coeff = _b;
90  else
91  temp_coeff = 1.0;
92 
93  ln_expansion += temp_coeff * std::pow(-1.0, Real(i)) * std::pow(_u[_qp], Real(i) - 2.0);
94  }
95  break;
96  }
97 
98  RealGradient GradDFDCons;
99 
100  switch (_log_approach)
101  {
102  case 0: // approach using tolerance
103  GradDFDCons = grad_c * frac - sum_grad_L;
104  break;
105 
106  case 1: // approach using cancelation from the mobility
107  GradDFDCons = grad_c - (1.0 + c) * sum_grad_L;
108  break;
109 
110  case 2: // appraoch using substitution
111  GradDFDCons = ln_expansion * grad_c - sum_grad_L;
112  break;
113 
114  case 3: // Just using the log
115  GradDFDCons = grad_c / (1.0 + c) - sum_grad_L;
116  break;
117  }
118 
119  Real residual = _M[_qp] * GradDFDCons * _grad_test[_i][_qp];
120  return residual;
121 }
122 
123 Real
125 {
126  Real c = _u[_qp];
127  RealGradient grad_c = _grad_u[_qp];
128  RealGradient sum_grad_L;
129 
130  for (unsigned int i = 0; i < _num_L; ++i)
131  sum_grad_L += (*_grad_vals[i])[_qp] * 0.5;
132 
133  Real frac, dfrac;
134  Real ln_expansion = 0.0;
135 
136  switch (_log_approach)
137  {
138  case 0: // approach using tolerance
139  if (1.0 + c < _tol)
140  {
141  frac = 1.0 / _tol;
142  dfrac = -1.0 / (_tol * _tol);
143  }
144  else
145  {
146  frac = 1.0 / (1.0 + c);
147  dfrac = -1.0 / ((1.0 + c) * (1.0 + c));
148  }
149  break;
150 
151  case 2:
152  for (unsigned int i = 2; i < (_n_exp_terms + 2.0); ++i)
153  {
154  // Apply Coefficents to Taylor Series defined in input file
155  Real temp_coeff;
156  if (i == 2)
157  temp_coeff = _c;
158  else if (i == 3)
159  temp_coeff = _a;
160  else if (i == 4)
161  temp_coeff = _b;
162  else
163  temp_coeff = 1.0;
164 
165  ln_expansion += temp_coeff * std::pow(-1.0, Real(i)) * std::pow(_u[_qp], Real(i) - 2.0);
166  }
167  break;
168  }
169 
170  RealGradient dGradDFDConsdC;
171  Real Dln_expansion = 0.0;
172 
173  switch (_log_approach)
174  {
175  case 0: // approach using tolerance
176  dGradDFDConsdC = _grad_phi[_j][_qp] * frac + _phi[_j][_qp] * grad_c * dfrac;
177  break;
178 
179  case 1: // approach using cancelation from the mobility
180  dGradDFDConsdC = _grad_phi[_j][_qp] - _phi[_j][_qp] * sum_grad_L;
181  break;
182 
183  case 2: // appraoch using substitution
184  for (unsigned int i = 2; i < (_n_exp_terms + 2.0); ++i)
185  {
186  Real temp_coeff;
187  if (i == 2)
188  temp_coeff = _c;
189  else if (i == 3)
190  temp_coeff = _a;
191  else if (i == 4)
192  temp_coeff = _b;
193  else
194  temp_coeff = 1.0;
195 
196  Dln_expansion += temp_coeff * std::pow(static_cast<Real>(-1.0), static_cast<Real>(i)) *
197  (static_cast<Real>(i) - 2.0) *
198  std::pow(_u[_qp], static_cast<Real>(i) - 3.0);
199  }
200 
201  dGradDFDConsdC = ln_expansion * _grad_phi[_j][_qp] + _phi[_j][_qp] * Dln_expansion * grad_c;
202  break;
203 
204  case 3: // Nothing special
205  dGradDFDConsdC =
206  _grad_phi[_j][_qp] / (1.0 + c) - grad_c / ((1.0 + c) * (1.0 + c)) * _phi[_j][_qp];
207  break;
208  }
209 
210  return _M[_qp] * dGradDFDConsdC * _grad_test[_i][_qp];
211 }
212 
213 Real
215 {
216  Real c = _u[_qp];
217 
218  for (unsigned int i = 0; i < _num_L; ++i)
219  if (jvar == _vals_var[i])
220  {
221 
222  RealGradient dsum_grad_L = _grad_phi[_j][_qp] * 0.5;
223  RealGradient dGradDFDConsdL;
224  switch (_log_approach)
225  {
226  case 0: // approach using tolerance
227  dGradDFDConsdL = -dsum_grad_L;
228  break;
229 
230  case 1: // approach using cancelation from the mobility
231  dGradDFDConsdL = -(1.0 + c) * dsum_grad_L;
232  break;
233 
234  case 2: // appraoch using substitution
235  dGradDFDConsdL = -dsum_grad_L;
236  break;
237 
238  case 3: // nothing special
239  dGradDFDConsdL = -dsum_grad_L;
240  break;
241  }
242 
243  return _M[_qp] * dGradDFDConsdL * _grad_test[_i][_qp];
244  }
245 
246  return 0.0;
247 }
const Real _a
Definition: CHPFCRFF.h:46
InputParameters validParams< CHPFCRFF >()
Definition: CHPFCRFF.C:13
const MooseEnum _log_approach
Definition: CHPFCRFF.h:38
std::vector< unsigned int > _vals_var
Definition: CHPFCRFF.h:42
const unsigned int _n_exp_terms
Definition: CHPFCRFF.h:45
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Definition: CHPFCRFF.C:214
CHPFCRFF(const InputParameters &parameters)
Definition: CHPFCRFF.C:34
virtual Real computeQpJacobian()
Definition: CHPFCRFF.C:124
const Real _tol
Definition: CHPFCRFF.h:39
const Real _b
Definition: CHPFCRFF.h:47
const Real _c
Definition: CHPFCRFF.h:48
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
std::vector< const VariableGradient * > _grad_vals
Definition: CHPFCRFF.h:43
const unsigned int _num_L
Definition: CHPFCRFF.h:41
const MaterialProperty< Real > & _M
Definition: CHPFCRFF.h:34
virtual Real computeQpResidual()
Definition: CHPFCRFF.C:58