File deriv_store.hxx#

Definition of derivative methods storage class

Copyright 2018 D.Dickinson, P.Hill, B.Dudson

Contact: Ben Dudson, bd512@york.ac.uk

This file is part of BOUT++.

BOUT++ is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

BOUT++ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with BOUT++. If not, see http://www.gnu.org/licenses/.

template<typename FieldType>
struct DerivativeStore#
#include <deriv_store.hxx>

Here we have a templated singleton that is used to store DerivativeFunctions for all types of derivatives. It is templated on the FieldType (2D or 3D) as the function interfaces also depend on this. It provides public routines for registering and fetching derivative methods defined by a string key (e.g. “C2”) a DIRECTION (e.g. DIRECTION::X) and a STAGGER (e.g. STAGGER::None). There is one routine for each class of derivative (standard, standard2nd, standard4th, upwind and flux).

Public Types

using standardFunc = std::function<void(const FieldType&, FieldType&, const std::string&)>#
using flowFunc = std::function<void(const FieldType&, const FieldType&, FieldType&, const std::string&)>#
using upwindFunc = flowFunc#
using fluxFunc = flowFunc#
template<typename K, typename V>
using storageType = std::unordered_map<K, V>#

Public Functions

DerivativeStore(const DerivativeStore &junk) = delete#
inline bool isEmpty() const#

Report if store has any registered methods.

inline bool isEmpty(std::size_t key) const#

Report if store has any registered methods for specific type determined by key.

inline bool isEmpty(DERIV derivType, DIRECTION direction, STAGGER stagger = STAGGER::None) const#

Report if store has any registered methods for specific type.

inline std::set<std::string> getAvailableMethods(DERIV derivType, DIRECTION direction, STAGGER stagger = STAGGER::None) const#

Returns a vector of all registered method names for the specified derivative type, direction and stagger.

inline void listAvailableMethods(DERIV derivType, DIRECTION direction, STAGGER stagger = STAGGER::None) const#

Outputs a list of all registered method names for the specified derivative type, direction and stagger.

inline void registerDerivative(standardFunc func, DERIV derivType, DIRECTION direction, STAGGER stagger, std::string methodName)#

Register a function with standardFunc interface. Which map is used depends on the derivType input.

inline void registerDerivative(upwindFunc func, DERIV derivType, DIRECTION direction, STAGGER stagger, std::string methodName)#

Register a function with upwindFunc/fluxFunc interface. Which map is used depends on the derivType input.

template<typename Direction, typename Stagger, typename Method>
inline void registerDerivative(standardFunc func, Direction direction, Stagger stagger, Method method)#

Templated versions of the above registration routines.

template<typename Direction, typename Stagger, typename Method>
inline void registerDerivative(upwindFunc func, Direction direction, Stagger stagger, Method method)#
inline standardFunc getStandardDerivative(std::string name, DIRECTION direction, STAGGER stagger = STAGGER::None, DERIV derivType = DERIV::Standard) const#

Routines to return a specific differential operator. Note we have to have a separate routine for different methods as they have different return types. As such we choose to use a different name for each of the method-classes so everything is consistently treated

inline standardFunc getStandard2ndDerivative(std::string name, DIRECTION direction, STAGGER stagger = STAGGER::None) const#
inline standardFunc getStandard4thDerivative(std::string name, DIRECTION direction, STAGGER stagger = STAGGER::None) const#
inline flowFunc getFlowDerivative(std::string name, DIRECTION direction, STAGGER stagger = STAGGER::None, DERIV derivType = DERIV::Upwind) const#
inline upwindFunc getUpwindDerivative(std::string name, DIRECTION direction, STAGGER stagger = STAGGER::None) const#
inline fluxFunc getFluxDerivative(std::string name, DIRECTION direction, STAGGER stagger = STAGGER::None) const#
inline void initialise(Options *options)#
inline void forceDefaultMethod(std::string methodName, DERIV deriv, DIRECTION direction, STAGGER stagger = STAGGER::None)#

Provide a method to override/force a specific default method.

inline void clear()#

Empty all member storage.

inline void reset()#

Reset to initial state.

Public Static Functions

static inline DerivativeStore &getInstance()#

Private Functions

inline DerivativeStore()#
inline void setDefaults()#
inline std::string getMethodName(std::string name, DIRECTION direction, STAGGER stagger = STAGGER::None) const#
inline std::string nameLookup(const std::string name, const std::string defaultName) const#
inline std::size_t getKey(DIRECTION direction, STAGGER stagger, std::string key) const#

Provides a routine to produce a unique key given information about the specific type required. This is templated so requires compile-time information. Need to also supply a non-templated version to account for run-time choices Note : We could include the derivType in the key &#8212; this would allow us to store all methods with the same function interface in the same map, which might be nice.

template<typename Direction, typename Stagger, typename Method>
inline std::size_t getKey() const#

Provides a routine to produce a unique key given information about the specific type required. This is templated so requires compile-time information. Makes use of a non-templated version that can be used to account for run-time choices

Private Members

storageType<std::size_t, standardFunc> standard#
storageType<std::size_t, standardFunc> standardSecond#
storageType<std::size_t, standardFunc> standardFourth#
storageType<std::size_t, upwindFunc> upwind#
storageType<std::size_t, fluxFunc> flux#
storageType<std::size_t, std::set<std::string>> registeredMethods#
storageType<std::size_t, std::string> defaultMethods#

The following stores what actual method to use when DIFF_DEFAULT is passed. The key is determined using the getKey routine here, where the name we pass is determined by the type of method (standard, upwind etc.). Note for now we’ll always use STAGGER::None as we currently assume the default method is independent of staggering &#8212; it might be useful to relax this assumption!