Skip to content

Draft: Access to individual DoFs

Marcus Mohr requested to merge mohr/ReadWriteDoF-draft into master


The idea of this suggested extension is to allow read/write access to individual degrees of freedom of a FE-function from the outside. IMHO this could provide an easy and practical way for users to implement functionality that is currently not (directly) representable by the available function class methods. We see that in these cases either existing methods, such as e.g. interpolate(), are creatively (mis)used to accomplish the respective goal, or needlessly expensive workarounds, such as e.g. velocityMaxMagnitude() from CFDHelpers.cpp need to be implemented.


In the current proof-of-concept implementation access to a degree of freedom is accomplished via two templated free-functions

  • readDoFValue()
  • writeDoFValue()

The rationale for not just providing a function such as e.g. accessDoF(), which returns a reference to the data item, is to be able to implement the two functions also for our CSFVectorFunctions, as in that case no underlying dof-vector exists, which could be referenced.


A DoF is identified by a corresponding DoFIdentifier object. In the case of a P1DoFIdentifier this, e.g., is a class storing the following three pieces of information: level to work on, ID of associated primitive and the integer index into the data array for the function.

class P1DoFIdentifier : public BaseDoFIdentifier
   PrimitiveID primitiveID_;
   uint_t      level_;
   uint_t      arrayIndex_;

   bool operator==( const P1DoFIdentifier& other ) const
      return ( primitiveID_ == other.primitiveID_ ) && ( arrayIndex_ == other.arrayIndex_ ) && ( level_ == other.level_ );


In order for the user to allow to work with the accessors, the idea is to have iterators which can be used to "loop" over all degrees of freedom of a specific function class. Note that this is local, i.e. the iterator only treats dofs/primitives owned by the corresponding MPI process. Currently the draft implements to iterators:

  • P1DoFIterator
  • EdgeDoFIterator

In order to demonstrate the validity and usefulness of the concept there are two tests:

  • DoFIterator+AccessTest.cpp: demonstrates the basic use of the concept and checks that we can iterate over all DoFs (externally)
  • CSFVectorFunctionMagnitudeTest.cpp: Implements the getMaxMagnitude() functionality that is currently missing from the CSFVectorFunction class using the dof accessor idea.


  • Note that this is only a demo implementation. Hence there is much room for improvement. Especially the iterators should be improved, if we want to go with this approach.
  • Another questions is, whether an iterator should also provide a flag to only include certain primitives, in the same way as e.g. the interpolate() and apply(() methods.
  • For full usability one would often also need to obtain the micro-coordinates for a DoF (if avalaible for the corresponding FE function representation). This could be handled in multiple ways
    • as part of a specialised iterator that adds this info to the dof identifier
    • by a separate query method
    • as a secondary readDoFValue() function that also returns the coordinates

Please feel free to comment.

Merge request reports