<?php 

	function coldplate_TR($data) {
		return floordec( ($data["pjt"] - @$_SESSION['sim_data']['bdry']["inlet_temperature"])/@$_SESSION['sim_data']['bdry']["heat_power"],3); 
	}
	function coldplate_TR_wTIM($data) {
		return floordec( ($data["mjtt"] - @$_SESSION['sim_data']['bdry']["inlet_temperature"])/@$_SESSION['sim_data']['bdry']["heat_power"],3); 
	}
	function overall_TR($data) {
	 	return floordec( ($data["pjt"] - @$_SESSION['sim_data']['bdry']["inlet_temperature"])/@$_SESSION['sim_data']['bdry']["heat_power"],3); 

	}
	function tim_TR($data) {
		return overall_TR($data) - coldplate_TR_wTIM($data);
	}	
	function floordec($d,$decimals=2) {    
	
		$decimals = ($d <= 0.01 ? 4:$decimals);
	
     return floor($d*pow(10,$decimals))/pow(10,$decimals);
	}
	function hasTIM() {
		return ( $_SESSION['sim_data']['geom']['tim_thickness'] == '0' ? false: true );
	}
?>

<?php if ($results) { ?>

	<div style="float:left; width:47%;" class="ptight">
		
        
		<?php if (hasTIM()) { ?>
         <p>Max Coldplate Surface temp: <?php echo floordec($results["mjtt"]);?> &deg;C </p>
        <p>Max TIM Surface temp: <?php echo floordec($results["pjt"]);?> &deg;C </p>
        <p>Overall Thermal Resistance<sup>1</sup>: <?php echo overall_TR($results);?> k/W </p>
        <p>Coldplate Thermal Resistance<sup>2</sup>: <?php echo coldplate_TR_wTIM($results);?> k/W </p>
        <p>TIM Thermal Resistance<sup>3</sup>: <?php echo tim_TR($results);?> k/W </p>
        <p>Presssure Drop [inlet to outlet]: <?php echo floordec($results["pd"]/100,3);?> bar </p>
        <p>Outlet Fluid Temp: <?php echo floordec($results["tfo"]);?>  &deg;C </p>
        <p>Fluid Temp Rise [inlet to outlet]: <?php echo floordec($results["dtf"]);?> &deg;C </p>
        <p>Heat Transfer Coeff. (Average): <?php echo floordec($results["mbf"]);?>  kW/m<sup>2</sup>K </p>
        <p>Heat Transfer Coeff. (Wetted Area): <?php echo floordec($results["htc"]);?>  kW/m<sup>2</sup>K </p>
        <p>Fluid Velocity<sup>4</sup>: <?php echo floordec($results["iv"],3);?> m/s</p>
        <p>Reynolds Number: <?php echo floordec($results["ir"]);?> </p>
        <p>Flow Regime<sup>5</sup>: <?php echo $results["fr"];?></p>
        
        <?php } else { ?>
        <p>Max Coldplate Surface temp: <?php echo floordec($results["pjt"]);?> &deg;C </p>
        <p>Thermal Resistance<sup>1</sup>: <?php echo coldplate_TR($results);?> k/W </p>
        <p>Presssure Drop [inlet to outlet]: <?php echo floordec($results["pd"]/100,3);?> bar </p>
        <p>Outlet Fluid Temp: <?php echo floordec($results["tfo"]);?>  &deg;C </p>
        <p>Fluid Temp Rise [inlet to outlet]: <?php echo floordec($results["dtf"]);?> &deg;C </p>
        <p>Heat Transfer Coeff. (Average): <?php echo floordec($results["mbf"]);?>  kW/m<sup>2</sup>K </p>
        <p>Heat Transfer Coeff. (Wetted Area): <?php echo floordec($results["htc"]);?>  kW/m<sup>2</sup>K </p>
        <p>Fluid Velocity<sup>2</sup>: <?php echo floordec($results["iv"],3);?> m/s</p>
        <p>Reynolds Number: <?php echo floordec($results["ir"]);?> </p>
        <p>Flow Regime<sup>3</sup>: <?php echo $results["fr"];?></p>
        
		<?php } ?>
        


    </div>
          
    <div align="center" style="width:50%; float:left;">   
        <table cellpadding="0" cellspacing="0" style="text-align:center;">
        	<tr>
        		<td style="position:relative; padding-left:30px;">
                	<div style="z-index:2;position:relative; top:20px;">Temperature (°C)</div>
    				<img style="margin-top:-15px;" width="380" src="data:image/jpg;base64,<?php echo $results["webfig"];?>">
                    <div style="z-index:2;position:relative; top:-10px;">Fig. 1. Temperature map of base plate surface</div>
				</td>
        	</tr>
             <tr><td></td></tr>
             <tr><td>&nbsp;</td></tr>
             <tr><td><input id="save_simulation" name="save_simulation" value="Save Simulation as PDF" onclick="window.open('assets/templates/cooltoolreport.php','_blank')" type="button"></td></tr>
        </table>
    </div>
    <div style="float:left; width:100%; clear:both;" class="ptight">
    		<?php if (hasTIM()) { ?>
    
            <p><sup>1</sup>Overall Thermal Resistance = (Max TIM Surface Temp – Inlet Fluid Temp) / Heat Power</p>
            <p><sup>2</sup>Coldplate Thermal Resistance = (Max Coldplate Surface Temp – Inlet Fluid Temp) / Heat Power</p>
            <p><sup>3</sup>TIM Thermal Resistance = Overall Thermal Resistance - Coldplate Thermal Resistance</p>
          	<p><sup>4</sup>Fluid Velocity is taken at minimum cross sectional area of flow.</p>
          	<p><sup>5</sup>Laminar Flow < 2300, Transition 2,300 – 4,000, Turbulent > 4,000.</p>
            
			<?php } else { ?>
            
            <p><sup>1</sup>Thermal Resistance = (Max Coldplate Surface Temp – Inlet Fluid Temp) / Heat Power</p>
          	<p><sup>2</sup>Fluid Velocity is taken at minimum cross sectional area of flow.</p>
          	<p><sup>3</sup>Laminar Flow < 2300, Transition 2,300 – 4,000, Turbulent > 4,000.</p>
            
			<?php } ?>
            
    </div>
<?php } ?>