108 const std::vector<PointSource>& sources,
109 PointSourceMap& pointSourceMap,
110 const std::string& paramGroup =
"")
112 [[maybe_unused]]
const bool boxPointSourceLumping =
getParamFromGroup<bool>(paramGroup,
"PointSource.EnableBoxLumping",
true);
113 for (
const auto& source : sources)
116 const auto eIdx = source.elementIndex();
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);
124 const auto element = gridGeometry.boundingBoxTree().entitySet().entity(eIdx);
125 fvGeometry.bindElement(element);
126 const auto globalPos = source.position();
128 if (boxPointSourceLumping)
131 Dune::ReservedVector<std::size_t, Detail::LocalDofs::maxNumLocalDofs<typename GridGeometry::LocalView>()> scvIndices;
132 for (
const auto& scv :
scvs(fvGeometry))
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");
141 scvIndices.push_back(scv.indexInElement());
144 if (scvIndices.empty())
145 DUNE_THROW(Dune::InvalidStateException,
146 "Point source at " << globalPos <<
" is not inside any sub control volume of element " << eIdx);
150 for (
auto scvIdx : scvIndices)
152 const auto key = std::make_pair(eIdx, scvIdx);
153 if (pointSourceMap.count(key))
154 pointSourceMap.at(key).push_back(source);
156 pointSourceMap.insert({key, {source}});
158 auto& s = pointSourceMap.at(key).back();
159 s.setEmbeddings(scvIndices.size()*s.embeddings());
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))
173 const auto key = std::make_pair(eIdx, scv.indexInElement());
174 if (pointSourceMap.count(key))
175 pointSourceMap.at(key).push_back(source);
177 pointSourceMap.insert({key, {source}});
180 auto& s = pointSourceMap.at(key).back();
181 s.setIntegrationElement(shapeValues[scv.indexInElement()][0]*s.integrationElement());
189 const auto key = std::make_pair(eIdx, 0);
190 if (pointSourceMap.count(key))
191 pointSourceMap.at(key).push_back(source);
193 pointSourceMap.insert({key, {source}});
196 DUNE_THROW(Dune::NotImplemented,
"IntegrationPointSourceHelper for discretization method " << GridGeometry::discMethod);