/*============================================================================

 Function      vfInit

 Usage         vfInit(nz, eta, beta, alpha, delta, Z, V)

 Arguments     nz:    constant integer representing number of values in TFP
                      grid.

	       eta:   constant double representing risk aversion.

	       beta:  constant double representing the discount factor.

	       alpha: constant double representing capital share.

	       delta: constant double representing the depreciation rate.

	       Z:     pointer to the array of constant doubles which stores
	              the AR1 grid values.

	       V:     pointer to the array of doubles which stores the initial
	              value function.

 Description   This function is a CUDA kernel that initializes the value
               function.

 Return value  void.

 =============================================================================

 Author:       Eric M. Aldrich

 Contact:      ealdrich@gmail.com

 Date:         20 April 2010

 ============================================================================*/

__global__ void vfInit(const int nz,  const double eta, const double beta,
		       const double alpha, const double delta, const double* Z,
		       double* V)
{ 
  // thread
  const int i = blockIdx.x * blockDim.x + threadIdx.x;
  const int j = blockIdx.y * blockDim.y + threadIdx.y;

  // initialize
  const double Kj = pow((1/(alpha*Z[j]))*((1/beta)-1+delta),1/(alpha-1));
  V[i*nz+j] = pow(Z[j]*pow(Kj, alpha) - delta*Kj,1-eta)/(1-eta);
}
