<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Hi Felix,</p>
    <p>if you want to access the finiteElement() of a leaf basis node,
      you have to bind it to an element, since, e.g. LagrangeNode uses a
      FiniteElementCache that gives you a different FiniteElement
      depending on the element type. Binding a TypeTree to an element
      could be done using the free function `bindTree(tree, element)`
      from dune/functions/functionspacebases/nodes.hh. But therefore you
      need a mutable tree object. The LocalView gives you only a
      const& to the TypeTree. An option would be to simply create a
      copy of the tree and bind this copy to the element, i.e.</p>
    <p>auto tree = lv.tree();<br>
      bindTree(tree, coarseElement);<br>
      forEachLeafNode(tree, [&](auto const& node, auto&&
      tp) {<br>
        const auto& fe = node.finiteElement();<br>
        // do something with fe<br>
      }<em><br>
      </em></p>
    <p>The tree traversal does not require a bound tree, so you could
      also bind the leaf node directly to an element, i.e.</p>
    <p>forEachLeafNode(lv.tree(), [&](auto node, auto&& tp)
      { // node argument by value<br>
        node.bind(coarseElement);<br>
        const auto& fe = node.finiteElement();<br>
        // do something with fe<br>
      }<em><br>
      </em></p>
    <p>This should solve your problem with AlbertaGrid,</p>
    <p>Best,<br>
      Simon<br>
    </p>
    <div class="moz-cite-prefix">Am 09.11.18 um 09:07 schrieb Felix
      Mueller:<br>
    </div>
    <blockquote type="cite"
cite="mid:20181109140751.Horde.9qP_FXM7wNIWF2Q2bGa8T6R@mail.zih.tu-dresden.de">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <title></title>
      <p>Dear dune-functions developers,<br>
        <br>
        I am working on some code for data transfer during grid
        adaptation. In this I have a data vector that contains the
        degrees of freedom (DOF) of the grid's finite elements, modeled
        by a vector indexed with the index set of a dune-functions
        basis.<br>
        Since I am losing geometric grid information of elements that
        disappear during a call to adapt(), I want to compute the DOFs
        of coarse grid entities before calling adapt(). To do this I
        require the finite element type of those entities, as well as
        the indices corresponding to the child entites of the coarse
        entity.<br>
        <br>
        The following code illustrates the process:<br>
        <br>
        <em>auto lv = basis.localView();<br>
          // loop over all leaf elements<br>
          for (auto leafElement : leafElements) {<br>
            lv.bind(leafElement);<br>
            const auto& node = lv.tree();<br>
            const auto& fe = node.finiteElement();<br>
            auto feSize = fe.size();<br>
          <br>
            for (std::size_t i = 0; i < feSize; ++i) {<br>
              auto index = lv.index(node.localIndex(i);<br>
              // save vector[index] for later use<br>
              // ...<br>
            }<br>
          }<br>
          <br>
          lv.bind(coarseElement);<br>
          const auto& node = lv.tree();<br>
        </em>const auto& fe = node.finiteElement();<em><br>
          // do something with fe<br>
          // ...</em><br>
        <br>
        Note that <em>coarseElement</em> does not access the basis's
        index set here.<br>
        <br>
        This process works for <em>Dune::UGGrid<2></em> and <em>Dune::Functions::LagrangeBasis<GridView,
          k></em> with <em>k</em> of any order and
        Dune::AlbertaGrid<2,2> with <em>Dune::Functions::LagrangeBasis<GridView,
          1></em>.<br>
        <br>
        However it fails for Dune::AlbertaGrid<2,2> with <em>Dune::Functions::LagrangeBasis<GridView,
          k></em> with <em>k ≠ 1</em> at:<br>
        <strong>dune/grid/albertagrid/indexsets.hh:482</strong>: <em>Assertion
          `(subIndex >= 0) && (subIndex < size( codim ))'
          failed.</em><br>
        Deactivating the assertion prevents the crash and makes my code
        run just fine.<br>
        <br>
        The issue above seems to be caused by <strong>dune/functions/functionspacebases/defaultlocalview.hh:72:</strong><br>
        void bind(const Element& e)<br>
        {<br>
        element_ = e;<br>
        bindTree(tree_, element_);<br>
        nodeIndexSet_.bind(tree_);<br>
        indices_.resize(size());<br>
        Hybrid::ifElse(<br>
        Std::is_detected<hasIndices,NodeIndexSet>{},<br>
        [&](auto id) {<br>
        id(nodeIndexSet_).indices(indices_.begin());<br>
        },<br>
        [&](auto id) {<br>
        for (size_type i = 0 ; i < this->size() ; ++i)<br>
        indices_[i] = id(nodeIndexSet_).index(i);<br>
        });<br>
        }<br>
        This tries to access the index set on <em>coarseElement</em>,
        which is not defined and not needed within my code either.<br>
        <strong>Dune-functions 2.5</strong> had a seperate binding
        mechanism for the local view and index sets, providing only the
        method<br>
        <em>void bind(const Element& e)<br>
          {<br>
            element_ = e;<br>
            bindTree(tree_, element_);<br>
          }</em><br>
        which is completely sufficient for my purpose.<br>
        <br>
        <br>
        <u>My question now is:</u><br>
        - Is this behaviour intended or is this a bug in either <strong>defaultlocalview.hh</strong>
        or <strong>AlbertaGrid</strong>?<br>
        - If it is intended, is there a way to only bind the local view
        without binding the index set, like in v2.5?<br>
        <br>
        <br>
        Thanks for your attention and helpful answers!<br>
        <br>
        Felix Müller<br>
        <br>
        <br>
        PS: You will find a small file reproducing the error attached. A
        filename for the AlbertaReader must be provided as argument to
        the main method. I have used <strong>dune-grid/doc/grids/amc/grid-2-2.amc</strong>
        as grid file for my tests.</p>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
dune-functions mailing list
<a class="moz-txt-link-abbreviated" href="mailto:dune-functions@lists.dune-project.org">dune-functions@lists.dune-project.org</a>
<a class="moz-txt-link-freetext" href="https://lists.dune-project.org/mailman/listinfo/dune-functions">https://lists.dune-project.org/mailman/listinfo/dune-functions</a></pre>
    </blockquote>
  </body>
</html>