scalar scalar_lambda=0.1; scalar beta=0.0065;
cout<<"lambda= "; cin>>scalar_lambda;  cout<<"beta= "; cin>>beta;
ii=0;

volScalarField gg
(
     IOobject
         (
	     "gg",
	     runTime.timeName(),
	     mesh,
	     IOobject::NO_READ,
	     IOobject::AUTO_WRITE
	 ),
	     mesh
); 

volScalarField gg_int
(
      IOobject
               (
           "gg_int",
	    runTime.timeName(),
             mesh,
             IOobject::NO_READ,
            IOobject::AUTO_WRITE
	      ),
	        mesh
        );


volScalarField zeta1
(
     IOobject
         (
	     "zeta1",
	     runTime.timeName(),
		  "/Weights",
	     mesh,
	     IOobject::NO_READ,
	     IOobject::AUTO_WRITE
	 ),
	     mesh
);

volScalarField zeta2
(
     IOobject
         (
	     "zeta2",
	     runTime.timeName(),
		  "/Weights",
	     mesh,
	     IOobject::NO_READ,
	     IOobject::AUTO_WRITE
	 ),
	     mesh
);

volScalarField lambda
(
     IOobject
         (
	     "lambda",
	     runTime.timeName(),
		  "/Weights",
	     mesh,
	     IOobject::NO_READ,
	     IOobject::AUTO_WRITE
	 ),
	     mesh
);

forAll(lambda,ii){
	lambda[ii]=scalar_lambda;
}
Info<<"Lambda "<<endl;

// ALFA1
jj=0; sum=0; kk=0; ii=0; scalar ww=0;
forAll(alfa1,cellI){
	alfa1[cellI]=0;
}
 while(jj<(nx*ny*nz)){ 
	 sum=sum+psi1[jj]*fi1[jj]*(1/vv1)*dx*dz;
    
	 
	 if (kk==(nx-1))
	 {   
         alfa1[ii]=alfa1[ii]+sum;
		 kk=0; 
		 ii=ii+1;
		 sum=0;
	 }else{	 
		kk=kk+1; 
	 }
	 if(ww==(nx*ny-1)){
		 ww=0; 
		 ii=0;
	 }else{
		 ww=ww+1;		 
	 }
	    
	 jj=jj+1;
	 
	 
    }
alfa1.write();
Info<<"alfa1 "<<endl;
	
// ALFA2
jj=0; sum=0; kk=0; ii=0; ww=0;
forAll(alfa1,cellI){
	alfa2[cellI]=0;
}
 while(jj<(nx*ny*nz)){ 
	 sum=sum+psi2[jj]*fi2[jj]*(1/vv2)*dx*dz;
    
  
	 if (kk==(nx-1))
	 {   
         alfa2[ii]=alfa2[ii]+sum;
		 kk=0; 
		 ii=ii+1;
		 sum=0;
	 } else{	 
		kk=kk+1; 
	 }
	 if(ww==(nx*ny-1)){
		 ww=0; 
		 ii=0;
	 }else{
		 ww=ww+1;		 
	 }
	 
	 jj=jj+1;
	 
    } 
alfa2.write();
	Info<<"alfa2 "<<endl;
	
// DELTA1
jj=0; sum=0; kk=0; ii=0; ww=0;
forAll(alfa1,cellI){
	delta1[cellI]=0;
}
 while(jj<(nx*ny*nz)){ 
     sum=sum+psi1[jj]*(DD1[jj]+dDD1[jj])*fi1[jj]*dx*dz;
     
	 
	 if (kk==(nx-1))
	 {   
         delta1[ii]=delta1[ii]+sum;
		 kk=0; 
		 ii=ii+1;
		 sum=0;
	 } else{	 
		kk=kk+1; 
	 }
	 if(ww==(nx*ny-1)){
		 ww=0; 
		 ii=0;
	 }else{
		 ww=ww+1;		 
	 }
	 
	 jj=jj+1;
	 
    } 
delta1.write();
	Info<<"delta1 "<<endl;
	
// DELTA2
jj=0; sum=0; kk=0; ii=0; ww=0;
forAll(alfa1,cellI){
	delta2[cellI]=0;
}
 while(jj<(nx*ny*nz)){ 
     sum=sum+psi2[jj]*(DD2[jj]+dDD2[jj])*fi2[jj]*dx*dz; 
	 
	 
	 if (kk==(nx-1))
	 {   
         delta2[ii]=delta2[ii]+sum;
		 kk=0; 
		 ii=ii+1;
		 sum=0;
	 } else{	 
		kk=kk+1; 
	 }
if(ww==(nx*ny-1)){
		 ww=0; 
		 ii=0;
	 }else{
		 ww=ww+1;		 
	 }
	 jj=jj+1;
	
    } 
delta2.write();
	Info<<"delta2 "<<endl;
	
