<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Dear Dune users & developers,<div class=""><br class=""></div><div class="">we are using dune-functions and the core modules in a simple FEM code. We want to strongly enforce Dirichlet boundary conditions.</div><div class="">The boundary conditions are specified locally for each element as a function of the element and the local position.</div><div class=""><br class=""></div><div class="">For globally defined analytical functions, we could use a global interpolate to get the coefficient / Dirichlet values. But how do we do this for “piece-wise”-defined boundary conditions?</div><div class="">We came up with something like this (restriction to simple Lagrange basis, nothing composite and assuming all dofs are Dirichlet for now):</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">Dune::BlockVector<Dune::FieldVector<double, numEq>> dirichletValues;</font></div><div class=""><pre class="highlight code" lang="cpp"><font face="Menlo" class=""><span id="LC389" class="line" lang="cpp"><span class="k">auto</span> <span class="n">getDirichletValues</span> <span class="o">=</span> <span class="p">[</span><span class="o">&</span><span class="p">]</span> <span class="p">(</span><span class="k">auto</span> <span class="n">localIndex</span><span class="p">, </span></span><span id="LC390" class="line" lang="cpp"><span class="k">const</span> <span class="k">auto</span><span class="o">&</span> <span class="n">localView</span><span class="p">, </span></span><span id="LC391" class="line" lang="cpp"><span class="k">const</span> <span class="k">auto</span><span class="o">&</span> <span class="n">intersection</span><span class="p">)</span></span>
<span id="LC392" class="line" lang="cpp"><span class="p">{</span></span>
<span id="LC393" class="line" lang="cpp"><span class="k"> const</span> <span class="k">auto</span><span class="o">&</span> <span class="n">element</span> <span class="o">=</span> <span class="n">localView</span><span class="p">.</span><span class="n">element</span><span class="p">();</span></span>
<span id="LC400" class="line" lang="cpp"><span class="c1"> // get the local coordinates of the dofs of the element</span></span>
<span id="LC404" class="line" lang="cpp"><span class="n"> std</span><span class="o">::</span><span class="n">vector</span><span class="o"><</span><span class="kt">double</span><span class="o">></span> <span class="n">coords</span><span class="p">;</span></span>
<span id="LC405" class="line" lang="cpp"> <span class="k">const</span> <span class="k">auto</span><span class="o">&</span> <span class="n">interp</span> <span class="o">=</span> <span class="n">localView</span><span class="p">.</span><span class="n">tree</span><span class="p">().</span><span class="n">finiteElement</span><span class="p">().</span><span class="n">localInterpolation</span><span class="p">();</span></span></font></pre><pre class="highlight code" lang="cpp"><font face="Menlo" class=""><span id="LC406" class="line" lang="cpp"> <span class="n">interp</span><span class="p">.</span><span class="n">interpolate</span><span class="p">([</span><span class="o">&</span><span class="p">]</span> <span class="p">(</span><span class="k">const</span> <span class="n">LocalCoordinate</span><span class="o">&</span> <span class="n">x</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span> <span class="p">},</span> <span class="n">coords</span><span class="p">);</span></span>
<span id="LC408" class="line" lang="cpp"> <span class="n">localDofCoords</span><span class="p">.</span><span class="n">resize</span><span class="p">(</span><span class="n">coords</span><span class="p">.</span><span class="n">size</span><span class="p">());</span></span>
<span id="LC409" class="line" lang="cpp"> <span class="k">for</span> <span class="p">(</span><span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">coords</span><span class="p">.</span><span class="n">size</span><span class="p">();</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span></span>
<span id="LC410" class="line" lang="cpp"> <span class="n">localDofCoords</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">coords</span><span class="p">[</span><span class="n">i</span><span class="p">];</span></span>
<span id="LC411" class="line" lang="cpp"></span>
<span id="LC412" class="line" lang="cpp"> <span class="n">interp</span><span class="p">.</span><span class="n">interpolate</span><span class="p">([</span><span class="o">&</span><span class="p">]</span> <span class="p">(</span><span class="k">const</span> <span class="n">LocalCoordinate</span><span class="o">&</span> <span class="n">x</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span> <span class="p">},</span> <span class="n">coords</span><span class="p">);</span></span>
<span id="LC413" class="line" lang="cpp"> <span class="k">for</span> <span class="p">(</span><span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">coords</span><span class="p">.</span><span class="n">size</span><span class="p">();</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span></span>
<span id="LC414" class="line" lang="cpp"> <span class="n">localDofCoords</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">coords</span><span class="p">[</span><span class="n">i</span><span class="p">];</span></span>
<span id="LC415" class="line" lang="cpp"></span>
<span id="LC416" class="line" lang="cpp"> </span><span id="LC420" class="line" lang="cpp"><span class="k">const</span> <span class="k">auto</span> <span class="n">index</span> <span class="o">=</span> <span class="n">localView</span><span class="p">.</span><span class="n">index</span><span class="p">(</span><span class="n">localIndex</span><span class="p">);</span></span>
<span id="LC421" class="line" lang="cpp"> <span class="k">for</span> <span class="p">(</span><span class="kt">unsigned</span> <span class="kt">int</span> <span class="n">eqIdx</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">eqIdx</span> <span class="o"><</span> <span class="n">numEq</span><span class="p">;</span> <span class="o">++</span><span class="n">eqIdx</span><span class="p">)</span></span>
<span id="LC422" class="line" lang="cpp"> </span><span style="white-space: normal;" class="">dirichletValues</span><span id="LC424" class="line" lang="cpp"><span class="p">[</span><span class="n">index</span><span class="p">]</span> <span class="o">=</span> <span class="n">problem</span><span class="p">.</span><span class="n">dirichlet</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">localDofCoords</span><span class="p">[</span><span class="n">localIndex</span><span class="p">]</span>);<br class=""></span>};</font></pre><pre class="highlight code" lang="cpp"><font face="Menlo" class=""><span id="LC427" class="line" lang="cpp"></span>
<span id="LC428" class="line" lang="cpp"><span class="n">Dune</span><span class="o">::</span><span class="n">Functions</span><span class="o">::</span><span class="n">forEachBoundaryDOF</span><span class="p">(lagrangeB</span><span class="n">asis</span><span class="p">,</span> <span class="n">getDirichletValues</span><span class="p">);</span></span></font>
</pre><div class=""><br class=""></div></div><div class="">which is far from nice. In this way the coordinates are recomputed every time although it would be enough to compute them once per element type. Also we could figure out how to get the full position instead of only the x,y,z-components separately.</div><div class="">There seems to be no obvious way to get the local position of a DOF within an element, although this sounds like a very basic thing to do.</div><div class="">With the `localKey` it is possible to obtain the subEntity and its center position via the reference element. But this doesn’t (necessarily) correspond to the DOF position of course.</div><div class=""><br class=""></div><div class="">Is there some obvious way that we are missing on how to solve this problem without writing an excessive amount of code?</div><div class="">Do you have any suggestion or comments on how “piece-wise” defined strongly enforced Dirichlet boundary conditions could be realized?</div><div class=""><br class=""></div><div class="">Thanks a lot for your help</div><div class="">Timo</div><div class=""><br class=""><div class="">
<div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;">-- <br class="">_________________________________________________</div><div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;"><br class="">Timo Koch phone: +49 711 685 64676<br class="">IWS, Universität Stuttgart fax: +49 711 685 60430<br class="">Pfaffenwaldring 61 <a href="mailto:timo.koch@iws.uni-stuttgart.de" class="">email: timo.koch@iws.uni-stuttgart.de</a><br class="">D-70569 Stuttgart url: <a href="http://www.iws.uni-stuttgart.de/en/lh2/" class="">www.iws.uni-stuttgart.de/en/lh2/</a><br class="">_________________________________________________</div>
</div>
<br class=""></div></body></html>