<commit_before>#ifndef DUNE_FEM_FUNCTIONALS_FUNCTIONTOOLS_HH
#define DUNE_FEM_FUNCTIONALS_FUNCTIONTOOLS_HH

// dune grid includes
#include <dune/fem/io/file/vtkio.hh>

namespace Dune {

namespace FemTools {

/**
  * \brief  Function to set a discrete function to a constant value.
  *
  *         There should be an easier way to do this in Fem, but i can't come up with one at the moment.
  **/
template <class DiscreteFunctionType>
void setDiscreteFunctionToScalarValue(DiscreteFunctionType& discreteFunction, const double& scalar)
{
  discreteFunction.clear();

  typedef typename DiscreteFunctionType::DofIteratorType DofIteratorType;
  DofIteratorType it    = discreteFunction.dbegin();
  DofIteratorType itEnd = discreteFunction.dend();
  for (; it != itEnd; ++it)
    *it = scalar;
  return;
}

/**
  * \brief  Function to write a discrete function to .vtk for visualizytion purpose.
  **/
template <class DiscreteFunctionType>
void writeDiscreteFunctionToVTK(const DiscreteFunctionType& discreteFunction,
                                const std::string filename = "discrete_function_written_by_fem_tools")
{
  typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType::GridPartType GridPartType;
  const GridPartType& gridPart = discreteFunction.space().gridPart();

  typedef Dune::VTKIO<GridPartType> VTKWriterType;
  VTKWriterType vtkWriter(gridPart);

  //    vtkWriter.addVectorVertexData( computedSolutions.discreteVelocity() );
  vtkWriter.addVertexData(discreteFunction);<commit_msg>added dimension-dependent output to writeDiscreteFunctionToVTK()<commit_after>#ifndef DUNE_FEM_FUNCTIONALS_FUNCTIONTOOLS_HH
#define DUNE_FEM_FUNCTIONALS_FUNCTIONTOOLS_HH

// dune grid includes
#include <dune/fem/io/file/vtkio.hh>

namespace Dune {

namespace FemTools {

/**
  * \brief  Function to set a discrete function to a constant value.
  *
  *         There should be an easier way to do this in Fem, but i can't come up with one at the moment.
  **/
template <class DiscreteFunctionType>
void setDiscreteFunctionToScalarValue(DiscreteFunctionType& discreteFunction, const double& scalar)
{
  discreteFunction.clear();

  typedef typename DiscreteFunctionType::DofIteratorType DofIteratorType;
  DofIteratorType it    = discreteFunction.dbegin();
  DofIteratorType itEnd = discreteFunction.dend();
  for (; it != itEnd; ++it)
    *it = scalar;
  return;
}

/**
  * \brief  Function to write a discrete function to .vtk for visualizytion purpose.
  **/
template <class DiscreteFunctionType>
void writeDiscreteFunctionToVTK(const DiscreteFunctionType& discreteFunction,
                                const std::string filename = "discrete_function_written_by_fem_tools")
{
  typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType::GridPartType GridPartType;
  const GridPartType& gridPart = discreteFunction.space().gridPart();

  typedef Dune::VTKIO<GridPartType> VTKWriterType;
  VTKWriterType vtkWriter(gridPart);

  if (DiscreteFunctionType::FunctionSpaceType::dimRange == 1)
    vtkWriter.addVertexData(discreteFunction);
  else
    vtkWriter.addVectorVertexData(discreteFunction);

{'fraction_non_alphanumeric': 0.0828782524895599, 'fraction_numerical': 0.00032123353678124, 'mean_word_length': 4.954110898661568, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4646463', 'n_tokens_mistral': 937, 'n_tokens_neox': 917, 'n_words': 228}