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

/*
 * Log Events class source.
 */
#include "../PetscUtils/PetscUtils.h"	// USES PetscUtils
#include "LogEvents.h"


POWERFLOWER_NAMESPACE_BEGIN

/////////////////////////////// PUBLIC ///////////////////////////////////////

//============================= LIFECYCLE ====================================

#undef __FUNCT__
#define __FUNCT__ "LogEvents::LogEvents"
LogEvents::LogEvents(void) :
	mAMBuild(-1), mAMAddBranch(-1), mAMRemBranch(-1)
{
} // LogEvents::LogEvents

//============================= OPERATIONS ===================================

#undef __FUNCT__
#define __FUNCT__ "LogEvents::Register"
bool LogEvents::Register(void)
{
	PetscErrorCode err;

	// PowerSystemExt
	err = PetscLogEventRegister("PF_PSRead", 0, &mPSRead); CHKERRB(err);
	err = PetscLogEventRegister("PF_PSWrite", 0, &mPSWrite); CHKERRB(err);
	err = PetscLogEventRegister("PF_PSIsConnected", 0, &mPSIsConnected); CHKERRB(err);
	// Admittance Matrix
	err = PetscLogEventRegister("PF_AMBuild", 0, &mAMBuild); CHKERRB(err);
	err = PetscLogEventRegister("PF_AMAddBranch", 0, &mAMAddBranch); CHKERRB(err);
	err = PetscLogEventRegister("PF_AMRemBranch", 0, &mAMRemBranch); CHKERRB(err);
	// PowerFlowProblem
	err = PetscLogEventRegister("PF_PFPCreateJac", 0, &mPFPCreateJacobianSystem); CHKERRB(err);
	err = PetscLogEventRegister("PF_PFPCalcJac", 0, &mPFPCalculateJacobianSystem); CHKERRB(err);
	// PowerFlower
	err = PetscLogEventRegister("PF_PFSolve", 0, &mPFSolve); CHKERRB(err);
	err = PetscLogEventRegister("PF_PowerFlow", 0, &mPowerFlow); CHKERRB(err);
	err = PetscLogEventRegister("PF_Contingency", 0, &mContingencyAnalysis); CHKERRB(err);

	return true;
} // LogEvents::Register

#undef __FUNCT__
#define __FUNCT__ "LogEvents::Begin"
bool LogEvents::Begin(PetscLogEvent event) const
{
	if (event < 0) return false;
	PetscErrorCode err = PetscLogEventBegin(event, 0, 0, 0, 0); CHKERRB(err);
	return true;
} // LogEvents::Begin

#undef __FUNCT__
#define __FUNCT__ "LogEvents::End"
bool LogEvents::End(PetscLogEvent event) const
{
	if (event < 0) return false;
	PetscErrorCode err = PetscLogEventEnd(event, 0, 0, 0, 0); CHKERRB(err);
	return true;
} // LogEvents::End

//============================= ACCESS     ===================================

/////////////////////////////// PRIVATE    ///////////////////////////////////

POWERFLOWER_NAMESPACE_END
