13#include <dune/common/float_cmp.hh>
14#include <dune/grid/utility/hierarchicsearch.hh>
29template <
int size,
typename LV>
33 lagrangeNodeGlobalCoords.emplace_back(localView.element().geometry().global(localCoordinate));
49template <
int size,
typename Basis>
52 "globalIndexFromGlobalPosition is only supported for Lagrange basis");
53 constexpr double tol = 1e-8;
54 using LocalView = std::remove_cvref_t<
decltype(
basis.localView())>;
55 using MultiIndex =
typename LocalView::MultiIndex;
56 Dune::HierarchicSearch hSearch(
basis.gridView().grid(),
basis.gridView().indexSet());
57 const auto& ele = hSearch.findEntity(pos);
58 auto localView =
basis.localView();
60 const auto geo = localView.element().geometry();
61 const auto& node = localView.tree();
65 if (Dune::FloatCmp::eq(geo.global(localCoordinate), pos, tol)) {
67 for (
int j = 0; j < size; j++)
68 globalIndices.value()[j] = localView.index(node.child(j).localIndex(nodeNumber));
75 DUNE_THROW(Dune::InvalidStateException,
"No Lagrange node found at the given position in the grid.");
91 const auto& referenceElement = Dune::referenceElement<double, dim>(element.type());
92 const int numberOfVertices = referenceElement.size(codim);
94 auto getPosition = [=](
const int i) {
return referenceElement.position(i, codim); };
95 return std::views::transform(std::views::iota(0, numberOfVertices), getPosition);
105template <
typename FE>
Contains functions to traverse through a tree to its different nodes.
auto referenceElementSubEntityPositions(FE &fe, int codim)
A function to obtain the local coordinates of subentities of an FiniteElement.
Definition: functionhelper.hh:88
auto referenceElementVertexPositions(FE &fe)
A function to obtain the local coordinates the vertices of an FiniteElement.
Definition: functionhelper.hh:106
auto globalIndexFromGlobalPosition(const Basis &basis, const Dune::FieldVector< double, size > &pos)
A helper function to obtain the global index from the global positions for a Lagrange node.
Definition: functionhelper.hh:50
void obtainLagrangeGlobalNodePositions(const LV &localView, std::vector< Dune::FieldVector< double, size > > &lagrangeNodeGlobalCoords)
A function to obtain the global positions of the nodes of an element with Lagrangian basis.
Definition: functionhelper.hh:30
void globalIndices(const FiniteElement &fe, std::vector< typename FiniteElement::LocalView::MultiIndex > &globalIndices)
Get the global indices for the provided finite element.
Definition: fehelper.hh:127
Definition: algorithms.hh:17
void forEachLagrangeNodePosition(const LV &localView, F &&f)
A helper function that helps in traversing over the local coordinates of an element and call a user-d...
Definition: traversal.hh:65
def basis(gv, tree)
Definition: basis.py:10
FE class is a base class for all finite elements.
Definition: febase.hh:79
const GridElement & gridElement() const
Get the grid element associated with the local view.
Definition: febase.hh:128
static constexpr int mydim
Dimension of the geometry.
Definition: fetraits.hh:63
Definition: utils/dirichletvalues.hh:32
Concept to check if a node in a basis tree is a Lagrangian node.
Definition: concepts.hh:82