www.mooseframework.org
SystemBase.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 "MooseApp.h"
11 #include "SystemBase.h"
12 #include "Factory.h"
13 #include "SubProblem.h"
14 #include "MooseVariableFE.h"
15 #include "MooseVariableFV.h"
16 #include "MooseVariableScalar.h"
18 #include "Conversion.h"
19 #include "Parser.h"
21 #include "MooseTypes.h"
22 #include "InitialCondition.h"
23 #include "ScalarInitialCondition.h"
24 #include "Assembly.h"
25 #include "MooseMesh.h"
26 #include "MooseUtils.h"
27 #include "FVBoundaryCondition.h"
28 
29 #include "libmesh/dof_map.h"
30 #include "libmesh/string_to_enum.h"
31 
33 void
34 extraSendList(std::vector<dof_id_type> & send_list, void * context)
35 {
36  SystemBase * sys = static_cast<SystemBase *>(context);
37  sys->augmentSendList(send_list);
38 }
39 
41 void
42 extraSparsity(SparsityPattern::Graph & sparsity,
43  std::vector<dof_id_type> & n_nz,
44  std::vector<dof_id_type> & n_oz,
45  void * context)
46 {
47  SystemBase * sys = static_cast<SystemBase *>(context);
48  sys->augmentSparsity(sparsity, n_nz, n_oz);
49 }
50 
52  const std::string & name,
53  Moose::VarKindType var_kind)
54  : libMesh::ParallelObject(subproblem),
55  ConsoleStreamInterface(subproblem.getMooseApp()),
56  _subproblem(subproblem),
57  _app(subproblem.getMooseApp()),
58  _factory(_app.getFactory()),
59  _mesh(subproblem.mesh()),
60  _name(name),
61  _vars(libMesh::n_threads()),
62  _var_map(),
63  _max_var_number(0),
64  _saved_old(NULL),
65  _saved_older(NULL),
66  _saved_dot_old(NULL),
67  _saved_dotdot_old(NULL),
68  _var_kind(var_kind),
69  _max_var_n_dofs_per_elem(0),
70  _max_var_n_dofs_per_node(0),
71  _time_integrator(nullptr),
72  _automatic_scaling(false),
73  _verbose(false),
74  _solution_states_initialized(false)
75 {
76 }
77 
79 SystemBase::getVariable(THREAD_ID tid, const std::string & var_name) const
80 {
82  dynamic_cast<MooseVariableFieldBase *>(_vars[tid].getVariable(var_name));
83  if (!var)
84  mooseError("Variable '", var_name, "' does not exist in this system");
85  return *var;
86 }
87 
89 SystemBase::getVariable(THREAD_ID tid, unsigned int var_number) const
90 {
91  if (var_number < _numbered_vars[tid].size())
92  if (_numbered_vars[tid][var_number])
93  return *_numbered_vars[tid][var_number];
94 
95  mooseError("Variable #", Moose::stringify(var_number), " does not exist in this system");
96 }
97 
98 template <typename T>
100 SystemBase::getFieldVariable(THREAD_ID tid, const std::string & var_name)
101 {
102  return *_vars[tid].getFieldVariable<T>(var_name);
103 }
104 
105 template <typename T>
107 SystemBase::getActualFieldVariable(THREAD_ID tid, const std::string & var_name)
108 {
109  return *_vars[tid].getActualFieldVariable<T>(var_name);
110 }
111 
112 template <typename T>
114 SystemBase::getFVVariable(THREAD_ID tid, const std::string & var_name)
115 {
116  return *_vars[tid].getFVVariable<T>(var_name);
117 }
118 
119 template <typename T>
121 SystemBase::getFieldVariable(THREAD_ID tid, unsigned int var_number)
122 {
123  return *_vars[tid].getFieldVariable<T>(var_number);
124 }
125 
126 template <typename T>
128 SystemBase::getActualFieldVariable(THREAD_ID tid, unsigned int var_number)
129 {
130  return *_vars[tid].getActualFieldVariable<T>(var_number);
131 }
132 
134 SystemBase::getScalarVariable(THREAD_ID tid, const std::string & var_name) const
135 {
136  MooseVariableScalar * var = dynamic_cast<MooseVariableScalar *>(_vars[tid].getVariable(var_name));
137  if (!var)
138  mooseError("Scalar variable '" + var_name + "' does not exist in this system");
139  return *var;
140 }
141 
143 SystemBase::getScalarVariable(THREAD_ID tid, unsigned int var_number) const
144 {
145  MooseVariableScalar * var =
146  dynamic_cast<MooseVariableScalar *>(_vars[tid].getVariable(var_number));
147  if (!var)
148  mooseError("variable #" + Moose::stringify(var_number) + " does not exist in this system");
149  return *var;
150 }
151 
152 const std::set<SubdomainID> *
153 SystemBase::getVariableBlocks(unsigned int var_number)
154 {
155  mooseAssert(_var_map.find(var_number) != _var_map.end(), "Variable does not exist.");
156  if (_var_map[var_number].empty())
157  return nullptr;
158  else
159  return &_var_map[var_number];
160 }
161 
162 void
164 {
165  _vars_to_be_zeroed_on_residual.push_back(var_name);
166 }
167 
168 void
170 {
171  _vars_to_be_zeroed_on_jacobian.push_back(var_name);
172 }
173 
174 void
175 SystemBase::setVariableGlobalDoFs(const std::string & var_name)
176 {
177  AllLocalDofIndicesThread aldit(_subproblem, {var_name});
179  Threads::parallel_reduce(elem_range, aldit);
180 
181  // Gather the dof indices across procs to get all the dof indices for var_name
182  aldit.dofIndicesSetUnion();
183 
184  const auto & all_dof_indices = aldit.getDofIndices();
185  _var_all_dof_indices.assign(all_dof_indices.begin(), all_dof_indices.end());
186 }
187 
188 void
189 SystemBase::zeroVariables(std::vector<std::string> & vars_to_be_zeroed)
190 {
191  if (vars_to_be_zeroed.size() > 0)
192  {
194 
195  auto problem = dynamic_cast<FEProblemBase *>(&_subproblem);
196  if (!problem)
197  mooseError("System needs to be registered in FEProblemBase for using zeroVariables.");
198 
199  AllLocalDofIndicesThread aldit(*problem, vars_to_be_zeroed, true);
201  Threads::parallel_reduce(elem_range, aldit);
202 
203  const auto & dof_indices_to_zero = aldit.getDofIndices();
204 
205  solution.close();
206 
207  for (const auto & dof : dof_indices_to_zero)
208  solution.set(dof, 0);
209 
210  solution.close();
211 
212  // Call update to update the current_local_solution for this system
213  system().update();
214  }
215 }
216 
217 void
219 {
221 }
222 
223 void
225 {
227 }
228 
229 Order
231 {
232  Order order = CONSTANT;
233  const std::vector<MooseVariableFieldBase *> & vars = _vars[0].fieldVariables();
234  for (const auto & var : vars)
235  {
236  FEType fe_type = var->feType();
237  if (fe_type.default_quadrature_order() > order)
238  order = fe_type.default_quadrature_order();
239  }
240 
241  return order;
242 }
243 
244 void
246 {
248  {
249  const std::set<MooseVariableFieldBase *> & active_elemental_moose_variables =
251  const std::vector<MooseVariableFieldBase *> & vars = _vars[tid].fieldVariables();
252  for (const auto & var : vars)
253  var->clearDofIndices();
254 
255  for (const auto & var : active_elemental_moose_variables)
256  if (&(var->sys()) == this)
257  var->prepare();
258  }
259  else
260  {
261  const std::vector<MooseVariableFieldBase *> & vars = _vars[tid].fieldVariables();
262  for (const auto & var : vars)
263  var->prepare();
264  }
265 }
266 
267 void
268 SystemBase::prepareFace(THREAD_ID tid, bool resize_data)
269 {
270  // We only need to do something if the element prepare was restricted
272  {
273  const std::set<MooseVariableFieldBase *> & active_elemental_moose_variables =
275 
276  std::vector<MooseVariableFieldBase *> newly_prepared_vars;
277 
278  const std::vector<MooseVariableFieldBase *> & vars = _vars[tid].fieldVariables();
279  for (const auto & var : vars)
280  {
281  mooseAssert(&var->sys() == this,
282  "I will cry if we store variables in our warehouse that don't belong to us");
283 
284  // If it wasn't in the active list, we need to prepare it. This has the potential to duplicate
285  // prepare if we have these conditions:
286  //
287  // 1. We have a displaced problem
288  // 2. We are using AD
289  // 3. We are not using global AD indexing
290  //
291  // But I think I would rather risk duplicate prepare than introduce an additional member set
292  // variable for tracking prepared variables. Set insertion is slow and some simulations have a
293  // ton of variables
294  if (!active_elemental_moose_variables.count(var))
295  {
296  var->prepare();
297  newly_prepared_vars.push_back(var);
298  }
299  }
300 
301  // Make sure to resize the residual and jacobian datastructures for all the new variables
302  if (resize_data)
303  for (const auto var_ptr : newly_prepared_vars)
304  {
305  _subproblem.assembly(tid, number()).prepareVariable(var_ptr);
308  }
309  }
310 }
311 
312 void
314 {
315  const std::vector<MooseVariableFieldBase *> & vars = _vars[tid].fieldVariables();
316  for (const auto & var : vars)
317  var->prepareNeighbor();
318 }
319 
320 void
322 {
323  const std::vector<MooseVariableFieldBase *> & vars = _vars[tid].fieldVariables();
324  for (const auto & var : vars)
325  var->prepareLowerD();
326 }
327 
328 void
329 SystemBase::reinitElem(const Elem * /*elem*/, THREAD_ID tid)
330 {
331 
333  {
334  const std::set<MooseVariableFieldBase *> & active_elemental_moose_variables =
336  for (const auto & var : active_elemental_moose_variables)
337  if (&(var->sys()) == this)
338  var->computeElemValues();
339  }
340  else
341  {
342  const std::vector<MooseVariableFieldBase *> & vars = _vars[tid].fieldVariables();
343  for (const auto & var : vars)
344  var->computeElemValues();
345  }
346 }
347 
348 void
349 SystemBase::reinitElemFace(const Elem * /*elem*/,
350  unsigned int /*side*/,
351  BoundaryID /*bnd_id*/,
352  THREAD_ID tid)
353 {
354  const std::vector<MooseVariableFieldBase *> & vars = _vars[tid].fieldVariables();
355  for (const auto & var : vars)
356  var->computeElemValuesFace();
357 }
358 
359 void
360 SystemBase::reinitNeighborFace(const Elem * /*elem*/,
361  unsigned int /*side*/,
362  BoundaryID /*bnd_id*/,
363  THREAD_ID tid)
364 {
365  const std::vector<MooseVariableFieldBase *> & vars = _vars[tid].fieldVariables();
366  for (const auto & var : vars)
367  var->computeNeighborValuesFace();
368 }
369 
370 void
371 SystemBase::reinitNeighbor(const Elem * /*elem*/, THREAD_ID tid)
372 {
373  const std::vector<MooseVariableFieldBase *> & vars = _vars[tid].fieldVariables();
374  for (const auto & var : vars)
375  var->computeNeighborValues();
376 }
377 
378 void
380 {
381  const std::vector<MooseVariableFieldBase *> & vars = _vars[tid].fieldVariables();
382  for (const auto & var : vars)
383  var->computeLowerDValues();
384 }
385 
386 void
387 SystemBase::reinitNode(const Node * /*node*/, THREAD_ID tid)
388 {
389  const std::vector<MooseVariableFieldBase *> & vars = _vars[tid].fieldVariables();
390  for (const auto & var : vars)
391  {
392  var->reinitNode();
393  if (var->isNodalDefined())
394  var->computeNodalValues();
395  }
396 }
397 
398 void
399 SystemBase::reinitNodeFace(const Node * /*node*/, BoundaryID /*bnd_id*/, THREAD_ID tid)
400 {
401  const std::vector<MooseVariableFieldBase *> & vars = _vars[tid].fieldVariables();
402  for (const auto & var : vars)
403  {
404  var->reinitNode();
405  if (var->isNodalDefined())
406  var->computeNodalValues();
407  }
408 }
409 
410 void
411 SystemBase::reinitNodes(const std::vector<dof_id_type> & nodes, THREAD_ID tid)
412 {
413  const std::vector<MooseVariableFieldBase *> & vars = _vars[tid].fieldVariables();
414  for (const auto & var : vars)
415  {
416  var->reinitNodes(nodes);
417  var->computeNodalValues();
418  }
419 }
420 
421 void
422 SystemBase::reinitNodesNeighbor(const std::vector<dof_id_type> & nodes, THREAD_ID tid)
423 {
424  const std::vector<MooseVariableFieldBase *> & vars = _vars[tid].fieldVariables();
425  for (const auto & var : vars)
426  {
427  var->reinitNodesNeighbor(nodes);
428  var->computeNodalNeighborValues();
429  }
430 }
431 
432 void
433 SystemBase::reinitScalars(THREAD_ID tid, bool reinit_for_derivative_reordering /*=false*/)
434 {
435  const std::vector<MooseVariableScalar *> & vars = _vars[tid].scalars();
436  for (const auto & var : vars)
437  var->reinit(reinit_for_derivative_reordering);
438 }
439 
440 void
441 SystemBase::augmentSendList(std::vector<dof_id_type> & send_list)
442 {
443  std::set<dof_id_type> & ghosted_elems = _subproblem.ghostedElems();
444 
445  DofMap & dof_map = dofMap();
446 
447  std::vector<dof_id_type> dof_indices;
448 
449  System & sys = system();
450 
451  unsigned int sys_num = sys.number();
452 
453  unsigned int n_vars = sys.n_vars();
454 
455  for (const auto & elem_id : ghosted_elems)
456  {
457  Elem * elem = _mesh.elemPtr(elem_id);
458 
459  if (elem->active())
460  {
461  dof_map.dof_indices(elem, dof_indices);
462 
463  // Only need to ghost it if it's actually not on this processor
464  for (const auto & dof : dof_indices)
465  if (dof < dof_map.first_dof() || dof >= dof_map.end_dof())
466  send_list.push_back(dof);
467 
468  // Now add the DoFs from all of the nodes. This is necessary because of block
469  // restricted variables. A variable might not live _on_ this element but it
470  // might live on nodes connected to this element.
471  for (unsigned int n = 0; n < elem->n_nodes(); n++)
472  {
473  Node * node = elem->node_ptr(n);
474 
475  // Have to get each variable's dofs
476  for (unsigned int v = 0; v < n_vars; v++)
477  {
478  const Variable & var = sys.variable(v);
479  unsigned int var_num = var.number();
480  unsigned int n_comp = var.n_components();
481 
482  // See if this variable has any dofs at this node
483  if (node->n_dofs(sys_num, var_num) > 0)
484  {
485  // Loop over components of the variable
486  for (unsigned int c = 0; c < n_comp; c++)
487  send_list.push_back(node->dof_number(sys_num, var_num, c));
488  }
489  }
490  }
491  }
492  }
493 }
494 
498 void
500 {
501  const auto states =
502  _solution_states[static_cast<unsigned short>(Moose::SolutionIterationType::Time)].size();
503  if (states > 1)
504  {
505  _saved_solution_states.resize(states);
506  for (unsigned int i = 1; i <= states - 1; ++i)
507  if (!_saved_solution_states[i])
509  &addVector("save_solution_state_" + std::to_string(i), false, PARALLEL);
510 
511  for (unsigned int i = 1; i <= states - 1; ++i)
513  }
514 
516  _saved_dot_old = &addVector("save_solution_dot_old", false, PARALLEL);
518  _saved_dotdot_old = &addVector("save_solution_dotdot_old", false, PARALLEL);
519 
520  if (solutionUDotOld())
522 
523  if (solutionUDotDotOld())
525 }
526 
530 void
532 {
533  const auto states =
534  _solution_states[static_cast<unsigned short>(Moose::SolutionIterationType::Time)].size();
535  if (states > 1)
536  for (unsigned int i = 1; i <= states - 1; ++i)
537  if (_saved_solution_states[i])
538  {
540  removeVector("save_solution_state_" + std::to_string(i));
541  _saved_solution_states[i] = nullptr;
542  }
543 
545  {
547  removeVector("save_solution_dot_old");
548  _saved_dot_old = nullptr;
549  }
551  {
553  removeVector("save_solution_dotdot_old");
554  _saved_dotdot_old = nullptr;
555  }
556 }
557 
560 {
561  if (!_subproblem.matrixTagExists(tag))
562  mooseError("Cannot add tagged matrix with TagID ",
563  tag,
564  " in system '",
565  name(),
566  "' because the tag does not exist in the problem");
567 
568  if (hasMatrix(tag))
569  return getMatrix(tag);
570 
571  const auto matrix_name = _subproblem.matrixTagName(tag);
572  SparseMatrix<Number> & mat = system().add_matrix(matrix_name);
573  associateMatrixToTag(mat, tag);
574 
575  return mat;
576 }
577 
578 void
580 {
581  if (!_subproblem.matrixTagExists(tag_id))
582  mooseError("Cannot remove the matrix with TagID ",
583  tag_id,
584  "\nin system '",
585  name(),
586  "', because that tag does not exist in the problem");
587 
588  if (hasMatrix(tag_id))
589  {
590  const auto matrix_name = _subproblem.matrixTagName(tag_id);
591  system().remove_matrix(matrix_name);
592  _tagged_matrices[tag_id] = nullptr;
593  }
594 }
595 
597 SystemBase::addVector(const std::string & vector_name, const bool project, const ParallelType type)
598 {
599  if (hasVector(vector_name))
600  return getVector(vector_name);
601 
602  NumericVector<Number> & vec = system().add_vector(vector_name, project, type);
603  return vec;
604 }
605 
607 SystemBase::addVector(TagID tag, const bool project, const ParallelType type)
608 {
609  if (!_subproblem.vectorTagExists(tag))
610  mooseError("Cannot add tagged vector with TagID ",
611  tag,
612  " in system '",
613  name(),
614  "' because the tag does not exist in the problem");
615 
616  if (hasVector(tag))
617  {
618  auto & vec = getVector(tag);
619 
620  if (type != ParallelType::AUTOMATIC && vec.type() != type)
621  mooseError("Cannot add tagged vector '",
623  "', in system '",
624  name(),
625  "' because a vector with the same name was found with a different parallel type");
626 
627  return vec;
628  }
629 
630  const auto vector_name = _subproblem.vectorTagName(tag);
631  NumericVector<Number> & vec = system().add_vector(vector_name, project, type);
632  associateVectorToTag(vec, tag);
633 
634  return vec;
635 }
636 
637 void
639 {
640  if (!_subproblem.vectorTagExists(tag))
641  mooseError("Cannot close vector with TagID ",
642  tag,
643  " in system '",
644  name(),
645  "' because that tag does not exist in the problem");
646  else if (!hasVector(tag))
647  mooseError("Cannot close vector tag with name '",
649  "' in system '",
650  name(),
651  "' because there is no vector associated with that tag");
652 
653  getVector(tag).close();
654 }
655 
656 void
657 SystemBase::closeTaggedVectors(const std::set<TagID> & tags)
658 {
659  for (const auto tag : tags)
660  closeTaggedVector(tag);
661 }
662 
663 void
665 {
666  if (!_subproblem.vectorTagExists(tag))
667  mooseError("Cannot zero vector with TagID ",
668  tag,
669  " in system '",
670  name(),
671  "' because that tag does not exist in the problem");
672  else if (!hasVector(tag))
673  mooseError("Cannot zero vector tag with name '",
675  "' in system '",
676  name(),
677  "' because there is no vector associated with that tag");
678 
679  getVector(tag).zero();
680 }
681 
682 void
683 SystemBase::zeroTaggedVectors(const std::set<TagID> & tags)
684 {
685  for (const auto tag : tags)
686  zeroTaggedVector(tag);
687 }
688 
689 void
691 {
692  if (!_subproblem.vectorTagExists(tag_id))
693  mooseError("Cannot remove the vector with TagID ",
694  tag_id,
695  "\nin system '",
696  name(),
697  "', because that tag does not exist in the problem");
698 
699  if (hasVector(tag_id))
700  {
701  auto vector_name = _subproblem.vectorTagName(tag_id);
702  system().remove_vector(vector_name);
703  _tagged_vectors[tag_id] = nullptr;
704  }
705 }
706 
707 void
708 SystemBase::addVariable(const std::string & var_type,
709  const std::string & name,
710  InputParameters & parameters)
711 {
713 
714  auto components = parameters.get<unsigned int>("components");
715 
716  // Convert the std::vector parameter provided by the user into a std::set for use by libMesh's
717  // System::add_variable method
718  std::set<SubdomainID> blocks;
719  const auto & block_param = parameters.get<std::vector<SubdomainName>>("block");
720  for (const auto & subdomain_name : block_param)
721  {
722  SubdomainID blk_id = _mesh.getSubdomainID(subdomain_name);
723  blocks.insert(blk_id);
724  }
725 
726  auto fe_type = FEType(Utility::string_to_enum<Order>(parameters.get<MooseEnum>("order")),
727  Utility::string_to_enum<FEFamily>(parameters.get<MooseEnum>("family")));
728 
729  unsigned int var_num;
730 
731  if (var_type == "ArrayMooseVariable")
732  {
733  if (fe_type.family == NEDELEC_ONE || fe_type.family == LAGRANGE_VEC ||
734  fe_type.family == MONOMIAL_VEC || fe_type.family == RAVIART_THOMAS)
735  mooseError("Vector family type cannot be used in an array variable");
736 
737  // Build up the variable names
738  std::vector<std::string> var_names;
739  for (unsigned int i = 0; i < components; i++)
740  var_names.push_back(SubProblem::arrayVariableComponent(name, i));
741 
742  // The number returned by libMesh is the _last_ variable number... we want to hold onto the
743  // _first_
744  var_num = system().add_variables(var_names, fe_type, &blocks) - (components - 1);
745 
746  // Set as array variable
747  if (parameters.isParamSetByUser("array") && !parameters.get<bool>("array"))
748  mooseError("Variable '",
749  name,
750  "' is an array variable ('components' > 1) but 'array' is set to false.");
751  parameters.set<bool>("array") = true;
752  }
753  else
754  var_num = system().add_variable(name, fe_type, &blocks);
755 
756  parameters.set<unsigned int>("_var_num") = var_num;
757  parameters.set<SystemBase *>("_system_base") = this;
758 
759  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
760  {
761  parameters.set<THREAD_ID>("tid") = tid;
762  std::shared_ptr<MooseVariableBase> var =
763  _factory.create<MooseVariableBase>(var_type, name, parameters, tid);
764 
765  _vars[tid].add(name, var);
766 
767  if (auto fe_var = dynamic_cast<MooseVariableFieldBase *>(var.get()))
768  {
769  auto required_size = var_num + components;
770  if (required_size > _numbered_vars[tid].size())
771  _numbered_vars[tid].resize(required_size);
772  for (MooseIndex(components) component = 0; component < components; ++component)
773  _numbered_vars[tid][var_num + component] = fe_var;
774 
775  if (auto * const functor = dynamic_cast<Moose::FunctorBase<ADReal> *>(fe_var))
776  _subproblem.addFunctor(name, *functor, tid);
777  else if (auto * const functor = dynamic_cast<Moose::FunctorBase<ADRealVectorValue> *>(fe_var))
778  _subproblem.addFunctor(name, *functor, tid);
779  else if (auto * const functor = dynamic_cast<Moose::FunctorBase<RealEigenVector> *>(fe_var))
780  _subproblem.addFunctor(name, *functor, tid);
781  else
782  mooseError("This should be a functor");
783  }
784 
785  if (var->blockRestricted())
786  for (const SubdomainID & id : var->blockIDs())
787  for (MooseIndex(components) component = 0; component < components; ++component)
788  _var_map[var_num + component].insert(id);
789  else
790  for (MooseIndex(components) component = 0; component < components; ++component)
791  _var_map[var_num + component] = std::set<SubdomainID>();
792  }
793 
794  // getMaxVariableNumber is an API method used in Rattlesnake
795  if (var_num > _max_var_number)
796  _max_var_number = var_num;
797 }
798 
799 bool
800 SystemBase::hasVariable(const std::string & var_name) const
801 {
802  auto & names = getVariableNames();
803  if (system().has_variable(var_name))
804  return system().variable_type(var_name).family != SCALAR;
805  if (std::find(names.begin(), names.end(), var_name) != names.end())
806  // array variable
807  return true;
808  else
809  return false;
810 }
811 
812 bool
813 SystemBase::isArrayVariable(const std::string & var_name) const
814 {
815  auto & names = getVariableNames();
816  if (!system().has_variable(var_name) &&
817  std::find(names.begin(), names.end(), var_name) != names.end())
818  // array variable
819  return true;
820  else
821  return false;
822 }
823 
824 bool
825 SystemBase::hasScalarVariable(const std::string & var_name) const
826 {
827  if (system().has_variable(var_name))
828  return system().variable_type(var_name).family == SCALAR;
829  else
830  return false;
831 }
832 
833 bool
834 SystemBase::isScalarVariable(unsigned int var_num) const
835 {
836  return (system().variable(var_num).type().family == SCALAR);
837 }
838 
839 unsigned int
841 {
842  unsigned int n = nFieldVariables();
843  n += _vars[0].scalars().size();
844 
845  return n;
846 }
847 
848 unsigned int
850 {
851  unsigned int n = 0;
852  for (auto & var : _vars[0].fieldVariables())
853  n += var->count();
854 
855  return n;
856 }
857 
858 unsigned int
860 {
861  unsigned int n = 0;
862  for (auto & var : _vars[0].fieldVariables())
863  if (var->isFV())
864  n += var->count();
865 
866  return n;
867 }
868 
872 bool
873 SystemBase::hasVector(const std::string & name) const
874 {
875  return system().have_vector(name);
876 }
877 
882 SystemBase::getVector(const std::string & name)
883 {
884  return system().get_vector(name);
885 }
886 
887 const NumericVector<Number> &
888 SystemBase::getVector(const std::string & name) const
889 {
890  return system().get_vector(name);
891 }
892 
895 {
896  if (!hasVector(tag))
897  {
898  if (!_subproblem.vectorTagExists(tag))
899  mooseError("Cannot retreive vector with tag ", tag, " because that tag does not exist");
900  else
901  mooseError("Cannot retreive vector with tag ",
902  tag,
903  " in system '",
904  name(),
905  "'\nbecause a vector has not been associated with that tag.");
906  }
907 
908  return *_tagged_vectors[tag];
909 }
910 
911 const NumericVector<Number> &
913 {
914  if (!hasVector(tag))
915  {
916  if (!_subproblem.vectorTagExists(tag))
917  mooseError("Cannot retreive vector with tag ", tag, " because that tag does not exist");
918  else
919  mooseError("Cannot retreive vector with tag ",
920  tag,
921  " in system '",
922  name(),
923  "'\nbecause a vector has not been associated with that tag.");
924  }
925 
926  return *_tagged_vectors[tag];
927 }
928 
929 void
931 {
932  if (!_subproblem.vectorTagExists(tag))
933  mooseError("Cannot associate vector to tag ", tag, " because that tag does not exist");
934 
935  if (_tagged_vectors.size() < tag + 1)
936  _tagged_vectors.resize(tag + 1);
937 
938  _tagged_vectors[tag] = &vec;
939 }
940 
941 void
943 {
944  if (!_subproblem.vectorTagExists(tag))
945  mooseError("Cannot disassociate vector from tag ", tag, " because that tag does not exist");
946  if (hasVector(tag) && &getVector(tag) != &vec)
947  mooseError("You can not disassociate a vector from a tag which it was not associated to");
948 
950 }
951 
952 void
954 {
955  if (!_subproblem.vectorTagExists(tag))
956  mooseError("Cannot disassociate vector from tag ", tag, " because that tag does not exist");
957 
958  if (_tagged_vectors.size() < tag + 1)
959  _tagged_vectors.resize(tag + 1);
960  _tagged_vectors[tag] = nullptr;
961 }
962 
963 void
965 {
966  const auto tags = defaultVectorTags();
967  for (const auto tag : tags)
968  if (_subproblem.vectorTagExists(tag))
970 }
971 
974 {
975  if (!hasMatrix(tag))
976  {
977  if (!_subproblem.matrixTagExists(tag))
978  mooseError("Cannot retreive matrix with tag ", tag, " because that tag does not exist");
979  else
980  mooseError("Cannot retreive matrix with tag ",
981  tag,
982  " in system '",
983  name(),
984  "'\nbecause a matrix has not been associated with that tag.");
985  }
986 
987  return *_tagged_matrices[tag];
988 }
989 
990 const SparseMatrix<Number> &
992 {
993  if (!hasMatrix(tag))
994  {
995  if (!_subproblem.matrixTagExists(tag))
996  mooseError("Cannot retreive matrix with tag ", tag, " because that tag does not exist");
997  else
998  mooseError("Cannot retreive matrix with tag ",
999  tag,
1000  " in system '",
1001  name(),
1002  "'\nbecause a matrix has not been associated with that tag.");
1003  }
1004 
1005  return *_tagged_matrices[tag];
1006 }
1007 
1008 void
1009 SystemBase::closeTaggedMatrices(const std::set<TagID> & tags)
1010 {
1011  for (auto tag : tags)
1012  if (hasMatrix(tag))
1013  getMatrix(tag).close();
1014 }
1015 
1016 void
1017 SystemBase::flushTaggedMatrices(const std::set<TagID> & tags)
1018 {
1019  for (auto tag : tags)
1020  if (hasMatrix(tag))
1021  getMatrix(tag).flush();
1022 }
1023 
1024 void
1026 {
1027  if (!_subproblem.matrixTagExists(tag))
1028  mooseError("Cannot associate matrix to tag ", tag, " because that tag does not exist");
1029 
1030  if (_tagged_matrices.size() < tag + 1)
1031  _tagged_matrices.resize(tag + 1);
1032 
1033  _tagged_matrices[tag] = &matrix;
1034 }
1035 
1036 void
1038 {
1039  if (!_subproblem.matrixTagExists(tag))
1040  mooseError("Cannot disassociate matrix from tag ", tag, " because that tag does not exist");
1041  if (hasMatrix(tag) && &getMatrix(tag) != &matrix)
1042  mooseError("You can not disassociate a matrix from a tag which it was not associated to");
1043 
1045 }
1046 
1047 void
1049 {
1050  if (!_subproblem.matrixTagExists(tag))
1051  mooseError("Cannot disassociate matrix from tag ", tag, " because that tag does not exist");
1052 
1053  if (_tagged_matrices.size() < tag + 1)
1054  _tagged_matrices.resize(tag + 1);
1055  _tagged_matrices[tag] = nullptr;
1056 }
1057 
1058 void
1060 {
1061  const auto tags = defaultMatrixTags();
1062  for (const auto tag : tags)
1063  if (_subproblem.matrixTagExists(tag))
1065 }
1066 
1067 void
1069 {
1070  mooseAssert(_subproblem.matrixTagExists(tag),
1071  "Cannot active Matrix with matrix_tag : " << tag << "that does not exist");
1072 
1073  if (_matrix_tag_active_flags.size() < tag + 1)
1074  _matrix_tag_active_flags.resize(tag + 1);
1075 
1076  _matrix_tag_active_flags[tag] = true;
1077 }
1078 
1079 void
1081 {
1082  mooseAssert(_subproblem.matrixTagExists(tag),
1083  "Cannot deactivate Matrix with matrix_tag : " << tag << "that does not exist");
1084 
1085  if (_matrix_tag_active_flags.size() < tag + 1)
1086  _matrix_tag_active_flags.resize(tag + 1);
1087 
1088  _matrix_tag_active_flags[tag] = false;
1089 }
1090 
1091 void
1093 {
1094  auto num_matrix_tags = _subproblem.numMatrixTags();
1095 
1096  _matrix_tag_active_flags.resize(num_matrix_tags);
1097 
1098  for (decltype(num_matrix_tags) tag = 0; tag < num_matrix_tags; tag++)
1099  _matrix_tag_active_flags[tag] = false;
1100 }
1101 
1102 void
1104 {
1105  auto num_matrix_tags = _subproblem.numMatrixTags();
1106 
1107  _matrix_tag_active_flags.resize(num_matrix_tags);
1108 
1109  for (decltype(num_matrix_tags) tag = 0; tag < num_matrix_tags; tag++)
1110  if (hasMatrix(tag))
1111  _matrix_tag_active_flags[tag] = true;
1112  else
1113  _matrix_tag_active_flags[tag] = false;
1114 }
1115 
1116 bool
1118 {
1119  mooseAssert(_subproblem.matrixTagExists(tag), "Matrix tag " << tag << " does not exist");
1120 
1121  return tag < _matrix_tag_active_flags.size() && _matrix_tag_active_flags[tag];
1122 }
1123 
1124 unsigned int
1126 {
1127  return system().number();
1128 }
1129 
1130 DofMap &
1132 {
1133  return system().get_dof_map();
1134 }
1135 
1136 const DofMap &
1138 {
1139  return system().get_dof_map();
1140 }
1141 
1142 void
1143 SystemBase::addVariableToCopy(const std::string & dest_name,
1144  const std::string & source_name,
1145  const std::string & timestep)
1146 {
1147  _var_to_copy.push_back(VarCopyInfo(dest_name, source_name, timestep));
1148 }
1149 
1150 void
1151 SystemBase::copyVars(ExodusII_IO & io)
1152 {
1153  int n_steps = io.get_num_time_steps();
1154 
1155  bool did_copy = false;
1156  for (const auto & vci : _var_to_copy)
1157  {
1158  int timestep = -1;
1159 
1160  if (vci._timestep == "LATEST")
1161  // Use the last time step in the file from which to retrieve the solution
1162  timestep = n_steps;
1163  else
1164  {
1165  timestep = MooseUtils::convert<int>(vci._timestep);
1166  if (timestep > n_steps)
1167  mooseError("Invalid value passed as \"initial_from_file_timestep\". Expected \"LATEST\" or "
1168  "a valid integer between 1 and ",
1169  n_steps,
1170  " inclusive, received ",
1171  vci._timestep);
1172  }
1173 
1174  did_copy = true;
1175 
1176  if (hasVariable(vci._dest_name))
1177  {
1178  const auto & var = getVariable(0, vci._dest_name);
1179  if (var.isArray())
1180  {
1181  const auto & array_var = getFieldVariable<RealEigenVector>(0, vci._dest_name);
1182  for (MooseIndex(var.count()) i = 0; i < var.count(); ++i)
1183  {
1184  const auto exodus_var = _subproblem.arrayVariableComponent(vci._source_name, i);
1185  const auto system_var = array_var.componentName(i);
1186  if (var.isNodal())
1187  io.copy_nodal_solution(system(), exodus_var, system_var, timestep);
1188  else
1189  io.copy_elemental_solution(system(), exodus_var, system_var, timestep);
1190  }
1191  }
1192  else
1193  {
1194  if (var.isNodal())
1195  io.copy_nodal_solution(system(), vci._dest_name, vci._source_name, timestep);
1196  else
1197  io.copy_elemental_solution(system(), vci._dest_name, vci._source_name, timestep);
1198  }
1199  }
1200  else if (hasScalarVariable(vci._dest_name))
1201  io.copy_scalar_solution(system(), {vci._dest_name}, {vci._source_name}, timestep);
1202  else
1203  mooseError("Unrecognized variable ", vci._dest_name, " in variables to copy.");
1204  }
1205 
1206  if (did_copy)
1207  solution().close();
1208 }
1209 
1210 void
1211 SystemBase::update(const bool update_libmesh_system)
1212 {
1213  if (update_libmesh_system)
1214  system().update();
1215 }
1216 
1217 void
1219 {
1220  system().solve();
1221 }
1222 
1226 void
1228 {
1229  system().update();
1230 
1231  // Copying the solutions backward so the current solution will become the old, and the old will
1232  // become older. The same applies to the nonlinear iterates.
1233  for (const auto iteration_index : index_range(_solution_states))
1234  {
1235  const auto states = _solution_states[iteration_index].size();
1236  if (states > 1)
1237  for (unsigned int i = states - 1; i > 0; --i)
1238  solutionState(i, Moose::SolutionIterationType(iteration_index)) =
1239  solutionState(i - 1, Moose::SolutionIterationType(iteration_index));
1240  }
1241 
1242  if (solutionUDotOld())
1243  *solutionUDotOld() = *solutionUDot();
1244  if (solutionUDotDotOld())
1246  if (solutionPreviousNewton())
1248 }
1249 
1253 void
1255 {
1256  const auto states =
1257  _solution_states[static_cast<unsigned short>(Moose::SolutionIterationType::Time)].size();
1258  if (states > 1)
1259  for (unsigned int i = states - 1; i > 0; --i)
1260  solutionState(i) = solutionState(i - 1);
1261 
1262  if (solutionUDotOld())
1263  *solutionUDotOld() = *solutionUDot();
1264  if (solutionUDotDotOld())
1266  if (solutionPreviousNewton())
1268 }
1269 
1273 void
1275 {
1276  if (!hasSolutionState(1))
1277  mooseError("Cannot restore solutions without old solution");
1278 
1279  *(const_cast<NumericVector<Number> *&>(currentSolution())) = solutionOld();
1280  solution() = solutionOld();
1281  if (solutionUDotOld())
1282  *solutionUDot() = *solutionUDotOld();
1283  if (solutionUDotDotOld())
1285  if (solutionPreviousNewton())
1287  system().update();
1288 }
1289 
1290 void
1291 SystemBase::removeVector(const std::string & name)
1292 {
1293  system().remove_vector(name);
1294 }
1295 
1296 const std::string &
1298 {
1299  return system().name();
1300 }
1301 
1304 {
1307  else
1308  return nullptr;
1309 }
1310 
1311 const NumericVector<Number> *
1313 {
1316  else
1317  return nullptr;
1318 }
1319 
1320 void
1322 {
1323  // Default is the current solution
1324  unsigned int state = 0;
1325 
1326  // Add additional states as required by the variable states requested
1327  for (const auto & var : getVariables(/* tid = */ 0))
1328  state = std::max(state, var->oldestSolutionStateRequested());
1329  for (const auto & var : getScalarVariables(/* tid = */ 0))
1330  state = std::max(state, var->oldestSolutionStateRequested());
1331 
1333 
1335 }
1336 
1337 TagName
1339  const Moose::SolutionIterationType iteration_type) const
1340 {
1341  mooseAssert(state != 0, "Not an old state");
1342 
1343  if (iteration_type == Moose::SolutionIterationType::Time)
1344  {
1345  if (state == 1)
1346  return Moose::OLD_SOLUTION_TAG;
1347  else if (state == 2)
1349  }
1350  else if (iteration_type == Moose::SolutionIterationType::Nonlinear && state == 1)
1352 
1353  return "solution_state_" + std::to_string(state) + "_" + Moose::stringify(iteration_type);
1354 }
1355 
1356 const NumericVector<Number> &
1357 SystemBase::solutionState(const unsigned int state,
1358  const Moose::SolutionIterationType iteration_type) const
1359 {
1360  if (!hasSolutionState(state, iteration_type))
1361  mooseError("For iteration type '",
1362  Moose::stringify(iteration_type),
1363  "': solution state ",
1364  state,
1365  " was requested in ",
1366  name(),
1367  " but only up to state ",
1368  _solution_states[static_cast<unsigned short>(iteration_type)].size() - 1,
1369  " is available.");
1370 
1371  const auto & solution_states = _solution_states[static_cast<unsigned short>(iteration_type)];
1372 
1373  if (state == 0)
1374  mooseAssert(solution_states[0] == &solutionInternal(), "Inconsistent current solution");
1375  else
1376  mooseAssert(solution_states[state] ==
1377  &getVector(oldSolutionStateVectorName(state, iteration_type)),
1378  "Inconsistent solution state");
1379 
1380  return *solution_states[state];
1381 }
1382 
1384 SystemBase::solutionState(const unsigned int state,
1385  const Moose::SolutionIterationType iteration_type)
1386 {
1387  if (!hasSolutionState(state, iteration_type))
1388  needSolutionState(state, iteration_type);
1389  return *_solution_states[static_cast<unsigned short>(iteration_type)][state];
1390 }
1391 
1392 void
1393 SystemBase::needSolutionState(const unsigned int state,
1394  const Moose::SolutionIterationType iteration_type)
1395 {
1396  libmesh_parallel_only(this->comm());
1397 
1398  if (hasSolutionState(state, iteration_type))
1399  return;
1400 
1401  auto & solution_states = _solution_states[static_cast<unsigned short>(iteration_type)];
1402  solution_states.resize(state + 1);
1403 
1404  // The 0-th (current) solution state is owned by libMesh
1405  if (!solution_states[0])
1406  solution_states[0] = &solutionInternal();
1407  else
1408  mooseAssert(solution_states[0] == &solutionInternal(), "Inconsistent current solution");
1409 
1410  // We will manually add all states past current
1411  for (unsigned int i = 1; i <= state; ++i)
1412  if (!solution_states[i])
1413  {
1414  auto tag = _subproblem.addVectorTag(oldSolutionStateVectorName(i, iteration_type),
1416  solution_states[i] = &addVector(tag, true, GHOSTED);
1417  }
1418  else
1419  mooseAssert(solution_states[i] == &getVector(oldSolutionStateVectorName(i, iteration_type)),
1420  "Inconsistent solution state");
1421 }
1422 
1423 void
1424 SystemBase::applyScalingFactors(const std::vector<Real> & inverse_scaling_factors)
1425 {
1426  for (MooseIndex(_vars) thread = 0; thread < _vars.size(); ++thread)
1427  {
1428  auto & field_variables = _vars[thread].fieldVariables();
1429  for (MooseIndex(field_variables) i = 0, p = 0; i < field_variables.size(); ++i)
1430  {
1431  auto factors = field_variables[i]->arrayScalingFactor();
1432  for (unsigned int j = 0; j < field_variables[i]->count(); ++j, ++p)
1433  factors[j] /= inverse_scaling_factors[p];
1434 
1435  field_variables[i]->scalingFactor(factors);
1436  }
1437 
1438  auto offset = field_variables.size();
1439 
1440  auto & scalar_variables = _vars[thread].scalars();
1441  for (MooseIndex(scalar_variables) i = 0; i < scalar_variables.size(); ++i)
1442  scalar_variables[i]->scalingFactor(
1443  {1. / inverse_scaling_factors[offset + i] * scalar_variables[i]->scalingFactor()});
1444 
1445  if (thread == 0 && _verbose)
1446  {
1447  _console << "Automatic scaling factors:\n";
1448  auto original_flags = _console.flags();
1449  auto original_precision = _console.precision();
1450  _console.unsetf(std::ios_base::floatfield);
1451  _console.precision(6);
1452 
1453  for (const auto & field_variable : field_variables)
1454  {
1455  const auto & factors = field_variable->arrayScalingFactor();
1456  _console << " " << field_variable->name() << ":";
1457  for (const auto i : make_range(field_variable->count()))
1458  _console << " " << factors[i];
1459  _console << "\n";
1460  }
1461  for (const auto & scalar_variable : scalar_variables)
1462  _console << " " << scalar_variable->name() << ": " << scalar_variable->scalingFactor()
1463  << "\n";
1464  _console << "\n" << std::endl;
1465 
1466  // restore state
1467  _console.flags(original_flags);
1468  _console.precision(original_precision);
1469  }
1470  }
1471 }
1472 
1473 void
1475 {
1476  addVector("scaling_factors", /*project=*/false, libMesh::ParallelType::GHOSTED);
1478 }
1479 
1480 bool
1482 {
1484 }
1485 
1486 void
1488 {
1489  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
1490  _vars[tid].initialSetup();
1491 }
1492 
1493 void
1495 {
1496  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
1497  _vars[tid].timestepSetup();
1498 }
1499 
1500 void
1502 {
1503  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
1504  _vars[tid].customSetup(exec_type);
1505 }
1506 
1507 void
1509 {
1510  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
1511  _vars[tid].subdomainSetup();
1512 }
1513 
1514 void
1516 {
1517  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
1518  _vars[tid].residualSetup();
1519 }
1520 
1521 void
1523 {
1524  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
1525  _vars[tid].jacobianSetup();
1526 }
1527 
1528 void
1530 {
1531  for (auto & var_warehouse : _vars)
1532  var_warehouse.clearAllDofIndices();
1533 }
1534 
1535 void
1537 {
1538  _vars[tid].setActiveVariableCoupleableVectorTags(vtags);
1539 }
1540 
1541 void
1543  THREAD_ID tid)
1544 {
1545  _vars[tid].setActiveScalarVariableCoupleableVectorTags(vtags);
1546 }
1547 
1548 template MooseVariableFE<Real> & SystemBase::getFieldVariable<Real>(THREAD_ID tid,
1549  const std::string & var_name);
1550 
1552 SystemBase::getFieldVariable<RealVectorValue>(THREAD_ID tid, const std::string & var_name);
1553 
1555 SystemBase::getFieldVariable<RealEigenVector>(THREAD_ID tid, const std::string & var_name);
1556 
1557 template MooseVariableFE<Real> & SystemBase::getFieldVariable<Real>(THREAD_ID tid,
1558  unsigned int var_number);
1559 
1561 SystemBase::getFieldVariable<RealVectorValue>(THREAD_ID tid, unsigned int var_number);
1562 
1564 SystemBase::getFieldVariable<RealEigenVector>(THREAD_ID tid, unsigned int var_number);
1565 
1566 template MooseVariableField<Real> &
1567 SystemBase::getActualFieldVariable<Real>(THREAD_ID tid, const std::string & var_name);
1568 
1570 SystemBase::getActualFieldVariable<RealVectorValue>(THREAD_ID tid, const std::string & var_name);
1571 
1573 SystemBase::getActualFieldVariable<RealEigenVector>(THREAD_ID tid, const std::string & var_name);
1574 
1575 template MooseVariableField<Real> &
1576 SystemBase::getActualFieldVariable<Real>(THREAD_ID tid, unsigned int var_number);
1577 
1579 SystemBase::getActualFieldVariable<RealVectorValue>(THREAD_ID tid, unsigned int var_number);
1580 
1582 SystemBase::getActualFieldVariable<RealEigenVector>(THREAD_ID tid, unsigned int var_number);
1583 
1584 template MooseVariableFV<Real> & SystemBase::getFVVariable<Real>(THREAD_ID tid,
1585  const std::string & var_name);
std::string name(const ElemQuality q)
void zeroTaggedVector(const TagID tag)
Zero vector with the given tag.
Definition: SystemBase.C:664
virtual void update(bool update_libmesh_system=true)
Update the system (doing libMesh magic)
Definition: SystemBase.C:1211
virtual const std::set< SubdomainID > * getVariableBlocks(unsigned int var_number)
Get the block where a variable of this system is defined.
Definition: SystemBase.C:153
virtual void needSolutionState(const unsigned int state, Moose::SolutionIterationType iteration_type=Moose::SolutionIterationType::Time)
Registers that the solution state state is needed.
Definition: SystemBase.C:1393
virtual void reinitNode(const Node *node, THREAD_ID tid)
Reinit nodal assembly info.
Definition: SystemBase.C:387
const std::vector< MooseVariableFieldBase * > & getVariables(THREAD_ID tid)
Definition: SystemBase.h:732
void closeTaggedVector(const TagID tag)
Close vector with the given tag.
Definition: SystemBase.C:638
virtual const NumericVector< Number > *const & currentSolution() const =0
The solution vector that is currently being operated on.
std::vector< std::vector< MooseVariableFieldBase * > > _numbered_vars
Map variable number to its pointer.
Definition: SystemBase.h:976
ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems...
Definition: MooseMesh.C:1040
virtual NumericVector< Number > * solutionUDot()=0
Order
virtual void disassociateVectorFromTag(NumericVector< Number > &vec, TagID tag)
Disassociate a given vector from a given tag.
Definition: SystemBase.C:942
std::vector< dof_id_type > _var_all_dof_indices
Container for the dof indices of a given variable.
Definition: SystemBase.h:988
virtual NumericVector< Number > & solutionInternal() const =0
Internal getter for solution owned by libMesh.
virtual void reinitNeighborFace(const Elem *elem, unsigned int side, BoundaryID bnd_id, THREAD_ID tid)
Compute the values of the variables at all the current points.
Definition: SystemBase.C:360
unsigned int n_threads()
const std::vector< MooseVariableScalar * > & getScalarVariables(THREAD_ID tid)
Definition: SystemBase.h:737
void zeroTaggedVectors(const std::set< TagID > &tags)
Zero all vectors for given tags.
Definition: SystemBase.C:683
bool hasVector(const std::string &tag_name) const
Check if the named vector exists in the system.
Definition: SystemBase.C:873
void applyScalingFactors(const std::vector< Real > &inverse_scaling_factors)
Applies scaling factors to the system&#39;s variables.
Definition: SystemBase.C:1424
LAGRANGE_VEC
virtual void copyOldSolutions()
Shifts the solutions backwards in time.
Definition: SystemBase.C:1254
bool _solution_states_initialized
Whether or not the solution states have been initialized.
Definition: SystemBase.h:985
SCALAR
unsigned int TagID
Definition: MooseTypes.h:199
virtual Elem * elemPtr(const dof_id_type i)
Definition: MooseMesh.C:2863
NumericVector< Number > & solution()
Definition: SystemBase.h:176
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters &parameters)
Canonical method for adding a variable.
Definition: SystemBase.C:708
virtual void reinitElemFace(const Elem *elem, unsigned int side, BoundaryID bnd_id, THREAD_ID tid)
Reinit assembly info for a side of an element.
Definition: SystemBase.C:349
PARALLEL
virtual bool computingScalingJacobian() const =0
Getter for whether we&#39;re computing the scaling jacobian.
NumericVector< Number > & addVector(const std::string &vector_name, const bool project, const ParallelType type)
Adds a solution length vector to the system.
Definition: SystemBase.C:597
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
const TagName OLDER_SOLUTION_TAG
Definition: MooseTypes.C:29
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
std::vector< std::string > _vars_to_be_zeroed_on_residual
Definition: SystemBase.h:940
std::vector< SparseMatrix< Number > * > _tagged_matrices
Tagged matrices (pointer)
Definition: SystemBase.h:949
std::ios_base::fmtflags flags() const
Return the current flags.
Definition: ConsoleStream.C:58
virtual void initSolutionState()
Initializes the solution state.
Definition: SystemBase.C:1321
virtual void disassociateDefaultVectorTags()
Disassociate the vectors associated with the default vector tags of this system.
Definition: SystemBase.C:964
virtual void reinitElem(const Elem *elem, THREAD_ID tid)
Reinit an element assembly info.
Definition: SystemBase.C:329
virtual void reinitLowerD(THREAD_ID tid)
Compute the values of the variables on the lower dimensional element.
Definition: SystemBase.C:379
virtual TagID addVectorTag(const TagName &tag_name, const Moose::VectorTagType type=Moose::VECTOR_TAG_RESIDUAL)
Create a Tag.
Definition: SubProblem.C:81
virtual const std::set< MooseVariableFieldBase * > & getActiveElementalMooseVariables(const THREAD_ID tid) const
Get the MOOSE variables to be reinited on each element.
Definition: SubProblem.C:420
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
virtual void associateVectorToTag(NumericVector< Number > &vec, TagID tag)
Associate a vector for a given tag.
Definition: SystemBase.C:930
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters &parameters, THREAD_ID tid=0, bool print_deprecated=true)
Definition: Factory.C:110
virtual Order getMinQuadratureOrder()
Get minimal quadrature order needed for integrating variables in this system.
Definition: SystemBase.C:230
void addFunctor(const std::string &name, const Moose::FunctorBase< T > &functor, const THREAD_ID tid)
add a functor to the problem functor container
Definition: SubProblem.h:1289
virtual NumericVector< Number > & solutionState(const unsigned int state, Moose::SolutionIterationType iteration_type=Moose::SolutionIterationType::Time)
Get a state of the solution (0 = current, 1 = old, 2 = older, etc).
Definition: SystemBase.C:1384
MeshBase & mesh
Factory & _factory
Definition: SystemBase.h:927
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
bool computingScalingJacobian() const
Whether we are computing an initial Jacobian for automatic variable scaling.
Definition: SystemBase.C:1481
const Parallel::Communicator & comm() const
virtual NumericVector< Number > * solutionUDotDotOld()=0
virtual void addVariableToCopy(const std::string &dest_name, const std::string &source_name, const std::string &timestep)
Add info about variable that will be copied.
Definition: SystemBase.C:1143
virtual bool hasMatrix(TagID tag) const
Check if the tagged matrix exists in the system.
Definition: SystemBase.h:328
void removeMatrix(TagID tag)
Removes a matrix with a given tag.
Definition: SystemBase.C:579
This class provides an interface for common operations on field variables of both FE and FV types wit...
virtual void prepareFace(THREAD_ID tid, bool resize_data)
Prepare the system for use on sides.
Definition: SystemBase.C:268
void addScalingVector()
Add the scaling factor vector to the system.
Definition: SystemBase.C:1474
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
void setActiveVariableCoupleableVectorTags(const std::set< TagID > &vtags, THREAD_ID tid)
Set the active vector tags for the variables.
Definition: SystemBase.C:1536
Base class for a system (of equations)
Definition: SystemBase.h:84
virtual bool isArrayVariable(const std::string &var_name) const
If a variable is an array variable.
Definition: SystemBase.C:813
virtual void reinitNodes(const std::vector< dof_id_type > &nodes, THREAD_ID tid)
Reinit variables at a set of nodes.
Definition: SystemBase.C:411
virtual void reinitNodesNeighbor(const std::vector< dof_id_type > &nodes, THREAD_ID tid)
Reinit variables at a set of neighbor nodes.
Definition: SystemBase.C:422
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
MooseVariableFV< T > & getFVVariable(THREAD_ID tid, const std::string &var_name)
Return a finite volume variable.
Definition: SystemBase.C:114
const std::set< dof_id_type > & getDofIndices() const
virtual void zero()=0
auto max(const L &left, const R &right)
MONOMIAL_VEC
virtual unsigned int nVariables() const
Get the number of variables in this system.
Definition: SystemBase.C:840
void setActiveScalarVariableCoupleableVectorTags(const std::set< TagID > &vtags, THREAD_ID tid)
Set the active vector tags for the scalar variables.
Definition: SystemBase.C:1542
Grab all the (possibly semi)local dof indices for the variables passed in, in the system passed in...
virtual const std::string & name() const
Definition: SystemBase.C:1297
virtual void jacobianSetup()
Definition: SystemBase.C:1522
void unsetf(std::ios_base::fmtflags mask) const
Unset format flags.
Definition: ConsoleStream.C:40
void closeTaggedMatrices(const std::set< TagID > &tags)
Close all matrices associated the tags.
Definition: SystemBase.C:1009
virtual void deactiveAllMatrixTags()
Make matrices inactive.
Definition: SystemBase.C:1092
std::vector< VarCopyInfo > _var_to_copy
Definition: SystemBase.h:964
virtual void flush()
virtual DofMap & dofMap()
Gets writeable reference to the dof map.
Definition: SystemBase.C:1131
CONSTANT
int convert< int >(const std::string &str, bool throw_on_failure)
Definition: MooseUtils.C:999
unsigned int n_vars
const TagName OLD_SOLUTION_TAG
Definition: MooseTypes.C:28
virtual void zeroVariablesForResidual()
Zero out the solution for the variables that were registered as needing to have their solutions zeroe...
Definition: SystemBase.C:218
std::vector< bool > _matrix_tag_active_flags
Active flags for tagged matrices.
Definition: SystemBase.h:951
GHOSTED
std::vector< std::string > _vars_to_be_zeroed_on_jacobian
Definition: SystemBase.h:941
boundary_id_type BoundaryID
Information about variables that will be copied.
Definition: SystemBase.h:66
void hasScalingVector(const unsigned int nl_sys_num)
Tells this problem that the assembly associated with the given nonlinear system number involves a sca...
Definition: SubProblem.C:1115
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:627
virtual void prepareNeighbor(THREAD_ID tid)
Prepare the system for use.
Definition: SystemBase.C:313
An inteface for the _console for outputting to the Console object.
virtual void reinitScalars(THREAD_ID tid, bool reinit_for_derivative_reordering=false)
Reinit scalar varaibles.
Definition: SystemBase.C:433
virtual void associateMatrixToTag(SparseMatrix< Number > &matrix, TagID tag)
Associate a matrix to a tag.
Definition: SystemBase.C:1025
SubProblem & _subproblem
Definition: SystemBase.h:924
virtual void augmentSparsity(SparsityPattern::Graph &sparsity, std::vector< dof_id_type > &n_nz, std::vector< dof_id_type > &n_oz)=0
Will modify the sparsity pattern to add logical geometric connections.
virtual bool matrixTagActive(TagID tag) const
If or not a matrix tag is active.
Definition: SystemBase.C:1117
virtual bool checkNonlocalCouplingRequirement()
Definition: SubProblem.h:88
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
SparseMatrix< Number > & addMatrix(TagID tag)
Adds a matrix with a given tag.
Definition: SystemBase.C:559
virtual std::set< dof_id_type > & ghostedElems()
Return the list of elements that should have their DoFs ghosted to this processor.
Definition: SubProblem.h:627
NumericVector< Real > * _saved_dot_old
Definition: SystemBase.h:958
virtual bool vectorTagExists(const TagID tag_id) const
Check to see if a particular Tag exists.
Definition: SubProblem.h:163
virtual bool hasSolutionState(const unsigned int state, Moose::SolutionIterationType iteration_type=Moose::SolutionIterationType::Time) const
Whether or not the system has the solution state (0 = current, 1 = old, 2 = older, etc).
Definition: SystemBase.h:1004
virtual System & system()=0
Get the reference to the libMesh system.
virtual void activeAllMatrixTags()
Make all exsiting matrices ative.
Definition: SystemBase.C:1103
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1125
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:62
void copyVars(ExodusII_IO &io)
Definition: SystemBase.C:1151
void closeTaggedVectors(const std::set< TagID > &tags)
Close all vectors for given tags.
Definition: SystemBase.C:657
virtual void reinitNeighbor(const Elem *elem, THREAD_ID tid)
Compute the values of the variables at all the current points.
Definition: SystemBase.C:371
void extraSendList(std::vector< dof_id_type > &send_list, void *context)
Free function used for a libMesh callback.
Definition: SystemBase.C:34
std::streamsize precision() const
Return the current precision.
Definition: ConsoleStream.C:46
virtual bool hasVariable(const std::string &var_name) const
Query a system for a variable.
Definition: SystemBase.C:800
virtual void close()=0
std::map< unsigned int, std::set< SubdomainID > > _var_map
Map of variables (variable id -> array of subdomains where it lives)
Definition: SystemBase.h:936
virtual void copySolutionsBackwards()
Copy current solution into old and older.
Definition: SystemBase.C:1227
virtual std::set< TagID > defaultMatrixTags() const
Get the default matrix tags associted with this system.
Definition: SystemBase.h:287
virtual void disassociateMatrixFromTag(SparseMatrix< Number > &matrix, TagID tag)
Disassociate a matrix from a tag.
Definition: SystemBase.C:1037
virtual void solve()
Solve the system (using libMesh magic)
Definition: SystemBase.C:1218
virtual unsigned int numMatrixTags() const
The total number of tags.
Definition: SubProblem.h:210
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was by the user.
virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a scalar variable with specified number.
Definition: SystemBase.C:134
virtual void activeMatrixTag(TagID tag)
Active a matrix for tag.
Definition: SystemBase.C:1068
virtual void saveOldSolutions()
Save the old and older solutions.
Definition: SystemBase.C:499
static std::string arrayVariableComponent(const std::string &var_name, unsigned int i)
Returns the variable name of a component of an array variable.
Definition: SubProblem.h:261
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:934
virtual void close()=0
SystemBase(SubProblem &subproblem, const std::string &name, Moose::VarKindType var_kind)
Definition: SystemBase.C:51
RAVIART_THOMAS
virtual void subdomainSetup()
Definition: SystemBase.C:1508
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:75
bool _verbose
True if printing out additional information.
Definition: SystemBase.h:982
void removeVector(const std::string &name)
Remove a vector from the system with the given name.
Definition: SystemBase.C:1291
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
unsigned int nFVVariables() const
Get the number of finite volume variables in this system.
Definition: SystemBase.C:859
MooseMesh & _mesh
Definition: SystemBase.h:929
virtual void addVariableToZeroOnResidual(std::string var_name)
Adds this variable to the list of variables to be zeroed during each residual evaluation.
Definition: SystemBase.C:163
MooseVariableFE< T > & getFieldVariable(THREAD_ID tid, const std::string &var_name)
Gets a reference to a variable of with specified name.
Definition: SystemBase.C:100
void prepareVariableNonlocal(MooseVariableFieldBase *var)
Definition: Assembly.C:2768
virtual SparseMatrix< Number > & getMatrix(TagID tag)
Get a raw SparseMatrix.
Definition: SystemBase.C:973
virtual void reinitNodeFace(const Node *node, BoundaryID bnd_id, THREAD_ID tid)
Reinit nodal assembly info on a face.
Definition: SystemBase.C:399
virtual void zeroVariablesForJacobian()
Zero out the solution for the variables that were registered as needing to have their solutions zeroe...
Definition: SystemBase.C:224
virtual std::set< TagID > defaultVectorTags() const
Get the default vector tags associated with this system.
Definition: SystemBase.h:280
TagName oldSolutionStateVectorName(const unsigned int, Moose::SolutionIterationType iteration_type) const
Gets the vector name used for an old (not current) solution state.
Definition: SystemBase.C:1338
std::array< std::vector< NumericVector< Number > * >, 2 > _solution_states
The solution states (0 = current, 1 = old, 2 = older, etc)
Definition: SystemBase.h:998
Class for scalar variables (they are different).
IntRange< T > make_range(T beg, T end)
NumericVector< Real > * _saved_dotdot_old
Definition: SystemBase.h:959
const std::vector< VariableName > & getVariableNames() const
Definition: SystemBase.h:843
virtual void prepare(THREAD_ID tid)
Prepare the system for use.
Definition: SystemBase.C:245
virtual void addVariableToZeroOnJacobian(std::string var_name)
Adds this variable to the list of variables to be zeroed during each Jacobian evaluation.
Definition: SystemBase.C:169
virtual const NumericVector< Number > * solutionPreviousNewton() const
Definition: SystemBase.C:1312
virtual void customSetup(const ExecFlagType &exec_type)
Definition: SystemBase.C:1501
void prepareVariable(MooseVariableFieldBase *var)
Used for preparing the dense residual and jacobian blocks for one particular variable.
Definition: Assembly.C:2740
virtual NumericVector< Number > * solutionUDotOld()=0
virtual NumericVector< Number > * solutionUDotDot()=0
virtual bool isScalarVariable(unsigned int var_name) const
Definition: SystemBase.C:834
unsigned int nFieldVariables() const
Get the number of field variables in this system.
Definition: SystemBase.C:849
virtual void set(const numeric_index_type i, const Number value)=0
virtual TagName vectorTagName(const TagID tag) const
Retrieve the name associated with a TagID.
Definition: SubProblem.C:198
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
virtual bool hasActiveElementalMooseVariables(const THREAD_ID tid) const
Whether or not a list of active elemental moose variables has been set.
Definition: SubProblem.C:426
virtual void prepareLowerD(THREAD_ID tid)
Prepare the system for use for lower dimensional elements.
Definition: SystemBase.C:321
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
Definition: SystemBase.C:79
NEDELEC_ONE
virtual void deactiveMatrixTag(TagID tag)
deactive a matrix for tag
Definition: SystemBase.C:1080
void setVariableGlobalDoFs(const std::string &var_name)
set all the global dof indices for a variable
Definition: SystemBase.C:175
std::vector< NumericVector< Number > * > _tagged_vectors
Tagged vectors (pointer)
Definition: SystemBase.h:947
NumericVector< Number > & solutionOld()
Definition: SystemBase.h:177
virtual bool hasScalarVariable(const std::string &var_name) const
Definition: SystemBase.C:825
const TagName PREVIOUS_NL_SOLUTION_TAG
Definition: MooseTypes.C:30
virtual void augmentSendList(std::vector< dof_id_type > &send_list)
Will modify the send_list to add all of the extra ghosted dofs for this system.
Definition: SystemBase.C:441
virtual void initialSetup()
Setup Functions.
Definition: SystemBase.C:1487
virtual Assembly & assembly(const THREAD_ID tid, const unsigned int nl_sys_num)=0
virtual void restoreSolutions()
Restore current solutions (call after your solve failed)
Definition: SystemBase.C:1274
virtual NumericVector< Number > & getVector(const std::string &name)
Get a raw NumericVector by name.
Definition: SystemBase.C:882
void extraSparsity(SparsityPattern::Graph &sparsity, std::vector< dof_id_type > &n_nz, std::vector< dof_id_type > &n_oz, void *context)
Free function used for a libMesh callback.
Definition: SystemBase.C:42
virtual void residualSetup()
Definition: SystemBase.C:1515
std::vector< NumericVector< Number > * > _saved_solution_states
The saved solution states (0 = current, 1 = old, 2 = older, etc)
Definition: SystemBase.h:1000
virtual void disassociateDefaultMatrixTags()
Disassociate the matrices associated with the default matrix tags of this system. ...
Definition: SystemBase.C:1059
void clearAllDofIndices()
Clear all dof indices from moose variables.
Definition: SystemBase.C:1529
unsigned int _max_var_number
Maximum variable number.
Definition: SystemBase.h:938
virtual void zeroVariables(std::vector< std::string > &vars_to_be_zeroed)
Zero out the solution for the list of variables passed in.
Definition: SystemBase.C:189
virtual void restoreOldSolutions()
Restore the old and older solutions when the saved solutions present.
Definition: SystemBase.C:531
auto index_range(const T &sizable)
void flushTaggedMatrices(const std::set< TagID > &tags)
flushes all matrices associated to tags.
Definition: SystemBase.C:1017
virtual bool matrixTagExists(const TagName &tag_name) const
Check to see if a particular Tag exists.
Definition: SubProblem.C:294
SolutionIterationType
Definition: MooseTypes.h:229
virtual TagName matrixTagName(TagID tag)
Retrieve the name associated with a TagID.
Definition: SubProblem.C:323
unsigned int THREAD_ID
Definition: MooseTypes.h:198
SubdomainID getSubdomainID(const SubdomainName &subdomain_name) const
Get the associated subdomain ID for the subdomain name.
Definition: MooseMesh.C:1513
ParallelType
virtual void timestepSetup()
Definition: SystemBase.C:1494
MooseVariableField< T > & getActualFieldVariable(THREAD_ID tid, const std::string &var_name)
Returns a field variable pointer - this includes finite volume variables.
Definition: SystemBase.C:107