File invertable_operator.hxx#

namespace bout

Provides access to the Hypre library, handling initialisation and finalisation.

Usage

#include <bout/hyprelib.hxx>

class MyClass { public:

private: HypreLib lib; };

This will then automatically initialise Hypre the first time an object is created, and finalise it when the last object is destroyed.

Copyright 2012 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu

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/.

Information about the version of BOUT++

The build system will update this file on every commit, which may result in files that include it getting rebuilt. Therefore it should be included in as few places as possible

Information about the version of BOUT++

The build system will update this file at configure-time

SNB model

namespace inversion#

Functions

template<typename T>
T identity(const T &in)#

No-op function to use as a default &#8212; may wish to remove once testing phase complete.

template<typename T>
PetscErrorCode fieldToPetscVec(const T &in, Vec out)#

Pack a PetscVec from a Field<T>

template<typename T>
PetscErrorCode petscVecToField(Vec in, T &out)#

Pack a Field<T> from a PetscVec.

template<typename T>
class InvertableOperator#
#include <invertable_operator.hxx>

Class to define an invertable operator. Provides interface to PETSc routines for solving A.x = b

Public Types

using data_type = T#

What type of field does the operator take?

using function_signature = std::function<T(const T&)>#

The signature of the functor that applies the operator.

Public Functions

inline InvertableOperator(const function_signature &func = identity<T>, Options *optIn = nullptr, Mesh *localmeshIn = nullptr)#

Almost empty constructor &#8212; currently don’t actually use Options for anything.

inline ~InvertableOperator()#

Destructor just has to cleanup the PETSc owned objects.

inline void setOperatorFunction(const function_signature &func, bool alsoSetPreconditioner = true)#

Allow the user to override the existing function Note by default we set the preconditioner function to match this as this is the usual mode of operation. If the user doesn’t want to do this they can set alsoSetPreconditioner to false.

inline void setPreconditionerFunction(const function_signature &func)#

Allow the user to override the existing preconditioner function.

inline T operator()(const T &input)#

Provide a way to apply the operator to a Field.

inline T apply(const T &input)#

Provide a synonym for applying the operator to a Field.

inline PetscErrorCode setup()#

Sets up the PETSc objects required for inverting the operator Currently also takes the functor that applies the operator this class represents. Not actually required by any of the setup so this should probably be moved to a separate place (maybe the constructor).

inline T invert(const T &rhsField, const T &guess)#
inline T invert(const T &rhsField)#

Triggers the solve of A.x = b for x, where b = rhs and A is the matrix representation of the operator we represent. Should probably provide an overload or similar as a way of setting the initial guess.

inline bool verify(const T &rhsIn, BoutReal tol = 1.0e-5)#

With checks enabled provides a convience routine to check that applying the registered function on the calculated inverse gives back the initial values.

Public Static Functions

static inline void reportTime()#

Reports the time spent in various parts of InvertableOperator. Note that as the Timer “labels” are not unique to an instance the time reported is summed across all different instances.

Private Members

Mat matOperator#
Mat matPreconditioner#
Vec rhs#
Vec lhs#
KSP ksp#
function_signature operatorFunction = identity<T>#

The function that represents the operator that we wish to invert.

function_signature preconditionerFunction = identity<T>#

The function that represents the preconditioner for the operator that we wish to invert

Options *opt = nullptr#
Mesh *localmesh = nullptr#
bool doneSetup = false#
PetscLib lib#

Private Static Functions

static inline PetscErrorCode functionWrapper(Mat m, Vec v1, Vec v2)#

Wrapper that gets a pointer to the parent InvertableOperator instance from the Matrix m and uses this to get the actual function to call. Copies data from v1 into a field of type T, calls the function on this and then copies the result into the v2 argument.

static inline PetscErrorCode preconditionerWrapper(Mat m, Vec v1, Vec v2)#

Wrapper that gets a pointer to the parent InvertableOperator instance from the Matrix m and uses this to get the actual function to call. Copies data from v1 into a field of type T, calls the function on this and then copies the result into the v2 argument.