/*
 * Copyright (C) 2008-2012 Delft University of Technology - All rights reserved.
 *
 * Author: Reijer Idema
 */

/**
 * @file ForcingTerms.h
 * !PowerFlower ForcingTerms class header.
 */
#ifndef PowerFlower_ForcingTerms_h
#define PowerFlower_ForcingTerms_h

#include "../NonLinearSolver/ForcingTerms.h"	// ISA ForcingTerms
#include "PowerFlower.def"

POWERFLOWER_NAMESPACE_BEGIN

/**
 * Forcing terms test class.
 * Implements a forcing term strategy for testing purposes.
 */
class ForcingTermsTest : public NONLINEARSOLVER_NAMESPACE_NAME::ForcingTerms
{
public:
	ForcingTermsTest(void);
	virtual ~ForcingTermsTest(void);
	virtual PetscErrorCode Initialize(PetscReal relativeTolerance, PetscReal absoluteTolerance, PetscReal divergenceTolerance, PetscInt maxIterationCount, PetscReal nonlinearAbsoluteTolerance);
	virtual PetscErrorCode TestConvergence(KSP ksp, PetscInt it, PetscReal rnorm, KSPConvergedReason* pReason);

private:
	/**
	 * Updates the tolerances.
	 * Called by TestConvergence() in the first convergence test of every non-linear iteration.
	 * @return non-zero error code on failure, 0 on success.
	 */
	virtual PetscErrorCode UpdateTolerances(void);

	// MEMBER VARIABLES
	PetscInt mNonLinearIterationCount;	///< Current non-linear iteration.
	PetscReal mNonLinearResidualNorm;	///< Norm of the initial linear residual of the current non-linear iteration. For right preconditioning equal to the non-linear residual at the start of the current Newton iteration.
	void* mDefaultConvergedContext;		///< Default converged context, needed for KSPDefaultConverged.
};

//	ForcingTermsFixed(void);
//	virtual ~ForcingTermsFixed(void);
//	virtual PetscErrorCode Initialize(PetscReal relativeTolerance, PetscReal absoluteTolerance, PetscReal divergenceTolerance, PetscInt maxIterationCount);
//	virtual PetscErrorCode TestConvergence(KSP ksp, PetscInt it, PetscReal rnorm, KSPConvergedReason* pReason);

POWERFLOWER_NAMESPACE_END

#endif // PowerFlower_ForcingTerms_h
