import java.io.*;
import javax.swing.*;
import javax.tools.*;
import java.util.*;

public class natural_convection_vertical_plate
 {
  public static double kmetal(double t)
  {double T=t+273.15;
   double a=71.62587939698594-0.03447361809045638*T-7.927135678388277E-6*T*T;
  return a;
  }
  public static double k(double t)
  {double T=t+273.15;
  Gas g=new Gas("air");
   double ka=g.k(T);
  return ka;
  }	 	   	 
  public static double Rayleigh(double t,double tinf,double L) 
  { // Rayleigh number (natural convection)
    // t degree c fin surface temperature
    // tinf degree C outside air temperature
    // L height of plate m
    // h convective heat transfer coefficient W/(m^2K)
    double P=1.01325; //bar
    Gas g=new Gas("air");
   double tf=(t+tinf)/2.0; //degree C
   double Tf=tf+273.15; //degree K
   double T=t+273.15; //degree K
   double beta=1/Tf;//1/K
   double gyc=9.80;//m/s
   double ro=g.M/g.v(Tf,P);//kg/m^3
   double nu=g.vis(Tf)/ro;
   double alfa=g.alfa(Tf,P);
   double Pr=g.Prandtl(Tf);
   double Gr=gyc*beta*(t-tinf)*L*L*L/(nu*nu);
   double Ra=Gr*Pr;
      System.out.println("Gr="+Gr+"Ra="+Ra+"t="+t+"tinf="+tinf+"tf="+tf+"vis="+g.vis(Tf)+"ro="+ro+"nu="+nu);
   System.out.println("gy="+gyc+"nu="+nu+"beta="+beta+"alfa="+alfa);
   return Ra;
  }
  
  public static double h(double t,double tinf,double L ) 
  {  // Natural convection heat transfer coefficient 
     // vertical plate
  Gas g=new Gas("air");
  double tf=(t+tinf)/2.0;
  double Tf=tf+273.15;
  double Pr=g.Prandtl(Tf);
  double Ra=Rayleigh(t,tinf,L);
  double Gr=Ra/Pr;
  double delta=6*L/Math.pow((Gr/4),0.25);
  System.out.println("delta="+delta);
  double k=g.k(Tf);
  double Nu;
  double x1,x2,x3;
  x2=Math.pow((0.492/Pr),(9.0/16.0));
  if(Ra<1e9)
  {
  x1=Math.pow(Ra,0.25);
  Nu=0.68+0.67*x1/Math.pow((1+x2),(4/9));
  } 
  else  
  {
  x1=Math.pow(Ra,(1.0/6.0));
  x2=Math.pow((0.492/Pr),(9/16));
  x3=0.825+0.387*x1/Math.pow((1.0+x2),(8.0/27.0));
  Nu=x3*x3;
  }  
  double hh=Nu*k/L;
  return hh;
  }
   
  public static void main(String args[]) throws IOException
  {
  double t=232;
  double tinf=23;
  double L=0.71;
  double h2=h(t,tinf,L);
  System.out.println("h="+h2);
  }
 }