Line data Source code
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 "NeighborCoupleable.h"
11 :
12 : #include "FEProblem.h"
13 : #include "MooseError.h" // mooseDeprecated
14 : #include "MooseVariableFE.h"
15 : #include "Problem.h"
16 : #include "SubProblem.h"
17 :
18 13745 : NeighborCoupleable::NeighborCoupleable(const MooseObject * moose_object,
19 : bool nodal,
20 : bool neighbor_nodal,
21 13745 : bool is_fv)
22 13745 : : Coupleable(moose_object, nodal, is_fv), _neighbor_nodal(neighbor_nodal)
23 : {
24 13745 : }
25 :
26 : const VariableValue &
27 1465 : NeighborCoupleable::coupledNeighborValue(const std::string & var_name, unsigned int comp) const
28 : {
29 1465 : const auto * var = getVarHelper<MooseVariableField<Real>>(var_name, comp);
30 1465 : if (_neighbor_nodal)
31 0 : return (_c_is_implicit) ? var->dofValuesNeighbor() : var->dofValuesOldNeighbor();
32 : else
33 1465 : return (_c_is_implicit) ? var->slnNeighbor() : var->slnOldNeighbor();
34 : }
35 :
36 : std::vector<const VariableValue *>
37 0 : NeighborCoupleable::coupledNeighborValues(const std::string & var_name) const
38 : {
39 0 : auto func = [this, &var_name](unsigned int comp)
40 0 : { return &coupledNeighborValue(var_name, comp); };
41 0 : return coupledVectorHelper<const VariableValue *>(var_name, func);
42 : }
43 :
44 : std::vector<const VariableValue *>
45 0 : NeighborCoupleable::coupledNeighborValuesOld(const std::string & var_name) const
46 : {
47 0 : auto func = [this, &var_name](unsigned int comp)
48 0 : { return &coupledNeighborValueOld(var_name, comp); };
49 0 : return coupledVectorHelper<const VariableValue *>(var_name, func);
50 : }
51 :
52 : std::vector<const VariableValue *>
53 0 : NeighborCoupleable::coupledNeighborValuesOlder(const std::string & var_name) const
54 : {
55 0 : auto func = [this, &var_name](unsigned int comp)
56 0 : { return &coupledNeighborValueOlder(var_name, comp); };
57 0 : return coupledVectorHelper<const VariableValue *>(var_name, func);
58 : }
59 :
60 : const ADVariableValue &
61 85 : NeighborCoupleable::adCoupledNeighborValue(const std::string & var_name, unsigned int comp) const
62 : {
63 85 : const auto * var = getVarHelper<MooseVariableField<Real>>(var_name, comp);
64 :
65 85 : if (!var)
66 0 : return *getADDefaultValue(var_name);
67 :
68 85 : if (_neighbor_nodal)
69 0 : mooseError("adCoupledNeighborValue cannot be used for nodal compute objects at this time");
70 85 : if (!_c_is_implicit)
71 0 : mooseError("adCoupledNeighborValue returns a data structure with derivatives. Explicit schemes "
72 : "use old solution data which do not have derivatives so adCoupledNeighborValue is "
73 : "not appropriate. Please use coupledNeighborValue instead");
74 :
75 85 : return var->adSlnNeighbor();
76 : }
77 :
78 : const ADVariableValue &
79 0 : NeighborCoupleable::adCoupledNeighborValueDot(const std::string & var_name, unsigned int comp) const
80 : {
81 0 : const auto * var = getVarHelper<MooseVariableField<Real>>(var_name, comp);
82 :
83 0 : if (!_c_is_implicit)
84 0 : mooseError(
85 : "adCoupledNeighborValueDot returns a data structure with derivatives. Explicit schemes "
86 : "use old solution data which do not have derivatives so adCoupledNeighborValueDot is "
87 : "not appropriate. Please use coupledNeighborValueDot instead");
88 :
89 0 : if (_neighbor_nodal)
90 0 : mooseError("adCoupledNeighborValueDot cannot be used for nodal compute objects at this time");
91 : else
92 0 : return var->adUDotNeighbor();
93 : }
94 :
95 : std::vector<const ADVariableValue *>
96 0 : NeighborCoupleable::adCoupledNeighborValues(const std::string & var_name) const
97 : {
98 0 : auto func = [this, &var_name](unsigned int comp)
99 0 : { return &adCoupledNeighborValue(var_name, comp); };
100 0 : return coupledVectorHelper<const ADVariableValue *>(var_name, func);
101 : }
102 :
103 : const ADVectorVariableValue &
104 24 : NeighborCoupleable::adCoupledVectorNeighborValue(const std::string & var_name,
105 : unsigned int comp) const
106 : {
107 24 : auto var = getVarHelper<MooseVariableField<RealVectorValue>>(var_name, comp);
108 :
109 24 : if (!var)
110 0 : return *getADDefaultVectorValue(var_name);
111 :
112 24 : if (_neighbor_nodal)
113 0 : mooseError(
114 : "adCoupledVectorNeighborValue cannot be used for nodal compute objects at this time");
115 24 : if (!_c_is_implicit)
116 0 : mooseError(
117 : "adCoupledVectorNeighborValue returns a data structure with derivatives. Explicit schemes "
118 : "use old solution data which do not have derivatives so adCoupledVectorNeighborValue is "
119 : "not appropriate. Please use coupledNeighborValue instead");
120 :
121 24 : return var->adSlnNeighbor();
122 : }
123 :
124 : const VariableValue &
125 83 : NeighborCoupleable::coupledNeighborValueDot(const std::string & var_name, unsigned int comp) const
126 : {
127 83 : const auto * var = getVar(var_name, comp);
128 83 : if (_neighbor_nodal)
129 0 : return var->dofValuesDotNeighbor();
130 : else
131 83 : return var->uDotNeighbor();
132 : }
133 :
134 : const VariableValue &
135 59 : NeighborCoupleable::coupledNeighborValueDotDu(const std::string & var_name, unsigned int comp) const
136 : {
137 59 : const auto * var = getVar(var_name, comp);
138 59 : if (_neighbor_nodal)
139 0 : return var->dofValuesDuDotDuNeighbor();
140 : else
141 59 : return var->duDotDuNeighbor();
142 : }
143 :
144 : const VariableValue &
145 147 : NeighborCoupleable::coupledNeighborValueOld(const std::string & var_name, unsigned int comp) const
146 : {
147 147 : validateExecutionerType(var_name, "coupledNeighborValueOld");
148 :
149 147 : const auto * var = getVar(var_name, comp);
150 147 : if (_neighbor_nodal)
151 0 : return (_c_is_implicit) ? var->dofValuesOldNeighbor() : var->dofValuesOlderNeighbor();
152 : else
153 147 : return (_c_is_implicit) ? var->slnOldNeighbor() : var->slnOlderNeighbor();
154 : }
155 :
156 : const VariableValue &
157 39 : NeighborCoupleable::coupledNeighborValueOlder(const std::string & var_name, unsigned int comp) const
158 : {
159 39 : validateExecutionerType(var_name, "coupledNeighborValueOlder");
160 :
161 39 : const auto * var = getVar(var_name, comp);
162 39 : if (_neighbor_nodal)
163 : {
164 0 : if (_c_is_implicit)
165 0 : return var->dofValuesOlderNeighbor();
166 : else
167 0 : mooseError("Older values not available for explicit schemes");
168 : }
169 : else
170 : {
171 39 : if (_c_is_implicit)
172 39 : return var->slnOlderNeighbor();
173 : else
174 0 : mooseError("Older values not available for explicit schemes");
175 : }
176 : }
177 :
178 : const VariableGradient &
179 575 : NeighborCoupleable::coupledNeighborGradient(const std::string & var_name, unsigned int comp) const
180 : {
181 575 : if (_neighbor_nodal)
182 0 : mooseError("Nodal variables do not have gradients");
183 :
184 575 : const auto * var = getVarHelper<MooseVariableField<Real>>(var_name, comp);
185 575 : return (_c_is_implicit) ? var->gradSlnNeighbor() : var->gradSlnOldNeighbor();
186 : }
187 :
188 : std::vector<const VariableGradient *>
189 187 : NeighborCoupleable::coupledNeighborGradients(const std::string & var_name) const
190 : {
191 187 : auto func = [this, &var_name](unsigned int comp)
192 187 : { return &coupledNeighborGradient(var_name, comp); };
193 374 : return coupledVectorHelper<const VariableGradient *>(var_name, func);
194 : }
195 :
196 : const VariableGradient &
197 0 : NeighborCoupleable::coupledNeighborGradientOld(const std::string & var_name,
198 : unsigned int comp) const
199 : {
200 0 : if (_neighbor_nodal)
201 0 : mooseError("Nodal variables do not have gradients");
202 :
203 0 : validateExecutionerType(var_name, "coupledNeighborGradientOld");
204 0 : const auto * var = getVar(var_name, comp);
205 0 : return (_c_is_implicit) ? var->gradSlnOldNeighbor() : var->gradSlnOlderNeighbor();
206 : }
207 :
208 : const VariableGradient &
209 0 : NeighborCoupleable::coupledNeighborGradientOlder(const std::string & var_name,
210 : unsigned int comp) const
211 : {
212 0 : if (_neighbor_nodal)
213 0 : mooseError("Nodal variables do not have gradients");
214 :
215 0 : validateExecutionerType(var_name, "coupledNeighborGradientOlder");
216 0 : const auto * var = getVar(var_name, comp);
217 0 : if (_c_is_implicit)
218 0 : return var->gradSlnOlderNeighbor();
219 : else
220 0 : mooseError("Older values not available for explicit schemes");
221 : }
222 :
223 : const ADVariableGradient &
224 24 : NeighborCoupleable::adCoupledNeighborGradient(const std::string & var_name, unsigned int comp) const
225 : {
226 24 : if (_neighbor_nodal)
227 0 : mooseError("Nodal variables do not have gradients");
228 24 : if (!_c_is_implicit)
229 0 : mooseError(
230 : "adCoupledNeighborGradient returns a data structure with derivatives. Explicit schemes "
231 : "use old solution data which do not have derivatives so adCoupledNeighborGradient is "
232 : "not appropriate. Please use coupledNeighborGradient instead");
233 :
234 24 : const auto * var = getVarHelper<MooseVariableField<Real>>(var_name, comp);
235 24 : return var->adGradSlnNeighbor();
236 : }
237 :
238 : const VectorVariableGradient &
239 0 : NeighborCoupleable::coupledVectorNeighborGradient(const std::string & var_name,
240 : unsigned int comp) const
241 : {
242 0 : if (_neighbor_nodal)
243 0 : mooseError("Gradients are non-sensical with nodal compute objects");
244 :
245 0 : const auto * var = getVectorVar(var_name, comp);
246 0 : return (_c_is_implicit) ? var->gradSlnNeighbor() : var->gradSlnOldNeighbor();
247 : }
248 :
249 : const VectorVariableGradient &
250 0 : NeighborCoupleable::coupledVectorNeighborGradientOld(const std::string & var_name,
251 : unsigned int comp) const
252 : {
253 0 : if (_neighbor_nodal)
254 0 : mooseError("Gradients are non-sensical with nodal compute objects");
255 :
256 0 : validateExecutionerType(var_name, "coupledVectorNeighborGradientOld");
257 0 : const auto * var = getVectorVar(var_name, comp);
258 0 : return (_c_is_implicit) ? var->gradSlnOldNeighbor() : var->gradSlnOlderNeighbor();
259 : }
260 :
261 : const VectorVariableGradient &
262 0 : NeighborCoupleable::coupledVectorNeighborGradientOlder(const std::string & var_name,
263 : unsigned int comp) const
264 : {
265 0 : if (_neighbor_nodal)
266 0 : mooseError("Gradients are non-sensical with nodal compute objects");
267 :
268 0 : validateExecutionerType(var_name, "coupledVectorNeighborGradientOlder");
269 0 : const auto * var = getVectorVar(var_name, comp);
270 0 : if (_c_is_implicit)
271 0 : return var->gradSlnOlderNeighbor();
272 : else
273 0 : mooseError("Older values not available for explicit schemes");
274 : }
275 :
276 : const ArrayVariableValue &
277 0 : NeighborCoupleable::coupledArrayNeighborValue(const std::string & var_name, unsigned int comp) const
278 : {
279 0 : const auto * var = getArrayVar(var_name, comp);
280 0 : if (_neighbor_nodal)
281 0 : return (_c_is_implicit) ? var->dofValuesNeighbor() : var->dofValuesOldNeighbor();
282 : else
283 0 : return (_c_is_implicit) ? var->slnNeighbor() : var->slnOldNeighbor();
284 : }
285 :
286 : const ArrayVariableGradient &
287 0 : NeighborCoupleable::coupledArrayNeighborGradient(const std::string & var_name,
288 : unsigned int comp) const
289 : {
290 0 : if (_neighbor_nodal)
291 0 : mooseError("Gradients are non-sensical with nodal compute objects");
292 :
293 0 : const auto * var = getArrayVar(var_name, comp);
294 0 : return (_c_is_implicit) ? var->gradSlnNeighbor() : var->gradSlnOldNeighbor();
295 : }
296 :
297 : const ArrayVariableGradient &
298 0 : NeighborCoupleable::coupledArrayNeighborGradientOld(const std::string & var_name,
299 : unsigned int comp) const
300 : {
301 0 : if (_neighbor_nodal)
302 0 : mooseError("Gradients are non-sensical with nodal compute objects");
303 :
304 0 : validateExecutionerType(var_name, "coupledArrayNeighborGradientOld");
305 0 : const auto * var = getArrayVar(var_name, comp);
306 0 : return (_c_is_implicit) ? var->gradSlnOldNeighbor() : var->gradSlnOlderNeighbor();
307 : }
308 :
309 : const ArrayVariableGradient &
310 0 : NeighborCoupleable::coupledArrayNeighborGradientOlder(const std::string & var_name,
311 : unsigned int comp) const
312 : {
313 0 : if (_neighbor_nodal)
314 0 : mooseError("Gradients are non-sensical with nodal compute objects");
315 :
316 0 : validateExecutionerType(var_name, "coupledArrayNeighborGradientOlder");
317 0 : const auto * var = getArrayVar(var_name, comp);
318 0 : if (_c_is_implicit)
319 0 : return var->gradSlnOlderNeighbor();
320 : else
321 0 : mooseError("Older values not available for explicit schemes");
322 : }
323 :
324 : const VariableSecond &
325 0 : NeighborCoupleable::coupledNeighborSecond(const std::string & var_name, unsigned int comp) const
326 : {
327 0 : if (_neighbor_nodal)
328 0 : mooseError("Nodal variables do not have second derivatives");
329 :
330 0 : const auto * var = getVar(var_name, comp);
331 0 : return (_c_is_implicit) ? var->secondSlnNeighbor() : var->secondSlnOldNeighbor();
332 : }
333 :
334 : const VariableValue &
335 26 : NeighborCoupleable::coupledNeighborDofValues(const std::string & var_name, unsigned int comp) const
336 : {
337 26 : if (_neighbor_nodal)
338 0 : mooseError("nodal objects should not call coupledDofValues");
339 :
340 26 : const auto * var = getVar(var_name, comp);
341 26 : return (_c_is_implicit) ? var->dofValuesNeighbor() : var->dofValuesOldNeighbor();
342 : }
343 :
344 : const VariableValue &
345 0 : NeighborCoupleable::coupledNeighborDofValuesOld(const std::string & var_name,
346 : unsigned int comp) const
347 : {
348 0 : if (_neighbor_nodal)
349 0 : mooseError("nodal objects should not call coupledDofValuesOld");
350 :
351 0 : validateExecutionerType(var_name, "coupledNeighborDofValuesOld");
352 0 : const auto * var = getVar(var_name, comp);
353 0 : return (_c_is_implicit) ? var->dofValuesOldNeighbor() : var->dofValuesOlderNeighbor();
354 : }
355 :
356 : const VariableValue &
357 0 : NeighborCoupleable::coupledNeighborDofValuesOlder(const std::string & var_name,
358 : unsigned int comp) const
359 : {
360 0 : if (_neighbor_nodal)
361 0 : mooseError("nodal objects should not call coupledDofValuesOlder");
362 :
363 0 : validateExecutionerType(var_name, "coupledNeighborDofValuesOlder");
364 0 : const auto * var = getVar(var_name, comp);
365 0 : if (_c_is_implicit)
366 0 : return var->dofValuesOlderNeighbor();
367 : else
368 0 : mooseError("Older values not available for explicit schemes");
369 : }
|