KASKADE 7 development version
Loading...
Searching...
No Matches
functionspace.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2002-2025 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef FUNCTIONSPACE_HH
14#define FUNCTIONSPACE_HH
15
29
30#include <cassert>
31#include <map>
32#include <sstream>
33
34#include <boost/mpl/int.hpp>
35#include <boost/mpl/range_c.hpp>
36#include <boost/multi_array.hpp>
37#include <boost/signals2.hpp>
38#include <boost/type_traits/remove_pointer.hpp>
39#include <boost/type_traits/remove_reference.hpp>
40
41#include <boost/fusion/algorithm.hpp>
42#include <boost/fusion/sequence.hpp>
43
44#include "dune/common/config.h"
45// #include "dune/common/dynmatrixev.hh"
46#include "dune/common/fmatrixev.hh"
47#include "dune/geometry/quadraturerules.hh"
48#include "dune/istl/bvector.hh"
49
50#include "fem/gridmanager.hh"
53#include "linalg/crsutil.hh"
55
56namespace Kaskade
57{
58
59 // forward declarations
60 template <class LocalToGlobalMapper> class FEFunctionSpace;
61
62 template <template <class, class> class, class, class> class BoundaryMapper;
63
65 namespace FunctionSpace_Detail
66 {
67 template <class Mapper>
68 struct IsBoundaryMapperStruct : std::false_type {};
69 template<template <class, class> class DomainMapper, class Scalar, class GridView>
70 struct IsBoundaryMapperStruct<BoundaryMapper<DomainMapper,Scalar,GridView>> : std::true_type {};
71 // if Mapper is a BoundaryMapper this returns true, otherwise false
72 template <class Mapper>
73 constexpr bool isBoundaryMapper() {
74 return IsBoundaryMapperStruct<Mapper>::value;
75 }
76
77 template <class Mapper>
78 struct ChooseDomainMapperStruct {
79 using type = void;
80 };
81 template<template <class, class> class DomainMapper, class Scalar, class GridView>
82 struct ChooseDomainMapperStruct<BoundaryMapper<DomainMapper,Scalar,GridView>> {
83 using type = DomainMapper<Scalar,GridView>;
84 };
85 // if Mapper is a BoundaryMapper this gives the underlying FE mapper, otherwise it gives the void type
86 template<class Mapper>
87 using ChooseDomainMapper = typename ChooseDomainMapperStruct<Mapper>::type;
88
89 // checks whether two LeafGridViews are the same (i.e. whether they belong to the same grid (tested by memory address of grid))
90 template<class Grid>
91 bool gridViewsAreSame(typename Grid::LeafGridView gv1, typename Grid::LeafGridView gv2) {
92 return &(gv1.grid()) == &(gv2.grid());
93 }
94 // checks whether two LevelGridViews are the same (i.e. whether they belong to the same grid and are of the same level)
95 template<class Grid>
96 bool gridViewsAreSame(typename Grid::LevelGridView gv1, typename Grid::LevelGridView gv2) {
97 return (gv1.template begin<0>()->level() == gv2.template begin<0>()->level()) && (&(gv1.grid()) == &(gv2.grid()));
98 }
99
100 // --------------------------------------------------------------------------------------------
101
102 enum CoefficientTransfer { START, FINISH };
103 }
105
115
116 //---------------------------------------------------------------------
117 //---------------------------------------------------------------------
118
130 template <class Spaces, int Idx>
132 {
133 using type = std::remove_pointer_t<typename boost::fusion::result_of::value_at_c<Spaces,Idx>::type>;
134 };
135
136
137 //---------------------------------------------------------------------
138 //---------------------------------------------------------------------
139
157 template <class Cell, class ctype>
158 std::pair<Cell,Dune::FieldVector<ctype,Cell::dimension>>
159 findCellOnLevel(Cell cell, Dune::FieldVector<ctype,Cell::dimension> xi, int level=std::numeric_limits<int>::max())
160 {
161 ctype const tol = 100*std::numeric_limits<ctype>::epsilon();
162 assert(checkInside(cell.type(),xi) < tol);
163 assert(level>=0);
164
165 using namespace Dune;
166
167 if (level <= cell.level()) // go downwards - that's easy
168 {
169 while (level < cell.level())
170 {
171 xi = cell.geometryInFather().global(xi);
172 cell = cell.father();
173 }
174 }
175 else // go upwards - we have to check in which child the position is
176 {
177 // Move up if we have not yet blundered into the leaf or the max level
178 while (cell.level()<level && !cell.isLeaf())
179 // Check all the direct children
180 for (Cell const& c: descendantElements(cell,cell.level()+1))
181 {
182 auto xiC = c.geometryInFather().local(xi);
183 // and if the point is inside one child, that's it
184 if (checkInside(c.type(),xiC) < tol)
185 {
186 cell = c;
187 xi = xiC;
188 break;
189 }
190 }
191 }
192
193 return std::make_pair(cell,xi);
194 }
195
196
197 //---------------------------------------------------------------------
198
199
212 template <class GridView>
214 {
215 const double tol = 1e-12 ;
216
217 using namespace Dune;
218
219 // Do linear search on coarse grid (level 0).
220 auto coarseIterator = std::find_if(gv.grid().levelGridView(0).template begin<0>(), gv.grid().levelGridView(0).template end<0>(),
221 [&](Cell<GridView> const& cell)
222 {
223 return checkInside(cell.type(),cell.geometry().local(global)) < tol;
224 });
225
226 if (coarseIterator == gv.grid().levelGridView(0).template end<0>()) // not found
227 {
228 std::ostringstream msg;
229 msg << "findCell(): global point << " << global << " is not contained in any level 0 cell in the grid!";
230 msg.flush();
231 throw LookupException(msg.str(),__FILE__,__LINE__);
232 }
233
234 // Do a hierarchical search for a leaf cell containing the point.
235 Cell<GridView> ci(*coarseIterator);
236
237 int lastFound = 0;
238
239 for( int level = 0; level <= gv.grid().maxLevel(); level++ )
240 {
241 if (ci.isLeaf())
242 return ci;
243
244 for (auto hi = ci.hbegin(level+1); hi != ci.hend(level+1) ; ++hi)
245 if( checkInside(hi->type(),hi->geometry().local(global)) < tol )
246 {
247 ci = typename GridView::Grid::template Codim<0>::Entity(*hi);
248 lastFound = level;
249 break ;
250 }
251 }
252
253 // We should never get here... For a position outside the domain, no coarse grid cell should have been
254 // found, leading to an exception being raised above. If, on the other hand, a coarse grid cell has been
255 // found, there should be a leaf cell containing the given point as well.
256 std::cerr << "findCell() at " << __FILE__ << ':' << __LINE__ << '\n'
257 << "Global point << " << global
258 << " is not contained in any cell in the grid!\n"
259 << " last found on " << lastFound << " of " << gv.grid().maxLevel() << "\n";
260 abort();
261 return ci; // never get here! (just for formal correctness return something)
262 }
263
264
265 //---------------------------------------------------------------------
266
267
313 template <class FunctionSpace, int m>
315 {
316 public:
318 using Space = FunctionSpace;
319
321 using GridView = typename Space::GridView;
322
324 using ctype = typename GridView::ctype;
325
327 typedef FunctionSpaceElement <Space, m> Self;
329 typedef typename Space::Scalar Scalar;
330
337
340
345
352
355
357 static int const components = Space::sfComponents * m;
358
361
377
380
381
392 data(fs.degreesOfFreedom()), sp(&fs), transferMe(*this)
393 {
394 data = 0;
395 transferConnection = sp->requestToRefine.connect(transferMe);
396 }
397
400 data(fse.data), sp(fse.sp), transferMe(*this)
401 {
402 transferConnection = sp->requestToRefine.connect(transferMe);
403 }
404
407 : data(std::move(fse.data))
408 , sp(fse.sp)
409 , transferMe(*this)
410 {
411 transferConnection = sp->requestToRefine.connect(transferMe);
412 }
413
415 {
416 transferConnection.disconnect();
417 sp = 0;
418 }
419
423
428
436 Self& operator=(Self const& fse)
437 {
438 if(this != &fse) // nothing to do on self-assignment
439 {
440 if (sp == fse.sp) // the same function space
441 data = fse.data;
442 else // different function spaces
444 }
445 return *this;
446 }
447
456 {
457 if(this != &fse) { // nothing to do on self-assignment
458 if (sp == fse.sp) // the same function space
459 {
460 data = std::move(fse.data);
461 fse.transferConnection.disconnect();
462 }
463 else // different function spaces
465 }
466 return *this;
467 }
468
477 template <class OtherSpace>
479 {
481 return *this;
482 }
483
494 template <template <class, class> class DomainMapper>
496 {
497 bool hasEquivalentUnderlyingMapper = !FunctionSpace_Detail::isBoundaryMapper<typename Space::Mapper>();
498 hasEquivalentUnderlyingMapper = (hasEquivalentUnderlyingMapper && std::is_same<DomainMapper<Scalar,typename Space::GridView>, typename Space::Mapper>::value);
499 hasEquivalentUnderlyingMapper = (hasEquivalentUnderlyingMapper && space().mapper().maxOrder()==bf.space().mapper().maxOrder());
500 hasEquivalentUnderlyingMapper = (hasEquivalentUnderlyingMapper && FunctionSpace_Detail::gridViewsAreSame<typename Space::GridView::Grid>(space().gridView(),bf.space().gridView()));
501 if (hasEquivalentUnderlyingMapper)
502 {
503 BoundaryMapper<DomainMapper, Scalar, typename Space::GridView> const& boundaryMapper = bf.space().mapper();
504 *this = 0.0;
505 for(typename StorageType::size_type vi=0;vi<size();++vi)
506 {
507 std::pair<bool,typename StorageType::size_type> restrictedIndex = boundaryMapper.unrestrictedToRestrictedIndex(vi);
508 if (restrictedIndex.first)
509 data[vi] = bf[restrictedIndex.second];
510 }
511 }
512 else
513 {
514 // TODO: When interpolateGlobally works correctly (better said: as one would expect) for boundary functions as second argument remove the following three lines
515 FEFunctionSpace<DomainMapper<Scalar,typename Space::GridView>> domainSpace(bf.space().gridManager(),bf.space().gridView(),bf.space().mapper().maxOrder());
516 typename FEFunctionSpace<DomainMapper<Scalar,typename Space::GridView>>::template Element_t<m> df(domainSpace);
517 df = bf;
519 }
520 return *this;
521 }
522
532 template <class Mapper>
533 std::enable_if_t<std::is_same<Mapper,FunctionSpace_Detail::ChooseDomainMapper<typename Space::Mapper>>::value,Self&>
535 {
536 bool hasEquivalentUnderlyingMapper = FunctionSpace_Detail::isBoundaryMapper<typename Space::Mapper>();
537 hasEquivalentUnderlyingMapper = (hasEquivalentUnderlyingMapper && space().mapper().maxOrder()==f.space().mapper().maxOrder());
538 hasEquivalentUnderlyingMapper = (hasEquivalentUnderlyingMapper && FunctionSpace_Detail::gridViewsAreSame<typename Space::GridView::Grid>(space().gridView(),f.space().gridView()));
539 if (hasEquivalentUnderlyingMapper)
540 {
541 typename Space::Mapper const& boundaryMapper = space().mapper();
542 for(typename StorageType::size_type vi=0;vi<f.size();++vi)
543 {
544 std::pair<bool,typename StorageType::size_type> restrictedIndex = boundaryMapper.unrestrictedToRestrictedIndex(vi);
545 if (restrictedIndex.first)
546 data[restrictedIndex.second] = f[vi];
547 }
548 }
549 else
551
552 return *this;
553 }
554
569 template <class Functor>
571 {
573 return *this;
574 }
575
589 template <class Space, class Functor>
591 {
592 interpolateGlobally(*this,f);
593 return *this;
594 }
595
602 {
603 assert(data.size()==v.size());
604 data = v;
605 return *this;
606 }
607
616 {
617 for (int i=0; i<data.N(); ++i)
618 data[i] = a;
619 return *this;
620 }
621
629 {
630 for(size_t i=0; i<data.N(); ++i)
631 data[i] = val;
632 return *this;
633 }
634
638
642
648 Self& operator+=(Self const& f)
649 {
650 if (sp==f.sp) // same function space
651 coefficients() += f.coefficients();
652 else {
653 Self tmp(space()); tmp = f; *this += tmp;
654 }
655 return *this;
656 }
657
664 template <class OtherSpace>
666 {
667 Self tmp(space()); tmp = f; *this += tmp;
668 return *this;
669 }
670
675 {
676 assert(data.size()==v.size());
677 data += v;
678 return *this;
679 }
680
688 {
689 for (int i=0; i<data.N(); ++i)
690 data[i] += val;
691 return *this;
692 }
693
701 {
702 if (sp==f.sp) // same function space
703 coefficients() -= f.coefficients();
704 else {
705 Self tmp(space()); tmp = f; *this -= tmp;
706 }
707 return *this;
708 }
709
716 template <class OtherSpace>
718 {
719 Self tmp(space()); tmp = f; *this -= tmp;
720 return *this;
721 }
722
727 {
728 assert(data.size()==v.size());
729 data -= v;
730 return *this;
731 }
732
739 Self& operator-=(Scalar const& val)
740 {
741 for (int i=0; i<data.N(); ++i)
742 data[i] -= val;
743 return *this;
744 }
745
751 Self& axpy(Scalar a, Self const& f)
752 {
753 if (sp==f.sp) // same function space
754 coefficients().axpy(a,f.coefficients());
755 else {
756 Self tmp(space()); tmp = f; this->axpy(a,tmp);
757 }
758 return *this;
759 }
760
767 template <class OtherSpace>
769 {
770 Self tmp(space()); tmp = f; this->axpy(a,tmp);
771 return *this;
772 }
773
778 {
779 assert(data.size()==v.size());
780 data.axpy(a,v);
781 return *this;
782 }
783
786 {
787 data *= a;
788 return *this;
789 }
790
794
799
809 ValueType value(typename Space::Evaluator const& evaluator) const
810 {
811 ValueType y(0);
812
813 size_t esize = evaluator.size();
814
815 for (size_t i=0; i<esize; ++i)
816 {
817 StorageValueType const& coeff = data[evaluator.globalIndices()[i]];
818 auto const& sfVal = evaluator.evalData[i].value;
819 for (int n=0; n<m; ++n)
820 for (int l=0; l<Space::sfComponents; ++l)
821 y[n*Space::sfComponents+l] += coeff[n]*sfVal[l];
822 }
823
824 return y;
825 }
826
834 LocalPosition<GridView> const& local) const
835 {
836 typename Space::Evaluator eval(space());
837 eval.moveTo(cell);
838 eval.evaluateAt(local);
839
840 return value(eval);
841 }
842
850 {
851 auto cell = findCell(space().gridView(),x); // throws LookupException if no cell is found
852 auto xi = cell.geometry().local(x); // may end up slightly outside of reference element
853 // due to rounding errors...
854 return value(cell,xi); // ... but this should have a negligible impact.
855 }
856
857
865 DerivativeType derivative(typename FunctionSpace::Evaluator const& evaluator) const
866 {
867 DerivativeType dy(0);
868
869 size_t esize = evaluator.size();
870 for (size_t i=0; i<esize; ++i) // step through all restricted ansatz functions
871 {
872 auto const& coeff = data[evaluator.globalIndices()[i]];
873 auto const& sfGrad = evaluator.evalData[i].derivative;
874 for (int n=0; n<m; ++n) // step through all FE function components
875 for (int l=0; l<Space::sfComponents; ++l) // step through all shape function components
876 dy[n*Space::sfComponents+l] += coeff[n] * sfGrad[l];
877 }
878
879 return dy;
880 }
881
890 LocalPosition<GridView> const& local) const
891 {
892 typename Space::Evaluator eval(space());
893 eval.moveTo(cell);
894 eval.evaluateAt(local);
895
896 return derivative(eval);
897 }
898
906 {
907 auto ci = findCell(space().gridView(),global) ;
908
909 return derivative(ci,ci.geometry().local(global));
910 }
911
912
920 HessianType hessian(typename FunctionSpace::Evaluator const& evaluator) const
921 {
922 HessianType ddy(0);
923
924 assert(evaluator.derivatives() >= 2);
925
926 size_t esize = evaluator.size();
927 for (size_t i=0; i<esize; ++i) {
928 StorageValueType const& coeff = data[evaluator.globalIndices()[i]];
929 auto const& sfHess = evaluator.evalData[i].hessian;
930 for (int n=0; n<m; ++n)
931 for (int l=0; l<Space::sfComponents; ++l) {
932 auto hess = sfHess[l];
933 hess *= coeff[n];
934 ddy[n*Space::sfComponents+l] += hess;
935 }
936 }
937
938 return ddy;
939 }
940
949 LocalPosition<GridView> const& local) const
950 {
951 typename Space::Evaluator eval(space(),nullptr,2);
952 eval.moveTo(cell);
953 eval.evaluateAt(local);
954
955 return hessian(eval);
956 }
957
964 {
965 auto ci = findCell(space().gridView(),global);
966 return hessian(ci,ci.geometry().local(global));
967 }
968
972
973
981 StorageType const& coefficients() const { return data; }
982
987
991 StorageValueType& operator[](size_t i) { return data[i]; }
992
996 StorageValueType const& operator[](size_t i) const { return data[i]; }
997
1001
1006
1008 int dim() const { return data.dim(); }
1009
1016 int size() const { assert(data.size()*m==dim()); return data.size(); }
1017
1021 Space const& space() const { return *sp; }
1022
1026 int order(Cell<GridView> const& cell) const
1027 {
1028 return space().order(cell);
1029 }
1030
1032 // Why not simply calling sfs.order directly? Can we delete this method?
1033 template<class SFS>
1034 [[deprecated]] int order(SFS const& sfs) const
1035 {
1036 return sfs.order();
1037 }
1038
1044 void transfer(typename TransferData<Space>::TransferMatrix const& transferMatrix)
1045 {
1046 std::unique_ptr<Dune::BlockVector<StorageValueType>> newCoeff = transferMatrix.apply(data);
1047 data = *newCoeff;
1048 }
1049
1053
1054 private:
1055
1056 struct TransferMe
1057 {
1058 TransferMe(Self& fe) : myFSE(fe) {}
1059
1060 TransferMe(TransferMe const& other)
1061 : myFSE(other.myFSE)
1062 {}
1063
1064 void operator()(typename TransferData<Space>::TransferMatrix const* transfer)
1065 {
1066 if (transfer)
1067 {
1068 // auto f = [&]() { myFSE.transfer(*transfer); };
1069 // f();
1070 future = std::async(std::launch::async,[transfer,f=&myFSE]() { f->transfer(*transfer); });
1071 }
1072 else
1073 {
1074 assert(future.valid());
1075 future.get();
1076 }
1077 }
1078
1079 private:
1080 Self& myFSE;
1081 std::future<void> future;
1082 };
1083
1084
1085
1086 protected:
1088 Space const* sp;
1089
1090 private:
1091 TransferMe transferMe;
1092 boost::signals2::connection transferConnection;
1093 };
1094
1100 template <class Space, int m, class OutIter>
1101 OutIter vectorToSequence(FunctionSpaceElement<Space,m> const& v, OutIter iter)
1102 {
1103 return vectorToSequence(v.coefficients(),iter);
1104 }
1105
1106 template <class Space, int m, class InIter>
1108 {
1109 return vectorFromSequence(v.coefficients(),in);
1110 }
1111
1113 {
1114 // if an FEFunction is restricted to the boundary transform it in to a new FEFunction
1115 // over the whole domain, otherwise leave it unchanged. Used by writeVTK.
1116 template <class FEFunction>
1118 public:
1119 ToDomainRepresentation(FEFunction const& f_) : f(f_){}
1120
1121 FEFunction const& get() const {
1122 return f;
1123 }
1124
1125 private:
1126 FEFunction const& f;
1127 };
1128
1129 template <template <class, class> class DomainMapper, typename Scalar, typename GridView, int m>
1131 {
1132
1135 using DomainFESpace = typename DomainFEFunction::Space;
1136
1137 public:
1138 ToDomainRepresentation(BoundaryFEFunction const& f_) : space(f_.space().gridManager(),f_.space().gridView()
1139 ,f_.space().mapper().maxOrder()), f(space)
1140 {
1141 f = f_;
1142 }
1143
1144 DomainFEFunction const& get() const {
1145 return f;
1146 }
1147
1148 private:
1149 DomainFESpace space;
1150 DomainFEFunction f;
1151 };
1152 }
1153
1154 //------------------------------------------------------------------------------------------------
1155 //------------------------------------------------------------------------------------------------
1156
1180 template <class LocalToGlobalMapper>
1182 {
1184
1185 public:
1187 using GridView = typename LocalToGlobalMapper::GridView;
1189 typedef typename GridView::Grid Grid;
1191 typedef typename GridView::IndexSet IndexSet;
1192
1194 typedef typename LocalToGlobalMapper::Scalar Scalar;
1195
1201
1203 typedef typename Grid::ctype ctype;
1204
1206 typedef LocalToGlobalMapper Mapper;
1207
1209 static int const dim = Grid::dimension;
1210
1212 static int const dimworld = Grid::dimensionworld;
1213
1217 static int const sfComponents = Mapper::ShapeFunctionSet::comps;
1218
1226 static int const continuity = Mapper::continuity;
1227
1231 template <int m>
1232 struct [[deprecated]] Element
1233 {
1235 };
1236
1245 template <int m>
1247
1260 {
1261 typedef typename IndexSet::IndexType IndexType;
1262
1264 typedef Self Space;
1265
1270
1274 static int const sfComponents = Mapper::ShapeFunctionSet::comps;
1275
1280
1284 typedef typename Mapper::GlobalIndexRange GlobalIndexRange;
1285
1289 typedef typename Mapper::SortedIndexRange SortedIndexRange;
1290
1300 Evaluator(Self const& space_, ShapeFunctionCache<Grid,Scalar>* cache_=nullptr, int deriv_ = 1) :
1301 space(space_), sf(nullptr), cache(cache_), sfValues(nullptr), combiner_(nullptr),
1302 globIdx(space.mapper().initGlobalIndexRange()), sortedIdx(space.mapper().initSortedIndexRange()),
1303 deriv(deriv_), currentCell(nullptr)
1304 { }
1305
1309 Evaluator(Evaluator const& eval):
1310 evalData(eval.evalData),
1311 space(eval.space), sf(eval.sf), sfSize(eval.sfSize), cache(eval.cache), sfValues(eval.sfValues), lastQr(eval.lastQr), lastSubId(eval.lastSubId), combiner_(nullptr),
1312 globIdx(eval.globIdx), sortedIdx(eval.sortedIdx), deriv(eval.deriv), currentXloc(eval.currentXloc), currentCell(nullptr)
1313 {
1314 if (eval.combiner_)
1315 combiner_ = std::make_unique<typename Mapper::Combiner>(*eval.combiner_);
1316 if (eval.currentCell)
1317 currentCell = std::make_unique<Cell>(*eval.currentCell);
1318 }
1319
1324 {
1325 assert(&space==&eval.space);
1326 sf = eval.sf;
1327 sfSize = eval.sfSize;
1328 cache = eval.cache;
1329 sfValues = eval.sfValues;
1330 lastQr = nullptr;
1331 lastSubId = -1;
1332 converter = eval.converter;
1333 if (eval.combiner_) {
1334 combiner_ = std::make_unique<typename Mapper::Combiner>(*eval.combiner_);
1335 } else {
1336 combiner_.reset();
1337 }
1338 globIdx = eval.globIdx;
1339 sortedIdx = eval.sortedIdx;
1340 evalData = eval.evalData;
1341 deriv = eval.deriv;
1342 currentXloc = eval.currentXloc;
1343 if (eval.currentCell) {
1344 currentCell = std::make_unique<Cell>(*eval.currentCell);
1345 } else {
1346 currentCell.reset();
1347 }
1348
1349 return *this;
1350 }
1351
1364 void moveTo(Cell const& cell, IndexType const index)
1365 {
1366 sf = &space.mapper().shapefunctions(index);
1367 sfSize = sf->size();
1368 assert(sfSize>=0);
1369
1370 currentCell = std::make_unique<Cell>(cell);
1371
1372 converter.moveTo(*currentCell);
1373
1374 combiner_ = std::make_unique<typename Mapper::Combiner>(space.mapper().combiner(*currentCell,index));
1375
1376 globIdx = space.mapper().globalIndices(index);
1377 sortedIdx = space.mapper().sortedIndices(index);
1378 }
1379
1386 void moveTo(Cell const& cell)
1387 {
1388 moveTo(cell,space.indexSet().index(cell));
1389 }
1390
1401 template <int subDim>
1402 void useQuadratureRule(Dune::QuadratureRule<typename Grid::ctype,subDim> const& qr, int subId)
1403 {
1404 // reusing data does not work for boundary mapper in its current (non optimal) implementation,
1405 // where every cell has its own restricted shape function set.
1406 // TODO: When the implementation of boundary mapper is improved (i.e. all cells use the
1407 // same shape function set and restriction is handled by the Combiner) remove the following line.
1408 if(FunctionSpace_Detail::isBoundaryMapper<Mapper>())
1409 return;
1410 // check whether we have the data corresponding to the lookup key (qr,subId) already available
1411 if (sfValues && lastQr==&qr && lastSubId==subId)
1412 return;
1413
1414 if (cache)
1415 {
1416 sfValues = &cache->evaluate(*sf,qr,subId); // extract data from cache
1417 lastQr = &qr; // remember extraction key
1418 lastSubId = subId;
1419 }
1420 }
1421
1426 {
1427 currentXloc = xi;
1428 evalData.clear();
1429
1430 converter.setLocalPosition(xi);
1431
1432 evalData.reserve(sfSize);
1433 for (int i=0; i<sfSize; ++i)
1434 {
1436
1437 typename Mapper::ShapeFunctionSet::value_type const& sfun = (*sf)[i];
1438 evalData.push_back( derivatives()<=1?
1439 converter.global(SfArg(sfun.evaluateFunction(xi),sfun.evaluateDerivative(xi)),1) :
1440 converter.global(SfArg(sfun.evaluateFunction(xi),sfun.evaluateDerivative(xi),sfun.evaluate2ndDerivative(xi)),2) );
1441 }
1442 combiner_->rightTransform(evalData);
1443 }
1444
1453 template <int subDim>
1455 Dune::QuadratureRule<typename Grid::ctype,subDim> const& qr, int ip, int subId)
1456 {
1457 if (cache)
1458 {
1459 currentXloc = x;
1460 evalData.clear();
1461 converter.setLocalPosition(x);
1462
1463 if (sfValues)
1464 for (int i=0; i<sfSize; ++i)
1465 evalData.push_back( converter.global((*sfValues)[ip][i],derivatives()) );
1466 else
1467 {
1468 auto const& localData = cache->evaluate(*sf,qr,ip,subId);
1469
1470 for (int i=0; i<sfSize; ++i)
1471 evalData.push_back( converter.global(localData[i],derivatives()) );
1472 }
1473
1474 combiner_->rightTransform(evalData);
1475 }
1476 else
1477 evaluateAt(x);
1478 }
1479
1481 GlobalIndexRange globalIndices() const { return globIdx; }
1482
1486 SortedIndexRange sortedIndices() const { return sortedIdx; }
1487
1492 int size() const
1493 {
1494 return globalIndices().size();
1495 }
1496
1497
1499 int order() const
1500 {
1501 return sf->order();
1502 }
1503
1505 typename Mapper::ShapeFunctionSet const& shapeFunctions() const { return *sf; }
1506
1508 typename Mapper::Combiner const& combiner() const { return *combiner_; }
1509
1515 std::vector<VarArg> evalData;
1516
1520 GridView const& gridView() const
1521 {
1522 return space.gridView();
1523 }
1524
1525 LocalToGlobalMapper const& mapper() const
1526 {
1527 return space.mapper();
1528 }
1529
1533 Cell const& cell() const
1534 {
1535 assert(currentCell);
1536 return *currentCell;
1537 }
1538
1542 Dune::FieldVector<ctype,dim> const& xloc() const { return currentXloc; }
1543
1547 int derivatives() const { return deriv; }
1548
1549 private:
1550 Self const& space;
1551 typename Mapper::ShapeFunctionSet const* sf;
1552 int sfSize;
1554 typename ShapeFunctionCache<Grid,Scalar>::template DataType<sfComponents>::type const* sfValues;
1555 void const* lastQr; // lookup key for cached shape function values
1556 int lastSubId; // lookup key for cached shape function values
1557 typename Mapper::Converter converter;
1558 std::unique_ptr<typename Mapper::Combiner> combiner_; // TODO: why held by pointer? Wouldn't a member variable make more sense and simplify things? (For this, something like a default constructor would be needed)
1559 GlobalIndexRange globIdx;
1560 SortedIndexRange sortedIdx;
1561 int deriv; // number of derivatives to evaluate
1562 Dune::FieldVector<ctype,dim> currentXloc; // local coordinates of current evaluation point
1563 std::unique_ptr<Cell> currentCell; // cell containing current evaluation point (want Evaluator to store its own Entity object
1564 // (previously it only stored a raw pointer),
1565 // unfortunately not all grid implementations (especially AluGrid) provide a
1566 // default constructor for Entity, so we cannot hold it by value.
1567 }; // end of class Evaluator
1568
1573
1591 template <typename... Args>
1593 GridView const& gridView_,
1594 Args... args)
1595 : gridman(gridMan)
1596 , m_gridView(gridView_)
1597 , mapper_(m_gridView,args...)
1598 , rtf(*this,gridman)
1599 {
1600 refConnection = gridman.signals.informAboutRefinement.connect(int(GridSignals::allocResources),rtf);
1601 }
1602
1615 : gridman(gridman_)
1616 , m_gridView(m.gridView())
1617 , mapper_(m)
1618 , rtf(*this,gridman)
1619 {
1620 refConnection = gridman.signals.informAboutRefinement.connect(int(GridSignals::allocResources),rtf);
1621 }
1622
1627 gridman(fs.gridman),
1628 m_gridView(fs.m_gridView),
1629 mapper_(fs.mapper()),
1630 rtf(*this,gridman)
1631 {
1632 refConnection = gridman.signals.informAboutRefinement.connect(int(GridSignals::allocResources),rtf);
1633 }
1634
1636 {
1637 refConnection.disconnect();
1638 }
1639
1644
1649 size_t degreesOfFreedom() const { return mapper_.size(); }
1650
1654 int order(Cell<GridView> const& cell) const
1655 {
1656 return mapper().shapefunctions(cell).order();
1657 }
1658
1662 int maxOrder() const
1663 {
1664 return mapper().maxOrder();
1665 }
1666
1670
1675
1679 Grid const& grid() const { return gridman.grid(); }
1680
1685 GridManagerBase<Grid>& gridManager() const { return gridman; }
1686
1691 IndexSet const& indexSet() const { return m_gridView.indexSet(); }
1692
1696 GridView const& gridView() const { return m_gridView; }
1697
1701
1705 LocalToGlobalMapper const & mapper() const { return mapper_; }
1706
1710 LocalToGlobalMapper /* const */ & mapper() /* const */ { return mapper_; }
1711
1717 template <int m>
1719 {
1720 return Element_t<m>(*this);
1721 }
1722
1727
1733 Evaluator evaluator(ShapeFunctionCache<Grid,Scalar>* cache=nullptr, int deriv = 1) const { return Evaluator(*this,cache,deriv); }
1734
1750 std::vector<std::pair<size_t,SfValueType>> linearCombination(Evaluator const& evaluator,
1751 bool cleaned = false) const
1752 {
1753 std::vector<std::pair<size_t,SfValueType>> ic;
1754
1755 size_t esize = evaluator.size();
1756 ic.reserve(esize);
1757
1758 for (size_t j=0; j<esize; ++j)
1759 {
1760 size_t i = evaluator.globalIndices()[j];
1761 auto const& c = evaluator.evalData[j].value;
1762 ic.push_back(std::make_pair(i,c));
1763 }
1764
1765 if (cleaned)
1766 ic.erase(std::remove_if(ic.begin(),ic.end(),[](auto const& pair)
1767 { return std::abs(pair.second) < 1e-12; }),
1768 ic.end());
1769
1770 return ic;
1771 }
1772
1784 std::vector<std::pair<size_t,SfValueType>>
1786 bool cleaned=false) const
1787 {
1788 Evaluator eval(*this);
1789 eval.moveTo(cell);
1790 eval.evaluateAt(xi);
1791
1792 return linearCombination(eval,cleaned);
1793 }
1794
1807 std::vector<std::pair<size_t,SfValueType>>
1809 {
1810 auto cell = findCell(gridView(),x); // throws LookupException if no cell is found
1811 auto xi = cell.geometry().local(x); // may end up slightly outside of reference element
1812
1813 return linearCombination(cell,xi);
1814 }
1815
1819
1820 private:
1821
1822 // The slot class that connects to the grid manager signal to be informed about the
1823 // state of the refinement process.
1824 struct ReactToRefinement
1825 {
1826 ReactToRefinement(Self & space, GridManagerBase<Grid>& gm_)
1827 : mySpace(space), gm(gm_) {};
1828
1829 ReactToRefinement(ReactToRefinement const& rtr)
1830 : mySpace(rtr.mySpace)
1831 , gm(rtr.gm)
1832 {}
1833
1834 void operator()(typename GridSignals::Status const ref)
1835 {
1836 switch (ref)
1837 {
1839 assert(!future.valid());
1840 if (!mySpace.requestToRefine.empty()) // no functions registered -> nothing to do
1841 future = std::async(std::launch::async, // otherwise create transfer matrix data
1842 [&]() { transferData.reset(new TransferData<Self>(mySpace)); });
1843 break;
1844
1845 case GridSignals::BeforeRefinementComplete: // Now we need to have the data ready
1846 if (future.valid()) // (if there is any).
1847 future.get(); // Block execution until the data is complete.
1848 break;
1849
1851 mySpace.mapper().update(); // new grid available -> new indexing
1852 if(!mySpace.requestToRefine.empty()) // no functions registered -> nothing to do
1853 {
1854 assert(transferData!=0);
1855 assert(!future.valid());
1856 future = std::async(std::launch::async,
1857 [&]() {
1858 transferMatrix = transferData->transferMatrix();
1859 transferData.reset();
1860 mySpace.requestToRefine(transferMatrix.get());
1861 });
1862 }
1863 break;
1864
1866 if (future.valid())
1867 future.get();
1868 mySpace.requestToRefine(nullptr);
1869 transferMatrix.reset();
1870 }
1871 }
1872
1873 private:
1874 Self& mySpace;
1875 GridManagerBase<Grid>& gm;
1876 std::unique_ptr<TransferData<Self>> transferData;
1877 std::unique_ptr<typename TransferData<Self>::TransferMatrix> transferMatrix;
1878 std::future<void> future;
1879 };
1880
1881 GridManagerBase<Grid>& gridman;
1882 GridView m_gridView;
1883 LocalToGlobalMapper mapper_;
1884 ReactToRefinement rtf;
1885 boost::signals2::connection refConnection;
1886
1887 public:
1897 mutable typename boost::signals2::signal<void (typename TransferData<Self>::TransferMatrix const*) > requestToRefine;
1898
1899 };
1900
1901
1902
1903 //---------------------------------------------------------------------
1904 //---------------------------------------------------------------------
1905
1915 template <class Cache>
1917 {
1918 public:
1919 GetEvaluators(Cache* cache_, std::map<void const*,int> const& deriv_ = std::map<void const*,int>()):
1920 cache(cache_), deriv(deriv_)
1921 {}
1922
1923 template <class Space>
1924 typename Space::Evaluator operator()(Space const* space) const
1925 {
1926 auto it = deriv.find(space);
1927 int derivatives = it==deriv.end()? 1: it->second; // defaults to first derivatives
1928 return typename Space::Evaluator(*space,cache,derivatives);
1929 }
1930
1931 private:
1932 Cache* cache;
1933 std::map<void const*,int> const& deriv;
1934 };
1935
1943 {
1944 public:
1945 template <class Space>
1946 typename Space::Evaluator operator()(Space const*);
1947 };
1948
1960 template <class Spaces, class ShapeFunctionCache>
1961 auto getEvaluators(Spaces const& spaces, ShapeFunctionCache* cache,
1962 std::map<void const*,int> const& deriv = std::map<void const*,int>())
1963 {
1964// return boost::fusion::as_vector(boost::fusion::transform(spaces,GetEvaluators<ShapeFunctionCache>(cache,deriv)));
1965 return boost::fusion::as_vector(boost::fusion::transform(spaces,[&](auto const* space)
1966 {
1967 auto it = deriv.find(space);
1968 int derivatives = it==deriv.end()? 1: it->second; // defaults to first derivatives
1969 return space->evaluator(cache,derivatives);
1970 }));
1971 }
1972
1978 template <class Spaces>
1979 using Evaluators = typename boost::fusion::result_of::as_vector<
1980 typename boost::fusion::result_of::transform<Spaces,GetEvaluatorTypes>::type
1981 >::type;
1982
1983 //---------------------------------------------------------------------
1991 template<class Evaluators>
1992 class [[deprecated]] GetVarArgs
1993 {
1994 public:
1995 template <class T> struct result {};
1996
1997 template <class VD>
1998 struct result<GetVarArgs(VD)>
1999 {
2000 static int const sidx = VD::spaceIndex;
2001 typedef typename boost::fusion::result_of::value_at_c<Evaluators, sidx>::type::VarArg type;
2002 };
2003 };
2004
2005 //---------------------------------------------------------------------
2006
2010 template <class Evaluators, class Cell>
2011 void moveEvaluatorsToCell(Evaluators& evals, Cell const& cell)
2012 {
2013 boost::fusion::for_each(evals,[&cell](auto& eval) { eval.moveTo(cell); });
2014 }
2015
2022 template <class Evaluators, class Cell, class Index>
2023 void moveEvaluatorsToCell(Evaluators& evals, Cell const& cell, Index idx)
2024 {
2025 boost::fusion::for_each(evals,[&cell,idx](auto& eval) { eval.moveTo(cell,idx); });
2026 }
2027
2028//---------------------------------------------------------------------
2029
2034 template <class Evaluator, class QuadratureRule>
2035 void useQuadratureRuleInEvaluators(Evaluator& evals, QuadratureRule const& qr, int subId)
2036 {
2037 boost::fusion::for_each(evals,[&qr,subId](auto& eval) { eval.useQuadratureRule(qr,subId); });
2038 }
2039
2040 //---------------------------------------------------------------------
2041
2051 template <class Evaluators, class CoordType, int dim, int subDim>
2053 Dune::QuadratureRule<CoordType,subDim> const& qr, int ip, int subId)
2054 {
2055 boost::fusion::for_each(evals,[&x,&qr,ip,subId](auto& eval) { eval.evaluateAt(x,qr,ip,subId); });
2056 }
2057
2064 template <class Evaluators, class CoordType, int dim>
2066 {
2067 boost::fusion::for_each(evals,[&x](auto& eval) { eval.evaluateAt(x); });
2068 }
2069
2070 //---------------------------------------------------------------------
2071
2076 template <class Evaluators>
2077 int maxOrder(Evaluators const& evals)
2078 {
2079 auto getOrder = [](auto const& eval) -> int { return eval.order(); };
2080 auto max = [](auto a, auto b) -> int { return std::max(a,b); };
2081 return boost::fusion::fold(boost::fusion::transform(evals,getOrder),0,max);
2082 }
2083
2084} /* end of namespace Kaskade */
2085
2086#endif
A local to global mapper implementation for boundary spaces, with functions defined on the domain bou...
A representation of a finite element function space defined over a domain covered by a grid.
FEFunctionSpace(GridManagerBase< Grid > &gridman_, Mapper &&m)
Constructs a finite element space from a directly given mapper.
GridManagerBase< Grid > & gridManager() const
Access to the GridManager.
LocalToGlobalMapper::Scalar Scalar
typename Evaluator::VarArg::ValueType SfValueType
type of shape function values
LocalToGlobalMapper Mapper
corresponding mapper
Element_t< m > element() const
Creates a new function in this function space.
typename LocalToGlobalMapper::GridView GridView
Type of grid view.
size_t degreesOfFreedom() const
Returns the dimension of the function space, i.e. the number of degrees of freedom of a one-component...
int order(Cell< GridView > const &cell) const
Provides the polynomial order of shape functions on the given cell.
Evaluator evaluator(ShapeFunctionCache< Grid, Scalar > *cache=nullptr, int deriv=1) const
Creates a new evaluator for this space.
std::vector< std::pair< size_t, SfValueType > > linearCombination(Evaluator const &evaluator, bool cleaned=false) const
Returns the coefficients of the linear combination of global DoFs that define the value at the positi...
Grid const & grid() const
Provides access to the grid on which this finite element space is defined.
FEFunctionSpace(GridManagerBase< Grid > &gridMan, GridView const &gridView_, Args... args)
Constructs a finite element space from a GridManager, a grid view, and possibly extra arguments passe...
Scalar field_type
The scalar field type on which the linear (function) space is based. This is provided for consistency...
boost::signals2::signal< void(typename TransferData< Self >::TransferMatrix const *) > requestToRefine
static int const sfComponents
The number of components of shape functions.
FEFunctionSpace(FEFunctionSpace< LocalToGlobalMapper > const &fs)
Copy constructor.
std::vector< std::pair< size_t, SfValueType > > linearCombination(Cell< GridView > const &cell, LocalPosition< GridView > const &xi, bool cleaned=false) const
Returns the coefficients of the linear combination of global DoFs that define the value at the given ...
std::vector< std::pair< size_t, SfValueType > > linearCombination(GlobalPosition< GridView > const &x) const
Returns the coefficients of the linear combination of global DoFs that define the value at the given ...
int maxOrder() const
Returns the maximum polynomial order of the shape functions on any cell in the grid.
IndexSet const & indexSet() const
Provides access to the index set defining the part of the grid on which the space is defined.
LocalToGlobalMapper & mapper()
Provides read-write access to the node manager.
DiscontinuousLagrangeMapper< double, Grid > const & mapper() const
A class for representing finite element functions.
int order(SFS const &sfs) const
Self & axpy(Scalar a, StorageType const &v)
Computes for coefficient vectors.
Self & operator-=(Scalar const &val)
Subtraction of a constant value from the coefficient vector.
FunctionSpaceElement(Self &&fse)
Move constructor.
Self & operator+=(Self const &f)
Addition of a function from the same (type of) space. Note that despite the same type the function sp...
Self & operator=(Scalar val)
Sets all coefficients to the given value.
FunctionSpaceElement(Space const &fs)
Constructor.
Self & operator+=(StorageType const &v)
Addition of coefficient vectors.
Self & operator=(FunctionSpaceElement< FEFunctionSpace< BoundaryMapper< DomainMapper, Scalar, typename Space::GridView > >, m > const &bf)
Assignment from an FE function which is restricted to the boundary to a suitable FE function.
DerivativeType derivative(Cell< GridView > const &cell, LocalPosition< GridView > const &local) const
Evaluates the derivative of the FE function at the given local position inside the given cell.
Self & operator+=(Scalar val)
Addition of a constant value to the coefficient vector.
ValueType value(Cell< GridView > const &cell, LocalPosition< GridView > const &local) const
Evaluates the FE function at the specified local position in the given cell.
Self & operator=(FunctionSpaceElement< OtherSpace, m > const &f)
Assignment from functions belonging to other function spaces.
int order(Cell< GridView > const &cell) const
The polynomial order of the function on the provided cell.
HessianType hessian(GlobalPosition< GridView > const &global) const
Evaluates the FE function's Hessian at the specified global position.
Self & operator=(FunctionViewAdaptor< Space, Functor > const &f)
Assignment from a function view adaptor.
StorageValueType const & operator[](size_t i) const
EXPERIMENTAL Provides read-only access to the coefficients of the finite element basis functions.
FunctionSpaceElement(Self const &fse)
Copy constructor.
Self & operator=(Self &&fse)
Move assignment.
HessianType hessian(Cell< GridView > const &cell, LocalPosition< GridView > const &local) const
Evaluates the Hessian of the FE function at the given local position inside the given cell.
std::enable_if_t< std::is_same< Mapper, FunctionSpace_Detail::ChooseDomainMapper< typename Space::Mapper > >::value, Self & > operator=(FunctionSpaceElement< FEFunctionSpace< Mapper >, m > const &f)
Assignment from a suitable FE function to an FE function which is restricted to the boundary.
StorageType const & coefficients() const
Provides read-only access to the coefficients of the finite element basis functions.
Dune::FieldMatrix< Scalar, components, Space::dimworld > DerivativeType
Self & operator-=(StorageType const &v)
Subtraction of coefficient vectors.
Self & operator+=(FunctionSpaceElement< OtherSpace, m > const &f)
Addition of a function from a different function space, but with the same number of components.
Self & operator=(StorageType const &v)
Assignment from vector of coefficients.
ValueType value(GlobalPosition< GridView > const &x) const
Evaluates the FE function at the specified global position.
DerivativeType derivative(GlobalPosition< GridView > const &global) const
Evaluates the FE function's gradient at the specified global position.
Self & operator=(Self const &fse)
Copy assignment.
DerivativeType derivative(typename FunctionSpace::Evaluator const &evaluator) const
Evaluates the derivative of the FE function wrt global coordinates at the position used to construct ...
Self & axpy(Scalar a, FunctionSpaceElement< OtherSpace, m > const &f)
Computes for a function x from a different function space, but with the same number of components.
Tensor< Scalar, components, Space::dimworld, Space::dimworld > HessianType
Self & operator=(WeakFunctionViewAdaptor< Functor > const &f)
Assignment from a weak function view adaptor.
Self & operator-=(FunctionSpaceElement< OtherSpace, m > const &f)
Subtraction of a function from a different function space, but with the same number of components.
HessianType hessian(typename FunctionSpace::Evaluator const &evaluator) const
Evaluates the Hessian of the FE function at the position used to construct the evaluator.
Self & operator=(StorageValueType const &a)
Sets all coefficients to the given value. As StorageValueType is a vector, one value for each compone...
void transfer(typename TransferData< Space >::TransferMatrix const &transferMatrix)
StorageValueType & operator[](size_t i)
EXPERIMENTAL Provides access to the coefficients of the finite element basis functions.
Space const & space() const
Provides access to the FEFunctionSpace to which this function belongs.
ValueType value(typename Space::Evaluator const &evaluator) const
int size() const
Number of coefficient blocks.
Self & axpy(Scalar a, Self const &f)
Computes for a function x from the same (type of) space. Note that despite the same type the functio...
int dim() const
Number of scalar degrees of freedom.
Self & operator-=(Self const &f)
Subtraction of a function from the same (type of) space.
Self & operator*=(Scalar a)
Scaling.
StorageType & coefficients()
Provides access to the coefficients of the finite element basis functions.
An adaptor that allows to turn lambda functions into function views.
A boost::fusion functor for extracting the evaluator type from a pointer to a FE space....
Space::Evaluator operator()(Space const *)
Space::Evaluator operator()(Space const *space) const
GetEvaluators(Cache *cache_, std::map< void const *, int > const &deriv_=std::map< void const *, int >())
A boost::fusion functor for creating a variational arg from the space, using a shape function cache t...
Basic functionality for managing grids and their refinement.
An exception that can be thrown whenever a key lookup fails.
This class caches values and derivatives of shape functions at quadrature points.
A class for representing tensors of arbitrary static rank and extents.
Definition tensor.hh:86
Matrix that transforms a data vector v_1 corresponding to the old grid to a data vector v_2 correspon...
std::unique_ptr< Dune::BlockVector< StorageValue > > apply(Dune::BlockVector< StorageValue > const &oldCoeff) const
Transforms oldCoeff, which lives on the old grid to an equivalent vector that lives on the new grid.
std::pair< bool, size_t > unrestrictedToRestrictedIndex(size_t unrestrictedIndex)
An adaptor that turns callables (e.g., lambdas) into weak function views.
std::tuple< std::vector< typename EntryTraits< Entry >::field_type >, DynamicMatrix< typename EntryTraits< Entry >::field_type >, std::vector< int > > qr(DynamicMatrix< Entry > const &A)
Computes a rank-revealing QR decomposition of using column pivoting.
void useQuadratureRuleInEvaluators(Evaluator &evals, QuadratureRule const &qr, int subId)
Tells all evaluators to use the given quadrature rule on the given subentity.
void moveEvaluatorsToIntegrationPoint(Evaluators &evals, Dune::FieldVector< CoordType, dim > const &x, Dune::QuadratureRule< CoordType, subDim > const &qr, int ip, int subId)
Moves all provided evaluators to the given integration point, evaluating the shape functions there.
int maxOrder(Evaluators const &evals)
Computes the maximum ansatz order used in a collection of evaluators.
typename boost::fusion::result_of::as_vector< typename boost::fusion::result_of::transform< Spaces, GetEvaluatorTypes >::type >::type Evaluators
the heterogeneous sequence type of Evaluators for the given spaces
auto getEvaluators(Spaces const &spaces, ShapeFunctionCache *cache, std::map< void const *, int > const &deriv=std::map< void const *, int >())
returns a heterogeneous sequence of evaluators for the given spaces
OutIter vectorToSequence(FunctionSpaceElement< Space, m > const &v, OutIter iter)
Writes the coefficients into a flat sequence. <Space,m>
void interpolateGlobally(FSElement &fse, Function const &fu)
Interpolates FunctionSpaceElement to FunctionSpaceElement.
void interpolateGloballyWeak(Target &target, Source const &fu)
Interpolates WeakFunctionViews to FunctionSpaceElement.
ProblemType
A type for describing the nature of a PDE problem.
@ VariationalFunctional
typename GridView::template Codim< 0 >::Entity Cell
The type of cells (entities of codimension 0) in the grid view.
Definition gridBasics.hh:35
Status
The argument type of the signal that is emitted before and after grid adaptation.
std::pair< Cell, Dune::FieldVector< ctype, Cell::dimension > > findCellOnLevel(Cell cell, Dune::FieldVector< ctype, Cell::dimension > xi, int level=std::numeric_limits< int >::max())
Returns a descendant or ancestor cell of the given cell containing the specified local coordinate.
Cell< GridView > findCell(GridView const &gv, GlobalPosition< GridView > global)
Returns a cell of the given grid containing the specified global coordinate.
Dune::FieldVector< typename GridView::ctype, GridView::dimensionworld > GlobalPosition
The type of global positions within the grid view.
Definition gridBasics.hh:50
Dune::FieldVector< typename GridView::ctype, GridView::dimension > LocalPosition
The type of local positions within cells of the grid view.
Definition gridBasics.hh:59
Dune::FieldVector< T, n > max(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise maximum.
Definition fixdune.hh:73
LocalCoordinate::field_type checkInside(Dune::GeometryType const &gt, LocalCoordinate const &x)
Checks whether a point is inside or outside the reference element, and how much.
Definition fixdune.hh:692
OutIter vectorToSequence(double x, OutIter iter)
Definition crsutil.hh:30
void moveEvaluatorsToCell(Evaluators &evals, Cell const &cell)
Moves all provided evaluators to the given cell.
InIter vectorFromSequence(FunctionSpaceElement< Space, m > &v, InIter in)
DEPRECATED use Element_t<m> instead.
FunctionSpaceElement< Self, m > type
A helper class that stores all informations necessary to evaluate FE functions at a certain point.
void evaluateAt(Dune::FieldVector< ctype, dim > const &xi)
Evaluates the shape functions at the given local coordinate.
void useQuadratureRule(Dune::QuadratureRule< typename Grid::ctype, subDim > const &qr, int subId)
Tells the evaluator that subsequent calls to evaluateAt(x,qr,ip,subId) refer to the given quadrature ...
Self Space
The type of function space we belong to.
SortedIndexRange sortedIndices() const
Provides access to (global,local) index pairs sorted ascendingly by global index.
VariationalArg< Scalar, dimworld, sfComponents > VarArg
The type of variational test/ansatz arguments storing value and derivatives/hessians of restricted an...
int derivatives() const
The number of derivatives that can be evaluated.
int order() const
Returns the polynomial order of the shape functions.
static int const sfComponents
The number of components of the shape functions.
Evaluator(Self const &space_, ShapeFunctionCache< Grid, Scalar > *cache_=nullptr, int deriv_=1)
Construct a shape function evaluator for a given space, possibly using the given shape function cache...
Mapper::Combiner const & combiner() const
Returns the algebraic combiner associated to the cell.
Mapper::SortedIndexRange SortedIndexRange
A range of sorted (global index, local index) pairs.
Dune::FieldVector< ctype, dim > const & xloc() const
Returns the local coordinates of the current evaluation point.
GridView const & gridView() const
The grid view on which the space is defined.
Mapper::ShapeFunctionSet const & shapeFunctions() const
Returns the shape function set.
void moveTo(Cell const &cell)
A convenience overload, looking up the cell index itself.
Cell const & cell() const
Returns the cell containing the current evaluation point.
Mapper::GlobalIndexRange GlobalIndexRange
The type of ranges of global indices.
Kaskade::Cell< GridView > Cell
The type of cells in the grid.
LocalToGlobalMapper const & mapper() const
GlobalIndexRange globalIndices() const
Provides access to the global indices.
std::vector< VarArg > evalData
The container holding values and gradients of the global ansatz functions at the evaluation point.
Evaluator & operator=(Evaluator const &eval)
Assignment.
void evaluateAt(Dune::FieldVector< ctype, dim > const &x, Dune::QuadratureRule< typename Grid::ctype, subDim > const &qr, int ip, int subId)
Evaluates the shape functions at the given integration point of the given quadrature rule....
Evaluator(Evaluator const &eval)
Copy constructor.
void moveTo(Cell const &cell, IndexType const index)
Tells the evaluator that subsequent calls refer to the given cell.
boost::fusion::result_of::value_at_c< Evaluators, sidx >::type::VarArg type
Extracts the type of FE space with given index from set of spaces.
std::remove_pointer_t< typename boost::fusion::result_of::value_at_c< Spaces, Idx >::type > type
A class that stores values, gradients, and Hessians of evaluated shape functions.