https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MooseVariableDataLinearFV.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
11#include "MooseVariableDataFV.h"
12#include "MooseVariableField.h"
13#include "Assembly.h"
14#include "MooseError.h"
15#include "DisplacedSystem.h"
16#include "TimeIntegrator.h"
17#include "MooseVariableFV.h"
18#include "MooseTypes.h"
19#include "MooseMesh.h"
20#include "Attributes.h"
21#include "FVDirichletBCBase.h"
22#include "SubProblem.h"
23#include "FVKernel.h"
24#include "ADUtils.h"
26
27#include "libmesh/quadrature.h"
28#include "libmesh/fe_base.h"
29#include "libmesh/system.h"
30#include "libmesh/type_n_tensor.h"
31
32template <typename OutputType>
35 SystemBase & sys,
36 THREAD_ID tid,
37 Moose::ElementType element_type,
38 const Elem * const & elem)
39 : MooseVariableDataBase<OutputType>(var, sys, tid),
40 _var(var),
41 _fe_type(_var.feType()),
42 _var_num(_var.number()),
43 _assembly(_subproblem.assembly(_tid, var.kind() == Moose::VAR_SOLVER ? sys.number() : 0)),
44 _element_type(element_type),
45 _time_integrator(_sys.queryTimeIntegrator(_var_num)),
46 _elem(elem),
47 _displaced(dynamic_cast<const DisplacedSystem *>(&_sys) ? true : false),
48 _qrule(nullptr)
49{
50}
51
52template <typename OutputType>
53void
55{
56 switch (gm_type)
57 {
58 case Moose::Volume:
59 {
60 _qrule = _assembly.qRule();
61 // TODO: set integration multiplier to cell volume
62 break;
63 }
64 case Moose::Face:
65 {
66 _qrule = _assembly.qRuleFace();
67 // TODO: set integration multiplier to face area
68 break;
69 }
70 }
71}
72
73template <typename OutputType>
74void
76{
77 auto && active_coupleable_matrix_tags =
78 _sys.subproblem().getActiveFEVariableCoupleableMatrixTags(_tid);
79 mooseAssert(_qrule, "We should have a non-null qrule");
80 const auto nqp = _qrule->n_points();
81
82 for (auto tag : _required_vector_tags)
83 if (_need_vector_tag_u[tag])
84 {
85 _vector_tag_u[tag].resize(nqp);
86 assignForAllQps(0, _vector_tag_u[tag], nqp);
87 }
88
89 for (auto tag : active_coupleable_matrix_tags)
90 if (_need_matrix_tag_u[tag])
91 {
92 _matrix_tag_u[tag].resize(nqp);
93 assignForAllQps(0, _matrix_tag_u[tag], nqp);
94 }
95}
96
97template <typename OutputType>
98const std::vector<dof_id_type> &
100{
101 // We might not have a valid element, so we don't use the element to get the dof
102 Moose::initDofIndices(*this, *_elem);
103 return _dof_indices;
104}
105
106template <typename OutputType>
107void
109{
110 getDofIndices(_elem, _dof_indices);
111 initializeSolnVars();
112
113 unsigned int num_dofs = _dof_indices.size();
114
115 if (num_dofs > 0)
116 fetchDofValues();
117 else
118 // We don't have any dofs. There's nothing to do
119 return;
120
121 mooseAssert(num_dofs == 1 && _vector_tags_dof_u[_solution_tag].size() == 1,
122 "There should only be one dof per elem for FV variables");
123
124 const auto nqp = _qrule->n_points();
125 auto && active_coupleable_matrix_tags =
126 _sys.subproblem().getActiveFEVariableCoupleableMatrixTags(_tid);
127
128 for (const auto qp : make_range(nqp))
129 {
130 for (auto tag : _required_vector_tags)
131 if (_need_vector_tag_u[tag])
132 _vector_tag_u[tag][qp] = _vector_tags_dof_u[tag][0];
133
134 for (auto tag : active_coupleable_matrix_tags)
135 if (_need_matrix_tag_u[tag])
136 _matrix_tag_u[tag][qp] = _matrix_tags_dof_u[tag][0];
137 }
138}
139
140template <typename OutputType>
141void
143{
144 initDofIndices();
145 _vector_tags_dof_u[_solution_tag].resize(_dof_indices.size());
146}
147
148template <typename OutputType>
149void
151{
152 mooseAssert(index == 0, "We only ever have one dof value locally");
153 _vector_tags_dof_u[_solution_tag][index] = value;
154 _has_dof_values = true;
155
156 auto & u = _vector_tag_u[_solution_tag];
157 // Update the qp values as well
158 for (const auto qp : index_range(u))
159 u[qp] = value;
160}
161
162template <typename OutputType>
163void
165{
166 auto & dof_values = _vector_tags_dof_u[_solution_tag];
167 for (unsigned int i = 0; i < values.size(); i++)
168 dof_values[i] = values(i);
169 _has_dof_values = true;
170}
171
172template <typename OutputType>
173void
175 std::vector<dof_id_type> & dof_indices) const
176{
177 // Avoid calling the dof map routine (for performance)
178 const auto n_dofs = elem->n_dofs(_sys.number(), _var_num);
179 if (n_dofs)
180 {
181 mooseAssert(n_dofs == 1, "Should be just one dof");
182 dof_indices.resize(1);
183 dof_indices[0] = elem->dof_number(_sys.number(), _var_num, 0);
184 }
185 else
186 dof_indices.clear();
187}
188
189template <typename OutputType>
192{
193 return _var;
194}
195
197// TODO: implement vector fv variable support. This will require some template
198// specializations for various member functions in this and the FV variable
199// classes. And then you will need to uncomment out the line below:
200// template class MooseVariableDataLinearFV<RealVectorValue>;
unsigned int THREAD_ID
Definition MooseTypes.h:237
std::array< Real, 2 > values
Definition MortarUtils.C:52
This class provides variable solution interface for linear finite volume problems.
Moose::DOFType< OutputType >::type DofValue
Class holding the data members for linear finite volume variables.
void setGeometry(Moose::GeometryType gm_type)
Set the geometry type before calculating variables values.
void prepareIC()
Prepare the initial condition: initialize DOF indices and resize the DOF value array.
virtual const MooseLinearVariableFV< OutputType > & var() const override
Get the corresponding variable.
void setDofValues(const DenseVector< DofValue > &values)
Set local DOF values to the entries of values .
MooseVariableDataLinearFV(const MooseLinearVariableFV< OutputType > &var, SystemBase &sys, THREAD_ID tid, Moose::ElementType element_type, const Elem *const &elem)
void getDofIndices(const Elem *elem, std::vector< dof_id_type > &dof_indices) const
Get the dof indices for an element.
void setDofValue(const DofValue &value, unsigned int index)
Set local DOF value at index to value .
void computeValues()
Compute the variable values.
const std::vector< dof_id_type > & initDofIndices()
Fetch and return the dof indices of this variable on the current element.
Base class for a system (of equations)
Definition SystemBase.h:87
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
void initDofIndices(T &data, const Elem &elem)