version 3.11-dev
Loading...
Searching...
No Matches
integrationpointsource.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//
14
15#ifndef DUMUX_INTEGRATION_POINTSOURCE_HH
16#define DUMUX_INTEGRATION_POINTSOURCE_HH
17
18#include <type_traits>
19#include <dune/common/exceptions.hh>
20#include <dune/common/reservedvector.hh>
23#include <dumux/common/typetraits/localdofs_.hh>
25
26namespace Dumux {
27
33template<class GlobalPosition, class SourceValues, typename IdType = std::size_t>
34class IntegrationPointSource : public IdPointSource<GlobalPosition, SourceValues, IdType>
35{
37 using Scalar = std::decay_t<decltype(std::declval<SourceValues>()[0])>;
38
39public:
42 Scalar qpweight, Scalar integrationElement,
43 std::size_t elementIndex)
44 : ParentType(pos, values, id)
45 , qpweight_(qpweight)
46 , integrationElement_(integrationElement)
47 , elementIndex_(elementIndex)
48 {}
49
53 Scalar qpweight, Scalar integrationElement,
54 std::size_t elementIndex)
55 : ParentType(pos, id)
56 , qpweight_(qpweight)
57 , integrationElement_(integrationElement)
58 , elementIndex_(elementIndex)
59 {}
60
61 Scalar quadratureWeight() const
62 { return qpweight_; }
63
64 Scalar integrationElement() const
65 { return integrationElement_; }
66
67 void setQuadratureWeight(const Scalar qpWeight)
68 { qpweight_ = qpWeight; }
69
70 void setIntegrationElement(const Scalar ie)
71 { integrationElement_ = ie; }
72
74 std::size_t elementIndex() const
75 { return elementIndex_; }
76
79 {
81 return *this;
82 }
83
86 {
88 return *this;
89 }
90
91private:
92 Scalar qpweight_;
93 Scalar integrationElement_;
94 std::size_t elementIndex_;
95};
96
102{
103
104public:
106 template<class GridGeometry, class PointSource, class PointSourceMap>
107 static void computePointSourceMap(const GridGeometry& gridGeometry,
108 const std::vector<PointSource>& sources,
109 PointSourceMap& pointSourceMap,
110 const std::string& paramGroup = "")
111 {
112 [[maybe_unused]] const bool boxPointSourceLumping = getParamFromGroup<bool>(paramGroup, "PointSource.EnableBoxLumping", true);
113 for (const auto& source : sources)
114 {
115 // get the index of the element in which the point source falls
116 const auto eIdx = source.elementIndex();
118 {
119 static_assert(!Detail::LocalDofs::hasNonCVLocalDofsInterface<typename GridGeometry::LocalView>(),
120 "Point sources in the sub control volumes need a scheme where every local dof has a control volume, "
121 "use the interface with the element variables otherwise");
122 auto fvGeometry = localView(gridGeometry);
123 // check in which subcontrolvolume(s) we are
124 const auto element = gridGeometry.boundingBoxTree().entitySet().entity(eIdx);
125 fvGeometry.bindElement(element);
126 const auto globalPos = source.position();
127
128 if (boxPointSourceLumping)
129 {
130 // loop over all sub control volumes and check if the point source is inside
131 Dune::ReservedVector<std::size_t, Detail::LocalDofs::maxNumLocalDofs<typename GridGeometry::LocalView>()> scvIndices;
132 for (const auto& scv : scvs(fvGeometry))
133 {
134 if constexpr (requires { scv.isOverlapping(); })
135 if (scv.isOverlapping())
136 DUNE_THROW(Dune::NotImplemented,
137 "Point sources in overlapping sub control volumes, "
138 "set PointSource.EnableBoxLumping to false to distribute them with the basis functions");
139
140 if (intersectsPointGeometry(globalPos, fvGeometry.geometry(scv)))
141 scvIndices.push_back(scv.indexInElement());
142 }
143
144 if (scvIndices.empty())
145 DUNE_THROW(Dune::InvalidStateException,
146 "Point source at " << globalPos << " is not inside any sub control volume of element " << eIdx);
147
148 // for all scvs that where tested positive add the point sources
149 // to the element/scv to point source map
150 for (auto scvIdx : scvIndices)
151 {
152 const auto key = std::make_pair(eIdx, scvIdx);
153 if (pointSourceMap.count(key))
154 pointSourceMap.at(key).push_back(source);
155 else
156 pointSourceMap.insert({key, {source}});
157 // split equally on the number of matched scvs
158 auto& s = pointSourceMap.at(key).back();
159 s.setEmbeddings(scvIndices.size()*s.embeddings());
160 }
161 }
162
163 // distribute the sources using the basis function weights
164 else
165 {
166 const auto& localBasis = fvGeometry.feLocalBasis();
167 const auto ipLocal = element.geometry().local(globalPos);
168 using ShapeValue = typename std::decay_t<decltype(localBasis)>::Traits::RangeType;
169 std::vector<ShapeValue> shapeValues;
170 localBasis.evaluateFunction(ipLocal, shapeValues);
171 for (const auto& scv : scvs(fvGeometry))
172 {
173 const auto key = std::make_pair(eIdx, scv.indexInElement());
174 if (pointSourceMap.count(key))
175 pointSourceMap.at(key).push_back(source);
176 else
177 pointSourceMap.insert({key, {source}});
178
179 // adjust the integration element
180 auto& s = pointSourceMap.at(key).back();
181 s.setIntegrationElement(shapeValues[scv.indexInElement()][0]*s.integrationElement());
182 }
183 }
184 }
185 else if constexpr (GridGeometry::discMethod == DiscretizationMethods::cctpfa
186 || GridGeometry::discMethod == DiscretizationMethods::ccmpfa)
187 {
188 // add the pointsource to the DOF map
189 const auto key = std::make_pair(eIdx, /*scvIdx=*/ 0);
190 if (pointSourceMap.count(key))
191 pointSourceMap.at(key).push_back(source);
192 else
193 pointSourceMap.insert({key, {source}});
194 }
195 else
196 DUNE_THROW(Dune::NotImplemented, "IntegrationPointSourceHelper for discretization method " << GridGeometry::discMethod);
197 }
198 }
199};
200
201} // end namespace Dumux
202
203#endif
IdPointSource(GlobalPosition pos, SourceValues values, IdType id)
Definition pointsource.hh:168
IdPointSource & operator=(const SourceValues &values)
Definition pointsource.hh:181
A helper class calculating a DOF-index to point source map.
Definition integrationpointsource.hh:102
static void computePointSourceMap(const GridGeometry &gridGeometry, const std::vector< PointSource > &sources, PointSourceMap &pointSourceMap, const std::string &paramGroup="")
calculate a DOF index to point source map from given vector of point sources
Definition integrationpointsource.hh:107
IntegrationPointSource(GlobalPosition pos, SourceValues values, IdType id, Scalar qpweight, Scalar integrationElement, std::size_t elementIndex)
Constructor for integration point sources.
Definition integrationpointsource.hh:41
Scalar quadratureWeight() const
Definition integrationpointsource.hh:61
IntegrationPointSource & operator=(const SourceValues &values)
Convenience = operator overload modifying only the values.
Definition integrationpointsource.hh:78
void setQuadratureWeight(const Scalar qpWeight)
Definition integrationpointsource.hh:67
void setIntegrationElement(const Scalar ie)
Definition integrationpointsource.hh:70
IntegrationPointSource(GlobalPosition pos, IdType id, Scalar qpweight, Scalar integrationElement, std::size_t elementIndex)
Definition integrationpointsource.hh:52
std::decay_t< decltype(std::declval< SourceValues >()[0])> Scalar
Definition pointsource.hh:45
typename GridGeometry< i >::GlobalCoordinate GlobalPosition
Definition pointsource.hh:47
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition localview.hh:26
bool intersectsPointGeometry(const Dune::FieldVector< ctype, dimworld > &point, const Geometry &g)
Find out whether a point is inside a three-dimensional geometry.
Definition intersectspointgeometry.hh:28
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition parameters.hh:168
The available discretization methods in Dumux.
constexpr CCMpfa ccmpfa
Definition method.hh:175
constexpr CCTpfa cctpfa
Definition method.hh:174
constexpr bool isCVFE
Definition method.hh:67
Definition adapt.hh:17
std::ranges::range auto scvs(const FVElementGeometry &fvGeometry, const LocalDof &localDof)
Definition localdof.hh:82
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
A point source class, i.e. sources located at a single point in space.