https://mooseframework.inl.gov
MooseVariableField.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "MooseVariableField.h"
11 #include "SystemBase.h"
12 #include "TimeIntegrator.h"
13 
14 #include "libmesh/fe_base.h"
15 
16 using namespace Moose;
17 
18 template <typename OutputType>
21 {
23 }
24 
25 template <typename OutputType>
27  : MooseVariableFieldBase(parameters),
28  Moose::FunctorBase<typename Moose::ADType<OutputType>::type>(name()),
29  MeshChangedInterface(parameters),
30  _time_integrator(_sys.queryTimeIntegrator(_var_num))
31 {
32 }
33 
34 template <typename OutputType>
35 void
37 {
40 }
41 
42 template <typename OutputType>
43 void
45 {
48 }
49 
50 template <typename OutputType>
51 void
53 {
56 }
57 
58 template <typename OutputType>
61 {
62  // It's not safe to use solutionState(0) because it returns the libMesh System solution member
63  // which is wrong during things like finite difference Jacobian evaluation, e.g. when PETSc
64  // perturbs the solution vector we feed these perturbations into the current_local_solution
65  // while the libMesh solution is frozen in the non-perturbed state
66  return (state.state == 0) ? *this->_sys.currentSolution()
67  : this->_sys.solutionState(state.state, state.iteration_type);
68 }
69 
70 template <typename OutputType>
73 {
74  if (std::is_same<OutputType, Real>::value)
76  else if (std::is_same<OutputType, RealVectorValue>::value)
78  else if (std::is_same<OutputType, RealEigenVector>::value)
80  else
81  mooseError("Unknown variable field type");
82 }
83 
84 template <typename OutputType>
85 bool
87 {
88  const auto is_array = MooseVariableBase::isArray();
89  if (std::is_same<OutputType, RealEigenVector>::value != is_array)
90  mooseError("A variable is marked as an array variable in a base class, but in a derived class "
91  "the output type is not consistent.");
92  return is_array;
93 }
94 
95 template <typename OutputType>
96 bool
98 {
99  return std::is_same<OutputType, RealVectorValue>::value;
100 }
101 
102 template <>
103 template <>
104 const MooseArray<Real> &
106 {
107  return dofValues();
108 }
109 
110 template <>
111 template <>
112 const MooseArray<Real> &
114 {
115  return dofValues();
116 }
117 
118 template <>
119 template <>
120 const MooseArray<Real> &
122 {
123  mooseError("genericDofValues not implemented for array variables");
124 }
125 
126 template class MooseVariableField<Real>;
std::string name(const ElemQuality q)
MooseVariableField(const InputParameters &parameters)
VarFieldType
Definition: MooseTypes.h:721
static InputParameters validParams()
Base class template for functor objects.
Definition: MooseFunctor.h:137
Class for stuff related to variables.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
This class provides an interface for common operations on field variables of both FE and FV types wit...
virtual void jacobianSetup() override
const libMesh::NumericVector< libMesh::Number > & getSolution(const Moose::StateArg &state) const
Get the solution corresponding to the provided state.
static InputParameters validParams()
virtual Moose::VarFieldType fieldType() const override
Field type of this variable.
Interface for notifications that the mesh has changed.
virtual void timestepSetup()
Gets called at the beginning of the timestep before this object is asked to do its job...
SolutionIterationType iteration_type
The solution iteration type, e.g. time or nonlinear.
virtual bool isArray() const
virtual bool isVector() const override
State argument for evaluating functors.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
virtual void timestepSetup() override
virtual void jacobianSetup()
Gets called just before the Jacobian is computed and before this object is asked to do its job...
virtual void residualSetup()
Gets called just before the residual is computed and before this object is asked to do its job...
unsigned int state
The state.
virtual void residualSetup() override
virtual bool isArray() const override