Skip to content
Snippets Groups Projects
Commit afa1aea7 authored by Simon Praetorius's avatar Simon Praetorius
Browse files

Merge branch 'feature/clean-up-factorial-and-power' into 'master'

Use dune-common's power and factorial

See merge request !188
parents 3e2e3dbb 578b15d0
No related branches found
No related tags found
1 merge request!188Use dune-common's power and factorial
Pipeline #43108 passed
......@@ -18,7 +18,6 @@
#include <dune/common/hybridutilities.hh>
#include <dune/common/typetraits.hh>
#include <dune/common/iteratorrange.hh>
#include <dune/common/power.hh>
#include <dune/common/math.hh>
#include <dune/geometry/referenceelement.hh>
......
......@@ -41,7 +41,6 @@
#include <dune/common/fvector.hh>
#include <dune/common/iteratorfacades.hh>
#include <dune/common/power.hh>
#include <dune/geometry/referenceelements.hh>
#include <dune/geometry/axisalignedcubegeometry.hh>
......@@ -107,7 +106,7 @@ namespace Dune
nVertices(unsigned nIntervals)
{
// return (nIntervals + 1)^dim
return Power<dimension>::eval(nIntervals+1u);
return Dune::power(nIntervals+1u, unsigned(dimension));
}
template<int dimension, class CoordType>
......@@ -134,7 +133,7 @@ namespace Dune
static_assert(dimension >= 0,
"Negative dimension given, what the heck is that supposed to mean?");
// return nIntervals^dim
return Power<dimension>::eval(nIntervals);
return Dune::power(nIntervals, unsigned(dimension));
}
template<int dimension, class CoordType>
......
......@@ -102,7 +102,7 @@ namespace Dune
RefinementImp<dimension, CoordType>::
nVertices(int nIntervals)
{
return BackendRefinement::nVertices(nIntervals) * Factorial<dimension>::factorial;
return BackendRefinement::nVertices(nIntervals) * factorial(int(dimension));
}
template<int dimension, class CoordType>
......@@ -126,7 +126,7 @@ namespace Dune
RefinementImp<dimension, CoordType>::
nElements(int nIntervals)
{
return BackendRefinement::nElements(nIntervals) * Factorial<dimension>::factorial;
return BackendRefinement::nElements(nIntervals) * factorial(int(dimension));
}
template<int dimension, class CoordType>
......@@ -171,7 +171,7 @@ namespace Dune
protected:
typedef typename Refinement::BackendRefinement BackendRefinement;
typedef typename BackendRefinement::template Codim<dimension>::SubEntityIterator BackendIterator;
enum { nKuhnSimplices = Factorial<dimension>::factorial };
enum { nKuhnSimplices = factorial(int(dimension)) };
int nIntervals_;
......@@ -256,7 +256,7 @@ namespace Dune
protected:
typedef typename Refinement::BackendRefinement BackendRefinement;
typedef typename BackendRefinement::template Codim<0>::SubEntityIterator BackendIterator;
enum { nKuhnSimplices = Factorial<dimension>::factorial };
enum { nKuhnSimplices = factorial(dimension) };
int nIntervals_;
......
......@@ -249,7 +249,7 @@
#include <algorithm>
#include <dune/common/fvector.hh>
#include <dune/common/power.hh>
#include <dune/common/math.hh>
#include <dune/geometry/multilineargeometry.hh>
#include <dune/geometry/referenceelements.hh>
......@@ -279,7 +279,11 @@ namespace Dune {
/*! @brief Calculate n!
Runtime is of order O(n).
\deprecate Use factorial from dune/common/math instead. Will be
removed after Dune 2.9.
*/
[[deprecated("Use factorial from dune-common's math.hh")]]
inline int factorial(int n)
{
int prod = 1;
......@@ -291,7 +295,11 @@ namespace Dune {
/*! @brief calculate \f$\left({upper}\atop{lower}\right)\f$
Runtime is of order O(min {lower, upper-lower})
\deprecate Use binomial from dune/common/math instead. Will be
removed after Dune 2.9.
*/
[[deprecated("Use binomial from dune-common's math.hh")]]
inline int binomial(int upper, int lower)
{
lower = std::min( lower, upper - lower );
......@@ -300,7 +308,7 @@ namespace Dune {
int prod = 1;
for(int i = upper - lower; i < upper; ++i)
prod *= (i+1);
return prod / factorial(lower);
return prod / Dune::factorial(lower);
}
/*! @brief calculate the index of a given gridpoint within a
......@@ -314,7 +322,7 @@ namespace Dune {
{
int index = 0;
for(int i = 0; i < dimension; ++i)
index += binomial(dimension-i + point[i]-1, dimension-i);
index += Dune::binomial(dimension-i + point[i]-1, dimension-i);
return index;
}
......@@ -455,7 +463,7 @@ namespace Dune {
RefinementImp<dimension, CoordType>::
nVertices(int nIntervals)
{
return binomial(dimension + nIntervals, dimension);
return Dune::binomial(dimension + nIntervals, (int)dimension);
}
template<int dimension, class CoordType>
......@@ -479,7 +487,7 @@ namespace Dune {
RefinementImp<dimension, CoordType>::
nElements(int nIntervals)
{
return Dune::Power<dimension>::eval(nIntervals);
return Dune::power(nIntervals, int(dimension));
}
template<int dimension, class CoordType>
......@@ -624,7 +632,7 @@ namespace Dune {
protected:
typedef FieldVector<int, dimension> Vertex;
enum { nKuhnIntervals = Factorial<dimension>::factorial };
enum { nKuhnIntervals = Dune::factorial(dimension) };
Vertex origin;
int kuhnIndex;
......
......@@ -8,6 +8,7 @@
#include <config.h>
#include <dune/common/math.hh>
#include <dune/common/quadmath.hh>
#include <dune/geometry/referenceelements.hh>
#include <dune/geometry/quadraturerules.hh>
......@@ -72,7 +73,7 @@ ctype analyticalSolution (Dune::GeometryType t, int p, int direction )
exact = ctype( 1 );
}
else
exact = ctype( 1 ) / ctype( Dune::Factorial< pdim >::factorial * (p+1));
exact = ctype( 1 ) / ctype( Dune::factorial(pdim) * (p+1));
return exact;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment