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