14#ifndef DUMUX_POINTSOURCE_HH
15#define DUMUX_POINTSOURCE_HH
21#include <dune/common/exceptions.hh>
22#include <dune/common/reservedvector.hh>
40template<
class PositionType,
class ValueType>
45 using Scalar = std::decay_t<decltype(std::declval<ValueType>()[0])>;
58 :
values_(0.0), pos_(pos), embeddings_(1) {}
113 template<
class Problem,
class FVElementGeometry,
class ElementVolumeVariables>
115 const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity &element,
116 const FVElementGeometry &fvGeometry,
117 const ElementVolumeVariables &elemVolVars,
118 const typename FVElementGeometry::SubControlVolume &scv)
147 std::size_t embeddings_;
157template<
class GlobalPosition,
class SourceValues,
class I>
169 : ParentType(pos,
values), id_(
id) {}
174 : ParentType(pos, SourceValues(0.0)), id_(
id) {}
202template<
class TypeTag>
204 GetPropType<TypeTag, Properties::GridGeometry>::GridView::dimensionworld>,
205 Dumux::NumEqVector<GetPropType<TypeTag, Properties::PrimaryVariables>>>
212 using SubControlVolume =
typename FVElementGeometry::SubControlVolume;
213 using Element =
typename GridView::template Codim<0>::Entity;
215 static const int dimworld = GridView::dimensionworld;
216 using GlobalPosition =
typename Dune::FieldVector<typename GridView::ctype, dimworld>;
218 using ValueFunction =
typename std::function<SourceValues(
const Problem &problem,
219 const Element &element,
220 const FVElementGeometry &fvGeometry,
221 const ElementVolumeVariables &elemVolVars,
222 const SubControlVolume &scv)>;
231 ValueFunction valueFunction)
232 : ParentType(pos, SourceValues(0.0)), valueFunction_(valueFunction) {}
238 const Element &element,
239 const FVElementGeometry &fvGeometry,
240 const ElementVolumeVariables &elemVolVars,
241 const SubControlVolume &scv)
242 { this->
values_ = valueFunction_(problem, element, fvGeometry, elemVolVars, scv); }
259 ValueFunction valueFunction_;
272 template<
class Gr
idGeometry,
class Po
intSource,
class Po
intSourceMap>
274 const std::vector<PointSource>& sources,
275 PointSourceMap& pointSourceMap,
276 const std::string& paramGroup =
"")
278 const auto& boundingBoxTree = gridGeometry.boundingBoxTree();
280 for (
const auto& s : sources)
286 if (entities.empty())
296 constexpr int dim = GridGeometry::GridView::dimension;
297 std::vector<std::pair<std::size_t, Dune::ReservedVector<std::size_t, 1<<dim>>> located;
298 auto fvGeometry =
localView(gridGeometry);
299 for (
const auto eIdx : entities)
301 fvGeometry.bindElement(boundingBoxTree.entitySet().entity(eIdx));
303 if (!scvIndices.empty())
304 located.emplace_back(eIdx, scvIndices);
308 source.setEmbeddings(located.size()*source.embeddings());
312 for (
const auto& [eIdx, scvIndices] : located)
314 for (
const auto scvIdx : scvIndices)
316 const auto key = std::make_pair(eIdx, scvIdx);
317 if (pointSourceMap.count(key))
318 pointSourceMap.at(key).push_back(source);
320 pointSourceMap.insert({key, {source}});
322 auto& s = pointSourceMap.at(key).back();
323 s.setEmbeddings(scvIndices.size()*s.embeddings());
331 source.setEmbeddings(entities.size()*source.embeddings());
332 for (
const auto eIdx : entities)
335 const auto key = std::make_pair(eIdx, 0);
336 if (pointSourceMap.count(key))
337 pointSourceMap.at(key).push_back(source);
339 pointSourceMap.insert({key, {source}});
343 DUNE_THROW(Dune::NotImplemented,
"BoundingBoxTreePointSourceHelper for discretization method " << GridGeometry::discMethod);
An axis-aligned bounding box volume hierarchy for dune grids.
A helper class calculating a sub control volume to point source map This class uses the bounding box ...
Definition pointsource.hh:269
static void computePointSourceMap(const GridGeometry &gridGeometry, const std::vector< PointSource > &sources, PointSourceMap &pointSourceMap, const std::string ¶mGroup="")
calculate a DOF index to point source map from given vector of point sources
Definition pointsource.hh:273
I IdType
export the id type
Definition pointsource.hh:165
IdPointSource(GlobalPosition pos, IdType id)
Constructor for sol dependent point sources, when there is no.
Definition pointsource.hh:173
IdPointSource(GlobalPosition pos, SourceValues values, IdType id)
Constructor for constant point sources.
Definition pointsource.hh:168
IdType id() const
Definition pointsource.hh:177
IdPointSource & operator=(const SourceValues &values)
Convenience = operator overload modifying only the values.
Definition pointsource.hh:181
void setEmbeddings(std::size_t embeddings)
set the number of embeddings for this point source
Definition pointsource.hh:122
PointSource & operator*=(Scalar s)
Convenience *= operator overload modifying only the values.
Definition pointsource.hh:75
ValueType Values
Export the value type.
Definition pointsource.hh:49
PointSource & operator+=(Scalar s)
Convenience += operator overload modifying only the values.
Definition pointsource.hh:61
PointSource(GlobalPosition pos)
Constructor for sol dependent point sources, when there is no.
Definition pointsource.hh:57
std::decay_t< decltype(std::declval< ValueType >()[0])> Scalar
Export the scalar type.
Definition pointsource.hh:45
Values values() const
Definition pointsource.hh:103
PositionType GlobalPosition
Export the position type.
Definition pointsource.hh:47
Values values_
Definition pointsource.hh:144
const GlobalPosition & position() const
return the source position
Definition pointsource.hh:107
void update(const Problem &problem, const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const typename FVElementGeometry::SubControlVolume &scv)
an update function called before adding the value
Definition pointsource.hh:114
PointSource & operator-=(Scalar s)
Convenience -= operator overload modifying only the values.
Definition pointsource.hh:68
PointSource(GlobalPosition pos, Values values)
Constructor for constant point sources.
Definition pointsource.hh:52
PointSource & operator=(const Values &values)
Convenience = operator overload modifying only the values.
Definition pointsource.hh:89
PointSource & operator/=(Scalar s)
Convenience /= operator overload modifying only the values.
Definition pointsource.hh:82
std::size_t embeddings() const
Definition pointsource.hh:138
SolDependentPointSource & operator=(const SourceValues &values)
Convenience = operator overload modifying only the values.
Definition pointsource.hh:245
SolDependentPointSource(GlobalPosition pos, ValueFunction valueFunction)
Constructor for sol dependent point sources, when there is no.
Definition pointsource.hh:230
void update(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolume &scv)
an update function called before adding the value
Definition pointsource.hh:237
Defines all properties used in Dumux.
The elements and the sub-control volumes of a grid discretization that contain a point.
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
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition localview.hh:26
Dune::ReservedVector< std::size_t, maxNumScvs > scvsContainingPoint(const ElementDiscretization &elemDisc, const GlobalPosition &globalPos)
The local indices of the sub-control volumes of the bound element that contain a point.
Definition elementscontainingpoint.hh:45
std::vector< std::pair< int, std::size_t > > intersectingEntities(const Dune::FieldVector< ctype, dimworld > &point, const DistributedBoundingBoxTree< EntitySet > &tree, bool isCartesianGrid=false, bool onlyOwned=true)
Compute all intersections between entities and a point on a distributed tree.
Definition distributedintersectingentities.hh:81
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition propertysystem.hh:296
Algorithms that find which geometric entities intersect.
The available discretization methods in Dumux.
constexpr CCMpfa ccmpfa
Definition method.hh:175
constexpr FCDiamond fcdiamond
Definition method.hh:184
constexpr CCTpfa cctpfa
Definition method.hh:174
constexpr Box box
Definition method.hh:176
A helper to deduce a vector with the same size as numbers of equations.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.