Using magnitudeType for coordinates in MueLu
Created by: etphipp
@trilinos/muelu @kliegeois
MueLu developers,
I have a student, @kliegeois, working on a modification of one of Stokhos' scalar types that changes Teuchos::ScalarTraits::magnitudeType to something other than a builtin type, and we are running into many issues in MueLu, where magnitudeType is feely converted to/from double. The issue seems to be that the interface for mesh coordinates takes vectors of magnitudeType, but the implementation often assigns these values to double types. We started converting most of this code to use magnitudeType throughout, but this is becoming untenable and we are wondering what the right path forward is.
It seems to me that using magnitudeType for coordinates is something of an abuse of what magnitudeType is supposed to represent, since it is supposed to represent magnitudes (i.e., real, non-negative numbers). What would you think of introducing a new type trait for coordinates that would compute the coordinate type from the scalar type, but be divorced from magnitudeType? This could be done using Teuchos::ScalarTraits (e.g., Teuchos::ScalarTraits::coordinateType), or MueLu could introduce its own trait, something like:
// Default implementation where CoordinateTraits<Scalar>::type == Scalar
template <class Scalar>
struct CoordinateTraits {
typedef Scalar type;
};
// Specialization for std::complex<>
template <class T> {
struct CoordinateTraits< std::complex<T> > {
typedef T type;
};
Then Stokhos would then provide its own specialization where CoordinateTraits<>::type is a builtin type.
To me, this seems like the right way to do this. If someone wanted to use, e.g., extended precision types, then magnitudeType would be extended precision (and therefore not safely convertible to double), but it seems very unlikely that anyone would want the coordinate type to be extended precision.