// GAMMA1
jj=0; sum=0; kk=0; ii=0; ww=0;
forAll(alfa1,cellI){
	gamma1[cellI]=0;
}
 while(jj<(nx*ny*nz)){ 
	 sum=sum+psi1[jj]*((DD1[jj]+dDD1[jj])*grad_fi1_y[jj]+grad_DD1_fi1_y[jj])*dx*dz;
	 
	 
	 if (kk==(nx-1))
	 {   
         gamma1[ii]=gamma1[ii]+sum;
		 kk=0; 
		 ii=ii+1;
		 sum=0;
	 } else{	 
		kk=kk+1; 
	 }
 if(ww==(nx*ny-1)){
		 ww=0; 
		 ii=0;
	 }else{
		 ww=ww+1;		 
	 }
	 jj=jj+1;
	 
    } 
gamma1.write(); 
	Info<<"gamma1 "<<endl;
	
// GAMMA2
jj=0; sum=0; kk=0; ii=0; ww=0;
forAll(alfa1,cellI){
	gamma2[cellI]=0;
}
 while(jj<(nx*ny*nz)){ 
	 sum=sum+psi2[jj]*((DD2[jj]+dDD2[jj])*grad_fi2_y[jj]+grad_DD2_fi2_y[jj])*dx*dz;
	 
	 
	 if (kk==(nx-1))
	 {   
         gamma2[ii]=gamma2[ii]+sum;
		 kk=0; 
		 ii=ii+1;
		 sum=0;
	 } else{	 
		kk=kk+1; 
	 }
if(ww==(nx*ny-1)){
		 ww=0; 
		 ii=0;
	 }else{
		 ww=ww+1;		 
	 }
	 jj=jj+1;
	 
    } 
gamma2.write();
	Info<<"gamma2 "<<endl;
	
// ETA1
jj=0; sum=0; kk=0; ii=0; ww=0;
forAll(alfa1,cellI){
	eta1[cellI]=0;
}
 while(jj<(nx*ny*nz)){ 
       sum=sum+psi1[jj]*(lap_dDD1_fi1[jj]+((1-beta)*dnisf1[jj]-ds1[jj])*fi1[jj]-beta*nisf1[jj]*fi1[jj]-nisf2[jj]*fi2[jj])*dx*dz;
	 
	 if (kk==(nx-1))
	 {   
         eta1[ii]=eta1[ii]+sum;
		 kk=0; 
		 ii=ii+1;
		 sum=0;
	 } else{	 
		kk=kk+1; 
	 }
if(ww==(nx*ny-1)){
		 ww=0; 
		 ii=0;
	 }else{
		 ww=ww+1;		 
	 }
	 jj=jj+1;
	 
 } 
eta1.write();
	Info<<"eta1 "<<endl;
	
// ETA2
jj=0; sum=0; kk=0; ii=0; ww=0;
forAll(alfa1,cellI){
	eta2[cellI]=0;
}
 while(jj<(nx*ny*nz)){ 
	 sum=sum+psi2[jj]*(lap_dDD2_fi2[jj]-ss12[jj]*fi1[jj]-ds2[jj]*fi2[jj])*dx*dz;

	 
	 if (kk==(nx-1))
	 {   
         eta2[ii]=eta2[ii]+sum;
		 kk=0; 
		 ii=ii+1;
		 sum=0;
	 } else{	 
		kk=kk+1; 
	 }
	 if(ww==(nx*ny-1)){
		 ww=0; 
		 ii=0;
	 }else{
		 ww=ww+1;		 
	 }

	 jj=jj+1;
	 
    } 
eta2.write();
	Info<<"eta2 "<<endl;
	
// BETA1
jj=0; sum=0; kk=0; ii=0; ww=0;
forAll(alfa1,cellI){
	beta1[cellI]=0;
}
 while(jj<(nx*ny*nz)){ 
	  sum=sum+psi1[jj]*fi2[jj]*(1-beta)*(nisf2[jj]+dnisf2[jj])*dx*dz;
	 
	 
	 if (kk==(nx-1))
	 {   
         beta1[ii]=beta1[ii]+sum;
		 kk=0; 
		 ii=ii+1;
		 sum=0;
	 } else{	 
		kk=kk+1; 
	 }
	 
	 if(ww==(nx*ny-1)){
		 ww=0; 
		 ii=0;
	 }else{
		 ww=ww+1;		 
	 }

	 jj=jj+1;
	 
    } 
beta1.write(); 
	Info<<"Beta1 "<<endl;
	
	
// BETA2
jj=0; sum=0; kk=0; ii=0; ww=0;
forAll(alfa1,cellI){
	beta2[cellI]=0;
}
 while(jj<(nx*ny*nz)){ 
	 sum=sum+psi2[jj]*fi1[jj]*(ss12[jj]+ds12[jj])*dx*dz;
	 
	 
	 if (kk==(nx-1))
	 {   
         beta2[ii]=beta2[ii]+sum;
		 kk=0; 
		 ii=ii+1;
		 sum=0;
	 } else{	 
		kk=kk+1; 
	 }
	 if(ww==(nx*ny-1)){
		 ww=0; 
		 ii=0;
	 }else{
		 ww=ww+1;		 
	 }
	 jj=jj+1;
    } 
