3 #ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_BSPLINEBASIS_HH 4 #define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_BSPLINEBASIS_HH 14 #include <dune/common/dynmatrix.hh> 16 #include <dune/localfunctions/common/localbasis.hh> 17 #include <dune/common/diagonalmatrix.hh> 18 #include <dune/localfunctions/common/localkey.hh> 19 #include <dune/localfunctions/common/localfiniteelementtraits.hh> 20 #include <dune/geometry/type.hh> 28 template<
typename GV,
typename R>
31 template<
typename GV,
class MI>
43 template<
class GV,
class R>
48 typedef typename GV::ctype D;
49 enum {dim = GV::dimension};
53 typedef LocalBasisTraits<D,dim,Dune::FieldVector<D,dim>,R,1,Dune::FieldVector<R,1>,
62 : preBasis_(preBasis),
70 std::vector<FieldVector<R,1> >& out)
const 72 FieldVector<D,dim> globalIn =
offset_;
73 scaling_.umv(in,globalIn);
75 preBasis_.evaluateFunction(globalIn, out, lFE_.currentKnotSpan_);
82 std::vector<FieldMatrix<D,1,dim> >& out)
const 84 FieldVector<D,dim> globalIn =
offset_;
85 scaling_.umv(in,globalIn);
87 preBasis_.evaluateJacobian(globalIn, out, lFE_.currentKnotSpan_);
89 for (
size_t i=0; i<out.size(); i++)
90 for (
int j=0; j<dim; j++)
91 out[i][0][j] *= scaling_[j][j];
96 inline void evaluate (
const typename std::array<int,k>& directions,
97 const typename Traits::DomainType& in,
98 std::vector<typename Traits::RangeType>& out)
const 107 FieldVector<D,dim> globalIn =
offset_;
108 scaling_.umv(in,globalIn);
110 preBasis_.evaluate(directions, globalIn, out, lFE_.currentKnotSpan_);
112 for (
size_t i=0; i<out.size(); i++)
113 out[i][0] *= scaling_[directions[0]][directions[0]];
118 FieldVector<D,dim> globalIn =
offset_;
119 scaling_.umv(in,globalIn);
121 preBasis_.evaluate(directions, globalIn, out, lFE_.currentKnotSpan_);
123 for (
size_t i=0; i<out.size(); i++)
124 out[i][0] *= scaling_[directions[0]][directions[0]]*scaling_[directions[1]][directions[1]];
128 DUNE_THROW(NotImplemented,
"B-Spline derivatives of order " << k <<
" not implemented yet!");
141 return *std::max_element(preBasis_.order_.begin(), preBasis_.order_.end());
159 DiagonalMatrix<D,dim> scaling_;
179 std::array<unsigned int,dim> multiindex (
unsigned int i)
const 181 std::array<unsigned int,dim> alpha;
182 for (
int j=0; j<dim; j++)
184 alpha[j] = i % sizes_[j];
191 void setup1d(std::vector<unsigned int>& subEntity)
202 unsigned lastIndex=0;
203 subEntity[lastIndex++] = 0;
204 for (
unsigned i = 0; i < sizes_[0] - 2; ++i)
205 subEntity[lastIndex++] = 0;
207 subEntity[lastIndex++] = 1;
209 assert(
size()==lastIndex);
212 void setup2d(std::vector<unsigned int>& subEntity)
214 unsigned lastIndex=0;
228 subEntity[lastIndex++] = 0;
229 for (
unsigned i = 0; i < sizes_[0]-2; ++i)
230 subEntity[lastIndex++] = 2;
232 subEntity[lastIndex++] = 1;
235 for (
unsigned e = 0; e < sizes_[1]-2; ++e)
237 subEntity[lastIndex++] = 0;
238 for (
unsigned i = 0; i < sizes_[0]-2; ++i)
239 subEntity[lastIndex++] = 0;
240 subEntity[lastIndex++] = 1;
244 subEntity[lastIndex++] = 2;
245 for (
unsigned i = 0; i < sizes_[0]-2; ++i)
246 subEntity[lastIndex++] = 3;
248 subEntity[lastIndex++] = 3;
250 assert(
size()==lastIndex);
255 void init(
const std::array<unsigned,dim>& sizes)
262 std::vector<unsigned int> codim(li_.size());
264 for (std::size_t i=0; i<codim.size(); i++)
269 std::array<unsigned int,dim> mIdx = multiindex(i);
270 for (
int j=0; j<dim; j++)
271 if (mIdx[j]==0 or mIdx[j]==sizes[j]-1)
280 std::vector<unsigned int> index(
size());
282 for (std::size_t i=0; i<index.size(); i++)
286 std::array<unsigned int,dim> mIdx = multiindex(i);
288 for (
int j=dim-1; j>=0; j--)
289 if (mIdx[j]>0 and mIdx[j]<sizes[j]-1)
290 index[i] = (sizes[j]-1)*index[i] + (mIdx[j]-1);
294 std::vector<unsigned int> subEntity(li_.size());
296 if (subEntity.size() > 0)
302 }
else if (dim==2 and sizes_[0]>1 and sizes_[1]>1) {
309 for (
size_t i=0; i<li_.size(); i++)
310 li_[i] = LocalKey(subEntity[i], codim[i], index[i]);
316 return std::accumulate(sizes_.begin(), sizes_.end(), 1, std::multiplies<unsigned int>());
328 std::array<unsigned, dim> sizes_;
330 std::vector<LocalKey> li_;
337 template<
int dim,
class LB>
342 template<
typename F,
typename C>
345 DUNE_THROW(NotImplemented,
"BSplineLocalInterpolation::interpolate");
360 template<
class GV,
class R>
363 typedef typename GV::ctype D;
364 enum {dim = GV::dimension};
370 typedef LocalFiniteElementTraits<BSplineLocalBasis<GV,R>,
377 : preBasis_(preBasis),
378 localBasis_(preBasis,*this)
387 void bind(
const std::array<unsigned,dim>& elementIdx)
390 for (
size_t i=0; i<elementIdx.size(); i++)
392 currentKnotSpan_[i] = 0;
395 while (preBasis_.knotVectors_[i][currentKnotSpan_[i]+1] < preBasis_.knotVectors_[i][currentKnotSpan_[i]]+1e-8)
396 currentKnotSpan_[i]++;
398 for (
size_t j=0; j<elementIdx[i]; j++)
400 currentKnotSpan_[i]++;
403 while (preBasis_.knotVectors_[i][currentKnotSpan_[i]+1] < preBasis_.knotVectors_[i][currentKnotSpan_[i]]+1e-8)
404 currentKnotSpan_[i]++;
408 localBasis_.offset_[i] = preBasis_.knotVectors_[i][currentKnotSpan_[i]];
409 localBasis_.scaling_[i][i] = preBasis_.knotVectors_[i][currentKnotSpan_[i]+1] - preBasis_.knotVectors_[i][currentKnotSpan_[i]];
413 std::array<unsigned int, dim> sizes;
414 for (
size_t i=0; i<dim; i++)
416 localCoefficients_.init(sizes);
428 return localCoefficients_;
434 return localInterpolation_;
441 for (
int i=0; i<dim; i++)
450 return GeometryType(GeometryType::cube,dim);
458 const auto&
order = preBasis_.order_;
459 unsigned int r =
order[i]+1;
460 if (currentKnotSpan_[i]<
order[i])
461 r -= (
order[i] - currentKnotSpan_[i]);
462 if (
order[i] > (preBasis_.knotVectors_[i].size() - currentKnotSpan_[i] - 2) )
463 r -=
order[i] - (preBasis_.knotVectors_[i].size() - currentKnotSpan_[i] - 2);
478 template<
typename GV,
typename TP>
481 template<
typename GV,
class MI,
class TP>
494 template<
typename GV,
class MI>
497 static const int dim = GV::dimension;
500 class MultiDigitCounter
507 MultiDigitCounter(
const std::array<unsigned int,dim>& limits)
510 std::fill(counter_.begin(), counter_.end(), 0);
514 MultiDigitCounter& operator++()
516 for (
int i=0; i<dim; i++)
521 if (counter_[i] < limits_[i])
530 const unsigned int& operator[](
int i)
const 536 unsigned int cycle()
const 539 for (
int i=0; i<dim; i++)
547 const std::array<unsigned int,dim> limits_;
550 std::array<unsigned int,dim> counter_;
593 const std::vector<double>& knotVector,
595 bool makeOpen =
true)
596 : gridView_(gridView)
599 std::fill(elements_.begin(), elements_.end(), knotVector.size()-1);
603 assert( std::accumulate(elements_.begin(), elements_.end(), 1, std::multiplies<unsigned>()) == gridView_.size(0) );
605 for (
int i=0; i<dim; i++)
610 for (
unsigned int j=0; j<
order; j++)
611 knotVectors_[i].push_back(knotVector[0]);
613 knotVectors_[i].insert(knotVectors_[i].end(), knotVector.begin(), knotVector.end());
616 for (
unsigned int j=0; j<
order; j++)
617 knotVectors_[i].push_back(knotVector.back());
620 std::fill(order_.begin(), order_.end(),
order);
645 const FieldVector<double,dim>& lowerLeft,
646 const FieldVector<double,dim>& upperRight,
647 const std::array<unsigned int,dim>& elements,
649 bool makeOpen =
true)
650 : elements_(elements),
655 assert( std::accumulate(elements_.begin(), elements_.end(), 1, std::multiplies<unsigned>()) == gridView_.size(0) );
657 for (
int i=0; i<dim; i++)
662 for (
unsigned int j=0; j<
order; j++)
663 knotVectors_[i].push_back(lowerLeft[i]);
666 for (
size_t j=0; j<elements[i]+1; j++)
667 knotVectors_[i].push_back(lowerLeft[i] + j*(upperRight[i]-lowerLeft[i]) / elements[i]);
670 for (
unsigned int j=0; j<
order; j++)
671 knotVectors_[i].push_back(upperRight[i]);
674 std::fill(order_.begin(), order_.end(),
order);
727 assert(prefix.size() == 0 || prefix.size() == 1);
728 return (prefix.size() == 0) ?
size() : 0;
741 for (
int i=0; i<dim; i++)
742 result *= order_[i]+1;
749 unsigned int result = 1;
750 for (
size_t i=0; i<dim; i++)
756 unsigned int size (
size_t d)
const 758 return knotVectors_[d].size() - order_[d] - 1;
764 std::vector<FieldVector<R,1> >& out,
765 const std::array<unsigned,dim>& currentKnotSpan)
const 768 std::array<std::vector<R>, dim> oneDValues;
770 for (
size_t i=0; i<dim; i++)
771 evaluateFunction(in[i], oneDValues[i], knotVectors_[i], order_[i], currentKnotSpan[i]);
773 std::array<unsigned int, dim> limits;
774 for (
int i=0; i<dim; i++)
775 limits[i] = oneDValues[i].
size();
777 MultiDigitCounter ijkCounter(limits);
779 out.resize(ijkCounter.cycle());
781 for (
size_t i=0; i<out.size(); i++, ++ijkCounter)
784 for (
size_t j=0; j<dim; j++)
785 out[i] *= oneDValues[j][ijkCounter[j]];
795 std::vector<FieldMatrix<R,1,dim> >& out,
796 const std::array<unsigned,dim>& currentKnotSpan)
const 799 std::array<unsigned int, dim> limits;
800 for (
int i=0; i<dim; i++)
802 limits[i] = order_[i]+1;
803 if (currentKnotSpan[i]<order_[i])
804 limits[i] -= (order_[i] - currentKnotSpan[i]);
805 if ( order_[i] > (knotVectors_[i].
size() - currentKnotSpan[i] - 2) )
806 limits[i] -= order_[i] - (knotVectors_[i].
size() - currentKnotSpan[i] - 2);
810 std::array<unsigned int, dim> offset;
811 for (
int i=0; i<dim; i++)
812 offset[i] = std::max((
int)(currentKnotSpan[i] - order_[i]),0);
815 std::array<std::vector<R>, dim> oneDValues;
818 std::array<std::vector<R>, dim> lowOrderOneDValues;
820 std::array<DynamicMatrix<R>, dim> values;
822 for (
size_t i=0; i<dim; i++)
824 evaluateFunctionFull(in[i], values[i], knotVectors_[i], order_[i], currentKnotSpan[i]);
825 oneDValues[i].resize(knotVectors_[i].
size()-order_[i]-1);
826 for (
size_t j=0; j<oneDValues[i].size(); j++)
827 oneDValues[i][j] = values[i][order_[i]][j];
831 lowOrderOneDValues[i].resize(knotVectors_[i].
size()-(order_[i]-1)-1);
832 for (
size_t j=0; j<lowOrderOneDValues[i].size(); j++)
833 lowOrderOneDValues[i][j] = values[i][order_[i]-1][j];
839 std::array<std::vector<R>, dim> oneDDerivatives;
840 for (
size_t i=0; i<dim; i++)
842 oneDDerivatives[i].resize(limits[i]);
845 std::fill(oneDDerivatives[i].begin(), oneDDerivatives[i].end(),
R(0.0));
848 for (
size_t j=offset[i]; j<offset[i]+limits[i]; j++)
850 R derivativeAddend1 = lowOrderOneDValues[i][j] / (knotVectors_[i][j+order_[i]]-knotVectors_[i][j]);
851 R derivativeAddend2 = lowOrderOneDValues[i][j+1] / (knotVectors_[i][j+order_[i]+1]-knotVectors_[i][j+1]);
853 if (std::isnan(derivativeAddend1))
854 derivativeAddend1 = 0;
855 if (std::isnan(derivativeAddend2))
856 derivativeAddend2 = 0;
857 oneDDerivatives[i][j-offset[i]] = order_[i] * ( derivativeAddend1 - derivativeAddend2 );
864 std::array<std::vector<R>, dim> oneDValuesShort;
866 for (
int i=0; i<dim; i++)
868 oneDValuesShort[i].resize(limits[i]);
870 for (
size_t j=0; j<limits[i]; j++)
871 oneDValuesShort[i][j] = oneDValues[i][offset[i] + j];
877 MultiDigitCounter ijkCounter(limits);
879 out.resize(ijkCounter.cycle());
882 for (
size_t i=0; i<out.size(); i++, ++ijkCounter)
883 for (
int j=0; j<dim; j++)
886 for (
int k=0; k<dim; k++)
887 out[i][0][j] *= (j==k) ? oneDDerivatives[k][ijkCounter[k]]
888 : oneDValuesShort[k][ijkCounter[k]];
894 template <
size_type k>
895 void evaluate(
const typename std::array<int,k>& directions,
896 const FieldVector<typename GV::ctype,dim>& in,
897 std::vector<FieldVector<R,1> >& out,
898 const std::array<unsigned,dim>& currentKnotSpan)
const 900 if (k != 1 && k != 2)
901 DUNE_THROW(RangeError,
"Differentiation order greater than 2 is not supported!");
904 std::array<std::vector<R>, dim> oneDValues;
905 std::array<std::vector<R>, dim> oneDDerivatives;
906 std::array<std::vector<R>, dim> oneDSecondDerivatives;
910 for (
size_t i=0; i<dim; i++)
911 evaluateAll(in[i], oneDValues[i],
true, oneDDerivatives[i],
false, oneDSecondDerivatives[i], knotVectors_[i], order_[i], currentKnotSpan[i]);
913 for (
size_t i=0; i<dim; i++)
914 evaluateAll(in[i], oneDValues[i],
true, oneDDerivatives[i],
true, oneDSecondDerivatives[i], knotVectors_[i], order_[i], currentKnotSpan[i]);
917 std::array<unsigned int, dim> offset;
918 for (
int i=0; i<dim; i++)
919 offset[i] = std::max((
int)(currentKnotSpan[i] - order_[i]),0);
922 std::array<unsigned int, dim> limits;
923 for (
int i=0; i<dim; i++)
927 limits[i] = order_[i]+1;
928 if (currentKnotSpan[i]<order_[i])
929 limits[i] -= (order_[i] - currentKnotSpan[i]);
930 if ( order_[i] > (knotVectors_[i].
size() - currentKnotSpan[i] - 2) )
931 limits[i] -= order_[i] - (knotVectors_[i].
size() - currentKnotSpan[i] - 2);
936 std::array<std::vector<R>, dim> oneDValuesShort;
938 for (
int i=0; i<dim; i++)
940 oneDValuesShort[i].resize(limits[i]);
942 for (
size_t j=0; j<limits[i]; j++)
943 oneDValuesShort[i][j] = oneDValues[i][offset[i] + j];
947 MultiDigitCounter ijkCounter(limits);
949 out.resize(ijkCounter.cycle());
954 for (
size_t i=0; i<out.size(); i++, ++ijkCounter)
957 for (
int l=0; l<dim; l++)
958 out[i][0] *= (directions[0]==l) ? oneDDerivatives[l][ijkCounter[l]]
959 : oneDValuesShort[l][ijkCounter[l]];
966 for (
size_t i=0; i<out.size(); i++, ++ijkCounter)
969 for (
int j=0; j<dim; j++)
971 if (directions[0] != directions[1])
972 if (directions[0] == j || directions[1] == j)
973 out[i][0] *= oneDDerivatives[j][ijkCounter[j]];
975 out[i][0] *= oneDValuesShort[j][ijkCounter[j]];
977 if (directions[0] == j)
978 out[i][0] *= oneDSecondDerivatives[j][ijkCounter[j]];
980 out[i][0] *= oneDValuesShort[j][ijkCounter[j]];
991 static std::array<unsigned int,dim>
getIJK(
typename GridView::IndexSet::IndexType idx, std::array<unsigned int,dim> elements)
993 std::array<unsigned,dim> result;
994 for (
int i=0; i<dim; i++)
996 result[i] = idx%elements[i];
1011 const std::vector<R>& knotVector,
1013 unsigned int currentKnotSpan)
1015 std::size_t outSize = order+1;
1016 if (currentKnotSpan<order)
1017 outSize -= (order - currentKnotSpan);
1018 if ( order > (knotVector.size() - currentKnotSpan - 2) )
1019 outSize -= order - (knotVector.size() - currentKnotSpan - 2);
1020 out.resize(outSize);
1023 DynamicMatrix<R> N(order+1, knotVector.size()-1);
1031 for (
size_t i=0; i<knotVector.size()-1; i++)
1032 N[0][i] = (i == currentKnotSpan);
1034 for (
size_t r=1; r<=
order; r++)
1035 for (
size_t i=0; i<knotVector.size()-r-1; i++)
1037 R factor1 = ((knotVector[i+r] - knotVector[i]) > 1e-10)
1038 ? (in - knotVector[i]) / (knotVector[i+r] - knotVector[i])
1040 R factor2 = ((knotVector[i+r+1] - knotVector[i+1]) > 1e-10)
1041 ? (knotVector[i+r+1] - in) / (knotVector[i+r+1] - knotVector[i+1])
1043 N[r][i] = factor1 * N[r-1][i] + factor2 * N[r-1][i+1];
1050 for (
size_t i=0; i<out.size(); i++) {
1051 out[i] = N[
order][std::max((
int)(currentKnotSpan - order),0) + i];
1068 DynamicMatrix<R>& out,
1069 const std::vector<R>& knotVector,
1071 unsigned int currentKnotSpan)
1074 DynamicMatrix<R>& N = out;
1076 N.resize(order+1, knotVector.size()-1);
1084 for (
size_t i=0; i<knotVector.size()-1; i++)
1085 N[0][i] = (i == currentKnotSpan);
1087 for (
size_t r=1; r<=
order; r++)
1088 for (
size_t i=0; i<knotVector.size()-r-1; i++)
1090 R factor1 = ((knotVector[i+r] - knotVector[i]) > 1e-10)
1091 ? (in - knotVector[i]) / (knotVector[i+r] - knotVector[i])
1093 R factor2 = ((knotVector[i+r+1] - knotVector[i+1]) > 1e-10)
1094 ? (knotVector[i+r+1] - in) / (knotVector[i+r+1] - knotVector[i+1])
1096 N[r][i] = factor1 * N[r-1][i] + factor2 * N[r-1][i+1];
1111 std::vector<R>& out,
1113 bool evaluateHessian, std::vector<R>& outHess,
1114 const std::vector<R>& knotVector,
1116 unsigned int currentKnotSpan)
1121 if (currentKnotSpan<order)
1122 limit -= (order - currentKnotSpan);
1123 if ( order > (knotVector.size() - currentKnotSpan - 2) )
1124 limit -= order - (knotVector.size() - currentKnotSpan - 2);
1127 unsigned int offset;
1128 offset = std::max((
int)(currentKnotSpan - order),0);
1131 DynamicMatrix<R> values;
1133 evaluateFunctionFull(in, values, knotVector, order, currentKnotSpan);
1135 out.resize(knotVector.size()-order-1);
1136 for (
size_t j=0; j<out.size(); j++)
1137 out[j] = values[order][j];
1140 std::vector<R> lowOrderOneDValues;
1144 lowOrderOneDValues.resize(knotVector.size()-(order-1)-1);
1145 for (
size_t j=0; j<lowOrderOneDValues.size(); j++)
1146 lowOrderOneDValues[j] = values[order-1][j];
1150 std::vector<R> lowOrderTwoDValues;
1152 if (order>1 && evaluateHessian)
1154 lowOrderTwoDValues.resize(knotVector.size()-(order-2)-1);
1155 for (
size_t j=0; j<lowOrderTwoDValues.size(); j++)
1156 lowOrderTwoDValues[j] = values[order-2][j];
1160 if (evaluateJacobian)
1162 outJac.resize(limit);
1165 std::fill(outJac.begin(), outJac.end(),
R(0.0));
1168 for (
size_t j=offset; j<offset+limit; j++)
1170 R derivativeAddend1 = lowOrderOneDValues[j] / (knotVector[j+
order]-knotVector[j]);
1171 R derivativeAddend2 = lowOrderOneDValues[j+1] / (knotVector[j+order+1]-knotVector[j+1]);
1173 if (std::isnan(derivativeAddend1))
1174 derivativeAddend1 = 0;
1175 if (std::isnan(derivativeAddend2))
1176 derivativeAddend2 = 0;
1177 outJac[j-offset] = order * ( derivativeAddend1 - derivativeAddend2 );
1183 if (evaluateHessian)
1185 outHess.resize(limit);
1188 std::fill(outHess.begin(), outHess.end(),
R(0.0));
1191 for (
size_t j=offset; j<offset+limit; j++)
1193 assert(j+2 < lowOrderTwoDValues.size());
1194 R derivativeAddend1 = lowOrderTwoDValues[j] / (knotVector[j+
order]-knotVector[j]) / (knotVector[j+order-1]-knotVector[j]);
1195 R derivativeAddend2 = lowOrderTwoDValues[j+1] / (knotVector[j+
order]-knotVector[j]) / (knotVector[j+order]-knotVector[j+1]);
1196 R derivativeAddend3 = lowOrderTwoDValues[j+1] / (knotVector[j+order+1]-knotVector[j+1]) / (knotVector[j+order]-knotVector[j+1]);
1197 R derivativeAddend4 = lowOrderTwoDValues[j+2] / (knotVector[j+order+1]-knotVector[j+1]) / (knotVector[j+1+order]-knotVector[j+2]);
1200 if (std::isnan(derivativeAddend1))
1201 derivativeAddend1 = 0;
1202 if (std::isnan(derivativeAddend2))
1203 derivativeAddend2 = 0;
1204 if (std::isnan(derivativeAddend3))
1205 derivativeAddend3 = 0;
1206 if (std::isnan(derivativeAddend4))
1207 derivativeAddend4 = 0;
1208 outHess[j-offset] = order * (order-1) * ( derivativeAddend1 - derivativeAddend2 -derivativeAddend3 + derivativeAddend4 );
1229 template<
typename GV,
typename TP>
1233 static const int dim = GV::dimension;
1241 using Element =
typename GV::template Codim<0>::Entity;
1246 preBasis_(preBasis),
1247 finiteElement_(*preBasis)
1262 return finiteElement_;
1269 auto elementIndex = preBasis_->gridView().indexSet().index(e);
1270 finiteElement_.bind(preBasis_->getIJK(elementIndex,preBasis_->elements_));
1271 this->setSize(finiteElement_.size());
1284 template<
typename GV,
class MI,
class TP>
1287 enum {dim = GV::dimension};
1301 preBasis_(&preBasis)
1314 for (
int i=0; i<dim; i++)
1315 localSizes_[i] = node_->finiteElement().size(i);
1329 return node_->finiteElement().size();
1333 template<
typename It>
1338 std::array<unsigned int,dim> localIJK = preBasis_->getIJK(i, localSizes_);
1340 const auto currentKnotSpan = node_->finiteElement().currentKnotSpan_;
1341 const auto order = preBasis_->order_;
1343 std::array<unsigned int,dim> globalIJK;
1344 for (
int i=0; i<dim; i++)
1345 globalIJK[i] = std::max((
int)currentKnotSpan[i] - (
int)
order[i], 0) + localIJK[i];
1350 for (
int i=dim-2; i>=0; i--)
1351 globalIdx = globalIdx * preBasis_->size(i) + globalIJK[i];
1353 *it = {{globalIdx}};
1378 template<
typename GV>
1386 #endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_BSPLINEBASIS_HH const PreBasis * preBasis_
Definition: bsplinebasis.hh:1359
std::array< unsigned int, dim > localSizes_
Definition: bsplinebasis.hh:1363
typename PreBasis::template Node< TP > Node
Definition: bsplinebasis.hh:1298
void bind(const Element &e)
Bind to element.
Definition: bsplinebasis.hh:1266
typename GV::template Codim< 0 >::Entity Element
Definition: bsplinebasis.hh:1241
const size_type offset_
Definition: nodes.hh:40
IndexSet< TP > indexSet() const
Create tree node index set with given root tree path.
Definition: bsplinebasis.hh:719
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: bsplinebasis.hh:1294
std::size_t size() const
number of coefficients
Definition: bsplinebasis.hh:314
double R
Definition: bsplinebasis.hh:572
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: bsplinebasis.hh:682
Node< TP > node(const TP &tp) const
Create tree node with given root tree path.
Definition: bsplinebasis.hh:704
LocalBasis class in the sense of dune-localfunctions, presenting the restriction of a B-spline patch ...
Definition: bsplinebasis.hh:44
BSplinePreBasis(const GridView &gridView, const std::vector< double > &knotVector, unsigned int order, bool makeOpen=true)
Construct a B-spline basis for a given grid view and set of knot vectors.
Definition: bsplinebasis.hh:592
size_type size(const SizePrefix prefix) const
Return number of possible values for next position in multi index.
Definition: bsplinebasis.hh:725
void bind(const std::array< unsigned, dim > &elementIdx)
Bind LocalFiniteElement to a specific knot span of the spline patch.
Definition: bsplinebasis.hh:387
const BSplineLocalCoefficients< dim > & localCoefficients() const
Hand out a LocalCoefficients object.
Definition: bsplinebasis.hh:426
BSplinePreBasis(const GridView &gridView, const FieldVector< double, dim > &lowerLeft, const FieldVector< double, dim > &upperRight, const std::array< unsigned int, dim > &elements, unsigned int order, bool makeOpen=true)
Construct a B-spline basis for a given grid view with uniform knot vectors.
Definition: bsplinebasis.hh:644
std::size_t size_type
Definition: bsplinebasis.hh:1239
BSplineNodeIndexSet(const PreBasis &preBasis)
Definition: bsplinebasis.hh:1300
std::array< unsigned, dim > elements_
Number of grid elements in the different coordinate directions.
Definition: bsplinebasis.hh:1222
LocalBasisTraits< D, dim, Dune::FieldVector< D, dim >, R, 1, Dune::FieldVector< R, 1 >, Dune::FieldMatrix< R, 1, dim > > Traits
export type traits for function signature
Definition: bsplinebasis.hh:54
void init(const std::array< unsigned, dim > &sizes)
Definition: bsplinebasis.hh:255
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: bsplinebasis.hh:738
FiniteElement finiteElement_
Definition: bsplinebasis.hh:1278
GeometryType type() const
Return the reference element that the local finite element is defined on (here, a hypercube) ...
Definition: bsplinebasis.hh:448
std::size_t size_type
Definition: bsplinebasis.hh:558
unsigned int size() const
Total number of B-spline basis functions.
Definition: bsplinebasis.hh:747
void evaluate(const typename std::array< int, k > &directions, const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions and derivatives of any order.
Definition: bsplinebasis.hh:96
unsigned int size(size_t d) const
Number of shape functions in one direction.
Definition: bsplinebasis.hh:756
Local interpolation in the sense of dune-localfunctions, for the B-spline basis on tensor-product gri...
Definition: bsplinebasis.hh:338
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:42
void unbind()
Unbind the view.
Definition: bsplinebasis.hh:1320
Pre-basis for B-spline basis.
Definition: bsplinebasis.hh:32
void evaluateJacobian(const FieldVector< typename GV::ctype, dim > &in, std::vector< FieldMatrix< R, 1, dim > > &out, const std::array< unsigned, dim > ¤tKnotSpan) const
Evaluate Jacobian of all B-spline basis functions.
Definition: bsplinebasis.hh:794
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: bsplinebasis.hh:688
const BSplinePreBasis< GV, FlatMultiIndex< std::size_t > > * preBasis_
Definition: bsplinebasis.hh:1276
void interpolate(const F &f, std::vector< C > &out) const
Local interpolation of a function.
Definition: bsplinebasis.hh:343
std::array< unsigned int, dim > order_
Order of the B-spline for each space dimension.
Definition: bsplinebasis.hh:1216
void bind(const Node &node)
Bind the view to a grid element.
Definition: bsplinebasis.hh:1309
size_type size() const
Size of subtree rooted in this node (element-local)
Definition: bsplinebasis.hh:1327
A multi-index class with only one level.
Definition: flatmultiindex.hh:31
static std::array< unsigned int, dim > getIJK(typename GridView::IndexSet::IndexType idx, std::array< unsigned int, dim > elements)
Compute integer element coordinates from the element index.
Definition: bsplinebasis.hh:991
Definition: bsplinebasis.hh:482
std::array< std::vector< double >, dim > knotVectors_
The knot vectors, one for each space dimension.
Definition: bsplinebasis.hh:1219
static void evaluateAll(const typename GV::ctype &in, std::vector< R > &out, bool evaluateJacobian, std::vector< R > &outJac, bool evaluateHessian, std::vector< R > &outHess, const std::vector< R > &knotVector, unsigned int order, unsigned int currentKnotSpan)
Evaluate the second derivatives of all one-dimensional B-spline functions for a given coordinate dire...
Definition: bsplinebasis.hh:1110
Attaches a shape function to an entity.
Definition: bsplinebasis.hh:176
LocalFiniteElement in the sense of dune-localfunctions, for the B-spline basis on tensor-product grid...
Definition: bsplinebasis.hh:29
const Node * node_
Definition: bsplinebasis.hh:1361
unsigned int order() const
Polynomial order of the shape functions.
Definition: bsplinebasis.hh:139
BSplineLocalBasis< GV, R > localBasis_
Definition: bsplinebasis.hh:469
void evaluateFunction(const FieldVector< typename GV::ctype, dim > &in, std::vector< FieldVector< R, 1 > > &out, const std::array< unsigned, dim > ¤tKnotSpan) const
Evaluate all B-spline basis functions at a given point.
Definition: bsplinebasis.hh:763
const BSplinePreBasis< GV, FlatMultiIndex< std::size_t > > & preBasis_
Definition: bsplinebasis.hh:467
unsigned size() const
Number of shape functions in this finite element.
Definition: bsplinebasis.hh:438
const BSplineLocalInterpolation< dim, BSplineLocalBasis< GV, R > > & localInterpolation() const
Hand out a LocalInterpolation object.
Definition: bsplinebasis.hh:432
void evaluateJacobian(const FieldVector< D, dim > &in, std::vector< FieldMatrix< D, 1, dim > > &out) const
Evaluate Jacobian of all shape functions.
Definition: bsplinebasis.hh:81
GV GridView
The grid view that the FE space is defined on.
Definition: bsplinebasis.hh:557
Definition: bsplinebasis.hh:479
void evaluateFunction(const FieldVector< D, dim > &in, std::vector< FieldVector< R, 1 > > &out) const
Evaluate all shape functions.
Definition: bsplinebasis.hh:69
std::size_t size_type
Definition: bsplinebasis.hh:1291
std::array< unsigned, dim > currentKnotSpan_
Definition: bsplinebasis.hh:474
GridView gridView_
Definition: bsplinebasis.hh:1224
void initializeIndices()
Initialize the global indices.
Definition: bsplinebasis.hh:678
Definition: polynomial.hh:7
const LocalKey & localKey(std::size_t i) const
get i'th index
Definition: bsplinebasis.hh:320
static void evaluateFunctionFull(const typename GV::ctype &in, DynamicMatrix< R > &out, const std::vector< R > &knotVector, unsigned int order, unsigned int currentKnotSpan)
Evaluate all one-dimensional B-spline functions for a given coordinate direction. ...
Definition: bsplinebasis.hh:1067
const FiniteElement & finiteElement() const
Return the LocalFiniteElement for the element we are bound to.
Definition: bsplinebasis.hh:1260
BSplineLocalBasis(const BSplinePreBasis< GV, FlatMultiIndex< std::size_t >> &preBasis, const BSplineLocalFiniteElement< GV, R > &lFE)
Constructor with a given B-spline patch.
Definition: bsplinebasis.hh:60
static void evaluateFunction(const typename GV::ctype &in, std::vector< R > &out, const std::vector< R > &knotVector, unsigned int order, unsigned int currentKnotSpan)
Evaluate all one-dimensional B-spline functions for a given coordinate direction. ...
Definition: bsplinebasis.hh:1010
const BSplineLocalBasis< GV, R > & localBasis() const
Hand out a LocalBasis object.
Definition: bsplinebasis.hh:420
Dune::ReservedVector< size_type, 1 > SizePrefix
Definition: bsplinebasis.hh:569
std::size_t size() const
Return the number of basis functions on the current knot span.
Definition: bsplinebasis.hh:146
BSplineLocalFiniteElement(const BSplinePreBasis< GV, FlatMultiIndex< std::size_t >> &preBasis)
Constructor with a given B-spline basis.
Definition: bsplinebasis.hh:376
BSplineLocalCoefficients< dim > localCoefficients_
Definition: bsplinebasis.hh:470
BSplineNode(const TreePath &treePath, const BSplinePreBasis< GV, FlatMultiIndex< std::size_t >> *preBasis)
Definition: bsplinebasis.hh:1244
Element element_
Definition: bsplinebasis.hh:1279
TP TreePath
Definition: bsplinebasis.hh:1240
It indices(It it) const
Maps from subtree index set [0..size-1] to a globally unique multi index in global basis...
Definition: bsplinebasis.hh:1334
void evaluate(const typename std::array< int, k > &directions, const FieldVector< typename GV::ctype, dim > &in, std::vector< FieldVector< R, 1 > > &out, const std::array< unsigned, dim > ¤tKnotSpan) const
Evaluate Derivatives of all B-spline basis functions.
Definition: bsplinebasis.hh:895
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: bsplinebasis.hh:732
LocalFiniteElementTraits< BSplineLocalBasis< GV, R >, BSplineLocalCoefficients< dim >, BSplineLocalInterpolation< dim, BSplineLocalBasis< GV, R > > > Traits
Export various types related to this LocalFiniteElement.
Definition: bsplinebasis.hh:372
unsigned int size(int i) const
Number of degrees of freedom for one coordinate direction.
Definition: bsplinebasis.hh:456
BSplineLocalInterpolation< dim, BSplineLocalBasis< GV, R > > localInterpolation_
Definition: bsplinebasis.hh:471
const Element & element() const
Return current element, throw if unbound.
Definition: bsplinebasis.hh:1251