def extract_coefficient_spaces(forms):
    """Extract a list of tuples

      (classname, finite_element_classname, dofmap_classname)

    for the coefficient spaces in the set of given forms. This can
    then be used for input to the function space template."""
    spaces = {}
    for form in forms:
        for i, name in enumerate(form.coefficient_names):
            if name in spaces:
                continue
            spaces[name] = ('CoefficientSpace_%s' % name, form.
                ufc_finite_element_classnames[form.rank + i], form.
                ufc_dofmap_classnames[form.rank + i])
    names = sorted(spaces.keys())
    return [spaces[name] for name in names]
