https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SLKKSSum.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 "SLKKSSum.h"
11#include "MathUtils.h"
12
13registerMooseObject("PhaseFieldApp", SLKKSSum);
14
17{
18 auto params = Kernel::validParams();
19 params.addClassDescription(
20 "Enforce the sum of sublattice concentrations to a given phase concentration.");
21 params.addRequiredCoupledVar("cs", "other sublattice concentrations in the same phase");
22 params.addRequiredParam<Real>("a", "Sublattice site fraction for the kernel variable");
23 params.addRequiredParam<std::vector<Real>>("as", "Phase a sublattice site fractions");
24 params.addRequiredCoupledVar("sum", "prescribed sum");
25 return params;
26}
27
29 : JvarMapKernelInterface<Kernel>(parameters),
30 _ncs(coupledComponents("cs")),
31 _cs(_ncs),
32 _a_cs(getParam<std::vector<Real>>("as")),
33 _cs_map(getParameterJvarMap("cs")),
34 _a_u(getParam<Real>("a")),
35 _target(coupledValue("sum"))
36{
37 if (_a_cs.size() != _ncs)
38 paramError("as", "Specify one sublattice site fraction per sublattice concentration variable");
39
40 // check and re-normalize sublattice B site fractions
41 Real sum = _a_u;
42 for (std::size_t i = 0; i < _ncs; ++i)
43 sum += _a_cs[i];
44 if (sum <= 0.0)
45 paramError("as", "The sum of the 'as' values and 'a' must be greater than zero");
46 for (std::size_t i = 0; i < _ncs; ++i)
47 _a_cs[i] /= sum;
48 _a_u /= sum;
49
50 // fetch coupled concentrations
51 for (std::size_t i = 0; i < _ncs; ++i)
52 _cs[i] = &coupledValue("cs", i);
53}
54
55Real
57{
58 Real csum = _u[_qp] * _a_u;
59 for (std::size_t i = 0; i < _ncs; ++i)
60 csum += (*_cs[i])[_qp] * _a_cs[i];
61
62 return _test[_i][_qp] * (csum - _target[_qp]);
63}
64
65Real
67{
68 return _test[_i][_qp] * _phi[_j][_qp] * _a_u;
69}
70
71Real
73{
74 auto csvar = mapJvarToCvar(jvar, _cs_map);
75 if (csvar >= 0)
76 return _test[_i][_qp] * _phi[_j][_qp] * _a_cs[csvar];
77
78 return 0.0;
79}
registerMooseObject("PhaseFieldApp", SLKKSSum)
unsigned int mapJvarToCvar(unsigned int jvar)
static InputParameters validParams()
Enforce the sum of sublattice concentrations to a given phase concentration.
Definition SLKKSSum.h:23
const JvarMap & _cs_map
Definition SLKKSSum.h:38
unsigned int _ncs
sublattice A variables
Definition SLKKSSum.h:35
virtual Real computeQpResidual()
Definition SLKKSSum.C:56
std::vector< Real > _a_cs
Definition SLKKSSum.h:37
SLKKSSum(const InputParameters &parameters)
Definition SLKKSSum.C:28
virtual Real computeQpJacobian()
Definition SLKKSSum.C:66
static InputParameters validParams()
Definition SLKKSSum.C:16
Real _a_u
sublattice fraction for the sublattice B concentration represented by the kernel variable
Definition SLKKSSum.h:42
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Definition SLKKSSum.C:72
const VariableValue & _target
AuxVariable to hold the target sum.
Definition SLKKSSum.h:45
std::vector< const VariableValue * > _cs
Definition SLKKSSum.h:36