version 3.11-dev
Loading...
Searching...
No Matches
mass/1p/felocalresidual.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
15#ifndef DUMUX_NAVIERSTOKES_MASS_ONEP_FE_LOCAL_RESIDUAL_HH
16#define DUMUX_NAVIERSTOKES_MASS_ONEP_FE_LOCAL_RESIDUAL_HH
17
18#include <vector>
19
22#include <dumux/common/typetraits/localdofs_.hh>
25
26namespace Dumux {
27
32template<class TypeTag>
35{
37
39 using GridVariablesCache = typename GridVariables::GridVariablesCache;
40 using ElementVariables = typename GridVariablesCache::LocalView;
41
45 using ElementDiscretization = typename GridGeometry::LocalView;
46 using GridView = typename GridGeometry::GridView;
47 using Element = typename GridView::template Codim<0>::Entity;
50 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
51
52public:
53 using ElementResidualVector = typename ParentType::ElementResidualVector;
54 using ParentType::ParentType;
55
66 const Problem& problem,
67 const Element& element,
68 const ElementDiscretization& elemDisc,
69 const ElementVariables& elemVars,
70 bool isPreviousTimeLevel) const
71 {
72 if constexpr (Detail::LocalDofs::hasNonCVLocalDofsInterface<ElementDiscretization>())
73 {
74 if (nonCVLocalDofs(elemDisc).empty())
75 return;
76
77 // mass lumping, so only the integrals of the basis functions are needed
78 std::vector<Scalar> integralShapeFunctions(Detail::LocalDofs::numLocalDofs(elemDisc), 0.0);
79 for (const auto& qpData : CVFE::quadratureRule(elemDisc, element))
80 {
81 const auto& shapeValues = cache(elemVars, qpData.ipData()).shapeValues();
82 for (const auto& localDof : nonCVLocalDofs(elemDisc))
83 integralShapeFunctions[localDof.index()] += qpData.weight()*shapeValues[localDof.index()][0];
84 }
85
86 for (const auto& localDof : nonCVLocalDofs(elemDisc))
87 {
88 const auto localDofIdx = localDof.index();
89 storage[localDofIdx][Indices::conti0EqIdx]
90 += integralShapeFunctions[localDofIdx]*elemVars[localDofIdx].density();
91 }
92 }
93 }
94
106 const Problem& problem,
107 const Element& element,
108 const ElementDiscretization& elemDisc,
109 const ElementVariables& elemVars) const
110 {
111 if constexpr (Detail::LocalDofs::hasNonCVLocalDofsInterface<ElementDiscretization>())
112 {
113 if (nonCVLocalDofs(elemDisc).empty())
114 return;
115
116 for (const auto& qpData : CVFE::quadratureRule(elemDisc, element))
117 {
118 const auto& ipData = qpData.ipData();
119 const auto& ipCache = cache(elemVars, ipData);
120 const auto& shapeValues = ipCache.shapeValues();
121
122 const Scalar divV = problem.velocityDivergence(elemDisc, ipData);
123
124 Scalar density = 0.0;
125 GlobalPosition gradDensity(0.0);
126 for (const auto& localDof : localDofs(elemDisc))
127 {
128 const auto localDensity = elemVars[localDof.index()].density();
129 density += localDensity*shapeValues[localDof.index()][0];
130 gradDensity.axpy(localDensity, ipCache.gradN(localDof.index()));
131 }
132
133 const auto velocity = problem.velocity(elemDisc, ipData);
134 const auto source = problem.source(elemDisc, elemVars, ipData);
135 const Scalar divMassFlux = density*divV + (velocity*gradDensity);
136
137 for (const auto& localDof : nonCVLocalDofs(elemDisc))
138 {
139 const auto localDofIdx = localDof.index();
140 residual[localDofIdx][Indices::conti0EqIdx]
141 += qpData.weight() * shapeValues[localDofIdx]
142 * (divMassFlux - source[Indices::conti0EqIdx]);
143 }
144 }
145 }
146 }
147};
148
149} // end namespace Dumux
150
151#endif
Element-wise FE continuity residual for the one-phase mass subdomain.
Definition mass/1p/felocalresidual.hh:35
typename ParentType::ElementResidualVector ElementResidualVector
Definition mass/1p/felocalresidual.hh:53
void addToElementFluxAndSourceResidual(ElementResidualVector &residual, const Problem &problem, const Element &element, const ElementDiscretization &elemDisc, const ElementVariables &elemVars) const
Adds the continuity residual.
Definition mass/1p/felocalresidual.hh:105
void addToElementStorage(ElementResidualVector &storage, const Problem &problem, const Element &element, const ElementDiscretization &elemDisc, const ElementVariables &elemVars, bool isPreviousTimeLevel) const
Adds the storage at one time level.
Definition mass/1p/felocalresidual.hh:65
Defines all properties used in Dumux.
The default local operator than can be specialized for each discretization scheme.
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition propertysystem.hh:296
auto quadratureRule(const FVElementGeometry &fvGeometry, const typename FVElementGeometry::SubControlVolume &scv, QuadratureRules::MidpointQuadrature)
Midpoint quadrature for scv.
Definition quadraturerules.hh:159
Definition adapt.hh:17
typename Detail::DiscretizationDefaultLocalOperator< TypeTag >::type DiscretizationDefaultLocalOperator
Definition defaultlocaloperator.hh:26
auto localDofs(const FVElementGeometry &fvGeometry)
range over local dofs
Definition localdof.hh:50
A helper to deduce a vector with the same size as numbers of equations.
Quadrature rules over sub-control volumes and sub-control volume faces.