Skip to content
Snippets Groups Projects
Commit 39d8a9e6 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

BUG: array-bound error for SphericalTensor component-wise functions

STYEL: use constexpr for VectorSpaceOps
parent b4a047eb
No related branches found
No related tags found
No related merge requests found
......@@ -157,6 +157,34 @@ inline Cmpt magSqr(const SphericalTensor<Cmpt>& st)
}
template<class Cmpt>
inline Cmpt cmptMax(const SphericalTensor<Cmpt>& st)
{
return st.ii();
}
template<class Cmpt>
inline Cmpt cmptMin(const SphericalTensor<Cmpt>& st)
{
return st.ii();
}
template<class Cmpt>
inline Cmpt cmptSum(const SphericalTensor<Cmpt>& st)
{
return 3*st.ii();
}
template<class Cmpt>
inline Cmpt cmptAv(const SphericalTensor<Cmpt>& st)
{
return st.ii();
}
//- Return the trace of a spherical tensor
template<class Cmpt>
inline Cmpt tr(const SphericalTensor<Cmpt>& st)
......
......@@ -44,27 +44,37 @@ class VectorSpaceOps
{
public:
static const int endLoop = (I < N-1) ? 1 : 0;
//- End for next loop. Is 0 for loop termination.
static constexpr direction loopN() noexcept
{
return (I+1 < N) ? N : 0;
}
//- Index for next loop. Is 0 for loop termination.
static constexpr direction loopI1() noexcept
{
return (I+1 < N) ? I+1 : 0;
}
template<class V, class S, class EqOp>
static inline void eqOpS(V& vs, const S& s, EqOp eo)
{
eo(vs.v_[I], s);
VectorSpaceOps<endLoop*N, endLoop*(I+1)>::eqOpS(vs, s, eo);
VectorSpaceOps<loopN(), loopI1()>::eqOpS(vs, s, eo);
}
template<class S, class V, class EqOp>
static inline void SeqOp(S& s, const V& vs, EqOp eo)
{
eo(s, vs.v_[I]);
VectorSpaceOps<endLoop*N, endLoop*(I+1)>::SeqOp(s, vs, eo);
VectorSpaceOps<loopN(), loopI1()>::SeqOp(s, vs, eo);
}
template<class V1, class V2, class EqOp>
static inline void eqOp(V1& vs1, const V2& vs2, EqOp eo)
{
eo(vs1.v_[I], vs2.v_[I]);
VectorSpaceOps<endLoop*N, endLoop*(I+1)>::eqOp(vs1, vs2, eo);
VectorSpaceOps<loopN(), loopI1()>::eqOp(vs1, vs2, eo);
}
......@@ -72,25 +82,26 @@ public:
static inline void opVS(V& vs, const V1& vs1, const S& s, Op o)
{
vs.v_[I] = o(vs1.v_[I], s);
VectorSpaceOps<endLoop*N, endLoop*(I+1)>::opVS(vs, vs1, s, o);
VectorSpaceOps<loopN(), loopI1()>::opVS(vs, vs1, s, o);
}
template<class V, class S, class V1, class Op>
static inline void opSV(V& vs, const S& s, const V1& vs1, Op o)
{
vs.v_[I] = o(s, vs1.v_[I]);
VectorSpaceOps<endLoop*N, endLoop*(I+1)>::opSV(vs, s, vs1, o);
VectorSpaceOps<loopN(), loopI1()>::opSV(vs, s, vs1, o);
}
template<class V, class V1, class Op>
static inline void op(V& vs, const V1& vs1, const V1& vs2, Op o)
{
vs.v_[I] = o(vs1.v_[I], vs2.v_[I]);
VectorSpaceOps<endLoop*N, endLoop*(I+1)>::op(vs, vs1, vs2, o);
VectorSpaceOps<loopN(), loopI1()>::op(vs, vs1, vs2, o);
}
};
//- Specialization for loop termination of vector space ops
template<>
class VectorSpaceOps<0, 0>
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment