-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Kernel.C
174 lines (144 loc) · 5.57 KB
/
Kernel.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/
#include "Kernel.h"
#include "Assembly.h"
#include "MooseVariable.h"
#include "Problem.h"
#include "SubProblem.h"
#include "SystemBase.h"
// libmesh includes
#include "threads.h"
template<>
InputParameters validParams<Kernel>()
{
InputParameters params = validParams<MooseObject>();
params += validParams<TransientInterface>();
params.addRequiredParam<std::string>("variable", "The name of the variable that this kernel operates on");
params.addParam<std::vector<SubdomainName> >("block", "The list of ids of the blocks (subdomain) that this kernel will be applied to");
params.addParam<std::vector<std::string> >("save_in", "The name of auxiliary variables to save this Kernel's residual contributions to. Everything about that variable must match everything about this variable (the type, what blocks it's on, etc.)");
// testing, dude
params.addPrivateParam<bool>("use_displaced_mesh", false);
params.addPrivateParam<std::string>("built_by_action", "add_kernel");
return params;
}
Kernel::Kernel(const std::string & name, InputParameters parameters) :
MooseObject(name, parameters),
SetupInterface(parameters),
Coupleable(parameters, false),
ScalarCoupleable(parameters),
MooseVariableInterface(parameters, false),
FunctionInterface(parameters),
UserObjectInterface(parameters),
TransientInterface(parameters),
PostprocessorInterface(parameters),
MaterialPropertyInterface(parameters),
GeometricSearchInterface(parameters),
_problem(*parameters.get<Problem *>("_problem")),
_subproblem(*parameters.get<SubProblem *>("_subproblem")),
_sys(*parameters.get<SystemBase *>("_sys")),
_tid(parameters.get<THREAD_ID>("_tid")),
_assembly(_subproblem.assembly(_tid)),
_var(_sys.getVariable(_tid, parameters.get<std::string>("variable"))),
_mesh(_subproblem.mesh()),
_dim(_mesh.dimension()),
_current_elem(_var.currentElem()),
_current_elem_volume(_subproblem.elemVolume(_tid)),
_q_point(_subproblem.points(_tid)),
_qrule(_subproblem.qRule(_tid)),
_JxW(_subproblem.JxW(_tid)),
_coord(_subproblem.coords(_tid)),
_phi(_assembly.phi()),
_grad_phi(_assembly.gradPhi()),
_test(_var.phi()),
_grad_test(_var.gradPhi()),
_u(_var.sln()),
_grad_u(_var.gradSln()),
_u_dot(_var.uDot()),
_du_dot_du(_var.duDotDu()),
_real_zero(_problem._real_zero[_tid]),
_zero(_problem._zero[_tid]),
_grad_zero(_problem._grad_zero[_tid]),
_second_zero(_problem._second_zero[_tid]),
_save_in_strings(parameters.get<std::vector<std::string> >("save_in"))
{
_save_in.resize(_save_in_strings.size());
for(unsigned int i=0; i<_save_in_strings.size(); i++)
{
MooseVariable * var = &_problem.getVariable(_tid, _save_in_strings[i]);
if(var->feType() != _var.feType())
mooseError("Error in " + _name + ". When saving residual values in an Auxiliary variable the AuxVariable must be the same type as the nonlinear variable the object is acting on.");
_save_in[i] = var;
var->sys().addVariableToZeroOnResidual(_save_in_strings[i]);
}
_has_save_in = _save_in.size() > 0;
}
void
Kernel::computeResidual()
{
DenseVector<Number> & re = _assembly.residualBlock(_var.number());
_local_re.resize(re.size());
_local_re.zero();
precalculateResidual();
for (_i = 0; _i < _test.size(); _i++)
for (_qp = 0; _qp < _qrule->n_points(); _qp++)
_local_re(_i) += _JxW[_qp] * _coord[_qp] * computeQpResidual();
re += _local_re;
if(_has_save_in)
{
Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
for(unsigned int i=0; i<_save_in.size(); i++)
_save_in[i]->sys().solution().add_vector(_local_re, _save_in[i]->dofIndices());
}
}
void
Kernel::computeJacobian()
{
DenseMatrix<Number> & ke = _assembly.jacobianBlock(_var.number(), _var.number());
for (_i = 0; _i < _test.size(); _i++)
for (_j = 0; _j < _phi.size(); _j++)
for (_qp = 0; _qp < _qrule->n_points(); _qp++)
{
ke(_i, _j) += _JxW[_qp] * _coord[_qp] * computeQpJacobian();
}
}
void
Kernel::computeOffDiagJacobian(unsigned int jvar)
{
// Moose::perf_log.push("computeOffDiagJacobian()",_name);
DenseMatrix<Number> & ke = _assembly.jacobianBlock(_var.number(), jvar);
for (_i=0; _i<_test.size(); _i++)
for (_j=0; _j<_phi.size(); _j++)
for (_qp=0; _qp<_qrule->n_points(); _qp++)
{
if(jvar == _var.number())
ke(_i,_j) += _JxW[_qp]*_coord[_qp]*computeQpJacobian();
else
ke(_i,_j) += _JxW[_qp]*_coord[_qp]*computeQpOffDiagJacobian(jvar);
}
// Moose::perf_log.pop("computeOffDiagJacobian()",_name);
}
Real
Kernel::computeQpJacobian()
{
return 0;
}
Real
Kernel::computeQpOffDiagJacobian(unsigned int /*jvar*/)
{
return 0;
}
void
Kernel::precalculateResidual()
{
}