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