version 3.8
pointsourcedata.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-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
13#ifndef DUMUX_MULTIDOMAIN_EMBEDDED_POINTSOURCEDATA_HH
14#define DUMUX_MULTIDOMAIN_EMBEDDED_POINTSOURCEDATA_HH
15
16#include <vector>
17#include <dune/common/fvector.hh>
21
22namespace Dumux {
23
29template<class MDTraits>
31{
32 using Scalar = typename MDTraits::Scalar;
33 using ShapeValues = typename std::vector<Dune::FieldVector<Scalar, 1> >;
34
35 template<std::size_t id> using SubDomainTypeTag = typename MDTraits::template SubDomain<id>::TypeTag;
36 template<std::size_t id> using GridGeometry = GetPropType<SubDomainTypeTag<id>, Properties::GridGeometry>;
37 template<std::size_t id> using GridView = typename GridGeometry<id>::GridView;
38 template<std::size_t id> using GridIndex = typename IndexTraits<GridView<id>>::GridIndex;
39 template<std::size_t id> using SolutionVector = GetPropType<SubDomainTypeTag<id>, Properties::SolutionVector>;
40 template<std::size_t id> using PrimaryVariables = GetPropType<SubDomainTypeTag<id>, Properties::PrimaryVariables>;
41
42 static constexpr auto bulkIdx = typename MDTraits::template SubDomain<0>::Index();
43 static constexpr auto lowDimIdx = typename MDTraits::template SubDomain<1>::Index();
44
45 template<std::size_t id>
46 static constexpr bool isBox()
47 { return GridGeometry<id>::discMethod == DiscretizationMethods::box; }
48
49public:
50 void addBulkInterpolation(const ShapeValues& shapeValues,
51 const std::vector<GridIndex<bulkIdx>>& cornerIndices,
52 GridIndex<bulkIdx> eIdx)
53 {
54 static_assert(isBox<bulkIdx>(), "This interface is only available for the box method.");
55 bulkElementIdx_ = eIdx;
56 bulkCornerIndices_ = cornerIndices;
57 bulkShapeValues_ = shapeValues;
58 }
59
60 void addLowDimInterpolation(const ShapeValues& shapeValues,
61 const std::vector<GridIndex<lowDimIdx>>& cornerIndices,
62 GridIndex<lowDimIdx> eIdx)
63 {
64 static_assert(isBox<lowDimIdx>(), "This interface is only available for the box method.");
65 lowDimElementIdx_ = eIdx;
66 lowDimCornerIndices_ = cornerIndices;
67 lowDimShapeValues_ = shapeValues;
68 }
69
70 void addBulkInterpolation(GridIndex<bulkIdx> eIdx)
71 {
72 static_assert(!isBox<bulkIdx>(), "This interface is not available for the box method.");
73 bulkElementIdx_ = eIdx;
74 }
75
76 void addLowDimInterpolation(GridIndex<lowDimIdx> eIdx)
77 {
78 static_assert(!isBox<lowDimIdx>(), "This interface is not available for the box method.");
79 lowDimElementIdx_ = eIdx;
80 }
81
82 PrimaryVariables<bulkIdx> interpolateBulk(const SolutionVector<bulkIdx>& sol) const
83 {
84 PrimaryVariables<bulkIdx> bulkPriVars(0.0);
85 if (isBox<bulkIdx>())
86 {
87 for (int i = 0; i < bulkCornerIndices_.size(); ++i)
88 for (int priVarIdx = 0; priVarIdx < bulkPriVars.size(); ++priVarIdx)
89 bulkPriVars[priVarIdx] += sol[bulkCornerIndices_[i]][priVarIdx]*bulkShapeValues_[i];
90 }
91 else
92 {
93 bulkPriVars = sol[bulkElementIdx()];
94 }
95 return bulkPriVars;
96 }
97
98 PrimaryVariables<lowDimIdx> interpolateLowDim(const SolutionVector<lowDimIdx>& sol) const
99 {
100 PrimaryVariables<lowDimIdx> lowDimPriVars(0.0);
101 if (isBox<lowDimIdx>())
102 {
103 for (int i = 0; i < lowDimCornerIndices_.size(); ++i)
104 for (int priVarIdx = 0; priVarIdx < lowDimPriVars.size(); ++priVarIdx)
105 lowDimPriVars[priVarIdx] += sol[lowDimCornerIndices_[i]][priVarIdx]*lowDimShapeValues_[i];
106 }
107 else
108 {
109 lowDimPriVars = sol[lowDimElementIdx()];
110 }
111 return lowDimPriVars;
112 }
113
114 GridIndex<lowDimIdx> lowDimElementIdx() const
115 { return lowDimElementIdx_; }
116
117 GridIndex<bulkIdx> bulkElementIdx() const
118 { return bulkElementIdx_; }
119
120private:
121 ShapeValues bulkShapeValues_, lowDimShapeValues_;
122 std::vector<GridIndex<bulkIdx>> bulkCornerIndices_;
123 std::vector<GridIndex<lowDimIdx>> lowDimCornerIndices_;
124 GridIndex<bulkIdx> bulkElementIdx_;
125 GridIndex<lowDimIdx> lowDimElementIdx_;
126};
127
137template<class MDTraits>
139{
141 using Scalar = typename MDTraits::Scalar;
142 using ShapeValues = typename std::vector<Dune::FieldVector<Scalar, 1> >;
143
144 template<std::size_t id> using SubDomainTypeTag = typename MDTraits::template SubDomain<id>::TypeTag;
145 template<std::size_t id> using GridGeometry = GetPropType<SubDomainTypeTag<id>, Properties::GridGeometry>;
146 template<std::size_t id> using GridView = typename GridGeometry<id>::GridView;
147 template<std::size_t id> using GridIndex = typename IndexTraits<GridView<id>>::GridIndex;
148 template<std::size_t id> using SolutionVector = GetPropType<SubDomainTypeTag<id>, Properties::SolutionVector>;
149 template<std::size_t id> using PrimaryVariables = GetPropType<SubDomainTypeTag<id>, Properties::PrimaryVariables>;
150
151 static constexpr auto bulkIdx = typename MDTraits::template SubDomain<0>::Index();
152 static constexpr auto lowDimIdx = typename MDTraits::template SubDomain<1>::Index();
153
154 template<std::size_t id>
155 static constexpr bool isBox()
156 { return GridGeometry<id>::discMethod == DiscretizationMethods::box; }
157
158public:
159 PointSourceDataCircleAverage() : enableBulkCircleInterpolation_(false) {}
160
161 PrimaryVariables<bulkIdx> interpolateBulk(const SolutionVector<bulkIdx>& sol) const
162 {
163 // bulk interpolation on the circle is only enabled for source in the
164 // lower dimensional domain if we use a circle distributed bulk sources
165 // (see coupling manager circle sources)
166 PrimaryVariables<bulkIdx> bulkPriVars(sol[0]);
167 bulkPriVars = 0.0;
168 if (enableBulkCircleInterpolation_)
169 {
170 // compute the average of the bulk privars over the circle around the integration point
171 // this computes $\bar{p} = \frac{1}{2\pi R} int_0^2*\pi p R \text{d}\theta.
172 if (isBox<bulkIdx>())
173 {
174 assert(circleCornerIndices_.size() == circleShapeValues_.size());
175
176 Scalar weightSum = 0.0;
177 for (std::size_t j = 0; j < circleStencil_.size(); ++j)
178 {
179 PrimaryVariables<bulkIdx> priVars(0.0);
180 const auto& cornerIndices = *(circleCornerIndices_[j]);
181 const auto& shapeValues = circleShapeValues_[j];
182 for (int i = 0; i < cornerIndices.size(); ++i)
183 {
184 const auto& localSol = sol[cornerIndices[i]];
185 const auto& shapeValue = shapeValues[i];
186 for (int priVarIdx = 0; priVarIdx < PrimaryVariables<bulkIdx>::size(); ++priVarIdx)
187 priVars[priVarIdx] += localSol[priVarIdx]*shapeValue;
188 }
189 // multiply with weight and add
190 priVars *= circleIpWeight_[j];
191 weightSum += circleIpWeight_[j];
192 bulkPriVars += priVars;
193 }
194 bulkPriVars /= weightSum;
195 }
196 else
197 {
198 Scalar weightSum = 0.0;
199 for (int j = 0; j < circleStencil_.size(); ++j)
200 {
201 for (int priVarIdx = 0; priVarIdx < bulkPriVars.size(); ++priVarIdx)
202 bulkPriVars[priVarIdx] += sol[circleStencil_[j]][priVarIdx]*circleIpWeight_[j];
203
204 weightSum += circleIpWeight_[j];
205 }
206 bulkPriVars /= weightSum;
207 }
208 return bulkPriVars;
209 }
210 else
211 {
212 return ParentType::interpolateBulk(sol);
213 }
214 }
215
216 void addCircleInterpolation(const std::vector<const std::vector<GridIndex<bulkIdx>>*>& circleCornerIndices,
217 const std::vector<ShapeValues>& circleShapeValues,
218 const std::vector<Scalar>& circleIpWeight,
219 const std::vector<GridIndex<bulkIdx>>& circleStencil)
220 {
221 circleCornerIndices_ = circleCornerIndices;
222 circleShapeValues_ = circleShapeValues;
223 circleIpWeight_ = circleIpWeight;
224 circleStencil_ = circleStencil;
225 enableBulkCircleInterpolation_ = true;
226
227 }
228
229 void addCircleInterpolation(const std::vector<Scalar>& circleIpWeight,
230 const std::vector<GridIndex<bulkIdx>>& circleStencil)
231 {
232 circleIpWeight_ = circleIpWeight;
233 circleStencil_ = circleStencil;
234 enableBulkCircleInterpolation_ = true;
235 }
236
237 const std::vector<GridIndex<bulkIdx>>& circleStencil() const
238 { return circleStencil_; }
239
240private:
241 std::vector<const std::vector<GridIndex<bulkIdx>>*> circleCornerIndices_;
242 std::vector<ShapeValues> circleShapeValues_;
243 std::vector<Scalar> circleIpWeight_;
244 std::vector<GridIndex<bulkIdx>> circleStencil_;
245 bool enableBulkCircleInterpolation_;
246};
247
248} // end namespace Dumux
249
250#endif
A point source data class used for integration in multidimensional models.
Definition: pointsourcedata.hh:139
const std::vector< GridIndex< bulkIdx > > & circleStencil() const
Definition: pointsourcedata.hh:237
void addCircleInterpolation(const std::vector< Scalar > &circleIpWeight, const std::vector< GridIndex< bulkIdx > > &circleStencil)
Definition: pointsourcedata.hh:229
PointSourceDataCircleAverage()
Definition: pointsourcedata.hh:159
PrimaryVariables< bulkIdx > interpolateBulk(const SolutionVector< bulkIdx > &sol) const
Definition: pointsourcedata.hh:161
void addCircleInterpolation(const std::vector< const std::vector< GridIndex< bulkIdx > > * > &circleCornerIndices, const std::vector< ShapeValues > &circleShapeValues, const std::vector< Scalar > &circleIpWeight, const std::vector< GridIndex< bulkIdx > > &circleStencil)
Definition: pointsourcedata.hh:216
A point source data class used for integration in multidimensional models.
Definition: pointsourcedata.hh:31
GridIndex< bulkIdx > bulkElementIdx() const
Definition: pointsourcedata.hh:117
void addLowDimInterpolation(const ShapeValues &shapeValues, const std::vector< GridIndex< lowDimIdx > > &cornerIndices, GridIndex< lowDimIdx > eIdx)
Definition: pointsourcedata.hh:60
GridIndex< lowDimIdx > lowDimElementIdx() const
Definition: pointsourcedata.hh:114
void addBulkInterpolation(GridIndex< bulkIdx > eIdx)
Definition: pointsourcedata.hh:70
PrimaryVariables< lowDimIdx > interpolateLowDim(const SolutionVector< lowDimIdx > &sol) const
Definition: pointsourcedata.hh:98
void addBulkInterpolation(const ShapeValues &shapeValues, const std::vector< GridIndex< bulkIdx > > &cornerIndices, GridIndex< bulkIdx > eIdx)
Definition: pointsourcedata.hh:50
PrimaryVariables< bulkIdx > interpolateBulk(const SolutionVector< bulkIdx > &sol) const
Definition: pointsourcedata.hh:82
void addLowDimInterpolation(GridIndex< lowDimIdx > eIdx)
Definition: pointsourcedata.hh:76
Defines all properties used in Dumux.
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
Defines the index types used for grid and local indices.
The available discretization methods in Dumux.
constexpr Box box
Definition: method.hh:147
Definition: adapt.hh:17
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:26