www.mooseframework.org
MooseVariableFE.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "MooseVariableFE.h"
11 #include <typeinfo>
12 #include "TimeIntegrator.h"
13 #include "NonlinearSystemBase.h"
14 #include "DisplacedSystem.h"
15 #include "Assembly.h"
16 #include "MooseVariableData.h"
17 
18 template <typename OutputType>
20  const FEType & fe_type,
21  SystemBase & sys,
22  const Assembly & assembly,
23  Moose::VarKindType var_kind,
24  THREAD_ID tid)
25  : MooseVariableFEBase(var_num, fe_type, sys, var_kind, tid), _assembly(assembly)
26 {
27  _element_data = libmesh_make_unique<MooseVariableData<OutputType>>(*this,
28  sys,
29  tid,
31  _assembly.qRule(),
33  _assembly.node(),
34  _assembly.elem());
36  libmesh_make_unique<MooseVariableData<OutputType>>(*this,
37  sys,
38  tid,
40  _assembly.qRuleNeighbor(), // Place holder
44  _lower_data =
45  libmesh_make_unique<MooseVariableData<OutputType>>(*this,
46  sys,
47  tid,
50  _assembly.qRuleFace(), // Place holder
51  _assembly.node(), // Place holder
53 }
54 
55 template <typename OutputType>
56 const std::set<SubdomainID> &
58 {
59  return _sys.system().variable(_var_num).active_subdomains();
60 }
61 
62 template <typename OutputType>
63 bool
65 {
66  return _sys.system().variable(_var_num).active_on_subdomain(subdomain);
67 }
68 
69 template <typename OutputType>
70 void
72 {
73  _element_data->clearDofIndices();
74 }
75 
76 template <typename OutputType>
77 void
79 {
80  _element_data->prepare();
81 }
82 
83 template <typename OutputType>
84 void
86 {
87  _neighbor_data->prepare();
88 }
89 
90 template <typename OutputType>
91 void
93 {
94  _lower_data->prepare();
95 }
96 
97 template <typename OutputType>
98 void
100 {
101  _element_data->hasDofValues(false);
102  _neighbor_data->hasDofValues(false);
103  _lower_data->hasDofValues(false);
104 }
105 
106 template <typename OutputType>
107 void
109 {
110  _element_data->reinitNode();
111 }
112 
113 template <typename OutputType>
114 void
116 {
117  _element_data->reinitAux();
118 }
119 
120 template <typename OutputType>
121 void
123 {
124  _neighbor_data->reinitAux();
125 }
126 
127 template <typename OutputType>
128 void
129 MooseVariableFE<OutputType>::reinitNodes(const std::vector<dof_id_type> & nodes)
130 {
131  _element_data->reinitNodes(nodes);
132 }
133 
134 template <typename OutputType>
135 void
136 MooseVariableFE<OutputType>::reinitNodesNeighbor(const std::vector<dof_id_type> & nodes)
137 {
138  _neighbor_data->reinitNodes(nodes);
139 }
140 
141 template <typename OutputType>
142 void
144  std::vector<dof_id_type> & dof_indices) const
145 {
146  _element_data->getDofIndices(elem, dof_indices);
147 }
148 
149 template <typename OutputType>
150 Number
152 {
153  return _element_data->getNodalValue(node, Moose::Current);
154 }
155 
156 template <typename OutputType>
157 Number
159 {
160  return _element_data->getNodalValue(node, Moose::Old);
161 }
162 
163 template <typename OutputType>
164 Number
166 {
167  return _element_data->getNodalValue(node, Moose::Older);
168 }
169 
170 template <typename OutputType>
171 Number
172 MooseVariableFE<OutputType>::getElementalValue(const Elem * elem, unsigned int idx) const
173 {
174  return _element_data->getElementalValue(elem, Moose::Current, idx);
175 }
176 
177 template <typename OutputType>
178 Number
179 MooseVariableFE<OutputType>::getElementalValueOld(const Elem * elem, unsigned int idx) const
180 {
181  return _element_data->getElementalValue(elem, Moose::Old, idx);
182 }
183 
184 template <typename OutputType>
185 Number
186 MooseVariableFE<OutputType>::getElementalValueOlder(const Elem * elem, unsigned int idx) const
187 {
188  return _element_data->getElementalValue(elem, Moose::Older, idx);
189 }
190 
191 template <typename OutputType>
192 void
193 MooseVariableFE<OutputType>::insert(NumericVector<Number> & residual)
194 {
195  _element_data->insert(residual);
196 }
197 
198 template <typename OutputType>
199 void
200 MooseVariableFE<OutputType>::add(NumericVector<Number> & residual)
201 {
202  _element_data->add(residual);
203 }
204 
205 template <typename OutputType>
206 const MooseArray<Number> &
208 {
209  mooseDeprecated("Use dofValues instead of dofValue");
210  return dofValues();
211 }
212 
213 template <typename OutputType>
214 const MooseArray<Number> &
216 {
217  return _element_data->dofValues();
218 }
219 
220 template <typename OutputType>
221 const MooseArray<Number> &
223 {
224  return _element_data->dofValuesOld();
225 }
226 
227 template <typename OutputType>
228 const MooseArray<Number> &
230 {
231  return _element_data->dofValuesOlder();
232 }
233 
234 template <typename OutputType>
235 const MooseArray<Number> &
237 {
238  return _element_data->dofValuesPreviousNL();
239 }
240 
241 template <typename OutputType>
242 const MooseArray<Number> &
244 {
245  return _neighbor_data->dofValues();
246 }
247 
248 template <typename OutputType>
249 const MooseArray<Number> &
251 {
252  return _neighbor_data->dofValuesOld();
253 }
254 
255 template <typename OutputType>
256 const MooseArray<Number> &
258 {
259  return _neighbor_data->dofValuesOlder();
260 }
261 
262 template <typename OutputType>
263 const MooseArray<Number> &
265 {
266  return _neighbor_data->dofValuesPreviousNL();
267 }
268 
269 template <typename OutputType>
270 const MooseArray<Number> &
272 {
273  return _element_data->dofValuesDot();
274 }
275 
276 template <typename OutputType>
277 const MooseArray<Number> &
279 {
280  return _element_data->dofValuesDotDot();
281 }
282 
283 template <typename OutputType>
284 const MooseArray<Number> &
286 {
287  return _element_data->dofValuesDotOld();
288 }
289 
290 template <typename OutputType>
291 const MooseArray<Number> &
293 {
294  return _element_data->dofValuesDotDotOld();
295 }
296 
297 template <typename OutputType>
298 const MooseArray<Number> &
300 {
301  return _neighbor_data->dofValuesDot();
302 }
303 
304 template <typename OutputType>
305 const MooseArray<Number> &
307 {
308  return _neighbor_data->dofValuesDotDot();
309 }
310 
311 template <typename OutputType>
312 const MooseArray<Number> &
314 {
315  return _neighbor_data->dofValuesDotOld();
316 }
317 
318 template <typename OutputType>
319 const MooseArray<Number> &
321 {
322  return _neighbor_data->dofValuesDotDotOld();
323 }
324 
325 template <typename OutputType>
326 const MooseArray<Number> &
328 {
329  return _element_data->dofValuesDuDotDu();
330 }
331 
332 template <typename OutputType>
333 const MooseArray<Number> &
335 {
336  return _element_data->dofValuesDuDotDotDu();
337 }
338 
339 template <typename OutputType>
340 const MooseArray<Number> &
342 {
343  return _neighbor_data->dofValuesDuDotDu();
344 }
345 
346 template <typename OutputType>
347 const MooseArray<Number> &
349 {
350  return _neighbor_data->dofValuesDuDotDotDu();
351 }
352 
353 template <typename OutputType>
354 void
356 {
357  _element_data->prepareIC();
358 }
359 
360 template <typename OutputType>
361 void
363 {
364  _element_data->setGeometry(Moose::Volume);
365  _element_data->computeValues();
366 }
367 
368 template <typename OutputType>
369 void
371 {
372  _element_data->setGeometry(Moose::Face);
373  _element_data->computeValues();
374 }
375 
376 template <typename OutputType>
377 void
379 {
380  _neighbor_data->setGeometry(Moose::Face);
381  _neighbor_data->computeValues();
382 }
383 
384 template <typename OutputType>
385 void
387 {
388  _neighbor_data->setGeometry(Moose::Volume);
389  _neighbor_data->computeValues();
390 }
391 
392 template <typename OutputType>
393 void
395 {
396  _lower_data->setGeometry(Moose::Volume);
397  _lower_data->computeValues();
398 }
399 
400 template <typename OutputType>
401 void
402 MooseVariableFE<OutputType>::computeIncrementAtQps(const NumericVector<Number> & increment_vec)
403 {
404  _element_data->computeIncrementAtQps(increment_vec);
405 }
406 
407 template <typename OutputType>
408 void
409 MooseVariableFE<OutputType>::computeIncrementAtNode(const NumericVector<Number> & increment_vec)
410 {
411  _element_data->computeIncrementAtNode(increment_vec);
412 }
413 
414 template <typename OutputType>
415 OutputType
417  const std::vector<std::vector<OutputType>> & phi) const
418 {
419  std::vector<dof_id_type> dof_indices;
420  _dof_map.dof_indices(elem, dof_indices, _var_num);
421 
422  OutputType value = 0;
423  if (isNodal())
424  {
425  for (unsigned int i = 0; i < dof_indices.size(); ++i)
426  {
427  // The zero index is because we only have one point that the phis are evaluated at
428  value += phi[i][0] * (*_sys.currentSolution())(dof_indices[i]);
429  }
430  }
431  else
432  {
433  mooseAssert(dof_indices.size() == 1, "Wrong size for dof indices");
434  value = (*_sys.currentSolution())(dof_indices[0]);
435  }
436 
437  return value;
438 }
439 
440 template <typename OutputType>
443  const Elem * elem,
444  const std::vector<std::vector<typename OutputTools<OutputType>::OutputGradient>> & grad_phi)
445  const
446 {
447  std::vector<dof_id_type> dof_indices;
448  _dof_map.dof_indices(elem, dof_indices, _var_num);
449 
451  if (isNodal())
452  {
453  for (unsigned int i = 0; i < dof_indices.size(); ++i)
454  {
455  // The zero index is because we only have one point that the phis are evaluated at
456  value += grad_phi[i][0] * (*_sys.currentSolution())(dof_indices[i]);
457  }
458  }
459  else
460  {
461  mooseAssert(dof_indices.size() == 1, "Wrong size for dof indices");
462  value = 0.0;
463  }
464 
465  return value;
466 }
467 
468 template <typename OutputType>
469 const OutputType &
471 {
472  return _element_data->nodalValue(Moose::Current);
473 }
474 
475 template <typename OutputType>
476 const OutputType &
478 {
479  return _neighbor_data->nodalValue(Moose::Current);
480 }
481 
482 template <typename OutputType>
483 const MooseArray<Real> &
485 {
486  return _element_data->nodalVectorTagValue(tag);
487 }
488 
489 template <typename OutputType>
490 const MooseArray<Real> &
492 {
493  return _element_data->nodalMatrixTagValue(tag);
494 }
495 
496 template <typename OutputType>
497 const OutputType &
499 {
500  return _element_data->nodalValue(Moose::Old);
501 }
502 
503 template <typename OutputType>
504 const OutputType &
506 {
507  return _neighbor_data->nodalValue(Moose::Old);
508 }
509 
510 template <typename OutputType>
511 const OutputType &
513 {
514  return _element_data->nodalValue(Moose::Older);
515 }
516 
517 template <typename OutputType>
518 const OutputType &
520 {
521  return _neighbor_data->nodalValue(Moose::Older);
522 }
523 
524 template <typename OutputType>
525 const OutputType &
527 {
528  return _element_data->nodalValue(Moose::PreviousNL);
529 }
530 
531 template <typename OutputType>
532 const OutputType &
534 {
535  return _neighbor_data->nodalValue(Moose::PreviousNL);
536 }
537 
538 template <typename OutputType>
539 const OutputType &
541 {
542  return _element_data->nodalValueDot();
543 }
544 
545 template <typename OutputType>
546 const OutputType &
548 {
549  return _element_data->nodalValueDotDot();
550 }
551 
552 template <typename OutputType>
553 const OutputType &
555 {
556  return _element_data->nodalValueDotOld();
557 }
558 
559 template <typename OutputType>
560 const OutputType &
562 {
563  return _element_data->nodalValueDotDotOld();
564 }
565 
566 template <typename OutputType>
567 void
569 {
570  _element_data->computeNodalValues();
571 }
572 
573 template <typename OutputType>
574 void
576 {
577  _neighbor_data->computeNodalValues();
578 }
579 
580 template <typename OutputType>
581 void
582 MooseVariableFE<OutputType>::setDofValues(const DenseVector<Number> & values)
583 {
584  _element_data->setDofValues(values);
585 }
586 
587 template <typename OutputType>
588 void
589 MooseVariableFE<OutputType>::setNodalValue(OutputType value, unsigned int idx /* = 0*/)
590 {
591  _element_data->setNodalValue(value, idx);
592 }
593 
594 template <typename OutputType>
595 bool
597 {
598  return std::is_same<OutputType, RealVectorValue>::value;
599 }
600 
601 template <typename OutputType>
604 {
605  return _element_data->secondPhi();
606 }
607 
608 template <typename OutputType>
611 {
612  return _element_data->curlPhi();
613 }
614 
615 template <typename OutputType>
618 {
619  return _element_data->secondPhiFace();
620 }
621 
622 template <typename OutputType>
625 {
626  return _element_data->curlPhiFace();
627 }
628 
629 template <typename OutputType>
632 {
633  return _neighbor_data->secondPhi();
634 }
635 
636 template <typename OutputType>
639 {
640  return _neighbor_data->curlPhi();
641 }
642 
643 template <typename OutputType>
646 {
647  return _neighbor_data->secondPhiFace();
648 }
649 
650 template <typename OutputType>
653 {
654  return _neighbor_data->curlPhiFace();
655 }
656 
657 template <typename OutputType>
658 bool
660 {
661  return _element_data->usesSecondPhi();
662 }
663 
664 template <typename OutputType>
665 bool
667 {
668  return _neighbor_data->usesSecondPhi();
669 }
670 
671 template <typename OutputType>
672 bool
674 {
675  return _element_data->computingCurl();
676 }
677 
678 template <typename OutputType>
679 bool
681 {
682  return _element_data->isNodalDefined();
683 }
684 
685 template <typename OutputType>
686 bool
688 {
689  return _neighbor_data->isNodalDefined();
690 }
691 
692 template class MooseVariableFE<Real>;
693 template class MooseVariableFE<RealVectorValue>;
const Elem *const & elem() const
Return the current element.
Definition: Assembly.h:283
const MooseArray< Number > & dofValuesDotDotOldNeighbor() override
Returns old second time derivative of neighboring degrees of freedom.
Number getNodalValueOlder(const Node &node) override
Get the t-2 value of this variable at given node.
const MooseArray< Number > & dofValuesDot() override
Returns time derivative of degrees of freedom.
bool isNodalNeighborDefined() const
const MooseArray< Number > & dofValuesOlder() override
Returns older dof solution on element.
const FieldVariablePhiSecond & secondPhiFace() const
const OutputType & nodalValuePreviousNL()
const FieldVariablePhiCurl & curlPhi() const
Keeps track of stuff related to assembling.
Definition: Assembly.h:62
const MooseArray< Number > & dofValuesDotOld() override
Returns old time derivative of degrees of freedom.
unsigned int TagID
Definition: MooseTypes.h:162
const FieldVariablePhiSecond & secondPhi() const
const OutputType & nodalValueOlderNeighbor()
const FieldVariablePhiSecond & secondPhiFaceNeighbor() const
const MooseArray< Number > & dofValuesDotDot() override
Returns second time derivative of degrees of freedom.
const std::set< SubdomainID > & activeSubdomains() const override
The subdomains the variable is active on.
virtual void computeLowerDValues() override
compute values at quadrature points on the lower dimensional element
const FieldVariablePhiCurl & curlPhiFaceNeighbor() const
void computeIncrementAtQps(const NumericVector< Number > &increment_vec)
Compute and store incremental change in solution at QPs based on increment_vec.
const OutputType & nodalValueOld()
void reinitAux() override
bool activeOnSubdomain(SubdomainID subdomain) const override
Is the variable active on the subdomain?
const FieldVariablePhiSecond & secondPhiNeighbor() const
void reinitNodes(const std::vector< dof_id_type > &nodes) override
bool isVector() const override
std::unique_ptr< MooseVariableData< OutputType > > _neighbor_data
Holder for all the data associated with the neighbor element.
void prepareNeighbor() override
Prepare the neighbor element degrees of freedom.
virtual void prepareIC() override
Prepare the initial condition.
Base class for a system (of equations)
Definition: SystemBase.h:92
const OutputType & nodalValuePreviousNLNeighbor()
MooseVariableFE(unsigned int var_num, const FEType &fe_type, SystemBase &sys, const Assembly &assembly, Moose::VarKindType var_kind, THREAD_ID tid)
const MooseArray< Number > & dofValue() override
Deprecated method.
virtual void computeNodalValues() override
Compute nodal values of this variable.
bool usesSecondPhi() const
Whether or not this variable is computing any second derivatives.
const FieldVariablePhiCurl & curlPhiNeighbor() const
void prepareLowerD() override
Prepare a lower dimensional element&#39;s degrees of freedom.
const MooseArray< Number > & dofValuesDotDotOld() override
Returns old second time derivative of degrees of freedom.
const OutputType & nodalValueDot()
const FieldVariablePhiCurl & curlPhiFace() const
const MooseArray< Number > & dofValuesPreviousNL() override
Returns previous nl solution on element.
const OutputType & nodalValueNeighbor()
const MooseArray< Number > & dofValuesDotDotNeighbor() override
Returns second time derivative of neighboring degrees of freedom.
const QBase *const & qRuleNeighbor() const
Returns the reference to the current quadrature being used on a current neighbor. ...
Definition: Assembly.h:357
void reinitAuxNeighbor() override
const MooseArray< Number > & dofValuesDotNeighbor() override
Returns time derivative of neighboring degrees of freedom.
void getDofIndices(const Elem *elem, std::vector< dof_id_type > &dof_indices) const override
virtual void computeElemValuesFace() override
Compute values at facial quadrature points.
void insert(NumericVector< Number > &residual) override
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:481
const MooseArray< Number > & dofValuesOld() override
Returns old dof solution on element.
void setDofValues(const DenseVector< Number > &value) override
Set values for this variable to keep everything up to date.
const MooseArray< Number > & dofValuesDotOldNeighbor() override
Returns old time derivative of neighboring degrees of freedom.
virtual void computeNodalNeighborValues() override
Compute nodal values of this variable in the neighbor.
const QBase *const & qRule() const
Returns the reference to the current quadrature being used.
Definition: Assembly.h:168
const OutputType & nodalValue()
Methods for retrieving values of variables at the nodes.
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:236
subdomain_id_type SubdomainID
const OutputType & nodalValueOldNeighbor()
void reinitNodesNeighbor(const std::vector< dof_id_type > &nodes) override
std::unique_ptr< MooseVariableData< OutputType > > _lower_data
Holder for all the data associated with the lower dimeensional element.
const Node *const & nodeNeighbor() const
Returns the reference to the neighboring node.
Definition: Assembly.h:387
void clearDofIndices() override
Clear out the dof indices.
const MooseArray< Number > & dofValuesPreviousNLNeighbor() override
Returns previous nl solution on neighbor element.
void computeIncrementAtNode(const NumericVector< Number > &increment_vec)
Compute and store incremental change at the current node based on increment_vec.
const MooseArray< Number > & dofValuesDuDotDu() override
Returns derivative of time derivative of degrees of freedom.
virtual void computeNeighborValuesFace() override
Compute values at facial quadrature points for the neighbor.
bool isNodalDefined() const
Number getElementalValueOld(const Elem *elem, unsigned int idx=0) const override
Get the old value of this variable on an element.
const QBase *const & qRuleFace() const
Returns the reference to the current quadrature being used on a current face.
Definition: Assembly.h:235
forward declarations
Definition: MooseArray.h:16
Number getElementalValueOlder(const Elem *elem, unsigned int idx=0) const override
Get the older value of this variable on an element.
OutputType getValue(const Elem *elem, const std::vector< std::vector< OutputType >> &phi) const
Compute the variable value at a point on an element.
const MooseArray< Number > & dofValuesNeighbor() override
Returns dof solution on neighbor element.
virtual void computeNeighborValues() override
Compute values at quadrature points for the neighbor.
const MooseArray< Number > & dofValuesDuDotDuNeighbor() override
Returns derivative of time derivative of neighboring degrees of freedom.
Number getElementalValue(const Elem *elem, unsigned int idx=0) const override
Get the current value of this variable on an element.
const OutputType & nodalValueDotOld()
void setNodalValue(OutputType value, unsigned int idx=0)
const MooseArray< Number > & dofValuesDuDotDotDu() override
Returns derivative of second time derivative of degrees of freedom.
bool computingCurl() const
Whether or not this variable is computing the curl.
const Elem *const & neighbor() const
Return the neighbor element.
Definition: Assembly.h:329
const OutputType & nodalValueDotDot()
const MooseArray< Number > & dofValuesDuDotDotDuNeighbor() override
Returns derivative of second time derivative of neighboring degrees of freedom.
void prepare() override
Prepare the elemental degrees of freedom.
const MooseArray< Number > & dofValuesOlderNeighbor() override
Returns older dof solution on neighbor element.
void reinitNode() override
bool usesSecondPhiNeighbor() const
Whether or not this variable is actually using the shape function second derivative on a neighbor...
const MooseArray< Real > & nodalVectorTagValue(TagID tag)
const OutputType & nodalValueDotDotOld()
std::unique_ptr< MooseVariableData< OutputType > > _element_data
Holder for all the data associated with the "main" element.
Number getNodalValue(const Node &node) override
Get the value of this variable at given node.
TensorTools::IncrementRank< OutputShape >::type OutputGradient
Definition: MooseTypes.h:173
const MooseArray< Number > & dofValuesOldNeighbor() override
Returns old dof solution on neighbor element.
const Node *const & node() const
Returns the reference to the node.
Definition: Assembly.h:381
OutputTools< OutputType >::OutputGradient getGradient(const Elem *elem, const std::vector< std::vector< typename OutputTools< OutputType >::OutputGradient >> &grad_phi) const
Compute the variable gradient value at a point on an element.
SystemBase & sys()
Get the system this variable is part of.
const OutputType & nodalValueOlder()
const Elem *const & lowerDElem() const
Return the lower dimensional element.
Definition: Assembly.h:335
virtual void computeElemValues() override
Actually compute variable values.
const Assembly & _assembly
Number getNodalValueOld(const Node &node) override
Get the old value of this variable at given node.
void add(NumericVector< Number > &residual) override
unsigned int THREAD_ID
Definition: MooseTypes.h:161
const MooseArray< Real > & nodalMatrixTagValue(TagID tag)
void prepareAux() override
const MooseArray< Number > & dofValues() override
Returns dof solution on element.