Skip to content

template specialization for processorFvPatchScalarField

@andy @Mattijs

While doing the mingw port I keep hitting a very strange compilation issue. It complains about duplicate thunks for processorFvPatchField<scalar>::initInterfaceMatrixUpdate etc. Oddly enough, it doesn't have any problem with processorFaPatchField<scalar>::initInterfaceMatrixUpdate which is structured exactly the same way.

I've looked high and low, but can't find anything indicating duplicate inclusion of the file. Also tried with including the declaration of the specialization into processorFvPatchField.H itself.

To make a virtue out of a necessity, I simply discarded the specialization and made an 'in-line' specialization within processorFvPatchField.C itself. For example,

// Consume straight from scalarReceiveBuf_
 
if (!std::is_fundamental<Type>::value)
{
    // Transform according to the transformation tensor
    transformCoupleField(scalarReceiveBuf_, cmpt);
}

This will skip the transformCoupleField for label, scalar, solveScalar etc and thus does the same as the template specialization. For C++11, the compiler will presumably be intelligent enough to remove this as unused code (depending on the type). For C++17 the if-constexpr means that it will definitely be removed, as if it were a templated bit of code.

From my perspective, I think that this would be a reasonably good change to make since it does remove some code duplication (and helps with my compilation).

  • Anything that I might be missing?
  • Any other places with template specialization could also be addressed like this?
Edited by Mark OLESEN