
/*******************************************************************************
*
* File parms.c
*
* Copyright (C) 2005, 2007 Martin Luescher, 2011 Andrea Nobile
*
* This software is distributed under the terms of the GNU General Public
* License (GPL)
*
* Parameter data base
*
*/



#define PARMS_C

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <float.h>
#include "mpi.h"
#include "start.h"
#include "flags.h"
#include "block.h"
#include "global.h"

static lat_parms_t lat={0.0,0.0,0.0,0.0};
static gcr_parms_t gcr={0,0,0,0};



lat_parms_t set_lat_parms(double beta,double kappa,double csw)
{
   double dprms[3];

   if (NPROC>1)
   {
      dprms[0]=beta;
      dprms[1]=kappa;
      dprms[2]=csw;

      MPI_Bcast(dprms,3,MPI_DOUBLE,0,MPI_COMM_WORLD);

      error((dprms[0]!=beta)||(dprms[1]!=kappa)||(dprms[2]!=csw),1,
             "set_lat_parms [parms.c]","Parameters are not global");
   }

   error_root(kappa<=0.0,1,
              "set_lat_parms [parms.c]","kappa must be positive");

   if (lat.csw!=csw)
      set_flags(CHANGED_CSW);
   else if (lat.kappa!=kappa)
      set_flags(CHANGED_QUARK_MASS);

   lat.beta=beta;
   lat.kappa=kappa;
   lat.m0=1.0/(2.0*kappa)-4.0;
   lat.csw=csw;

   return lat;
}


lat_parms_t lat_parms(void)
{
   return lat;
}


void set_gcr_parms_no_bs(int nmr,int ncy,int nkv)
{
    
   gcr.nmr=nmr;
   gcr.ncy=ncy;
   gcr.nkv=nkv;


}


gcr_parms_t set_gcr_parms(int *bs,int nmr,int ncy,int nkv)
{
   int iprms[3],nb,isw;

   if (NPROC>1)
   {
      iprms[0]=nmr;
      iprms[1]=ncy;
      iprms[2]=nkv;

      MPI_Bcast(iprms,3,MPI_INT,0,MPI_COMM_WORLD);

      error((iprms[0]!=nmr)||(iprms[1]!=ncy)||(iprms[2]!=nkv),1,
             "set_gcr_parms [parms.c]","Parameters are not global");
   }

   error_root((nmr<0)||(ncy<0)||(nkv<1),1,
               "set_gcr_parms [parms.c]","Improper parameters nmr,ncy,nkv");
   alloc_bgr(GCR_BLOCKS,bs);
   blk_list(GCR_BLOCKS,&nb,&isw);

   gcr.nb=nb;
   gcr.nmr=nmr;
   gcr.ncy=ncy;
   gcr.nkv=nkv;

   return gcr;
}


gcr_parms_t gcr_parms(void)
{
   return gcr;
}
