12#ifndef DUMUX_POINTSOURCES_HH
13#define DUMUX_POINTSOURCES_HH
21#include <dune/common/exceptions.hh>
22#include <dune/common/reservedvector.hh>
26#include <dumux/common/typetraits/localdofs_.hh>
45 constexpr bool empty()
const {
return true; }
47 template<
class ElementDiscretization>
48 std::span<const Context>
contexts(
const ElementDiscretization&,
49 const typename ElementDiscretization::SubControlVolume&)
const
52 template<
class ElementDiscretization>
53 std::span<const Context>
contexts(
const ElementDiscretization&,
54 const typename ElementDiscretization::Element&)
const
57 template<
class ElementDiscretization,
class ElementVariables>
58 auto eval(
const ElementDiscretization&,
const ElementVariables&,
const Context&)
const
72template<
class PositionType>
89 {
return embeddings_; }
96 std::size_t embeddings_ = 1;
105template<
class Context,
class IdType>
128template<
class Context>
139 {
return scvIndex_; }
142 std::size_t scvIndex_ = 0;
153template<
class Context,
class Function>
157 using Scalar =
typename Context::GlobalPosition::value_type;
160 using MapType = std::map<std::pair<std::size_t, std::size_t>, std::vector<ScvContext>>;
164 : map_(std::move(map)), f_(std::move(f))
168 bool empty()
const {
return map_.empty(); }
171 template<
class ElementDiscretization>
172 std::span<const ScvContext>
contexts(
const ElementDiscretization& elemDisc,
173 const typename ElementDiscretization::SubControlVolume& scv)
const
175 const auto eIdx = elemDisc.gridGeometry().elementMapper().index(elemDisc.element());
176 const auto scvIdx = scv.indexInElement();
177 const auto it = map_.find({eIdx, scvIdx});
178 return (it != map_.end()) ? std::span<const ScvContext>(it->second)
179 : std::span<const ScvContext>{};
183 template<
class ElementDiscretization>
184 auto contexts(
const ElementDiscretization& elemDisc,
185 const typename ElementDiscretization::Element& element)
const
187 return scvs(elemDisc)
188 | std::views::transform([
this, &elemDisc](
const auto& scv)
189 {
return this->
contexts(elemDisc, scv); })
194 template<
class ElementDiscretization,
class ElementVariables>
195 auto eval(
const ElementDiscretization& elemDisc,
196 const ElementVariables& elemVars,
197 const ScvContext& context)
const
199 auto values = f_(elemDisc, elemVars, context);
200 values /=
static_cast<Scalar
>(context.embeddings());
221template<
class Gr
idDiscretization,
class Context>
223 std::initializer_list<Context> contexts)
226template<
class Gr
idDiscretization,
class Context>
228 const std::vector<Context>& contexts)
231 std::map<std::pair<std::size_t, std::size_t>, std::vector<ScvContext>> map;
232 const auto& boundingBoxTree = gridDiscretization.boundingBoxTree();
234 for (
const auto& ctx : contexts)
237 if (entities.empty())
241 if constexpr (isCVFE)
243 auto elemDisc =
localView(gridDiscretization);
244 for (
const auto eIdx : entities)
246 const auto element = boundingBoxTree.entitySet().entity(eIdx);
247 elemDisc.bindElement(element);
249 using ElemDisc =
typename GridDiscretization::LocalView;
250 Dune::ReservedVector<std::size_t, Dumux::Detail::LocalDofs::maxNumLocalDofs<ElemDisc>()> scvIndices;
251 for (
const auto& scv :
scvs(elemDisc))
253 scvIndices.push_back(scv.indexInElement());
255 for (
const auto scvIdx : scvIndices)
258 entry.setEmbeddings(ctx.embeddings() * entities.size() * scvIndices.size());
259 map[{eIdx, scvIdx}].emplace_back(entry, scvIdx);
266 for (
const auto eIdx : entities)
269 entry.setEmbeddings(ctx.embeddings() * entities.size());
270 map[{eIdx, std::size_t(0)}].emplace_back(entry, std::size_t(0));
274 DUNE_THROW(Dune::NotImplemented,
275 "makePointSourceMap for discretization method " << GridDiscretization::discMethod);
289template<
class Gr
idDiscretization,
class Context,
class Function>
291 std::initializer_list<Context> contexts,
293{
return makePointSources(gridDiscretization, std::vector<Context>(contexts), std::move(f)); }
295template<
class Gr
idDiscretization,
class Context,
class Function>
297 const std::vector<Context>& contexts,
IdType Id
Definition pointsources.hh:109
IdType id() const
Definition pointsources.hh:117
IdPointSourceContext()=default
IdPointSourceContext(const Context &ctx, IdType id)
Definition pointsources.hh:112
const GlobalPosition & position() const
Definition pointsources.hh:85
PointSourceContext()=default
std::size_t embeddings() const
Definition pointsources.hh:88
void setEmbeddings(std::size_t embeddings)
Definition pointsources.hh:91
PositionType GlobalPosition
Definition pointsources.hh:76
PointSourceContext(GlobalPosition position, std::size_t embeddings=1)
Definition pointsources.hh:80
Combines a point source map with a user-provided evaluation function.
Definition pointsources.hh:155
std::map< std::pair< std::size_t, std::size_t >, std::vector< ScvContext > > MapType
Definition pointsources.hh:160
std::span< const ScvContext > contexts(const ElementDiscretization &elemDisc, const typename ElementDiscretization::SubControlVolume &scv) const
Return the context range of a sub-control volume.
Definition pointsources.hh:172
bool empty() const
Returns whether no point sources have been registered.
Definition pointsources.hh:168
auto contexts(const ElementDiscretization &elemDisc, const typename ElementDiscretization::Element &element) const
Return the context range of the whole element.
Definition pointsources.hh:184
auto eval(const ElementDiscretization &elemDisc, const ElementVariables &elemVars, const ScvContext &context) const
Evaluate the source for a given context.
Definition pointsources.hh:195
PointSources(MapType map, Function f)
Definition pointsources.hh:163
Point source context enriched with the sub-control volume index.
Definition pointsources.hh:130
std::size_t scvIndex() const
Definition pointsources.hh:138
ScvPointSourceContext()=default
ScvPointSourceContext(const Context &ctx, std::size_t scvIdx)
Definition pointsources.hh:133
auto makePointSourceMap(const GridDiscretization &gridDiscretization, std::initializer_list< Context > contexts)
Build a point source map from a list of point source contexts.
Definition pointsources.hh:222
typename NumEqVectorTraits< PrimaryVariables >::type NumEqVector
A vector with the same size as numbers of equations This is the default implementation and has to be ...
Definition numeqvector.hh:34
auto makePointSources(const GridDiscretization &gridDiscretization, std::initializer_list< Context > contexts, Function f)
Build a PointSources object from a list of contexts and an evaluation function.
Definition pointsources.hh:290
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
std::vector< std::size_t > intersectingEntities(const Dune::FieldVector< ctype, dimworld > &point, const BoundingBoxTree< EntitySet > &tree, bool isCartesianGrid=false)
Compute all intersections between entities and a point.
Definition intersectingentities.hh:102
Algorithms that finds which geometric entities intersect.
Detect if a point intersects a geometry.
Free function to get the local view of a grid cache object.
The available discretization methods in Dumux.
constexpr CCMpfa ccmpfa
Definition method.hh:165
constexpr CCTpfa cctpfa
Definition method.hh:164
constexpr bool isCVFE
Definition method.hh:67
Definition assembly/assembler.hh:44
std::ranges::range auto scvs(const FVElementGeometry &fvGeometry, const LocalDof &localDof)
Definition localdof.hh:82
A helper to deduce a vector with the same size as numbers of equations.
Dummy context type satisfying the assembly interface.
Definition pointsources.hh:43
Empty point sources.
Definition pointsources.hh:41
std::span< const Context > contexts(const ElementDiscretization &, const typename ElementDiscretization::Element &) const
Definition pointsources.hh:53
std::span< const Context > contexts(const ElementDiscretization &, const typename ElementDiscretization::SubControlVolume &) const
Definition pointsources.hh:48
constexpr bool empty() const
Definition pointsources.hh:45
auto eval(const ElementDiscretization &, const ElementVariables &, const Context &) const
Definition pointsources.hh:58