# -*- coding: utf-8 -*-
"""
Created on Tue Apr 03 11:06:37 2018

@author: vmg
"""

import sdf
import numpy as np

# Load 2006 LUT for interpolation
# 2006 Groeneveld Look-Up Table as presented in 
# "2006 CHF Look-Up Table", Nuclear Engineering and Design 237, pp. 190-1922.

# This file requires the file 2006LUTdata.txt

# Pressure range [MPa] from 2006 LUT, convert to [Pa]
P = np.array((0.10,0.30,0.50,1.0,2.0,3.0,5.0,7.0,10.0,12.0,14.0,16.0,18.0,20.0,21.0))*1e6

# Mass Flux range [kg/m^2-s] from 2006 .LUT.
G = np.array((0.,50.,100.,300.,500.,750.,1000.,1500.,2000.,2500.,3000.,3500.,4000.,4500.,5000.,5500.,6000.,6500.,7000.,7500.,8000.))

# Quality range from 2006 LUT
x = np.array((-0.50,-0.40,-0.30,-0.20,-0.15,-0.10,-0.05,0.00,0.05,0.10,0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50,0.60,0.70,0.80,0.90,1.00))

# Critical heat flux [kW/m^2] from 2006 LUT, convert to [W/m^2]
q_raw=np.loadtxt('../Data/2006LUTdata.txt')*1e3

# Convert the imported array into a (MxNxQ) where:
#   M is number of mass flux divisions
#   N is number of quality divisions
#   Q is number of pressure divisions
lenG = len(G)
lenx = len(x)
lenP = len(P)
q = np.zeros((lenG,lenx,lenP))
for i in xrange(lenG):
    for j in xrange(lenx):
        for k in xrange(lenP):
            q[i,j,k] = q_raw[i + k*lenG,j]    
            
# Create the datasets:
ds_G = sdf.Dataset('G', data=G, unit='kg/(m2.s)', is_scale=True, display_name='Mass Flux')
ds_x = sdf.Dataset('x', data=x, unit='1', is_scale=True, display_name='Quality')
ds_P = sdf.Dataset('P', data=P, unit='Pa', is_scale=True, display_name='Pressure')
ds_q = sdf.Dataset('q', data=q, unit='W/m2', scales=[ds_G,ds_x,ds_P])

# Create the root group and write the file:
g = sdf.Group('/', comment='2006 CHF LUT', datasets=[ds_G,ds_x,ds_P,ds_q])
sdf.save('../Data/2006LUT.sdf', g)
[((21, 4, 21, 132), 'numpy.array', 'np.array', ({(21, 13, 21, 131): '(0.0, 50.0, 100.0, 300.0, 500.0, 750.0, 1000.0, 1500.0, 2000.0, 2500.0, \n    3000.0, 3500.0, 4000.0, 4500.0, 5000.0, 5500.0, 6000.0, 6500.0, 7000.0,\n    7500.0, 8000.0)'}, {}), '((0.0, 50.0, 100.0, 300.0, 500.0, 750.0, 1000.0, 1500.0, 2000.0, \n    2500.0, 3000.0, 3500.0, 4000.0, 4500.0, 5000.0, 5500.0, 6000.0, 6500.0,\n    7000.0, 7500.0, 8000.0))', True, 'import numpy as np\n'), ((24, 4, 24, 137), 'numpy.array', 'np.array', ({(24, 13, 24, 136): '(-0.5, -0.4, -0.3, -0.2, -0.15, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15, 0.2, \n    0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)'}, {}), '((-0.5, -0.4, -0.3, -0.2, -0.15, -0.1, -0.05, 0.0, 0.05, 0.1, 0.15,\n    0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0))', True, 'import numpy as np\n'), ((36, 4, 36, 30), 'numpy.zeros', 'np.zeros', ({(36, 13, 36, 29): '(lenG, lenx, lenP)'}, {}), '((lenG, lenx, lenP))', True, 'import numpy as np\n'), ((43, 7, 43, 90), 'sdf.Dataset', 'sdf.Dataset', (), '', False, 'import sdf\n'), ((44, 7, 44, 80), 'sdf.Dataset', 'sdf.Dataset', (), '', False, 'import sdf\n'), ((45, 7, 45, 82), 'sdf.Dataset', 'sdf.Dataset', (), '', False, 'import sdf\n'), ((46, 7, 46, 69), 'sdf.Dataset', 'sdf.Dataset', (), '', False, 'import sdf\n'), ((49, 4, 49, 74), 'sdf.Group', 'sdf.Group', (), '', False, 'import sdf\n'), ((50, 0, 50, 34), 'sdf.save', 'sdf.save', ({(50, 9, 50, 30): '"""../Data/2006LUT.sdf"""', (50, 32, 50, 33): 'g'}, {}), "('../Data/2006LUT.sdf', g)", False, 'import sdf\n'), ((18, 4, 18, 85), 'numpy.array', 'np.array', ({(18, 13, 18, 84): '(0.1, 0.3, 0.5, 1.0, 2.0, 3.0, 5.0, 7.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0,\n    21.0)'}, {}), '((0.1, 0.3, 0.5, 1.0, 2.0, 3.0, 5.0, 7.0, 10.0, 12.0, 14.0, 16.0, \n    18.0, 20.0, 21.0))', True, 'import numpy as np\n'), ((27, 6, 27, 43), 'numpy.loadtxt', 'np.loadtxt', ({(27, 17, 27, 42): '"""../Data/2006LUTdata.txt"""'}, {}), "('../Data/2006LUTdata.txt')", True, 'import numpy as np\n')]