www.mooseframework.org
CahnHilliardFluxBCBase.h
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 #ifndef CAHNHILLIARDFLUXBCBASE_H
8 #define CAHNHILLIARDFLUXBCBASE_H
9 
10 #include "IntegratedBC.h"
11 #include "JvarMapInterface.h"
12 #include "DerivativeMaterialInterface.h"
13 
19 template <typename T>
21  : public DerivativeMaterialInterface<JvarMapIntegratedBCInterface<IntegratedBC>>
22 {
23 public:
24  CahnHilliardFluxBCBase(const InputParameters & parameters);
25 
26  static InputParameters validParams();
27 
28 protected:
29  virtual Real computeQpResidual();
30  virtual Real computeQpJacobian();
31  virtual Real computeQpOffDiagJacobian(unsigned int jvar);
32 
33  virtual void initialSetup();
34 
35  const RealGradient _flux;
36 
37  const MaterialProperty<T> & _M;
38  const MaterialProperty<T> & _dMdw;
39  std::vector<const MaterialProperty<T> *> _dMdarg;
40 };
41 
42 template <typename T>
43 CahnHilliardFluxBCBase<T>::CahnHilliardFluxBCBase(const InputParameters & parameters)
44  : DerivativeMaterialInterface<JvarMapIntegratedBCInterface<IntegratedBC>>(parameters),
45  _flux(getParam<RealGradient>("flux")),
46  _M(getMaterialProperty<T>("mob_name")),
47  _dMdw(getMaterialPropertyDerivative<T>("mob_name", _var.name()))
48 {
49  // Get number of coupled variables
50  unsigned int nvar = _coupled_moose_vars.size();
51 
52  // reserve space for derivatives
53  _dMdarg.resize(nvar);
54 
55  // Iterate over all coupled variables
56  for (unsigned int i = 0; i < nvar; ++i)
57  _dMdarg[i] = &getMaterialPropertyDerivative<T>("mob_name", _coupled_moose_vars[i]->name());
58 }
59 
60 template <typename T>
61 InputParameters
63 {
64  InputParameters params = ::validParams<IntegratedBC>();
65  params.addClassDescription("Cahn-Hilliard base Kernel");
66  params.addParam<RealGradient>("flux", "The flux set at the boundary");
67  params.addParam<MaterialPropertyName>("mob_name", "M", "The mobility used with the kernel");
68  params.addCoupledVar("args", "Vector of arguments of the mobility");
69  return params;
70 }
71 
72 template <typename T>
73 void
75 {
76  validateNonlinearCoupling<Real>("mob_name");
77 }
78 
79 template <typename T>
80 Real
82 {
83  return (_flux - _M[_qp] * _grad_u[_qp]) * _normals[_qp] * _test[_i][_qp];
84 }
85 
86 template <typename T>
87 Real
89 {
90  return -(_M[_qp] * _grad_phi[_j][_qp] + _phi[_j][_qp] * _dMdw[_qp] * _grad_u[_qp]) *
91  _normals[_qp] * _test[_i][_qp];
92 }
93 
94 template <typename T>
95 Real
97 {
98  // get the coupled variable jvar is referring to
99  const unsigned int cvar = mapJvarToCvar(jvar);
100 
101  return -_phi[_j][_qp] * (*_dMdarg[cvar])[_qp] * _grad_u[_qp] * _normals[_qp] * _test[_i][_qp];
102 }
103 
104 #endif // CAHNHILLIARDFLUXBCBASE_H
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
const MaterialProperty< T > & _dMdw
std::vector< const MaterialProperty< T > * > _dMdarg
Flux boundary condition base class for variable dependent mobilities.
const MaterialProperty< T > & _M
static InputParameters validParams()
CahnHilliardFluxBCBase(const InputParameters &parameters)