ufl.Max issue with Zero entry
Using ufl.Max(a,0)
or ufl.Max(a,0.)
is translated in ufl
to using ufl.constantvalue.Zero
. In the code generation process uses cplusplus.makeExpression(0)
in dune-fem/python/dune/ufl/codegen.py:293
. This leads to C++ code of std::max(a,0)
which fails if a
is a double
. We could change this to cplusplus.makeExpression(0.)
but this could now fail with integer a
.
Using std::max<double>
instead of std::max
directly would also work but lead to the same problem in cases where the return value is supposed to be an integer.
Issue: ufl.constvalue.Zero
does not store if the argument was float or integer (at least I think so).
Question: do we need to worry about cases where the return value of the maximum needs to be integer or can we use std::max<double>
in all cases in the code generation?
We could introduce our own Dune::Fem::Max
function of the form
template <class A> A Max(const A&x,const A&y) { return std::max(x,y); }
template <class I> double Max(const double&x, const I&y) { return std::max<double>(x,y); }
template <class I> double Max(const I&x, const double&y) { return std::max<double>(x,y); }