beta2.write();
	Info<<"Beta2 "<<endl;
	
	
	// ZETA1
jj=0; sum=0; kk=0; ii=0; ww=0;
forAll(alfa1,cellI){
	zeta1[cellI]=0;
}
 while(jj<(nx*ny*nz)){ 
	 sum=sum+psi1[jj]*fi1[jj]*beta*(nisf1[jj]+dnisf1[jj])*dx*dz;
	 
	 
	 if (kk==(nx-1))
	 {   
         zeta1[ii]=zeta1[ii]+sum;
		 kk=0; 
		 ii=ii+1;
		 sum=0;
	 } else{	 
		kk=kk+1; 
	 }
if(ww==(nx*ny-1)){
		 ww=0; 
		 ii=0;
	 }else{
		 ww=ww+1;		 
	 }
	 jj=jj+1;
	 
    } 
zeta1.write();
	Info<<"Zeta1 "<<endl;
	
	
	// ZETA2
jj=0; sum=0; kk=0; ii=0; ww=0;
forAll(alfa1,cellI){
	zeta2[cellI]=0;
}
 while(jj<(nx*ny*nz)){ 
	 sum=sum+psi1[jj]*fi2[jj]*beta*(nisf2[jj]+dnisf2[jj])*dx*dz;
	 	 
	 if (kk==(nx-1))
	 {   
         zeta2[ii]=zeta2[ii]+sum;
		 kk=0; 
		 ii=ii+1;
		 sum=0;
	 } else{	 
		kk=kk+1; 
	 }
if(ww==(nx*ny-1)){
		 ww=0; 
		 ii=0;
	 }else{
		 ww=ww+1;		 
	 }
	 jj=jj+1;
	
    } 
zeta2.write();
	Info<<"Zeta2 "<<endl;

     
	 // GG
jj=0; sum=0; kk=0; ii=0; ww=0;
scalar gg_0=0;
forAll(alfa1,cellI){
	gg[cellI]=0;
}
 while(jj<(nx*ny*nz)){ 
	 sum=sum+psi1[jj]*(beta/scalar_lambda)*(nisf1[jj]*fi1[jj]+nisf2[jj]*fi2[jj])*dx*dz;
	 	 
	 if (kk==(nx-1))
	 {   
         gg[ii]=gg[ii]+sum;
		 kk=0; 
		 ii=ii+1;
		 sum=0;
	 } else{	 
		kk=kk+1; 
	 }
if(ww==(nx*ny-1)){
		 ww=0; 
		 ii=0;
	 }else{
		 ww=ww+1;		 
	 }
	 jj=jj+1;
	
    } 
gg.write();
          forAll(gg,cellI)
          {
	     gg_0=gg_0+gg[cellI]*dy/HH;
	  }
	Info<<"GG "<<gg_0<<endl;
	
	          forAll(gg,cellI)
	          {
              gg_int=gg_0;
                  }
       

scalar AA0=0;

	for(ii=0;ii<(nx*ny*nz);ii++) 
	{
	AA0+= (1-beta)*(nisf1[ii]*fi1[ii]+nisf2[ii]*fi2[ii])*dx*dy*dz;
	}
	cout<<"AA0="<<AA0;

//  FI1_NISF1_Y
jj=0; sum=0; kk=0; ii=0; ww=0;
forAll(alfa1,cellI){
	fi1_nisf1_y[cellI]=0;
}
 while(jj<(nx*ny*nz)){ 
	 sum=sum+fi1[jj]*(1-beta)*(nisf1[jj]+dnisf1[jj])*dx*dz;
	 
	 
	 if (kk==(nx-1))
	 {   
         fi1_nisf1_y[ii]=fi1_nisf1_y[ii]+sum;
		 kk=0; 
		 ii=ii+1;
		 sum=0;
	 } else{	 
		kk=kk+1; 
	 }
	 if(ww==(nx*ny-1)){
		 ww=0; 
		 ii=0;
	 }else{
		 ww=ww+1;		 
	 }

	 jj=jj+1;
	 
    }
fi1_nisf1_y.write();
Info<<"fi1_nisf1_y "<<endl;

// FI2_NISF2_Y
jj=0; sum=0; kk=0; ii=0; ww=0;
forAll(alfa1,cellI){
	fi2_nisf2_y[cellI]=0;
}
 while(jj<(nx*ny*nz)){ 
	 sum=sum+fi2[jj]*(1-beta)*(nisf2[jj]+dnisf2[jj])*dx*dz;
	 
	 
	 if (kk==(nx-1))
	 {   
         fi2_nisf2_y[ii]=fi2_nisf2_y[ii]+sum;
		 kk=0; 
		 ii=ii+1;
		 sum=0;
	 } else{	 
		kk=kk+1; 
	 }
if(ww==(nx*ny-1)){
		 ww=0; 
		 ii=0;
	 }else{
		 ww=ww+1;		 
	 }
	 jj=jj+1;
	 
    }
fi2_nisf2_y.write();
	Info<<"fi2_nisf2_y "<<endl;
